From e8e6054955303e2daf7733cf434b2fa7aa715d8f Mon Sep 17 00:00:00 2001 From: "venbatechnologies@gmail.com" Date: Tue, 31 Jul 2018 09:55:37 +0530 Subject: [PATCH] db chnages in visa_app --- application/config/autoload.php | 6 +- application/config/config.php | 2 +- application/config/database.php | 12 +- application/config/routes.php | 38 +- .../controllers/Dashboard_Controller.php | 197 +++++++++- application/controllers/Error.php | 46 +++ application/controllers/Login_Controller.php | 257 ++++++++++++ application/controllers/User_Controller.php | 369 ++++++++++++++++++ application/controllers/Welcome.php | 27 -- application/helpers/cias_helper.php | 152 ++++++++ application/libraries/BaseController.php | 133 ++++++- application/models/Dashboard_Model.php | 69 ++++ application/models/Home_Model.php | 20 - application/models/Login_Model.php | 137 +++++++ application/models/Login_model.php | 124 ------ application/models/NewModel.php | 25 -- application/models/User_Model.php | 268 +++++++++++++ application/models/user_model.php | 315 --------------- application/views/404.php | 45 ++- application/views/500.php | 47 +++ application/views/UsersListing.php | 87 +++++ application/views/access.php | 44 ++- application/views/addUser.php | 125 ++++++ application/views/changePassword.php | 250 ++++++++++++ application/views/city_master.php | 8 +- application/views/country_master.php | 10 +- application/views/document_upload.php | 31 +- application/views/editUser.php | 149 +++++++ application/views/includes/Header.php | 10 +- application/views/lockscreen.php | 77 ++++ application/views/login.php | 51 ++- application/views/loginHistory.php | 89 +++++ application/views/visa_type_master.php | 8 +- 33 files changed, 2629 insertions(+), 599 deletions(-) create mode 100644 application/controllers/Error.php create mode 100644 application/controllers/Login_Controller.php create mode 100644 application/controllers/User_Controller.php delete mode 100755 application/controllers/Welcome.php create mode 100644 application/helpers/cias_helper.php mode change 100755 => 100644 application/libraries/BaseController.php create mode 100644 application/models/Dashboard_Model.php delete mode 100755 application/models/Home_Model.php create mode 100644 application/models/Login_Model.php delete mode 100755 application/models/Login_model.php delete mode 100755 application/models/NewModel.php create mode 100644 application/models/User_Model.php delete mode 100755 application/models/user_model.php create mode 100755 application/views/500.php create mode 100644 application/views/UsersListing.php create mode 100644 application/views/addUser.php create mode 100644 application/views/changePassword.php create mode 100644 application/views/editUser.php create mode 100755 application/views/lockscreen.php mode change 100755 => 100644 application/views/login.php create mode 100644 application/views/loginHistory.php diff --git a/application/config/autoload.php b/application/config/autoload.php index 9631443..ee23a0a 100755 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -58,8 +58,8 @@ $autoload['packages'] = array(); | | $autoload['libraries'] = array('user_agent' => 'ua'); */ -$autoload['libraries'] = array(); -//$autoload['libraries'] = array('database', 'session','BaseController'); +//$autoload['libraries'] = array(); +$autoload['libraries'] = array('database', 'session'); /* | ------------------------------------------------------------------- @@ -90,7 +90,7 @@ $autoload['drivers'] = array(); | | $autoload['helper'] = array('url', 'file'); */ -$autoload['helper'] = array('url'); +$autoload['helper'] = array('url', 'file','cias_helper'); /* | ------------------------------------------------------------------- diff --git a/application/config/config.php b/application/config/config.php index 7e840eb..3ec793c 100755 --- a/application/config/config.php +++ b/application/config/config.php @@ -39,7 +39,7 @@ $config['base_url'] = $base; | variable so that it is blank. | */ -$config['index_page'] = 'index.php'; +$config['index_page'] = ''; /* |-------------------------------------------------------------------------- diff --git a/application/config/database.php b/application/config/database.php index a46f9f1..346da4f 100755 --- a/application/config/database.php +++ b/application/config/database.php @@ -74,14 +74,10 @@ $active_group = 'default'; $query_builder = TRUE; -// $hostname ="localhost"; -// $username ="root"; -// $password =""; -// $database ="mydb"; -$hostname = 'sidharthindustries.com'; -$username = 'kasiram9_Siddh'; -$password = 'sidh@1234'; -$database = 'kasiram9_SIADEV'; +$hostname ="localhost"; +$username ="root"; +$password =""; +$database ="Visa_DB"; $db['default'] = array( 'dsn' => '', diff --git a/application/config/routes.php b/application/config/routes.php index 273e41f..8319813 100755 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -49,16 +49,48 @@ defined('BASEPATH') OR exit('No direct script access allowed'); | Examples: my-controller/index -> my_controller/index | my-controller/my-method -> my_controller/my_method */ -$route['default_controller'] = 'Dashboard_Controller'; -//$route['default_controller'] = 'Login'; + +$route['default_controller'] = 'Login_Controller'; + $route['404_override'] = ''; $route['translate_uri_dashes'] = FALSE; $route['Routes'] = 'Dashboard_Controller/index'; $route['Dashboard'] = 'Dashboard_Controller/Dashboard'; $route['country_master'] = 'Dashboard_Controller/country_master'; +$route['Add_country_master'] = 'Dashboard_Controller/Add_country_master'; + $route['city_master'] = 'Dashboard_Controller/city_master'; +$route['Add_city_master'] = 'Dashboard_Controller/Add_city_master'; + $route['visa_type_master'] = 'Dashboard_Controller/visa_type_master'; +$route['Add_visa_type_master'] = 'Dashboard_Controller/Add_visa_type_master'; + $route['document_master'] = 'Dashboard_Controller/document_master'; +$route['Add_document_master'] = 'Dashboard_Controller/Add_document_master'; + $route['visa_type_master'] = 'Dashboard_Controller/visa_type_master'; -$route['country_visa_details'] = 'Dashboard_Controller/country_visa_details'; \ No newline at end of file +$route['country_visa_details'] = 'Dashboard_Controller/country_visa_details'; + + +$route['loginMe'] = 'Login_Controller/loginMe'; +$route['forgotPassword'] = "Login_Controller/forgotPassword"; +$route['resetPasswordUser'] = "Login_Controller/resetPasswordUser"; +$route['resetPasswordConfirmUser'] = "Login_Controller/resetPasswordConfirmUser"; +$route['createPasswordUser'] = "Login_Controller/createPasswordUser"; + + +$route['logout'] = 'User_Controller/logout'; +$route['userListing'] = 'User_Controller/userListing'; +$route['addNew'] = "User_Controller/addNew"; +$route['addNewUser'] = "User_Controller/addNewUser"; +$route['editOld'] = "User_Controller/editOld"; +$route['editUser'] = "User_Controller/editUser"; +$route['deleteUser'] = "User_Controller/deleteUser"; +$route['loadChangePass'] = "User_Controller/loadChangePass"; +$route['changePassword'] = "User_Controller/changePassword"; +$route['checkEmailExists'] = "User_Controller/checkEmailExists"; +$route['login-history'] = "User_Controller/loginHistoy"; + +/* End of file routes.php */ +/* Location: ./application/config/routes.php */ \ No newline at end of file diff --git a/application/controllers/Dashboard_Controller.php b/application/controllers/Dashboard_Controller.php index 4cece60..3e205fc 100755 --- a/application/controllers/Dashboard_Controller.php +++ b/application/controllers/Dashboard_Controller.php @@ -14,6 +14,7 @@ class Dashboard_Controller extends BaseController */ public function __construct(){ parent::__construct(); + $this->load->model('Dashboard_Model'); } /** @@ -21,9 +22,7 @@ class Dashboard_Controller extends BaseController */ public function index() { - - - $this->loadViews('Dashboard', NULL); + $this->Dashboard(); } /** @@ -31,26 +30,186 @@ class Dashboard_Controller extends BaseController */ function Dashboard() { - - $this->loadViews('Dashboard', NULL); + $this->global['pageTitle'] = 'Visa : Dashboard'; + $this->loadViews('Dashboard', $this->global,NULL , NULL); } + /** + * This function used to load the Country Master page + */ function country_master(){ - $this->loadViews('country_master',NULL); - } - function city_master(){ - $this->loadViews('city_master',NULL); - } - function visa_type_master(){ - $this->loadViews('visa_type_master',NULL); - } - function document_master(){ - $this->loadViews('document_upload',NULL); - } - function country_visa_details(){ - $this->loadViews('country_visa_details',NULL); + $this->global['pageTitle'] = 'Visa : Country Master'; + $this->loadViews('country_master', $this->global,NULL , NULL); } + /** + * To Store Country Master Values + */ + function Add_country_master(){ + + + $CountryMasterDatas = + array( 'CountryName'=>$this->input->post('CountryName'), + 'CapitalCity'=>$this->input->post('CapitalCity'), + 'CountryDescription'=>$this->input->post('Editor')); + + $Added = $this->Dashboard_Model->Add_CountryMaster($CountryMasterDatas); + + + if( $Added >= 1 ){ + echo ""; + redirect ( 'country_master' ); + } + else + { + echo ""; + redirect ( 'country_master' ); + } + } -?> +/** + * This function used to load the City Master page + */ + function city_master(){ + $this->global['pageTitle'] = 'Visa : Country Master'; + $this->loadViews('city_master', $this->global,NULL , NULL); + } + + /** + * To Store City Master Values + */ + function Add_city_master(){ + + $CityMasterDatas = + array( 'CityName'=>$this->input->post('CityName'), + 'CityDescription'=>$this->input->post('CitiesDescription')); + + $Added = $this->Dashboard_Model->Add_CityMaster($CityMasterDatas); + + + if( $Added >= 1 ){ + echo ""; + redirect ( 'city_master' ); + } + else + { + echo ""; + redirect ( 'city_master' ); + } + + } + + /** + * This function used to load the Visa Type Master page + */ + function visa_type_master(){ + $this->global['pageTitle'] = 'Visa : Visa Type Master'; + $this->loadViews('visa_type_master', $this->global,NULL , NULL); + } + + /** + * To Store Visa Type Master Values + */ + function Add_visa_type_master(){ + + $VisaTypeMasterDatas = + array( 'VisaName'=>$this->input->post('VisaName'), + 'VisaDescription'=>$this->input->post('VisaDescription')); + + $Added = $this->Dashboard_Model->Add_VisaType($VisaTypeMasterDatas); + + + if( $Added >= 1 ){ + echo ""; + redirect ( 'visa_type_master' ); + } + else + { + echo ""; + redirect ( 'visa_type_master' ); + } + + } + + + /** + * This function used to load the Document page + */ + function document_master(){ + $this->global['pageTitle'] = 'Visa : Upload Document'; + $this->loadViews('document_upload', $this->global,NULL , NULL); + } + + /** + * To Store Visa's File & Documents Datas + */ + function Add_document_master(){ + + $DocumentMasterDatas = + array( 'DocumentName'=>$this->input->post('DocumentName'), + 'Document'=>$this->uploadFile(), + 'DocumentDescription'=>$this->input->post('Description')); + + $Added = $this->Dashboard_Model->Add_Document($DocumentMasterDatas); + + + if( $Added >= 1 ){ + echo ""; + + } + else + { + echo ""; + + } + + } + + /** + * To add employee revalant images(for profile pictures) + */ + /** + * To upload IGR files + */ + function uploadFile() + { + $config['upload_path'] = 'Uploads'; + $config['allowed_types'] = 'png|jpg|jpeg|pdf|docx'; + $config['file_name'] = $_FILES['DocumentFile']['name']; + + //Load upload library and initialize configuration + $this->load->library('upload',$config); + $this->upload->initialize($config); + + + if($this->upload->do_upload('DocumentFile')) + { + $uploadData = $this->upload->data(); + $uploadfilename = $uploadData['file_name']; + return $uploadfilename; + } + else + { + $error = array('error' => $this->upload->display_errors()); + $uploadfilename = ''; + return 0; + } + + + } + + + /** + * This function used to load the Dashboard page + */ + function country_visa_details(){ + $this->global['pageTitle'] = 'Visa : CountryWise Visa Details'; + $data['records'] = $this->Dashboard_Model->Get_CountryMaster(); + $this->loadViews('country_visa_details',$this->global,$data, NULL); + } + + +} + +?> \ No newline at end of file diff --git a/application/controllers/Error.php b/application/controllers/Error.php new file mode 100644 index 0000000..4cfb8fe --- /dev/null +++ b/application/controllers/Error.php @@ -0,0 +1,46 @@ +isLoggedIn(); + } + + /** + * This function used to check the user is logged in or not + */ + function isLoggedIn() + { + $isLoggedIn = $this->session->userdata('isLoggedIn'); + + if(!isset($isLoggedIn) || $isLoggedIn != TRUE) + { + $this->load->view('login'); + } + else + { + redirect('pageNotFound'); + } + } +} + +?> \ No newline at end of file diff --git a/application/controllers/Login_Controller.php b/application/controllers/Login_Controller.php new file mode 100644 index 0000000..fb5c047 --- /dev/null +++ b/application/controllers/Login_Controller.php @@ -0,0 +1,257 @@ +load->model('Login_Model'); + } + + /** + * Index Page for this controller. + */ + public function index() + { + $this->isLoggedIn(); + } + + /** + * This function used to check the user is logged in or not + */ + function isLoggedIn() + { + $isLoggedIn = $this->session->userdata('isLoggedIn'); + + if(!isset($isLoggedIn) || $isLoggedIn != TRUE) + { + $this->load->view('login'); + } + else + { + redirect('/Dashboard'); + } + } + + + /** + * This function used to logged in user + */ + public function loginMe() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules('email', 'Email', 'required|valid_email|max_length[128]|trim'); + $this->form_validation->set_rules('password', 'Password', 'required|max_length[32]'); + + if($this->form_validation->run() == FALSE) + { + $this->index(); + } + else + { + $email = $this->security->xss_clean($this->input->post('email')); + $password = $this->input->post('password'); + + $result = $this->Login_Model->loginMe($email, $password); + + if(!empty($result)) + { + $lastLogin = $this->Login_Model->lastLoginInfo($result->userId); + + $sessionArray = array('userId'=>$result->userId, + 'role'=>$result->roleId, + 'roleText'=>$result->role, + 'name'=>$result->name, + 'lastLogin'=> $lastLogin->createdDtm, + 'isLoggedIn' => TRUE + ); + + $this->session->set_userdata($sessionArray); + + unset($sessionArray['userId'], $sessionArray['isLoggedIn'], $sessionArray['lastLogin']); + + $loginInfo = array("userId"=>$result->userId, "sessionData" => json_encode($sessionArray), "machineIp"=>$_SERVER['REMOTE_ADDR'], "userAgent"=>getBrowserAgent(), "agentString"=>$this->agent->agent_string(), "platform"=>$this->agent->platform()); + + $this->Login_Model->lastLogin($loginInfo); + + redirect('/Dashboard'); + } + else + { + $this->session->set_flashdata('error', 'Email or password mismatch'); + + redirect('/login'); + } + } + } + + /** + * This function used to load forgot password view + */ + // public function forgotPassword() + // { + // $isLoggedIn = $this->session->userdata('isLoggedIn'); + + // if(!isset($isLoggedIn) || $isLoggedIn != TRUE) + // { + // $this->load->view('forgotPassword'); + // } + // else + // { + // redirect('/Dashboard'); + // } + // } + + /** + * This function used to generate reset password request link + */ + function resetPasswordUser() + { + $status = ''; + + $this->load->library('form_validation'); + + $this->form_validation->set_rules('login_email','Email','trim|required|valid_email'); + + if($this->form_validation->run() == FALSE) + { + $this->forgotPassword(); + } + else + { + $email = $this->security->xss_clean($this->input->post('login_email')); + + if($this->Login_Model->checkEmailExist($email)) + { + $encoded_email = urlencode($email); + + $this->load->helper('string'); + $data['email'] = $email; + $data['activation_id'] = random_string('alnum',15); + $data['createdDtm'] = date('Y-m-d H:i:s'); + $data['agent'] = getBrowserAgent(); + $data['client_ip'] = $this->input->ip_address(); + + $save = $this->Login_Model->resetPasswordUser($data); + + if($save) + { + $data1['reset_link'] = base_url() . "resetPasswordConfirmUser/" . $data['activation_id'] . "/" . $encoded_email; + $userInfo = $this->Login_Model->getCustomerInfoByEmail($email); + + if(!empty($userInfo)){ + $data1["name"] = $userInfo[0]->name; + $data1["email"] = $userInfo[0]->email; + $data1["message"] = "Reset Your Password"; + } + + $sendStatus = resetPasswordEmail($data1); + + if($sendStatus){ + $status = "send"; + setFlashData($status, "Reset password link sent successfully, please check mails."); + } else { + $status = "notsend"; + setFlashData($status, "Email has been failed, try again."); + } + } + else + { + $status = 'unable'; + setFlashData($status, "It seems an error while sending your details, try again."); + } + } + else + { + $status = 'invalid'; + setFlashData($status, "This email is not registered with us."); + } + redirect('/forgotPassword'); + } + } + + /** + * This function used to reset the password + * @param string $activation_id : This is unique id + * @param string $email : This is user email + */ + function resetPasswordConfirmUser($activation_id, $email) + { + // Get email and activation code from URL values at index 3-4 + $email = urldecode($email); + + // Check activation id in database + $is_correct = $this->Login_Model->checkActivationDetails($email, $activation_id); + + $data['email'] = $email; + $data['activation_code'] = $activation_id; + + if ($is_correct == 1) + { + $this->load->view('newPassword', $data); + } + else + { + redirect('/login'); + } + } + + /** + * This function used to create new password for user + */ + function createPasswordUser() + { + $status = ''; + $message = ''; + $email = $this->input->post("email"); + $activation_id = $this->input->post("activation_code"); + + $this->load->library('form_validation'); + + $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->resetPasswordConfirmUser($activation_id, urlencode($email)); + } + else + { + $password = $this->input->post('password'); + $cpassword = $this->input->post('cpassword'); + + // Check activation id in database + $is_correct = $this->Login_Model->checkActivationDetails($email, $activation_id); + + if($is_correct == 1) + { + $this->Login_Model->createPasswordUser($email, $password); + + $status = 'success'; + $message = 'Password changed successfully'; + } + else + { + $status = 'error'; + $message = 'Password changed failed'; + } + + setFlashData($status, $message); + + redirect("/login"); + } + } +} + +?> \ No newline at end of file diff --git a/application/controllers/User_Controller.php b/application/controllers/User_Controller.php new file mode 100644 index 0000000..f789164 --- /dev/null +++ b/application/controllers/User_Controller.php @@ -0,0 +1,369 @@ +load->model('User_Model'); + $this->isLoggedIn(); + } + + /** + * This function used to load the first screen of the user + */ + public function index() + { + $this->global['pageTitle'] = 'CodeInsect : Dashboard'; + + $this->loadViews("dashboard", $this->global, NULL , NULL); + } + + /** + * This function is used to load the user list + */ + function userListing() + { + if($this->isAdmin() == TRUE) + { + $this->loadThis(); + } + else + { + $searchText = $this->security->xss_clean($this->input->post('searchText')); + $data['searchText'] = $searchText; + + $this->load->library('pagination'); + + $count = $this->User_Model->userListingCount($searchText); + + $returns = $this->paginationCompress ( "userListing/", $count, 10 ); + + $data['userRecords'] = $this->User_Model->userListing($searchText, $returns["page"], $returns["segment"]); + + $this->global['pageTitle'] = 'CodeInsect : User Listing'; + + $this->loadViews("users", $this->global, $data, NULL); + } + } + + /** + * This function is used to load the add new form + */ + function addNew() + { + if($this->isAdmin() == TRUE) + { + $this->loadThis(); + } + else + { + $this->load->model('User_Model'); + $data['roles'] = $this->User_Model->getUserRoles(); + + $this->global['pageTitle'] = 'CodeInsect : Add New User'; + + $this->loadViews("addNew", $this->global, $data, NULL); + } + } + + /** + * This function is used to check whether email already exist or not + */ + function checkEmailExists() + { + $userId = $this->input->post("userId"); + $email = $this->input->post("email"); + + if(empty($userId)){ + $result = $this->User_Model->checkEmailExists($email); + } else { + $result = $this->User_Model->checkEmailExists($email, $userId); + } + + if(empty($result)){ echo("true"); } + else { echo("false"); } + } + + /** + * This function is used to add new user to the system + */ + function addNewUser() + { + if($this->isAdmin() == TRUE) + { + $this->loadThis(); + } + else + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules('fname','Full Name','trim|required|max_length[128]'); + $this->form_validation->set_rules('email','Email','trim|required|valid_email|max_length[128]'); + $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]'); + + if($this->form_validation->run() == FALSE) + { + $this->addNew(); + } + else + { + $name = ucwords(strtolower($this->security->xss_clean($this->input->post('fname')))); + $email = $this->security->xss_clean($this->input->post('email')); + $password = $this->input->post('password'); + $roleId = $this->input->post('role'); + $mobile = $this->security->xss_clean($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:s')); + + $this->load->model('User_Model'); + $result = $this->User_Model->addNewUser($userInfo); + + if($result > 0) + { + $this->session->set_flashdata('success', 'New User created successfully'); + } + else + { + $this->session->set_flashdata('error', 'User creation failed'); + } + + redirect('addNew'); + } + } + } + + + /** + * This function is used load user edit information + * @param number $userId : Optional : This is user id + */ + function editOld($userId = NULL) + { + if($this->isAdmin() == TRUE || $userId == 1) + { + $this->loadThis(); + } + else + { + if($userId == null) + { + redirect('userListing'); + } + + $data['roles'] = $this->User_Model->getUserRoles(); + $data['userInfo'] = $this->User_Model->getUserInfo($userId); + + $this->global['pageTitle'] = 'CodeInsect : 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 + { + $this->load->library('form_validation'); + + $userId = $this->input->post('userId'); + + $this->form_validation->set_rules('fname','Full Name','trim|required|max_length[128]'); + $this->form_validation->set_rules('email','Email','trim|required|valid_email|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]'); + + if($this->form_validation->run() == FALSE) + { + $this->editOld($userId); + } + else + { + $name = ucwords(strtolower($this->security->xss_clean($this->input->post('fname')))); + $email = $this->security->xss_clean($this->input->post('email')); + $password = $this->input->post('password'); + $roleId = $this->input->post('role'); + $mobile = $this->security->xss_clean($this->input->post('mobile')); + + $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:s')); + } + 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:s')); + } + + $result = $this->User_Model->editUser($userInfo, $userId); + + if($result == true) + { + $this->session->set_flashdata('success', 'User updated successfully'); + } + else + { + $this->session->set_flashdata('error', 'User updation failed'); + } + + redirect('userListing'); + } + } + } + + + /** + * This function is used to delete the user using userId + * @return boolean $result : TRUE / FALSE + */ + 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:s')); + + $result = $this->User_Model->deleteUser($userId, $userInfo); + + if ($result > 0) { echo(json_encode(array('status'=>TRUE))); } + else { echo(json_encode(array('status'=>FALSE))); } + } + } + + /** + * This function is used to load the change password screen + */ + function loadChangePass() + { + $this->global['pageTitle'] = 'CodeInsect : Change Password'; + + $this->loadViews("changePassword", $this->global, NULL, NULL); + } + + + /** + * This function is used to change the password of the user + */ + function changePassword() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules('oldPassword','Old password','required|max_length[20]'); + $this->form_validation->set_rules('newPassword','New password','required|max_length[20]'); + $this->form_validation->set_rules('cNewPassword','Confirm new password','required|matches[newPassword]|max_length[20]'); + + if($this->form_validation->run() == FALSE) + { + $this->loadChangePass(); + } + else + { + $oldPassword = $this->input->post('oldPassword'); + $newPassword = $this->input->post('newPassword'); + + $resultPas = $this->User_Model->matchOldPassword($this->vendorId, $oldPassword); + + if(empty($resultPas)) + { + $this->session->set_flashdata('nomatch', 'Your old password not correct'); + redirect('loadChangePass'); + } + else + { + $usersData = array('password'=>getHashedPassword($newPassword), 'updatedBy'=>$this->vendorId, + 'updatedDtm'=>date('Y-m-d H:i:s')); + + $result = $this->User_Model->changePassword($this->vendorId, $usersData); + + if($result > 0) { $this->session->set_flashdata('success', 'Password updation successful'); } + else { $this->session->set_flashdata('error', 'Password updation failed'); } + + redirect('loadChangePass'); + } + } + } + + /** + * Page not found : error 404 + */ + function pageNotFound() + { + $this->global['pageTitle'] = 'CodeInsect : 404 - Page Not Found'; + + $this->loadViews("404", $this->global, NULL, NULL); + } + + /** + * This function used to show login history + * @param number $userId : This is user id + */ + function loginHistoy($userId = NULL) + { + if($this->isAdmin() == TRUE) + { + $this->loadThis(); + } + else + { + $userId = ($userId == NULL ? $this->session->userdata("userId") : $userId); + + $searchText = $this->input->post('searchText'); + $fromDate = $this->input->post('fromDate'); + $toDate = $this->input->post('toDate'); + + $data["userInfo"] = $this->User_Model->getUserInfoById($userId); + + $data['searchText'] = $searchText; + $data['fromDate'] = $fromDate; + $data['toDate'] = $toDate; + + $this->load->library('pagination'); + + $count = $this->User_Model->loginHistoryCount($userId, $searchText, $fromDate, $toDate); + + $returns = $this->paginationCompress ( "login-history/".$userId."/", $count, 5, 3); + + $data['userRecords'] = $this->User_Model->loginHistory($userId, $searchText, $fromDate, $toDate, $returns["page"], $returns["segment"]); + + $this->global['pageTitle'] = 'CodeInsect : User Login History'; + + $this->loadViews("loginHistory", $this->global, $data, NULL); + } + } +} + +?> \ No newline at end of file diff --git a/application/controllers/Welcome.php b/application/controllers/Welcome.php deleted file mode 100755 index 1f2ec89..0000000 --- a/application/controllers/Welcome.php +++ /dev/null @@ -1,27 +0,0 @@ - - * @see https://codeigniter.com/user_guide/general/urls.html - */ - public function index() - { - $this->load->view('includes/Header', NULL); - $this->load->view('welcome_message', NULL); - $this->load->view('includes/Footer', NULL); - } -} diff --git a/application/helpers/cias_helper.php b/application/helpers/cias_helper.php new file mode 100644 index 0000000..6af44aa --- /dev/null +++ b/application/helpers/cias_helper.php @@ -0,0 +1,152 @@ +"; + print_r($data); + echo ""; +} + +/** + * This function used to get the CI instance + */ +if(!function_exists('get_instance')) +{ + function get_instance() + { + $CI = &get_instance(); + } +} + +/** + * This function used to generate the hashed password + * @param {string} $plainPassword : This is plain text password + */ +if(!function_exists('getHashedPassword')) +{ + function getHashedPassword($plainPassword) + { + return password_hash($plainPassword, PASSWORD_DEFAULT); + } +} + +/** + * This function used to generate the hashed password + * @param {string} $plainPassword : This is plain text password + * @param {string} $hashedPassword : This is hashed password + */ +if(!function_exists('verifyHashedPassword')) +{ + function verifyHashedPassword($plainPassword, $hashedPassword) + { + return password_verify($plainPassword, $hashedPassword) ? true : false; + } +} + +/** + * This method used to get current browser agent + */ +if(!function_exists('getBrowserAgent')) +{ + function getBrowserAgent() + { + $CI = get_instance(); + $CI->load->library('user_agent'); + + $agent = ''; + + if ($CI->agent->is_browser()) + { + $agent = $CI->agent->browser().' '.$CI->agent->version(); + } + else if ($CI->agent->is_robot()) + { + $agent = $CI->agent->robot(); + } + else if ($CI->agent->is_mobile()) + { + $agent = $CI->agent->mobile(); + } + else + { + $agent = 'Unidentified User Agent'; + } + + return $agent; + } +} + +if(!function_exists('setProtocol')) +{ + function setProtocol() + { + $CI = &get_instance(); + + $CI->load->library('email'); + + $config['protocol'] = PROTOCOL; + $config['mailpath'] = MAIL_PATH; + $config['smtp_host'] = SMTP_HOST; + $config['smtp_port'] = SMTP_PORT; + $config['smtp_user'] = SMTP_USER; + $config['smtp_pass'] = SMTP_PASS; + $config['charset'] = "utf-8"; + $config['mailtype'] = "html"; + $config['newline'] = "\r\n"; + + $CI->email->initialize($config); + + return $CI; + } +} + +if(!function_exists('emailConfig')) +{ + function emailConfig() + { + $CI->load->library('email'); + $config['protocol'] = PROTOCOL; + $config['smtp_host'] = SMTP_HOST; + $config['smtp_port'] = SMTP_PORT; + $config['mailpath'] = MAIL_PATH; + $config['charset'] = 'UTF-8'; + $config['mailtype'] = "html"; + $config['newline'] = "\r\n"; + $config['wordwrap'] = TRUE; + } +} + +if(!function_exists('resetPasswordEmail')) +{ + function resetPasswordEmail($detail) + { + $data["data"] = $detail; + // pre($detail); + // die; + + $CI = setProtocol(); + + $CI->email->from(EMAIL_FROM, FROM_NAME); + $CI->email->subject("Reset Password"); + $CI->email->message($CI->load->view('email/resetPassword', $data, TRUE)); + $CI->email->to($detail["email"]); + $status = $CI->email->send(); + + return $status; + } +} + +if(!function_exists('setFlashData')) +{ + function setFlashData($status, $flashMsg) + { + $CI = get_instance(); + $CI->session->set_flashdata($status, $flashMsg); + } +} + +?> \ No newline at end of file diff --git a/application/libraries/BaseController.php b/application/libraries/BaseController.php old mode 100755 new mode 100644 index dbd0bb9..898d765 --- a/application/libraries/BaseController.php +++ b/application/libraries/BaseController.php @@ -3,11 +3,92 @@ /** * Class : BaseController * Base Class to control over all the classes - * @author : Kishor Mali + * @author : Suren * @version : 1.1 - * @since : 15 November 2016 + * @since : 27 July 2018 */ class BaseController extends CI_Controller { + protected $role = ''; + protected $vendorId = ''; + protected $name = ''; + protected $roleText = ''; + protected $global = array (); + protected $lastLogin = ''; + + /** + * Takes mixed data and optionally a status code, then creates the response + * + * @access public + * @param array|NULL $data + * Data to output to the user + * running the script; otherwise, exit + */ + public function response($data = NULL) { + $this->output->set_status_header ( 200 )->set_content_type ( 'application/json', 'utf-8' )->set_output ( json_encode ( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ) )->_display (); + exit (); + } + + /** + * This function used to check the user is logged in or not + */ + function isLoggedIn() { + $isLoggedIn = $this->session->userdata ( 'isLoggedIn' ); + + if (! isset ( $isLoggedIn ) || $isLoggedIn != TRUE) { + redirect ( 'Login_Controller' ); + } else { + $this->role = $this->session->userdata ( 'role' ); + $this->vendorId = $this->session->userdata ( 'userId' ); + $this->name = $this->session->userdata ( 'name' ); + $this->roleText = $this->session->userdata ( 'roleText' ); + $this->lastLogin = $this->session->userdata ( 'lastLogin' ); + + $this->global ['name'] = $this->name; + $this->global ['role'] = $this->role; + $this->global ['role_text'] = $this->roleText; + $this->global ['last_login'] = $this->lastLogin; + } + } + + /** + * This function is used to check the access + */ + // function isAdmin() { + // if ($this->role != ROLE_ADMIN) { + // return true; + // } else { + // return false; + // } + // } + + /** + * This function is used to check the access + */ + // function isTicketter() { + // if ($this->role != ROLE_ADMIN || $this->role != ROLE_MANAGER) { + // return true; + // } else { + // return false; + // } + // } + + /** + * This function is used to load the set of views + */ + function loadThis() { + $this->global ['pageTitle'] = 'Visa : Access Denied'; + $this->load->view ( 'includes/Header', $this->global ); + $this->load->view ( 'access' ); + $this->load->view ( 'includes/Footer' ); + } + + /** + * This function is used to logged out user from system + */ + function logout() { + $this->session->sess_destroy (); + redirect ( 'Login_Controller' ); + } /** * This function used to load views @@ -18,9 +99,53 @@ class BaseController extends CI_Controller { * @return {null} $result : null */ function loadViews($viewName = "", $headerInfo = NULL, $pageInfo = NULL, $footerInfo = NULL){ - + $this->load->view('includes/Header', $headerInfo); $this->load->view($viewName, $pageInfo); $this->load->view('includes/Footer', $footerInfo); } -} + + /** + * 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 + * @return {mixed} $result : This is array of records and pagination data + */ + function paginationCompress($link, $count, $perPage = 10, $segment = SEGMENT) { + $this->load->library ( 'pagination' ); + + $config ['base_url'] = base_url () . $link; + $config ['total_rows'] = $count; + $config ['uri_segment'] = $segment; + $config ['per_page'] = $perPage; + $config ['num_links'] = 5; + $config ['full_tag_open'] = ''; + $config ['first_tag_open'] = '
  • '; + $config ['first_link'] = 'First'; + $config ['first_tag_close'] = '
  • '; + $config ['prev_link'] = 'Previous'; + $config ['prev_tag_open'] = '
  • '; + $config ['prev_tag_close'] = '
  • '; + $config ['next_link'] = 'Next'; + $config ['next_tag_open'] = '
  • '; + $config ['next_tag_close'] = '
  • '; + $config ['cur_tag_open'] = '
  • '; + $config ['cur_tag_close'] = '
  • '; + $config ['num_tag_open'] = '
  • '; + $config ['num_tag_close'] = '
  • '; + $config ['last_tag_open'] = '
  • '; + $config ['last_link'] = 'Last'; + $config ['last_tag_close'] = '
  • '; + + $this->pagination->initialize ( $config ); + $page = $config ['per_page']; + $segment = $this->uri->segment ( $segment ); + + return array ( + "page" => $page, + "segment" => $segment + ); + } +} \ No newline at end of file diff --git a/application/models/Dashboard_Model.php b/application/models/Dashboard_Model.php new file mode 100644 index 0000000..69adc5d --- /dev/null +++ b/application/models/Dashboard_Model.php @@ -0,0 +1,69 @@ +db->insert('Tab_CountryMaster',$CountryMasterDatas); + $CountryMaster = $this->db->affected_rows(); + + return $CountryMaster; + } + + /** + * To store City Related details into 'Tab_CityMaster' table + * @param array $CityMasterDatas : Its have all the City master datas + * @return $CityMaster : This will return how many value are inserted (return as count) + */ + function Add_CityMaster($CityMasterDatas) + { + + $this->db->insert('Tab_CityMaster',$CityMasterDatas); + $CityMaster = $this->db->affected_rows(); + + return $CityMaster; + } + + + /** + * To store VisaType Related details into 'Tab_VisaTypeMaster' table + * @param array $VisaTypeMasterDatas : Its have all the City master datas + * @return $CityMaster : This will return how many value are inserted (return as count) + */ + function Add_VisaType($VisaTypeMasterDatas) + { + $this->db->insert('Tab_VisaTypeMaster',$VisaTypeMasterDatas); + $VisaTypeMaster = $this->db->affected_rows(); + + return $VisaTypeMaster; + } + + /** + * To store Document Related details into 'Tab_Documents' table + * @param array $DocumentMasterDatas : Its have all the document master datas + * @return $Documents : This will return how many value are inserted (return as count) + */ + function Add_Document($DocumentMasterDatas) + { + $this->db->insert('Tab_Documents',$DocumentMasterDatas); + $Documents = $this->db->affected_rows(); + + return $Documents; + } + + function Get_CountryMaster() + { + $this->db->select('*'); + $this->db->from('Tab_CountryMaster'); + $query = $this->db->get(); + $CountryMasterDatas = $query->result(); + return $CountryMasterDatas; + } + +} \ No newline at end of file diff --git a/application/models/Home_Model.php b/application/models/Home_Model.php deleted file mode 100755 index d325b88..0000000 --- a/application/models/Home_Model.php +++ /dev/null @@ -1,20 +0,0 @@ -load->database(); - - } - - function NewListing() - { - $this->db->from('actor'); - $query = $this->db->get(); - $result = $query->result(); - return $result; - } - -} -?> \ No newline at end of file diff --git a/application/models/Login_Model.php b/application/models/Login_Model.php new file mode 100644 index 0000000..9024770 --- /dev/null +++ b/application/models/Login_Model.php @@ -0,0 +1,137 @@ +db->select('BaseTbl.userId, BaseTbl.password, BaseTbl.name, BaseTbl.roleId, Roles.role'); + $this->db->from('Tab_Users as BaseTbl'); + $this->db->join('Tab_Roles as Roles','Roles.roleId = BaseTbl.roleId'); + $this->db->where('BaseTbl.email', $email); + $this->db->where('BaseTbl.isDeleted', 0); + $query = $this->db->get(); + + $user = $query->row(); + + if(!empty($user)){ + if(verifyHashedPassword($password, $user->password)){ + return $user; + } else { + return array(); + } + } else { + return array(); + } + } + + /** + * This function used to check email exists or not + * @param {string} $email : This is users email id + * @return {boolean} $result : TRUE/FALSE + */ + function checkEmailExist($email) + { + $this->db->select('userId'); + $this->db->where('email', $email); + $this->db->where('isDeleted', 0); + $query = $this->db->get('Tab_Users'); + + if ($query->num_rows() > 0){ + return true; + } else { + return false; + } + } + + + /** + * This function used to insert reset password data + * @param {array} $data : This is reset password data + * @return {boolean} $result : TRUE/FALSE + */ + function resetPasswordUser($data) + { + $result = $this->db->insert('Tab_ResetPassword', $data); + + if($result) { + return TRUE; + } else { + return FALSE; + } + } + + /** + * This function is used to get customer information by email-id for forget password email + * @param string $email : Email id of customer + * @return object $result : Information of customer + */ + function getCustomerInfoByEmail($email) + { + $this->db->select('userId, email, name'); + $this->db->from('Tab_Users'); + $this->db->where('isDeleted', 0); + $this->db->where('email', $email); + $query = $this->db->get(); + + return $query->result(); + } + + /** + * This function used to check correct activation deatails for forget password. + * @param string $email : Email id of user + * @param string $activation_id : This is activation string + */ + function checkActivationDetails($email, $activation_id) + { + $this->db->select('id'); + $this->db->from('Tab_ResetPassword'); + $this->db->where('email', $email); + $this->db->where('activation_id', $activation_id); + $query = $this->db->get(); + return $query->num_rows(); + } + + // This function used to create new password by reset link + function createPasswordUser($email, $password) + { + $this->db->where('email', $email); + $this->db->where('isDeleted', 0); + $this->db->update('Tab_Users', array('password'=>getHashedPassword($password))); + $this->db->delete('Tab_ResetPassword', array('email'=>$email)); + } + + /** + * This function used to save login information of user + * @param array $loginInfo : This is users login information + */ + function lastLogin($loginInfo) + { + $this->db->trans_start(); + $this->db->insert('Tab_LastLogin', $loginInfo); + $this->db->trans_complete(); + } + + /** + * This function is used to get last login info by user id + * @param number $userId : This is user id + * @return number $result : This is query result + */ + function lastLoginInfo($userId) + { + $this->db->select('BaseTbl.createdDtm'); + $this->db->where('BaseTbl.userId', $userId); + $this->db->order_by('BaseTbl.id', 'DESC'); + $this->db->limit(1); + $query = $this->db->get('Tab_LastLogin as BaseTbl'); + + return $query->row(); + } +} + +?> \ No newline at end of file diff --git a/application/models/Login_model.php b/application/models/Login_model.php deleted file mode 100755 index 6778a2f..0000000 --- a/application/models/Login_model.php +++ /dev/null @@ -1,124 +0,0 @@ -db->select('BaseTbl.userId, BaseTbl.password, Emp.EmpID,Emp.FirstName,Emp.Designation, BaseTbl.roleId, Roles.role,DEPT.DEPCode,DEPT.DepartmentName,DEPT.HeadDept'); - $this->db->from('tbl_users as BaseTbl'); - $this->db->join('tbl_roles as Roles','Roles.roleId = BaseTbl.roleId'); - $this->db->join('T_Employee_Details as Emp','BaseTbl.EmpID = Emp.EmpID'); - $this->db->join('T_DepartmentDetails as DEPT','Emp.Departmentcode = DEPT.DEPCode'); - $this->db->where('BaseTbl.isDeleted !=',1); - $this->db->where('BaseTbl.email', $email); - $this->db->or_where('Emp.ContactNumber', $email); - $this->db->where('BaseTbl.isDeleted !=',1); - - $query = $this->db->get(); - - - $user = $query->result(); - print_r($user);die; - if(!empty($user)){ - if(verifyHashedPassword($password, $user[0]->password)){ - return $user; - } else { - return array(); - } - } else { - return array(); - } - } - - 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(); - } - /** - * get the user dtl - */ - function getuserid($mobileno,$emailid) - { - $this->db->select('UsrTbl.userId,UsrTbl.email,EmpTbl.ContactNumber,EmpTbl.FirstName'); - $this->db->from('tbl_users as UsrTbl'); - $this->db->join('T_Employee_Details as EmpTbl','UsrTbl.EmpID = EmpTbl.EmpID'); - $this->db->where('EmpTbl.ContactNumber', $mobileno); - $this->db->where('UsrTbl.email',$emailid); - $this->db->where('UsrTbl.isDeleted', 0); - $res = $this->db->get(); - return $res->result(); - - } - - /** - * To update opt in our database - **/ - function temp2($userId,$otp){ - $this->db->set('OTP',$otp); - $this->db->where('userId',$userId); - $this->db->update('tbl_users'); - $count = $this->db->affected_rows(); - - if($count > 0) - { - $subQuery = "select OTP from tbl_users where userId = '".$userId."'"; - $query = $this->db->query($subQuery); - return $query->result(); - } - } - - /** - * To get user id - **/ - function getuserdtl($phno){ - $this->db->select('BaseTbl.userId'); - $this->db->from('tbl_users as BaseTbl'); - $this->db->join('T_Employee_Details as Emp','BaseTbl.EmpID = Emp.EmpID'); - $this->db->where('Emp.ContactNumber', $phno); - $query = $this->db->get(); - $result = $query->result(); - return $result; - } - - /** - * To update password and otp - **/ - function resetpassword($Array,$userid){ - - $this->db->where('userId',$userid); - $this->db->update('tbl_users',$Array); - $count = $this->db->affected_rows(); - return $count; - - } - - /** - * To update password only - **/ - function updatepassword($userid,$password){ - - $this->db->set('password',$password); - $this->db->where('userId',$userid); - $this->db->update('tbl_users'); - $count = $this->db->affected_rows(); - return $count; - - } - -} - -?> diff --git a/application/models/NewModel.php b/application/models/NewModel.php deleted file mode 100755 index bacee09..0000000 --- a/application/models/NewModel.php +++ /dev/null @@ -1,25 +0,0 @@ -load->database(); - - } - - function NewListing() - { - $this->db->from('actor'); - $query = $this->db->get(); - $result = $query->result(); - return $result; - } - -} -?> \ No newline at end of file diff --git a/application/models/User_Model.php b/application/models/User_Model.php new file mode 100644 index 0000000..48f7f6d --- /dev/null +++ b/application/models/User_Model.php @@ -0,0 +1,268 @@ +db->select('BaseTbl.userId, BaseTbl.email, BaseTbl.name, BaseTbl.mobile, Role.role'); + $this->db->from('Tab_Users as BaseTbl'); + $this->db->join('Tab_Roles as Role', 'Role.roleId = BaseTbl.roleId','left'); + if(!empty($searchText)) { + $likeCriteria = "(BaseTbl.email LIKE '%".$searchText."%' + OR BaseTbl.name LIKE '%".$searchText."%' + OR BaseTbl.mobile LIKE '%".$searchText."%')"; + $this->db->where($likeCriteria); + } + $this->db->where('BaseTbl.isDeleted', 0); + $this->db->where('BaseTbl.roleId !=', 1); + $query = $this->db->get(); + + return $query->num_rows(); + } + + /** + * This function is used to get the user listing count + * @param string $searchText : This is optional search text + * @param number $page : This is pagination offset + * @param number $segment : This is pagination limit + * @return array $result : This is result + */ + function userListing($searchText = '', $page, $segment) + { + $this->db->select('BaseTbl.userId, BaseTbl.email, BaseTbl.name, BaseTbl.mobile, Role.role'); + $this->db->from('Tab_Users as BaseTbl'); + $this->db->join('Tab_Roles as Role', 'Role.roleId = BaseTbl.roleId','left'); + if(!empty($searchText)) { + $likeCriteria = "(BaseTbl.email LIKE '%".$searchText."%' + OR BaseTbl.name LIKE '%".$searchText."%' + OR BaseTbl.mobile LIKE '%".$searchText."%')"; + $this->db->where($likeCriteria); + } + $this->db->where('BaseTbl.isDeleted', 0); + $this->db->where('BaseTbl.roleId !=', 1); + $this->db->limit($page, $segment); + $query = $this->db->get(); + + $result = $query->result(); + return $result; + } + + /** + * This function is used to get the user roles information + * @return array $result : This is result of the query + */ + function getUserRoles() + { + $this->db->select('roleId, role'); + $this->db->from('Tab_Roles'); + $this->db->where('roleId !=', 1); + $query = $this->db->get(); + + return $query->result(); + } + + /** + * This function is used to check whether email id is already exist or not + * @param {string} $email : This is email id + * @param {number} $userId : This is user id + * @return {mixed} $result : This is searched result + */ + function checkEmailExists($email, $userId = 0) + { + $this->db->select("email"); + $this->db->from("Tab_Users"); + $this->db->where("email", $email); + $this->db->where("isDeleted", 0); + if($userId != 0){ + $this->db->where("userId !=", $userId); + } + $query = $this->db->get(); + + return $query->result(); + } + + + /** + * This function is used to add new user to system + * @return number $insert_id : This is last inserted id + */ + function addNewUser($userInfo) + { + $this->db->trans_start(); + $this->db->insert('Tab_Users', $userInfo); + + $insert_id = $this->db->insert_id(); + + $this->db->trans_complete(); + + return $insert_id; + } + + /** + * This function used to get user information by id + * @param number $userId : This is user id + * @return array $result : This is user information + */ + function getUserInfo($userId) + { + $this->db->select('userId, name, email, mobile, roleId'); + $this->db->from('Tab_Users'); + $this->db->where('isDeleted', 0); + $this->db->where('roleId !=', 1); + $this->db->where('userId', $userId); + $query = $this->db->get(); + + return $query->result(); + } + + + /** + * This function is used to update the user information + * @param array $userInfo : This is users updated information + * @param number $userId : This is user id + */ + function editUser($userInfo, $userId) + { + $this->db->where('userId', $userId); + $this->db->update('Tab_Users', $userInfo); + + return TRUE; + } + + + + /** + * This function is used to delete the user information + * @param number $userId : This is user id + * @return boolean $result : TRUE / FALSE + */ + function deleteUser($userId, $userInfo) + { + $this->db->where('userId', $userId); + $this->db->update('Tab_Users', $userInfo); + + return $this->db->affected_rows(); + } + + + /** + * This function is used to match users password for change password + * @param number $userId : This is user id + */ + function matchOldPassword($userId, $oldPassword) + { + $this->db->select('userId, password'); + $this->db->where('userId', $userId); + $this->db->where('isDeleted', 0); + $query = $this->db->get('Tab_Users'); + + $user = $query->result(); + + if(!empty($user)){ + if(verifyHashedPassword($oldPassword, $user[0]->password)){ + return $user; + } else { + return array(); + } + } else { + return array(); + } + } + + /** + * This function is used to change users password + * @param number $userId : This is user id + * @param array $userInfo : This is user updation info + */ + function changePassword($userId, $userInfo) + { + $this->db->where('userId', $userId); + $this->db->where('isDeleted', 0); + $this->db->update('Tab_Users', $userInfo); + + return $this->db->affected_rows(); + } + + + /** + * This function is used to get user login history + * @param number $userId : This is user id + */ + function loginHistoryCount($userId, $searchText, $fromDate, $toDate) + { + $this->db->select('BaseTbl.userId, BaseTbl.sessionData, BaseTbl.machineIp, BaseTbl.userAgent, BaseTbl.agentString, BaseTbl.platform, BaseTbl.createdDtm'); + if(!empty($searchText)) { + $likeCriteria = "(BaseTbl.email LIKE '%".$searchText."%')"; + $this->db->where($likeCriteria); + } + if(!empty($fromDate)) { + $likeCriteria = "DATE_FORMAT(BaseTbl.createdDtm, '%Y-%m-%d' ) >= '".date('Y-m-d', strtotime($fromDate))."'"; + $this->db->where($likeCriteria); + } + if(!empty($toDate)) { + $likeCriteria = "DATE_FORMAT(BaseTbl.createdDtm, '%Y-%m-%d' ) <= '".date('Y-m-d', strtotime($toDate))."'"; + $this->db->where($likeCriteria); + } + $this->db->where('BaseTbl.userId', $userId); + $this->db->from('Tab_LastLogin as BaseTbl'); + $query = $this->db->get(); + + return $query->num_rows(); + } + + /** + * This function is used to get user login history + * @param number $userId : This is user id + * @param number $page : This is pagination offset + * @param number $segment : This is pagination limit + * @return array $result : This is result + */ + function loginHistory($userId, $searchText, $fromDate, $toDate, $page, $segment) + { + $this->db->select('BaseTbl.userId, BaseTbl.sessionData, BaseTbl.machineIp, BaseTbl.userAgent, BaseTbl.agentString, BaseTbl.platform, BaseTbl.createdDtm'); + $this->db->from('Tab_LastLogin as BaseTbl'); + if(!empty($searchText)) { + $likeCriteria = "(BaseTbl.email LIKE '%".$searchText."%')"; + $this->db->where($likeCriteria); + } + if(!empty($fromDate)) { + $likeCriteria = "DATE_FORMAT(BaseTbl.createdDtm, '%Y-%m-%d' ) >= '".date('Y-m-d', strtotime($fromDate))."'"; + $this->db->where($likeCriteria); + } + if(!empty($toDate)) { + $likeCriteria = "DATE_FORMAT(BaseTbl.createdDtm, '%Y-%m-%d' ) <= '".date('Y-m-d', strtotime($toDate))."'"; + $this->db->where($likeCriteria); + } + $this->db->where('BaseTbl.userId', $userId); + $this->db->order_by('BaseTbl.id', 'DESC'); + $this->db->limit($page, $segment); + $query = $this->db->get(); + + $result = $query->result(); + return $result; + } + + /** + * This function used to get user information by id + * @param number $userId : This is user id + * @return array $result : This is user information + */ + function getUserInfoById($userId) + { + $this->db->select('userId, name, email, mobile, roleId'); + $this->db->from('Tab_Users'); + $this->db->where('isDeleted', 0); + $this->db->where('userId', $userId); + $query = $this->db->get(); + + return $query->row(); + } + +} + + \ No newline at end of file diff --git a/application/models/user_model.php b/application/models/user_model.php deleted file mode 100755 index 0f5850c..0000000 --- a/application/models/user_model.php +++ /dev/null @@ -1,315 +0,0 @@ -db->select('EMP.EmpID,EMP.FirstName,EMP.LastName,EMP.Designation,EMP.EmailId,EMP.ContactNumber, - DEPT.DEPCode,DEPT.DepartmentName,role.role,user.userId'); - $this->db->from('T_Employee_Details EMP'); - $this->db->join('T_DepartmentDetails DEPT', 'EMP.Departmentcode = DEPT.DEPCode'); - $this->db->join('tbl_users user', 'user.EmpID = EMP.EmpID'); - $this->db->join('tbl_roles role', 'user.roleId = role.roleId'); - - - $this->db->where('user.isDeleted !=', 1); - - $query = $this->db->get(); - - $result = $query->result(); - return $result; - } - - function GetRoleNameByUserID($UserId) - { - $subQuery = 'select roleId, role from tbl_roles - where roleId = (select roleId from tbl_users where userId=?)'; - - $query = $this->db->query($subQuery, array($UserId)); - - - return $query->result(); - - } - /** - * This function is used to get the user roles information - * @return array $result : This is result of the query - */ - function getUserRoles() - { - $this->db->select('roleId, role'); - $this->db->from('tbl_roles'); - $this->db->where("roleid <", 4); - $query = $this->db->get(); - - return $query->result(); - } - - /** - * This function is used to check whether email id is already exist or not - * @param {string} $email : This is email id - * @param {number} $userId : This is user id - * @return {mixed} $result : This is searched result - */ - function checkEmailExists($email, $userId = 0) - { - $this->db->select("email"); - $this->db->from("tbl_users"); - $this->db->where("email", $email); - $this->db->where("isDeleted", 0); - if($userId != 0){ - $this->db->where("userId !=", $userId); - } - $query = $this->db->get(); - - return $query->result(); - } - - - /** - * This function is used to add new user to system - * @return number $insert_id : This is last inserted id - */ - function addNewUser($userInfo) - { - - $this->db->trans_start(); - $this->db->insert('tbl_users', $userInfo); - - $insert_id = $this->db->affected_rows(); - - $this->db->trans_complete(); - - return $insert_id; - } - - /** - * This function used to get user information by id - * @param number $userId : This is user id - * @return array $result : This is user information - */ - function getUserInfo($userId) - { - $this->db->select('userId, name, email, mobile, roleId,isDeleted'); - $this->db->from('tbl_users'); - $this->db->where('isDeleted', 0); - $this->db->where('roleId !=', 1); - $this->db->where('userId', $userId); - $query = $this->db->get(); - - return $query->result(); - } - - - /** - * This function is used to update the user information - * @param array $userInfo : This is users updated information - * @param number $userId : This is user id - */ - function editUser($userInfo, $userId) - { - $this->db->where('EmpID', $userId); - $this->db->update('tbl_users', $userInfo); - //print_r($this->db->last_query()); - return TRUE; - } - - - - /** - * This function is used to delete the user information - * @param number $userId : This is user id - * @return boolean $result : TRUE / FALSE - */ - function deleteUser($userId, $userInfo) - { - $this->db->where('userId', $userId); - $this->db->update('tbl_users', $userInfo); - - return $this->db->affected_rows(); - } - - - /** - * This function is used to match users password for change password - * @param number $userId : This is user id - */ - function matchOldPassword($userId, $oldPassword) - { - $this->db->select('userId, password'); - $this->db->where('userId', $userId); - $this->db->where('isDeleted', 0); - $query = $this->db->get('tbl_users'); - - $user = $query->result(); - - if(!empty($user)){ - if(verifyHashedPassword($oldPassword, $user[0]->password)){ - return $user; - } else { - return array(); - } - } else { - return array(); - } - } - - /** - * This function is used to change users password - * @param number $userId : This is user id - * @param array $userInfo : This is user updation info - */ - function changePassword($userId, $userInfo) - { - $this->db->where('userId', $userId); - $this->db->where('isDeleted', 0); - $this->db->update('tbl_users', $userInfo); - - return $this->db->affected_rows(); - } - /** - * This function is used to get Employee details based on Employee ID Selection - * @return array $result : This is result of the query - */ - function GetEmployeeDetails($UserId) - { - //echo $UserId; - $subQuery = 'select EMP.EmpID,EMP.FirstName,EMP.LastName,EMP.Designation,EMP.EmailId,EMP.ContactNumber,DEPT.DEPCode,DEPT.DepartmentName from - T_Employee_Details EMP join T_DepartmentDetails DEPT on - EMP.Departmentcode = DEPT.DEPCode where EMP.EmpID= (select EmpID from tbl_users where userId=?)'; - - $query = $this->db->query($subQuery, array($UserId)); - - - - return $query->result(); - } - /** - * This function is used to get the All employees - * @return array $result : This is result of the query - */ - function getAllEmployees() - { - /*$this->db->select('EmpID,FirstName,LastName'); - $this->db->from('T_Employee_Details'); - $query = $this->db->get(); - - return $query->result(); */ - $this->db->select('EMP.EmpID,EMP.FirstName,EMP.LastName,EMP.Designation,EMP.EmailId,EMP.ContactNumber,DEPT.DEPCode,DEPT.DepartmentName'); - $this->db->from('T_Employee_Details EMP'); - $this->db->join('T_DepartmentDetails DEPT', 'EMP.Departmentcode = DEPT.DEPCode'); - $this->db->where('EMP.IsActive ',1 ); - $query = $this->db->get(); - 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; - } - - - //this function used to delivery performances - - function deliver_perform($fa,$aa,$m) -{ - - - - $sql="select ip_invoices.*,ip_invoice_items.item_quantity as qty, - ip_clients.* from ip_invoices - join ip_clients on ip_clients.client_id=ip_invoices.client_id -join ip_invoice_items on ip_invoice_items .invoice_id =ip_invoices.invoice_id - join ip_invoice_custom icf on icf.invoice_id = ip_invoices.invoice_id - where icf.invoice_custom_fieldid = 8 and ip_invoices.invoice_status_id != 1"; - - - - if ($fa and $aa != ''){ - - $sql.=" and (ip_invoices.invoice_date_created >= '".$fa."-04-01' and ip_invoices.invoice_date_created <= '".$aa."-03-31')"; - - } - - - - - if ($m!= ''){ - - $sql.=" and monthname(ip_invoices.invoice_date_created) = '".$m."'"; - - } - - $sql .= " ORDER BY ip_invoices.invoice_date_created DESC"; - $query = $this->db->query($sql); - return $query->result(); -} - - function fincalYear() - { - $sql="SELECT - CASE WHEN MONTH(invoice_date_created)>=4 THEN - concat(YEAR(invoice_date_created), '-',YEAR(invoice_date_created)+1) - ELSE concat(YEAR(invoice_date_created)-1,'-', YEAR(invoice_date_created)) END AS financial_year - FROM ip_invoices -GROUP BY financial_year "; - - $query = $this->db->query($sql); - //print_r($query->result()); - return $query->result(); - } - - /* - *fav model - */ - function favouriteadd($favourite) - - { //echo $favourite['Menu_ID'];die; - if($favourite['Menu_ID'] !=''){ - //echo "if"; - - // $this->db->where('id', $id); - // return $this->db->delete('employee'); - $this->db->where('Menu_ID',$favourite['Menu_ID']); - $this->db->delete('T_fav_add'); - - }else{ - //echo "else"; - - $this->db->insert('T_fav_add',$favourite); - $r = $this->db->affected_rows(); - return $r; - } - } - - -} - - \ No newline at end of file diff --git a/application/views/404.php b/application/views/404.php index 19faf45..0b3e739 100755 --- a/application/views/404.php +++ b/application/views/404.php @@ -1,15 +1,46 @@ -
    + +
    +

    - 404 - This is not the page you are looking for + 404 Error Page

    +
    + +
    -
    -
    - Page Not Found Image +
    +

    404

    + +
    +

    Oops! Page not found.

    + +

    + We could not find the page you were looking for. + Meanwhile, you may return to dashboard or try using the search form. +

    + +
    +
    + + +
    + +
    + +
    + +
    +
    -
    \ No newline at end of file + +
    + \ No newline at end of file diff --git a/application/views/500.php b/application/views/500.php new file mode 100755 index 0000000..e7bcc1a --- /dev/null +++ b/application/views/500.php @@ -0,0 +1,47 @@ + +
    + +
    +

    + 500 Error Page +

    + +
    + + +
    + +
    +

    500

    + +
    +

    Oops! Something went wrong.

    + +

    + We will work on fixing that right away. + Meanwhile, you may return to dashboard or try using the search form. +

    + +
    +
    + + +
    + +
    +
    + +
    +
    +
    + + +
    + +
    + \ No newline at end of file diff --git a/application/views/UsersListing.php b/application/views/UsersListing.php new file mode 100644 index 0000000..fbe281c --- /dev/null +++ b/application/views/UsersListing.php @@ -0,0 +1,87 @@ +
    + +
    +

    + User Management + Add, Edit, Delete +

    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    +

    Users List

    +
    +
    +
    + +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + +
    IdNameEmailMobileRoleActions
    userId ?>name ?>email ?>mobile ?>role ?> + | + + +
    + +
    + +
    +
    +
    +
    +
    + + diff --git a/application/views/access.php b/application/views/access.php index ea49534..7726d6e 100755 --- a/application/views/access.php +++ b/application/views/access.php @@ -1,15 +1,45 @@ -
    + +
    +

    - Access Denied - You are not authorize user to use this + Access Denied

    +
    + +
    -
    -
    - Access Denied Image +
    +

    Access Denied

    + +
    +

    Oops! Page not found.

    + +

    + You are not authorize user to use this +

    + +
    +
    + + +
    + +
    + +
    + +
    +
    -
    \ No newline at end of file + +
    + \ No newline at end of file diff --git a/application/views/addUser.php b/application/views/addUser.php new file mode 100644 index 0000000..9245bd7 --- /dev/null +++ b/application/views/addUser.php @@ -0,0 +1,125 @@ +
    + +
    +

    + User Management + Add / Edit User +

    +
    + +
    + +
    + +
    + + + + +
    +
    +

    Enter User Details

    +
    + + load->helper("form"); ?> +
    +
    +
    +
    +
    + + +
    + +
    +
    +
    + + +
    +
    +
    +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    + load->helper('form'); + $error = $this->session->flashdata('error'); + if($error) + { + ?> +
    + + session->flashdata('error'); ?> +
    + + session->flashdata('success'); + if($success) + { + ?> +
    + + session->flashdata('success'); ?> +
    + + +
    +
    + ', '
    '); ?> +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/application/views/changePassword.php b/application/views/changePassword.php new file mode 100644 index 0000000..7d41561 --- /dev/null +++ b/application/views/changePassword.php @@ -0,0 +1,250 @@ + + + + + +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    +

    Change Password

    +
    + +
    +
    +
    +
    + +
    +
    +
    + +

    + +
    +
    +
    + +
    +
    + +
    +
    + +
    +
    +
    +
    +
    + +
    Or
    + +
    +
    +
    + +
    + +
    + +
    + +
    + + +
    + +
    + + + + \ No newline at end of file diff --git a/application/views/city_master.php b/application/views/city_master.php index 4523138..0814da6 100755 --- a/application/views/city_master.php +++ b/application/views/city_master.php @@ -200,11 +200,11 @@ span:nth-child(3) .slide-up:active {

    City Master

    -
    +
    - + @@ -214,14 +214,14 @@ span:nth-child(3) .slide-up:active {
    - +
    Or
    - +
    diff --git a/application/views/country_master.php b/application/views/country_master.php index d385922..88186c7 100755 --- a/application/views/country_master.php +++ b/application/views/country_master.php @@ -200,11 +200,11 @@ span:nth-child(3) .slide-up:active {

    Country Master

    -
    +
    - + @@ -212,7 +212,7 @@ span:nth-child(3) .slide-up:active {
    - + @@ -222,7 +222,7 @@ span:nth-child(3) .slide-up:active {
    -
    @@ -239,7 +239,7 @@ span:nth-child(3) .slide-up:active {
    Or
    - +
    diff --git a/application/views/document_upload.php b/application/views/document_upload.php index 04f45f9..0d1f185 100755 --- a/application/views/document_upload.php +++ b/application/views/document_upload.php @@ -200,11 +200,11 @@ span:nth-child(3) .slide-up:active {

    Document Master

    -
    +
    - + @@ -214,7 +214,7 @@ span:nth-child(3) .slide-up:active {
    - + @@ -224,14 +224,14 @@ span:nth-child(3) .slide-up:active {
    - +
    Or
    - +
    @@ -249,4 +249,23 @@ span:nth-child(3) .slide-up:active {
    - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/application/views/editUser.php b/application/views/editUser.php new file mode 100644 index 0000000..7e98666 --- /dev/null +++ b/application/views/editUser.php @@ -0,0 +1,149 @@ +userId; + $name = $uf->name; + $email = $uf->email; + $mobile = $uf->mobile; + $roleId = $uf->roleId; + } +} + + +?> + +
    + +
    +

    + User Management + Add / Edit User +

    +
    + +
    + +
    + +
    + + + + +
    +
    +

    Enter User Details

    +
    + + +
    +
    +
    +
    +
    + + + +
    + +
    +
    +
    + + +
    +
    +
    +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    + load->helper('form'); + $error = $this->session->flashdata('error'); + if($error) + { + ?> +
    + + session->flashdata('error'); ?> +
    + + session->flashdata('success'); + if($success) + { + ?> +
    + + session->flashdata('success'); ?> +
    + + +
    +
    + ', '
    '); ?> +
    +
    +
    +
    + +
    + + \ No newline at end of file diff --git a/application/views/includes/Header.php b/application/views/includes/Header.php index a65e662..4b05808 100755 --- a/application/views/includes/Header.php +++ b/application/views/includes/Header.php @@ -3,7 +3,7 @@ - VISA | Dashboard + <?php echo $pageTitle; ?> @@ -87,10 +87,10 @@ @@ -114,7 +114,7 @@

    Visa Employee

    - Online + Online
    @@ -154,7 +154,7 @@
  • Document Master
  • -
  • +
  • Country Visa Details diff --git a/application/views/lockscreen.php b/application/views/lockscreen.php new file mode 100755 index 0000000..a7f7424 --- /dev/null +++ b/application/views/lockscreen.php @@ -0,0 +1,77 @@ + + + + + + AdminLTE 2 | Lockscreen + + + + + + + + + + + + + + + + + + + + +
    + + +
    John Doe
    + + +
    + +
    + User Image +
    + + + +
    +
    + + +
    + +
    +
    +
    + + +
    + +
    + Enter your password to retrieve your session +
    + + +
    + + + + + + + + diff --git a/application/views/login.php b/application/views/login.php old mode 100755 new mode 100644 index fcd4847..1609fc6 --- a/application/views/login.php +++ b/application/views/login.php @@ -7,15 +7,15 @@ - + - + - + - + - +