public function editPost($id) { $view = new View("product/edit.php"); $modelProduct = new Product(); $modelProduct->updateProduct($id, $_POST['name'], $_POST['price'], $_POST['description']); header('Location: ' . BASEURL . '?c=product/edit&id=' . $id . '&m=ok'); }
$price1 = $_REQUEST['price']; $image_name1 = $_REQUEST['image_name']; $description1 = $_REQUEST['description']; if ($_FILES["image_path"]["error"] > 0) { echo "<font size = '5'><font color=\"#e31919\">Error: NO CHOSEN FILE <br />"; echo "<p><font size = '5'><font color=\"#e31919\">INSERT TO DATABASE FAILED"; } else { $uploaddir = "images/"; move_uploaded_file($_FILES["image_path"]["tmp_name"], "{$uploaddir}" . $_FILES["image_path"]["name"]); echo "<font size = '5'><font color=\"#0CF44A\">SAVED<br>"; } $file1 = "{$uploaddir}" . $_FILES["image_path"]["name"]; switch ($_REQUEST['operation']) { case "add": $product->addProduct("product_details", "product_name,price,image_name,image_path,description", "'{$product_name}','{$price}','{$image_name}','{$file}','{$description}'"); break; case "update": $product->updateProduct("product_details", "product_name='{$product_name1}',price='{$price1}',image_name='{$image_name1}',\r\n\timage_path='{$file1}',description='{$description1}'", "product_id='{$product_id1}'"); break; case "delete_rec": $product->deleteProduct("product_details", "product_id='{$product_id}'"); break; case "view": $product->viewProduct($product_list, $table); break; case "view_single": $product->viewSingleProduct($product_list, $table, $condition); break; default: echo "<H3 color='red'>Invalid Option Please Try again!</h3>"; }
/** * Action для страницы "Редактировать товар" */ public function actionUpdate($id) { // Получаем список категорий для выпадающего списка $categories = Category::getCategoriesList(); // Получаем данные о конкретном заказе $product = Product::getProductById($id); $options = array(); // Флаг ошибок в форме $errors = false; // Обработка формы if (isset($_POST['submit'])) { $options['name'] = $_POST['name']; $options['code'] = $_POST['code']; $options['price'] = $_POST['price']; $options['category_id'] = $_POST['category_id']; $options['brand'] = $_POST['brand']; $options['availability'] = $_POST['availability']; $options['description'] = $_POST['description']; $options['is_new'] = $_POST['is_new']; $options['is_recommended'] = $_POST['is_recommended']; $options['status'] = $_POST['status']; // При необходимости можно валидировать значения нужным образом if (!isset($options['name']) || empty($options['name'])) { $errors[] = 'Неправильно введено имя'; } if ($errors === false) { // Если ошибок нет, сохраняем изменения Product::updateProduct($options, $id); // Проверяем. загружалось ли через форму изображение if (is_uploaded_file($_FILES['image']['tmp_name'])) { // Если загружалось, переместим его в нужную папку, дадим новое имя move_uploaded_file($_FILES['image']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . "/upload/images/{$id}.jpg"); } // Перенаправляем пользователя на страницу управления товарами header('Location: /admin/product/'); } } // Подключаем вид require_once ROOT . '/views/admin_product/update.php'; return true; }
$general->redirectUrl($url, $num); exit; } else { $pattern = '/^[0-9]+(?:\\.[0-9]{0,2})?$/'; if (preg_match($pattern, trim($_REQUEST['sellingprice'])) == '0') { $_SESSION['msg'] = 'Please enter valid selling'; $num = 'danger'; $num .= '&id=' . $_REQUEST['id']; $url = ADMIN_URL . "/products/edit.php"; $general->redirectUrl($url, $num); exit; } } $cond = array("id" => $_REQUEST['id']); $fieldvalues = array('status' => $_REQUEST['status'], 'categoryid' => $_REQUEST['category'], 'productname' => $_REQUEST['productname'], 'skucode' => $_REQUEST['skucode'], "barcode" => $_REQUEST['barcode'], "model" => $_REQUEST['model'], "unit" => $_REQUEST['unit'], "volume" => $_REQUEST['volume'], "costprice" => $_REQUEST['costprice'], "sellingprice" => $_REQUEST['sellingprice'], "description" => $_REQUEST['description']); $updated = $Product->updateProduct($fieldvalues, $cond); if ($updated) { $general->addLogAction($_SESSION['adm_user_id'], 'Edited', $_REQUEST['id'], 'Product Management', $_SESSION['adm_status']); $error = 'success'; $_SESSION['msg'] = 'Record updated successfully.'; } else { $error = 'danger'; $_SESSION['msg'] = 'Error updating record.'; } $url = ADMIN_URL . "/products/index.php"; $general->redirectUrl($url, $error); exit; } /*************************************************************************************/ if (isset($_REQUEST['FLAG']) && $_REQUEST['FLAG'] == 'DELETE') { $id = $_REQUEST['id'];
* edit products */ require '../inc.php'; if (isset($_REQUEST['id'])) { //check is passed product_id exists $sql = "SELECT id FROM products WHERE id = '" . $_REQUEST['id'] . "';"; $results = mysql_query($sql) or die('trying to look up this product_id for an edit form populate: Error in sql: ' . $sql); if (mysql_num_rows($results) < 1) { //this product id doesn't exist header('Location: ' . resellerLocatorBaseWebAddress() . '/products/index.php?message=notexist'); } $product = new Product($_REQUEST['id']); } // check for form submission (if empty form submission then print the form..) if (!empty($_POST)) { $product->updateProduct(); } /***********************************************************************************/ //No data was submitted or validation failed // ...so print the form for user to fill out and submit /***********************************************************************************/ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Edit Reseller Product</title> <link href="/admin/reseller_locator/css/newtek_nav.css" rel="stylesheet" type="text/css" /> <link href="/admin/reseller_locator/css/tri_subnav.css" rel="stylesheet" type="text/css" />
$productModel->_setProductColor($productDetails->color); $productModel->_setProductDescription($productDetails->description); $productModel->_setProductPackaging($productDetails->packaging); $productModel->_setProductType($productDetails->materialtypeid); $productModel->_setProductOperation($productDetails->opertaion); $productObj = new Product($productModel); switch ($productDetails->opertaion) { case 'insert': # code... if (!$productObj->isAvailable($dbh)) { $productObj->insertProductInToDb($dbh, $userId); } else { $showAlerts->showAlert("Failure", "Product you are trying to add is already added"); } break; case 'delete': # code... //$productObj = new Product(); $productObj->deleteProduct($dbh, $userId, $productDetails); break; case 'modify': if ($productDetails->isProductMasterTable || $productDetails->isProductDetailsTable || $productDetails->isProductPackagingTable || $productDetails->isProductMaterialTable) { $productObj->updateProduct($dbh, $userId, $productDetails); } else { $showAlerts->showAlert('Failure', "Nothing to update"); } break; default: # code... break; }