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 :  /proc/self/root/var/www/kanvakanva.com/public_html/application/controllers/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

class Cart extends Public_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model('cart_model');   
		$this->load->model('product_m'); 
		$this->load->library('form_validation');
		$this->load->library('cart');
		$this->load->model('customer_m');
		$this->load->helper('rajaongkir');
	}

	public function index($carrier = NULL) 
	{	
		if ($this->customer_m->loggedin() == false) {
			redirect('register');
		}
		
		//get SEO
		$this->db->select('website_name, meta_keywords')->from('configuration')->where('id_configuration', 1);
		$website_name = $this->db->get()->row();
		$this->data_header['browser_title'] =  ucwords($website_name->website_name) . ' - My Cart'; 
		$this->data_header['meta_description'] = ucwords($website_name->website_name) . ' - My Cart';
		$this->data_header['meta_keywords'] = $website_name->meta_keywords;

		if (!$this->cart->contents()){
			
			$data['message'] = '<p style="background:#564E52; color:white; padding:10px; margin-bottom:100px;">Your cart is empty</p>';
		
		} else {
		
			$data['message'] = $this->session->flashdata('message');
		}

		$id_customer = (int) $this->session->userdata('customer')['customer_id'];
		//get customer detail
		$data['shipping'] = $this->customer_m->get_shipping($id_customer);

		//get address customer
		$data['address'] = $this->customer_m->get_shipping_address($id_customer);

		switch ($carrier) {
			case 'sicepat_reguler':
				$data['carrier'] = 'sicepat';
				$data['code_carrier'] = 'sicepat_reguler';
				$data['carrier_name'] = 'SICEPAT REG';
				break;
			case 'sicepat_best':
				$data['carrier'] = 'sicepat';
				$data['code_carrier'] = 'sicepat_best';
				$data['carrier_name'] = 'SICEPAT BEST';
				break;
			default:
				$data['carrier'] = 'sicepat';
				$data['code_carrier'] = 'sicepat_reguler';
				$data['carrier_name'] = 'SICEPAT REG';
				break;
		}

		$data['carrier'] = 'jne';
		$data['code_carrier'] = 'jne_reguler';
		$data['carrier_name'] = 'JNE REG';

		$this->load->view('template/header', $this->data_header);
		$this->load->view('cart', $data);
		$this->load->view('template/footer', $this->data_footer);
	}

	public function add()  
	{
		//check if there is post request, if not, reject & redirect
		if (empty($_POST)) {
			redirect('cart'); 
		}

		//validation in action
		//validation check in action
		
		$config = array( 
            array(
                 'field'   => 'product_size', 
                 'label'   => 'product Size',
                 'rules'   => 'trim|required|callback_cek_stock'
              ),
            );
		$this->form_validation->set_rules($config); 
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

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

			//get options name
			$this->db->select('product_size')->from('product_size')->where('id_product_size', $this->input->post('product_size'));
			$data['options']['size'] = $this->db->get()->row()->product_size;

			$data['id'] = (int) $this->input->post('product_id');		
			$data['name'] = $this->input->post('product_name') . ' ' . $data['options']['size']; 
			$data['qty'] = (int) $this->input->post('qty');
			$data['price'] = (int) $this->input->post('price');
			$data['options']['size_id'] = $this->input->post('product_size');

			$data['options']['voucher_email'] = $this->security->xss_clean($this->input->post('voucher_email'));
			$data['options']['voucher_message'] = $this->security->xss_clean($this->input->post('voucher_message'));

			$this->cart->product_name_rules = '[:print:]'; //this is to eliminate cart product name restriction on special characters
			$this->cart->insert($data); 
				
			// redirect('cart');
			$this->db->select('alias');
			$this->db->from('products');
			$this->db->where('id_products', (int) $this->input->post('product_id'));
			$query = $this->db->get();
			$product_alias = $query->row();
			
			redirect(base_url() . 'product/' .  $product_alias->alias);
		
		} else {
			//get product alias
			$this->db->select('alias');
			$this->db->from('products');
			$this->db->where('id_products', (int) $this->input->post('product_id'));
			$query = $this->db->get();
			$product_alias = $query->row();

			$this->session->set_flashdata('no_stock', '<br>
				<p style="background:black; color:white; padding:5px; font-weight:bold;">Not enough stock for chosen size. Please choose other size.</p>');
			redirect(base_url() . 'product/' .  $product_alias->alias);
		}  
	}
	
	function remove($rowid) {
		if ($rowid=="all"){
			$this->cart->destroy();
		}else{
			$data = array(
				'rowid'   => $rowid,
				'qty'     => 0
			);

			$this->cart->update($data);
		}
		
		redirect('cart');
	}	

	function update_cart(){

		// Recieve post values,calcute them and update
		$cart_info = $_POST['cart'] ;
		
		foreach( $cart_info as $id => $cart) {

			// echo '<pre>';
			// print_r($cart);
			// echo '</pre>';
			// exit;	

			$rowid = $cart['rowid'];
			$price = $cart['price'];
			$amount = $price * $cart['qty'];
			$qty = $cart['qty'];
			$product_id = $cart['id'];	
			$size_id = $cart['size_id'];
	
			//get current stock froms stocks table
			$this->db->select('stock')->from('stocks')->where('size_id', $size_id)->where('product_id', $product_id);
			$current_stock = $this->db->get()->row()->stock;
		
			if($current_stock < $qty) {
				$this->session->set_flashdata('no_stock', "<br>
				<p style='background:black; color:white; padding:5px; font-weight:bold;'>Not enough stock for {$cart['name']}. Please choose other quantity.</p>");

				redirect('cart');
			} else {

				$data = array(
					'rowid' => $rowid,
					'price' => $price,
					'amount' => $amount,
					'qty' => $qty
					);
		
					$this->cart->update($data);
			}
		}

		redirect('cart');
	}

	//callback function validation cek stock available when add to cart
	public function cek_stock() {

		$product_size = $this->input->post('product_size'); 
		$product_id = (int) $this->input->post('product_id');	
		$quantity = (int) $this->input->post('qty');

		//get current stock froms stocks table
		$this->db->select('stock')->from('stocks')->where('size_id', $product_size)->where('product_id', $product_id);
		$stock = $this->db->get()->row();
		$current_stock = (int) $stock->stock;

		//check if quantity is less or equal to current stock
		if ($quantity > $current_stock) {
			return FALSE;
		
		} else {
			return TRUE;  
		}	
	
	}




}

https://t.me/RX1948 - 2025