public function editCategory($id)
 {
     if (Authorization::Authorize('Admin')) {
         $this->view->category = $this->model->getCategory();
         // viet code xy lu o day
         $this->data = array();
         $this->view->title = 'Edit Category';
         $this->view->cat = $this->model->showCatById($id);
         if (isset($_POST['submit'])) {
             if (empty($_POST['catname'])) {
                 $this->view->msg = "Vui lòng nhập tên Category";
                 $this->view->renderAdmin('category/editcategory');
             } else {
                 $this->data['catname'] = mysqli_real_escape_string($this->model->connect, $_POST['catname']);
                 $this->data['parent'] = $_POST['category'];
                 if ($this->model->editCat($this->data, $id) == true) {
                     $this->view->redirect('listcategory');
                 } else {
                     $this->view->msg = "Edit category faild";
                     $this->view->renderAdmin('category/editcategory');
                 }
             }
         } else {
             $this->view->renderAdmin("category/editcategory");
         }
     } else {
         $this->view->render("user/index");
     }
 }
 public function index()
 {
     $this->view->title = "Dashboard";
     if (Authorization::Authorize('Admin')) {
         $this->view->title = "Dashboard";
         $this->view->cat = $this->model->getCat();
         $this->view->post = $this->model->getPost();
         $this->view->comment = $this->model->getComment();
         $this->view->user = $this->model->getUser();
         $this->view->page = $this->model->getPage();
         $this->view->renderAdmin("dashboard/index");
     } else {
         $this->view->render("user/index");
     }
 }
function Authorize($request)
{
    $A = new Authorization();
    return $A->Authorize($request);
}
示例#4
0
 public function edit($id)
 {
     if (Authorization::Authorize('Admin')) {
         $this->view->title = "Edit Post";
         $this->view->cat = $this->category->getCategory();
         $this->view->news = $this->model->getPostById($id);
         if (isset($_POST['submit'])) {
             ///////////////////////////////////////
             //VALIDATE FORM
             //////////////////////////////////////
             $error = NULL;
             $data = array();
             if (isset($_POST['title'])) {
                 $data['title'] = $this->model->escape($_POST['title']);
             } else {
                 $error[] = 'title';
             }
             if (isset($_POST['category']) && filter_var($_POST['category'], FILTER_VALIDATE_INT, array('min_range' => 1))) {
                 $data['category'] = $_POST['category'];
             } else {
                 $error[] = 'category';
             }
             ///////////////////////////////////////////////
             //VALIDATE IMAGE
             ///////////////////////////////////////////////
             if (isset($_FILES['image'])) {
                 $allow = array('image/jpg', 'image/jpeg', 'image/png', 'image/gif');
                 if (in_array(strtolower($_FILES['image']['type']), $allow)) {
                     $tmp = explode('.', $_FILES['image']['name']);
                     $ext = end($tmp);
                     $reName = uniqid(rand(), true) . '.' . $ext;
                     if (!move_uploaded_file($_FILES['image']['tmp_name'], "public/public/upload/images/" . $reName)) {
                         $this->view->error['image'] = "Vui long nhap Image";
                     } else {
                         $data['image'] = SITE_PATH . "public/public/upload/images/" . $reName;
                     }
                 } else {
                     $this->view->error['image2'] = "Ko dung dinh dang";
                 }
             }
             ///////////////////////////////////////////////////////
             //END VALIDATE
             //////////////////////////////////////////////////////
             if (isset($_POST['content'])) {
                 $data['content'] = Functions::the_content($_POST['content']);
             } else {
                 $error[] = 'content';
             }
             if (isset($_POST['status'])) {
                 $data['status'] = $_POST['status'];
             } else {
                 $error[] = 'status';
             }
             if (empty($error)) {
                 $this->model->editById($data, $id);
                 $this->view->redirect('listpost');
             } else {
                 $this->view->renderAdmin('news/edit');
             }
         } else {
             $this->view->renderAdmin('news/edit');
         }
     } else {
         $this->view->render("user/index");
     }
 }