D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
ksclnmuac
/
www
/
ci_panel
/
application
/
controllers
/
admin
/
Filename :
Department.php
back
Copy
<?php class Department extends CI_controller{ public function __construct(){ 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 addDepartment() { # code... $this->load->library('form_validation'); $this->load->model('Department_model'); // ===>view code start $department = $this->Department_model->index(); $data = []; // for sidebar $data['mainModule'] = 'department'; $data['subModule'] = 'department'; $data['department'] = $department; // ===>view code end $this->form_validation->set_rules('department', 'Department', 'trim|required'); $this->form_validation->set_error_delimiters('<p class="invalid-feedback">', '</p>'); if($this->form_validation->run() == true){ $formArray = []; $formArray['dept_name'] = $this->input->post('department'); $formArray['date'] = date('Y-m-d H:i:s'); $this->Department_model->create($formArray); $this->session->set_flashdata('success', 'Department Added Successfully!'); redirect(base_url().'admin/department/addDepartment'); }else{ $this->load->view('admin/department', $data); } } public function delete($id) { # code... // echo $id; $this->load->model('Department_model'); $dept = $this->Department_model->getDept($id); if(empty($dept)){ $this->session->set_flashdata('error', 'Department not found!'); redirect(base_url().'admin/department/addDepartment'); }else{ $this->Department_model->deleteDept($id); $this->session->set_flashdata('success', 'Department deleted successfully!'); redirect(base_url().'admin/department/addDepartment'); } } public function getDataAjax($id) { # code... $this->load->model('Department_model'); $temp_dept = $this->Department_model->getDept($id); $dept = json_encode($temp_dept); echo $dept; } public function edit() { # code... $this->load->model('Department_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('edepartment', 'Department', 'trim|required'); if($this->form_validation->run()==true){ $id = $this->input->post('eid'); $formArray = []; $formArray['dept_name'] = $this->input->post('edepartment'); $this->Department_model->editDepartment($id, $formArray); $this->session->set_flashdata('success', 'Department Updated Successfully!'); redirect(base_url().'admin/department/addDepartment'); }else{ $this->session->set_flashdata('error', 'Department not found!'); redirect(base_url().'admin/department/addDepartment'); } } }