public function adggd()
 {
     $categoriesObj = new categories_model();
     $this->data['categories'] = $categoriesObj->get();
     if ($this->input->post()) {
         $insert_data['name'] = $this->input->post('name');
         $insert_data['description'] = $this->input->post('description');
         $insert_data['category'] = $this->input->post('category');
         $insert_data['price'] = $this->input->post('price');
         $insert_data['promotion'] = $this->input->post('promotion');
         $insert_data['promotion_price'] = $this->input->post('promotion_price');
         $insert_data['image'] = $this->input->post('image');
         $this->form_validation->set_rules('name', 'Product Name', 'required');
         $this->form_validation->set_rules('category', 'Category', 'required');
         $this->form_validation->set_rules('price', 'Price', 'required|decimal');
         $this->form_validation->set_rules('promotion[]', 'Promotion', 'required|decimal');
         $this->form_validation->set_rules('promotion_price', 'Promotion Price', 'decimal');
         //$this->form_validation->set_rules('image', 'Image', 'required');
         if ($this->form_validation->run() == FALSE) {
             $this->data['form'] = $insert_data;
             $this->data['errors'] = '';
             $this->load->view('admin/add-product', $this->data);
         } else {
             $categoriesObj = new categories_model();
             $category_id = $categoriesObj->get_id('name', $insert_data['category']);
             $productsObj = new products_model();
             $productsObj->name = $insert_data['name'];
             $productsObj->description = $insert_data['description'];
             $productsObj->price = $insert_data['price'];
             $productsObj->category = $category_id;
             $productsObj->image = 'defaults.jpg';
             $productsObj->status = 0;
             $productsObj->promotion = $insert_data['promotion'][0] == 'yes' ? 1 : 0;
             $productsObj->promotion_price = $insert_data['promotion_price'];
             $productsObj->insert();
             if (!$productsObj->id) {
                 echo "Fail";
             } else {
                 $this->data['form'] = $productsObj->get();
                 // File Uploading
                 $config['upload_path'] = './assests/products/';
                 $config['allowed_types'] = 'gif|jpg|png';
                 $config['max_size'] = '100';
                 $config['max_width'] = '1024';
                 $config['max_height'] = '768';
                 $config['file_name'] = 'products_' . $productsObj->id;
                 $this->load->library('upload', $config);
                 if (!$this->upload->do_upload('image')) {
                     $this->session->set_flashdata('error', $this->upload->display_errors());
                     redirect('admin/products/edit/' . $productsObj->id, 'refresh');
                 } else {
                     $data = array('upload_data' => $this->upload->data());
                     $productsObj->image = $data['upload_data']['file_name'];
                     $productsObj->update();
                     redirect('admin/products', 'refresh');
                 }
             }
         }
     } else {
         $this->data['errors'] = '';
         $this->load->view('admin/add-product', $this->data);
     }
 }