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,
|
$sessionArray = array('userId'=>$res->userId,
|
||||||
'role'=>$res->roleId,
|
'role'=>$res->roleId,
|
||||||
'roleText'=>$res->role,
|
'roleText'=>$res->role,
|
||||||
'name'=>$res->name,
|
'name'=>$res->FirstName,
|
||||||
|
'Designation'=>$res->Designation,
|
||||||
|
'DEPCode'=>$res->DEPCode,
|
||||||
|
'HeadDept'=>$res->HeadDept,
|
||||||
|
'DepartmentName'=>$res->DepartmentName,
|
||||||
'isLoggedIn' => TRUE
|
'isLoggedIn' => TRUE
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,8 @@ class User extends BaseController
|
|||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->load->model('user_model');
|
$this->load->model('user_model');
|
||||||
|
$this->load->library('form_validation');
|
||||||
|
|
||||||
$this->isLoggedIn();
|
$this->isLoggedIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +48,6 @@ class User extends BaseController
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->load->model('user_model');
|
|
||||||
|
|
||||||
$searchText = $this->input->post('searchText');
|
$searchText = $this->input->post('searchText');
|
||||||
$data['searchText'] = $searchText;
|
$data['searchText'] = $searchText;
|
||||||
@ -55,7 +56,7 @@ class User extends BaseController
|
|||||||
|
|
||||||
$count = $this->user_model->userListingCount($searchText);
|
$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"]);
|
$data['userRecords'] = $this->user_model->userListing($searchText, $returns["page"], $returns["segment"]);
|
||||||
|
|
||||||
@ -77,8 +78,9 @@ class User extends BaseController
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->load->model('user_model');
|
$data['EmpList'] = $this->user_model->getAllEmployees();
|
||||||
$data['roles'] = $this->user_model->getUserRoles();
|
|
||||||
|
$data['roles'] = $this->user_model->getUserRoles();
|
||||||
|
|
||||||
$this->global['pageTitle'] = 'Siddharth : Add New User';
|
$this->global['pageTitle'] = 'Siddharth : Add New User';
|
||||||
|
|
||||||
@ -103,7 +105,38 @@ class User extends BaseController
|
|||||||
if(empty($result)){ echo("true"); }
|
if(empty($result)){ echo("true"); }
|
||||||
else { echo("false"); }
|
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
|
* This function is used to add new user to the system
|
||||||
*/
|
*/
|
||||||
@ -115,14 +148,12 @@ class User extends BaseController
|
|||||||
}
|
}
|
||||||
else
|
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('EmpList','EmpList','trim|callback_Employee_validateS');
|
||||||
$this->form_validation->set_rules('email','Email','trim|required|valid_email|xss_clean|max_length[128]');
|
$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('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('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)
|
if($this->form_validation->run() == FALSE)
|
||||||
{
|
{
|
||||||
@ -130,28 +161,32 @@ class User extends BaseController
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$name = ucwords(strtolower($this->input->post('fname')));
|
$EmpID = $this->input->post('EmpList');
|
||||||
$email = $this->input->post('email');
|
$roleId = $this->input->post('role');
|
||||||
$password = $this->input->post('password');
|
$password = $this->input->post('password');
|
||||||
$roleId = $this->input->post('role');
|
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
|
||||||
$mobile = $this->input->post('mobile');
|
$Createddt = $dt->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
$userInfo = array('email'=>$email, 'password'=>getHashedPassword($password), 'roleId'=>$roleId, 'name'=> $name,
|
$email = $this->input->post('MailID');
|
||||||
'mobile'=>$mobile, 'createdBy'=>$this->vendorId, 'createdDtm'=>date('Y-m-d H:i:sa'));
|
|
||||||
|
|
||||||
|
$userInfo = array('email'=>$email,'EmpID'=>$EmpID,'password'=>getHashedPassword($password),'roleId'=>$roleId,'createdBy'=>$this->vendorId,'createdDtm'=>$Createddt);
|
||||||
|
|
||||||
$this->load->model('user_model');
|
|
||||||
$result = $this->user_model->addNewUser($userInfo);
|
$result = $this->user_model->addNewUser($userInfo);
|
||||||
|
|
||||||
if($result > 0)
|
if($result > 0)
|
||||||
{
|
{
|
||||||
$this->session->set_flashdata('success', 'New User created successfully');
|
echo "<script>alert('New User Created successfully!');</script>";
|
||||||
|
redirect('userListing','refresh');
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->session->set_flashdata('error', 'User creation failed');
|
echo "<script>alert('Failiure User Creation!');</script>";
|
||||||
|
redirect('userListing','refresh');
|
||||||
|
|
||||||
}
|
}
|
||||||
echo $result;
|
|
||||||
redirect('addNew');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,21 +196,32 @@ class User extends BaseController
|
|||||||
* This function is used load user edit information
|
* This function is used load user edit information
|
||||||
* @param number $userId : Optional : This is user id
|
* @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();
|
$this->loadThis();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if($userId == null)
|
if($UserId == '')
|
||||||
{
|
{
|
||||||
redirect('userListing');
|
// redirect('userListing');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$Uid = $_GET['UID'];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$data['roles'] = $this->user_model->getUserRoles();
|
$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';
|
$this->global['pageTitle'] = 'Siddharth : Edit User';
|
||||||
|
|
||||||
@ -195,16 +241,11 @@ class User extends BaseController
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->load->library('form_validation');
|
$userId = $this->session->userdata ( 'userId' );
|
||||||
|
$this->form_validation->set_rules('EmpList','EmpList','trim|callback_Employee_validateS');
|
||||||
$userId = $this->input->post('userId');
|
$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('fname','Full Name','trim|required|max_length[128]|xss_clean');
|
$this->form_validation->set_rules('cpassword','Confirm Password','trim|required|matches[password]|max_length[20]');
|
||||||
$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');
|
|
||||||
|
|
||||||
if($this->form_validation->run() == FALSE)
|
if($this->form_validation->run() == FALSE)
|
||||||
{
|
{
|
||||||
@ -212,25 +253,21 @@ class User extends BaseController
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$name = ucwords(strtolower($this->input->post('fname')));
|
//$EmpID = $this->input->post('EmpList');
|
||||||
$email = $this->input->post('email');
|
$roleId = $this->input->post('role');
|
||||||
$password = $this->input->post('password');
|
$password = $this->input->post('password');
|
||||||
$roleId = $this->input->post('role');
|
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
|
||||||
$mobile = $this->input->post('mobile');
|
$updatedDate = $dt->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$userInfo = array();
|
||||||
|
|
||||||
|
|
||||||
|
$userInfo = array('password'=>getHashedPassword($password),'roleId'=>$roleId,'updatedBy'=>$this->vendorId,'updatedDtm'=>$updatedDate);
|
||||||
|
|
||||||
|
|
||||||
$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'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $this->user_model->editUser($userInfo, $userId);
|
$result = $this->user_model->editUser($userInfo, $userId);
|
||||||
|
|
||||||
@ -255,20 +292,18 @@ class User extends BaseController
|
|||||||
*/
|
*/
|
||||||
function deleteUser()
|
function deleteUser()
|
||||||
{
|
{
|
||||||
if($this->isAdmin() == TRUE)
|
echo 'Delete';
|
||||||
{
|
$Uid = $this->input->post('id');
|
||||||
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'));
|
|
||||||
|
|
||||||
$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);
|
||||||
|
|
||||||
|
echo 'Succssfully change the user status to InAcive';
|
||||||
|
|
||||||
if ($result > 0) { echo(json_encode(array('status'=>TRUE))); }
|
|
||||||
else { echo(json_encode(array('status'=>FALSE))); }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user