McGansWebsite/admin/application/controllers/Employee.php
dotwingssoftware e71c4c7872 20230111
20230111
2023-01-11 12:47:57 +05:30

148 lines
3.6 KiB
PHP

<?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');
}
public function employee_list()
{
$data['emp']=$this->Employee_model->list_emp();
$this->load->view('employee/list',$data);
}
function add_employee()
{
$data['role']=$this->Employee_model->list_role();
if($this->input->post('submit'))
{
$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');
$code=$this->input->post('code');
$img=$this->input->post('img');
$user=$this->input->post('User');
$password=$this->input->post('Password');
$table="employee";
$values=array('name'=>$employeename,
'mobileNumber'=>$mobileNumber,
'roleId'=>$roleId,
'address'=>$address,
'email'=>$email,
'pincode'=>$code,
'image'=>$img,
'username'=>$user,
'password'=>$password,
'createdOn'=>date('Y-m-d'),
'createdBy'=>1,
'status'=>1);
$result=$this->Commonsql_model->insert_table($table,$values);
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->input->post('submit'))
{
$employeename=$this->input->post('employeename');
$mobileNumber=$this->input->post('mobileNumber');
$address=$this->input->post('address');
$email=$this->input->post('email');
$code=$this->input->post('code');
$img=$this->input->post('img');
$user=$this->input->post('User');
$password=$this->input->post('Password');
$hiddenpass=$this->input->post('hiddenpass');
if($password=="")
{
$newpassword=$hiddenpass;
}
else
{
$newpassword=md5($password);
}
$table="employee";
$where=array("id"=>$empid);
$values=array('name'=>$employeename,
'mobileNumber'=>$mobileNumber,
'address'=>$address,
'email'=>$email,
'pincode'=>$code,
'username'=>$user,
'image'=>$img,
'password'=>$newpassword,
'updatedOn'=>date('Y-m-d'),
'updatedBy'=>1,
'status'=>1);
$result=$this->Commonsql_model->updateTable($table,$where,$values);
if($result)
{
$this->session->set_userdata('suc','successfully Updated');
redirect('employee');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('employee');
}
}
//echo "sdsd";exit;
$data['emp']=$this->Employee_model->get_emp($empid);
//echo $this->db->last_query();exit;
$this->load->view('add_emplayee/edit',$data);
}
function deleted_employee()
{
if($this->input->post('submit'))
{
$empid=$this->input->post('hiddenid');
$table="employee";
$where=array("id"=>$empid);
$values=array(
'status'=>0);
$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');
}
}
}
}