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/symphony-solusi.co.id/public_html/application/controllers/admin/ |
Upload File : |
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Solution extends Admin_Controller { //this property is used for validating existing blog title on call back edit blog private $solution_current_id = NULL; private $image1_filename = NULL; private $image2_filename = NULL; private $image3_filename = 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('solution_m'); $this->load->helper('form'); } public function index() { if (isset($_POST['submit'])) { $this->imageupload_indexpage = TRUE; //check & processing image banner upload files if ($_FILES['userfile']['size'] !== 0) { $config = array(); $config['upload_path'] = './uploads/blog/'; $config['allowed_types'] = 'jpg|png|jpeg'; $config['max_size'] = '1024'; $config['max_width'] = '2000'; $config['max_height'] = '2000'; $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->solution_current_id != NULL) { redirect('admin/solution/edit/' . $this->solution_current_id); } elseif ($this->solution_current_id == NULL && $this->imageupload_indexpage == FALSE) { redirect('admin/solution/add'); } elseif ($this->solution_current_id == NULL && $this->imageupload_indexpage == TRUE) { redirect('admin/solution'); } } else { $image = $this->upload->data(); $image_filename = $image['file_name']; } } $data = array( 'category_landingpage_description' => $this->input->post('description'), 'category_landingpage_description_en' => $this->input->post('description_en') ); //image upload if (isset($image_filename)) { $data['category_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;">Solution Landing Page Edit Successful</p>'); } //get landingpage banner image, description and link $this->db->select('category_landingpage_image,category_landingpage_description,category_landingpage_description_en')->from('configuration')->where('id_configuration', 1); $this->data['solution_landingpage'] = $this->db->get()->row(); //pagination in action. 100 results per page $this->load->library('pagination'); $config['base_url'] = base_url() . 'admin/solution/index'; $config['total_rows'] = $this->solution_m->record_count(); $config['per_page'] = 100; $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['solution'] = $this->solution_m->get_all_solution( $config["per_page"], $this->uri->segment(4) ); $this->db->select('*'); $this->db->from('configuration'); $data['config'] = $this->db->get()->result(); foreach ($data['config'] as $item) { $this->data_header['image'] = $item->logo; $this->data_header['icon'] = $item->website_icon; } //load view $this->data['subview'] = 'admin/solution/index'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } public function add() { $this->data['solution'] = $this->solution_m->get_new(); //get ordering number and display at add form $this->db->select_max('priority')->from('solution'); $current_priority = $this->db->get()->row()->priority; if ($current_priority == NULL) { $this->data['solution']->priority = 1; } else { $this->data['solution']->priority = $current_priority + 1; } $config = $this->solution_m->rules; $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); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); if ($this->form_validation->run($this) == TRUE) { //check & processing IMAGE INTRO if ($_FILES['image1']['size'] !== 0) { $config = array(); $config['upload_path'] = './uploads/blog/'; $config['allowed_types'] = 'jpg|png|jpeg'; $config['max_size'] = '1024'; $config['max_width'] = '2000'; $config['max_height'] = '2000'; $this->load->library('upload', $config); if (!$this->upload->do_upload('image1')) { // return the error message and kill the script // echo $this->upload->display_errors(); $this->session->set_flashdata('image1-error', '<br> <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); redirect('admin/solution/add'); } else { $image1 = $this->upload->data(); $image1_filename = $image1['file_name']; } } if ($_FILES['image2']['size'] !== 0) { $config = array(); $config['upload_path'] = './uploads/blog/'; $config['allowed_types'] = 'jpg|png|jpeg'; $config['max_size'] = '1024'; $config['max_width'] = '2000'; $config['max_height'] = '2000'; $this->load->library('upload', $config); if (!$this->upload->do_upload('image2')) { // return the error message and kill the script // echo $this->upload->display_errors(); // exit(); $this->session->set_flashdata('image2-error', '<br> <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); redirect('admin/solution/add'); } else { $image2 = $this->upload->data(); $image2_filename = $image2['file_name']; } } if ($_FILES['image3']['size'] !== 0) { $config = array(); $config['upload_path'] = './uploads/blog/'; $config['allowed_types'] = 'jpg|png|jpeg'; $config['max_size'] = '1024'; $config['max_width'] = '2000'; $config['max_height'] = '2000'; $this->load->library('upload', $config); if (!$this->upload->do_upload('image3')) { // return the error message and kill the script // echo $this->upload->display_errors(); $this->session->set_flashdata('image3-error', '<br> <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); redirect('admin/solution/add'); } else { $image3 = $this->upload->data(); $image3_filename = $image3['file_name']; } } $data = array( 'title' => $this->security->xss_clean($this->input->post('title')), 'title_en' => $this->security->xss_clean($this->input->post('title_en')), 'alias' => url_title($this->security->xss_clean($this->input->post('title'))), 'alias_en' => url_title($this->security->xss_clean($this->input->post('title_en'))), 'description' => $this->security->xss_clean($this->input->post('description')), 'description_en' => $this->security->xss_clean($this->input->post('description_en')), 'text_thumbnail' => $this->security->xss_clean($this->input->post('text_thumbnail')), 'text_thumbnail_en' => $this->security->xss_clean($this->input->post('text_thumbnail_en')), 'priority' => $this->security->xss_clean($this->input->post('priority')), 'status' => $this->security->xss_clean($this->input->post('status')) ); if (isset($image1_filename)) { $data['image1'] = $image1_filename; } if (isset($image2_filename)) { $data['image2'] = $image2_filename; } if (isset($image3_filename)) { $data['image3'] = $image3_filename; } $this->solution_m->add_solution($data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Solution Add Successful</p>'); redirect('admin/solution'); } $this->db->select('*'); $this->db->from('configuration'); $data['config'] = $this->db->get()->result(); foreach ($data['config'] as $item) { $this->data_header['image'] = $item->logo; $this->data_header['icon'] = $item->website_icon; } $this->data['subview'] = 'admin/solution/edit'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } public function edit($id = NULL) { if ($id == NULL) { show_404(); } $count = $this->solution_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } $this->data['solution'] = $this->solution_m->get($id); $this->solution_current_id = (int) $id; $config = $this->solution_m->rules; $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); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); if ($this->form_validation->run($this) == TRUE) { //check & processing IMAGE INTRO if ($_FILES['image1']['size'] !== 0) { $config = array(); $config['upload_path'] = './uploads/blog/'; $config['allowed_types'] = 'jpg|png|jpeg'; $config['max_size'] = '1024'; $config['max_width'] = '2000'; $config['max_height'] = '2000'; $this->load->library('upload', $config); if (!$this->upload->do_upload('image1')) { // return the error message and kill the script // echo $this->upload->display_errors(); $this->session->set_flashdata('image1-error', '<br> <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); redirect('admin/solution/edit/' . $id); } else { $image1 = $this->upload->data(); $image1_filename = $image1['file_name']; } } if ($_FILES['image2']['size'] !== 0) { $config = array(); $config['upload_path'] = './uploads/blog/'; $config['allowed_types'] = 'jpg|png|jpeg'; $config['max_size'] = '1024'; $config['max_width'] = '2000'; $config['max_height'] = '2000'; $this->load->library('upload', $config); if (!$this->upload->do_upload('image2')) { // return the error message and kill the script // echo $this->upload->display_errors(); // exit(); $this->session->set_flashdata('image2-error', '<br> <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); redirect('admin/solution/edit/' . $id); } else { $image2 = $this->upload->data(); $image2_filename = $image2['file_name']; } } if ($_FILES['image3']['size'] !== 0) { $config = array(); $config['upload_path'] = './uploads/blog/'; $config['allowed_types'] = 'jpg|png|jpeg'; $config['max_size'] = '1024'; $config['max_width'] = '2000'; $config['max_height'] = '2000'; $this->load->library('upload', $config); if (!$this->upload->do_upload('image3')) { // return the error message and kill the script // echo $this->upload->display_errors(); $this->session->set_flashdata('image3-error', '<br> <p style="background:red; color:white; padding:5px; font-weight:bold;">Image Upload Error. Wrong format or size.</p>'); redirect('admin/solution/edit/' . $id); } else { $image3 = $this->upload->data(); $image3_filename = $image3['file_name']; } } $data = array( 'title' => $this->security->xss_clean($this->input->post('title')), 'title_en' => $this->security->xss_clean($this->input->post('title_en')), 'alias' => url_title($this->security->xss_clean($this->input->post('title'))), 'alias_en' => url_title($this->security->xss_clean($this->input->post('title_en'))), 'description' => $this->security->xss_clean($this->input->post('description')), 'description_en' => $this->security->xss_clean($this->input->post('description_en')), 'text_thumbnail' => $this->security->xss_clean($this->input->post('text_thumbnail')), 'text_thumbnail_en' => $this->security->xss_clean($this->input->post('text_thumbnail_en')), 'priority' => $this->security->xss_clean($this->input->post('priority')), 'status' => $this->security->xss_clean($this->input->post('status')) ); if (isset($image1_filename)) { $data['image1'] = $image1_filename; } if (isset($image2_filename)) { $data['image2'] = $image2_filename; } if (isset($image3_filename)) { $data['image3'] = $image3_filename; } $this->solution_m->edit_solution($id, $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Solution edit Successful</p>'); redirect('admin/solution/edit/' . $id); } $this->db->select('*'); $this->db->from('configuration'); $data['config'] = $this->db->get()->result(); foreach ($data['config'] as $item) { $this->data_header['image'] = $item->logo; $this->data_header['icon'] = $item->website_icon; } $this->data['subview'] = 'admin/solution/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 blog public function delete($id) { //check if id exist. If not exist, show 404. $count = $this->solution_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('image1, image2,image3')->from('solution')->where('id_solution', (int) $id); $image = $this->db->get()->row(); if ($image->image1 != '') { //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH . '/uploads/blog/' . $image->image1); } if ($image->image2 != '') { //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH . '/uploads/blog/' . $image->image2); } if ($image->image3 != '') { //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH . '/uploads/blog/' . $image->image3); } //delete blog $this->solution_m->delete($id); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Solution Delete Successful</p>'); redirect('admin/solution'); } //make it private by adding _ public function _cek_existing_title($str) { $num_rows = $this->solution_m->cek_existing_title($str, $this->solution_current_id); if ($num_rows != 0) { $this->form_validation->set_message('_cek_existing_title', 'solution name already exist !'); return FALSE; } else { return TRUE; } } public function delete_landingpage_image() { //get image file name for deletion $this->db->select('category_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/blog/' . $image); //Delete image field from database $data = array( 'category_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/solution'); } public function delete_image($id = NULL, $image_type = NULL) { $count = $this->solution_m->count_exist($id); if ($id == NULL || $count == 0) { redirect('admin/solution'); } if ($image_type == NULL) { redirect('admin/solution'); } //get image file name for deletion $this->db->select('image1, image2, image3')->from('solution')->where('id_solution', (int) $id); $image = $this->db->get()->row(); if ($image_type == 'image1') { //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH . '/uploads/blog/' . $image->image1); //Delete image field from database $data = array( 'image1' => '', ); } elseif ($image_type == 'image2') { //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH . '/uploads/blog/' . $image->image2); //Delete image field from database $data = array( 'image2' => '', ); } elseif ($image_type == 'image3') { //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH . '/uploads/blog/' . $image->image3); //Delete image field from database $data = array( 'image3' => '', ); } $this->db->where('id_solution', (int) $id); $this->db->update('solution', $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Image Delete Successful</p>'); redirect('admin/solution/edit/' . $id); } }