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 Brands extends Admin_Controller { //this property is used for validating existing brand title on call back edit brand private $brand_current_id = NULL; function __construct() { parent::__construct(); $this->load->model('brand_m'); $this->load->model('product_m'); $this->load->helper('rajaongkir'); } //this is to list all brands public function index() { //pagination in action. 50 results per page $this->load->library('pagination'); $config['base_url'] = base_url() . 'admin/brands/index'; $config['total_rows'] = $this->brand_m->record_count(); $config['per_page'] = 50; $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['brands'] = $this->brand_m->get_all_brands($config["per_page"], $this->uri->segment(4)); //load view $this->data['subview'] = 'admin/brands/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); } //to add a new brand public function add() { $this->data['provinces'] = get_rajaongkir_data('province'); $this->data['brands'] = $this->brand_m->get_new(); //validation in action //validation check in action $config = $this->brand_m->rules; $this->form_validation->set_rules($config); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); if($this->form_validation->run() == TRUE) { $image_filename = $this->image_processing($_FILES['userfile']['size']); //get province name by id_province from RajaOngkir $province = get_rajaongkir_data( 'province?id=' . (int) $this->input->post('province') ); //get from helper file $province = $province['rajaongkir']['results']['province']; //get district /city name by id_district from RajaOngkir $district = get_rajaongkir_data( 'city?id=' . (int) $this->input->post('district') ); //get from helper file $district = $district['rajaongkir']['results']['city_name']; $data = $this->table_data_processing($this->input->post('brand_name'), $this->input->post('status'), $this->input->post('description'), $image_filename, $this->input->post('priority'), $this->input->post('meta_description'), $this->input->post('meta_keywords'), $this->input->post('province'), $this->input->post('district'), $province, $district, $this->input->post('kanva_group') ); $this->brand_m->add_brand($data); $this->session->set_flashdata('success', '<br><p style="background:orange; color:white; padding:5px; font-weight:bold;">Brand Add Successful</p>'); redirect('admin/brands'); } $this->data['subview'] = 'admin/brands/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 brand in admin public function edit($id = NULL) { $this->data['provinces'] = get_rajaongkir_data('province'); if ($id == NULL) { show_404(); } //check if id exist. If not exist, show 404. $count = $this->brand_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } $this->data['brands'] = $this->brand_m->get($id); $this->brand_current_id = (int) $id; //validation check in action $config = $this->brand_m->rules; $this->form_validation->set_rules($config); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); if($this->form_validation->run() == TRUE) { $image_filename = $this->image_processing($_FILES['userfile']['size']); //get province name by id_province from RajaOngkir $province = get_rajaongkir_data( 'province?id=' . (int) $this->input->post('province') ); //get from helper file $province = $province['rajaongkir']['results']['province']; //get district /city name by id_district from RajaOngkir $district = get_rajaongkir_data( 'city?id=' . (int) $this->input->post('district') ); //get from helper file $district = $district['rajaongkir']['results']['city_name']; $data = $this->table_data_processing($this->input->post('brand_name'), $this->input->post('status'), $this->input->post('description'), $image_filename, $this->input->post('priority'), $this->input->post('meta_description'), $this->input->post('meta_keywords'), $this->input->post('province'), $this->input->post('district'), $province, $district, $this->input->post('kanva_group') ); $this->brand_m->edit_brand($id, $data); $this->session->set_flashdata('success', '<br><p style="background:orange; color:white; padding:5px; font-weight:bold;">Brand Edit Successful</p>'); redirect('admin/brands/edit/' . $id); } $this->data['subview'] = 'admin/brands/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 delete a brand public function delete($id) { //check if id exist. If not exist, show 404. $count = $this->brand_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } //delete image from server //check if there is an existing image $this->db->select('image')->from('brands')->where('id_brands', (int) $id); $image = $this->db->get()->row(); if ($image->image != '' || $image->image != NULL) { //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/brand/'. $image->image); } //delete brand $this->brand_m->delete($id); $this->session->set_flashdata('success', '<br><p style="background:orange; color:white; padding:5px; font-weight:bold;">Brand Delete Successful</p>'); redirect('admin/brands'); } //image upload processing private function image_processing($image_file_size) { //get max image width and height from configuration table $this->db->select('brand_image_width, brand_image_height')->from('configuration')->where('id_configuration', 1); $image_dimension = $this->db->get()->row(); //check & processing image banner upload files if ($image_file_size !== 0) { $config['upload_path'] = './uploads/brand/'; $config['allowed_types'] = 'png'; $config['max_size'] = '300'; $config['max_width'] = $image_dimension->brand_image_width; $config['max_height'] = $image_dimension->brand_image_height; $this->load->library('upload', $config); if ( ! $this->upload->do_upload()) { //echo $this->upload->display_errors(); die(); $this->session->set_flashdata('error', '<br> <p style="background:orange; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); if ($this->brand_current_id != NULL) { redirect('admin/brands/edit/' . $this->brand_current_id); } else { redirect('admin/brands/add'); } } else { $image = $this->upload->data(); $image_filename = $image['file_name']; return $image_filename; } } } private function table_data_processing($brand_name, $status, $description, $image_filename, $priority, $meta_description, $meta_keywords, $id_province, $id_district, $province, $district, $kanva_group) { $data = array( 'brand' => $this->security->xss_clean($brand_name), 'alias' => url_title($brand_name), 'status' => $status, 'description' => $description, 'priority' => $priority, 'meta_description' => $meta_description, 'meta_keywords' => $meta_keywords, 'id_province' => $id_province, 'id_district' => $id_district, 'province' => $province, 'district' => $district, 'kanva_group' => $kanva_group, ); //image upload if (isset($image_filename)) { $data['image'] = $image_filename; } return $data; } //callback function validation add new brand //make it private by adding _ public function _cek_existing_brand_title($str) { $num_rows = $this->brand_m->cek_existing_brand_title($str, $this->brand_current_id); if ($num_rows != 0 ) { $this->form_validation->set_message('_cek_existing_brand_title', 'Brand name already exist !'); return FALSE; } else { return TRUE; } } //To delete brand image file from server, and from database public function delete_image($id = NULL) { $count = $this->brand_m->count_exist($id); if ($id == NULL || $count == 0) { redirect('admin/brands'); } //get image file name for deletion $this->db->select('image')->from('elephant_packages_gallery')->where('id_brands', (int) $id); $image = $this->db->get()->row(); //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/brand/'. $image->image); //Delete image field from database $data = array( 'image' => '', ); $this->db->where('id_brands', (int) $id); $this->db->update('brands', $data); $this->session->set_flashdata('success', '<br><p style="background:orange; color:white; padding:5px; font-weight:bold;">Image Delete Successful</p>'); redirect('admin/brands/edit/' . $id); } }