load->model('Department_model'); $this->load->model('Commonsql_model'); } /** * Index Page for this controller. * * Maps to the following URL * http://example.com/index.php/welcome * - or - * http://example.com/index.php/welcome/index * - or - * Since this controller is set as the default controller in * config/routes.php, it's displayed at http://example.com/ * * So any other public methods not prefixed with an underscore will * map to /index.php/welcome/ * @see https://codeigniter.com/user_guide/general/urls.html */ public function department_list() { if($this->session->userdata('id')==""){redirect('');} $data['dep']=$this->Department_model->dep_list(); $this->load->view('department/department_list',$data); } function add_department() { if($this->session->userdata('id')==""){redirect('');} $currentUser=$this->session->userdata('id'); $this->load->view('department/add_department'); if($this->input->post('submit')) { $name=$this->input->post('name'); $code=$this->input->post('code'); $year=$this->input->post('year'); if (!is_dir('uploads/department')) { mkdir('./uploads/department', 0777, TRUE); } if(file_exists($_FILES['depImage']['tmp_name'])) { $temp_user_img=$_FILES['depImage']['tmp_name']; $user_img=str_replace(' ', '_', $_FILES["depImage"]["name"]); $allowed = array('png,jpeg,jpg'); $extension1 = pathinfo($user_img, PATHINFO_EXTENSION); $user_img=date('ymdhis').'.'.$extension1; $targetPath='./uploads/department/'; $targetFile=$targetPath.$user_img; move_uploaded_file($temp_user_img, $targetFile); } $table="department"; $values=array('name'=>$name, 'code'=>$code, 'year'=>$year, 'image'=>$user_img, 'createdOn'=>date('Y-m-d'), 'createdBy'=>$currentUser, 'status'=>1); $result=$this->Commonsql_model->insert_table($table,$values); if($result) { $this->session->set_userdata('suc','successfully added'); redirect('department'); } else { $this->session->set_userdata('err','Please try again'); redirect('department'); } } } function editDepartment($id) { if($this->session->userdata('id')==""){redirect('');} $currentUser=$this->session->userdata('id'); if($this->input->post('submit')) { $name=$this->input->post('name'); $code=$this->input->post('code'); $year=$this->input->post('year'); $image=$this->input->post('image'); $hiddenImage=$this->input->post('hiddenImage'); //$primaryid=$this->input->post('hiddendepid'); if($image=="") { $newImage=$hiddenImage; } if(file_exists($_FILES['image']['tmp_name'])) { $temp_user_img=$_FILES['image']['tmp_name']; $newImage=str_replace(' ', '_', $_FILES["image"]["name"]); $allowed = array('png,jpeg,jpg'); $extension1 = pathinfo($newImage, PATHINFO_EXTENSION); $newImage=date('ymdhis').'.'.$extension1; $targetPath='./uploads/department/'; $targetFile=$targetPath.$newImage; move_uploaded_file($temp_user_img, $targetFile); } $table="department"; $where=array("id"=>$id); $values=array('name'=>$name, 'code'=>$code, 'year'=>$year, 'image'=>$newImage, 'updatedOn'=>date('Y-m-d'), 'updatedBy'=>$currentUser, 'status'=>1); $result=$this->Commonsql_model->updateTable($table,$where,$values); //echo $this->db->last_query();exit; if($result) { $this->session->set_userdata('suc','successfully Updated'); redirect('department'); } else { $this->session->set_userdata('err','Please try again'); redirect('department'); } } $data['dep']=$this->Department_model->get_dep($id); //echo $this->db->last_query();exit; $this->load->view('department/edit_department',$data); } function deleteDepartment() { if($this->session->userdata('id')==""){redirect('');} $currentUser=$this->session->userdata('id'); if($this->input->post('submit')) { $departmentId=$this->input->post('departmentId'); //echo $id ; exit; $table="department"; $where=array("id"=>$departmentId); $values=array('status'=>0,'updatedOn'=>date('Y-m-d'),'updatedBy'=>$currentUser); $result=$this->Commonsql_model->updateTable($table,$where,$values); if($result) { $this->session->set_userdata('suc','successfully deleted'); redirect('department'); } else { $this->session->set_userdata('err','Please try again'); redirect('department'); } } } }