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/rabbithabit.com/public_html/application/controllers/admin/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Marketplace extends Admin_Controller { //this property is used for validating existing page title on call back edit page private $marketplace_current_id = NULL; function __construct() { parent::__construct(); $this->load->model('marketplace_m'); if (!in_array('marketplace', $this->data['allowed_module'])) { $this->data['allowed'] = false; } else { $this->data['allowed'] = true; } } //this is to list all marketplace public function index() { //pagination in action. 20 results per page $this->load->library('pagination'); $config['base_url'] = base_url() . 'admin/marketplace/index'; $config['per_page'] = 20; $config["uri_segment"] = 4; //fetch all marketplace $config['total_rows'] = $this->marketplace_m->record_count(); $this->pagination->initialize($config); $this->data['marketplace'] = $this->marketplace_m->get_all_marketplace($config["per_page"], $this->uri->segment(4)); //load view $this->data['subview'] = 'admin/marketplace/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 page public function add() { if($this->data['allowed'] == false) { redirect('admin/dashboard'); } $this->data['marketplace'] = $this->marketplace_m->get_new(); //validation in action //validation check in action $config = $this->marketplace_m->rules; $this->load->library('form_validation'); $this->form_validation->set_rules($config); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); if($this->form_validation->run($this) == TRUE) { $data = $this->table_data_processing(); $this->marketplace_m->add_marketplace($data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Marketplace Add Successful</p>'); redirect('admin/marketplace'); } $this->data['subview'] = 'admin/marketplace/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 page in admin public function edit($id = NULL) { if($this->data['allowed'] == false) { redirect('admin/dashboard'); } //check if id exist. If not exist, show 404. $count = $this->marketplace_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } $this->data['marketplace'] = $this->marketplace_m->get($id); $this->marketplace_current_id = (int) $id; //validation check in action $config = $this->marketplace_m->rules; $this->load->library('form_validation'); $this->form_validation->set_rules($config); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); if($this->form_validation->run($this) == TRUE) { $data = $this->table_data_processing(); /*update semua harga produk pada margin marketplace produk*/ $marketplace_product_price = $this->db->select('*')->from('marketplace_product_price')->where('marketplace_id',$id)->order_by('id','ASC')->get()->result(); foreach ($marketplace_product_price as $item) { $product_price = $this->db->select('sale_price')->from('products')->where('id_products',$item->product_id)->get()->row()->sale_price; $final_price = $product_price + (($product_price*$data['margin_percentage'])/100) + $data['margin_amount']; $update_price = array( 'price' => $final_price, ); $this->db->where('product_id',$item->product_id); $this->db->where('marketplace_id',$id); $this->db->update('marketplace_product_price',$update_price); } /*update semua harga produk pada margin marketplace produk*/ $this->marketplace_m->edit_page($id, $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Marketplace Edit Successful</p>'); redirect('admin/marketplace/edit/' . $id); } $this->data['subview'] = 'admin/marketplace/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 page public function delete($id) { if($this->data['allowed'] == false || $this->data['role'] == 'admin') { redirect('admin/dashboard'); } //check if id exist. If not exist, show 404. $count = $this->marketplace_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } //delete page $this->marketplace_m->delete($id); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Marketplace Delete Successful</p>'); redirect('admin/marketplace'); } private function table_data_processing() { $data = array( 'name' => $this->security->xss_clean($this->input->post('name')), 'margin_percentage' => $this->security->xss_clean($this->input->post('margin_percentage')), 'margin_amount' => $this->security->xss_clean($this->input->post('margin_amount')), ); return $data; } }