www
/
wwwroot
/
magazinmiorita.be
/
admin
➕ New
📤 Upload
✎ Editing:
edit_product.php
← Back
<?php ob_start(); include('../includes/inc.config.php'); include('check_session.php'); $page = ($_GET['page'] ? 'page='.$_GET['page'].'&' : ''); $search = ($_GET['search'] ? 'search='.$_GET['search'].'&' : ''); $product_details = $database->execute(" SELECT * FROM `products` WHERE `id` = '".$_GET['id']."' "); while($row = $database->fetch($product_details)){ $product_code = $row['code']; $product_name = $row['name']; $product_description = $row['description']; $product_price = $row['price']; $product_cat_id = $row['cat_id']; $product_scat_id = $row['scat_id']; $product_status = $row['status']; $product_thumb = $row['thumb']; $product_sku = number_format($row['sku'],2); $product_weight = unserialize($row['weight']); $product_measure = $row['measure']; } $smarty->assign("product_code", $product_code); $smarty->assign("product_name", $product_name); $smarty->assign("product_description", $product_description); $smarty->assign("product_price", $product_price); $smarty->assign("product_cat_id", $product_cat_id); $smarty->assign("product_scat_id", $product_scat_id); $smarty->assign("product_status", $product_status); $smarty->assign("product_thumb", $product_thumb); $smarty->assign("product_sku", $product_sku); $smarty->assign("product_measure", $product_measure); $weight_results = array(); $get_weight = $database->execute(" SELECT * FROM `prod_weight` WHERE `prod_id` = '".$_GET['id']."' "); $get_DISTINCT = $database->execute(" SELECT DISTINCT type FROM `prod_weight` WHERE `prod_id` = '".$_GET['id']."' "); $t = $database->num($get_DISTINCT); $i = 0; while($row = $database->fetch($get_weight)){ $row['total'] = $i; $i++; $weight_results[] = $row; } $smarty->assign("total", ($t-1)); $smarty->assign("weight_results", $weight_results); if(isset($_POST['add'])){ $id = $_POST['id']; $code = $_POST['code']; $name = $_POST['name']; $measure = $_POST['measure']; $product_info = $_POST['product_info']; $description = $_POST['description']; $price = $_POST['price']; $cat_id = $_POST['cat_id']; $scat_id = $_POST['scat_id']; $sku = $_POST['sku']; $weight = $_POST['weight']; $type = $_POST['type']; $prod_id = $_GET['id']; $status = $_POST['status']; $filename = $_FILES['thumb']['name']; $ext = substr($filename, strrpos($filename, '.') + 1); // Thumb Image $thumb = "../uploads/images/".md5($filename)."_".time().".".$ext; if (is_uploaded_file($_FILES['thumb']['tmp_name'])) { $thumb_db = "uploads/images/".md5($filename)."_".time().".".$ext; }else{ $thumb_db = $product_thumb; } // Screenshots $error = ''; if ($_FILES['screens']) { if(!file_exists("../uploads/screens/prod_".$_GET['id']."")){ mkdir("../uploads/screens/prod_".$_GET['id']."", 0777); } for($i=0; $i<count($_FILES['screens']['name']); $i++) { //Get the temp file path $tmpFilePath = $_FILES['screens']['tmp_name'][$i]; //Make sure we have a filepath if ($tmpFilePath != ""){ //Setup our new file path $newFilePath = "../uploads/screens/prod_".$_GET['id']."/". $_FILES['screens']['name'][$i]; $newFile_DB = "uploads/screens/prod_".$_GET['id']."/". $_FILES['screens']['name'][$i]; //Upload the file into the temp dir if(move_uploaded_file($tmpFilePath, $newFilePath)) { $insert_screen = $database->execute("INSERT INTO screnshots(`item_id`, `image`) values('".$_GET['id']."', '".$newFile_DB."')"); $error = '0'; }else{ $error = '1'; } } } } $list = array(); $del_weight = $database->execute("DELETE FROM `prod_weight` WHERE `prod_id` = '".$_GET['id']."'"); for($i=0;$i<count($_POST['type']);$i++) { $list[$i] = array($_POST['type'][$i], $_POST['weight'][$i]); } foreach ($list as $w) { //$add_weight = $database->execute("INSERT INTO `prod_weight`(`prod_id`, `type`, `weight`)VALUES('$prod_id', '".$w[0]."', '".$w[1]."')"); } $edit_product = $database->execute("UPDATE `products` SET `code` = '$code', `name` = '$name', `measure` = '$measure', `description` = '$description', `product_info` = '$product_info', `price` = '$price', `cat_id` = '$cat_id', `scat_id` = '$scat_id', `sku` = '$sku', `thumb` = '$thumb_db', `status` = '$status' WHERE `id` = '".$_GET['id']."' "); if($edit_product && $error != '1'){ $get_thumb = $database->execute("SELECT * FROM `products` WHERE `id` = '".$_GET['id']."'"); while($row = $database->fetch($get_thumb)){ $old_thumb = $row['thumb']; } if (is_uploaded_file($_FILES['thumb']['tmp_name'])) { unlink('../'.$old_thumb); copy($_FILES['thumb']['tmp_name'], $thumb); } header('Location: products.php?'.$page.''.$search.'m=ok'); exit; }else{ $message = 'Error! Product can not be updated, please check and try again.'; $msg_type = 'err'; } } $screens_results = array(); $screens = $database->execute(" SELECT * FROM `screnshots` where item_id = '".$_GET['id']."' "); while($row = $database->fetch($screens)){ $screens_results[] = $row; } $categories_results = array(); $categories = $database->execute(" SELECT * FROM `categories` "); while($row = $database->fetch($categories)){ $categories_results[] = $row; } $subcategories_results = array(); $subcategories = $database->execute(" SELECT * FROM `subcategory` WHERE `cat_id` = '".$product_cat_id."' "); while($row = $database->fetch($subcategories)){ $subcategories_results[] = $row; } $smarty->assign("message", $message); $smarty->assign("type", $msg_type); $smarty->assign("screenshots", $screens_results); $smarty->assign("categories", $categories_results); $smarty->assign("subcategories", $subcategories_results); $smarty->display(END_PATH.'edit_product.tpl'); ?>
💾 Save Changes
Cancel
📤 Upload File
×
Select File
Upload
Cancel
➕ Create New
×
Type
📄 File
📁 Folder
Name
Create
Cancel
✎ Rename Item
×
Current Name
New Name
Rename
Cancel
🔐 Change Permissions
×
Target File
Permission (e.g., 0755, 0644)
0755
0644
0777
Apply
Cancel