/** * Edit Post */ public function edit($id) { if (!Auth::isLogged()) { Url::redirect('login'); } $data['js'] = array(Url::assetPath('js') . 'plugins/forms/selects/select2.min.js', Url::assetPath('js') . 'plugins/forms/validation/validate.min.js', Url::assetPath('js') . 'plugins/editors/summernote/summernote.min.js', Url::assetPath('js') . 'plugins/pickers/bootstrap-datetimepicker.min.js', Url::assetPath('js') . 'plugins/forms/styling/uniform.min.js', Url::assetPath('js') . 'plugins/notifications/bootbox.min.js', Url::assetPath('js') . 'pages/blog_add.js'); $data['categories'] = $this->blog->getCategories(); $data['statuses'] = (object) array(0 => (object) array('id' => '0', 'name' => $this->language->get('draft')), 1 => (object) array('id' => '1', 'name' => $this->language->get('publish'))); $data['post'] = $this->blog->getPost($id); if (isset($_POST['update'])) { $title = $_POST['title']; $status = $_POST['status']; $content = $_POST['content']; $category_id = $_POST['category']; $user_id = $_SESSION['id']; $schedule = isset($_POST['schedule']) ? '1' : '0'; if ($status == '1' && $schedule == '1') { if (isset($_POST['published_at'])) { $published_at = Date::convertLocalDateTimeToSQL($_POST['published_at'], $_SESSION['dateformat'] . ' ' . $_SESSION['timeformat']); } else { $published_at = ''; } } elseif ($status == '1' && $schedule == '0') { $published_at = Date::convertLocalDateTimeToSQL($_POST['published_at'], $_SESSION['dateformat'] . ' ' . $_SESSION['timeformat']); } else { $published_at = ''; $schedule = '0'; } if ($title == '') { $error[] = $this->language->get('title_required'); } if ($status == '') { $error[] = $this->language->get('status_required'); } if ($category_id == '') { $error[] = $this->language->get('category_required'); } if (!$error) { $data = array('title' => $title, 'content' => $content, 'status' => $status, 'category_id' => $category_id, 'user_id' => $user_id, 'schedule' => $schedule, 'published_at' => $published_at != '' ? $published_at : NULL); $where = array('id' => $id); $data_log = array('id' => $id, 'title' => $title, 'status' => $status, 'category_id' => $category_id, 'user_id' => $user_id, 'schedule' => $schedule, 'published_at' => $published_at != '' ? $published_at : NULL); $this->blog->updatePost($data, $where); Session::set('success', $this->language->get('msg_blog_edit')); Log::notice('log_blog_edit', $data_log); Url::redirect('blog'); } } if (isset($_POST['cancel'])) { Url::redirect('blog'); } View::renderTemplate('header', $data); View::renderModule('Blog/views/edit', $data, $error); View::renderTemplate('footer', $data); }