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 Project extends Admin_Controller { private $project_current_id; private $image1_filename = NULL; private $image2_filename = NULL; private $image3_filename = NULL; private $image4_filename = NULL; private $image5_filename = NULL; private $image6_filename = NULL; function __construct() { parent::__construct(); $this->load->model('product_m'); $this->load->model('project_m'); $this->load->model('category_m'); $this->load->model('brand_m'); $this->load->model('size_m'); $this->load->library('image_lib'); $this->load->helper('form'); } public function index(){ $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; } /*----FILTER SEARCH PRODUCT--*/ if(isset($_POST['search_project'])) { //get product name from form $this->data['keyword'] = $this->security->xss_clean($this->input->post('project')); $this->data['project'] = $this->product_m->get_all_products_search_product($this->data['keyword']); } elseif (isset($_POST['updateBanner'])) { $this->imageupload_indexpage = TRUE; //get max image width and height from configuration table $this->db->select('category_image_width, category_image_height')->from('configuration')->where('id_configuration', 1); $image_dimension = $this->db->get()->row(); //check & processing image banner upload files if ($_FILES['userfile']['size'] !== 0) { $config['upload_path'] = './uploads/banners/'; $config['allowed_types'] = 'jpeg|jpg|png'; $config['max_size'] = '1024'; $config['max_width'] = $image_dimension->category_image_width; $config['max_height'] = $image_dimension->category_image_height; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('userfile')) { //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>'); redirect('admin/project/index'); } else { $image = $this->upload->data(); $image_filename = $image['file_name']; } } //store image information to configuration table $data = array( 'category_landingpage_link' => $this->security->xss_clean($this->input->post('banner_link')) ); //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;">Projects Landing Page Edit Successful</p>'); } //get landingpage banner image, description and link $this->db->select('category_landingpage_description, category_landingpage_image, category_landingpage_link')->from('configuration')->where('id_configuration', 1); $this->data['category_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(); //function from helper file $config['base_url'] = base_url() . 'admin/project/index/'; $config['per_page'] = 100; $config['uri_segment'] = 4; $config['total_rows'] = $this->product_m->record_count(); $this->pagination->initialize($config); $this->data['project'] = $this->project_m->get_all_project($config['per_page'],$this->uri->segment($config['uri_segment'])); $this->data['use_pagination'] = 'yes'; //get website product ordering $this->db->select('website_product_ordering')->from('configuration')->where('id_configuration', 1); $this->data['website_product_ordering'] = $this->db->get()->row()->website_product_ordering; //load view $this->data['subview'] = 'admin/project/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 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/project'); } public function add(){ $this->data['project'] = $this->project_m->get_new(); $this->data['parent_categories'] = $this->category_m->get_parent_categories(); $this->data['brands'] = $this->brand_m->get_brands(); $this->data['sizes'] = $this->size_m->get_product_size(); $this->data['new_product'] = TRUE; //get ordering number and display at add form $this->db->select_max('priority')->from('project'); $current_priority = $this->db->get()->row()->priority; if($current_priority == NULL) { $this->data['project']->priority = 1; } else { $this->data['project']->priority = $current_priority + 1; } //validation in action //validation check in action $config = $this->project_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) { $data = $this->table_data_processing( $this->input->post('project_name'), $this->input->post('project_type'), $this->input->post('project_status'), $this->input->post('priority'), $this->input->post('glass_material'), $this->input->post('city') ); $project_id = (int) $this->project_m->add_project($data); //get category_id from view, then insert together with product_id to category_product table $categories_id = $this->input->post('category_id'); //check id there is content inside category array $categories_id_count = count($categories_id); if ($categories_id_count > 0) { //add to category_product table $categories_keywords = ''; foreach ($categories_id as $category_id) { $data = array( 'id' => $project_id, 'id_category' => $category_id, ); $this->db->insert('category_project', $data); //add to products table, categories column $this->db->select('category')->from('categories')->where('id_categories', $category_id); //append all categories keywords to this variable $categories_keywords .= $this->db->get()->row()->category . ','; } $data = array( 'category_product' => $categories_keywords, ); $this->db->where('id', $project_id); $this->db->update('project', $data); } else { $data = array( 'id' => $project_id, 'id_category' => NULL, ); $this->db->insert('category_project', $data); } $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Project Added Successful</p>'); redirect('admin/project'); } $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/project/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){ $this->db->select('id')->from('project')->where('id', $id); $count_product = $this->db->get()->num_rows(); if($count_product === 0) {show_404();} $this->data['project'] = $this->project_m->get($id); $this->data['parent_categories'] = $this->category_m->get_parent_categories(); //get all chosen (active) categories $this->db->select('*')->from('category_project')->where('id', $id); $this->data['chosen_categories'] = $this->db->get()->result(); //assign to properties, used for custom callback validation $this->project_current_id = (int) $this->data['project']->id; //validation check in action $config = $this->project_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) { $data = $this->table_data_processing( $this->input->post('project_name'), $this->input->post('project_type'), $this->input->post('project_status'), $this->input->post('priority'), $this->input->post('glass_material'), $this->input->post('city') ); $this->project_m->edit_project($id, $data); //get category_id from view, then insert together with product_id to category_product table $categories_id = $this->input->post('category_id'); //check id there is content inside category array $categories_id_count = count($categories_id); if ($categories_id_count > 0) { //firstly, we delete all existing category records inside category_product table $this->db->where('id', $id); $this->db->delete('category_project'); //secondly, we insert new category_id $categories_keywords = ''; foreach ($categories_id as $category_id) { $data = array( 'id' => $id, 'id_category' => $category_id, ); $this->db->insert('category_project', $data); //add to products table, categories column $this->db->select('category')->from('categories')->where('id_categories', $category_id); //append all categories keywords to this variable $categories_keywords .= $this->db->get()->row()->category . ','; } $data = array( 'category_product' => $categories_keywords, ); $this->db->where('id', $id); $this->db->update('project', $data); } else { //no category is checked at edit page //firstly, we delete all existing category records inside category_product table $this->db->where('id', $id); $this->db->delete('category_project'); //secondly, we insert new category_id of NULL $data = array( 'id' => $id, 'id_category' => NULL, ); $this->db->insert('category_project', $data); } $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Project Edit Successful</p>'); redirect('admin/project/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/project/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 delete ($id) { //check if id exist. If not exist, show 404. $count = $this->project_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } $this->project_m->delete($id); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Project Deleted Successful</p>'); redirect('admin/project'); } //callback function validation add new product public function _cek_existing_project_name($str) { $num_rows = $this->project_m->cek_existing_project_name($str, $this->project_current_id); if ($num_rows != 0 ) { $this->form_validation->set_message('_cek_existing_project_name', 'Project name already exist !'); return FALSE; } else { return TRUE; } } private function table_data_processing($project_name,$project_type,$project_status,$priority,$glass_material,$city){ $data = array( 'project_name' => $this->security->xss_clean($project_name), 'project_type' => $this->security->xss_clean($project_type), 'glass_material' =>$this->security->xss_clean($glass_material), 'city' => $this->security->xss_clean($city), 'project_status' => $this->security->xss_clean($project_status), 'priority' => $this->security->xss_clean($priority) ); return $data; } } ?>