public function updatePost() { $id = (int) $_POST['promo_id']; $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('id' => $id, '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_Except($seo_url, $id)) { $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 { $update_result = $promoDAO->update($seo_url, $subject, convert_date_to_us($promo_date), $content, $id); if ($update_result) { $this->registry->template->message = array('type' => 'info', 'value' => 'Đã sửa chương trình khuyến mãi thành công.'); } else { $this->registry->template->message = array('type' => 'error', 'value' => 'Có lỗi xảy ra.'); } } $tmp = $promoDAO->findById($id); if ($tmp == NULL) { $this->registry->template->message = array('type' => 'error_not_found', 'value' => 'Không tồn tại chương trình khuyến mãi này!'); } else { $this->registry->template->promo_backup = $tmp; } }