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 :  /var/www/blue-sky.co.id/public_html/application/controllers/admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

class Product_attributes extends Admin_Controller {

	//this property is used for validating existing size title on call back edit size
	protected $attribute_current_id;
	protected $attribute_detail_current_id;
		
	function __construct() {

		parent::__construct();	

		//admin role module check
		$this->check_admin_role('varian produk'); //method from Admin_controller
		
		$this->load->model('product_attributes_m');    
	} 

	//this is to list all brands
	function index() {

		//Add pagination
		$this->load->helper('pagination_helper'); 
		add_pagination(base_url() . 'admin/product_attributes/index', $this->product_attributes_m->record_count(), 6, 4);

		//get all attributes
   		$this->data['attributes'] = $this->product_attributes_m->get_all_attributes(6, $this->uri->segment(4));   

		//load view
		$this->data['subview'] = 'admin/product_attributes/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 refreshDisplayPriority(){
    	$this_data = $this->input->post('this_data');
    	$case_detail = $this->input->post('case_detail');

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

			$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Atribut Prioritas berhasil diubah</p>');
    	}else{
			foreach ($this_data as $key) {
	    		$u_data = array(
	    			'priority'=>$key['val'],
	    		);
	    		$this->db->update('product_attributes', $u_data, array('id' => $key['id']));
	    	}

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

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

    function ajax_addnew_varian_atribut(){
    	$inp_attribute = trim($this->input->post('inp_attribute'));
		$inp_attribute_detail = trim($this->input->post('inp_attribute_detail'));

		$data = array(
			'product_attribute' => $this->security->xss_clean($inp_attribute), 
		); 

		$query_product_attribute = $this->db->get_where("product_attributes",$data);

		$product_attributes_id = null;
		$output_text = "Varian ".$inp_attribute." & Atribut ".$inp_attribute_detail." berhasil dibuat";

		$this_fill = '';
		if ($query_product_attribute->num_rows()>0) { 
			$product_attributes_id = $query_product_attribute->row()->id;

			$data = array(
				'attribute_detail' => $this->security->xss_clean($inp_attribute_detail), 
				"product_attribute_id" =>$product_attributes_id,
			);

			$query_product_attribute_detail = $this->db->get_where("product_attributes_detail",$data);

 			if ($query_product_attribute_detail->num_rows() == 0) {  

				$this->db->insert('product_attributes_detail', $data);
				$output_text = "Varian ".$inp_attribute." berhasil menambahkan Atribut ".$inp_attribute_detail;
 			}else{
				$output_text = "Varian ".$inp_attribute." Atribut ".$inp_attribute_detail." ini sudah pernah di buat."; 
 			}

		}else{ 
			$this->db->insert('product_attributes', $data);
			$product_attributes_id = $this->db->insert_id();

			$data = array(
				'attribute_detail' => $this->security->xss_clean($inp_attribute_detail), 
				"product_attribute_id" =>$product_attributes_id,
			); 
			$this->db->insert('product_attributes_detail', $data);
			
			$this_fill .= "<option value='".$product_attributes_id."'>".ucwords($inp_attribute)."</option>";
		}  

		// $this->db->select('*')->from('product_attributes')
		// ->order_by('priority', 'ASC');
  //   	$variants = $this->db->get()->result(); 
    	
    	// foreach ($variants as $key) {
    	// 	$this_fill .= "<option value='".$key->id."'>".ucwords($key->product_attribute)."</option>";
    	// }

    	echo json_encode(array(
    		"this_fill"=>$this_fill,
    		"output_text"=>$output_text,
    		"current_id_varian"=>$product_attributes_id,
	    	"res"=>"sukses",  
    	));
    }

    //to edit size in admin
	function edit($id = NULL) {

		if ($id == NULL) {
			//create new attribute
			$this->data['attribute'] = $this->product_attributes_m->get_new();

			//get ordering number 
			$this->db->select_max('priority')->from('product_attributes'); 
			$current_priority = $this->db->get()->row()->priority;
			if($current_priority == NULL) {
				$this->data['attribute']->priority = 1;	
			} else {
				$this->data['attribute']->priority = $current_priority + 1;
			}
		} else {
			//check if id exist. If not exist, redirect to add new
			$count = $this->product_attributes_m->count_exist($id);
			if ($count == 0) { redirect(base_url('admin/product_attributes/edit')); } 	

			$this->data['attribute'] = $this->product_attributes_m->get($id);	

			$this->attribute_current_id = (int) $id;
		}


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

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

			if($this->attribute_current_id == NULL) {
				$this->product_attributes_m->add_attribute($data);
				$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Atribut berhasil dibuat</p>');
				redirect('admin/product_attributes');

			} else {
				$this->product_attributes_m->edit_attribute($id, $data); 
				$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Atribut berhasil diedit</p>');
				redirect('admin/product_attributes/edit/' .  $id);
			} 	
		} 
		
		$this->data['subview'] = 'admin/product_attributes/edit';
		$this->load->view('admin/templates/header', $this->data_header); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer');
	}

