public function add()
 {
     $this->data['redirect_url'] = $_SERVER["HTTP_REFERER"];
     $this->data['form_data']['upload_data'] = $this->session->flashdata('upload_data');
     $this->data['form_errors'] = $this->session->flashdata('form_errors');
     $categoriesObj = new categories_model();
     $this->data['categories'] = $categoriesObj->get();
     if ($this->input->post()) {
         $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');
         if ($this->form_validation->run() == FALSE) {
             $this->data['form_data'] = $this->input->post();
             // $this->data['form_data']['upload_data']['file_name'] = $this->input->post('pro_picture_file_name');
             // $this->data['form_data']['upload_data']['raw_name'] = $this->input->post('pro_picture_raw_name');
             // $this->data['form_data']['upload_data']['file_ext'] = $this->input->post('pro_picture_ext');
             $this->data['form_errors'] = validation_errors();
         } else {
             $productObj = new products_model();
             $productObj->data = new stdClass();
             $productObj->data->name = $this->input->post('name');
             $productObj->data->url = strtolower(url_title($this->input->post('name')));
             $productObj->data->description = $this->input->post('description');
             $productObj->data->category = $this->input->post('category');
             $productObj->data->price = $this->input->post('price');
             $productObj->data->promotion = $this->input->post('promotion');
             $productObj->data->promotion_price = $this->input->post('promotion_price');
             // $profileObj->pro_cat_id = $this->input->post('pro_cat_id');
             // $profileObj->pro_name = $this->input->post('pro_name');
             // $profileObj->first_name = $this->input->post('first_name');
             // $profileObj->last_name = $this->input->post('last_name');
             // $profileObj->pro_address1 = $this->input->post('pro_address1');
             // $profileObj->pro_address2 = $this->input->post('pro_address2');
             // $profileObj->pro_district = $this->input->post('pro_district');
             // $profileObj->pro_telephone = $this->input->post('pro_telephone');
             // $profileObj->pro_email = $this->input->post('pro_email');
             // $profileObj->pro_web = $this->input->post('pro_web');
             // $profileObj->pro_description = $this->input->post('pro_description');
             // $profileObj->pro_latitude  = $this->input->post('pro_latitude');
             // $profileObj->pro_longitude = $this->input->post('pro_longitude');
             // $profileObj->pro_status = ($this->input->post('pro_status') == 'active') ? 1 : 0;
             // $profileObj->pro_createdate = date('Y-m-d H:i:s');
             if ($product_id = $productObj->save()) {
                 $productObj->id = $product_id;
                 $image_path = $this->assets_path . 'products/';
                 if (!file_exists($image_path)) {
                     mkdir($image_path, 0755, true);
                 }
                 $uploade_image = $this->input->post('image-data');
                 $uploade_image = base64_decode($uploade_image);
                 $uploade_image_file = $image_path . $productObj->data->url . '.png';
                 $success = file_put_contents($uploade_image_file, $uploade_image);
                 // $image_path = $this->assets_path . 'products/profile-' . $product_id;
                 // if(!file_exists($image_path)){
                 //     mkdir($image_path, 0755, true);
                 // }
                 // if ($this->input->post('pro_picture_file_name') && $this->input->post('pro_picture_ext')) {
                 //     $new_image_name = 'profile-' . $product_id . $this->input->post('pro_picture_ext');
                 //     $this->load->library('image_lib');
                 //     // -------------------------------------
                 //     $config1['image_library'] = 'gd2';
                 //     $config1['source_image'] = $this->assets_path ;
                 //     $config1['new_image'] = $image_path . '/' . $new_image_name;
                 //     $config1['width'] = 300;
                 //     $config1['height'] = 300;
                 //     $config1['maintain_ratio'] = TRUE;
                 //     // ---------------------------------------
                 //     $this->image_lib->initialize($config1);
                 //     $this->image_lib->resize();
                 //     $this->image_lib->clear();
                 //     // -------------------------------------
                 //     // -------------------------------------
                 //     $config2['image_library'] = 'gd2';
                 //     $config2['source_image'] = $config1['new_image'];
                 //     $config2['new_image'] = $image_path . '/profile-' ;
                 //     $config2['width'] = 10;
                 //     $config2['height'] = 10;
                 //     $config2['maintain_ratio'] = TRUE;
                 //     // ---------------------------------------
                 //     $this->image_lib->initialize($config2);
                 //     $this->image_lib->resize();
                 //     $this->image_lib->clear();
                 //     // -------------------------------------
                 //     if ($new_image_name) {
                 //         $profileObj->id = $pro_id;
                 //         $profileObj->pro_picture = $new_image_name;
                 //         $profileObj->update();
                 //     }
                 //}
                 // redirect(base_url('profiles/category/' . $category_id), 'refresh');
             }
         }
     }
     $this->data['form_header'] = 'Add New';
     $this->load->view('products/add-edit', $this->data);
 }