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 : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Reward_customer extends Admin_Controller { private $reward_current_id = NULL; function __construct() { parent::__construct(); $this->load->model('reward_customer_m'); $this->load->helper('form'); } public function index() { //pagination in action. 100 results per page $this->load->library('pagination'); $config['base_url'] = base_url() . 'admin/reward_customer/index'; $config['total_rows'] = $this->reward_customer_m->record_count(); $config['per_page'] = 100; $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['reward'] = $this->reward_customer_m->get_all_reward($config["per_page"], $this->uri->segment(4)); //load view $this->data['subview'] = 'admin/reward_customer/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); } public function add() { $this->data['reward'] = $this->reward_customer_m->get_new(); $this->data['products'] = $this->reward_customer_m->get_products(); //validation in action //validation check in action $config = $this->reward_customer_m->rules; $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 $this->form_validation->set_rules($config); if($this->form_validation->run($this) == TRUE) { $data = array( 'min_buy' => $this->input->post('min_buy'), 'point' => $this->input->post('point'), 'created_at'=> date("Y-m-d H:i:s"), ); $type = $this->input->post('type'); if($type == 'discount'){ $data['discount'] = $this->input->post('discount'); }else{ $data['id_products'] = $this->input->post('id_products'); $data['discount'] = 0; } $this->reward_customer_m->add_reward($data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Reward add Successful</p>'); redirect('admin/reward_customer'); } $this->data['subview'] = 'admin/reward_customer/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 reward in admin public function edit($id = NULL) { if ($id == NULL) { show_404(); } //check if id exist. If not exist, show 404. $count = $this->reward_customer_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } $this->data['reward'] = $this->reward_customer_m->get_edit($id); $this->db->select('id_products'); $this->db->from('reward_customer'); $this->db->where('id_reward_customer', $id); $id_products = $this->db->get()->row('id_products'); $this->data['products'] = $this->reward_customer_m->get_products($id_products); $this->reward_current_id = (int) $id; //validation check in action $config = $this->reward_customer_m->rules; $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 $this->form_validation->set_rules($config); if($this->form_validation->run($this) == TRUE) { $data = array( 'min_buy' => $this->input->post('min_buy'), 'point' => $this->input->post('point'), 'last_update'=> date("Y-m-d H:i:s"), ); $type = $this->input->post('type'); if($type == 'discount'){ $data['discount'] = $this->input->post('discount'); }else{ $data['id_products'] = $this->input->post('id_products'); $data['discount'] = 0; } $this->reward_customer_m->edit_reward($id, $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Reward Edit Successful</p>'); redirect('admin/reward_customer/edit/' . $id); } $this->data['subview'] = 'admin/reward_customer/edit'; $this->load->view('admin/templates/header', $this->data); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } //to delete a reward public function delete($id) { //check if id exist. If not exist, show 404. $count = $this->reward_customer_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } //delete testimony $this->reward_customer_m->delete($id); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Reward Delete Successful</p>'); redirect('admin/reward_customer'); } }