	//callback function validation add new size
	function _cek_existing_attribute($str) {

		if(empty($str)) {
			$this->form_validation->set_message('_cek_existing_attribute', 'Nama Varian Indonesia tidak boleh kosong');
			return FALSE;
		}

		$num_rows = $this->product_attributes_m->cek_existing_attribute($str, $this->attribute_current_id);   
		if ($num_rows != 0 ) { 
			$this->form_validation->set_message('_cek_existing_attribute', 'Nama varian Indonesia sudah terdaftar !');
			return FALSE;
		} else {
			return TRUE;   
		}
	}

	//callback function validation add new size
	function _cek_existing_attribute_en($str) {

		if(empty($str)) {
			$this->form_validation->set_message('_cek_existing_attribute_en', 'Nama Varian Inggris tidak boleh kosong');
			return FALSE;
		}

		$num_rows = $this->product_attributes_m->cek_existing_attribute_en($str, $this->attribute_current_id);   
		if ($num_rows != 0 ) { 
			$this->form_validation->set_message('_cek_existing_attribute_en', 'Nama varian Inggris sudah terdaftar !');
			return FALSE;
		} else {
			return TRUE;   
		}
	}

	private function table_data_processing() {

		$data = array(
			'product_attribute' => $this->security->xss_clean($this->input->post('attribute')),
			'product_attribute_en' => $this->security->xss_clean($this->input->post('attribute_en')),
			'is_color' => $this->security->xss_clean($this->input->post('is_color')),
			'priority' => $this->security->xss_clean($this->input->post('priority'))
		);
		return $data;
	}

