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/mesinpolesshinemate.com/application/controllers/admin/ |
Upload File : |
<?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->load->helper('rajaongkir'); } //this is to list all vouchers public function index() { //pagination in action. 300 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'] = 300; $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_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } //to add a new voucher public function add() { $this->data['vouchers'] = $this->voucher_m->get_new(); //get parent product categories $this->load->model('category_m'); $this->data['parent_categories'] = $this->category_m->get_parent_categories(); //get brands $this->db->select('id_brands, brand')->from('brands')->where('status', '1')->order_by('brand', 'ASC'); $this->data['brands'] = $this->db->get()->result(); //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($this) == 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('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->input->post('voucher_type'), $this->input->post('birthmonth'), $this->input->post('gender'), $this->input->post('promostart'), $this->input->post('promoend'), $this->input->post('provincepromo'), $this->input->post('quantitypromo') ); $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'); } //get all provinces data from provinces table $this->db->select('rajaongkir_province_id, province')->from('indonesia_provinces')->order_by('rajaongkir_province_id', 'ASC'); $this->data['provinces'] = $this->db->get()->result(); //load view $this->data['subview'] = 'admin/vouchers/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 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->load->model('category_m'); $this->data['parent_categories'] = $this->category_m->get_parent_categories(); //get brands $this->db->select('id_brands, brand')->from('brands')->where('status', '1')->order_by('brand', 'ASC'); $this->data['brands'] = $this->db->get()->result(); $this->data['vouchers'] = $this->voucher_m->get($id); //get all chosen (active) categories $active_categories = $this->data['vouchers']->categorypromo; if($active_categories != NULL) { $this->data['chosen_categories'] = array_filter(explode(',', $active_categories)); //array_filter to remove empty array element } //get all chosen (active) brands $active_brands = $this->data['vouchers']->brandpromo; if($active_brands != NULL) { $this->data['chosen_brands'] = array_filter(explode(',', $active_brands)); //array_filter to remove empty array element } $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($this) == 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('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->input->post('voucher_type'), $this->input->post('birthmonth'), $this->input->post('gender'), $this->input->post('promostart'), $this->input->post('promoend'), $this->input->post('provincepromo'), $this->input->post('quantitypromo') ); $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); } //get all provinces data from provinces table $this->db->select('rajaongkir_province_id, province')->from('indonesia_provinces')->order_by('rajaongkir_province_id', 'ASC'); $this->data['provinces'] = $this->db->get()->result(); //load view $this->data['subview'] = 'admin/vouchers/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 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, $qty_ready, $maxqty_per_person, $min_order, $discount_type, $discount_value, $created_date, $new_expired_date, $voucher_type, $birthmonth, $gender, $promostart, $promoend, $provincepromo, $quantitypromo) { $data = array( 'voucher_name' => $this->security->xss_clean($voucher_name), 'voucher_code' => $this->security->xss_clean($voucher_code), 'discount_type' => $discount_type, 'discount_value' => (int) $this->security->xss_clean($discount_value), 'created_date' => $created_date, 'expired_date' => $new_expired_date, 'voucher_type' => $voucher_type, 'birthmonth' => $birthmonth, 'gender' => $gender, 'promostart' => $promostart, 'promoend' => $promoend, 'provincepromo' => $provincepromo, 'quantitypromo' => $quantitypromo ); 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); } //Promo by Product Category //get category_id from view, $categories_id = $this->input->post('category_id'); //check id there is content inside category array $categories_id_count = count($categories_id); if ($categories_id_count > 0) { $data['categorypromo'] = implode(',',$categories_id); } else { $data['categorypromo'] = NULL; } //Promo by Brand //get brand_id from view, $brands_id = $this->input->post('brand_id'); //check id there is content inside brand array $brands_id_count = count($brands_id); if ($brands_id_count > 0) { $data['brandpromo'] = implode(',', $brands_id); } else { $data['brandpromo'] = NULL; } 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; } } }