diff --git a/application/config/routes.php b/application/config/routes.php index abee6ba6..28196d5a 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -68,6 +68,7 @@ $route['editUser'] = "user/editUser"; $route['deleteUser'] = "user/deleteUser"; $route['profile'] = "user/profile"; +$route['profileUpdate'] = "user/profileUpdate"; $route['loadChangePass'] = "user/loadChangePass"; $route['changePassword'] = "user/changePassword"; diff --git a/application/controllers/User.php b/application/controllers/User.php index 7434aa0e..8db1b157 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -370,11 +370,45 @@ function loginHistoy($userId = NULL) */ function profile() { - $data["userInfo"] = $this->user_model->getUserInfoById($this->vendorId); + $data["userInfo"] = $this->user_model->getUserInfoWithRole($this->vendorId); $this->global['pageTitle'] = 'CodeInsect : My profile'; $this->loadViews("profile", $this->global, $data, NULL); } + + function profileUpdate() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules('fname','Full Name','trim|required|max_length[128]'); + $this->form_validation->set_rules('mobile','Mobile Number','required|min_length[10]'); + + if($this->form_validation->run() == FALSE) + { + $this->profile(); + } + else + { + $name = ucwords(strtolower($this->security->xss_clean($this->input->post('fname')))); + $mobile = $this->security->xss_clean($this->input->post('mobile')); + + $userInfo = array('name'=>$name, 'mobile'=>$mobile, 'updatedBy'=>$this->vendorId, 'updatedDtm'=>date('Y-m-d H:i:s')); + + $result = $this->user_model->editUser($userInfo, $this->vendorId); + + if($result == true) + { + $this->session->set_userdata('name', $name); + $this->session->set_flashdata('success', 'Profile updated successfully'); + } + else + { + $this->session->set_flashdata('error', 'Profile updation failed'); + } + + redirect('profile'); + } + } } ?> \ No newline at end of file diff --git a/application/models/User_model.php b/application/models/User_model.php index 3d3743bc..3d5ce24f 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -268,6 +268,23 @@ function getUserInfoById($userId) return $query->row(); } + /** + * This function used to get user information by id with role + * @param number $userId : This is user id + * @return aray $result : This is user information + */ + function getUserInfoWithRole($userId) + { + $this->db->select('BaseTbl.userId, BaseTbl.email, BaseTbl.name, BaseTbl.mobile, BaseTbl.roleId, Roles.role'); + $this->db->from('tbl_users as BaseTbl'); + $this->db->join('tbl_roles as Roles','Roles.roleId = BaseTbl.roleId'); + $this->db->where('BaseTbl.userId', $userId); + $this->db->where('BaseTbl.isDeleted', 0); + $query = $this->db->get(); + + return $query->row(); + } + } \ No newline at end of file diff --git a/application/views/includes/header.php b/application/views/includes/header.php index 2c27b734..e342f0b3 100644 --- a/application/views/includes/header.php +++ b/application/views/includes/header.php @@ -70,11 +70,14 @@