Skip to content

Commit baacf53

Browse files
committed
user profile update
1 parent 4f11550 commit baacf53

File tree

6 files changed

+104
-24
lines changed

6 files changed

+104
-24
lines changed

application/config/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
$route['editUser'] = "user/editUser";
6969
$route['deleteUser'] = "user/deleteUser";
7070
$route['profile'] = "user/profile";
71+
$route['profileUpdate'] = "user/profileUpdate";
7172

7273
$route['loadChangePass'] = "user/loadChangePass";
7374
$route['changePassword'] = "user/changePassword";

application/controllers/User.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,45 @@ function loginHistoy($userId = NULL)
370370
*/
371371
function profile()
372372
{
373-
$data["userInfo"] = $this->user_model->getUserInfoById($this->vendorId);
373+
$data["userInfo"] = $this->user_model->getUserInfoWithRole($this->vendorId);
374374

375375
$this->global['pageTitle'] = 'CodeInsect : My profile';
376376
$this->loadViews("profile", $this->global, $data, NULL);
377377
}
378+
379+
function profileUpdate()
380+
{
381+
$this->load->library('form_validation');
382+
383+
$this->form_validation->set_rules('fname','Full Name','trim|required|max_length[128]');
384+
$this->form_validation->set_rules('mobile','Mobile Number','required|min_length[10]');
385+
386+
if($this->form_validation->run() == FALSE)
387+
{
388+
$this->profile();
389+
}
390+
else
391+
{
392+
$name = ucwords(strtolower($this->security->xss_clean($this->input->post('fname'))));
393+
$mobile = $this->security->xss_clean($this->input->post('mobile'));
394+
395+
$userInfo = array('name'=>$name, 'mobile'=>$mobile, 'updatedBy'=>$this->vendorId, 'updatedDtm'=>date('Y-m-d H:i:s'));
396+
397+
$result = $this->user_model->editUser($userInfo, $this->vendorId);
398+
399+
if($result == true)
400+
{
401+
$this->session->set_userdata('name', $name);
402+
$this->session->set_flashdata('success', 'Profile updated successfully');
403+
}
404+
else
405+
{
406+
$this->session->set_flashdata('error', 'Profile updation failed');
407+
}
408+
409+
redirect('profile');
410+
}
411+
}
378412
}
379413

380414
?>

application/models/User_model.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,23 @@ function getUserInfoById($userId)
268268
return $query->row();
269269
}
270270

271+
/**
272+
* This function used to get user information by id with role
273+
* @param number $userId : This is user id
274+
* @return aray $result : This is user information
275+
*/
276+
function getUserInfoWithRole($userId)
277+
{
278+
$this->db->select('BaseTbl.userId, BaseTbl.email, BaseTbl.name, BaseTbl.mobile, BaseTbl.roleId, Roles.role');
279+
$this->db->from('tbl_users as BaseTbl');
280+
$this->db->join('tbl_roles as Roles','Roles.roleId = BaseTbl.roleId');
281+
$this->db->where('BaseTbl.userId', $userId);
282+
$this->db->where('BaseTbl.isDeleted', 0);
283+
$query = $this->db->get();
284+
285+
return $query->row();
286+
}
287+
271288
}
272289

273290

application/views/includes/header.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,14 @@
7070
<ul class="dropdown-menu">
7171
<!-- User image -->
7272
<li class="user-header">
73+
7374
<img src="<?php echo base_url(); ?>assets/dist/img/avatar.png" class="img-circle" alt="User Image" />
7475
<p>
75-
<?php echo $name; ?>
76+
<?php echo $name; ?>&nbsp;
77+
<a style="text-decoration: none; color:#fff" href="<?php echo base_url(); ?>profile"><i class="fa fa-pencil"></i></a>
7678
<small><?php echo $role_text; ?></small>
7779
</p>
80+
7881
</li>
7982
<!-- Menu Footer-->
8083
<li class="user-footer">

