public function edit() { $this->menuModel = new menuModel(); $menu = array(); if (isset($_GET['id']) && filter_var($_GET['id'], FILTER_VALIDATE_INT, array('min-range' => 1))) { $id = $_GET['id']; $menu['id'] = $id; } else { redirect_to("admin/index.php"); } if ($_SERVER['REQUEST_METHOD'] == "POST") { $errors = array(); if (!empty($_POST['name'])) { $menu['name'] = strip_tags($_POST['name']); $menu['url'] = vn2latin(strip_tags($_POST['name']), true); } else { $errors[] = "name"; } if (isset($_POST['position'])) { $menu['position'] = $_POST['position']; } else { $errors[] = "position"; } if (empty($errors)) { if ($this->menuModel->edit($menu)) { $message = "<div class='alert alert-success'>\n\t\t\t\t\t\t\t\t\t\t<strong>Well done !</strong>You was edit to database successfully !\n\t\t\t\t\t\t\t\t\t</div>"; $this->registry->template->message = $message; } else { $message = "<div class='alert alert-warning'>\n\t\t\t\t\t\t\t\t\t<strong>Wrong </strong>Have a error due to edit database !\n\t\t\t\t\t\t\t\t\t</div>"; $this->registry->template->message = $message; } } // Truyền biến vào views ..Những biến này chi khi nào click vào nút create trên trình duyệt nó mới được truyền . $this->registry->template->errors = $errors; } $this->registry->template->menu = $menu; $this->registry->template->title = "Edit Categories - DA MVC "; $this->registry->template->max_position = $this->menuModel->getPosition(); // Show views create_categories.php ... $this->registry->template->show('menu/menu.edit'); }
public function edit() { if (isset($_SESSION['level']) && $_SESSION['level'] >= 4) { if (isset($_GET['id']) && filter_var($_GET['id'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $this->pagesModel = new pagesModel(); $this->check_ajaxModel = new check_ajaxModel(); $pages = array(); $errors = array(); $pages_temp = array(); $id = $_GET['id']; $pages['id'] = $id; $pages_temp = $this->pagesModel->getPages($id); $this->registry->template->pages = $pages_temp; $page_menu = $this->pagesModel->getMenuById($id); $page_thumuc = $this->pagesModel->getThuMucById($id); $page_thumuc2 = $this->pagesModel->getThuMuc2ById($id); $pages['author_id'] = $_SESSION['id']; $this->registry->template->tags = $this->pagesModel->get_tags_target($id); if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (!empty($_POST['name'])) { if ($this->check_ajaxModel->check_edit_name_pages($_POST['name'], $id)) { $errors[] = "name_is_available"; } else { $pages['name'] = strip_tags($_POST['name']); $pages['url'] = vn2latin($_POST['name'], true); } } else { $errors[] = 'name'; } if (!empty($_POST['title'])) { $pages['title'] = strip_tags($_POST['title']); } else { $errors[] = 'title'; } if (!empty($_POST['chuyen_muc'])) { if ($_POST['chuyen_muc'] >= 100 && $_POST['chuyen_muc'] < 1000) { $pages['menu_id'] = $_POST['chuyen_muc'] - 100; $pages['thumuc_id'] = null; $pages['thumuc2_id'] = null; } else { if ($_POST['chuyen_muc'] > 1000 && $_POST['chuyen_muc'] < 10000) { $pages['menu_id'] = null; $pages['thumuc_id'] = $_POST['chuyen_muc'] - 1000; $pages['thumuc2_id'] = null; } else { if ($_POST['chuyen_muc'] > 10000) { $pages['menu_id'] = null; $pages['thumuc_id'] = null; $pages['thumuc2_id'] = $_POST['chuyen_muc'] - 10000; } } } } else { $errors[] = 'chuyen_muc'; } if (!empty($_FILES['image_icon']['name'])) { $temp = process_images_pages($_FILES['image_icon'], 150); if ($temp != null) { $pages['image_icon'] = $temp; } else { $pages['image_icon'] = $pages_temp['image_icon']; } } else { $pages['image_icon'] = $pages_temp['image_icon']; } if (!empty($_FILES['mp3']['name'])) { $temp = upload($_FILES['mp3']); if ($temp != "success") { $errors[] = "mp3"; $this->registry->template->mp3_error = $temp; } else { $pages['mp3'] = $_FILES['mp3']['name']; } } else { $pages['mp3'] = null; } if (!empty($_POST['content'])) { $pages['content'] = $_POST['content']; } else { $errors[] = "content"; } if (!empty($_POST['des'])) { $pages['des'] = $_POST['des']; } else { $errors[] = "des"; } if (!empty($_POST['keyword'])) { $pages['keyword'] = $_POST['keyword']; } else { $errors[] = "keyword"; } if (!empty($_POST['tags'])) { $tags = explode(",", $_POST['tags']); $i = 0; while (isset($tags[$i]) && $tags[$i] != null) { if (!$this->pagesModel->is_tags($tags[$i])) { //Kiểm tra xem tag đã tồn tại chưa $this->pagesModel->insert_tags($tags[$i]); // Thêm tag vào cơ sở dữ liệu nếu tag chưa đk add } $i++; } if ($this->pagesModel->del_tags_target($id)) { //Xóa những tag của page_id để chuẩn bị cho việc sửa đổi } else { $errors[] = "system"; } } else { $errors[] = "tags"; } if (empty($errors)) { if ($this->pagesModel->edit($pages)) { if (!empty($page_menu['menu_id'])) { if ($this->pagesModel->delete_page_menu($id)) { } else { $message = "errors"; $this->registry->template->message = $message; } } else { if (!empty($page_thumuc['thumuc_id'])) { if ($this->pagesModel->delete_page_thumuc($id)) { } else { $message = "errors"; $this->registry->template->message = $message; } } else { if (!empty($page_thumuc2['thumuc2_id'])) { if ($this->pagesModel->delete_page_thumuc2($id)) { } else { $message = "errors"; $this->registry->template->message = $message; } } } } if (!empty($id) && !empty($pages['menu_id'])) { if ($this->pagesModel->insert_page_menu($id, $pages['menu_id'])) { $message = "<div class='alert alert-success'>\n\t\t\t\t\t\t\t\t\t\t\t<strong>Well done !</strong> Bài viết của bạn đã được sửa thành công .\n\t\t\t\t\t\t\t\t\t\t\t\tXem bài viết <a href='?rt=pages&id=" . $id . "'>tại đây</a></div>"; $this->registry->template->message = $message; } else { $message = "<div class='alert alert-warning'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<strong>Error !</strong>Có lỗi xảy ra khi insert to page_name .</div>"; $this->registry->template->message = $message; } } else { if (!empty($id) && !empty($pages['thumuc_id'])) { if ($this->pagesModel->insert_page_thumuc($id, $pages['thumuc_id'])) { $message = "<div class='alert alert-success'>\n\t\t\t\t\t\t\t\t\t\t\t<strong>Well done !</strong> Bài viết của bạn đã được sửa thành công .\n\t\t\t\t\t\t\t\t\t\t\t\tXem bài viết <a href='?rt=pages&id=" . $id . "'>tại đây</a></div>"; $this->registry->template->message = $message; } else { $message = "<div class='alert alert-warning'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<strong>Error !</strong>Có lỗi xảy ra khi insert to page_thumuc .</div>"; $this->registry->template->message = $message; } } else { if (!empty($id) && !empty($pages['thumuc2_id'])) { if ($this->pagesModel->insert_page_thumuc2($id, $pages['thumuc2_id'])) { $message = "<div class='alert alert-success'>\n\t\t\t\t\t\t\t\t\t\t\t<strong>Well done !</strong> Bài viết của bạn đã được sửa thành công .\n\t\t\t\t\t\t\t\t\t\t\t\tXem bài viết <a href='?rt=pages&id=" . $id . "'>tại đây</a></div>"; $this->registry->template->message = $message; } else { $message = "<div class='alert alert-warning'>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<strong>Error !</strong>Có lỗi xảy ra khi insert to page_thumuc2 .</div>"; $this->registry->template->message = $message; } } } } $i = 0; while (isset($tags[$i]) && $tags[$i] != null) { $tag_id = $this->pagesModel->get_id_tags($tags[$i]); $this->pagesModel->insert_tags_target($id, $tag_id); $i++; } } else { $message = "<div class='alert alert-warning'>\n\t\t\t\t\t\t\t\t\t\t<strong>Error !</strong>Có lỗi xảy ra ... xin vui lòng thử lại lần sau .</div>"; $this->registry->template->message = $message; } } } $this->registry->template->errors = $errors; $this->registry->template->menu = $this->pagesModel->getMenu(); $this->registry->template->thumuc = $this->pagesModel->getThuMuc(); $this->registry->template->thumuc2 = $this->pagesModel->getThuMuc2(); // Load menu bar $this->registry->template->menu = $this->pagesModel->getMenu(); $this->registry->template->num_notice = $this->pagesModel->count_notice($_SESSION['id']); // End load menubar $this->registry->template->users = $this->pagesModel->getNewUsers(); $this->registry->template->top_class = $this->pagesModel->get_top_class(); $this->registry->template->show('pages/pages.edit'); } else { redirect_to("error404"); } } else { redirect_to(); } }
public function edit() { if (!isset($_SESSION['level']) || $_SESSION['level'] < 4) { redirect_to(); } if (isset($_GET['id']) && filter_var($_GET['id'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $this->thumucModel = new thumucModel(); $this->check_ajaxModel = new check_ajaxModel(); $id = $_GET['id']; $this->registry->template->thumuc = $this->thumucModel->getThuMucById($id); $thumuc = array(); $thumuc['id'] = $id; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); if (!empty($_POST['name'])) { $thumuc['name'] = strip_tags($_POST['name']); $thumuc['url'] = vn2latin(strip_tags($_POST['name']), true); } else { $errors[] = "name"; } if (!empty($_POST['menu_id'])) { $thumuc['menu_id'] = $_POST['menu_id']; } else { $errors[] = "menu_id"; } if (!empty($_POST['position'])) { $thumuc['position'] = $_POST['position']; } else { $errors[] = "position"; } if (empty($errors)) { if ($this->thumucModel->edit($thumuc)) { $message = "<div class='alert alert-success'>\n\t\t\t\t\t\t\t\t\t\t\t\t<strong>Well done !</strong>You was insert to database successfully !\n\t\t\t\t\t\t\t\t\t\t\t</div>"; $this->registry->template->message = $message; } else { $message = "<div class='alert alert-warning'>\n\t\t\t\t\t\t\t\t\t\t\t<strong>Wrong </strong>Have a error due to insert to database !\n\t\t\t\t\t\t\t\t\t\t\t</div>"; $this->registry->template->message = $message; } } $this->registry->template->errors = $errors; } // Load menu bar $this->registry->template->menu = $this->thumucModel->getMenu(); $this->registry->template->num_notice = $this->thumucModel->count_notice($_SESSION['id']); $this->registry->template->users = $this->thumucModel->getNewUsers(); $this->registry->template->top_class = $this->thumucModel->get_top_class(); // End load menubar $this->registry->template->max_position = $this->thumucModel->getPosition(); $this->registry->template->title = "Sửa thư mục DA-MVC"; $this->registry->template->show('thumuc/thumuc.edit'); } else { redirect_to(); } }
public function edit() { if (!isset($_SESSION['level']) || $_SESSION['level'] < 4) { redirect_to(); } if (isset($_GET['id']) && filter_var($_GET['id'], FILTER_VALIDATE_INT, array('min_range' => 1))) { $this->thumuc2Model = new thumuc2Model(); $id = $_GET['id']; $this->registry->template->thumuc2 = $this->thumuc2Model->getThuMuc2ById($id); $this->registry->template->thumuc = $this->thumuc2Model->getThuMuc($id); $thumuc2 = array(); $thumuc2['id'] = $id; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $errors = array(); if (!empty($_POST['name'])) { $thumuc2['name'] = strip_tags($_POST['name']); $thumuc2['url'] = vn2latin(strip_tags($_POST['name']), true); } else { $errors[] = "name"; } if (!empty($_POST['thumuc_id'])) { $thumuc2['thumuc_id'] = $_POST['thumuc_id']; } else { $errors[] = "thumuc_id"; } if (!empty($_POST['position'])) { $thumuc2['position'] = $_POST['position']; } else { $errors[] = "position"; } if (empty($errors)) { if ($this->thumuc2Model->edit($thumuc2)) { $message = "<div class='alert alert-success'>\n\t\t\t\t\t\t\t\t\t\t\t\t<strong>Well done !</strong>Bạn đã sửa thư mục thành công !\n\t\t\t\t\t\t\t\t\t\t\t</div>"; $this->registry->template->message = $message; } else { $message = "<div class='alert alert-warning'>\n\t\t\t\t\t\t\t\t\t\t\t<strong>Wrong </strong>Có lỗi xảy ra ... Chúng tôi xin lỗi về sự bất tiện này .!\n\t\t\t\t\t\t\t\t\t\t\t</div>"; $this->registry->template->message = $message; } } $this->registry->template->errors = $errors; } // Load menu bar $this->registry->template->menu = $this->thumuc2Model->getMenu(); $this->registry->template->num_notice = $this->thumuc2Model->count_notice($_SESSION['id']); // End load menubar $this->registry->template->max_position = $this->thumuc2Model->getPosition(); $this->registry->template->title = "Sửa thư mục DA-MVC"; $this->registry->template->users = $this->thumuc2Model->getNewUsers(); $this->registry->template->top_class = $this->thumuc2Model->get_top_class(); $this->registry->template->show('thumuc2/thumuc2.edit'); } else { redirect_to(); } }