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/blue-sky.co.id/public_html/application/controllers/admin/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Home_centerbanners extends Admin_Controller { function __construct() { parent::__construct(); //admin role module check $this->check_admin_role('home & promotion banner'); //method from Admin_controller $this->load->model('home_centerbanner_m'); } //this is to list all home_centerbanners public function index() { $this->edit(1); } //to edit brand in admin public function edit($id = NULL) { //check if id exist. If not exist, show 404. $count = $this->home_centerbanner_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } $this->data['home_centerbanners'] = $this->home_centerbanner_m->get($id); $fields = [ 'hero_title', 'hero_subtitle', 'business_tag', 'business_title', 'business_subtitle', 'business1_title', 'business1_subtitle', 'business1_btn_title', 'business1_btn_link', 'business1_tabtitle', 'business1_tabsubtitle', 'business2_title', 'business2_subtitle', 'business2_btn_title', 'business2_btn_link', 'business2_tabtitle', 'business2_tabsubtitle', 'business3_title', 'business3_subtitle', 'business3_btn_title', 'business3_btn_link', 'business3_tabtitle', 'business3_tabsubtitle', 'business4_title', 'business4_subtitle', 'business4_btn_title', 'business4_btn_link', 'business4_tabtitle', 'business4_tabsubtitle', 'why1_tag', 'why1_title', 'why1_subtitle', 'why2_tag', 'why2_title', 'why2_subtitle', 'why3_tag', 'why3_title', 'why3_subtitle', 'about_title', 'about_subtitle', 'testimony_title', 'testimony_subtitle', 'testimony_guest_serve', 'testimony_bookings', ]; $config = []; foreach ($fields as $field) { $config[] = [ 'field' => $field, 'label' => ucwords(str_replace('_', ' ', $field)), 'rules' => 'trim' ]; } $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 $this->form_validation->set_rules($config); if($this->form_validation->run() == TRUE) { if($_POST) { //check & processing image 1 banner upload files $data = []; foreach ($fields as $field) { $data[$field] = $this->input->post($field); } $image_fields = [ 'hero_image', 'business1_image', 'business2_image', 'business3_image', 'business4_image', 'why1_image', 'why2_image', 'why3_image', 'about_image1', 'about_image2', 'about_image3', 'popup_image' ]; foreach ($image_fields as $field) { if (isset($_FILES[$field]) && $_FILES[$field]['size'] !== 0) { $upload_config['upload_path'] = './uploads/page/'; $upload_config['allowed_types'] = 'jpg|jpeg|png|gif'; $upload_config['max_size'] = '2048'; // 2MB $this->load->library('upload', $upload_config); $this->upload->initialize($upload_config); if ($this->upload->do_upload($field)) { $upload_data = $this->upload->data(); $data[$field] = $upload_data['file_name']; // $this->resize_promo_banners('800', '500', 'page/', $upload_data['file_name']); } else { $this->session->set_flashdata('error', '<br><p style="background:orange; color:white; padding:5px; font-weight:bold;">Error uploading ' . $field . ': ' . $this->upload->display_errors() . '</p>'); redirect('admin/home_centerbanners/edit/' . $id); } } } /* echo '<pre>'; print_r($data); echo '</pre>'; exit(); */ $this->home_centerbanner_m->edit_home_centerbanners($id, $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Home center Banner Berhasil di Edit</p>'); redirect('admin/home_centerbanners'); } } $this->data['subview'] = 'admin/home_centerbanners/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->home_centerbanners_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } //delete brand $this->home_centerbanner_m->delete($id); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Home center Banner Berhasil di Hapus</p>'); redirect('admin/home_centerbanners'); } public function delete_image($field_name) { //get image file name for deletion $this->db->select($field_name)->from('home_centerbanners')->where('id_home_centerbanners', 1); $image = $this->db->get()->row()->$field_name; //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/page/'. $image); //Delete image field from database $data = array( $field_name => '', ); $this->db->where('id_home_centerbanners', 1); $this->db->update('home_centerbanners', $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Gambar Berhasil di Hapus</p>'); redirect('admin/home_centerbanners'); } public function delete_static_banner($image_number = NULL) { if($image_number == NULL) { show_404(); } //get image file name for deletion $this->db->select('banner1_image, banner2_image, banner3_image, banner4_image, banner5_image, banner6_image, banner7_image, banner8_image, banner9_image, banner10_image, banner11_image, banner12_image, banner13_image, banner14_image'); $this->db->from('home_centerbanners'); $this->db->where('id_home_centerbanners', 1); switch($image_number) { case '1': $image = $this->db->get()->row()->banner1_image; break; case '2': $image = $this->db->get()->row()->banner2_image; break; case '3': $image = $this->db->get()->row()->banner3_image; break; case '4': $image = $this->db->get()->row()->banner4_image; break; case '5': $image = $this->db->get()->row()->banner5_image; break; case '6': $image = $this->db->get()->row()->banner6_image; break; case '7': $image = $this->db->get()->row()->banner7_image; break; case '8': $image = $this->db->get()->row()->banner8_image; break; } //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/page/'. $image); //Delete image field from database $data = array( 'banner' . $image_number . '_image' => '', ); $this->db->where('id_home_centerbanners', 1); $this->db->update('home_centerbanners', $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Gambar Statis Berhasil di Hapus</p>'); redirect('admin/home_centerbanners'); } //admin resize images private function resize_promo_banners($width, $height, $upload_path, $image_name) { $this->load->library('image_lib'); //image resizing (SMALL IMAGE) $config['image_library'] = 'gd2'; $config['source_image'] = './uploads/'. $upload_path . $image_name; $config['new_image'] = './uploads/'. $upload_path; $config['create_thumb'] = FALSE; $config['maintain_ratio'] = TRUE; $config['width'] = $width; //$config['height'] = $height; $this->image_lib->initialize($config); $this->image_lib->resize(); } }