policybot/application/controllers/Staff.php
2021-11-30 16:26:55 +05:30

126 lines
3.4 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
date_default_timezone_set('Asia/Kolkata');
class Staff extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Staff_model');
$this->load->model('Role_model');
}
function list_staff()
{
if($this->session->userdata('id')==""){redirect('admin/login');}
$data['staff']=$this->Staff_model->list_staffs();
$this->load->view('admin/staff/list',$data);
}
function add_staff()
{
if($this->session->userdata('id')==""){redirect('admin/login');}
if($this->input->post('addstaff'))
{
$name=$this->input->post('Name');
$Role=$this->input->post('Role');
$Mobile=$this->input->post('Mobile');
$Email=$this->input->post('Email');
$loginvalue=$this->input->post('loginvalue');
$username=$this->input->post('username');
$password=$this->input->post('password');
$table="staff";
//echo $ledgername;
$values=array('role'=>$Role,
'name'=>$name,
'email'=>$Email,
'mobile'=>$Mobile,
'username'=>$username,
'password'=>md5($password),
'cdate'=>date('Y-m-d H:i:s'),
'status'=>1);
$result=$this->commonsql_model->insert_table($table,$values);
if($result)
{
$this->session->set_userdata('suc','successfully added');
redirect('admin/staff');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('admin/staff');
}
}
$data['role']=$this->Role_model->list_roles();
$this->load->view('admin/staff/add',$data);
}
function edit_staff($id)
{
if($this->session->userdata('id')==""){redirect('admin/login');}
if($this->input->post('addstaff'))
{
$name=$this->input->post('Name');
$Role=$this->input->post('Role');
$Mobile=$this->input->post('Mobile');
$Email=$this->input->post('Email');
$loginvalue=$this->input->post('loginvalue');
$username=$this->input->post('username');
$password=$this->input->post('password');
$old_pass=$this->input->post('old_pass');
if($password==""){ $curr_pass=$old_pass; }
else { $curr_pass=md5($password); }
$table="staff";
//echo $ledgername;
$values=array('role'=>$Role,
'name'=>$name,
'email'=>$Email,
'mobile'=>$Mobile,
'username'=>$username,
'password'=>$curr_pass,
'udate'=>date('Y-m-d H:i:s'),
'status'=>1);
$where=array("id"=>$id);
$result=$this->commonsql_model->updatetable($table,$where,$values);
if($result)
{
$this->session->set_userdata('suc','successfully updated');
redirect('admin/staff');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('admin/staff');
}
}
$data['role']=$this->Role_model->list_roles();
$data['staff']=$this->Staff_model->list_staffs($id);
$this->load->view('admin/staff/edit',$data);
}
function delete_staff($id)
{
if($this->session->userdata('id')==""){redirect('admin/login');}
if($this->input->post('yes'))
{
$table="staff";
//echo $ledgername;
$values=array(
'status'=>0);
$where=array("id"=>$id);
$result=$this->commonsql_model->updatetable($table,$where,$values);
if($result)
{
$this->session->set_userdata('suc','successfully deleted');
redirect('admin/staff');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('admin/staff');
}
}
}
}
?>