Example #1
0
 public function index()
 {
     if ($_SERVER['REQUEST_METHOD'] == 'GET') {
         $fromDate = get_cur_date('/');
         $toDate = $fromDate;
     } else {
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             if (isset($_POST['cart_id'])) {
                 $cart_id = $_POST['cart_id'];
                 if ((int) $cart_id <= 0) {
                     $message = 'Mã giỏ hàng không hợp lệ';
                     $this->registry->template->message = array('type' => 'error', 'value' => $message);
                 } else {
                     $message = '1';
                 }
             } else {
                 $fromDate = trim(remove_slashes($_POST['fromDate']));
                 $toDate = trim(remove_slashes($_POST['toDate']));
                 $message = '';
                 if ($fromDate != '') {
                     if (!valid_date_vn($fromDate)) {
                         $message .= 'Ngày bắt đầu không hợp lệ<br />';
                     }
                 }
                 if ($toDate != '') {
                     if (!valid_date_vn($toDate)) {
                         $message .= 'Ngày kết thúc không hợp lệ<br />';
                     }
                 }
                 if ($message != '') {
                     $this->registry->template->message = array('type' => 'error', 'value' => $message);
                 }
             }
         }
     }
     if (empty($message)) {
         $t1 = $fromDate == '' ? '01/01/2000' : $fromDate;
         $t2 = $toDate == '' ? '01/01/2050' : $toDate;
         $t1 = convert_date_to_us($t1) . ' 00:00:00';
         $t2 = convert_date_to_us($t2) . ' 23:59:59';
         $cartDAO = new CartDAO(DataSource::getInstance());
         $carts = $cartDAO->findByDateRange($t1, $t2);
         $cart_details = array();
         foreach ($carts as $key => $value) {
             $cart_details[$key] = $cartDAO->findDetail($key);
         }
     } else {
         if ($message == '1') {
             // search by cart id
             $cartDAO = new CartDAO(DataSource::getInstance());
             $cart = $cartDAO->findById((int) $cart_id);
             $carts = array();
             $cart_details = array();
             if ($cart) {
                 $carts[$cart_id] = $cart['checkout_datetime'];
                 $cart_details[$cart_id] = $cartDAO->findDetail($cart_id);
             }
         }
     }
     $this->registry->template->cart_id = $cart_id;
     $this->registry->template->fromDate = $fromDate;
     $this->registry->template->toDate = $toDate;
     $this->registry->template->carts = $carts;
     $this->registry->template->cart_details = $cart_details;
     $this->registry->template->tile_title = 'Danh sách giỏ hàng';
     $this->registry->template->tile_content = 'admin/cart.php';
     $this->registry->template->show('admin/layout/admin.php');
 }
Example #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.');
         }
     }
 }