function insert_multiple_products() { //$conn = connDB(); $multi_files = $_FILES["multi_files"]; //print_r($multi_files); $xls_file = ""; date_default_timezone_set("Asia/Jakarta"); $date = date('Y-m-d'); //include("static/thumbnail.php"); $tmp_name = current($multi_files["tmp_name"]); $error = current($multi_files["error"]); $type = current($multi_files["type"]); foreach ($multi_files["name"] as $name) { $name = $date . "_" . $name; if ($error == 0 && $type != "application/zip") { move_uploaded_file($tmp_name, "../files/uploads/products/{$name}"); if (strpos($name, ".xls") !== false) { $xls_file = "../files/uploads/products/" . $name; } } else { /* -- ZIP FILE HEADER --- */ $zip = new ZipArchive(); if ($zip->open($tmp_name) === TRUE) { if (!file_exists('../files/uploads/products/' . $date)) { mkdir('../files/uploads/products/' . $date, 0777); } $zip->extractTo('../files/uploads/products/' . $date . '/'); $zip->close(); if ($handle = opendir('../files/uploads/products/' . $date . '/')) { if (!file_exists('../files/uploads/products/thumb_240x360/' . $date)) { mkdir('../files/uploads/products/thumb_240x360/' . $date, 0777); } while (false !== ($entry = readdir($handle))) { if (strpos($entry, ".jpg") !== false || strpos($entry, ".jpeg") !== false || strpos($entry, ".png") !== false || strpos($entry, ".gif") !== false) { } $tg = new thumbnailGenerator(); $tg->generate('../files/uploads/products/' . $date . '/' . $entry, 240, 360, $prefix . '../files/uploads/products/thumb_240x360/' . $date . '/' . $entry); } } closedir($handle); } else { $error_zip = 1; } } $tmp_name = next($multi_files["tmp_name"]); $error = next($multi_files["error"]); $type = next($multi_files["type"]); } if ($xls_file != "") { read_xls($xls_file); } }
<?php $id = $_GET['id']; $dbHost = 'localhost'; $dbUser = '******'; $dbPass = ''; $dbName = 'gis_ksn'; $dbConn = mysql_connect($dbHost, $dbUser, $dbPass) or die('MySQL connect failed. ' . mysql_error()); mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error()); include "thumbnail.class.php"; $tg = new thumbnailGenerator(); $sql = "select * from ksn_galeri where id={$id}"; $result = mysql_query($sql); if ($result) { if ($data = mysql_fetch_array($result)) { $photo = "{$data['foto']}"; $tg->generate($photo, 200, 200); } }
public function renderThumbnail($documentId) { // Set up the template $oKTTemplating =& KTTemplating::getSingleton(); $oTemplate =& $oKTTemplating->loadTemplate('thumbnail_viewlet'); if (is_null($oTemplate)) { return ''; } // Check that the thumbnail exists on disk global $default; $varDir = $default->varDirectory; $thumbnailCheck = $varDir . '/thumbnails/' . $documentId . '.jpg'; // Use correct slashes for windows if (strpos(PHP_OS, 'WIN') !== false) { $thumbnailCheck = str_replace('/', '\\', $thumbnailCheck); } // if the thumbnail doesn't exist try to create it if (!file_exists($thumbnailCheck)) { $thumbnailer = new thumbnailGenerator(); $thumbnailer->setDocument($this->oDocument); $thumbnailer->processDocument(); // if it still doesn't exist, return an empty string if (!file_exists($thumbnailCheck)) { return ''; } } // check for existence and status of the instant view plugin $url = ''; if (KTPluginUtil::pluginIsActive('instaview.processor.plugin')) { require_once KTPluginUtil::getPluginPath('instaview.processor.plugin') . 'instaViewLinkAction.php'; $ivLinkAction = new instaViewLinkAction(); $url = $ivLinkAction->getViewLink($documentId, 'document'); } // Get the url to the thumbnail and render it // Ensure url has correct slashes $sHostPath = KTUtil::kt_url(); $plugin_path = KTPluginUtil::getPluginPath('thumbnails.generator.processor.plugin'); $thumbnailUrl = $plugin_path . 'thumbnail_view.php?documentId=' . $documentId; $thumbnailUrl = str_replace('\\', '/', $thumbnailUrl); $thumbnailUrl = str_replace(KT_DIR, $sHostPath, $thumbnailUrl); $oTemplate->setData(array('thumbnail' => $thumbnailUrl, 'url' => $url)); return $oTemplate->render(); }
function insert_product() { $conn = connDB(); //var_dump($_POST); include "static/thumbnail.php"; date_default_timezone_set("Asia/Jakarta"); $date = date('Y-m-d H:i:s'); $date_only = date('Y-m-d_H-i-s'); $product_category = $_POST["product_category"]; $product_size_type_id = $_POST["size_type_id"]; $product_id = $_POST["product_id"]; $product_name = $_POST["product_name"]; $type_id = $_POST["type_id"]; //array $color_id = $_POST["color_id"]; //array $type_name = $_POST["type_name"]; //array $type_alias = array(); foreach ($type_name as $type_name_) { array_push($type_alias, cleanurl($type_name_)); } $type_code = $_POST["type_code"]; //array $type_price = $_POST["type_price"]; //array $type_description = $_POST["type_description"]; //array //$type_image = $_POST["type_image"]; //double_array $type_delete = $_POST["type_delete"]; //array $order = $_POST["order"]; //double_array $image_id = $_POST["image_id"]; $image_delete = $_POST["image_delete"]; $stock_quantity = $_POST["stock_quantity"]; //double_array $stock_name = $_POST["stock_name"]; //double_array $type_weight = $_POST["type_weight"]; $page_title = $_POST["page_title"]; $page_description = $_POST["page_description"]; $product_alias = $_POST["product_alias"]; //!new product if ($product_id == '') { //!new product - get product order $get_order = mysql_query("\n\t\t\t\t\t\tSELECT * from tbl_product\n\t\t\t\t\t\tORDER BY product_order DESC\n\t\t\t\t\t ", $conn); if (mysql_num_rows($get_order) != null) { $get_order_array = mysql_fetch_array($get_order); $product_order = $get_order_array["product_order"] * 1 + 1; } //!new product - insert $sql = "\n\t\t\tINSERT INTO tbl_product(product_category, product_name,product_size_type_id,product_date_added,product_order,product_alias,page_title,page_description) \n\t\tVALUES('{$product_category}', '{$product_name}','{$product_size_type_id}','{$date}','{$product_order}','{$product_alias}','{$page_title}','{$page_description}')"; mysql_query($sql, $conn); //!new product - get the new product id $get_id = mysql_query("\n\t\t\t\tSELECT * from tbl_product\n\t\t\t\tWHERE product_category = '{$product_category}' AND product_name = '{$product_name}' AND product_size_type_id = '{$product_size_type_id}' AND product_date_added = '{$date}'\n\t\t\t\tORDER BY id DESC\n", $conn); if (mysql_num_rows($get_id) != null) { $get_id_array = mysql_fetch_array($get_id); $product_id = $get_id_array["id"]; } } else { $sql = "\n\t\t\tUPDATE tbl_product\n\t\t\tSET product_category = '{$product_category}', product_name = '{$product_name}', product_size_type_id = '{$product_size_type_id}', product_alias='{$product_alias}', page_title='{$page_title}', page_description='{$page_description}'\n\t\t\tWHERE id = '{$product_id}'\n\t\t"; mysql_query($sql, $conn); } //!product types for ($i = 1; $type_name[$i] != null; $i++) { //!delete if ($type_delete[$i] == '1') { //!delete the existing type if ($type_id[$i] != '') { //!delete - set the type_delete to 1 $type_id_ = $type_id[$i]; $sql = "\n\t\t\t\t\tUPDATE tbl_product_type\n\t\t\t\t\tSET type_delete = '1'\n\t\t\t\t\tWHERE type_id = '{$type_id_}'\n\t\t\t\t\t"; mysql_query($sql, $conn); //!delete - remove all stock mysql_query("\n\t\t\t\t\tDELETE FROM tbl_product_stock\n\t\t\t\t\tWHERE type_id = '{$type_id_}'\n\t\t\t\t\t", $conn); } } else { //!new product type if ($type_id[$i] == '') { //!new product type - insert $sql = "\n\t\t\t\tINSERT INTO tbl_product_type(type_code,type_name,type_price,type_description,color_id,type_weight,type_alias,product_id,type_order,page_title,page_description)\n\t\t\t\tVALUES ('{$type_code[$i]}','{$type_name[$i]}','{$type_price[$i]}','{$type_description[$i]}','{$color_id[$i]}','{$type_weight[$i]}','{$type_alias[$i]}','{$product_id}','{$counter}','{$page_title}','{$page_description}')\n\t\t\t"; mysql_query($sql, $conn); //!new product type - get the new type id $get_id = mysql_query("\n\t\t\t\tSELECT * from tbl_product_type\n\t\t\t\tWHERE type_code='{$type_code[$i]}' AND type_name='{$type_name[$i]}' AND type_description='{$type_description[$i]}' AND type_price='{$type_price[$i]}'\n\t\t\t\tORDER BY type_id DESC\n\t\t\t\t", $conn); if (mysql_num_rows($get_id) != null) { $get_id_array = mysql_fetch_array($get_id); $type_id_ = $get_id_array["type_id"]; //echo $type_id_; } } else { $type_id_ = $type_id[$i]; $sql = "\n\t\t\t\tUPDATE tbl_product_type\n\t\t\t\tSET type_code = '{$type_code[$i]}', type_name = '{$type_name[$i]}', type_price = '{$type_price[$i]}', type_description = '{$type_description[$i]}', color_id = '{$color_id[$i]}' , type_weight = '{$type_weight[$i]}', type_alias = '{$type_alias[$i]}',type_order='{$counter}', page_title='{$page_title}', page_description='{$page_description}'\n\t\t\t\tWHERE type_id = '{$type_id_}'\n\t\t\t"; mysql_query($sql, $conn); } //!product image for ($j = 0; $j < 5; $j++) { $k = $order[$i][$j]; //initial order $image_id_ = $image_id[$i][$k]; //!type image - new image if ($image_id_ == "") { //!type image - new image, image existed if ($_FILES["product_image"]["tmp_name"][$i][$k] != null) { $tmp_name = $_FILES["product_image"]["tmp_name"][$i][$k]; $name = cleanurl($product_name) . "_" . cleanurl($type_name[$i]) . "_" . $date_only . "_" . $_FILES["product_image"]["name"][$i][$k]; $error = $_FILES["product_image"]["error"][$i][$k]; //$link = $_POST["type_image"mage_counter]; if ($error == 0) { move_uploaded_file($tmp_name, "../files/uploads/product_image/{$name}"); $img_src = "files/uploads/product_image/{$name}"; } //!type image - new image create thumbnails $tg = new thumbnailGenerator(); $tg->generate('../files/uploads/product_image/' . $name, 240, 360, '../files/uploads/product_image/thumb_240x360/' . $name); mysql_query("\n\t\t\t\t\tINSERT INTO tbl_product_image(type_id,img_src,image_order)\n\t\t\t\t\tVALUES ('{$type_id_}','{$img_src}','{$j}')\n\n\t\t\t\t\t", $conn); } } else { //!type image - update image, image existed if ($_FILES["product_image"]["tmp_name"][$i][$k] != null) { $tmp_name = $_FILES["product_image"]["tmp_name"][$i][$k]; $name = cleanurl($product_name) . "_" . cleanurl($type_name[$i]) . "_" . $date_only . "_" . $_FILES["product_image"]["name"][$i][$k]; $error = $_FILES["product_image"]["error"][$i][$k]; //$link = $_POST["type_image"mage_counter]; if ($error == 0) { move_uploaded_file($tmp_name, "../files/uploads/product_image/{$name}"); $img_src = "files/uploads/product_image/{$name}"; } //!type image - new image create thumbnails $tg = new thumbnailGenerator(); $tg->generate('../files/uploads/product_image/' . $name, 240, 360, '../files/uploads/product_image/thumb_240x360/' . $name); mysql_query("\n\t\t\t\t\tUPDATE tbl_product_image\n\t\t\t\t\tSET img_src='{$img_src}'\n\t\t\t\t\tWHERE image_id='{$image_id_}'\n\t\t\t\t\t", $conn); } //!delete type image if ($image_delete[$i][$k] == '1') { mysql_query("\n\t\t\t\t\tDELETE FROM tbl_product_image\n\t\t\t\t\tWHERE image_id='{$image_id_}'\n\t\t\t\t\t", $conn); } //!type image - update image, order mysql_query("\n\t\t\t\tUPDATE tbl_product_image\n\t\t\t\tSET image_order='{$j}'\n\t\t\t\tWHERE image_id='{$image_id}'\n\t\t\t\t", $conn); } } //type image //!type stock //!type stock - delete all mysql_query("\n\t\t\t\t\tDELETE FROM tbl_product_stock\n\t\t\t\t\tWHERE type_id='{$type_id_}'\n\t\t\t\t\t", $conn); $stock_name_ = current($stock_name[$i]); foreach ($stock_quantity[$i] as $stock_quantity_) { if ($stock_quantity_ != 0) { $stock_sold_out = 0; } else { $stock_sold_out = 1; } //!type stock - insert mysql_query("\n\t\t\t\tINSERT INTO tbl_product_stock(type_id,stock_name,stock_quantity,stock_sold_out)\n\t\t\t\tVALUES ('{$type_id_}','{$stock_name_}','{$stock_quantity_}','{$stock_sold_out}')\n\n\t\t\t", $conn); $stock_name_ = next($stock_name[$i]); } } //delete } //for check_sold_out($product_id); }