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/iatax.com.au/public_html/application/controllers/admin/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Services extends Admin_Controller { private $service_current_id = null; private $imageupload_indexpage = FALSE; function __construct() { parent::__construct(); $this->load->model('service_m'); $this->load->library('Sitemap'); } //this is to list all services public function index() { $this->load->helper('form'); if(isset($_POST['landing_image'])) { $this->imageupload_indexpage = TRUE; //if there is a form submit banner image description at landing page $image_filename = $this->image_processing($_FILES['userfile']['size']); //image upload if (isset($image_filename)) { $data['service_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;">service Landing Page Edit Successful</p>'); } //get landingpage banner image, description and link $this->db->select('service_landingpage_image')->from('configuration')->where('id_configuration', 1); $this->data['service_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/services/index'; $config['total_rows'] = $this->service_m->record_count(); $config['per_page'] = 100; $config['uri_segment'] = 4; $this->pagination->initialize($config); $this->data['services'] = $this->service_m->get_all_services($config['per_page'], $this->uri->segment($config['uri_segment'])); //load view $this->data['subview'] = 'admin/services/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 service public function add() { $this->data['services'] = $this->service_m->get_new(); //get ordering number and display at add form $this->db->select_max('priority')->from('services'); $current_priority = $this->db->get()->row()->priority; if($current_priority == NULL) { $this->data['services']->priority = 1; } else { $this->data['services']->priority = $current_priority + 1; } //validation in action $this->load->library('form_validation'); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); $config = $this->service_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'],'userfile'); $image_filename1 = $this->image_processing($_FILES['userfile1'],'userfile1'); $image_filename2 = $this->image_processing($_FILES['userfile2'],'userfile2'); $image_filename3 = $this->image_processing($_FILES['userfile3'],'userfile3'); $image_filename4 = $this->image_processing($_FILES['userfile4'],'userfile4'); $data = $this->table_data_processing( $image_filename, $image_filename1, $image_filename2, $image_filename3, $image_filename4 ); $this->service_m->add_service($data); // generate site map $this->sitemap->create(); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Service Add Successful</p>'); redirect('admin/services'); } $this->data['subview'] = 'admin/services/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 service in admin public function edit($id = NULL) { if ($id == NULL) { show_404(); } //check if id exist. If not exist, show 404. $count = $this->service_m->count_exist($id); if ($count == 0) { show_404(); } $this->data['services'] = $this->service_m->get($id); $this->service_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->service_m->rules; $this->form_validation->set_rules($config); if($this->form_validation->run($this) == TRUE) { $image_filename = $this->image_processing($_FILES['userfile'],'userfile'); $image_filename1 = $this->image_processing($_FILES['userfile1'],'userfile1'); $image_filename2 = $this->image_processing($_FILES['userfile2'],'userfile2'); $image_filename3 = $this->image_processing($_FILES['userfile3'],'userfile3'); $image_filename4 = $this->image_processing($_FILES['userfile4'],'userfile4'); $data = $this->table_data_processing( $image_filename, $image_filename1, $image_filename2, $image_filename3, $image_filename4 ); $this->service_m->edit_service($id, $data); // generate site map $this->sitemap->create(); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Service Edit Successful</p>'); redirect('admin/services/edit/' . $id); } $this->data['subview'] = 'admin/services/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 service public function delete($id) { //check if id exist. If not exist, show 404. $count = $this->service_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('services')->where('id', (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/service/'. $image->image); } //delete service $this->service_m->delete($id); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Service Delete Successful</p>'); redirect('admin/services'); } //image upload processing private function image_processing($image_file, $input_name) { //check & processing image banner upload files if ($image_file['size'] !== 0) { $config['upload_path'] = './uploads/service/'; $config['allowed_types'] = 'jpg|png|jpeg'; $config['max_size'] = '600'; // $config['max_width'] = '350'; // $config['max_height'] = '477'; $this->load->library('upload', $config); $this->upload->initialize($config); if ( ! $this->upload->do_upload($input_name)) { //echo $this->upload->display_errors(); die(); $this->session->set_flashdata('banner_error', "<br> <p style='background:orange; color:white; padding:5px; font-weight:bold;'>{$this->upload->display_errors()}</p>"); if ($this->service_current_id != NULL) { redirect('admin/services/edit/' . $this->service_current_id); } elseif($this->service_current_id == NULL && $this->imageupload_indexpage == FALSE) { redirect('admin/services/add'); } elseif($this->service_current_id == NULL && $this->imageupload_indexpage == TRUE) { redirect('admin/services'); } } else { $image = $this->upload->data(); $image_filename = $image['file_name']; return $image_filename; } } } private function table_data_processing($image_filename, $image_filename1, $image_filename2, $image_filename3, $image_filename4) { $data = array( 'name' => $this->security->xss_clean($this->input->post('name')), 'slug' => url_title(strtolower($this->security->xss_clean($this->input->post('name')))), 'status' => $this->security->xss_clean($this->input->post('status')), 'title1' => $this->security->xss_clean($this->input->post('title1')), 'title2' => $this->security->xss_clean($this->input->post('title2')), 'title3' => $this->security->xss_clean($this->input->post('title3')), 'title4' => $this->security->xss_clean($this->input->post('title4')), 'description1' => $this->input->post('description1'), 'description2' => $this->input->post('description2'), 'description3' => $this->input->post('description3'), 'description4' => $this->input->post('description4'), 'priority' => $this->security->xss_clean($this->input->post('priority')), 'meta_description' => $this->security->xss_clean($this->input->post('meta_description')), 'meta_keywords' => $this->security->xss_clean($this->input->post('meta_keywords')), 'meta_title' => $this->security->xss_clean($this->input->post('meta_title')) ); //image upload if (isset($image_filename)) { $data['image'] = $image_filename; } if (isset($image_filename1)) { $data['image1'] = $image_filename1; } if (isset($image_filename2)) { $data['image2'] = $image_filename2; } if (isset($image_filename3)) { $data['image3'] = $image_filename3; } if (isset($image_filename4)) { $data['image4'] = $image_filename4; } return $data; } //To delete service landingpage banner image file from server, and from database public function delete_landingpage_image() { //get image file name for deletion $this->db->select('service_landingpage_image')->from('configuration')->where('id_configuration', 1); $image = $this->db->get()->row()->service_landingpage_image; //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/service/'. $image); //Delete image field from database $data = array( 'service_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/services'); } //To delete service banner image file from server, and from database public function delete_image($id = NULL, $img_num = NULL) { $count = $this->service_m->count_exist($id); if ($id == NULL || $count == 0) { redirect('admin/services'); } if($img_num) { //delete sub image switch ($img_num) { case '1': $this->db->select('image1')->from('services')->where('id', (int) $id); $image = $this->db->get()->row(); //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/service/'. $image->image1); //Delete image field from database $data = array( 'image1' => '', ); break; case '2': $this->db->select('image2')->from('services')->where('id', (int) $id); $image = $this->db->get()->row(); //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/service/'. $image->image2); //Delete image field from database $data = array( 'image2' => '', ); break; case '3': $this->db->select('image3')->from('services')->where('id', (int) $id); $image = $this->db->get()->row(); //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/service/'. $image->image3); //Delete image field from database $data = array( 'image3' => '', ); break; case '4': $this->db->select('image4')->from('services')->where('id', (int) $id); $image = $this->db->get()->row(); //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/service/'. $image->image4); //Delete image field from database $data = array( 'image4' => '', ); break; } $this->db->where('id', (int) $id); $this->db->update('services', $data); } else { //delete intro image $this->db->select('image')->from('services')->where('id', (int) $id); $image = $this->db->get()->row(); //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/service/'. $image->image); //Delete image field from database $data = array( 'image' => '', ); $this->db->where('id', (int) $id); $this->db->update('services', $data); } $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Image Delete Successful</p>'); redirect('admin/services/edit/' . $id); } }