Ejemplo n.º 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');
 }
Ejemplo n.º 2
0
 private function updatePost()
 {
     $id = (int) $_POST['id'];
     $full_name = trim(remove_slashes($_POST['full_name']));
     $address = trim(remove_slashes($_POST['address']));
     $email = trim(remove_slashes($_POST['email']));
     $birthday = trim(remove_slashes($_POST['birthday']));
     $city_id = (int) $_POST['city_id'];
     $note = trim(remove_slashes($_POST['note']));
     $phone = trim(remove_slashes($_POST['phone']));
     $this->registry->template->customer = array('id' => $id, 'full_name' => htmlspecialchars($full_name), 'address' => htmlspecialchars($address), 'email' => htmlspecialchars($email), 'birthday' => htmlspecialchars($birthday), 'city_id' => $city_id, 'note' => htmlspecialchars($note), 'phone' => htmlspecialchars($phone));
     $messageStr = '';
     if (!isset($full_name) || strlen($full_name) == 0) {
         $messageStr .= 'Họ và tên: không được bỏ trống.<br />';
     }
     if (isset($email) && strlen($email) > 0) {
         if (!valid_email($email)) {
             $messageStr .= 'Email: không hợp lệ.<br />';
         }
     }
     if (isset($birthday) && strlen($birthday) > 0) {
         if (!valid_date_vn($birthday)) {
             $messageStr .= 'Ngày sinh: không hợp lệ.<br />';
         }
     }
     $messageStr = trim($messageStr);
     $customerDAO = new CustomerDAO(DataSource::getInstance());
     if ($messageStr != '') {
         $this->registry->template->message = array('type' => 'error', 'value' => $messageStr);
     } else {
         $result = $customerDAO->update($id, $full_name, convert_date_to_us($birthday), $address, $email, $city_id, $note, $phone);
         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 = $customerDAO->findById($id);
     $this->registry->template->customer_backup = $tmp;
     if (!$tmp) {
         $this->registry->template->message = array('type' => 'error_not_found', 'value' => 'Không tồn tại khách hàng này!');
     }
 }
Ejemplo n.º 3
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.');
         }
     }
 }