McGansWebsite/admin/application/controllers/Employee.php

194 lines
5.2 KiB
PHP
Raw Normal View History

2023-01-05 12:19:39 +00:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Employee extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Employee_model');
$this->load->model('Commonsql_model');
}
2023-01-11 07:17:57 +00:00
2023-01-05 12:19:39 +00:00
public function employee_list()
{
if($this->session->userdata('id')==""){redirect('');}
2023-01-05 12:19:39 +00:00
$data['emp']=$this->Employee_model->list_emp();
2023-01-11 07:17:57 +00:00
$this->load->view('employee/list',$data);
2023-01-05 12:19:39 +00:00
}
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);
}
2023-01-05 12:19:39 +00:00
function add_employee()
{
if($this->session->userdata('id')==""){redirect('');}
2023-01-11 07:17:57 +00:00
$data['role']=$this->Employee_model->list_role();
2023-01-05 12:19:39 +00:00
if($this->input->post('submit'))
{
//echo "dsdsd";exit;
2023-01-05 12:19:39 +00:00
$employeename=$this->input->post('employeename');
2023-01-08 20:46:58 +00:00
$mobileNumber=$this->input->post('mobileNumber');
2023-01-11 07:17:57 +00:00
$roleId=$this->input->post('roleId');
2023-01-05 12:19:39 +00:00
$address=$this->input->post('address');
$email=$this->input->post('email');
$code=$this->input->post('code');
$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);
}
2023-01-05 12:19:39 +00:00
$table="employee";
$values=array('name'=>$employeename,
2023-01-08 20:46:58 +00:00
'mobileNumber'=>$mobileNumber,
2023-01-11 07:17:57 +00:00
'roleId'=>$roleId,
2023-01-05 12:19:39 +00:00
'address'=>$address,
'email'=>$email,
'pincode'=>$code,
'image'=>$eImage,
2023-01-05 12:19:39 +00:00
'username'=>$user,
'password'=>md5($password),
2023-01-08 20:46:58 +00:00
'createdOn'=>date('Y-m-d'),
'createdBy'=>1,
2023-01-05 12:19:39 +00:00
'status'=>1);
$result=$this->Commonsql_model->insert_table($table,$values);
//echo $this->db->last_query();exit;
2023-01-05 12:19:39 +00:00
if($result)
2023-01-11 07:17:57 +00:00
{
$this->session->set_userdata('suc','successfully added');
redirect('employee');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('employee');
}
2023-01-05 12:19:39 +00:00
}
2023-01-11 07:17:57 +00:00
$this->load->view('employee/add',$data);
2023-01-05 12:19:39 +00:00
}
function editEmployee($empid)
2023-01-05 12:19:39 +00:00
{
if($this->session->userdata('id')==""){redirect('');}
2023-01-05 12:19:39 +00:00
if($this->input->post('submit'))
{
$employeename=$this->input->post('employeename');
$roleId=$this->input->post('roleId');
2023-01-08 20:46:58 +00:00
$mobileNumber=$this->input->post('mobileNumber');
2023-01-05 12:19:39 +00:00
$address=$this->input->post('address');
$email=$this->input->post('email');
$code=$this->input->post('code');
$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');
2023-01-05 12:19:39 +00:00
if($password=="")
{
$newpassword=$hiddenPassword;
2023-01-05 12:19:39 +00:00
}
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);
}
2023-01-05 12:19:39 +00:00
$table="employee";
$where=array("id"=>$empid);
$values=array('name'=>$employeename,
'roleId'=>$roleId,
2023-01-08 20:46:58 +00:00
'mobileNumber'=>$mobileNumber,
2023-01-05 12:19:39 +00:00
'address'=>$address,
'email'=>$email,
'pincode'=>$code,
'username'=>$username,
'image'=>$newImage,
2023-01-05 12:19:39 +00:00
'password'=>$newpassword,
2023-01-08 20:46:58 +00:00
'updatedOn'=>date('Y-m-d'),
'updatedBy'=>1,
2023-01-05 12:19:39 +00:00
'status'=>1);
$result=$this->Commonsql_model->updateTable($table,$where,$values);
//echo $this->db->last_query();exit;
2023-01-05 12:19:39 +00:00
if($result)
{
$this->session->set_userdata('suc','successfully Updated');
redirect('employee');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('employee');
}
2023-01-05 12:19:39 +00:00
}
$data['role']=$this->Employee_model->list_role();
$data['emp']=$this->Employee_model->viewEmployee($empid);
$this->load->view('employee/edit',$data);
2023-01-05 12:19:39 +00:00
}
function deleteEmployee()
2023-01-05 12:19:39 +00:00
{
if($this->session->userdata('id')==""){redirect('');}
2023-01-05 12:19:39 +00:00
if($this->input->post('submit'))
{
//echo "test";exit;
$employeeId=$this->input->post('employeeId');
//echo $employeeId;exit;
2023-01-05 12:19:39 +00:00
$table="employee";
$where=array("id"=>$employeeId);
$values=array('status'=>0);
2023-01-05 12:19:39 +00:00
$result=$this->Commonsql_model->updateTable($table,$where,$values);
2023-01-05 12:19:39 +00:00
if($result)
{
$this->session->set_userdata('suc','successfully deleted');
redirect('employee');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('employee');
}
2023-01-05 12:19:39 +00:00
}
}
}