Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/kanvakanva.com/public_html/application/controllers/admin/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Products extends Admin_Controller { //this property is used for validating existing category title on call back edit category private $product_current_id; private $image1_filename = NULL; private $image2_filename = NULL; private $image3_filename = NULL; private $image4_filename = NULL; private $image5_filename = NULL; function __construct() { parent::__construct(); $this->load->model('product_m'); $this->load->model('category_m'); $this->load->model('brand_m'); $this->load->model('size_m'); } //this is to list all products public function index() { //pagination in action. 500 results per page $this->load->library('pagination'); $config['base_url'] = base_url() . 'admin/products/index'; $config['per_page'] = 500; $config["uri_segment"] = 4; $config['num_tag_open'] = '<span style="padding-left:10px; padding-right:10px">'; $config['num_tag_close'] = '</span>'; //fetch all products $config['total_rows'] = $this->product_m->record_count(); $this->pagination->initialize($config); $this->data['products'] = $this->product_m->get_all_products($config["per_page"], $this->uri->segment(4)); //load view $this->data['subview'] = 'admin/products/index'; $this->load->view('admin/templates/header', $this->data); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer', $this->data); } //to ADD a new product public function add() { $this->data['products'] = $this->product_m->get_new(); $this->data['parent_categories'] = $this->category_m->get_parent_categories(); $this->data['brands'] = $this->brand_m->get_brands(); $this->data['sizes'] = $this->size_m->get_product_size(); //get size $this->db->select('*')->from('product_size')->order_by('priority', 'ASC'); $this->data['stocks'] = $this->db->get()->result(); //validation in action //validation check in action $config = $this->product_m->rules; $this->form_validation->set_rules($config); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); if($this->form_validation->run() == TRUE) { //Get product image dimensions from configuration table $this->db->select('product_image_width, product_image_height, product_image_large_width, product_image_large_height, product_image_small_width, product_image_small_height, product_image_thumbnail_width, product_image_thumbnail_height')->from('configuration')->where('id_configuration', 1); $image_dimension = $this->db->get()->row(); //check & processing IMAGE 1 if ($_FILES['image1']['size'] !== 0) { $config['upload_path'] = './uploads/product/'; $config['allowed_types'] = 'jpg'; $config['max_size'] = '300'; $config['max_width'] = $image_dimension->product_image_width; $config['max_height'] = $image_dimension->product_image_height; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('image1')) { $this->session->set_flashdata('image1-error', '<br> <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); redirect('admin/products/add'); } else { $image1 = $this->upload->data(); $this->image1_filename = $image1['file_name']; //image resizing (LARGE IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image1['file_name']; $config['new_image'] = './uploads/product/large/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_large_width; $config['height'] = $image_dimension->product_image_large_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (SMALL IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image1['file_name']; $config['new_image'] = './uploads/product/small/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_small_width; $config['height'] = $image_dimension->product_image_small_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (THUMBNAIL) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image1['file_name']; $config['new_image'] = './uploads/product/thumbnail/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_thumbnail_width; $config['height'] = $image_dimension->product_image_thumbnail_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); } } //check & processing IMAGE 2 if ($_FILES['image2']['size'] !== 0) { $config['upload_path'] = './uploads/product/'; $config['allowed_types'] = 'jpg'; $config['max_size'] = '300'; $config['max_width'] = $image_dimension->product_image_width; $config['max_height'] = $image_dimension->product_image_height; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('image2')) { $this->session->set_flashdata('image2-error', '<br> <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); redirect('admin/products/add'); } else { $image2 = $this->upload->data(); $this->image2_filename = $image2['file_name']; //image resizing (LARGE IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image2['file_name']; $config['new_image'] = './uploads/product/large/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_large_width; $config['height'] = $image_dimension->product_image_large_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (SMALL IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image2['file_name']; $config['new_image'] = './uploads/product/small/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_small_width; $config['height'] = $image_dimension->product_image_small_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (THUMBNAIL) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image2['file_name']; $config['new_image'] = './uploads/product/thumbnail/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_thumbnail_width; $config['height'] = $image_dimension->product_image_thumbnail_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); } } //check & processing IMAGE 3 if ($_FILES['image3']['size'] !== 0) { $config['upload_path'] = './uploads/product/'; $config['allowed_types'] = 'jpg'; $config['max_size'] = '300'; $config['max_width'] = $image_dimension->product_image_width; $config['max_height'] = $image_dimension->product_image_height; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('image3')) { $this->session->set_flashdata('image3-error', '<br> <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); redirect('admin/products/add'); } else { $image3 = $this->upload->data(); $this->image3_filename = $image3['file_name']; //image resizing (LARGE IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image3['file_name']; $config['new_image'] = './uploads/product/large/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_large_width; $config['height'] = $image_dimension->product_image_large_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (SMALL IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image3['file_name']; $config['new_image'] = './uploads/product/small/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_small_width; $config['height'] = $image_dimension->product_image_small_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (THUMBNAIL) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image3['file_name']; $config['new_image'] = './uploads/product/thumbnail/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_thumbnail_width; $config['height'] = $image_dimension->product_image_thumbnail_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); } } //check & processing IMAGE 4 if ($_FILES['image4']['size'] !== 0) { $config['upload_path'] = './uploads/product/'; $config['allowed_types'] = 'jpg'; $config['max_size'] = '300'; $config['max_width'] = $image_dimension->product_image_width; $config['max_height'] = $image_dimension->product_image_height; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('image4')) { $this->session->set_flashdata('image4-error', '<br> <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); redirect('admin/products/add'); } else { $image4 = $this->upload->data(); $this->image4_filename = $image4['file_name']; //image resizing (LARGE IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image4['file_name']; $config['new_image'] = './uploads/product/large/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_large_width; $config['height'] = $image_dimension->product_image_large_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (SMALL IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image4['file_name']; $config['new_image'] = './uploads/product/small/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_small_width; $config['height'] = $image_dimension->product_image_small_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (THUMBNAIL) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image4['file_name']; $config['new_image'] = './uploads/product/thumbnail/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_thumbnail_width; $config['height'] = $image_dimension->product_image_thumbnail_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); } } //check & processing IMAGE 5 if ($_FILES['image5']['size'] !== 0) { $config['upload_path'] = './uploads/product/'; $config['allowed_types'] = 'jpg'; $config['max_size'] = '300'; $config['max_width'] = $image_dimension->product_image_width; $config['max_height'] = $image_dimension->product_image_height; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('image5')) { $this->session->set_flashdata('image5-error', '<br> <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); redirect('admin/products/add'); } else { $image5 = $this->upload->data(); $this->image5_filename = $image5['file_name']; //image resizing (LARGE IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image5['file_name']; $config['new_image'] = './uploads/product/large/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_large_width; $config['height'] = $image_dimension->product_image_large_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (SMALL IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image5['file_name']; $config['new_image'] = './uploads/product/small/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_small_width; $config['height'] = $image_dimension->product_image_small_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (THUMBNAIL) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image5['file_name']; $config['new_image'] = './uploads/product/thumbnail/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_thumbnail_width; $config['height'] = $image_dimension->product_image_thumbnail_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); } } $data = $this->table_data_processing( $this->input->post('product_name'), $this->input->post('brand_id'), $this->input->post('description'), $this->input->post('long_description'), $this->input->post('additional_information'), $this->input->post('price'), $this->input->post('discount_price'), $this->input->post('weight'), $this->input->post('product_status'), $this->input->post('preorder'), $this->input->post('priority'), $this->input->post('new_arrival'), $this->image1_filename, $this->image2_filename, $this->image3_filename, $this->image4_filename, $this->image5_filename, $this->input->post('meta_description'), $this->input->post('meta_keywords'), $this->input->post('themes'), $this->input->post('editor_notes'), $this->input->post('dimensions'), $this->input->post('material'), $this->input->post('good_to_know'), $this->input->post('new_sale'), $this->input->post('in_promo1'), $this->input->post('in_promo2') ); $product_id = $this->product_m->add_product($data); //get category_id from view, then insert together with product_id to category_product table $categories_id = $this->input->post('category_id'); //check id there is content inside category array $categories_id_count = count($categories_id); if ($categories_id_count > 0) { foreach ($categories_id as $category_id) { $data = array( 'id_product' => $product_id, 'id_category' => $category_id, ); $this->db->insert('category_product', $data); } } else { $data = array( 'id_product' => $product_id, 'id_category' => NULL, ); $this->db->insert('category_product', $data); } //INSERT STOCK //get the size table $this->db->select('*')->from('product_size')->order_by('priority', 'ASC'); $product_size = $this->db->get()->result(); foreach ($product_size as $item) { $data = array( 'product_id' => $product_id, 'size_id' => $item->id_product_size, 'stock' => $this->input->post('size' . $item->id_product_size), 'price' => $this->input->post('price' . $item->id_product_size), 'discounted_price' => $this->input->post('discounted_price' . $item->id_product_size), 'weight' => $this->input->post('weight' . $item->id_product_size), ); $this->db->insert('stocks', $data); } $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Product Added Successful</p>'); redirect('admin/products'); } $this->data['subview'] = 'admin/products/edit'; $this->load->view('admin/templates/header', $this->data); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer', $this->data); } //to EDIT product in admin public function edit($id) { $this->data['products'] = $this->product_m->get($id); $this->data['parent_categories'] = $this->category_m->get_parent_categories(); //get all chosen (active) categories $this->db->select('*')->from('category_product')->where('id_product', $id); $this->data['chosen_categories'] = $this->db->get()->result(); $this->data['brands'] = $this->brand_m->get_brands(); $this->product_current_id = (int) $this->data['products']->id_products; //get size and stocks $this->db->select('*'); $this->db->from('stocks'); $this->db->join('product_size', 'product_size.id_product_size = stocks.size_id'); $this->db->where('product_id', (int) $id); $this->db->order_by('product_size.priority', 'ASC'); $query = $this->db->get(); $this->data['stocks'] = $query->result(); //get brand id $this->db->select('brand_id')->from('products')->where('id_products', (int) $id); $products = $this->db->get()->row(); $this->data['brand_id'] = $products->brand_id; //validation check in action $config = $this->product_m->rules; $this->form_validation->set_rules($config); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); if($this->form_validation->run() == TRUE) { //Get product image dimensions from configuration table $this->db->select('product_image_width, product_image_height, product_image_large_width, product_image_large_height, product_image_small_width, product_image_small_height, product_image_thumbnail_width, product_image_thumbnail_height')->from('configuration')->where('id_configuration', 1); $image_dimension = $this->db->get()->row(); //check & processing IMAGE 1 if ($_FILES['image1']['size'] !== 0) { $config['upload_path'] = './uploads/product/'; $config['allowed_types'] = 'jpg'; $config['max_size'] = '300'; $config['max_width'] = $image_dimension->product_image_width; $config['max_height'] = $image_dimension->product_image_height; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('image1')) { $this->session->set_flashdata('image1-error', '<br> <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); redirect('admin/products/edit/'.$id); } else { $image1 = $this->upload->data(); $this->image1_filename = $image1['file_name']; //image resizing (LARGE IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image1['file_name']; $config['new_image'] = './uploads/product/large/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_large_width; $config['height'] = $image_dimension->product_image_large_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (SMALL IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image1['file_name']; $config['new_image'] = './uploads/product/small/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_small_width; $config['height'] = $image_dimension->product_image_small_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (THUMBNAIL) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image1['file_name']; $config['new_image'] = './uploads/product/thumbnail/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_thumbnail_width; $config['height'] = $image_dimension->product_image_thumbnail_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); } } //check & processing IMAGE 2 if ($_FILES['image2']['size'] !== 0) { $config['upload_path'] = './uploads/product/'; $config['allowed_types'] = 'jpg'; $config['max_size'] = '300'; $config['max_width'] = $image_dimension->product_image_width; $config['max_height'] = $image_dimension->product_image_height; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('image2')) { $this->session->set_flashdata('image2-error', '<br> <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); redirect('admin/products/edit/'.$id); } else { $image2 = $this->upload->data(); $this->image2_filename = $image2['file_name']; //image resizing (LARGE IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image2['file_name']; $config['new_image'] = './uploads/product/large/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_large_width; $config['height'] = $image_dimension->product_image_large_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (SMALL IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image2['file_name']; $config['new_image'] = './uploads/product/small/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_small_width; $config['height'] = $image_dimension->product_image_small_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (THUMBNAIL) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image2['file_name']; $config['new_image'] = './uploads/product/thumbnail/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_thumbnail_width; $config['height'] = $image_dimension->product_image_thumbnail_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); } } //check & processing IMAGE 3 if ($_FILES['image3']['size'] !== 0) { $config['upload_path'] = './uploads/product/'; $config['allowed_types'] = 'jpg'; $config['max_size'] = '300'; $config['max_width'] = $image_dimension->product_image_width; $config['max_height'] = $image_dimension->product_image_height; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('image3')) { $this->session->set_flashdata('image3-error', '<br> <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); redirect('admin/products/edit/'.$id); } else { $image3 = $this->upload->data(); $this->image3_filename = $image3['file_name']; //image resizing (LARGE IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image3['file_name']; $config['new_image'] = './uploads/product/large/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_large_width; $config['height'] = $image_dimension->product_image_large_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (SMALL IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image3['file_name']; $config['new_image'] = './uploads/product/small/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_small_width; $config['height'] = $image_dimension->product_image_small_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (THUMBNAIL) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image3['file_name']; $config['new_image'] = './uploads/product/thumbnail/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_thumbnail_width; $config['height'] = $image_dimension->product_image_thumbnail_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); } } //check & processing IMAGE 4 if ($_FILES['image4']['size'] !== 0) { $config['upload_path'] = './uploads/product/'; $config['allowed_types'] = 'jpg'; $config['max_size'] = '300'; $config['max_width'] = $image_dimension->product_image_width; $config['max_height'] = $image_dimension->product_image_height; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('image4')) { $this->session->set_flashdata('image4-error', '<br> <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); redirect('admin/products/edit/'.$id); } else { $image4 = $this->upload->data(); $this->image4_filename = $image4['file_name']; //image resizing (LARGE IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image4['file_name']; $config['new_image'] = './uploads/product/large/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_large_width; $config['height'] = $image_dimension->product_image_large_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (SMALL IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image4['file_name']; $config['new_image'] = './uploads/product/small/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_small_width; $config['height'] = $image_dimension->product_image_small_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (THUMBNAIL) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image4['file_name']; $config['new_image'] = './uploads/product/thumbnail/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_thumbnail_width; $config['height'] = $image_dimension->product_image_thumbnail_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); } } //check & processing IMAGE 5 if ($_FILES['image5']['size'] !== 0) { $config['upload_path'] = './uploads/product/'; $config['allowed_types'] = 'jpg'; $config['max_size'] = '300'; $config['max_width'] = $image_dimension->product_image_width; $config['max_height'] = $image_dimension->product_image_height; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('image5')) { $this->session->set_flashdata('image5-error', '<br> <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); redirect('admin/products/edit/'.$id); } else { $image5 = $this->upload->data(); $this->image5_filename = $image5['file_name']; //image resizing (LARGE IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image5['file_name']; $config['new_image'] = './uploads/product/large/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_large_width; $config['height'] = $image_dimension->product_image_large_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (SMALL IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image5['file_name']; $config['new_image'] = './uploads/product/small/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_small_width; $config['height'] = $image_dimension->product_image_small_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); //image resizing (THUMBNAIL) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/product/' . $image5['file_name']; $config['new_image'] = './uploads/product/thumbnail/'; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $image_dimension->product_image_thumbnail_width; $config['height'] = $image_dimension->product_image_thumbnail_height; $this->image_lib->initialize($config); //firstly autoload image_lib, then initialize it. Dont repeatly load it. $this->image_lib->resize(); } } $data = $this->table_data_processing( $this->input->post('product_name'), $this->input->post('brand_id'), $this->input->post('description'), $this->input->post('long_description'), $this->input->post('additional_information'), $this->input->post('price'), $this->input->post('discount_price'), $this->input->post('weight'), $this->input->post('product_status'), $this->input->post('preorder'), $this->input->post('priority'), $this->input->post('new_arrival'), $this->image1_filename, $this->image2_filename, $this->image3_filename, $this->image4_filename, $this->image5_filename, $this->input->post('meta_description'), $this->input->post('meta_keywords'), $this->input->post('themes'), $this->input->post('editor_notes'), $this->input->post('dimensions'), $this->input->post('material'), $this->input->post('good_to_know'), $this->input->post('new_sale'), $this->input->post('in_promo1'), $this->input->post('in_promo2') ); $this->product_m->edit_product($id, $data); //get category_id from view, then insert together with product_id to category_product table $categories_id = $this->input->post('category_id'); //check id there is content inside category array $categories_id_count = count($categories_id); if ($categories_id_count > 0) { //firstly, we delete all existing category records inside category_product table $this->db->where('id_product', $id); $this->db->delete('category_product'); //secondly, we insert new category_id foreach ($categories_id as $category_id) { $data = array( 'id_product' => $id, 'id_category' => $category_id, ); $this->db->insert('category_product', $data); } } else { //no category is checked at edit page //firstly, we delete all existing category records inside category_product table $this->db->where('id_product', $id); $this->db->delete('category_product'); //secondly, we insert new category_id of NULL $data = array( 'id_product' => $id, 'id_category' => NULL, ); $this->db->insert('category_product', $data); } //UPDATE STOCK //get the size table $this->db->select('*')->from('product_size')->order_by('priority', 'ASC'); $product_size = $this->db->get()->result(); foreach ($product_size as $item) { $data = array( 'stock' => (int) $this->input->post('size' . $item->id_product_size), 'price' => $this->input->post('price' . $item->id_product_size), 'discounted_price' => $this->input->post('discounted_price' . $item->id_product_size), 'weight' => $this->input->post('weight' . $item->id_product_size), ); $this->db->where('product_id', (int) $id); $this->db->where('size_id', (int) $item->id_product_size); $this->db->update('stocks', $data); } $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Product Edit Successful</p>'); redirect('admin/products'); } $this->data['subview'] = 'admin/products/edit'; $this->load->view('admin/templates/header', $this->data); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer', $this->data); } //to delete a product public function delete($id) { //check if id exist. If not exist, show 404. $count = $this->product_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } //delete image from server for ($i = 1; $i <= 5; $i++) { //check if there is an existing image on product table $this->db->select("image$i")->from('products')->where('id_products', (int) $id); $image = $this->db->get()->row_array(); //use array insted of object if ($image["image$i"] != '' || $image["image$i"] != NULL) { //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/product/'. $image["image$i"]); unlink(FCPATH .'/uploads/product/large/'. $image["image$i"]); unlink(FCPATH .'/uploads/product/small/'. $image["image$i"]); unlink(FCPATH .'/uploads/product/thumbnail/'. $image["image$i"]); } } $this->product_m->delete($id); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Product Deleted Successful</p>'); redirect('admin/products'); } //callback function validation add new product public function _cek_existing_product_title($str) { $num_rows = $this->product_m->cek_existing_product_title($str, $this->product_current_id); if ($num_rows != 0 ) { $this->form_validation->set_message('_cek_existing_product_title', 'Product name already exist !'); return FALSE; } else { return TRUE; } } private function table_data_processing($product_name, $brand_id, $description, $long_description, $additional_information, $price, $discount_price, $weight, $product_status, $preorder, $priority, $new_arrival, $image1_filename, $image2_filename, $image3_filename, $image4_filename, $image5_filename, $meta_description, $meta_keywords, $themes, $editor_notes, $dimensions, $material, $good_to_know, $new_sale, $in_promo1, $in_promo2) { $data = array( 'title' => $this->security->xss_clean($product_name), 'alias' => url_title($this->security->xss_clean($product_name)), 'brand_id' => (int) $brand_id, 'description' => $description, 'long_description' => $long_description, 'additional_information' => $additional_information, 'price' => (int) $price, 'discount_price' => (int) $discount_price, 'weight' => (int) $weight, 'product_status' => $product_status, 'preorder' => $preorder, 'priority' => $priority, 'new_arrival' => $new_arrival, 'meta_description' => $meta_description, 'meta_keywords' => $meta_keywords, 'theme_id' => $themes, 'editor_notes' => $editor_notes, 'dimensions' => $dimensions, 'material' => $material, 'good_to_know' => $good_to_know, 'is_voucher' => $this->input->post('is_voucher'), 'new_sale' => $new_sale, 'in_promo1' => $in_promo1, 'in_promo2' => $in_promo2 ); //image upload if (isset($image1_filename)) { $data['image1'] = $image1_filename; } if (isset($image2_filename)) { $data['image2'] = $image2_filename; } if (isset($image3_filename)) { $data['image3'] = $image3_filename; } if (isset($image4_filename)) { $data['image4'] = $image4_filename; } if (isset($image5_filename)) { $data['image5'] = $image5_filename; } return $data; } //To delete product image file from server, and from database public function delete_image($id = NULL, $image_name) { $count = $this->product_m->count_exist($id); if ($id == NULL || $image_name == NULL || $count == 0) { redirect('admin/brands'); } //get image file name for deletion $this->db->select($image_name)->from('products')->where('id_products', (int) $id); $image = $this->db->get()->row(); switch ($image_name) { case 'image1': //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/product/'. $image->image1); unlink(FCPATH .'/uploads/product/large/'. $image->image1); unlink(FCPATH .'/uploads/product/small/'. $image->image1); unlink(FCPATH .'/uploads/product/thumbnail/'. $image->image1); //Delete image field from database $data = array( 'image1' => NULL, ); break; case 'image2': //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/product/'. $image->image2); unlink(FCPATH .'/uploads/product/large/'. $image->image2); unlink(FCPATH .'/uploads/product/small/'. $image->image2); unlink(FCPATH .'/uploads/product/thumbnail/'. $image->image2); //Delete image field from database $data = array( 'image2' => NULL, ); break; case 'image3': //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/product/'. $image->image3); unlink(FCPATH .'/uploads/product/large/'. $image->image3); unlink(FCPATH .'/uploads/product/small/'. $image->image3); unlink(FCPATH .'/uploads/product/thumbnail/'. $image->image3); //Delete image field from database $data = array( 'image3' => NULL, ); break; case 'image4': //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/product/'. $image->image4); unlink(FCPATH .'/uploads/product/large/'. $image->image4); unlink(FCPATH .'/uploads/product/small/'. $image->image4); unlink(FCPATH .'/uploads/product/thumbnail/'. $image->image4); //Delete image field from database $data = array( 'image4' => NULL, ); break; case 'image5': //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/product/'. $image->image5); unlink(FCPATH .'/uploads/product/large/'. $image->image5); unlink(FCPATH .'/uploads/product/small/'. $image->image5); unlink(FCPATH .'/uploads/product/thumbnail/'. $image->image5); //Delete image field from database $data = array( 'image5' => NULL, ); break; } $this->db->where('id_products', (int) $id); $this->db->update('products', $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Image Delete Successful</p>'); redirect('admin/products/edit/' . $id); } public function search_product() { if(!isset($_POST['search_product'])) { show_404(); } //get product name from form $this->data['product_name'] = $this->input->post('product', TRUE); //get all products which only consist this word $this->db->select('*')->from('products')->join('brands', 'brands.id_brands = products.brand_id')->like('title', $this->data['product_name']); $this->db->order_by('title', 'ASC'); $this->data['products'] = $this->db->get()->result(); //load view $this->data['subview'] = 'admin/products/index'; $this->load->view('admin/templates/header', $this->data); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer', $this->data); } public function search_brand() { if(!isset($_POST['search_brand'])) { show_404(); } //get product name from form $this->data['brand_id'] = $this->input->post('brand', TRUE); if ($this->data['brand_id'] != '') { //get all brands which only consist this brand_id $this->db->select('*')->from('products')->where('brand_id', (int) $this->data['brand_id']); $this->db->order_by('title', 'ASC'); $this->data['products'] = $this->db->get()->result(); } else { //get all brands $this->db->select('*')->from('products'); $this->db->order_by('title', 'ASC'); $this->data['products'] = $this->db->get()->result(); } //load view $this->data['subview'] = 'admin/products/index'; $this->load->view('admin/templates/header', $this->data); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer', $this->data); } public function search_category() { if(!isset($_POST['search_category'])) { show_404(); } //get product name from form $this->data['category_id'] = $this->input->post('category', TRUE); if ($this->data['category_id'] == '') { $this->db->select('*')->from('products')->order_by('title', 'ASC'); $this->data['products'] = $this->db->get()->result(); //load view $this->data['subview'] = 'admin/products/index'; $this->load->view('admin/templates/header', $this->data); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer', $this->data); } else { $this->db->select('*'); $this->db->from('products'); $this->db->join('category_product', 'category_product.id_product = products.id_products'); $this->db->where('category_product.id_category', (int) $this->data['category_id']); $this->data['products'] = $this->db->get()->result(); //load view $this->data['subview'] = 'admin/products/index'; $this->load->view('admin/templates/header', $this->data); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer', $this->data); } } public function edit_stock($id_stocks) { $data = array( 'stock' => (int) $this->input->post('stock'), ); $this->db->where('id_stocks', (int) $id_stocks); $this->db->update('stocks', $data); redirect('admin/products/index', 'refresh'); } function update_data(){ $id_products = $this->input->post("id_products",true); $kolom = $this->input->post("kolom",true); $value = $this->input->post("value",true); $data = array( $kolom => $value, ); $this->db->where('id_products', (int) $id_products); $this->db->update('products', $data); echo '1'; } }