Example #1
0
 public function action_create()
 {
     if (Auth::is_admin_signed_in() === true) {
         $view = View::factory('acp/categories/create');
         $categories = new Model_Category();
         if ($this->request->method() === Request::POST) {
             $name = $this->request->post('name');
             $slug = $this->request->post('slug');
             $token = $this->request->param('id');
             if (!Security::check($token)) {
                 $this->request->redirect('acp/categories/create');
             }
             if (empty($slug)) {
                 $slug = URL::title($name, '_');
             }
             if (empty($name) && empty($slug)) {
                 $this->request->redirect('acp/categories/create');
             }
             $categories = new Model_Category();
             $create_category = $categories->create_category($name, $slug);
             if (!$create_category) {
                 $this->request->redirect('acp/categories/create');
             }
             $this->request->redirect('acp/categories');
         }
         $this->template->content = $view->render();
     } else {
         $this->request->redirect('acp');
     }
 }
Example #2
0
 public function action_index()
 {
     if (Auth::is_admin_signed_in() == false) {
         $this->template->content = View::factory('acp/login');
     } else {
         $this->template->content = View::factory('acp/home');
     }
 }
Example #3
0
 public function action_item()
 {
     if (Auth::is_admin_signed_in() === true) {
         $id = $this->request->param('id');
         if (empty($id)) {
             throw new Exception('ID Must Be Set!');
         }
         $view = View::factory('acp/products/info');
         $products = new Model_Product();
         $get_product_by_id = $products->get_product_by_id($id);
         $view->products = $get_product_by_id;
         if ($this->request->method() === Request::POST) {
             $name = strip_tags($this->request->post('name'));
             $is_discount = $this->request->post('is_discount');
             $discount = $this->request->post('discount');
             $description = $this->request->post('description');
             $price = $this->request->post('price') * 100;
             $img_url = $this->request->post('img_url');
             $count = $this->request->post('count');
             $token = $this->request->param('id');
             if (Security::check($token)) {
                 throw new Exception("Token is not valid!");
             }
             if (empty($is_discount) && empty($discount)) {
                 $is_discount = 0;
                 $discount = 0;
             } else {
                 $is_discount = 1;
             }
             if (empty($name) && empty($description) && empty($price)) {
                 throw new Exception("Please fill all fields!");
             }
             $products = new Model_Product();
             $data = array('is_discount' => $is_discount, 'discount' => $discount, 'name' => $name, 'description' => $description, 'price' => $price, 'image_url' => $img_url, 'count' => $count);
             $update_product_info = $products->update_product_info($data, $id);
             if (!$update_product_info) {
                 throw new Exception("Error with database");
             }
             $this->request->redirect('acp/products');
         }
         $this->template->content = $view->render();
     } else {
         $this->request->redirect('acp');
     }
 }