load->model('Employee_model'); $this->load->model('Commonsql_model'); } public function employee_list() { if($this->session->userdata('id')==""){redirect('');} $data['emp']=$this->Employee_model->list_emp(); $this->load->view('employee/list',$data); } public function viewEmployee($id) { if($this->session->userdata('id')==""){redirect('');} $data['viewEmployee']=$this->Employee_model->viewEmployee($id); //echo $this->db->last_query();exit; $this->load->view('employee/viewemployee',$data); } function add_employee() { if($this->session->userdata('id')==""){redirect('');} $currentUser=$this->session->userdata('id'); $data['role']=$this->Employee_model->list_role(); if($this->input->post('submit')) { //echo "dsdsd";exit; $employeename=$this->input->post('employeename'); $mobileNumber=$this->input->post('mobileNumber'); $roleId=$this->input->post('roleId'); $address=$this->input->post('address'); $email=$this->input->post('email'); $user=$this->input->post('User'); $password=$this->input->post('Password'); if (!is_dir('uploads/employee')) { mkdir('./uploads/employee', 0777, TRUE); } if(file_exists($_FILES['employeeImg']['tmp_name'])) { $temp_user_img=$_FILES['employeeImg']['tmp_name']; $eImage=str_replace(' ', '_', $_FILES["employeeImg"]["name"]); $allowed = array('png,jpeg,jpg'); $extension1 = pathinfo($eImage, PATHINFO_EXTENSION); $eImage=date('ymdhi').'.'.$extension1; $targetPath='./uploads/employee/'; $targetFile=$targetPath.$eImage; move_uploaded_file($temp_user_img, $targetFile); } $table="employee"; $values=array('name'=>$employeename, 'mobileNumber'=>$mobileNumber, 'roleId'=>$roleId, 'address'=>$address, 'email'=>$email, 'image'=>$eImage, 'username'=>$user, 'password'=>md5($password), 'createdOn'=>date('Y-m-d'), 'createdBy'=>$currentUser, 'status'=>1); $result=$this->Commonsql_model->insert_table($table,$values); //echo $this->db->last_query();exit; if($result) { $this->session->set_userdata('suc','successfully added'); redirect('employee'); } else { $this->session->set_userdata('err','Please try again'); redirect('employee'); } } $this->load->view('employee/add',$data); } function editEmployee($empid) { if($this->session->userdata('id')==""){redirect('');} $currentUser=$this->session->userdata('id'); if($this->input->post('submit')) { $employeename=$this->input->post('employeename'); $roleId=$this->input->post('roleId'); $mobileNumber=$this->input->post('mobileNumber'); $address=$this->input->post('address'); $email=$this->input->post('email'); $image=$this->input->post('image'); $hiddenImage=$this->input->post('hiddenImage'); $username=$this->input->post('username'); $password=$this->input->post('password'); $hiddenPassword=$this->input->post('hiddenPassword'); if($password=="") { $newpassword=$hiddenPassword; } else { $newpassword=md5($password); } 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('ymdhi').'.'.$extension1; $targetPath='./uploads/employee/'; $targetFile=$targetPath.$newImage; move_uploaded_file($temp_user_img, $targetFile); } $table="employee"; $where=array("id"=>$empid); $values=array('name'=>$employeename, 'roleId'=>$roleId, 'mobileNumber'=>$mobileNumber, 'address'=>$address, 'email'=>$email, 'username'=>$username, 'image'=>$newImage, 'password'=>$newpassword, '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('employee'); } else { $this->session->set_userdata('err','Please try again'); redirect('employee'); } } $data['role']=$this->Employee_model->list_role(); $data['emp']=$this->Employee_model->viewEmployee($empid); $this->load->view('employee/edit',$data); } function deleteEmployee() { if($this->session->userdata('id')==""){redirect('');} $currentUser=$this->session->userdata('id'); if($this->input->post('submit')) { //echo "test";exit; $employeeId=$this->input->post('employeeId'); //echo $employeeId;exit; $table="employee"; $where=array("id"=>$employeeId); $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('employee'); } else { $this->session->set_userdata('err','Please try again'); redirect('employee'); } } } }