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/mesinpolesshinemate.com/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; //this property is to mark whether we are uploading image in the index page private $imageupload_indexpage = FALSE; function __construct() { parent::__construct(); $this->load->model('brand_m'); $this->load->model('product_m'); } //this is to list all brands public function index() { $this->load->helper('form'); if (isset($_POST['submit'])) { $this->imageupload_indexpage = TRUE; //if there is a form submit banner image description at landing page $image_filename = $this->image_processing($_FILES['userfile']['size']); //store image information to configuration table $data = array( 'brand_landingpage_link' => $this->security->xss_clean($this->input->post('banner_link')), 'brand_landingpage_description' => $this->security->xss_clean($this->input->post('description')), 'brand_landingpage_description_en' => $this->security->xss_clean($this->input->post('description_en')), ); //image upload if (isset($image_filename)) { $data['brand_landingpage_image'] = $image_filename; } $this->db->where('id_configuration', 1); $this->db->update('configuration', $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Brand Landing Page Edit Successful</p>'); } //get landingpage banner image, description and link $this->db->select('brand_landingpage_description, brand_landingpage_description_en, brand_landingpage_image, brand_landingpage_link')->from('configuration')->where('id_configuration', 1); $this->data['brand_landingpage'] = $this->db->get()->row(); //pagination in action. 100 results per page $this->load->library('pagination'); $config = array(); $this->load->helper('pagination_helper'); $config = pagination_format(); $config['base_url'] = base_url() . 'admin/brands/index'; $config['total_rows'] = $this->brand_m->record_count(); $config['per_page'] = 100; $config['uri_segment'] = 4; $this->pagination->initialize($config); $this->data['brands'] = $this->brand_m->get_all_brands($config['per_page'], $this->uri->segment($config['uri_segment'])); //load view $this->data['subview'] = 'admin/brands/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 brand public function add() { $this->data['brands'] = $this->brand_m->get_new(); //get ordering number and display at add form $this->db->select_max('priority')->from('brands'); $current_priority = $this->db->get()->row()->priority; if($current_priority == NULL) { $this->data['brands']->priority = 1; } else { $this->data['brands']->priority = $current_priority + 1; } //validation in action //validation check in action $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 $config = $this->brand_m->rules; $this->form_validation->set_rules($config); //add $this because we use hmvc if($this->form_validation->run($this) == TRUE) { $image_filename = $this->image_processing($_FILES['userfile']['size']); $logo_filename = $this->logo_processing($_FILES['userfile2']['size']); $data = $this->table_data_processing( $this->input->post('brand_name'), $this->input->post('status'), $image_filename, $logo_filename, $this->input->post('priority'), $this->input->post('meta_description'), $this->input->post('meta_keywords'), $this->input->post('banner_link')); $this->brand_m->add_brand($data); $this->session->set_flashdata('success', '<br><p style="background:green; 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_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } //to edit brand in admin public function edit($id = NULL) { if ($id == NULL) { show_404(); } //check if id exist. If not exist, show 404. $count = $this->brand_m->count_exist($id); if ($count == 0) { show_404(); } $this->data['brands'] = $this->brand_m->get($id); $this->brand_current_id = (int) $id; //validation check in action $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 $config = $this->brand_m->rules; $this->form_validation->set_rules($config); if($this->form_validation->run($this) == TRUE) { $image_filename = $this->image_processing($_FILES['userfile']['size']); $logo_filename = $this->logo_processing($_FILES['userfile2']['size']); $data = $this->table_data_processing( $this->input->post('brand_name'), $this->input->post('status'), $image_filename, $logo_filename, $this->input->post('priority'), $this->input->post('meta_description'), $this->input->post('meta_keywords'), $this->input->post('banner_link')); $this->brand_m->edit_brand($id, $data); $this->session->set_flashdata('success', '<br><p style="background:green; 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_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } //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:green; 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'] = 'jpg|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('banner_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); } elseif($this->brand_current_id == NULL && $this->imageupload_indexpage == FALSE) { redirect('admin/brands/add'); } elseif($this->brand_current_id == NULL && $this->imageupload_indexpage == TRUE) { redirect('admin/brands'); } } else { $image = $this->upload->data(); $image_filename = $image['file_name']; return $image_filename; } } } //logo upload processing private function logo_processing($logo_file_size) { //get max logo width and height from configuration table $this->db->select('brand_logo_width, brand_logo_height')->from('configuration')->where('id_configuration', 1); $logo_dimension = $this->db->get()->row(); //check & processing image banner upload files if ($logo_file_size !== 0) { $config['upload_path'] = './uploads/brand/'; $config['allowed_types'] = 'jpg|png'; $config['max_size'] = '200'; $config['max_width'] = $logo_dimension->brand_logo_width; $config['max_height'] = $logo_dimension->brand_logo_height; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('userfile2')) { //echo $this->upload->display_errors(); die(); $this->session->set_flashdata('logo_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 { $logo = $this->upload->data(); $logo_filename = $logo['file_name']; return $logo_filename; } } } private function table_data_processing($brand_name, $status, $image_filename, $logo_filename, $priority, $meta_description, $meta_keywords, $banner_link) { $data = array( 'brand' => $this->security->xss_clean($brand_name), 'alias' => url_title($this->security->xss_clean($brand_name)), 'status' => $status, 'description' => $this->security->xss_clean($this->input->post('description')), 'description_en' => $this->security->xss_clean($this->input->post('description_en')), 'priority' => $priority, 'meta_description' => $this->security->xss_clean($meta_description), 'meta_keywords' => $this->security->xss_clean($meta_keywords), 'banner_link' => $this->security->xss_clean($banner_link) ); //image upload if (isset($image_filename)) { $data['image'] = $image_filename; } //logo upload if (isset($logo_filename)) { $data['logo'] = $logo_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 landingpage banner image file from server, and from database public function delete_landingpage_image() { //get image file name for deletion $this->db->select('brand_landingpage_image')->from('configuration')->where('id_configuration', 1); $image = $this->db->get()->row()->brand_landingpage_image; //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/brand/'. $image); //Delete image field from database $data = array( 'brand_landingpage_image' => '', ); $this->db->where('id_configuration', 1); $this->db->update('configuration', $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Image Delete Successful</p>'); redirect('admin/brands'); } //To delete brand banner 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('brands')->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:green; color:white; padding:5px; font-weight:bold;">Image Delete Successful</p>'); redirect('admin/brands/edit/' . $id); } //To delete brand logo file from server, and from database public function delete_logo($id = NULL) { $count = $this->brand_m->count_exist($id); if ($id == NULL || $count == 0) { redirect('admin/brands'); } //get logo file name for deletion $this->db->select('logo')->from('brands')->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->logo); //Delete image field from database $data = array( 'logo' => '', ); $this->db->where('id_brands', (int) $id); $this->db->update('brands', $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Logo Delete Successful</p>'); redirect('admin/brands/edit/' . $id); } }