Esempio n. 1
0
 public function insertPost()
 {
     $code = trim(remove_slashes($_POST['code']));
     $category_id = (int) $_POST['category_id'];
     $brand_id = (int) $_POST['brand_id'];
     $price_fonds = trim(remove_slashes($_POST['price_fonds']));
     $price_sell = trim(remove_slashes($_POST['price_sell']));
     $price_sell = trim(remove_slashes($_POST['price_sell']));
     $description = trim(remove_slashes($_POST['description']));
     $pics = trim(remove_slashes($_POST['pics']));
     $seo_url = trim(remove_slashes($_POST['seo_url']));
     $this->registry->template->product = array('code' => htmlspecialchars($code), 'category_id' => $category_id, 'brand_id' => $brand_id, 'price_fonds' => htmlspecialchars($price_fonds), 'price_sell' => htmlspecialchars($price_sell), 'description' => htmlspecialchars($description), 'pics' => $pics, 'seo_url' => $seo_url);
     $messageStr = '';
     $productDAO = new ProductDAO(DataSource::getInstance());
     if (!isset($code) || strlen($code) == 0) {
         $messageStr .= 'Mã sản phẩm: không được bỏ trống.<br />';
     } else {
         if ($productDAO->isExistedCode($code)) {
             $messageStr .= 'Mã sản phẩm: đã tồn tại.<br />';
         }
     }
     if (!isset($price_fonds) || strlen($price_fonds) == 0) {
         $messageStr .= 'Giá vốn: không được bỏ trống.<br />';
     } else {
         if ((int) $price_fonds <= 0) {
             $messageStr .= 'Giá vốn: phải là số nguyên dương.<br />';
         } else {
             $price_fonds_int = (int) $price_fonds;
         }
     }
     if (!isset($price_sell) || strlen($price_sell) == 0) {
         $messageStr .= 'Giá bán: không được bỏ trống.<br />';
     } else {
         if ((int) $price_sell <= 0) {
             $messageStr .= 'Giá bán: phải là số nguyên dương.<br />';
         } else {
             $price_sell_int = (int) $price_sell;
         }
     }
     if (isset($price_fonds_int) && isset($price_sell_int)) {
         if ($price_fonds_int > $price_sell_int) {
             $messageStr .= 'Giá bán: không được thấp hơn giá vốn.<br />';
         }
     }
     if (strlen($seo_url) == 0) {
         $messageStr .= 'SEO URL: không được bỏ trống.<br />';
     } else {
         if (!check_seo_url($seo_url)) {
             $messageStr .= 'SEO URL: không hợp lệ.<br />';
         } else {
             if ($productDAO->isExistedSeoUrl($seo_url)) {
                 $messageStr .= 'SEO URL: đã tồn tại.<br />';
             }
         }
     }
     $messageStr = trim($messageStr);
     if ($messageStr != '') {
         $this->registry->template->message = array('type' => 'error', 'value' => $messageStr);
     } else {
         $last_id = $productDAO->insert($code, $brand_id, $category_id, $price_fonds, $price_sell, $description, $pics, $seo_url);
         if ($last_id > -1) {
             $this->registry->template->message = array('type' => 'info', 'value' => 'Thêm sản phẩm thành công. ' . ' <a href="' . __SITE_CONTEXT . 'admin/product/update?id=' . $last_id . '">[Sửa]</a>');
             $this->registry->template->product = NULL;
         } else {
             $this->registry->template->message = array('type' => 'error', 'value' => 'Có lỗi xảy ra.');
         }
     }
 }
Esempio n. 2
0
<?php

require '../../include/global_functions.php';
loggedInOrRedirect();
$language_fields_addition = $_SESSION['language'] == 'en_US' ? '' : '_' . $_SESSION['language'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $image = base64_encode(file_get_contents($_FILES['image']['tmp_name']));
    $daoprod = new ProductDAO();
    //We insert the product in the database
    $resprod = $daoprod->insert($_POST["category"], $_POST["specification"], $_POST['serial_number'], $_POST['purchase_price'], $_POST['periodical_discount'], $_POST['brand'], $_POST['model'], $_POST['classification'], $_POST['cost'], $_POST['consumption'], $_POST['release_year'], $_POST['description'], $image);
}
?>

<script type="text/javascript">
<!-- This function display the specifications according to the category choose -->
function displayspecification(category_id) {

	var xhttp = new XMLHttpRequest();
	  xhttp.onreadystatechange = function() {
	    if (xhttp.readyState == 4 && xhttp.status == 200) {
	      document.getElementById("specification").innerHTML = xhttp.responseText;
	    }
	  }

	  xhttp.open("GET", "../getspecification.php?idcategory="+category_id, true);
	  xhttp.send();
}
</script>
<?php 
$category_dao = new CategoryDAO();
$categories = $category_dao->getAllCategories();