diff --git a/application/config/constants.php b/application/config/constants.php index af236578..e5ea10c2 100644 --- a/application/config/constants.php +++ b/application/config/constants.php @@ -139,6 +139,7 @@ define('FINANCE', 'DEP10'); define('PURCHASE', 'DEP11'); define('MANAGEMENT', 'DEP12'); define('HR', 'DEP13'); +define('SYSTEM_ADMIN', '1'); /* PO Type */ define('REVENUE', 'REVENUE'); define('SERVICE', 'SERVICE'); diff --git a/application/controllers/login.php b/application/controllers/login.php index cb4430b7..cc33d939 100644 --- a/application/controllers/login.php +++ b/application/controllers/login.php @@ -53,7 +53,7 @@ class Login extends CI_Controller $this->load->library('form_validation'); - $this->form_validation->set_rules('email', 'Email', 'required|valid_email|max_length[128]|xss_clean|trim'); + $this->form_validation->set_rules('password', 'Password', 'required|max_length[32]|'); $designation=''; $role=''; @@ -79,22 +79,24 @@ class Login extends CI_Controller 'name'=>$res->FirstName, 'Designation'=>$res->Designation, 'DEPCode'=>$res->DEPCode, - 'HeadDept'=>$res->HeadDept, + 'HeadDept'=>$res->HeadDept, + 'depaccess'=>$this->login_model->Accessdep($res->EmpID), 'DepartmentName'=>$res->DepartmentName, - 'EmpID' => $res->EmpID, - 'ProfilePic' =>$res->ProfilePic, + 'EmpID' => $res->EmpID, + 'ProfilePic' =>$res->ProfilePic, 'isLoggedIn' => TRUE ); $this->session->set_userdata($sessionArray); - $role=$res->roleId; - $designation=$res->Designation; + $role=$res->roleId; + $designation=$res->Designation; + $DEPCode=$res->DEPCode; } - if ($role == ROLE_EMPLOYEE && $designation == SECURITY) + if ($DEPCode == SECURITY) { redirect('/Addigr'); } @@ -130,4 +132,4 @@ class Login extends CI_Controller } -?> +?> \ No newline at end of file diff --git a/application/controllers/user.php b/application/controllers/user.php index b52b30ce..aa8f0ffc 100755 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -20,7 +20,7 @@ class user extends BaseController $this->load->model('user_model'); $this->load->model('dahsboard_Model'); $this->load->library('form_validation'); - /*$this->load->model('costcenter_model');*/ + $this->load->model('costcenter_model'); $this->isLoggedIn(); } @@ -31,33 +31,30 @@ class user extends BaseController public function index() { $this->global['pageTitle'] = 'Resico : Dashboard'; + + $this->load->model('employeedetails_model'); + $this->load->model('dahsboard_Model'); - $this->load->model('employeedetails_model'); - - - $this->load->model('dahsboard_Model'); - - $data['EmpCount'] = $this->employeedetails_model->getEmployeeCount(); - $data['UserCount'] = $this->dahsboard_Model->getUserCount(); - $data['totalpurchaseorder']=$this->dahsboard_Model->totalpurchaseorder(); - - - $data['totalordervalue']=$this->dahsboard_Model->totalordervalue(); - $data['pendingpo']=$this->dahsboard_Model->pendingpo(); - - $data['totalimportpo']=$this->dahsboard_Model->totalimportpo(); - - - $data['details']=$this->dahsboard_Model->reqdetail(); - - $data['pending_details']=$this->dahsboard_Model->req_pending(); - - - $data['serviceprogress']=$this->dahsboard_Model->serviceprogress(); + $data['EmpCount'] = $this->employeedetails_model->getEmployeeCount(); + $data['UserCount'] = $this->dahsboard_Model->getUserCount(); + $data['totalpurchaseorder']=$this->dahsboard_Model->totalpurchaseorder(); + + $data['totalordervalue']=$this->dahsboard_Model->totalordervalue(); + + $data['pendingpo']=$this->dahsboard_Model->pendingpo(); + + $data['totalimportpo']=$this->dahsboard_Model->totalimportpo(); + + $data['details']=$this->dahsboard_Model->reqdetail(); + + $data['pending_details']=$this->dahsboard_Model->req_pending(); + + $data['serviceprogress']=$this->dahsboard_Model->serviceprogress(); $data['revenueprogress']=$this->dahsboard_Model->revenueprogress(); $data['importprogress']=$this->dahsboard_Model->importprogress(); $data['capitalprogress']=$this->dahsboard_Model->capitalprogress(); - //month-wise area chart + + //month-wise area chart $data['getTotalServicePoCount'] = $this->dahsboard_Model->getTotalServicePoCount(); $data['getTotalimportPoCount'] = $this->dahsboard_Model->getTotalimportPoCount(); $data['getTotalcapitalPoCount'] = $this->dahsboard_Model->getTotalcapitalPoCount(); @@ -65,12 +62,12 @@ class user extends BaseController //dashboard pie chart - $data['importbudgt'] = $this->dahsboard_Model->importbudgt(); - $data['servicebudgt'] = $this->dahsboard_Model->servicebudgt(); - $data['revenuebudgt'] = $this->dahsboard_Model->revenuebudgt(); - $data['capitalbud'] = $this->dahsboard_Model->capitalbud(); - $data['typebal'] = $this->dahsboard_Model->typebal(); - + $data['importbudgt'] = $this->dahsboard_Model->importbudgt(); + $data['servicebudgt'] = $this->dahsboard_Model->servicebudgt(); + $data['revenuebudgt'] = $this->dahsboard_Model->revenuebudgt(); + $data['capitalbud'] = $this->dahsboard_Model->capitalbud(); + $data['typebal'] = $this->dahsboard_Model->typebal(); + /* HR DASHBOARD Controller Start*/ @@ -79,6 +76,7 @@ class user extends BaseController $data['totpay'] = $this->dahsboard_Model->totpay(); $data['totrec'] = $this->dahsboard_Model->totrec(); $data['emplist'] = $this->dahsboard_Model->emplist(); + $date = $this->input->post("id"); $dates = date('Y-m'); $date = $dates . '-01'; @@ -957,19 +955,19 @@ function attendanceyear($empID ='') */ function userListing() { - if($this->isAdmin() == TRUE) - { - $this->loadThis(); - } - else - { + // if($this->isAdmin() == TRUE) + // { + // $this->loadThis(); + // } + // else + // { $data['userRecords'] = $this->user_model->userListing(); $this->global['pageTitle'] = 'Resico : User Listing'; $this->loadViews("users", $this->global, $data, NULL); - } + //} } @@ -978,22 +976,22 @@ function attendanceyear($empID ='') */ function addNew() { - if($this->isAdmin() == TRUE) - { - $this->loadThis(); - } - else - { + // if($this->isAdmin() == TRUE) + // { + // $this->loadThis(); + // } + // else + // { $data['EmpList'] = $this->user_model->getAllEmployees(); $data['roles'] = $this->user_model->getUserRoles(); - //$data['Department'] = $this->costcenter_model->getDepartment(); + $data['Department'] = $this->costcenter_model->getDepartment(); $this->global['pageTitle'] = 'Resico : Add New User'; $this->loadViews("addNew", $this->global, $data, NULL); - } + //} } @@ -1051,87 +1049,101 @@ function attendanceyear($empID ='') */ function addNewUser() { - if($this->isAdmin() == TRUE) - { - $this->loadThis(); - } - else - { + // if($this->isAdmin() == TRUE) + // { + // $this->loadThis(); + // } + // else + // { - $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) - { - $this->addNew(); - } - else - { - $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) - { - - redirect('userListing','refresh'); - echo ""; + + $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) + { + $this->addNew(); + } else { - - redirect('userListing','refresh'); - echo ""; - } - + $EmpID = $this->input->post('EmpList'); + $roleId = '2'; + $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'); + $SelectedDepartment = $this->input->post('txtSelectedDepartment'); + $comma_separated = explode(':', $SelectedDepartment); + $userInfo = array('email'=>$email,'EmpID'=>$EmpID,'password'=>getHashedPassword($password),'roleId'=>$roleId,'createdBy'=>$this->vendorId,'createdDtm'=>$Createddt); + + $result = $this->user_model->addNewUser($userInfo); + + if($SelectedDepartment != '') + { + + for ($j = 0; $j < count($comma_separated); $j++) + { + $DeptCode = $comma_separated[$j]; + $userdept=array('EmpID'=>$EmpID,'Departmentcode'=>$DeptCode); + + $access= $this->user_model->addAccess($userdept); + } + } + + + if($result > 0) + { + + + echo ""; + redirect('userListing','refresh'); + + } + else + { + + redirect('userListing','refresh'); + echo ""; + } + + } + //} + } + + + function Adduserdepartment() + { + $empid= $this->input->post('Eid'); + $Depcode= $this->input->post('Department'); + $userdept=array('EmpID'=>$empid,'Departmentcode'=>$Depcode); + + $access= $this->user_model->addAccess($userdept); + if($access>0) + { + echo "Successfully Added"; } } - } + - - -function Adduserdepartment() - { - $empid= $this->input->post('Eid'); - $Depcode= $this->input->post('Department'); - $userdept=array('EmpID'=>$empid,'Departmentcode'=>$Depcode); - - $access= $this->user_model->addAccess($userdept); - if($access>0) + function Deleteuserdepartment() { - echo "Successfully Added"; + $empid= $this->input->post('Eid'); + $Depcode= $this->input->post('Department'); + $userdept=array('EmpID'=>$empid,'Departmentcode'=>$Depcode); + + $access= $this->user_model->DeleteAccess($empid,$Depcode); + + if($access>0) + { + echo "Successfully Deleted"; + } + } - } - - - function Deleteuserdepartment() - { - $empid= $this->input->post('Eid'); - $Depcode= $this->input->post('Department'); - $userdept=array('EmpID'=>$empid,'Departmentcode'=>$Depcode); - - $access= $this->user_model->DeleteAccess($empid,$Depcode); - - if($access>0) - { - echo "Successfully Deleted"; - } - - } - + /** * This function is used load user edit information @@ -1139,49 +1151,48 @@ function Adduserdepartment() */ function editOld($UserId = '') { - if($this->isAdmin() == TRUE ) - { - $this->loadThis(); - } - else - { + // if($this->isAdmin() == TRUE ) + // { + // $this->loadThis(); + // } + // else + // { if($UserId == '') { // redirect('userListing'); } $Uid = $_GET['UID']; - + $Empid = $_GET['EMPID'];//to ask $data['roles'] = $this->user_model->getUserRoles(); - //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); - + + $data['Departmentlist'] = $this->costcenter_model->getDepartmentnotadded($Empid); + $data['EmpRole'] = $this->user_model->GetRoleNameByUserID($Uid); + $data['AccessDept'] = $this->costcenter_model ->getaccessDept($Empid); + $this->global['pageTitle'] = 'Resico : Edit User'; $this->loadViews("editOld", $this->global, $data, NULL); - } + } + /** * This function is used to edit the user information */ function editUser() { - if($this->isAdmin() == TRUE) - { - $this->loadThis(); - } - else - { + // if($this->isAdmin() == TRUE) + // { + // $this->loadThis(); + // } + // else + // { $userId = $this->input->post('EmpList'); $this->form_validation->set_rules('EmpList','EmpList','trim|callback_Employee_validateS'); $this->form_validation->set_rules('role','role','trim|callback_Role_validate'); @@ -1193,39 +1204,39 @@ function Adduserdepartment() $this->editOld($userId); } else - { - $EmpID = $this->input->post('EmpList'); - $role = $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'); - - // echo $EmpID; - - $userInfo = array(); - - - $userInfo = array('password'=>getHashedPassword($password),'roleId'=>$role,'EmpId'=>$EmpID,'updatedDtm'=>$updatedDate); - - - + { + $EmpID = $this->input->post('EmpList'); + $role = $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'); + + // echo $EmpID; - $result = $this->user_model->editUser($userInfo, $EmpID); + $userInfo = array(); + + + $userInfo = array('password'=>getHashedPassword($password),'roleId'=>$role,'EmpId'=>$EmpID,'updatedDtm'=>$updatedDate); + + - if($result == true) - { - $this->session->set_flashdata('success', 'User updated successfully'); + + $result = $this->user_model->editUser($userInfo, $EmpID); + + if($result == true) + { + $this->session->set_flashdata('success', 'User updated successfully'); + } + else + { + $this->session->set_flashdata('error', 'User updation failed'); + } + + redirect('userListing'); } - else - { - $this->session->set_flashdata('error', 'User updation failed'); - } - - redirect('userListing'); - } + //} } - } - + /** @@ -1246,7 +1257,7 @@ function Adduserdepartment() echo 'Succssfully change the user status to InAcive'; } - + /** * To load the change password screen */ @@ -1310,17 +1321,8 @@ function Adduserdepartment() $this->loadViews("404", $this->global, NULL, NULL); } - - - - - - /////////////* this function used to Material Inward Register report controller parts*////////////////////// - - - function getMaterialInwardRegister() { @@ -1338,16 +1340,6 @@ function Adduserdepartment() $this->loadViews("Report_Material_inward_Register", $this->global,$data,NULL); } - - - - - - - - - - } ?> \ No newline at end of file diff --git a/application/libraries/BaseController.php b/application/libraries/BaseController.php index 8914a758..b1c72aca 100644 --- a/application/libraries/BaseController.php +++ b/application/libraries/BaseController.php @@ -16,6 +16,7 @@ class BaseController extends CI_Controller { protected $HeadDept = ''; protected $DepartmentName = ''; protected $roleText = ''; + //Protected depaccess = ''; protected $global = array (); /** @@ -49,12 +50,14 @@ class BaseController extends CI_Controller { $this->HeadDept = $this->session->userdata ( 'HeadDept' ); $this->DepartmentName = $this->session->userdata ( 'DepartmentName' ); $this->EmpID = $this->session->userdata ( 'EmpID' ); + $this->depaccess = $this->session->userdata ('depaccess'); $this->profilepic = $this->session->userdata ( 'ProfilePic' ); $this->global ['name'] = $this->name; $this->global ['role'] = $this->role; $this->global ['role_text'] = $this->roleText; $this->global ['DEPCode'] = $this->DEPCode; $this->global ['Designation'] = $this->Designation; + $this->global ['DepAccesslist'] = $this->depaccess; } } @@ -84,8 +87,8 @@ class BaseController extends CI_Controller { * This function is used to load the set of views */ function loadThis() { - $this->global ['pageTitle'] = 'Resico Industries : Access Denied'; - + + $this->global ['pageTitle'] = 'Resico : Access Denied'; $this->load->view ( 'includes/header', $this->global ); $this->load->view ( 'access' ); $this->load->view ( 'includes/footer' ); @@ -119,8 +122,7 @@ class BaseController extends CI_Controller { * This function used provide the pagination resources * @param {string} $link : This is page link * @param {number} $count : This is page count - * @param {number} $perPage : This is - * records per page limit + * @param {number} $perPage : This is records per page limit * @return {mixed} $result : This is array of records and pagination data */ function paginationCompress($link, $count, $perPage = 10) { diff --git a/application/models/costcenter_model.php b/application/models/costcenter_model.php index 2fe7a263..4ac6e9f1 100644 --- a/application/models/costcenter_model.php +++ b/application/models/costcenter_model.php @@ -441,5 +441,33 @@ class costcenter_model extends CI_Model $this->db->update('T_CostCenter_Budget', $Budget); return TRUE; } + + function getDepartmentnotadded($Empid) + { + + $subQuery = 'select Dept.DEPCode,Dept.DepartmentName from T_DepartmentDetails Dept + left join T_AccessDepartments Ass on Ass.Departmentcode= Dept.DEPCode + where Dept.DEPCode not in + (select Ass.Departmentcode from T_AccessDepartments Ass where EmpID=?) group by Dept.DEPCode'; + + $query = $this->db->query($subQuery, array($Empid)); + + + return $query->result(); + } + + function getaccessDept($Empid) + { + + $this->db->select('Ass.Departmentcode as AssDep,Dep.DepartmentName'); + $this->db->from('T_AccessDepartments Ass'); + $this->db->join('T_DepartmentDetails Dep', 'Dep.DEPCode = Ass.Departmentcode','left'); + $this->db->where('EmpID ',$Empid); + + $query = $this->db->get(); + + return $query->result(); + } + } ?> \ No newline at end of file diff --git a/application/models/login_model.php b/application/models/login_model.php index 1f5262c9..71b02fa9 100644 --- a/application/models/login_model.php +++ b/application/models/login_model.php @@ -110,6 +110,19 @@ class Login_model extends CI_Model return false; } } + + function Accessdep($EmpID) + { + + $this->db->select('Departmentcode as AssDep'); + $this->db->from('T_AccessDepartments'); + $this->db->where('EmpID', $EmpID); + + + $query = $this->db->get(); + // print_r( $this->db->last_query()); + return $query->result(); + } } ?> diff --git a/application/models/user_model.php b/application/models/user_model.php index 9d5f036d..edc1be28 100644 --- a/application/models/user_model.php +++ b/application/models/user_model.php @@ -82,7 +82,7 @@ class User_model extends CI_Model * @return number $insert_id : This is last inserted id */ function addNewUser($userInfo) - { + { $this->db->trans_start(); $this->db->insert('tbl_users', $userInfo); @@ -213,6 +213,27 @@ class User_model extends CI_Model return $query->result(); } + function addAccess($userdept) + { + $this->db->trans_start(); + $this->db->insert('T_AccessDepartments', $userdept); + + $insert_id = $this->db->affected_rows(); + + $this->db->trans_complete(); + + return $insert_id; + } + + + function DeleteAccess($empid,$Depcode) + { + $this->db->where("Departmentcode",$Depcode); + $this->db->where("EmpID",$empid); + $this->db->delete('T_AccessDepartments'); + + return TRUE; + } diff --git a/application/views/addNew.php b/application/views/addNew.php index 9cb9bb1a..acc0ee92 100644 --- a/application/views/addNew.php +++ b/application/views/addNew.php @@ -17,16 +17,14 @@