D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
ksclnmuac
/
public_html
/
ci_panel
/
application
/
controllers
/
admin
/
Filename :
Ssr.php
back
Copy
<?php class Ssr 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() { // ====> view code start # code... $data = []; // for sidebar $data['mainModule'] = 'naac'; $data['subModule'] = 'ssr'; $this->load->library('form_validation'); $this->load->model('Ssr_model'); $ssr = $this->Ssr_model->get_ssr(); $data['ssr'] = $ssr; // ===> view code end # code... $config['upload_path'] = './public/uploads/ssr/'; $config['allowed_types'] = 'pdf'; $config['encrypt_name'] = TRUE; $this->load->library('upload', $config); $this->form_validation->set_rules('session', 'Session', 'trim|required'); $this->form_validation->set_error_delimiters('<p class="invalid-feedback">', '</p>'); if($this->form_validation->run()==true){ if($_FILES['file']['name']!=""){ if($this->upload->do_upload('file')){ $data = $this->upload->data(); $formArray['session'] = $this->input->post('session'); $formArray['ssr_file'] = $data['file_name']; $formArray['added_on'] = date('Y-m-d H:i:s'); $this->Ssr_model->add_ssr($formArray); $this->session->set_flashdata('success', 'SSR added successfully!'); redirect(base_url().'admin/ssr/create'); }else{ $this->session->set_flashdata('error', 'Sorry, something went wrong!'); redirect(base_url().'admin/ssr/create'); } }else{ $this->session->set_flashdata('error', 'Sorry, something went wrong!'); redirect(base_url().'admin/ssr/create'); } }else{ $this->load->view('admin/ssr', $data); } } public function delete($id) { # code... $this->load->model('Ssr_model'); $ssr = $this->Ssr_model->getSingleSsr($id); if(empty($ssr)){ $this->session->set_flashdata('error', 'SSR not found!'); redirect(base_url().'admin/ssr/create'); }else{ if(file_exists('./public/uploads/ssr/'.$ssr[0]['ssr_file'])){ unlink('./public/uploads/ssr/'.$ssr[0]['ssr_file']); } $this->Ssr_model->deleteSsr($id); $this->session->set_flashdata('success', 'SSR deleted successfully!'); redirect(base_url().'admin/ssr/create'); } } public function getDataAjax($id) { # code... $this->load->model('Ssr_model'); $temp_ssr = $this->Ssr_model->getSingleSsr($id); $ssr = json_encode($temp_ssr); echo $ssr; } // edit code public function edit() { # code... $config['upload_path'] = './public/uploads/ssr/'; $config['allowed_types'] = 'pdf'; $config['encrypt_name'] = TRUE; $this->load->library('upload', $config); $this->load->model('Ssr_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('esession', 'Session', 'trim|required'); if($this->form_validation->run()==true){ $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 $ssr = $this->Ssr_model->getSingleSsr($id); $path = './public/uploads/ssr/'.$ssr[0]['ssr_file']; if(file_exists($path)){ unlink($path); } $formArray = []; $formArray['session'] = $this->input->post('esession'); $formArray['ssr_file'] = $data['file_name']; $this->Ssr_model->editSsr($id, $formArray); $this->session->set_flashdata('success', 'SSR Updated Successfully!'); redirect(base_url().'admin/ssr/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/ssr/create'); } }else{ // without file uploading $formArray = []; $formArray['session'] = $this->input->post('esession'); $this->Ssr_model->editSsr($id, $formArray); $this->session->set_flashdata('success', 'SSR Updated Successfully!'); redirect(base_url().'admin/ssr/create'); } }else{ $this->session->set_flashdata('error', 'Sorry, something went wrong!'); redirect(base_url().'admin/ssr/create'); } } }