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/indolok.id/application/controllers/admin/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Solutions extends Admin_Controller { //this property is used for validating existing solution title on call back edit solution protected $solution_current_id; //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 is to list all solutions public function index() { $this->load->helper('form'); //pagination in action. 100 results per page $this->load->library('pagination'); $config = array(); $this->load->helper('pagination_helper'); $config = pagination_format(); //function from helper file $config['base_url'] = base_url() . 'admin/solutions/index'; $config['per_page'] = 100; $config['uri_segment'] = 4; //fetch all solutions $config['total_rows'] = $this->solution_m->record_count(); $this->pagination->initialize($config); //get parent solutions only $this->data['solutions'] = $this->solution_m->get_all_solutions($config["per_page"], $this->uri->segment($config['uri_segment'])); //load view $this->data['subview'] = 'admin/solutions/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 solution public function add() { //if($this->data['allowed'] == false) { redirect('admin/dashboard'); } $this->data['solutions'] = $this->solution_m->get_new(); //$this->data['categories'] = $this->solution_m->get_parent_solutions(); //get ordering number and display at add form $this->db->select_max('priority')->from('solutions'); $current_priority = $this->db->get()->row()->priority; if($current_priority == NULL) { $this->data['solutions']->priority = 1; } else { $this->data['solutions']->priority = $current_priority + 1; } //validation in action //validation check in action $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); if($this->form_validation->run($this) == TRUE) { $image1_filename = $this->image_processing($_FILES['image1']['size'], 'image1'); $image2_filename = $this->image_processing($_FILES['image2']['size'], 'image2'); $image3_filename = $this->image_processing($_FILES['image3']['size'], 'image3'); $image4_filename = $this->image_processing($_FILES['image4']['size'], 'image4'); $thumbnail_filename = $this->image_processing($_FILES['thumbnail']['size'], 'thumbnail'); $data = $this->table_data_processing($image1_filename, $image2_filename, $image3_filename, $image4_filename, $thumbnail_filename); $this->solution_m->add_solution($data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Industry Add Successful</p>'); redirect('admin/solutions'); } $this->data['parent_categories'] = $this->db->select('*')->from('solution_categories')->where('parent', null)->get()->result(); $this->data['subview'] = 'admin/solutions/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 solution in admin public function edit($id = NULL) { //check if id exist. If not exist, show 404. $count = $this->solution_m->count_exist($id); if ($count == 0) { show_404(); } $this->data['solutions'] = $this->solution_m->get($id); $this->data['parent_categories'] = $this->db->select('*')->from('solution_categories')->where('parent', null)->get()->result(); $this->solution_current_id = (int) $this->data['solutions']->id_solutions; //validation check in action $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); if($this->form_validation->run($this) == TRUE) { $image1_filename = $this->image_processing($_FILES['image1']['size'], 'image1'); $image2_filename = $this->image_processing($_FILES['image2']['size'], 'image2'); $image3_filename = $this->image_processing($_FILES['image3']['size'], 'image3'); $image4_filename = $this->image_processing($_FILES['image4']['size'], 'image4'); $thumbnail_filename = $this->image_processing($_FILES['thumbnail']['size'], 'thumbnail'); $data = $this->table_data_processing($image1_filename, $image2_filename, $image3_filename, $image4_filename, $thumbnail_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;">Industry Edit Successful</p>'); redirect('admin/solutions/edit/' . $id); } $this->data['subview'] = 'admin/solutions/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 solution public function delete($id) { //if($this->data['allowed'] == false || $this->data['role'] == 'admin') { redirect('admin/dashboard'); } //check if id exist. If not exist, show 404. $count = $this->solution_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } $this->solution_m->delete($id); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Industry Delete Successful</p>'); redirect('admin/solutions'); } //image upload processing private function image_processing($image_file_size, $name) { //check & processing image banner upload files if ($image_file_size !== 0) { $config = array(); $config['upload_path'] = './uploads/solution/'; $config['allowed_types'] = 'png|jpg|jpeg'; $config['max_size'] = '1000'; $this->load->library('upload', $config); if ( ! $this->upload->do_upload($name)) { 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->solution_current_id != NULL) { redirect('admin/solutions/edit/' . $this->solution_current_id); } else { redirect('admin/solutions/add'); } } else { $image = $this->upload->data(); $image_filename = $image['file_name']; return $image_filename; } } } private function table_data_processing($image1_filename, $image2_filename, $image3_filename, $image4_filename, $thumbnail_filename) { $data = array( 'solution' => $this->security->xss_clean($this->input->post('solution')), 'alias' => url_title($this->security->xss_clean($this->input->post('solution'))), 'status' => $this->input->post('status'), 'description' => $this->security->xss_clean($this->input->post('description')), 'description2' => $this->security->xss_clean($this->input->post('description2')), 'priority' => $this->input->post('priority'), 'meta_description' => $this->security->xss_clean($this->input->post('meta_description')), 'solution_category_id' => $this->input->post('solution_category_id'), ); //image upload if (isset($image1_filename)) { $data['image1'] = $image1_filename; } //image upload if (isset($image2_filename)) { $data['image2'] = $image2_filename; } //image upload if (isset($image3_filename)) { $data['image3'] = $image3_filename; } //image upload if (isset($image4_filename)) { $data['image4'] = $image4_filename; } //thumbnail upload if (isset($thumbnail_filename)) { $data['thumbnail'] = $thumbnail_filename; } return $data; } //callback function validation add new solution //make it private by adding _ public function _cek_existing_solution_title($str) { $num_rows = $this->solution_m->cek_existing_solution_title($str, $this->solution_current_id); if ($num_rows != 0 ) { $this->form_validation->set_message('_cek_existing_solution_title', 'solution name already exist !'); return FALSE; } else { return TRUE; } } //To delete solution landingpage banner image file from server, and from database public function delete_landingpage_image() { //get image file name for deletion $this->db->select('solution_landingpage_image')->from('configuration')->where('id_configuration', 1); $image = $this->db->get()->row()->solution_landingpage_image; //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/solution/'. $image); //Delete image field from database $data = array( 'solution_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/solutions'); } //To delete solution image file from server, and from database public function delete_image($id = NULL) { $count = $this->solution_m->count_exist($id); if ($id == NULL || $count == 0) { redirect('admin/solutions'); } //get image file name for deletion $this->db->select('image')->from('solutions')->where('id_solutions', (int) $id); $image = $this->db->get()->row(); //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/solution/'. $image->image); //Delete image field from database $data = array( 'image' => '', ); $this->db->where('id_solutions', (int) $id); $this->db->update('solutions', $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Image Delete Successful</p>'); redirect('admin/solutions/edit/' . $id); } //To delete solution thumbnail file from server, and from database public function delete_thumbnail($id = NULL) { $count = $this->solution_m->count_exist($id); if ($id == NULL || $count == 0) { redirect('admin/solutions'); } //get thumbnail file name for deletion $this->db->select('thumbnail')->from('solutions')->where('id_solutions', (int) $id); $image = $this->db->get()->row(); //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/solution/'. $image->thumbnail); //Delete image field from database $data = array( 'thumbnail' => '', ); $this->db->where('id_solutions', (int) $id); $this->db->update('solutions', $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Thumbnail Delete Successful</p>'); redirect('admin/solutions/edit/' . $id); } public function ajax_get_ordering() { //test if ajax call to prevent direct access if (!$this->input->is_ajax_request()) { exit('No direct script access allowed'); } if($this->input->post('id_parentsolution') == 'no-parent') { //choose select option where value is no-parent at edit view //get ordering number and display at add form $this->db->select_max('priority')->from('solutions')->where('parent', NULL); $current_priority = $this->db->get()->row()->priority; if($current_priority == NULL) { $next_priority = 1; } else { $next_priority = $current_priority + 1; } } else { $id_parentsolution = (int) $this->input->post('id_parentsolution'); //get ordering number and display at add form $this->db->select_max('priority')->from('solutions')->where('parent', $id_parentsolution); $current_priority = $this->db->get()->row()->priority; $next_priority = $current_priority + 1; } echo $next_priority; } }