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/Events.php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Events extends Admin_Controller {

	//this property is used for validating existing event title on call back edit event
	private $event_current_id = NULL;
	private $thumbnail_filename = NULL;

	function __construct() { 
		parent::__construct();	
		$this->load->model('event_m');
		$this->load->helper('form');
	}
		
	//this is to list all event
	public function index() {
		//pagination in action. 100 results per page 
		$this->load->library('pagination');
		$config['base_url'] = base_url() . 'admin/events/index';
        $config['total_rows'] = $this->event_m->record_count(); 
		$config['per_page'] = 100;
		$config["uri_segment"] = 4;
		$config['num_tag_open'] = '<span style="padding-left:10px; padding-right:10px">';
		$config['num_tag_close'] = '</span>';

		$this->pagination->initialize($config);
   		$this->data['events'] = $this->event_m->get_all_events($config["per_page"], $this->uri->segment(4));   

		//load view
		$this->data['subview'] = 'admin/events/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 event 
	public function add() {
		$this->data['event'] = $this->event_m->get_new();	
		//validation in action
		//validation check in action 
		$config = $this->event_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) {

			//check & processing IMAGE THUMBNAIL
			if ($_FILES['thumbnail']['size'] !== 0) { 	

				$config['upload_path'] = './uploads/page/'; 
				$config['allowed_types'] = 'jpg|png|jpeg'; 
				$config['max_size']	= '300'; 
				$config['max_width'] = '800';
				$config['max_height'] = '800';

				$this->load->library('upload', $config); 

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

                    // return the error message and kill the script
                    echo $this->upload->display_errors(); 

                    $this->session->set_flashdata('thumbnail-error', '<br>
                        <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');
                    redirect('admin/events/add');
				
				} else {
					$thumbnail = $this->upload->data();
					$thumbnail_filename = $thumbnail['file_name']; 
				} 
			}

			$data = $this->table_data_processing($thumbnail_filename);
		
			$this->event_m->add_event($data);

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

			redirect('admin/events');
        } 
		
		$this->data['subview'] = 'admin/events/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 event in admin
	public function edit($id = NULL) {

		if ($id == NULL) { show_404(); }

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

		$this->data['event'] = $this->event_m->get($id);	

		$this->event_current_id = (int) $id;

		//validation check in action
		$config = $this->event_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) {

			//check & processing IMAGE INTRO
			if ($_FILES['thumbnail']['size'] !== 0) { 	

				$config['upload_path'] = './uploads/page/'; 
				$config['allowed_types'] = 'jpg|png|jpeg'; 
				$config['max_size']	= '300'; 
				$config['max_width'] = '800';
				$config['max_height'] = '800';

				$this->load->library('upload', $config); 

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

				// return the error message and kill the script
     			echo $this->upload->display_errors(); 

				$this->session->set_flashdata('thumbnail-error', '<br>
					<p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>');
				redirect('admin/events/edit/' .  $id);
				
				} else {
					$thumbnail = $this->upload->data();
					$this->thumbnail_filename = $thumbnail['file_name']; 
				} 
			}

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

			$this->event_m->edit_event($id, $data); 

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

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

		//check if id exist. If not exist, show 404.
		$count = $this->event_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('thumbnail')->from('events')->where('id', (int) $id);
		$image = $this->db->get()->row();
		
		if ($image->thumbnail != '') {
			//Delete the actual image file from server. FCPATH is codeigniter base path
			unlink(FCPATH .'/uploads/page/'. $image->thumbnail);
		} 

		//delete event
		$this->event_m->delete($id); 

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

	private function table_data_processing($thumbnail) {

		$publish_date = explode('-',$this->input->post('publish_date'));	
		$publish_date = $publish_date[2] . '-' . $publish_date[1] . '-' . $publish_date[0];

		$data = array(
			'event' 			=> $this->security->xss_clean($this->input->post('event')),
			'alias' 		=> url_title($this->security->xss_clean($this->input->post('event'))),
			'status' 		=> $this->input->post('status'),
			'description' 	=> $this->security->xss_clean($this->input->post('description')),
			'publish_date' 	=> $publish_date
		);

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

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

		$num_rows = $this->event_m->cek_existing_event_title($str, $this->event_current_id);   
		if ($num_rows != 0 ) {  
			$this->form_validation->set_message('_cek_existing_event_title', 'event name already exist !');
			return FALSE;
		} else {
			return TRUE;   
		}
	}

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

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

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

		if ($image_type == NULL) {redirect('admin/events'); }

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

		if($image_type == 'thumbnail') {
			//Delete the actual image file from server. FCPATH is codeigniter base path
			unlink(FCPATH .'/uploads/page/'. $image->thumbnail);

			//Delete image field from database
			$data = array( 
				'thumbnail' => '',
			);
		} 
		$this->db->where('id', (int) $id);
		$this->db->update('events', $data);	

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

https://t.me/RX1948 - 2025