D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
ksclnmuac
/
public_html
/
ci_panel
/
application
/
controllers
/
admin
/
Filename :
Fee.php
back
Copy
<?php class Fee 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'] = 'academic'; $data['subModule'] = 'fee'; $this->load->library('form_validation'); $this->load->model('Fee_model'); $fee = $this->Fee_model->get_fee(); $data['fee'] = $fee; // =====> view code end # code... $config['upload_path'] = './public/uploads/fees/'; $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['fee_str_file'] = $data['file_name']; $formArray['added_on'] = date('Y-m-d H:i:s'); $this->Fee_model->add_fee($formArray); $this->session->set_flashdata('success', 'Fees added successfully!'); redirect(base_url().'admin/fee/create'); }else{ $this->session->set_flashdata('error', 'Sorry, something went wrong!'); redirect(base_url().'admin/fee/create'); } }else{ $this->session->set_flashdata('error', 'Sorry, something went wrong!'); redirect(base_url().'admin/fee/create'); } }else{ $this->load->view('admin/fee', $data); } } public function delete($id) { # code... $this->load->model('Fee_model'); $fee = $this->Fee_model->getSingleFee($id); if(empty($fee)){ $this->session->set_flashdata('error', 'Fees not found!'); redirect(base_url().'admin/fee/create'); }else{ if(file_exists('./public/uploads/fees/'.$fee[0]['fee_str_file'])){ unlink('./public/uploads/fees/'.$fee[0]['fee_str_file']); } $this->Fee_model->deleteFee($id); $this->session->set_flashdata('success', 'Fees deleted successfully!'); redirect(base_url().'admin/fee/create'); } } public function getDataAjax($id) { # code... $this->load->model('Fee_model'); $fee_temp = $this->Fee_model->getSingleFee($id); $fee = json_encode($fee_temp); echo $fee; } // edit code public function edit() { # code... $config['upload_path'] = './public/uploads/fees/'; $config['allowed_types'] = 'pdf'; $config['encrypt_name'] = TRUE; $this->load->library('upload', $config); $this->load->model('Fee_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){ // 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 $tt = $this->Fee_model->getSingleFee($id); $path = './public/uploads/fees/'.$tt[0]['fee_str_file']; if(file_exists($path)){ unlink($path); } $formArray = []; $formArray['session'] = $this->input->post('esession'); $formArray['fee_str_file'] = $data['file_name']; $this->Fee_model->editFee($id, $formArray); $this->session->set_flashdata('success', 'Fee Structure Updated Successfully!'); redirect(base_url().'admin/fee/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/fee/create'); } }else{ // without file uploading $formArray = []; $formArray['session'] = $this->input->post('esession'); $this->Fee_model->editFee($id, $formArray); $this->session->set_flashdata('success', 'Fee Structure Updated Successfully!'); redirect(base_url().'admin/fee/create'); } }else{ $this->session->set_flashdata('error', 'Sorry, something went wrong!'); redirect(base_url().'admin/fee/create'); } } }