https://t.me/RX1948
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 :  /proc/self/root/var/www/blue-sky.co.id/public_html/application/controllers/admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/self/root/var/www/blue-sky.co.id/public_html/application/controllers/admin/Products.php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Products extends Admin_Controller {

    //this property is to mark whether we are uploading image in the index page
    private $imageupload_indexpage = FALSE;

	//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;
	private $image6_filename = NULL;
	private $image7_filename = NULL;
	private $image8_filename = NULL;
	private $image9_filename = NULL;
	private $image10_filename = NULL;
	private $image11_filename = NULL;
	private $image12_filename = NULL;
	private $image13_filename = NULL;
	private $image14_filename = NULL;
	private $image15_filename = NULL;
	private $image16_filename = NULL;
	private $image17_filename = NULL;
	private $image18_filename = NULL;
	private $image19_filename = NULL;
	private $image20_filename = NULL;
	private $image21_filename = NULL;
	private $image22_filename = NULL;
	private $image23_filename = NULL; 
	
	function __construct() { 

		parent::__construct();	

		//admin role module check
		$this->check_admin_role('produk'); //method from Admin_controller	
		
		$this->load->model('product_m');  
		$this->load->model('category_m'); 
		$this->load->model('configuration_m');
		$this->load->model('brand_m'); 
		$this->load->model('product_attributes_m');  
		$this->load->helper('form');
	}
		
	function index() { 

		/*----FILTER SEARCH PRODUCT--*/
		if(isset($_POST['search_product'])) { 

			//get product name from form
			$this->data['keyword'] = $this->security->xss_clean($this->input->post('product'));
			$this->data['products'] = $this->product_m->get_all_products_search_product($this->data['keyword']);  

		} elseif (isset($_POST['banner'])) {

            $this->imageupload_indexpage = TRUE;

            //get max image width and height from configuration table
            $this->db->select('*')->from('configuration')->where('id_configuration', 1);
            $image_dimension = $this->db->get()->row();

            //check & processing image banner upload files  
            if ($_FILES['userfile']['size'] !== 0) {  
            
                $config['upload_path'] = './uploads/blog/'; 
                $config['allowed_types'] = 'jpg|png|jpeg'; 
                $config['max_size'] = '2000';
                // $config['max_width'] = $image_dimension->image_banner_width;
                // $config['max_height'] = $image_dimension->image_banner_height;
                
                $this->load->library('upload', $config); 

                if ( ! $this->upload->do_upload()) {

                    // echo $this->upload->display_errors(); die();
                        
                    $this->session->set_flashdata('banner_msg', '<br>
                        <p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
                    $this->session->set_flashdata('banner', 'active');
                    redirect('admin/products/index');
                
                } else {
                    $image = $this->upload->data();
                    $image_filename = $image['file_name'];
                    // $this->resize_single_image($image_dimension->image_banner_width,$image_dimension->image_banner_height,'blog/',$image_filename);      
                } 
            }

            //image upload
	        if (isset($image_filename)) {
	            $data['produk_banner'] = $image_filename; 

	            $this->db->where('id_configuration', 1);
	            $this->db->update('configuration', $data); 

	            $this->session->set_flashdata('success_banner', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Edit Banner Berhasil</p>');
	        }  

	        $this->session->set_flashdata('banner', 'active');

	        //Add pagination
			$this->load->helper('pagination_helper'); 
			add_pagination(base_url() . 'admin/products/index', $this->product_m->record_count(), 100, 4);
			$this->data['products'] = $this->product_m->get_all_products(100,$this->uri->segment(4));  
			$this->data['use_pagination'] = 'yes'; 

		} else {
		
			//Add pagination
			$this->load->helper('pagination_helper'); 
			add_pagination(base_url() . 'admin/products/index', $this->product_m->record_count(), 100, 4);
			$this->data['products'] = $this->product_m->get_all_products(100,$this->uri->segment(4));  
			$this->data['use_pagination'] = 'yes'; 
		}

		$this->data['ide_produk'] = $this->db->select('produk_banner')->from('configuration')->get()->row();

		//get website product ordering
		$this->db->select('website_product_ordering')->from('configuration')->where('id_configuration', 1);
		$this->data['website_product_ordering'] = $this->db->get()->row()->website_product_ordering;

		//load view
		$this->data['subview'] = 'admin/products/index';
		$this->load->view('admin/templates/header', $this->data_header); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer'); 	 
    }

    //To delete blog landingpage banner image file from server, and from database
    public function delete_produk_banner() { 

        //get image file name for deletion
        $this->db->select('produk_banner')->from('configuration')->where('id_configuration', 1);
        $image = $this->db->get()->row()->produk_banner;

        //Delete the actual image file from server. FCPATH is codeigniter base path
        unlink(FCPATH .'/uploads/blog/'. $image);

        //Delete image field from database
        $data = array( 
            'produk_banner' => '',
        );

        $this->db->where('id_configuration', 1);
        $this->db->update('configuration', $data);  

        $this->session->set_flashdata('success_banner', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Hapus Banner Berhasil</p>');
        
        $this->session->set_flashdata('banner', 'active');
        redirect('admin/products/index'); 
    }

    function ajax_check_this_sku(){ 
    	$this_sku = $this->input->post('this_sku'); 

    	$query_check_sku = $this->db->select('sku')->from('product_details')->where('sku', $this_sku)->get();

    	$output_text = "";
    	if ($query_check_sku->num_rows()>0) {
    		$output_text = "SKU ".$this_sku." sudah ada.";
    		 
    	}
    	echo json_encode(array(
	    	"res"=>"sukses", 
	    	"output_text"=>$output_text, 
    	));
    }

    function refreshDisplayPriority(){
    	$this_data = $this->input->post('this_data');

    	foreach ($this_data as $key) {
    		$u_data = array(
    			'priority'=>$key['val'],
    		);
    		$this->db->update('products', $u_data, array('id_products' => $key['id']));
    	}

		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Produk Priority berhasil diubah</p>');

    	echo json_encode(array(
	    	"res"=>"sukses",
    		// "data"=>$this_data,
    	));
    }

    function refreshDisplayPriorityImages() {

    	$this_data = $this->input->post('this_data');

    	foreach ($this_data as $key) {
    		$u_data = array(
    			'priority'=>$key['val'],
    		);
    		$this->db->update('product_images', $u_data, array('id' => $key['id']));
    	}

		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Foto Produk Prioritas berhasil diubah</p>');

    	echo json_encode(array(
	    	"res"=>"sukses",
    		// "data"=>$this_data,
    	));
    }

    function refreshDisplayPriorityImagess() {

    	$this_data = $this->input->post('this_data');

    	foreach ($this_data as $key) {
    		$u_data = array(
    			'priority'=>$key['val'],
    		);
    		$this->db->update('testi_images', $u_data, array('id' => $key['id']));
    	}

		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Foto Produk Prioritas berhasil diubah</p>');

    	echo json_encode(array(
	    	"res"=>"sukses",
    		// "data"=>$this_data,
    	));
    }

    function changeStatusAct($trend){
    	$this_id = $this->input->post('this_id');
    	$toStat = $this->input->post('toStat');

    	$codeStat = null;
    	
    	if($trend!=1) {
	    	if ($toStat == "Ya") {
	    		$codeStat = '1';
	    	}else{
	    		$codeStat = '0'; 
	    	}

	    	$data = array(
	    		"product_status"=>$codeStat,
	    	);
	    } else {
	    	if ($toStat == "Ya") {
	    		$codeStat = 'yes';
	    	}else{
	    		$codeStat = 'no'; 
	    	}

	    	$data = array(
	    		"best_seller"=>$codeStat,
	    	);
	    }

    	$upd = $this->db->update('products', $data, array('id_products' => $this_id));

    	if ($upd) {
	    	echo json_encode(array(
	    		"res"=>"sukses",
	    	));
    	}

    }

     function changeStatusActImages(){

    	$this_id = $this->input->post('this_id');
    	$toStat = $this->input->post('toStat');

    	$codeStat = null;
    	if ($toStat == "Ya") {
    		$codeStat = '1';
    	}else{
    		$codeStat = '0'; 
    	}

    	$data = array(
    		"status" => $codeStat,
    	);

    	$upd = $this->db->update('product_images', $data, array('id' => $this_id));

    	if ($upd) {
	    	echo json_encode(array(
	    		"res"=>"sukses",
	    	));
    	}

    }
     function changeStatusActImagess(){

    	$this_id = $this->input->post('this_id');
    	$toStat = $this->input->post('toStat');

    	$codeStat = null;
    	if ($toStat == "Ya") {
    		$codeStat = '1';
    	}else{
    		$codeStat = '0'; 
    	}

    	$data = array(
    		"status" => $codeStat,
    	);

    	$upd = $this->db->update('testi_images', $data, array('id' => $this_id));

    	if ($upd) {
	    	echo json_encode(array(
	    		"res"=>"sukses",
	    	));
    	}

    }

    //to ADD or EDIT a product content 
	function edit($id = NULL) {

		if($id != NULL) {

			$this->db->select('id_products')->from('products')->where('id_products', $id);
			$count_product = $this->db->get()->num_rows();
			if($count_product === 0) {show_404();}

			//this is an existing product
			$this->data['new_product'] = 'no';  
		
			$this->data['products'] 			= $this->product_m->get($id);  
			//assign to properties, used for custom callback validation
			$this->product_current_id = (int) $this->data['products']->id_products;

		} else {

			//id is null. this is a new product
			$this->data['new_product'] = 'yes'; 
			/*get product data*/
			$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();

			/*get shipment method*/
			$this->data['shipment'] = $this->db->select('*')->from('shipment_method')->order_by('id','ASC')->get()->result();

			//get ordering number and display at add form
			$this->db->select_max('priority')->from('products');
			$current_priority = $this->db->get()->row()->priority;
			if($current_priority == NULL) {
				$this->data['products']->priority = 1;	
			} else {
				$this->data['products']->priority = $current_priority + 1;
			}
		}

		//validation in action 
		//validation check in action
		$config = $this->product_m->rules;    
		$this->load->library('form_validation');
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>'); //above is to add class to form validation error, to be styled  
		$this->form_validation->set_rules($config);  

		if($this->form_validation->run($this) == TRUE) {

			$data = $this->table_data_processing($id);

			if($id == NULL) {
				$product_id = (int) $this->product_m->add_product($data);
				$id = $product_id;
			} else {
				$this->product_m->edit_product($id, $data); 	 
			}

			/*INSERT SKU INTO PRODUCT DETAILS */
			//check if sku alredy exist
			$count_sku = $this->db->select('sku')->from('product_details')->where('sku', $id)->where('product_id', $id)->get()->num_rows();

			if($count_sku == 0) {
				$data = array(
					'product_id' => $id,
					'sku' => $id
				);
				$this->db->insert('product_details', $data);	
			} 

			/*INSERT INTO PRODUCT SPECIFICATION TABLE*/
			/*delete all contents inside this table */
			$this->db->where('product_id', $id);
			$this->db->delete('product_specification');

			for ($i=1; $i <= 10; $i++) {
				$data = array(
					'product_id' => $id
				);

				if($this->input->post('bahan' . $i)) {
					$data['bahan'] = $this->input->post('bahan' . $i);
				}

				if($this->input->post('ukuran' . $i)) {
					$data['ukuran'] = $this->input->post('ukuran' . $i);
				}

				if($this->input->post('min_order' . $i)) {
					$data['min_order'] = $this->input->post('min_order' . $i);
				}

				if($this->input->post('harga' . $i)) {
					$data['harga'] = $this->input->post('harga' . $i);
				}

				if($this->input->post('kelipatan' . $i)) {
					$data['kelipatan'] = $this->input->post('kelipatan' . $i);
				}
				$this->db->insert('product_specification', $data);
			}

			if($id != NULL) {
				$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Lounge berhasil diedit</p>');
				redirect('admin/products/edit/' . $id);		
			} else {
				$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Lounge berhasil dibuat</p>');
				redirect('admin/products');	
			}	
		}

		$this->data['subview'] = 'admin/products/edit';
		$this->load->view('admin/templates/header', $this->data_header); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer'); 	
	}

	public function delete_all(){
		$checkbox_for_del = $this->input->post('checkbox_del');
		if (empty($checkbox_for_del)) {
			redirect('admin/products'); 
		}

		for ($i=0; $i<count($checkbox_for_del) ; $i++) { 
			$id = $checkbox_for_del[$i];

			$this->product_m->delete($id); 

		}

		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Produk berhasil dihapus</p>');
		echo json_encode(array(
			'result'=>'sukses',
		));
	}

	public function delete_all_images(){

		$checkbox_for_del = $this->input->post('checkbox_del');
		$product_id = $this->input->post('product_id');

		if (empty($checkbox_for_del)) {
			redirect('admin/products/product_images/' . $product_id); 
		}

		for ($i=0; $i<count($checkbox_for_del) ; $i++) { 
			
			$id = $checkbox_for_del[$i];
			$this->db->where('id', $id);
			$this->db->delete('product_images');
		}

		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Foto Produk berhasil dihapus</p>');
		echo json_encode(array(
			'result'=>'sukses',
		));
	}

	public function delete_all_imagess(){

		$checkbox_for_del = $this->input->post('checkbox_del');
		$product_id = $this->input->post('product_id');

		if (empty($checkbox_for_del)) {
			redirect('admin/products/testi_images/' . $product_id); 
		}

		for ($i=0; $i<count($checkbox_for_del) ; $i++) { 
			
			$id = $checkbox_for_del[$i];
			$this->db->where('id', $id);
			$this->db->delete('testi_images');
		}

		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Foto Produk berhasil dihapus</p>');
		echo json_encode(array(
			'result'=>'sukses',
		));
	}

	//to delete a product
	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();
		}	

		$this->product_m->delete($id); 

		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Produk berhasil dihapus</p>');
		redirect('admin/products');
	}

	//to delete a product
	function delete_product_detail($id_product, $id_product_detail) {

		//check if id_product_detail exist. If not exist, show 404.
		$this->db->select('id')->from('product_details')->where('id', $id_product_detail);
		$count_product_detail = $this->db->get()->num_rows();
		if ($count_product_detail == 0) { show_404(); }	

		//check if id_product. If not exist, show 404.
		$this->db->select('id_products')->from('products')->where('id_products', $id_product);
		$count_product = $this->db->get()->num_rows();
		if ($count_product == 0) { show_404(); }	

		$this->db->where('id', $id_product_detail);
		$this->db->delete('product_details'); 

		$this->db->where('product_id', $id_product);
		$this->db->where('product_details_id', $id_product_detail);
		$this->db->delete('product_combination');
		
		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Produk Varian berhasil dihapus</p>');
		redirect('admin/products/edit/' . $id_product);
	}

	function product_images($product_id = NULL) { 

		if($product_id == NULL) {redirect(base_url('admin/products'));} 

		//pagination in action. 100 results per page
		$this->load->library('pagination');
		$config['base_url'] = base_url() . 'admin/products/product_images';
		$config['per_page'] = 100;
		$config['uri_segment'] = 3; 

		//fetch all product images 
		$this->db->select('id')->from('product_images')->where('product_id', $product_id);
		$config['total_rows'] = $this->db->get()->num_rows();
		$this->pagination->initialize($config);

		$this->db->select('*');
		$this->db->from('product_images');
		$this->db->where('product_id', $product_id);
		$this->db->order_by('product_details_id', 'ASC');
		$this->db->order_by('priority', 'ASC');
		$this->db->limit($config['per_page'], $this->uri->segment($config['uri_segment']));
		$this->data['product_images'] = $this->db->get()->result();	

		$this->data['product_id'] = $product_id;
		//get product name
		$this->db->select('title')->from('products')->where('id_products', $product_id);
		$this->data['product_name'] = $this->db->get()->row()->title;
		//load view
		$this->data['subview'] = 'admin/products/product_images';
		$this->load->view('admin/templates/header', $this->data_header); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer');	
	}

	function testi_images($product_id = NULL) { 

		if($product_id == NULL) {redirect(base_url('admin/products'));} 

		//pagination in action. 100 results per page
		$this->load->library('pagination');
		$config['base_url'] = base_url() . 'admin/products/testi_images';
		$config['per_page'] = 100;
		$config['uri_segment'] = 3; 

		//fetch all product images 
		$this->db->select('id')->from('testi_images')->where('product_id', $product_id);
		$config['total_rows'] = $this->db->get()->num_rows();
		$this->pagination->initialize($config);

		$this->db->select('*');
		$this->db->from('testi_images');
		$this->db->where('product_id', $product_id);
		$this->db->order_by('product_details_id', 'ASC');
		$this->db->order_by('priority', 'ASC');
		$this->db->limit($config['per_page'], $this->uri->segment($config['uri_segment']));
		$this->data['testi_images'] = $this->db->get()->result();	

		$this->data['product_id'] = $product_id;
		//get product name
		$this->db->select('title')->from('products')->where('id_products', $product_id);
		$this->data['product_name'] = $this->db->get()->row()->title;
		//load view
		$this->data['subview'] = 'admin/products/testi_images';
		$this->load->view('admin/templates/header', $this->data_header); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer');	
	}

	function edit_testi_image($product_id = NULL, $testi_image_id = NULL, $case_addnew = false) {

		if($product_id == NULL) {redirect(base_url('admin/products'));} 

		$case_save = $this->input->post('case_save');
		if (isset($case_save)) {
			if ($case_save == 'addnew') {
				$config = array( 
		          array(
		             'field'   => 'title',
		             'label'   => 'Banner Title',
		             'rules'   => 'trim|required'
		          ), 
		          array(
		             'field'   => 'product_detail_id',
		             'label'   => 'Varian',
		             'rules'   => 'required'
		          ),
		           array(
		             'field'   => 'text_1',
		             'label'   => 'text_1',
		             'rules'   => 'trim'
		          ),  
		            array(
		             'field'   => 'text_2',
		             'label'   => 'text_2',
		             'rules'   => 'trim'
		          ),  
		             array(
		             'field'   => 'description',
		             'label'   => 'description',
		             'rules'   => 'trim'
		          ),  
		          array(
		             'field'   => 'priority[]',
		             'label'   => 'Priority',
		             'rules'   => 'trim|numeric'
		          ),  
				  array(
		             'field'   => 'status[]',
		             'label'   => 'status',
		             'rules'   => 'trim|required'
		          )
		        );

		        $this->load->library('form_validation');
				$this->form_validation->set_rules($config); 
				$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

				if($this->form_validation->run() == TRUE){
					$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();

					$ar_status = $this->input->post('status[]');
					$ar_priority = $this->input->post('priority[]');
					// $ar_text_1 = $this->input->post('text_1[]');
					// $ar_text_2 = $this->input->post('text_2[]');
					// $ar_description = $this->input->post('description[]');

					$cpt = count($_FILES['image']['name']);

					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|gif|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = $image_dimension->product_image_width;
					// $config['max_height'] = $image_dimension->product_image_height;
					$this->load->library('upload', $config);  

    				$files = $_FILES;
				    for($i=0; $i<$cpt; $i++)
				    {       
				    	if ($_FILES['image']['size'][$i] !== 0) {

					    	$_FILES['image']['name']= $files['image']['name'][$i];

					        $_FILES['image']['type']= $files['image']['type'][$i];

					        $_FILES['image']['tmp_name']= $files['image']['tmp_name'][$i];

					        $_FILES['image']['error']= $files['image']['error'][$i];

					        $_FILES['image']['size']= $files['image']['size'][$i]; 

							

        					$this->upload->initialize($config);
							if ( ! $this->upload->do_upload('image')) {
				                // echo $this->upload->display_errors(); die();
								$this->session->set_flashdata('image_error', '<br>
								<p style="background:orange; color:white; padding:5px; font-weight:bold;">Image Upload Error. Salah format atau ukuran.</p>');
								redirect('admin/products/edit_testi_image/' . $product_id . '/' . $this->input->post('correct_product_details_id').'/addnew');
							} else {
								$image = $this->upload->data();
								$image_filename[$i] = $image['file_name']; 	 
							}	

							$this->load->library('image_lib');

							//image resizing (LARGE IMAGE)
							$config['image_library'] = 'gd2';
							$config['source_image'] = './uploads/product/' . $image_filename[$i];
							$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);  

							// $this->image_lib->resize();	

							//image resizing (SMALL IMAGE)
							$config['image_library'] = 'gd2';
							$config['source_image'] = './uploads/product/' . $image_filename[$i];
							$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);  

							// $this->image_lib->resize();	

							//image resizing (THUMBNAIL)
							$config['image_library'] = 'gd2';
							$config['source_image'] = './uploads/product/' . $image_filename[$i];
							$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);  

							// $this->image_lib->resize();	
						}
						$data = array(
							'product_id' => $product_id,
							'product_details_id' => 
							$this->input->post('correct_product_details_id'),
							'title' => 
							$this->security->xss_clean($this->input->post('title')),
							'text_1' => 
							$this->input->post('text_1'),
							'text_2' => 
							$this->input->post('text_2'),
							'description' => 
							$this->input->post('description'),
							'priority' => 
							$this->input->post('priority')[$i],
							'status' => 
							$this->input->post('status')[$i]
						);
						if (isset($image_filename[$i])) {
							$data['image'] = $image_filename[$i];
						} 

						
						

						$this->db->insert('testi_images', $data);	
				    } 
					
					redirect(base_url('admin/products/testi_images/' . $product_id));

				}
				
				// else{
				// 	// jika error
				// 	// echo validation_errors();

				// 	redirect('admin/products/edit_product_image/' . $product_id . '/' . $this->input->post('correct_product_details_id').'/addnew');
				// }
			}
			// return false;
		}
		if($testi_image_id == NULL) {
			//create new  photo
			$testi_image = new stdClass();
			$testi_image->title = '';
			$testi_image->image = '';
			$testi_image->text_1 = '';
			$testi_image->text_2 = '';
			$testi_image->description = '';	
			$testi_image->priority = '';
			$testi_image->status = '';
			$testi_image->product_details_id = '';
			$this->data['testi_image'] = $testi_image;

			//get ordering number and display at add form
			$this->db->select_max('priority')->from('testi_images');
			$current_priority = $this->db->get()->row()->priority;
			if($current_priority == NULL) {
				$this->data['testi_image']->priority = 1;	
			} else {
				$this->data['testi_image']->priority = $current_priority + 1;
			} 

		} else {

			//edit current photo
			$this->db->select('*')->from('testi_images')->where('id', $testi_image_id);
			$this->data['testi_image'] = $this->db->get()->row(); 

			if(count($this->data['testi_image']) == 0) {
				if (empty($case_addnew) || $case_addnew != 'addnew') {
					redirect(base_url('admin/products/testi_images/' . $product_id));
				}
			}
		}

		//validation check in action
		$config = array( 
          array(
             'field'   => 'title',
             'label'   => 'Banner Title',
             'rules'   => 'trim|required'
          ),
           array(
             'field'   => 'product_detail_id',
             'label'   => 'Varian',
             'rules'   => 'required'
          ),
           array(
             'field'   => 'text_1',
             'label'   => 'text_1',
             'rules'   => 'trim'
          ),  
           array(
             'field'   => 'text_2',
             'label'   => 'text_2',
             'rules'   => 'trim'
          ),  
           array(
             'field'   => 'description',
             'label'   => 'description',
             'rules'   => 'trim'
          ),  
          array(
             'field'   => 'priority',
             'label'   => 'Priority',
             'rules'   => 'trim|numeric'
          ),  
		  array(
             'field'   => 'status',
             'label'   => 'status',
             'rules'   => 'trim|required'
          )
        );

        $this->load->library('form_validation');
		$this->form_validation->set_rules($config); 
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

		if($this->form_validation->run() == TRUE) {

			$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();

			if ($_FILES['image']['size'] !== 0) {  

				$config['upload_path'] = './uploads/product/'; 
				$config['allowed_types'] = 'jpg|png|gif|jpeg'; 
				$config['max_size']	= '2000';
				// $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('image')) {
	                //echo $this->upload->display_errors(); die();
					$this->session->set_flashdata('image_error', '<br>
						<p style="background:orange; color:white; padding:5px; font-weight:bold;">Image Upload Error. Salah format atau ukuran.</p>');
					redirect('admin/products/edit_testi_image/' . $product_id);
				} else {
					$image = $this->upload->data();
					$image_filename = $image['file_name']; 	 
				}	

				$this->load->library('image_lib');

				//image resizing (LARGE IMAGE)
				$config['image_library'] = 'gd2';
				$config['source_image'] = './uploads/product/' . $image_filename;
				$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/' . $image_filename;
				$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/' . $image_filename;
				$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 = array(
				'product_id' => $product_id,
				'product_details_id' => $this->input->post('product_detail_id'),
				'title' => $this->security->xss_clean($this->input->post('title')),
				'text_1' => $this->input->post('text_1'),
				'text_2' => $this->input->post('text_2'),
				'description' => $this->input->post('description'),
				'priority' => $this->input->post('priority'),
				'status' => $this->input->post('status')
			);
			if (isset($image_filename)) {
				$data['image'] = $image_filename;
			} 

			if($testi_image_id == NULL) {

				$this->db->insert('testi_images', $data);	
				$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Foto produk berhasil ditambahkan</p>');
				redirect('admin/products/testi_images/' . $product_id);

			} else {

				$this->db->where('id', $testi_image_id);
				$this->db->update('testi_images', $data);
				$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Foto produk berhasil diedit</p>');
				redirect('admin/products/edit_testi_image/' . $product_id . '/' . $testi_image_id);
			}	
		} 

		$this->data['product_id'] = $product_id;
		//get product name
		$this->db->select('title')->from('products')->where('id_products', $product_id);
		$this->data['product_name'] = $this->db->get()->row()->title;

		//get product details
		$this->db->select('id, product_id, sku')->from('product_details')->where('product_id', $product_id)->order_by('id', 'ASC');
		$this->data['product_details'] = $this->db->get()->result();
		
		if ($case_addnew == 'addnew') {
			$this->data['case_addnew'] = $case_addnew;
		}
		$this->data['testi_image_id'] = $testi_image_id;

		$this->data['subview'] = 'admin/products/edit_testi_image';
		$this->load->view('admin/templates/header', $this->data_header); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer');	
	}

	function edit_product_image($product_id = NULL, $product_image_id = NULL, $case_addnew = false) {

		if($product_id == NULL) {redirect(base_url('admin/products'));} 

		$case_save = $this->input->post('case_save');
		if (isset($case_save)) {
			if ($case_save == 'addnew') {
				$config = array( 
		          array(
		             'field'   => 'title',
		             'label'   => 'Banner Title',
		             'rules'   => 'trim|required'
		          ), 
		          array(
		             'field'   => 'product_detail_id',
		             'label'   => 'Varian',
		             'rules'   => 'required'
		          ),
		          array(
		             'field'   => 'priority[]',
		             'label'   => 'Priority',
		             'rules'   => 'trim|numeric'
		          ),  
				  array(
		             'field'   => 'status[]',
		             'label'   => 'status',
		             'rules'   => 'trim|required'
		          )
		        );

		        $this->load->library('form_validation');
				$this->form_validation->set_rules($config); 
				$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

				if($this->form_validation->run() == TRUE){
					$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();

					$ar_status = $this->input->post('status[]');
					$ar_priority = $this->input->post('priority[]');
					$ar_text_1 = $this->input->post('text_1[]');
					$ar_text_2 = $this->input->post('text_2[]');
					$ar_description = $this->input->post('description[]');

					$cpt = count($_FILES['image']['name']);

					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|gif|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = '500';
					// $config['max_height'] = '500';
					$this->load->library('upload', $config);  

    				$files = $_FILES;
				    for($i=0; $i<$cpt; $i++)
				    {       
				    	if ($_FILES['image']['size'][$i] !== 0) {

					    	$_FILES['image']['name']= $files['image']['name'][$i];

					        $_FILES['image']['type']= $files['image']['type'][$i];

					        $_FILES['image']['tmp_name']= $files['image']['tmp_name'][$i];

					        $_FILES['image']['error']= $files['image']['error'][$i];

					        $_FILES['image']['size']= $files['image']['size'][$i]; 

							

        					$this->upload->initialize($config);
							if ( ! $this->upload->do_upload('image')) {
				                // echo $this->upload->display_errors(); die();
								$this->session->set_flashdata('image_error', '<br>
								<p style="background:orange; color:white; padding:5px; font-weight:bold;">Image Upload Error. Salah format atau ukuran.</p>');
								redirect('admin/products/edit_product_image/' . $product_id . '/' . $this->input->post('correct_product_details_id').'/addnew');
							} else {
								$image = $this->upload->data();
								$image_filename[$i] = $image['file_name']; 	 
							}	

							$this->load->library('image_lib');

							//image resizing (LARGE IMAGE)
							// $config['image_library'] = 'gd2';
							// $config['source_image'] = './uploads/product/' . $image_filename[$i];
							// $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);  

							// $this->image_lib->resize();	

							//image resizing (SMALL IMAGE)
							// $config['image_library'] = 'gd2';
							// $config['source_image'] = './uploads/product/' . $image_filename[$i];
							// $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);  

							// $this->image_lib->resize();	

							//image resizing (THUMBNAIL)
							// $config['image_library'] = 'gd2';
							// $config['source_image'] = './uploads/product/' . $image_filename[$i];
							// $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);  

							// $this->image_lib->resize();	
						}
						$data = array(
							'product_id' => $product_id,
							'product_details_id' => 
							$this->input->post('correct_product_details_id'),
							'title' => 
							$this->security->xss_clean($this->input->post('title')),
							'text_description' => 
							$this->security->xss_clean($this->input->post('text_description')),
							// 'text_1' => 
							// $this->input->post('text_1')[$i],
							// 'text_2' => 
							// $this->input->post('text_2')[$i],
							// 'description' => 
							// $this->input->post('description')[$i],
							'priority' => 
							$this->input->post('priority')[$i],
							'status' => 
							$this->input->post('status')[$i]
						);
						if (isset($image_filename[$i])) {
							$data['image'] = $image_filename[$i];
						} 

						$this->db->insert('product_images', $data);	
				    } 
					
					redirect(base_url('admin/products/product_images/' . $product_id));

				}
				
				// else{
				// 	// jika error
				// 	// echo validation_errors();

				// 	redirect('admin/products/edit_product_image/' . $product_id . '/' . $this->input->post('correct_product_details_id').'/addnew');
				// }
			}
			// return false;
		}
		if($product_image_id == NULL) {
			//create new  photo
			$product_image = new stdClass();
			$product_image->title = '';
			$product_image->image = '';	
			$product_image->text_description = '';
			$product_image->priority = '';
			$product_image->status = '';
			$product_image->product_details_id = '';
			$this->data['product_image'] = $product_image;

			//get ordering number and display at add form
			$this->db->select_max('priority')->from('product_images');
			$current_priority = $this->db->get()->row()->priority;
			if($current_priority == NULL) {
				$this->data['product_image']->priority = 1;	
			} else {
				$this->data['product_image']->priority = $current_priority + 1;
			} 

		} else {

			//edit current photo
			$this->db->select('*')->from('product_images')->where('id', $product_image_id);
			$this->data['product_image'] = $this->db->get()->row(); 

			if(empty($this->data['product_image'])) {
				if (empty($case_addnew) || $case_addnew != 'addnew') {
					redirect(base_url('admin/products/product_images/' . $product_id));
				}
			}
		}

		//validation check in action
		$config = array( 
          array(
             'field'   => 'title',
             'label'   => 'Banner Title',
             'rules'   => 'trim|required'
          ),
           array(
             'field'   => 'product_detail_id',
             'label'   => 'Varian',
             'rules'   => 'required'
          ),
          array(
             'field'   => 'priority',
             'label'   => 'Priority',
             'rules'   => 'trim|numeric'
          ),  
		  array(
             'field'   => 'status',
             'label'   => 'status',
             'rules'   => 'trim|required'
          )
        );

        $this->load->library('form_validation');
		$this->form_validation->set_rules($config); 
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

		if($this->form_validation->run() == TRUE) {

			$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();

			if ($_FILES['image']['size'] !== 0) {  

				$config['upload_path'] = './uploads/product/'; 
				$config['allowed_types'] = 'jpg|png|gif|jpeg'; 
				$config['max_size']	= '2000';
				// $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('image')) {
	                //echo $this->upload->display_errors(); die();
					$this->session->set_flashdata('image_error', '<br>
						<p style="background:orange; color:white; padding:5px; font-weight:bold;">Image Upload Error. Salah format atau ukuran.</p>');
					redirect('admin/products/edit_product_image/' . $product_id);
				} else {
					$image = $this->upload->data();
					$image_filename = $image['file_name']; 	 
				}	

				$this->load->library('image_lib');

				//image resizing (LARGE IMAGE)
				$config['image_library'] = 'gd2';
				$config['source_image'] = './uploads/product/' . $image_filename;
				$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/' . $image_filename;
				$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/' . $image_filename;
				$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 = array(
				'product_id' => $product_id,
				'product_details_id' => $this->input->post('product_detail_id'),
				'title' => $this->security->xss_clean($this->input->post('title')),
				'text_description' => $this->security->xss_clean($this->input->post('text_description')),
				'priority' => $this->input->post('priority'),
				'status' => $this->input->post('status')
			);
			if (isset($image_filename)) {
				$data['image'] = $image_filename;
			} 

			if($product_image_id == NULL) {

				$this->db->insert('product_images', $data);	
				$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Foto produk berhasil ditambahkan</p>');
				redirect('admin/products/product_images/' . $product_id);

			} else {

				$this->db->where('id', $product_image_id);
				$this->db->update('product_images', $data);
				$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Foto produk berhasil diedit</p>');
				redirect('admin/products/edit_product_image/' . $product_id . '/' . $product_image_id);
			}	
		} 

		$this->data['product_id'] = $product_id;
		//get product name
		$this->db->select('title')->from('products')->where('id_products', $product_id);
		$this->data['product_name'] = $this->db->get()->row()->title;

		//get product details
		$this->db->select('id, product_id, sku')->from('product_details')->where('product_id', $product_id)->order_by('id', 'ASC');
		$this->data['product_details'] = $this->db->get()->result();
		
		if ($case_addnew == 'addnew') {
			$this->data['case_addnew'] = $case_addnew;
		}
		$this->data['product_image_id'] = $product_image_id;

		$this->data['subview'] = 'admin/products/edit_product_image';
		$this->load->view('admin/templates/header', $this->data_header); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer');	
	}

	function delete_testi_image($product_id = NULL, $testi_image_id = NULL) {

		if($product_id == NULL || $testi_image_id == NULL) {redirect(base_url('admin/products'));}

		//get image file name for deletion
		$this->db->select('image')->from('testi_images')->where('id', $testi_image_id);
		$image = $this->db->get()->row()->image;

		if (file_exists(base_url() . 'uploads/product/' . $image)) {
			unlink(FCPATH .'/uploads/product/'. $image);
		}

		if (file_exists(base_url() . 'uploads/product/large/' . $image)) {
			unlink(FCPATH .'/uploads/product/large/'. $image);
		}	

		if (file_exists(base_url() . 'uploads/product/small/' . $image)) {
			unlink(FCPATH .'/uploads/product/small/'. $image);
		}

		if (file_exists(base_url() . 'uploads/product/thumbnail/' . $image)) {
			unlink(FCPATH .'/uploads/product/thumbnail/'. $image);
		}

		$this->db->where('id', $testi_image_id);
		$this->db->delete('testi_images');

		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Foto produk berhasil dihapus</p>');
		redirect('admin/products/testi_images/' . $product_id);
	}	

	function delete_product_image($product_id = NULL, $product_image_id = NULL) {

		if($product_id == NULL || $product_image_id == NULL) {redirect(base_url('admin/products'));}

		//get image file name for deletion
		$this->db->select('image')->from('product_images')->where('id', $product_image_id);
		$image = $this->db->get()->row()->image;

		if (file_exists(base_url() . 'uploads/product/' . $image)) {
			unlink(FCPATH .'/uploads/product/'. $image);
		}

		if (file_exists(base_url() . 'uploads/product/large/' . $image)) {
			unlink(FCPATH .'/uploads/product/large/'. $image);
		}	

		if (file_exists(base_url() . 'uploads/product/small/' . $image)) {
			unlink(FCPATH .'/uploads/product/small/'. $image);
		}

		if (file_exists(base_url() . 'uploads/product/thumbnail/' . $image)) {
			unlink(FCPATH .'/uploads/product/thumbnail/'. $image);
		}

		$this->db->where('id', $product_image_id);
		$this->db->delete('product_images');

		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Foto produk berhasil dihapus</p>');
		redirect('admin/products/product_images/' . $product_id);
	}

	//callback function validation add new product
	public function _cek_existing_product_code($str) {

		$num_rows = $this->product_m->cek_existing_product_code($str, $this->product_current_id);   
		if ($num_rows != 0 ) { 
			$this->form_validation->set_message('_cek_existing_product_code', 'Kode SKU Produk sudah ada sebelumnya !');
			return FALSE;
		} else {
			return TRUE; 
		}
	}

	//NOT USED CURRENTLY ! callback function validation add new product check SKU
	public function _cek_existing_sku($str) {

		//check if the code is already exist in products detail table..
		$this->db->select('sku')->from('product_details')->where('sku', $str);
		$count_code_productstable = $this->db->get()->num_rows();

		//check if the code is already exist in stocks table..
		$this->db->select('sku')->from('stocks')->where('sku', $str);
		$count_code_stockstable = $this->db->get()->num_rows();

		if ($count_code_productstable != 0 || $count_code_stockstable != 0) { 
			
			$this->form_validation->set_message('_cek_existing_product_code', 'Product Code (SKU) already exist !');
			return FALSE;
		} else {
			return TRUE; 
		}
	}
	
	private function table_data_processing($id = NULL) {

		$data = array(
			'title' 					=> $this->security->xss_clean($this->input->post('product_name')),
			'intro_title' 					=> $this->security->xss_clean($this->input->post('intro_title')),
			'alias' 					=> url_title($this->security->xss_clean($this->input->post('product_name'))),
			'description' 				=> $this->security->xss_clean($this->input->post('description')),
			'long_description' 			=> $this->input->post('long_description',FALSE),
			'location' 	=> $this->security->xss_clean($this->input->post('location')),
			'product_status' 			=> $this->input->post('product_status'),
			'priority' 					=> $this->input->post('priority'),
			'meta_description' 			=> $this->security->xss_clean($this->input->post('meta_description')),
			'meta_title' 				=> $this->security->xss_clean($this->input->post('meta_title')),
			
			'text_icon1' 				=> $this->security->xss_clean($this->input->post('text_icon1')),
			'text_icon2' 				=> $this->security->xss_clean($this->input->post('text_icon2')),
			'text_icon3' 				=> $this->security->xss_clean($this->input->post('text_icon3')),
			'text_icon4' 				=> $this->security->xss_clean($this->input->post('text_icon4')),
			'text_icon5' 				=> $this->security->xss_clean($this->input->post('text_icon5')),
			'text_icon6' 				=> $this->security->xss_clean($this->input->post('text_icon6')),
			'text_icon7' 				=> $this->security->xss_clean($this->input->post('text_icon7')),
			'text_icon8' 				=> $this->security->xss_clean($this->input->post('text_icon8')),
			'text_icon9' 				=> $this->security->xss_clean($this->input->post('text_icon9')),
			'text_icon10' 				=> $this->security->xss_clean($this->input->post('text_icon10')),
			'text_icon11' 				=> $this->security->xss_clean($this->input->post('text_icon11')),
			'text_icon12' 				=> $this->security->xss_clean($this->input->post('text_icon12')),
			'text_icon13' 				=> $this->security->xss_clean($this->input->post('text_icon13')),
			'text_icon14' 				=> $this->security->xss_clean($this->input->post('text_icon14')),
			'text_icon15' 				=> $this->security->xss_clean($this->input->post('text_icon15')),
			'text_icon16' 				=> $this->security->xss_clean($this->input->post('text_icon16')),
			'alamat' 				=> $this->security->xss_clean($this->input->post('alamat')),
			'email' 				=> $this->security->xss_clean($this->input->post('email')),
			'lounge_type' 				=> $this->security->xss_clean($this->input->post('lounge_type')),
			'nomor_telepon' 				=> $this->security->xss_clean($this->input->post('nomor_telepon')),
			'booking_active' 			=> $this->input->post('booking_active'),
			
			// Facility fields
			'facility_tag' 				=> $this->security->xss_clean($this->input->post('facility_tag')),
			'facility_title' 			=> $this->security->xss_clean($this->input->post('facility_title')),
			'facility_subtitle' 			=> $this->security->xss_clean($this->input->post('facility_subtitle')),
			'facility1_title' 			=> $this->security->xss_clean($this->input->post('facility1_title')),
			'facility1_subtitle' 		=> $this->security->xss_clean($this->input->post('facility1_subtitle')),
			'facility2_title' 			=> $this->security->xss_clean($this->input->post('facility2_title')),
			'facility2_subtitle' 		=> $this->security->xss_clean($this->input->post('facility2_subtitle')),
			'facility3_title' 			=> $this->security->xss_clean($this->input->post('facility3_title')),
			'facility3_subtitle' 		=> $this->security->xss_clean($this->input->post('facility3_subtitle')),
			'facility4_title' 			=> $this->security->xss_clean($this->input->post('facility4_title')),
			'facility4_subtitle' 		=> $this->security->xss_clean($this->input->post('facility4_subtitle')),
			
			// Testimony fields
			'testimony1_name' 			=> $this->security->xss_clean($this->input->post('testimony1_name')),
			'testimony1_work' 			=> $this->security->xss_clean($this->input->post('testimony1_work')),
			'testimony1_content' 		=> $this->input->post('testimony1_content',FALSE),
			'testimony2_name' 			=> $this->security->xss_clean($this->input->post('testimony2_name')),
			'testimony2_work' 			=> $this->security->xss_clean($this->input->post('testimony2_work')),
			'testimony2_content' 		=> $this->input->post('testimony2_content',FALSE),
			'testimony3_name' 			=> $this->security->xss_clean($this->input->post('testimony3_name')),
			'testimony3_work' 			=> $this->security->xss_clean($this->input->post('testimony3_work')),
			'testimony3_content' 		=> $this->input->post('testimony3_content',FALSE),
			'testimony4_name' 			=> $this->security->xss_clean($this->input->post('testimony4_name')),
			'testimony4_work' 			=> $this->security->xss_clean($this->input->post('testimony4_work')),
			'testimony4_content' 		=> $this->input->post('testimony4_content',FALSE),
			'testimony5_name' 			=> $this->security->xss_clean($this->input->post('testimony5_name')),
			'testimony5_work' 			=> $this->security->xss_clean($this->input->post('testimony5_work')),
			'testimony5_content' 		=> $this->input->post('testimony5_content',FALSE),
			'testimony6_name' 			=> $this->security->xss_clean($this->input->post('testimony6_name')),
			'testimony6_work' 			=> $this->security->xss_clean($this->input->post('testimony6_work')),
			'testimony6_content' 		=> $this->input->post('testimony6_content',FALSE),
			
			// FAQ fields
			'faq_tag' 				=> $this->security->xss_clean($this->input->post('faq_tag')),
			'faq_title' 				=> $this->security->xss_clean($this->input->post('faq_title')),
			'faq_subtitle' 				=> $this->security->xss_clean($this->input->post('faq_subtitle')),
			'faq1_question' 				=> $this->security->xss_clean($this->input->post('faq1_question')),
			'faq1_answer' 				=> $this->input->post('faq1_answer',FALSE),
			'faq2_question' 				=> $this->security->xss_clean($this->input->post('faq2_question')),
			'faq2_answer' 				=> $this->input->post('faq2_answer',FALSE),
			'faq3_question' 				=> $this->security->xss_clean($this->input->post('faq3_question')),
			'faq3_answer' 				=> $this->input->post('faq3_answer',FALSE),
			'faq4_question' 				=> $this->security->xss_clean($this->input->post('faq4_question')),
			'faq4_answer' 				=> $this->input->post('faq4_answer',FALSE),
			'faq5_question' 				=> $this->security->xss_clean($this->input->post('faq5_question')),
			'faq5_answer' 				=> $this->input->post('faq5_answer',FALSE),
			'faq6_question' 				=> $this->security->xss_clean($this->input->post('faq6_question')),
			'faq6_answer' 				=> $this->input->post('faq6_answer',FALSE)
		);

		if ($_FILES['image']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('image')) { 
						$this->session->set_flashdata('error', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image1 = $this->upload->data();
						$image1_filename = $image1['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}
		if ($_FILES['image1']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('image1')) { 
						$this->session->set_flashdata('error1', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image2 = $this->upload->data();
						$image2_filename = $image2['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}
		if ($_FILES['image2']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('image2')) { 
						$this->session->set_flashdata('error2', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image3 = $this->upload->data();
						$image3_filename = $image3['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}
		if ($_FILES['icon1']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('icon1')) { 
						$this->session->set_flashdata('error_icon1', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image4 = $this->upload->data();
						$image4_filename = $image4['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}
		if ($_FILES['icon2']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('icon2')) { 
						$this->session->set_flashdata('error_icon2', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image5 = $this->upload->data();
						$image5_filename = $image5['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}
		if ($_FILES['icon3']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('icon3')) { 
						$this->session->set_flashdata('error_icon3', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image6 = $this->upload->data();
						$image6_filename = $image6['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}
		if ($_FILES['icon4']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('icon4')) { 
						$this->session->set_flashdata('error_icon4', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image7 = $this->upload->data();
						$image7_filename = $image7['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}
		if ($_FILES['icon5']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('icon5')) { 
						$this->session->set_flashdata('error_icon5', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image8 = $this->upload->data();
						$image8_filename = $image8['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}
		if ($_FILES['icon6']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('icon6')) { 
						$this->session->set_flashdata('error_icon6', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image9 = $this->upload->data();
						$image9_filename = $image9['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}
		if ($_FILES['icon7']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('icon7')) { 
						$this->session->set_flashdata('error_icon7', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image10 = $this->upload->data();
						$image10_filename = $image10['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}
		if ($_FILES['icon8']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('icon8')) { 
						$this->session->set_flashdata('error_icon8', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image11 = $this->upload->data();
						$image11_filename = $image11['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}
		if ($_FILES['icon9']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
					$config['max_size']	= '2000';	
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('icon9')) { 
						$this->session->set_flashdata('error_icon9', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image13 = $this->upload->data();
						$image13_filename = $image13['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}

		if ($_FILES['icon10']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
				$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('icon10')) { 
						$this->session->set_flashdata('error_icon10', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image14 = $this->upload->data();
						$image14_filename = $image14['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}

		if ($_FILES['icon11']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('icon11')) { 
						$this->session->set_flashdata('error_icon11', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image15 = $this->upload->data();
						$image15_filename = $image15['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}

		if ($_FILES['icon12']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
				$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('icon12')) { 
						$this->session->set_flashdata('error_icon12', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image16 = $this->upload->data();
						$image16_filename = $image16['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}

		if ($_FILES['icon13']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
				$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('icon13')) { 
						$this->session->set_flashdata('error_icon13', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image17 = $this->upload->data();
						$image17_filename = $image17['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}

		if ($_FILES['icon14']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('icon14')) { 
						$this->session->set_flashdata('error_icon14', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image18 = $this->upload->data();
						$image18_filename = $image18['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}

		if ($_FILES['icon15']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
				$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('icon15')) { 
						$this->session->set_flashdata('error_icon15', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image19 = $this->upload->data();
						$image19_filename = $image19['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}

		if ($_FILES['icon16']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('icon16')) { 
						$this->session->set_flashdata('error_icon16', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image20 = $this->upload->data();
						$image20_filename = $image20['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}

		if ($_FILES['img_thumb']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/large/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = '370';
					// $config['max_height'] = '225';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('img_thumb')) { 
						$this->session->set_flashdata('img_thumb', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$img_thumb = $this->upload->data();
						$img_thumb_filename = $img_thumb['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}

		if ($_FILES['image3']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
				$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('image3')) { 
						$this->session->set_flashdata('error3', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image21 = $this->upload->data();
						$image21_filename = $image21['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}
		if ($_FILES['image4']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
				$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('image4')) { 
						$this->session->set_flashdata('error4', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image22 = $this->upload->data();
						$image22_filename = $image22['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}

		if ($_FILES['partnership']['size'] !== 0) {  	
 
					$config['upload_path'] = './uploads/product/'; 
					$config['allowed_types'] = 'jpg|png|jpeg'; 
					$config['max_size']	= '2000';
					// $config['max_width']  = '5000';
					// $config['max_height'] = '5000';
					
					$this->load->library('upload', $config);
              		$this->upload->initialize($config);

					if ( ! $this->upload->do_upload('partnership')) { 
						$this->session->set_flashdata('error_background_partnership', '<br>
							<p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>');
						if ($id ==  NULL ) {
							redirect('admin/products/edit');
						} else{
							redirect('admin/products/edit/'.$id);
						}
						
					} else {
						$image23 = $this->upload->data();
						$image23_filename = $image23['file_name']; 
						// $this->resize_single_image('580','500','home_about/',$image1_filename);	 
					}	
				}

				if (isset($img_thumb_filename)) {
					$data['img_thumb'] = $img_thumb_filename; 
				}
				if (isset($image1_filename)) {
					$data['image'] = $image1_filename; 
				}
				if (isset($image2_filename)) {
					$data['image1'] = $image2_filename; 
				}
				if (isset($image3_filename)) {
					$data['image2'] = $image3_filename; 
				} 
				if (isset($image4_filename)) {
					$data['icon1'] = $image4_filename; 
				} 
				if (isset($image5_filename)) {
					$data['icon2'] = $image5_filename; 
				} 
				if (isset($image6_filename)) {
					$data['icon3'] = $image6_filename; 
				} 
				if (isset($image7_filename)) {
					$data['icon4'] = $image7_filename; 
				} 
				if (isset($image8_filename)) {
					$data['icon5'] = $image8_filename; 
				} 
				if (isset($image9_filename)) {
					$data['icon6'] = $image9_filename; 
				} 
				if (isset($image10_filename)) {
					$data['icon7'] = $image10_filename; 
				} 
				if (isset($image11_filename)) {
					$data['icon8'] = $image11_filename; 
				} 
				if (isset($image13_filename)) {
					$data['icon9'] = $image13_filename; 
				} 
				if (isset($image14_filename)) {
					$data['icon10'] = $image14_filename; 
				} 
				if (isset($image15_filename)) {
					$data['icon11'] = $image15_filename; 
				} 
				if (isset($image16_filename)) {
					$data['icon12'] = $image16_filename; 
				} 
				if (isset($image17_filename)) {
					$data['icon13'] = $image17_filename; 
				} 
				if (isset($image18_filename)) {
					$data['icon14'] = $image18_filename; 
				} 
				if (isset($image19_filename)) {
					$data['icon15'] = $image19_filename; 
				} 
				if (isset($image20_filename)) {
					$data['icon16'] = $image20_filename; 
				} 
				if (isset($image12_filename)) {
					$data['background_testimoni'] = $image12_filename; 
				} 
				if (isset($image21_filename)) {
					$data['image3'] = $image21_filename; 
				} 
				if (isset($image22_filename)) {
					$data['image4'] = $image22_filename; 
				} 
				if (isset($image23_filename)) {
			$data['partnership'] = $image23_filename; 
		} 
		
		// Handle facility image uploads
		for ($i = 1; $i <= 4; $i++) {
			if ($_FILES['facility'.$i.'_image']['size'] !== 0) {
				$config['upload_path'] = './uploads/product/';
				$config['allowed_types'] = 'jpg|png|jpeg';
				$config['max_width'] = '5000';
				$config['max_height'] = '5000';
				
				$this->load->library('upload', $config);
				$this->upload->initialize($config);
				
				if ($this->upload->do_upload('facility'.$i.'_image')) {
					$facility_image = $this->upload->data();
					$data['facility'.$i.'_image'] = $facility_image['file_name'];
				}
			}
		}
		
		// Handle testimony image uploads
		for ($i = 1; $i <= 6; $i++) {
			if ($_FILES['testimony'.$i.'_image']['size'] !== 0) {
				$config['upload_path'] = './uploads/product/';
				$config['allowed_types'] = 'jpg|png|jpeg';
				$config['max_width'] = '5000';
				$config['max_height'] = '5000';
				
				$this->load->library('upload', $config);
				$this->upload->initialize($config);
				
				if ($this->upload->do_upload('testimony'.$i.'_image')) {
					$testimony_image = $this->upload->data();
					$data['testimony'.$i.'_image'] = $testimony_image['file_name'];
				}
			}
		}
		
		// Handle CTA image upload
		if ($_FILES['cta_image']['size'] !== 0) {
			$config['upload_path'] = './uploads/product/';
			$config['allowed_types'] = 'jpg|png|jpeg';
			$config['max_width'] = '5000';
			$config['max_height'] = '5000';
			
			$this->load->library('upload', $config);
			$this->upload->initialize($config);
			
			if ($this->upload->do_upload('cta_image')) {
				$cta_image = $this->upload->data();
				$data['cta_image'] = $cta_image['file_name'];
			}
		}
		
return $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('priority', 'ASC');
			$this->data['products'] = $this->db->get()->result(); 
		}

		//load view
		$this->data['subview'] = 'admin/products/index'; 
		$this->load->view('admin/templates/header', $this->data_header); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer'); 
	}

	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('priority', 'ASC');
			$this->data['products'] = $this->db->get()->result(); 

			//load view
			$this->data['subview'] = 'admin/products/index'; 
			$this->load->view('admin/templates/header', $this->data_header); 
			$this->load->view('admin/_layout_main', $this->data);
			$this->load->view('admin/templates/footer'); 
			
		} 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_header); 
			$this->load->view('admin/_layout_main', $this->data);
			$this->load->view('admin/templates/footer'); 

		}
	}	

	function ajax_get_attributes() {

		if (!$this->input->is_ajax_request()) {
   			exit('No direct script access allowed');
		}

		$varian_id = $this->input->post('id_varian');
		//get all attribute details
		$this->db->select('id, attribute_detail')->from('product_attributes_detail')->where('product_attribute_id', $varian_id)->order_by('priority', 'ASC');
		$data['attributes'] = $this->db->get()->result();
		$this->load->view('admin/products/ajax_get_attributes', $data);
	}

	function upload_products() {

		if(!$_POST) {
			redirect('admin/products');
		}

		$config['upload_path']		= 'uploads/excel/';
        $config['allowed_types']	= 'xlsx|xls';
        
        $this->load->library('upload', $config);
        
        if ( ! $this->upload->do_upload('userfile')){
            $this->session->set_flashdata('error', '<p style="background:red; color:white; padding:5px; font-weight:bold;">'.strip_tags($this->upload->display_errors()).'</p>');
            redirect('admin/products');
        }
        else{
        	require_once APPPATH . 'third_party/PHPExcel/IOFactory.php';

            $data 			= array('upload_data' => $this->upload->data());
            $upload_data 	= $this->upload->data(); //Mengambil detail data yang di upload
            $filename 		= $upload_data['file_name'];//Nama File

			//ini_set('memory_limit', '-1');

		    $inputFileName = 'uploads/excel/'.$filename;

		    try {
		    	$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
		    } 
		    catch(Exception $e) {
		    	die('Error loading file :' . $e->getMessage());
		    }

		    $worksheet	= $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
		    $numRows 	= count($worksheet);
		  
		    for ($i=1; $i < ($numRows+1) ; $i++) { 
		    	if ($i > 51) {
		    		break;
		    	}
		    	if($i != 1){
		    		$nama_product = $worksheet[$i]["A"];
		    		$sku = $worksheet[$i]["B"];
		    		$merek = $worksheet[$i]["C"];
		    		$kategori = $worksheet[$i]["D"];
		    		$harga_normal = $worksheet[$i]["E"];
		    		$harga_diskon = $worksheet[$i]["F"];
		    		$panjang_cm = $worksheet[$i]["G"];
		    		$lebar_cm = $worksheet[$i]["H"];
		    		$tinggi_cm = $worksheet[$i]["I"];
		    		$berat_cm = $worksheet[$i]["J"];
		    		$is_indent = $worksheet[$i]["K"];
		    		$varian = $worksheet[$i]["L"];
		    		$is_new_arrivals = $worksheet[$i]["R"];
		    		$is_featured = $worksheet[$i]["S"];
		    		$is_best_sellers = $worksheet[$i]["T"];

		    		if(empty($worksheet[$i]["M"])) {
		    			$short_descr_id = '';
		    		} else {
		    			$short_descr_id = $worksheet[$i]["M"];
		    		}

		    		if(empty($worksheet[$i]["N"])) {
		    			$short_descr_en = '';
		    		} else {
		    			$short_descr_en = $worksheet[$i]["N"];
		    		}

		    		if(empty($worksheet[$i]["O"])) {
		    			$long_descr_id = '';
		    		} else {
		    			$long_descr_id = $worksheet[$i]["O"];
		    		}

		    		if(empty($worksheet[$i]["P"])) {
		    			$long_descr_en = '';
		    		} else {
		    			$long_descr_en = $worksheet[$i]["P"];
		    		}

		    		if(empty($worksheet[$i]["Q"])) {
		    			$kurir_pengiriman = 3;
		    		} else {
		    			$kurir_pengiriman = $worksheet[$i]["Q"];
		    		}

		    		if(empty($worksheet[$i]["U"])) {
		    			$seo_judul = '';
		    		} else {
		    			$seo_judul = $worksheet[$i]["U"];
		    		}

		    		if(empty($worksheet[$i]["V"])) {
		    			$seo_descr_meta = '';
		    		} else {
		    			$seo_descr_meta = $worksheet[$i]["V"];
		    		}

		    		if(empty($worksheet[$i]["W"])) {
		    			$dp_produk_persen = 0;
		    		} else {
		    			$dp_produk_persen = $worksheet[$i]["W"];
		    		}

		    		if(empty($worksheet[$i]["X"])) {
		    			$durasi_info_indent = '';
		    		} else {
		    			$durasi_info_indent = $worksheet[$i]["X"];
		    		}

		    		$is_product_active = $worksheet[$i]["Y"];

		    		// query product
		    		$query_products = $this->db->get_where('products',array(
		    			'title'=>$nama_product,
		    		)); 

		    		// query brands
		    		$query_brands = $this->db->get_where('brands',array(
		    			'brand'=>$merek,
		    		)); 
		    		$id_brands = null;
		    		if ($query_brands->num_rows()>0) {
		    			$id_brands = $query_brands->row()->id_brands; 
		    		}

		    		// shipment method
		    		$output_kurir_pengiriman = '';
		    		$kurir_pengiriman = str_replace('.', ',', (string)$kurir_pengiriman);
		    		$id_kurir_pengiriman = explode(',', $kurir_pengiriman);
					// query shipment method
					for ($j=0; $j<count($id_kurir_pengiriman); $j++) {
			    		$query_shipment_method = $this->db->get_where('shipment_method',array(
			    			'id'=>$id_kurir_pengiriman[$j],
			    		)); 

			    		if ($query_shipment_method->num_rows()>0) { 
							$output_kurir_pengiriman .= $query_shipment_method->row()->name.",";
			    		}
					}
					$output_kurir_pengiriman = substr($output_kurir_pengiriman,0,-1);
 

					// data categories
					$data_group_categories = [];
					$group_categories = explode(',', $kategori);
					$cntr_categories = -1;
					for ($j=0; $j<count($group_categories); $j++) {
						$each_categories = explode('>', trim($group_categories[$j]));
						for ($k=0; $k<count($each_categories); $k++) { 
							$cntr_categories++;
							$data_group_categories[$cntr_categories]=trim($each_categories[$k]);
						}
					}

					// data varian
					$data_group_varians = [];
					$group_varians = explode(',', $varian);  

					for ($j=0; $j<count($group_varians); $j++) {
						$data_group_varians[$j] = explode('>', trim($group_varians[$j]));  
					}

					// status produk
					if ($is_product_active == 'ya' || $is_product_active == 'yes') {
						$is_product_active = 1;
					}else{
						$is_product_active = 0; 
					}

					// best seller
					if ($is_best_sellers == 'ya' || $is_best_sellers == 'yes') {
						$is_best_sellers = 'yes';
					}else{
						$is_best_sellers = 'no'; 
					}

					// new arrivals
					if ($is_new_arrivals == 'ya' || $is_new_arrivals == 'yes') {
						$is_new_arrivals = 'yes';
					}else{
						$is_new_arrivals = 'no'; 
					}

					// featured
					if ($is_featured == 'ya' || $is_featured == 'yes') {
						$is_featured = 'yes';
					}else{
						$is_featured = 'no'; 
					}   

					// is_indent
					if ($is_indent == 'ya' || $is_indent == 'yes') {
						$is_indent = 'yes';
					}else{
						$is_indent = 'no'; 
					}   

		    		// data products
	    			$data_products = array(
	    				"brand_id"=>$id_brands,
	    				"alias"=>preg_replace('/\s+/', '-', $nama_product),
	    				"description"=>$short_descr_id,
	    				"description_en"=>$short_descr_en,
	    				"long_description"=>$long_descr_id,
	    				"long_description_en"=>$long_descr_en,
	    				"shipment_method"=>$output_kurir_pengiriman,
	    				"best_seller"=>$is_best_sellers,
	    				"new_arrival"=>$is_new_arrivals,
	    				"popular_product"=>$is_featured,
	    				"indent_dp"=>$dp_produk_persen,
	    				"meta_title"=>$seo_judul,
	    				"meta_description"=>$seo_descr_meta,
	    				"indent_time"=>$durasi_info_indent,
	    				"product_status"=>$is_product_active,
	    			); 

	    			// data product details
	    			$data_product_details = array(
	    				"weight"=>$berat_cm, 
	    				"length"=>$panjang_cm, 
	    				"width"=>$lebar_cm, 
	    				"height"=>$tinggi_cm, 
	    				"price"=>$harga_normal, 
	    				"discounted_price"=>$harga_diskon, 
	    				"is_indent"=>$is_indent, 
	    			);

	    			$id_product = null;
		    		if ($query_products->num_rows()>0) { 
		    			// update products
		    			$id_product = $query_products->row()->id_products;
		    			$upd_products = $this->db->update("products",$data_products,array('title'=>$nama_product)); 
		    			
		    		}else{
		    			// insert products
		    			$data_products['title']=$nama_product;  

			    		if ($data_products['title'] != null) {
			    			$this->db->insert("products",$data_products); 
	   						$id_product = $this->db->insert_id();
			    		}

		    		}

		    		// query product details
		    		$query_product_details = $this->db->get_where(
		    			'product_details',array(
			    			'sku'=>$sku, 
			    		));

		    		$id_product_details = null;
			    	if ($query_product_details->num_rows()>0) {
			    		// update product details
		    			$id_product_details = $query_product_details->row()->id;
		    			$upd_products = $this->db->update("product_details",$data_product_details,array(
		    				'id'=>$id_product_details,
		    				'sku'=>$sku,
		    			));
			    	}else{
		    			// insert product details
		    			$data_product_details['sku']=$sku;
		    			$data_product_details['product_id']=$id_product;
			    		
			    		if ($data_product_details['weight'] != null) { 
			    			$this->db->insert("product_details",$data_product_details); 
	   						$id_product_details = $this->db->insert_id();
			    		}
			    	} 

		    		if ($id_product != null) {
		    			// delete categories by id product
		    			if($i <= 2){
		    				$del_categories = $this->db->delete('category_product',array('id_product'=>$id_product));
		    				$del_shipment = $this->db->delete('shipment_method_product',array('product_id'=>$id_product));
		    			}
		    			for ($j=0; $j<count($id_kurir_pengiriman); $j++) {
		    				// insert shipment product
		    				$query_check_shipment_product = 
		    				$this->db->get_where('shipment_method_product',array(
		    					"product_id"=>$id_product,
								"shipment_method_id"=>$id_kurir_pengiriman[$j],
		    				));

		    				if ($query_check_shipment_product->num_rows() == 0) {
								$ins_shipment_product = $this->db->insert('shipment_method_product',array(
									"product_id"=>$id_product,
									"shipment_method_id"=>$id_kurir_pengiriman[$j],
								));
		    				}
						}

						for ($j=0; $j<count($data_group_categories); $j++) {
							$this_val_for_search = strtolower($data_group_categories[$j]);

							$query_categories = $this->db->select('*')
							->from('categories')
							->where('category',$this_val_for_search)
							->or_where('category_en',$this_val_for_search)
							->or_where('alias',$this_val_for_search)
							->or_where('alias_en',$this_val_for_search)
							->get();

							if ($query_categories->num_rows()>0) {
								$id_categories = $query_categories->row()->id_categories;

								// insert category product
								$ins_category_product = $this->db->insert('category_product',array(
									"id_product"=>$id_product,
									"id_category"=>$id_categories,
								));
							}
						}
		    		}

		    		if ($id_product != null && $id_product_details != null) {
		    			// delete varians by id product
		    			if($i <= 2){
			    			$del_varians = $this->db->delete('product_combination',array(
			    				'product_id'=>$id_product,
			    				'product_details_id'=>$id_product_details,
			    			));
		    			}

						for ($j=0; $j<count($data_group_varians); $j++) {
							$key_product_attributes = strtolower($data_group_varians[$j][0]);
							$key_product_attributes_detail = strtolower($data_group_varians[$j][1]);

							$query_product_attributes = $this->db->select("*")
							->from("product_attributes")
							->where('product_attribute',$key_product_attributes)
							->or_where('product_attribute_en',$key_product_attributes)->get();

							if ($query_product_attributes->num_rows()>0) {
								$attribute_id = $query_product_attributes->row()->id;

								$query_product_detail_attributes = $this->db->select("*")
								->from("product_attributes_detail")
								->where('attribute_detail',$key_product_attributes_detail)
								->or_where('attribute_detail_en',$key_product_attributes_detail)
								->where('product_attribute_id',$attribute_id)->get();

								if ($query_product_detail_attributes->num_rows()>0) {
									$attribute_detail_id = $query_product_detail_attributes->row()->id;

									$ins_p_combination = $this->db->insert('product_combination',array(
										'product_id'=>$id_product,
										'product_details_id'=>$id_product_details,
										'attribute_id'=>$attribute_id,
										'attribute_detail_id'=>$attribute_detail_id,
									));
								}
							}
						}
		    		}
		    	}		            
		    }

		    unlink('uploads/excel/'.$filename);
		    $this->session->set_flashdata('success', '<p style="background:green; color:white; padding:5px; font-weight:bold;">Upload produk Sukses</p>');
		    redirect('admin/products');
		}
	}

}

https://t.me/RX1948 - 2025