Sindbad~EG File Manager

Current Path : /proc/thread-self/cwd/application/controllers/
Upload File :
Current File : //proc/thread-self/cwd/application/controllers/Promos.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once("Secure_Controller.php");

class Promos extends Secure_Controller
{
	public function __construct()
	{
		parent::__construct('Promos');
		$this->load->model('Promo'); //panggil model
	}

	public function index ()  //tampilan awal
	{
		$data['controller_name'] = 'promos';
		$data['table_headers'] = 'Promo, Mulai, Selesai, Hari';
		$data['item'] = $this->Promo->get_data_item();
		$data['dt_promo'] = $this->Promo->get_data_promo(); //var buat mangil db di view
		$this->load->view('promos/form', $data);
	}

	public function search()
	{
		$search = $this->input->get('search');
		$limit  = $this->input->get('limit');
		$offset = $this->input->get('offset');
		$sort   = $this->input->get('sort');
		$order  = $this->input->get('order');

		$promos = $this->Promo->search($search, $limit, $offset, $sort, $order);
		$total_rows = $this->Promo->get_found_rows($search);

		$data_rows = array();
		foreach($promos->result() as $promo)
		{
			$data_rows[] = $this->xss_clean(get_promo_data_row($promo));
		}

		echo json_encode(array('total' => $total_rows, 'rows' => $data_rows));
	}
	
	public function suggest_search()
	{
		$suggestions = $this->xss_clean($this->Promo->get_search_suggestions($this->input->post('term')));

		echo json_encode($suggestions);
	}



	// public function delete()
	// {
	// 	$promos_to_delete = $this->xss_clean($this->input->post('id'));

	// 	if($this->Giftcard->delete_list($promos_to_delete))
	// 	{
	// 		echo json_encode(array('success' => TRUE, 'message' => $this->lang->line('promos_successful_deleted') . ' ' .
	// 						count($promos_to_delete).' '.$this->lang->line('promos_one_or_multiple')));
	// 	}
	// 	else
	// 	{
	// 		echo json_encode(array('success' => FALSE, 'message' => $this->lang->line('promos_cannot_be_deleted')));
	// 	}
	// }
	
	public function submit_promo_add()
	{
		$this->load->helper(['form', 'url']);

		// print_r($this->input->post());

		$this->load->library('form_validation');

		$this->form_validation->set_rules('promo_type', 'Promo Type', 'required');

		if ($this->form_validation->run() == FALSE)
		{
				//$this->load->view('myform');
				return $this->output
					->set_content_type('application/json')
					->set_output(json_encode([
						'status' => 'failed',
						'errors' => validation_errors()
					]));
		}
		else
		{
			$promo_day = json_encode($this->input->post('promo_day'));
			$persentase_discount = ($this->input->post('tipe_diskon') == 'persentase') ? $this->input->post('promo_discount_values') : 0;
			$price_discount = ($this->input->post('tipe_diskon') == 'price') ? $this->input->post('promo_discount_values') : 0;
			$promo_product_get_discount = $this->input->post('promo_product_get_discount');
			$promo_get_gift_product_id = ($this->input->post('promo_type') == 'Gift With Purchase') ? $this->input->post('promo_product_get_discount') : 0;
			$promo_tebus_murah_price = 0;
			$promo_tebus_murah_items = json_encode([]);
			$promo_time = '00:00:00';

			$promo = [
				'promo_type' => $this->input->post('promo_type'),
				'condition_product_id' => $this->input->post('condition_product_id'),
				'condition_min_purchase' => $this->input->post('condition_min_purchase'),
				'promo_get_persentase_discount' => $persentase_discount,
				'promo_get_price_discount' => $price_discount,
				'promo_product_get_discount' => $promo_product_get_discount,
				'promo_get_gift_product_id' => $promo_get_gift_product_id,
				'promo_tebus_murah_price' => $promo_tebus_murah_price,
				'promo_tebus_murah_items' => $promo_tebus_murah_items,
				'promo_day' => $promo_day,
				'promo_time' => $promo_time,
				'tipe_diskon' => $this->input->post('tipe_diskon'),
				'promo_start_date' => $this->input->post('promo_start_date'),
				'promo_expire_date' => $this->input->post('promo_expire_date'),
				'member_id' => $this->input->post('member_id'),
				'created_at' => date('Y-m-d')
			];

			$this->Promo->addPromo($promo);
				//$this->load->view('formsuccess');

			return $this->output
				->set_content_type('application/json')
				->set_output(json_encode([
					'status' => 'success',
				]));
		}
	}

	public function item_search()
	{
		$suggestions = array();
		$receipt = $search = $this->input->get('term') != '' ? $this->input->get('term') : NULL;

		if($this->sale_lib->get_mode() == 'return' && $this->Sale->is_valid_receipt($receipt))
		{
			// if a valid receipt or invoice was found the search term will be replaced with a receipt number (POS #)
			$suggestions[] = $receipt;
		}
		$suggestions = array_merge($suggestions, $this->Promo->get_search_suggestions($search, array('search_custom' => FALSE, 'is_deleted' => FALSE), TRUE));
		$suggestions = array_merge($suggestions, $this->Item_kit->get_search_suggestions($search));

		$suggestions = $this->xss_clean($suggestions);

		echo json_encode($suggestions);
	}

	public function hapus($id)
	{
		$this->Promo->hapus($id);

		if ($this->db->affected_rows() > 0) {
			$this->session->set_flashdata('sukses','Data berhasil dihapus');
    	} else {
    		$this->session->set_flashdata('error','Data tidak ditemukan');
    	}
    	redirect('Promos');
	}

	public function enable($id)
	{
		$this->Promo->enable($id);
    	redirect('Promos');
	}

	public function disable($id)
	{
		$this->Promo->disable($id);
    	redirect('Promos');
	}
	
}
?>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists