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/serbaantik.com/public_html/application/controllers/admin/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Blog_category extends Admin_Controller { function __construct() { parent::__construct(); if (!in_array('blog category', $this->allowed_sections)) redirect('admin/dashboard'); $this->load->model('blog_category_m'); } //this is to list all blog_category public function index() { //pagination in action. 20 results per page $this->load->library('pagination'); $config['base_url'] = base_url() . 'admin/blog_category/index'; $config['per_page'] = 40; $config["uri_segment"] = 4; //fetch all blog_category $config['total_rows'] = $this->blog_category_m->record_count(); $this->pagination->initialize($config); $this->data['blog_category'] = $this->blog_category_m->get_all_blog_category($config["per_page"], $this->uri->segment(4)); //load view $this->data['subview'] = 'admin/blog_category/index'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer', $this->data_footer); } //to add a new blog_category public function add() { $this->data['blog_category'] = $this->blog_category_m->get_new(); //get ordering number and display at add form $this->db->select_max('priority')->from('blogs_category'); $current_priority = $this->db->get()->row()->priority; if($current_priority == NULL) { $this->data['blog_category']->priority = 1; } else { $this->data['blog_category']->priority = $current_priority + 1; } //validation check in action $config = array( array( 'field' => 'name', 'label' => 'Name', 'rules' => 'trim|required' ), array( 'field' => 'content', 'label' => 'content', 'rules' => 'trim|max_length[350]' ), array( 'field' => 'priority', 'label' => 'Priority', 'rules' => 'trim|required|numeric' ), array( 'field' => 'status', 'label' => 'status', 'rules' => 'trim|required' ), ); $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 banner upload files if ($_FILES['userfile']['size'] !== 0) { $config = array(); $config['upload_path'] = './uploads/blog/'; $config['allowed_types'] = '*'; // $config['allowed_types'] = 'jpg|png|jpeg|webp'; // $config['max_size'] = '500'; $this->load->library('upload', $config); $this->upload->initialize($config); if ( ! $this->upload->do_upload()) { //echo $this->upload->display_errors(); die(); $this->session->set_flashdata('error', '<br> <p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>'); redirect('admin/blog_category/add'); } else { $image = $this->upload->data(); $image_filename = $image['file_name']; } } $data = array( 'name' => $this->input->post('name'), 'alias' => url_title($this->input->post('name')), 'content' => $this->input->post('content'), 'priority' => $this->input->post('priority'), 'status' => $this->input->post('status'), ); //image upload if (isset($image_filename)) { $data['image'] = $image_filename; } $this->blog_category_m->add_blog_category($data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">blog Category Add Success</p>'); redirect('admin/blog_category'); } } $this->data['subview'] = 'admin/blog_category/edit'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer', $this->data_footer); } //to edit brand in admin public function edit($id = NULL) { //check if id exist. If not exist, show 404. $count = $this->blog_category_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } $this->data['blog_category'] = $this->blog_category_m->get($id); //validation check in action $config = array( array( 'field' => 'name', 'label' => 'Name', 'rules' => 'trim|required' ), array( 'field' => 'content', 'label' => 'content', 'rules' => 'trim|max_length[350]' ), array( 'field' => 'priority', 'label' => 'Priority', 'rules' => 'trim|required|numeric' ), array( 'field' => 'status', 'label' => 'status', 'rules' => 'trim|required' ), ); $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 banner upload files if ($_FILES['userfile']['size'] !== 0) { $config = array(); $config['upload_path'] = './uploads/blog/'; $config['allowed_types'] = '*'; // $config['allowed_types'] = 'jpg|png|jpeg|webp'; // $config['max_size'] = '500'; $this->load->library('upload', $config); $this->upload->initialize($config); if ( ! $this->upload->do_upload()) { echo $this->upload->display_errors(); die(); $this->session->set_flashdata('error', '<br> <p style="background:orange; color:white; padding:5px; font-weight:bold;">Kesalahan Unggah Gambar. Format atau ukuran salah.</p>'); redirect('admin/blog_category/edit/' . $id); } else { $image = $this->upload->data(); $image_filename = $image['file_name']; } } $data = array( 'name' => $this->input->post('name'), 'alias' => url_title($this->input->post('name')), 'content' => $this->input->post('content'), 'priority' => $this->input->post('priority'), 'status' => $this->input->post('status'), ); //image upload if (isset($image_filename)) { $data['image'] = $image_filename; } $this->blog_category_m->edit_blog_category($id, $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">blog_category success edit</p>'); redirect('admin/blog_category'); } } $this->data['subview'] = 'admin/blog_category/edit'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer', $this->data_footer); } //to delete a blog_category public function delete($id) { //check if id exist. If not exist, show 404. $count = $this->blog_category_m->count_exist($id); if ($count == 0) { //page not exist show_404(); } //delete brand $this->blog_category_m->delete($id); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">blog_category success deleted</p>'); redirect('admin/blog_category'); } //To delete customer photo file from server, and from database public function delete_customer_photo($id = NULL) { $count = $this->blog_category_m->count_exist($id); if ($id == NULL || $count == 0) { redirect('admin/blog_category'); } //get customer image file name for deletion $this->db->select('image')->from('blogs_category')->where('id', (int) $id); $image = $this->db->get()->row(); //Delete the actual image file from server. FCPATH is codeigniter base path unlink(FCPATH .'/uploads/blog/'. $image->image); //Delete image field from database $data = array( 'image' => '', ); $this->db->where('id', (int) $id); $this->db->update('blogs_category', $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Delete image success</p>'); redirect('admin/blog_category/edit/' . $id); } }