D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
ksclnmuac
/
www
/
ci_panel
/
application
/
controllers
/
admin
/
Filename :
Notification.php
back
Copy
<?php class Notification extends CI_controller{ public function __construct() { # code... parent::__construct(); $admin = $this->session->userdata('admin'); if(empty($admin)){ $this->session->set_flashdata('msg', 'Your session has been expired'); redirect(base_url('admin/login/index')); } } public function create($page=1) { # code... $config['upload_path'] = './public/uploads/notice/'; $config['allowed_types'] = 'pdf'; $config['encrypt_name'] = TRUE; // this will show error // ====>view code start $perpage = 5; $param = []; $param['limit'] = $perpage; $param['offset'] = ($page*$perpage)-$perpage; $this->load->library('pagination'); $this->load->library('form_validation'); $this->load->model('Notification_model'); $config['base_url'] = base_url('admin/notification/create'); $config['total_rows'] = $this->Notification_model->getNotificationCounts(); $config['per_page'] = $perpage; $config['use_page_numbers'] = true; $config['first_link'] = 'First'; $config['last_link'] = 'Last'; $config['next_link'] = 'Next'; $config['prev_link'] = 'Prev'; $config['full_tag_open'] = "<ul class='pagination'>"; $config['full_tag_close'] = "</ul>"; $config['num_tag_open'] = "<li class='page-item'>"; $config['num_tag_close'] = "</li>"; $config['cur_tag_open'] = "<li class='disabled page-item'><li class='active page-item'><a href='#' class=\"page-link\">"; $config['cur_tag_close'] = "<span class='sr-only'></span></a></li>"; $config['next_tag_open'] = "<li class=\"page-item\">"; $config['next_tagl_close'] = "</li>"; $config['prev_tag_open'] = "<li class=\"page-item\">"; $config['prev_tagl_close'] = "</li>"; $config['first_tag_open'] = "<li class=\"page-item\">"; $config['first_tagl_close'] = "</li>"; $config['last_tag_open'] = "<li class=\"page-item\">"; $config['last_tagl_close'] = "</li>"; $config['attributes'] = array('class' => 'page-link'); $this->pagination->initialize($config); $pagination_links = $this->pagination->create_links(); $notification = $this->Notification_model->get_notification($param); $data = []; $data['notification'] = $notification; // ====>view code end // for sidebar $data['mainModule'] = 'notification'; $data['subModule'] = 'notification'; $data['pagination_links'] = $pagination_links; $this->load->library('upload', $config); $this->form_validation->set_rules('title', 'Title', 'trim|required'); $this->form_validation->set_error_delimiters('<p class="invalid-feedback">', '</p>'); if($this->form_validation->run() == true){ if(!empty($_FILES['file']['name'])){ // data uploading with file if($this->upload->do_upload('file')){ $data = $this->upload->data(); $formArray = []; $formArray['notice'] = $this->input->post('title'); $formArray['file_name'] = $data['file_name']; $formArray['date'] = date('Y-m-d H:i:s'); $this->Notification_model->add_notice($formArray); $this->session->set_flashdata('success', 'Notification Uploaded Successfully!'); redirect(base_url().'admin/notification/create'); }else{ $error = $this->upload->display_errors("<p class='invalid-feedback'>", "</p>"); $data['errorFileUpload'] = $error; redirect(base_url().'admin/notification/create'); } }else{ // data uploading without file $formArray = []; $formArray['notice'] = $this->input->post('title'); $formArray['date'] = date('Y-m-d H:i:s'); $this->Notification_model->add_notice($formArray); $this->session->set_flashdata('success', 'Notification Uploaded Successfully!'); redirect(base_url().'admin/notification/create'); } }else{ $this->load->view('admin/notification', $data); } } public function delete($id) { # code... $this->load->model('Notification_model'); $notification = $this->Notification_model->getNoti($id); if(empty($notification)){ $this->session->set_flashdata('error', 'Notification not found!'); redirect(base_url().'admin/notification/create'); }else{ if(file_exists('./public/uploads/notice/'.$notification[0]['file_name'])){ unlink('./public/uploads/notice/'.$notification[0]['file_name']); }else{ echo "file not exists"; } $this->Notification_model->deleteNotification($id); $this->session->set_flashdata('success', 'This notification deleted successfully!'); redirect(base_url().'admin/notification/create'); } } public function getDataAjax($id) { # code... // echo $id; $this->load->model('Notification_model'); $temp_noti = $this->Notification_model->getNoti($id); $noti = json_encode($temp_noti); echo $noti; } // edit code public function edit() { # code... $config['upload_path'] = './public/uploads/notice/'; $config['allowed_types'] = 'pdf'; $config['encrypt_name'] = TRUE; $this->load->library('upload', $config); $this->load->model('Notification_model'); $this->load->library('form_validation'); // Validation start $this->form_validation->set_error_delimiters('<p class="invalid-feedback">', '</p>'); $this->form_validation->set_rules('eid', 'ID', 'trim|required'); $this->form_validation->set_rules('etitle', 'Title', 'trim|required'); if($this->form_validation->run()==true){ // main threat for updation ---> $id = $this->input->post('eid'); if(!empty($_FILES['efile']['name'])){ // file uploading if($this->upload->do_upload('efile')){ $data = $this->upload->data(); // unlink the older file first $noti = $this->Notification_model->getNoti($id); $path = './public/uploads/notice/'.$noti[0]['file_name']; if(file_exists($path)){ unlink($path); } $formArray = []; $formArray['notice'] = $this->input->post('etitle'); $formArray['file_name'] = $data['file_name']; $this->Notification_model->editNotification($id, $formArray); $this->session->set_flashdata('success', 'Notification Updated Successfully!'); redirect(base_url().'admin/notification/create'); }else{ // if we will get get any error $error = $this->upload->display_errors("<p class='invalid-feedback'>", "</p>"); $data['errorFileUpload'] = $error; redirect(base_url().'admin/notification/create'); } }else{ // without file uploading $formArray = []; $formArray['notice'] = $this->input->post('etitle'); $this->Notification_model->editNotification($id, $formArray); $this->session->set_flashdata('success', 'Notification Updated Successfully!'); redirect(base_url().'admin/notification/create'); } }else{ $this->session->set_flashdata('error', 'Sorry, something went wrong!'); redirect(base_url().'admin/notification/create'); } } }