| Server IP : 162.214.74.102 / Your IP : 216.73.217.80 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/public_html/lrsys_projetos/sopizzas/application/controllers/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
session_start(); //we need to call PHP's session object to access it through CI
class CouponRestaurant extends MY_Restaurant {
function __construct()
{
parent::__construct();
$this->load->helper("url");
$this->load->helper('form');
$this->load->library('form_validation');
$this->load->library('javascript');
$this->load->library('Ajax_pagination');
$this->perPage = ROW_PER_PAGE;
$this->load->model('coupon_model');
$session_data = $this->session->userdata('logged_in');
//if(empty($session_data)) { redirect('superadmin', 'refresh'); }
if($this->session->userdata('user_language'))
{
$language = $this->session->userdata('user_language');
}
else
{
$language = $this->config->item("language");
}
$data['user_language'] = $language;
$this->lang->load('restaurantAdmin', $language);
}
function index( $offset = 0 )
{
/*echo "<pre>";
print_r ($this->input->post());
echo "</pre>";
exit();*/
if ($this->input->server('REQUEST_METHOD') == 'POST')
{
if ($this->input->post('EditId') == '') {
$this->addCoupon();
}
else if($this->input->post('EditId') != '') {
$this->editCoupon();
}
}else
{
$this->showCouponList();
}
}
function showCouponList() {
$SearchBy = '';
$PerPage = $this->input->post('Per_Page');
if(!$PerPage){
$PerPage = $this->perPage;
}else{
$PerPage = $PerPage;
}
$session_data = $this->session->userdata('logged_in_restaurant');
$restaurant_id = $session_data['id'];
//total rows count
$totalRec = count($this->coupon_model->get_coupon_list_for_restaurant());
//pagination configuration
$config['target'] = '#postList';
$config['base_url'] = base_url().'couponrestaurant/ajaxPaginationDataCoupon/'.$SearchBy;
$config['total_rows'] = $totalRec;
$config['per_page'] = $PerPage;
$this->ajax_pagination->initialize($config);
//get the posts data
$data['CouponList'] = $this->coupon_model->get_coupon_list_for_restaurant(array('limit'=>$PerPage), $SearchBy);
$data['title']="Coupon";
$data['page']="coupon";
$this->load->view('restaurantadmin/header',$data);
$this->load->view('restaurantadmin/main-sidebar');
$this->load->view('restaurantadmin/coupon',$data);
$this->load->view('restaurantadmin/footer');
}
function ajaxPaginationDataCoupon(){
$page = $this->input->post('page');
if(!$page){
$offset = 0;
}else{
$offset = $page;
}
$action = $this->input->post('action');
/*if(!$action){
$action = '';
}else{
$action = $action;
}*/
$perpage = $this->input->post('per_page');
if(!$perpage){
$perpage = $this->perPage;
}else{
$perpage = $perpage;
}
$action2 = $this->input->post('action2');
if(!$action2){
$action2 = '0';
}else{
$action2 = $action2;
}
//total rows count
$totalRec = count($this->coupon_model->get_coupon_list_for_restaurant($params = array(), $action,$action2));
//pagination configuration
$config['target'] = '#postList';
$config['base_url'] = base_url().'couponrestaurant/ajaxPaginationDataCoupon';
$config['total_rows'] = $totalRec;
$config['per_page'] = $perpage;
$config['action'] = $action;
$config['action2'] = $action2;
$this->ajax_pagination->initialize($config);
//get the posts data
$data['CouponList'] = $this->coupon_model->get_coupon_list_for_restaurant(array('start'=>$offset,'limit'=>$perpage),$action,$action2);
$data['title']="Coupon";
$data['page']="coupon";
$data['perPageCount'] = $page;
/*** Remember what was the last page start ***/
if ($this->input->post('pagination') != '') {
$myPage = $this->input->post('page');
$myAction = $this->input->post('action');
$myPerPage = $this->input->post('per_page');
$myAction2 = $this->input->post('action2');
$paginationArray = array('page' => $myPage, 'action' => $myAction, 'per_page' => $myPerPage, 'action2' => $myAction2, 'page_name' => $data['page'], 'pagination' => $this->input->post('pagination'));
if ($this->session->userdata('paginationArray')) {
$this->session->unset_userdata('paginationArray');
}
$this->session->set_userdata('paginationArray', $paginationArray);
}
/*** Remember what was the last page end ***/
$this->load->view('restaurantadmin/coupon-list-ajax', $data, false);
}
function addCoupon() {
/*echo "<pre>";
print_r ($this->input->post());
echo "</pre>";
exit();*/
if($this->session->userdata('logged_in_restaurant')){
$session_data = $this->session->userdata('logged_in_restaurant');
$restaurant_id = $session_data['id'];
}else{
$restaurant_id = 0;
}
$now = date('Y-m-d H:i:s');
$this->form_validation->set_rules('coupon_code', 'Coupon Code', 'trim|required|xss_clean|callback_isCouponExist');
$this->form_validation->set_message('is_unique', 'Coupon Code already exist');
$this->form_validation->set_rules('offer_valid_from', 'Coupon Valid From', 'required|xss_clean|callback_isTimeOk');
$this->form_validation->set_rules('offer_valid_to');
$this->form_validation->set_rules('offer_percentage');
if ($this->input->post('offer_percentage') == '' && $this->input->post('offer_price') == '') {
$this->form_validation->set_rules('offer_price', 'Offer value', 'trim|required|xss_clean');
}
else {
$this->form_validation->set_rules('offer_price');
}
if ($this->form_validation->run() == FALSE) {
$this->showCouponList();
}
else {
$date1 = str_replace('/', '-', $this->input->post('offer_valid_from'));
$date_array = explode('-', $date1);
$date1 = $date_array[1]."-".$date_array[0]."-".$date_array[2];
$offer_valid_from = date("Y-m-d", strtotime($date1));
$date2 = str_replace('/', '-', $this->input->post('offer_valid_to'));
$date_array = explode('-', $date2);
$date2 = $date_array[1]."-".$date_array[0]."-".$date_array[2];
$offer_valid_to = date("Y-m-d", strtotime($date2));
$this->db->trans_start();
$data_in = array(
'coupon_code' => $this->input->post('coupon_code'),
'offer_percentage' => $this->input->post('offer_percentage'),
'offer_price' => $this->input->post('offer_price'),
'offer_valid_from' => $offer_valid_from,
'offer_valid_to' => $offer_valid_to,
'addeddate' => $now,
'restaurant_id' => $restaurant_id
);
$this->db->insert('rt_restaurant_offer', $data_in);
$this->db->trans_complete();
$this->session->set_flashdata('success_msg', $this->input->post('coupon_code').' is successfully added');
redirect('restaurantadmin/coupon');
}
}
function editCoupon() {
$EditId = $this->input->post('EditId');
$this->form_validation->set_rules('coupon_code', 'Coupon Code', 'trim|required|xss_clean|callback_isCouponExist');
$this->form_validation->set_rules('offer_valid_from');
$this->form_validation->set_rules('offer_valid_to');
$this->form_validation->set_rules('offer_percentage');
$this->form_validation->set_rules('offer_price');
if ($this->form_validation->run() == FALSE) {
$this->showCouponList();
}
else {
$date1 = str_replace('/', '-', $this->input->post('offer_valid_from'));
$date_array = explode('-', $date1);
$date1 = $date_array[1]."-".$date_array[0]."-".$date_array[2];
$offer_valid_from = date("Y-m-d", strtotime($date1));
$date2 = str_replace('/', '-', $this->input->post('offer_valid_to'));
$date_array = explode('-', $date2);
$date2 = $date_array[1]."-".$date_array[0]."-".$date_array[2];
$offer_valid_to = date("Y-m-d", strtotime($date2));
//echo $date1." ".$date2."<br>";
//echo $offer_valid_from." ".$offer_valid_to."<br>"; exit();
$this->db->trans_start();
$data_up = array(
'coupon_code' => $this->input->post('coupon_code'),
'offer_percentage' => $this->input->post('offer_percentage'),
'offer_price' => $this->input->post('offer_price'),
'offer_valid_from' => $offer_valid_from,
'offer_valid_to' => $offer_valid_to
);
$this->db->where('offer_id', $EditId);
if ($this->session->userdata('logged_in_restaurant')) {
$RestaurantIdField = 'restaurant_id';
$this->db->where($RestaurantIdField, $this->session->userdata('logged_in_restaurant')['id']);
}
$this->db->update('rt_restaurant_offer', $data_up);
$this->db->trans_complete();
$this->session->set_flashdata('success_msg', $this->input->post('coupon_code').' is successfully updated');
redirect('restaurantadmin/coupon');
}
}
function isCouponExist() {
if($this->session->userdata('logged_in_restaurant')){
$session_data = $this->session->userdata('logged_in_restaurant');
$restaurant_id = $session_data['id'];
}else{
$restaurant_id = 0;
}
$coupon_code = $this->input->post('coupon_code');
$offer_id = $this->input->post('EditId');
$is_exist = $this->coupon_model->isCouponExist($offer_id, $coupon_code, $restaurant_id);
if ($is_exist) {
$this->form_validation->set_message('isCouponExist', 'Coupon Code already exist');
return false;
}
else {
return true;
}
}
function isTimeOk() {
$date1 = str_replace('/', '-', $this->input->post('offer_valid_from'));
$date_array = explode('-', $date1);
$date1 = $date_array[1]."-".$date_array[0]."-".$date_array[2];
$offer_valid_from = date("Y-m-d", strtotime($date1));
$date2 = str_replace('/', '-', $this->input->post('offer_valid_to'));
$date_array = explode('-', $date2);
$date2 = $date_array[1]."-".$date_array[0]."-".$date_array[2];
$offer_valid_to = date("Y-m-d", strtotime($date2));
if ($offer_valid_from > $offer_valid_to) {
$this->form_validation->set_message('isTimeOk', 'Coupon Code Expire time should be greater than starting time.');
return false;
}
else {
return true;
}
}
}