application/views/profile.php

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
$email = $userInfo->email;
55
$mobile = $userInfo->mobile;
66
$roleId = $userInfo->roleId;
7+
$role = $userInfo->role;
78
?>
89

910
<div class="content-wrapper">
@@ -19,44 +20,53 @@
1920

2021
<div class="row">
2122
<!-- left column -->
22-
<div class="col-md-8">
23+
<div class="col-md-3">
2324
<!-- general form elements -->
24-
25+
26+
27+
<div class="box box-primary">
28+
<div class="box-body box-profile">
29+
<img class="img-responsive img-circle" src="<?php echo base_url(); ?>assets/dist/img/avatar.png" alt="User profile picture">
30+
<h3 class="profile-username text-center"><?= $name ?></h3>
31+
32+
<p class="text-muted text-center"><?= $role ?></p>
33+
34+
<ul class="list-group list-group-unbordered">
35+
<li class="list-group-item">
36+
<b>Email</b> <a class="pull-right"><?= $email ?></a>
37+
</li>
38+
<li class="list-group-item">
39+
<b>Mobile</b> <a class="pull-right"><?= $mobile ?></a>
40+
</li>
41+
</ul>
42+
</div>
43+
</div>
44+
45+
</div>
46+
47+
<div class="col-md-4">
2548
<div class="box box-primary">
2649
<div class="box-header">
27-
<h3 class="box-title">User Details</h3>
50+
<h3 class="box-title">You can modify your details</h3>
2851
</div><!-- /.box-header -->
29-
<!-- form start -->
30-
31-
<form role="form" action="<?php echo base_url() ?>profile" method="post" id="editUser" role="form">
52+
<!-- form start -->
53+
<form role="form" action="<?php echo base_url() ?>profileUpdate" method="post" id="editProfile" role="form">
3254
<div class="box-body">
3355
<div class="row">
34-
<div class="col-md-6">
56+
<div class="col-md-12">
3557
<div class="form-group">
3658
<label for="fname">Full Name</label>
37-
<input type="text" class="form-control" id="fname" placeholder="Full Name" name="fname" value="<?php echo $name; ?>" maxlength="128" />
38-
</div>
39-
40-
</div>
41-
<div class="col-md-6">
42-
<div class="form-group">
43-
<label for="email">Email address : </label>
44-
<h5><?php echo $email; ?></h5>
59+
<input type="text" class="form-control" id="fname" name="fname" placeholder="<?php echo $name; ?>" maxlength="128" />
4560
</div>
4661
</div>
4762
</div>
4863
<div class="row">
49-
<div class="col-md-6">
64+
<div class="col-md-12">
5065
<div class="form-group">
5166
<label for="mobile">Mobile Number</label>
52-
<input type="text" class="form-control" id="mobile" placeholder="Mobile Number" name="mobile" value="<?php echo $mobile; ?>" maxlength="10">
67+
<input type="text" class="form-control" id="mobile" name="mobile" placeholder="<?php echo $mobile; ?>" maxlength="10">
5368
</div>
5469
</div>
55-
<div class="col-md-6">
56-
<div class="form-group">
57-
<label for="role">Role</label>
58-
</div>
59-
</div>
6070
</div>
6171
</div><!-- /.box-body -->
6272

assets/js/editUser.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,19 @@ $(document).ready(function(){
2626
role : { required : "This field is required", selected : "Please select atleast one option" }
2727
}
2828
});
29+
30+
var editProfileForm = $("#editProfile");
31+
32+
var validator = editProfileForm.validate({
33+
34+
rules:{
35+
fname :{ required : true },
36+
mobile : { required : true, digits : true },
37+
},
38+
messages:{
39+
fname :{ required : "This field is required" },
40+
mobile : { required : "This field is required", digits : "Please enter numbers only" },
41+
}
42+
});
43+
2944
});

0 commit comments

Comments
 (0)