D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
ksclnmuac
/
public_html
/
ci_panel
/
application
/
controllers
/
admin
/
Filename :
Teacher.php
back
Copy
<?php class Teacher 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 index() { # code... $data = []; // for sidebar $data['mainModule'] = 'teacher'; $data['subModule'] = 'teacher_view'; $this->load->model('Teacher_model'); $teachers = $this->Teacher_model->get_teacher(); $data['teachers'] = $teachers; $this->load->view('admin/teacher/teacher_view', $data); } public function teacher_add() { # code... $data = []; $data['mainModule'] = 'teacher'; $data['subModule'] = 'teacher_add'; $config['upload_path'] = './public/uploads/teacher/'; $config['allowed_types'] = 'png|jpeg|jpg'; $config['encrypt_name'] = TRUE; $this->load->library('upload', $config); $this->load->library('form_validation'); $this->load->model('Teacher_model'); $this->load->model('department_model'); $department = $this->department_model->index(); $data['department'] = $department; $this->form_validation->set_rules('name', 'Teacher Name', 'trim|required'); $this->form_validation->set_rules('dob', 'Date of Birth', 'trim|required'); $this->form_validation->set_rules('gender', 'Gender', 'trim|required'); $this->form_validation->set_rules('fname', 'Father Name', 'trim|required'); $this->form_validation->set_rules('mob', 'Mobile Number', 'trim|required|min_length[10]|max_length[13]'); $this->form_validation->set_rules('email', 'Email', 'trim|required'); $this->form_validation->set_rules('department', 'Department', 'trim|required'); $this->form_validation->set_rules('designation', 'Designation', 'trim|required'); $this->form_validation->set_rules('qualification', 'Qualification', 'trim|required'); $this->form_validation->set_rules('address', 'Address', 'trim|required'); $this->form_validation->set_error_delimiters('<p class="invalid-feedback">', '</p>'); if($this->form_validation->run()==TRUE){ if(!empty($_FILES['file']['name'])){ if($this->upload->do_upload('file')){ $data = $this->upload->data(); $formArray['name'] = $this->input->post('name'); $formArray['dob'] = $this->input->post('dob'); $formArray['fname'] = $this->input->post('fname'); $formArray['gender'] = $this->input->post('gender'); $formArray['mobile'] = $this->input->post('mob'); $formArray['email'] = $this->input->post('email'); $formArray['dept_id'] = $this->input->post('department'); $formArray['designation'] = $this->input->post('designation'); $formArray['qualification'] = $this->input->post('qualification'); $formArray['address'] = $this->input->post('address'); $formArray['pic'] = $data['file_name']; $formArray['dor'] = date('Y-m-d H:i:s'); $this->Teacher_model->add_teacher($formArray); $this->session->set_flashdata('success', 'Teacher added successfully.'); redirect(base_url().'admin/teacher/index'); }else{ $error = $this->upload->display_errors("<p class='invalid-feedback'>", "</p>"); $data['errorImageUpload'] = $error; $this->load->view('admin/teacher/teacher_add', $data); } }else{ $formArray['name'] = $this->input->post('name'); $formArray['dob'] = $this->input->post('dob'); $formArray['fname'] = $this->input->post('fname'); $formArray['gender'] = $this->input->post('gender'); $formArray['mobile'] = $this->input->post('mob'); $formArray['email'] = $this->input->post('email'); $formArray['dept_id'] = $this->input->post('department'); $formArray['designation'] = $this->input->post('designation'); $formArray['qualification'] = $this->input->post('qualification'); $formArray['address'] = $this->input->post('address'); $formArray['dor'] = date('Y-m-d H:i:s'); $this->Teacher_model->add_teacher($formArray); $this->session->set_flashdata('success', 'Teacher added successfully.'); redirect(base_url().'admin/teacher/index'); } }else{ // will show error $this->load->view('admin/teacher/teacher_add', $data); } } public function delete($id) { # code... $this->load->model('Teacher_model'); $tech = $this->Teacher_model->getTeach($id); if(empty($tech)){ $this->session->set_flashdata('error', 'Teacher data not found!'); redirect(base_url().'admin/teacher/index'); }else{ if(file_exists('./public/uploads/teacher/'.$tech[0]['pic'])){ unlink('./public/uploads/teacher/'.$tech[0]['pic']); } $this->Teacher_model->deleteTeacher($id); $this->session->set_flashdata('success', 'Teacher deleted successfully!'); redirect(base_url().'admin/teacher/index'); } } public function edit($id) { # code... $data = []; $data['mainModule'] = 'teacher'; $data['subModule'] = ''; $config['upload_path'] = './public/uploads/teacher/'; $config['allowed_types'] = 'png|jpeg|jpg'; $config['encrypt_name'] = TRUE; $this->load->library('upload', $config); $this->load->library('form_validation'); $this->load->model('Teacher_model'); $this->load->model('department_model'); $techSingle = $this->Teacher_model->getTeach($id); if(empty($techSingle)){ $this->session->set_flashdata('error', 'Teacher not found!'); redirect(base_url('admin/teacher/index')); } $department = $this->department_model->index(); $data['department'] = $department; $data['tech'] = $techSingle; $this->form_validation->set_rules('name', 'Teacher Name', 'trim|required'); $this->form_validation->set_rules('dob', 'Date of Birth', 'trim|required'); $this->form_validation->set_rules('gender', 'Gender', 'trim|required'); $this->form_validation->set_rules('fname', 'Father Name', 'trim|required'); $this->form_validation->set_rules('mob', 'Mobile Number', 'trim|required|min_length[10]|max_length[13]'); $this->form_validation->set_rules('email', 'Email', 'trim|required'); $this->form_validation->set_rules('department', 'Department', 'trim|required'); $this->form_validation->set_rules('designation', 'Designation', 'trim|required'); $this->form_validation->set_rules('qualification', 'Qualification', 'trim|required'); $this->form_validation->set_rules('address', 'Address', 'trim|required'); $this->form_validation->set_error_delimiters('<p class="invalid-feedback">', '</p>'); if($this->form_validation->run()==TRUE){ if(!empty($_FILES['file']['name'])){ if($this->upload->do_upload('file')){ $data = $this->upload->data(); $path = './public/uploads/teacher/'.$techSingle[0]['pic']; if(file_exists($path)){ unlink($path); } $formArray['name'] = $this->input->post('name'); $formArray['dob'] = $this->input->post('dob'); $formArray['fname'] = $this->input->post('fname'); $formArray['gender'] = $this->input->post('gender'); $formArray['mobile'] = $this->input->post('mob'); $formArray['email'] = $this->input->post('email'); $formArray['dept_id'] = $this->input->post('department'); $formArray['designation'] = $this->input->post('designation'); $formArray['qualification'] = $this->input->post('qualification'); $formArray['address'] = $this->input->post('address'); $formArray['pic'] = $data['file_name']; $formArray['dor'] = date('Y-m-d H:i:s'); $this->Teacher_model->update_teacher($id, $formArray); $this->session->set_flashdata('success', 'Teacher updated successfully.'); redirect(base_url().'admin/teacher/index'); }else{ $error = $this->upload->display_errors("<p class='invalid-feedback'>", "</p>"); $data['errorImageUpload'] = $error; $this->load->view('admin/teacher/teacher_update', $data); } }else{ $formArray['name'] = $this->input->post('name'); $formArray['dob'] = $this->input->post('dob'); $formArray['fname'] = $this->input->post('fname'); $formArray['gender'] = $this->input->post('gender'); $formArray['mobile'] = $this->input->post('mob'); $formArray['email'] = $this->input->post('email'); $formArray['dept_id'] = $this->input->post('department'); $formArray['designation'] = $this->input->post('designation'); $formArray['qualification'] = $this->input->post('qualification'); $formArray['address'] = $this->input->post('address'); $formArray['dor'] = date('Y-m-d H:i:s'); $this->Teacher_model->update_teacher($id, $formArray); $this->session->set_flashdata('success', 'Teacher updated successfully.'); redirect(base_url().'admin/teacher/index'); } }else{ // will show error $this->load->view('admin/teacher/teacher_update', $data); } } }