	//to delete a size
	function delete($id) {

		if($id == NULL) redirect(base_url('admin/product_attributes'));
		//check if id exist. 
		$count = $this->product_attributes_m->count_exist($id);
		if ($count == 0) { redirect(base_url('admin/product_attributes')); }	
		
		$this->product_attributes_m->delete($id);

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

	/*-----ATTRIBUTES DETAIL----------*/

	function view_detail($attribute_id = NULL) {

		if($attribute_id == NULL) redirect(base_url('admin/product_attributes'));
		//check if id exist. 
		$count = $this->product_attributes_m->count_exist($attribute_id);
		if ($count == 0) { redirect(base_url('admin/product_attributes')); }	

		//Add pagination
		$this->load->helper('pagination_helper'); 
		add_pagination(base_url() . 'admin/product_attributes/view_detail', $this->product_attributes_m->record_count_detail($attribute_id), 6, 4);

   		$this->data['details'] = $this->product_attributes_m->get_all_attribute_details($attribute_id); 

   		//pass to view, attribute name and id
   		$this->data['attribute_id'] = $attribute_id;
   		$this->db->select('product_attribute')->from('product_attributes')->where('id', $attribute_id);
   		$this->data['attribute_name'] = $this->db->get()->row()->product_attribute;
		
		//load view
		$this->data['subview'] = 'admin/product_attributes/detail_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 edit_detail($attribute_id = NULL, $detail_id = NULL) {

		if($attribute_id == NULL && $detail_id == NULL) redirect(base_url('admin/product_attributes'));

		if($attribute_id != NULL && $detail_id == NULL) {

			//add new detail
			$count = $this->product_attributes_m->count_exist($attribute_id);
			if ($count == 0) { redirect(base_url('admin/product_attributes')); }

			$this->data['detail'] = $this->product_attributes_m->get_new_detail();	

			$this->data['detail']->product_attribute_id = $attribute_id;

			//get ordering number 
			$this->db->select_max('priority')->from('product_attributes_detail'); 
			$current_priority = $this->db->get()->row()->priority;
			if($current_priority == NULL) {
				$this->data['detail']->priority = 1;	
			} else {
				$this->data['detail']->priority = $current_priority + 1;
			}

		} elseif($attribute_id != NULL && $detail_id != NULL) {
			
			//edit current detail
			$count_attribute = $this->product_attributes_m->count_exist($attribute_id);
			if ($count_attribute == 0) { redirect(base_url('admin/product_attributes')); }

			$count_detail = $this->product_attributes_m->count_exist_detail($attribute_id, $detail_id);

			if ($count_detail == 0) { redirect(base_url('admin/product_attributes/view_detail/' . $attribute_id)); }

			//get attributes
			$this->db->select('*');
	        $this->db->from('product_attributes_detail');
	        $this->db->where('id', $detail_id);
	        $this->data['detail'] = $this->db->get()->row();

			$this->attribute_detail_current_id = $detail_id;	
		}

		//validation check
		$config = $this->product_attributes_m->detail_rules; 
		$this->form_validation->set_rules($config); 
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

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

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

				$config['upload_path'] = './uploads/varian/'; 
				$config['allowed_types'] = 'jpg|png'; 
				$config['max_size']	= '200';
				// $config['max_width']  = '200';
				// $config['max_height'] = '200';
				
				$this->load->library('upload', $config); 

				if ( ! $this->upload->do_upload('image1')) {
	                //echo $this->upload->display_errors(); die();
					$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($this->attribute_detail_current_id == NULL) {
						redirect('admin/product_attributes/edit_detail/' . $attribute_id);
					} else {
						redirect('product_attributes/edit_detail/'. $attribute_id . '/' . $detail_id);
					}	
				} else {
					$image1 = $this->upload->data();
					$image1_filename = $image1['file_name']; 

					$this->resize_single_image('200','200','varian/',$image1_filename);	 
				}	
			}  

			
			$data = array(
				'attribute_detail' => $this->security->xss_clean($this->input->post('attribute_detail')),
				'attribute_detail_en' => $this->security->xss_clean($this->input->post('attribute_detail_en')),
				'product_attribute_id' => $attribute_id,
				'priority' => $this->security->xss_clean($this->input->post('priority'))
			);

			$query_attribute = $this->db->get_where('product_attributes',array('id'=>$this->data['detail']->product_attribute_id));

			$is_color = 'no';
			if ($query_attribute->num_rows()>0) {
				$is_color = $query_attribute->row()->is_color;
			}

			if ($is_color == 'yes') {
				$data['color_hex'] = $this->security->xss_clean($this->input->post('color_hex'));
			}

			if (isset($image1_filename)) {
				$data['image'] = $image1_filename;
			} 

			if($this->attribute_detail_current_id == NULL) {

				$this->product_attributes_m->add_attribute_detail($data);  

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

				redirect('admin/product_attributes/view_detail/' . $attribute_id);

			} else {

				$this->product_attributes_m->edit_attribute_detail($detail_id, $data); 

				$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Atribut detail berhasil diubah</p>');
				
				redirect('admin/product_attributes/view_detail/' . $attribute_id);	
			}	
		} 

		$this->data['attribute_id'] = $attribute_id; 

		$this->db->select('product_attribute')->from('product_attributes')->where('id', $attribute_id);
		$this->data['product_attribute'] = $this->db->get()->row()->product_attribute; 
		
		$this->data['subview'] = 'admin/product_attributes/detail_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 _cek_existing_detail_title($str) {

		$num_rows = $this->product_attributes_m->cek_existing_detail_title($str, $this->attribute_detail_current_id);    

		if ($num_rows != 0 ) { 
			$this->form_validation->set_message('_cek_existing_detail_title', 'detail Atribut Indonesia sudah terdaftar !');
			return FALSE;
		} else {
			return TRUE;   
		}
	}

	public function _cek_existing_detail_title_en($str) {

		if(empty($str)) {
			$this->form_validation->set_message('_cek_existing_detail_title_en', 'Detail Atribut Inggris tidak boleh kosong');
			return FALSE;
		}

		$num_rows = $this->product_attributes_m->cek_existing_detail_title_en($str, $this->attribute_detail_current_id);    

		if ($num_rows != 0 ) { 
			$this->form_validation->set_message('_cek_existing_detail_title_en', 'detail Atribut Inggris sudah terdaftar !');
			return FALSE;
		} else {
			return TRUE;   
		}
	}

	public function delete_detail($detail_id) { 

		//get attribute id
		$this->db->select('product_attribute_id')->from('product_attributes_detail')->where('id', $detail_id);
        $attribute_id = $this->db->get()->row()->product_attribute_id; 	

		//delete detail
		$this->db->where('id', $detail_id);
		$this->db->delete('product_attributes_detail');

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

https://t.me/RX1948 - 2025