示例#1
0
 public function updatePost()
 {
     $id = (int) $_POST['id'];
     $code = trim(remove_slashes($_POST['code']));
     $brand_id = (int) $_POST['brand_id'];
     $category_id = (int) $_POST['category_id'];
     $price_fonds = trim(remove_slashes($_POST['price_fonds']));
     $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('id' => $id, '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' => htmlspecialchars($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_Except($code, $id)) {
             $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_Except($seo_url, $id)) {
                 $messageStr .= 'SEO URL: đã tồn tại.<br />';
             }
         }
     }
     $messageStr = trim($messageStr);
     if ($messageStr != '') {
         $this->registry->template->message = array('type' => 'error', 'value' => $messageStr);
     } else {
         $result = $productDAO->update($id, $code, $brand_id, $category_id, $price_fonds, $price_sell, $description, $pics, $seo_url);
         if ($result) {
             $this->registry->template->message = array('type' => 'info', 'value' => 'Lưu thành công!');
         } else {
             $this->registry->template->message = array('type' => 'error', 'value' => 'Có lỗi xảy ra.');
         }
     }
     $tmp = $productDAO->findById($id);
     $this->registry->template->product_backup = $tmp;
     if (!$tmp) {
         $this->registry->template->message = array('type' => 'error_not_found', 'value' => 'Không tồn tại sản phẩm này!');
     }
 }
示例#2
0
 private function insertPost()
 {
     $seo_url = trim(remove_slashes($_POST['seo_url']));
     $subject = trim(remove_slashes($_POST['subject']));
     $promo_date = trim(remove_slashes($_POST['promo_date']));
     $content = trim(remove_slashes($_POST['content']));
     $this->registry->template->promo = array('seo_url' => htmlspecialchars($seo_url), 'subject' => htmlspecialchars($subject), 'promo_date' => htmlspecialchars($promo_date), 'content' => $content);
     $promoDAO = new PromoDAO(DataSource::getInstance());
     $message = '';
     if (strlen($seo_url) == 0) {
         $message .= 'SEO URL: không được bỏ trống.<br />';
     } else {
         if (!check_seo_url($seo_url)) {
             $message .= 'SEO URL: không hợp lệ.<br />';
         } else {
             if ($promoDAO->isExistedSeoUrl($seo_url)) {
                 $message .= 'SEO URL: đã tồn tại.<br />';
             }
         }
     }
     if (strlen($subject) == 0) {
         $message .= 'Chủ đề: không được bỏ trống.<br />';
     }
     if (strlen($promo_date) == 0) {
         $message .= 'Ngày tạo: không được bỏ trống.<br />';
     } else {
         if (!valid_date_vn($promo_date)) {
             $message .= 'Ngày tạo: không hợp lệ.<br />';
         }
     }
     if (strlen($content) == 0) {
         $message .= 'Nội dung chương trình: không được bỏ trống.<br />';
     }
     if (strlen($message) != 0) {
         $this->registry->template->message = array('type' => 'error', 'value' => $message);
     } else {
         $last_id = $promoDAO->insert($seo_url, $subject, convert_date_to_us($promo_date), $content);
         if ($last_id > -1) {
             $this->registry->template->message = array('type' => 'info', 'value' => 'Đã thêm chương trình khuyến mãi thành công. ' . ' <a href="' . __SITE_CONTEXT . 'admin/promo/update?id=' . $last_id . '">[Sửa]</a>');
             $this->registry->template->promo = array('promo_date' => get_cur_date('/'));
         } else {
             $this->registry->template->message = array('type' => 'error', 'value' => 'Có lỗi xảy ra.');
         }
     }
 }