User Creation changes
This commit is contained in:
parent
c517e540bb
commit
b4583d80d3
@ -72,7 +72,11 @@ class Login extends CI_Controller
|
||||
$sessionArray = array('userId'=>$res->userId,
|
||||
'role'=>$res->roleId,
|
||||
'roleText'=>$res->role,
|
||||
'name'=>$res->name,
|
||||
'name'=>$res->FirstName,
|
||||
'Designation'=>$res->Designation,
|
||||
'DEPCode'=>$res->DEPCode,
|
||||
'HeadDept'=>$res->HeadDept,
|
||||
'DepartmentName'=>$res->DepartmentName,
|
||||
'isLoggedIn' => TRUE
|
||||
);
|
||||
|
||||
|
||||
@ -18,6 +18,8 @@ class User extends BaseController
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('user_model');
|
||||
$this->load->library('form_validation');
|
||||
|
||||
$this->isLoggedIn();
|
||||
}
|
||||
|
||||
@ -46,8 +48,7 @@ class User extends BaseController
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
|
||||
|
||||
$searchText = $this->input->post('searchText');
|
||||
$data['searchText'] = $searchText;
|
||||
|
||||
@ -55,7 +56,7 @@ class User extends BaseController
|
||||
|
||||
$count = $this->user_model->userListingCount($searchText);
|
||||
|
||||
$returns = $this->paginationCompress ( "userListing/", $count, 5 );
|
||||
$returns = $this->paginationCompress ( "userListing/", $count, 15 );
|
||||
|
||||
$data['userRecords'] = $this->user_model->userListing($searchText, $returns["page"], $returns["segment"]);
|
||||
|
||||
@ -76,9 +77,10 @@ class User extends BaseController
|
||||
$this->loadThis();
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
$data['roles'] = $this->user_model->getUserRoles();
|
||||
{
|
||||
$data['EmpList'] = $this->user_model->getAllEmployees();
|
||||
|
||||
$data['roles'] = $this->user_model->getUserRoles();
|
||||
|
||||
$this->global['pageTitle'] = 'Siddharth : Add New User';
|
||||
|
||||
@ -103,7 +105,38 @@ class User extends BaseController
|
||||
if(empty($result)){ echo("true"); }
|
||||
else { echo("false"); }
|
||||
}
|
||||
|
||||
/* Validation for Employee Dropdown
|
||||
*/
|
||||
function Employee_validate($selectValue)
|
||||
{
|
||||
//echo 'select_validate method called';
|
||||
// 'none' is the first option and the text says something like "-Choose one-"
|
||||
if($selectValue == '0')
|
||||
{
|
||||
$this->form_validation->set_message('Employee_validate', 'Please Select Employee.');
|
||||
return false;
|
||||
}
|
||||
else // user picked something
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/* Validation for Employee Dropdown
|
||||
*/
|
||||
function Role_validate($selectValue)
|
||||
{
|
||||
//echo 'select_validate method called';
|
||||
// 'none' is the first option and the text says something like "-Choose one-"
|
||||
if($selectValue == '0')
|
||||
{
|
||||
$this->form_validation->set_message('Role_validate', 'Please Select Role.');
|
||||
return false;
|
||||
}
|
||||
else // user picked something
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* This function is used to add new user to the system
|
||||
*/
|
||||
@ -115,14 +148,12 @@ class User extends BaseController
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->load->library('form_validation');
|
||||
|
||||
$this->form_validation->set_rules('fname','Full Name','trim|required|max_length[128]|xss_clean');
|
||||
$this->form_validation->set_rules('email','Email','trim|required|valid_email|xss_clean|max_length[128]');
|
||||
|
||||
$this->form_validation->set_rules('EmpList','EmpList','trim|callback_Employee_validateS');
|
||||
$this->form_validation->set_rules('role','role','trim|callback_Role_validate');
|
||||
$this->form_validation->set_rules('password','Password','required|max_length[20]');
|
||||
$this->form_validation->set_rules('cpassword','Confirm Password','trim|required|matches[password]|max_length[20]');
|
||||
$this->form_validation->set_rules('role','Role','trim|required|numeric');
|
||||
$this->form_validation->set_rules('mobile','Mobile Number','required|min_length[10]|xss_clean');
|
||||
|
||||
|
||||
if($this->form_validation->run() == FALSE)
|
||||
{
|
||||
@ -130,28 +161,32 @@ class User extends BaseController
|
||||
}
|
||||
else
|
||||
{
|
||||
$name = ucwords(strtolower($this->input->post('fname')));
|
||||
$email = $this->input->post('email');
|
||||
$password = $this->input->post('password');
|
||||
$roleId = $this->input->post('role');
|
||||
$mobile = $this->input->post('mobile');
|
||||
|
||||
$userInfo = array('email'=>$email, 'password'=>getHashedPassword($password), 'roleId'=>$roleId, 'name'=> $name,
|
||||
'mobile'=>$mobile, 'createdBy'=>$this->vendorId, 'createdDtm'=>date('Y-m-d H:i:sa'));
|
||||
|
||||
$this->load->model('user_model');
|
||||
$EmpID = $this->input->post('EmpList');
|
||||
$roleId = $this->input->post('role');
|
||||
$password = $this->input->post('password');
|
||||
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
|
||||
$Createddt = $dt->format('Y-m-d H:i:s');
|
||||
|
||||
$email = $this->input->post('MailID');
|
||||
|
||||
|
||||
$userInfo = array('email'=>$email,'EmpID'=>$EmpID,'password'=>getHashedPassword($password),'roleId'=>$roleId,'createdBy'=>$this->vendorId,'createdDtm'=>$Createddt);
|
||||
|
||||
$result = $this->user_model->addNewUser($userInfo);
|
||||
|
||||
if($result > 0)
|
||||
{
|
||||
$this->session->set_flashdata('success', 'New User created successfully');
|
||||
echo "<script>alert('New User Created successfully!');</script>";
|
||||
redirect('userListing','refresh');
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->session->set_flashdata('error', 'User creation failed');
|
||||
}
|
||||
echo $result;
|
||||
redirect('addNew');
|
||||
echo "<script>alert('Failiure User Creation!');</script>";
|
||||
redirect('userListing','refresh');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -161,21 +196,32 @@ class User extends BaseController
|
||||
* This function is used load user edit information
|
||||
* @param number $userId : Optional : This is user id
|
||||
*/
|
||||
function editOld($userId = NULL)
|
||||
function editOld($UserId = '')
|
||||
{
|
||||
if($this->isAdmin() == TRUE || $userId == 1)
|
||||
if($this->isAdmin() == TRUE )
|
||||
{
|
||||
$this->loadThis();
|
||||
}
|
||||
else
|
||||
{
|
||||
if($userId == null)
|
||||
if($UserId == '')
|
||||
{
|
||||
redirect('userListing');
|
||||
// redirect('userListing');
|
||||
}
|
||||
|
||||
|
||||
$Uid = $_GET['UID'];
|
||||
|
||||
|
||||
|
||||
$data['roles'] = $this->user_model->getUserRoles();
|
||||
$data['userInfo'] = $this->user_model->getUserInfo($userId);
|
||||
|
||||
//print_r($data);
|
||||
|
||||
$data['EmpList'] = $this->user_model->GetEmployeeDetails($Uid);
|
||||
//print_r($data);
|
||||
$data['EmpRole'] = $this->user_model->GetRoleNameByUserID($Uid);
|
||||
|
||||
// $data['userInfo'] = $this->user_model->getUserInfo($userId);
|
||||
|
||||
$this->global['pageTitle'] = 'Siddharth : Edit User';
|
||||
|
||||
@ -195,16 +241,11 @@ class User extends BaseController
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->load->library('form_validation');
|
||||
|
||||
$userId = $this->input->post('userId');
|
||||
|
||||
$this->form_validation->set_rules('fname','Full Name','trim|required|max_length[128]|xss_clean');
|
||||
$this->form_validation->set_rules('email','Email','trim|required|valid_email|xss_clean|max_length[128]');
|
||||
$this->form_validation->set_rules('password','Password','matches[cpassword]|max_length[20]');
|
||||
$this->form_validation->set_rules('cpassword','Confirm Password','matches[password]|max_length[20]');
|
||||
$this->form_validation->set_rules('role','Role','trim|required|numeric');
|
||||
$this->form_validation->set_rules('mobile','Mobile Number','required|min_length[10]|xss_clean');
|
||||
$userId = $this->session->userdata ( 'userId' );
|
||||
$this->form_validation->set_rules('EmpList','EmpList','trim|callback_Employee_validateS');
|
||||
$this->form_validation->set_rules('role','role','trim|callback_Role_validate');
|
||||
$this->form_validation->set_rules('password','Password','required|max_length[20]');
|
||||
$this->form_validation->set_rules('cpassword','Confirm Password','trim|required|matches[password]|max_length[20]');
|
||||
|
||||
if($this->form_validation->run() == FALSE)
|
||||
{
|
||||
@ -212,25 +253,21 @@ class User extends BaseController
|
||||
}
|
||||
else
|
||||
{
|
||||
$name = ucwords(strtolower($this->input->post('fname')));
|
||||
$email = $this->input->post('email');
|
||||
$password = $this->input->post('password');
|
||||
$roleId = $this->input->post('role');
|
||||
$mobile = $this->input->post('mobile');
|
||||
//$EmpID = $this->input->post('EmpList');
|
||||
$roleId = $this->input->post('role');
|
||||
$password = $this->input->post('password');
|
||||
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
|
||||
$updatedDate = $dt->format('Y-m-d H:i:s');
|
||||
|
||||
|
||||
$userInfo = array();
|
||||
|
||||
if(empty($password))
|
||||
{
|
||||
$userInfo = array('email'=>$email, 'roleId'=>$roleId, 'name'=>$name,
|
||||
'mobile'=>$mobile, 'updatedBy'=>$this->vendorId, 'updatedDtm'=>date('Y-m-d H:i:sa'));
|
||||
}
|
||||
else
|
||||
{
|
||||
$userInfo = array('email'=>$email, 'password'=>getHashedPassword($password), 'roleId'=>$roleId,
|
||||
'name'=>ucwords($name), 'mobile'=>$mobile, 'updatedBy'=>$this->vendorId,
|
||||
'updatedDtm'=>date('Y-m-d H:i:sa'));
|
||||
}
|
||||
|
||||
$userInfo = array();
|
||||
|
||||
|
||||
$userInfo = array('password'=>getHashedPassword($password),'roleId'=>$roleId,'updatedBy'=>$this->vendorId,'updatedDtm'=>$updatedDate);
|
||||
|
||||
|
||||
|
||||
|
||||
$result = $this->user_model->editUser($userInfo, $userId);
|
||||
|
||||
@ -255,20 +292,18 @@ class User extends BaseController
|
||||
*/
|
||||
function deleteUser()
|
||||
{
|
||||
if($this->isAdmin() == TRUE)
|
||||
{
|
||||
echo(json_encode(array('status'=>'access')));
|
||||
}
|
||||
else
|
||||
{
|
||||
$userId = $this->input->post('userId');
|
||||
$userInfo = array('isDeleted'=>1,'updatedBy'=>$this->vendorId, 'updatedDtm'=>date('Y-m-d H:i:sa'));
|
||||
echo 'Delete';
|
||||
$Uid = $this->input->post('id');
|
||||
|
||||
$result = $this->user_model->deleteUser($userId, $userInfo);
|
||||
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
|
||||
$updatedDate = $dt->format('Y-m-d H:i:s');
|
||||
|
||||
$userInfo = array('isDeleted'=>1,'updatedBy'=>$this->vendorId, 'updatedDtm'=>$updatedDate);
|
||||
|
||||
$result = $this->user_model->deleteUser($Uid, $userInfo);
|
||||
|
||||
if ($result > 0) { echo(json_encode(array('status'=>TRUE))); }
|
||||
else { echo(json_encode(array('status'=>FALSE))); }
|
||||
}
|
||||
echo 'Succssfully change the user status to InAcive';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
Reference in New Issue
Block a user