Backups Created:
/home/japatmex/public_html/wp-content/edit-wolf.php
Savvy
W
olf -
MANAGER
Edit File: Offers.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Offers extends MY_Controller { public function __construct(){ parent::__construct(); $this->load->model('Ecomm_model'); $this->load->helper('ecomm_helper'); } public function index($page = 1) { $this->data['page_title'] = 'Offers'; $this->data['current_page'] = 'Offers'; $category_id = (int)0; if($this->input->get('category_id')) { $category_id = $this->input->get('category_id'); } $row=$this->Ecomm_model->offers_list('id','DESC'); $config = array(); $config["base_url"] = base_url($this->config->item('apanel_name').'/ecomm/offers'); $config["total_rows"] = count($row); $config["per_page"] = 12; $config['num_links'] = 4; $config['use_page_numbers'] = TRUE; $config['reuse_query_string'] = TRUE; $config['enable_query_strings'] = TRUE; $config['page_query_string'] = FALSE; $config['full_tag_open'] = '<ul class="pagination">'; $config['full_tag_close'] = '</ul>'; $config['first_link'] = '<i class="fa fa-angle-double-left"></i>'; $config['first_tag_open'] = '<li>'; $config['first_tag_close'] = '</li>'; $config['last_link'] = '<i class="fa fa-angle-double-right"></i>'; $config['last_tag_open'] = '<li>'; $config['last_tag_close'] = '</li>'; $config['next_link'] = ''; $config['next_tag_open'] = '<span class="nextlink">'; $config['next_tag_close'] = '</span>'; $config['prev_link'] = ''; $config['prev_tag_open'] = '<span class="prevlink">'; $config['prev_tag_close'] = '</span>'; $config['cur_tag_open'] = '<li class="active"><a href="#">'; $config['cur_tag_close'] = '<span class="sr-only">(current)</span></a></li>'; $config['num_tag_open'] = '<li style="margin:3px">'; $config['num_tag_close'] = '</li>'; $this->pagination->initialize($config); $page=($page-1) * $config["per_page"]; if($this->input->post('search_value')!=''){ $keyword=addslashes(trim($this->input->post('search_value'))); $this->data['offers_list'] = $this->Ecomm_model->offers_list('id','DESC', '', '', $keyword); } else{ $this->data["links"] = $this->pagination->create_links(); $this->data['offers_list'] = $this->Ecomm_model->offers_list('id','DESC', $config['per_page'], $page); } $keyword=addslashes(trim($this->input->get('search_value'))); $row=$this->Ecomm_model->product_list_active_products('id','DESC', '', '', $keyword, $category_id); $this->data['products'] = $row; $this->data['categories_dropdown'] = category_dropdown(); $this->data['product'] = $row; $this->data['offer_list'] = $this->Ecomm_model->offers_list(); $this->data['view'] = 'admin/ecomm/offers'; $this->load->view('admin/layouts/default1', $this->data); } public function add() { $THEME = $rowSettings->Theme; $start_offer_date = ''; $end_offer_date = ''; if($this->input->method() == 'post') { $this->form_validation->set_rules('offer_title', 'Enter Offer Title', 'trim|required'); if($this->form_validation->run() == FALSE) { $messge = array('message' => $this->lang->line('input_required'),'class' => 'alert alert-danger'); $this->session->set_flashdata('response_msg', $messge); redirect(base_url($this->config->item('apanel_name').'/ecomm/offers/add').get_query_string()); } else { $config['upload_path'] = FCPATH . 'uplds'.$THEME.'/ecomm/images/offers/'; $config['allowed_types'] = 'jpg|png|jpeg'; $image = date('dmYhis').'_'.rand(0,99999).".".pathinfo($_FILES['file_name']['name'], PATHINFO_EXTENSION); $config['file_name'] = $image; $this->load->library('upload', $config); if (!$this->upload->do_upload('file_name')) { $messge = array('message' => $this->upload->display_errors(),'class' => 'alert alert-danger'); $this->session->set_flashdata('response_msg', $messge); redirect(base_url($this->config->item('apanel_name').'/ecomm/offers/add').get_query_string()); } else { $upload_data = $this->upload->data(); } $this->load->helper("date"); $slug = url_title($this->input->post('offer_title'), 'dash', TRUE); if(!empty($this->input->post('Start_offer_date')) || !empty($this->input->post('end_offer_date'))) { $start_offer_date = date('Y-m-d', strtotime($this->input->post('Start_offer_date'))); $end_offer_date = date('Y-m-d', strtotime($this->input->post('end_offer_date'))); } $data = array( 'offer_title' => $this->input->post('offer_title'), 'offer_slug' => $slug, 'offer_desc' => $this->input->post('offer_desc'), 'offer_percentage' => $this->input->post('offer_per') ?: 0, 'offer_fixed_amount' => $this->input->post('offer_fixed_amt') ?: 0, 'offer_image' => $image, 'start_offer_date' => $start_offer_date, 'end_offer_date' => $end_offer_date, 'created_at' => strtotime(date('d-m-Y h:i:s A')) ); $data = $this->security->xss_clean($data); if($this->common_model->insert($data, 'tbl_gf_ecomm_offers')){ $messge = array('message' => $this->lang->line('add_msg'),'class' => 'alert alert-success'); $this->session->set_flashdata('response_msg', $messge); } else{ $messge = array('message' => $this->lang->line('add_error'),'class' => 'alert alert-danger'); $this->session->set_flashdata('response_msg', $messge); } redirect(base_url($this->config->item('apanel_name').'/ecomm/offers/add').get_query_string()); } } $this->data['page_title'] = 'Offers'; $this->data['current_page'] = 'Add Offer'; $this->data['view'] = 'admin/ecomm/add_offer'; $this->load->view('admin/layouts/default1', $this->data); } public function edit($id) { $THEME = $rowSettings->Theme; $start_offer_date = ''; $end_offer_date = ''; if($this->input->method() == 'post') { $data = $this->Ecomm_model->single_offer($id); if($_FILES['file_name']['error']!=4){ if(file_exists(FCPATH . 'uplds'.$THEME.'/ecomm/images/offers/'.$data->offer_image)){ unlink(FCPATH . 'uplds'.$THEME.'/ecomm/images/offers/'.$data->offer_image); $mask = $data->offer_slug.'*_*'; array_map('unlink', glob(FCPATH . 'uplds'.$THEME.'/ecomm/images/offers/thumbs/'.$mask)); } $config['upload_path'] = FCPATH . 'uplds'.$THEME.'/ecomm/images/offers/'; $config['allowed_types'] = 'jpg|png|jpeg'; $image = date('dmYhis').'_'.rand(0,99999).".".pathinfo($_FILES['file_name']['name'], PATHINFO_EXTENSION); $config['file_name'] = $image; $this->load->library('upload', $config); if (!$this->upload->do_upload('file_name')) { $messge = array('message' => $this->upload->display_errors(),'class' => 'alert alert-danger'); $this->session->set_flashdata('response_msg', $messge); redirect(base_url($this->config->item('apanel_name').'/ecomm/offers/edit/'.$id).get_query_string()); } } else{ $image=$data->offer_image; } $this->load->helper("date"); $slug = url_title($this->input->post('offer_title'), 'dash', TRUE); if($this->input->post('Start_offer_date') || $this->input->post('end_offer_date')) { $start_offer_date = date('Y-m-d', strtotime($this->input->post('Start_offer_date'))); $end_offer_date = date('Y-m-d', strtotime($this->input->post('end_offer_date'))); } $data = array( 'offer_title' => $this->input->post('offer_title'), 'offer_slug' => $slug, 'offer_desc' => $this->input->post('offer_desc'), 'offer_percentage' => $this->input->post('offer_per') ?: 0, 'offer_fixed_amount' => $this->input->post('offer_fixed_amt') ?: 0, 'offer_image' => $image, 'start_offer_date' => $start_offer_date, 'end_offer_date' => $end_offer_date ); $data = $this->security->xss_clean($data); if($this->Ecomm_model->update($data, $id,'tbl_gf_ecomm_offers')){ $messge = array('message' => $this->lang->line('update_msg'),'class' => 'alert alert-success'); $this->session->set_flashdata('response_msg', $messge); } else{ $messge = array('message' => $this->lang->line('update_error'),'class' => 'alert alert-danger'); $this->session->set_flashdata('response_msg', $messge); } redirect(base_url($this->config->item('apanel_name').'/ecomm/offers/edit/'.$id).get_query_string()); } $this->data['page_title'] = 'Offers'; $this->data['offer'] = $this->Ecomm_model->single_offer($id); $this->data['current_page'] = 'Edit Offer'; $this->data['view'] = 'admin/ecomm/edit_offer'; $this->load->view('admin/layouts/default1', $this->data); } public function active($id) { $data = array( 'status' => 1 ); $data = $this->security->xss_clean($data); $this->Ecomm_model->update($data, $id,'tbl_gf_ecomm_offers'); echo $this->lang->line('enable_msg'); } public function deactive($id) { $data = array( 'status' => 0 ); $data = $this->security->xss_clean($data); $this->Ecomm_model->update($data, $id,'tbl_gf_ecomm_offers'); echo $this->lang->line('disable_msg'); } public function delete($id) { $this->Ecomm_model->delete($id, 'tbl_gf_ecomm_offers'); echo "success"; } public function activate() { $mrp = 0; $offer_id = $this->input->post('offer_id'); $product_ids = $this->input->post('product_ids'); if($offer_id == 0){ echo 'Please Select Offer'; exit; } if(!$product_ids){ echo 'Please Select Products'; exit; } $offer = $this->Ecomm_model->single_offer($offer_id); foreach ($product_ids as $product_id){ if($this->Ecomm_model->get_product_variation_types($product_id, 'tbl_gf_ecomm_product_variations_types')){ $variation_type_values = $this->Ecomm_model->get_product_variation_types($product_id, 'tbl_gf_ecomm_product_variations'); foreach($variation_type_values as $key =>$value){ $var_id = $value->id; $mrp = $value->price; $applied_offer = json_decode(calculate_offer($offer_id,$mrp)); $data=[ 'sale_price' => $applied_offer->selling_price, 'you_save_amt' => $applied_offer->you_save, 'you_save_percentage' => $applied_offer->you_save_per ]; $this->Ecomm_model->update($data, $var_id,'tbl_gf_ecomm_product_variations'); } } $product_details = $this->Ecomm_model->single_product($product_id); $product_mrp =$product_details[0]->product_mrp; $applied_offer_pro = json_decode(calculate_offer($offer_id,$product_mrp)); $data_pro=[ 'offer_id' => $offer_id, 'selling_price' => $applied_offer_pro->selling_price, 'you_save_amt' => $applied_offer_pro->you_save, 'you_save_per' => $applied_offer_pro->you_save_per ]; $this->Ecomm_model->update($data_pro, $product_id,'tbl_gf_ecomm_product'); } echo 'Offer Applied Successfully'; exit(); } public function deactivate() { $product_ids = $this->input->post('product_ids'); foreach ($product_ids as $productid) { $this->Ecomm_model->deactivate_offer($productid); $this->Ecomm_model->deactivate_offer_variation($productid); } echo 'Offer Deactivate Successfully'; exit(); } }