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/kanvakanva.com/public_html/application/controllers/admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //var/www/kanvakanva.com/public_html/application/controllers/admin/Categories.php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Categories extends Admin_Controller {

	//this property is used for validating existing category title on call back edit category
	protected $category_current_id; 
		
	function __construct() {
		parent::__construct();	
		$this->load->model('category_m');
		$this->load->model('product_m');
	}
		
	//this is to list all categories 
	public function index() {
		
		//pagination in action. 50 results per page
		$this->load->library('pagination');
		$config['base_url'] = base_url() . 'admin/categories/index';
		$config['per_page'] = 50;
		$config["uri_segment"] = 4;
		$config['num_tag_open'] = '<span style="padding-left:10px; padding-right:10px">';
		$config['num_tag_close'] = '</span>';

		//fetch all categories
		$config['total_rows'] = $this->category_m->record_count();  
		$this->pagination->initialize($config);
   		$this->data['categories'] = $this->category_m->get_all_categories($config["per_page"], 
		$this->uri->segment(4)); 
	
		//load view
		$this->data['subview'] = 'admin/categories/index';
		$this->load->view('admin/templates/header', $this->data); 
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer', $this->data);		
    }
	
	//to add a new category 
	public function add() {
	
		$this->data['categories'] = $this->category_m->get_new();  
		$this->data['parent_categories'] = $this->category_m->get_parent_categories();
		
		//validation in action
		//validation check in action 
		$config = $this->category_m->rules;
		$this->form_validation->set_rules($config);   
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

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

			$image_filename = $this->image_processing($_FILES['userfile']['size']);

			$data = $this->table_data_processing($this->input->post('category_name'), $this->input->post('status'), $this->input->post('description'), $image_filename, $this->input->post('priority'), $this->input->post('parent_id'), $this->input->post('meta_description'), $this->input->post('meta_keywords'));

			$this->category_m->add_category($data); 

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

			redirect('admin/categories');
			
		} 
		
		$this->data['subview'] = 'admin/categories/edit';
		$this->load->view('admin/templates/header', $this->data);
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer', $this->data);	
	}
	
	//to edit category in admin
	public function edit($id = NULL) {

		//check if id exist. If not exist, show 404.
		$count = $this->category_m->count_exist($id);
		
		if ($count == 0) { 
			//page not exist 
			show_404();
		}		

		$this->data['categories'] = $this->category_m->get($id);
		
		$this->data['parent_categories'] = $this->category_m->get_parent_categories();	

		$this->category_current_id = (int) $this->data['categories']->id_categories;

		//validation check in action
		$config = $this->category_m->rules;

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

		if($this->form_validation->run() == TRUE) {
			
			$image_filename = $this->image_processing($_FILES['userfile']['size']);

			$data = $this->table_data_processing($this->input->post('category_name'), $this->input->post('status'), $this->input->post('description'), $image_filename, $this->input->post('priority'), $this->input->post('parent_id'), $this->input->post('meta_description'), $this->input->post('meta_keywords'));

			$this->category_m->edit_category($id, $data); 

			$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Category Edit Successful</p>');
			
			redirect('admin/categories/edit/' .  $id);
		} 
		
		$this->data['subview'] = 'admin/categories/edit';
		$this->load->view('admin/templates/header', $this->data);
		$this->load->view('admin/_layout_main', $this->data);
		$this->load->view('admin/templates/footer', $this->data);	
	}
	

	//to delete a category
	public function delete($id) {

		//check if id exist. If not exist, show 404.
		$count = $this->category_m->count_exist($id);
		
		if ($count == 0) { 
			//page not exist 
			show_404();
		}	

		//delete image from server
		//check if there is an existing image
		$this->db->select('image')->from('categories')->where('id_categories', (int) $id);
		$image = $this->db->get()->row();
		
		if ($image->image != '' || $image->image != NULL) {
			
			//Delete the actual image file from server. FCPATH is codeigniter base path
			unlink(FCPATH .'/uploads/category/'. $image->image);
		}	

		//check if there are child categories belong to this parent category. if yes, set the parent category to NULL
		$this->db->select('id_categories')->from('categories')->where('parent', $id);
		$count_child_categories = $this->db->get()->num_rows();

		if ($count_child_categories > 0) {
			
			//child categories exist, then set their parent to NULL
			$this->db->select('id_categories')->from('categories')->where('parent', $id);
			$child_categories = $this->db->get()->result();

			foreach ($child_categories as $child_category) {

				$data = array(
                	'parent' => NULL,	
            	);

				$this->db->where('id_categories', $child_category->id_categories);
				$this->db->update('categories', $data); 
			}
		}

		//delete parent category
		$this->category_m->delete($id);

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

	//image upload processing
	private function image_processing($image_file_size) {

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

		//check & processing image banner upload files	
		if ($image_file_size !== 0) {  	

			$config['upload_path'] = './uploads/category/'; 
			$config['allowed_types'] = 'png|jpg';  
			$config['max_size']	= '500';
			$config['max_width']  = $image_dimension->category_image_width;
			$config['max_height']  = $image_dimension->category_image_height;
			
			$this->load->library('upload', $config); 

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

                //echo $this->upload->display_errors(); die();
					
				$this->session->set_flashdata('error', '<br>
					<p style="background:orange; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');

				if ($this->category_current_id != NULL) {
					redirect('admin/categories/edit/' . $this->category_current_id);
				} else {
					redirect('admin/categories/add');
				}
			
			} else {

			$image = $this->upload->data();
			$image_filename = $image['file_name']; 	 

			return $image_filename; 

			}	
		}
	}

	private function table_data_processing($category_name, $status, $description, $image_filename, $priority, $parent_id, $meta_description, $meta_keywords) {

		$data = array(
				'category' 		=> $this->security->xss_clean($category_name),
				'alias' 		=> url_title($category_name),
				'status' 		=> $status,
				'description' 	=> $description,
				'priority' 		=> $priority,
				'meta_description' => $meta_description,
				'meta_keywords' => $meta_keywords,
		);

		if ($parent_id == 'no-parent') {
			$data['parent'] = NULL;
		} else {
			$data['parent'] = (int) $parent_id;
		}

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

		return $data;
	}

	//callback function validation add new category
	//make it private by adding _
	public function _cek_existing_category_title($str) {

		$num_rows = $this->category_m->cek_existing_category_title($str, $this->category_current_id);   
		if ($num_rows != 0 ) {  
			$this->form_validation->set_message('_cek_existing_category_title', 'category name already exist !');
			return FALSE;
		} else {
			return TRUE;  
		}
	}

	//To delete category image file from server, and from database
	public function delete_image($id = NULL) { 

		$count = $this->category_m->count_exist($id);

		if ($id == NULL || $count == 0) {	
			redirect('admin/categories');
		}

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

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

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

		$this->db->where('id_categories', (int) $id);
		$this->db->update('categories', $data);	

		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Image Delete Successful</p>');
		
		redirect('admin/categories/edit/' . $id); 
	}
	
		
}

https://t.me/RX1948 - 2025