Skip to content

Commit

Permalink
user profile update
Browse files Browse the repository at this point in the history
  • Loading branch information
kishor10d committed Aug 28, 2018
1 parent 4f11550 commit baacf53
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 24 deletions.
1 change: 1 addition & 0 deletions application/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
36 changes: 35 additions & 1 deletion application/controllers/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}

?>
17 changes: 17 additions & 0 deletions application/models/User_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

}


5 changes: 4 additions & 1 deletion application/views/includes/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@
<ul class="dropdown-menu">
<!-- User image -->
<li class="user-header">

<img src="<?php echo base_url(); ?>assets/dist/img/avatar.png" class="img-circle" alt="User Image" />
<p>
<?php echo $name; ?>
<?php echo $name; ?>&nbsp;
<a style="text-decoration: none; color:#fff" href="<?php echo base_url(); ?>profile"><i class="fa fa-pencil"></i></a>
<small><?php echo $role_text; ?></small>
</p>

</li>
<!-- Menu Footer-->
<li class="user-footer">
Expand Down
54 changes: 32 additions & 22 deletions application/views/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
$email = $userInfo->email;
$mobile = $userInfo->mobile;
$roleId = $userInfo->roleId;
$role = $userInfo->role;
?>

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

<div class="row">
<!-- left column -->
<div class="col-md-8">
<div class="col-md-3">
<!-- general form elements -->



<div class="box box-primary">
<div class="box-body box-profile">
<img class="img-responsive img-circle" src="<?php echo base_url(); ?>assets/dist/img/avatar.png" alt="User profile picture">
<h3 class="profile-username text-center"><?= $name ?></h3>

<p class="text-muted text-center"><?= $role ?></p>

<ul class="list-group list-group-unbordered">
<li class="list-group-item">
<b>Email</b> <a class="pull-right"><?= $email ?></a>
</li>
<li class="list-group-item">
<b>Mobile</b> <a class="pull-right"><?= $mobile ?></a>
</li>
</ul>
</div>
</div>

</div>

<div class="col-md-4">
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">User Details</h3>
<h3 class="box-title">You can modify your details</h3>
</div><!-- /.box-header -->
<!-- form start -->

<form role="form" action="<?php echo base_url() ?>profile" method="post" id="editUser" role="form">
<!-- form start -->
<form role="form" action="<?php echo base_url() ?>profileUpdate" method="post" id="editProfile" role="form">
<div class="box-body">
<div class="row">
<div class="col-md-6">
<div class="col-md-12">
<div class="form-group">
<label for="fname">Full Name</label>
<input type="text" class="form-control" id="fname" placeholder="Full Name" name="fname" value="<?php echo $name; ?>" maxlength="128" />
</div>

</div>
<div class="col-md-6">
<div class="form-group">
<label for="email">Email address : </label>
<h5><?php echo $email; ?></h5>
<input type="text" class="form-control" id="fname" name="fname" placeholder="<?php echo $name; ?>" maxlength="128" />
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="col-md-12">
<div class="form-group">
<label for="mobile">Mobile Number</label>
<input type="text" class="form-control" id="mobile" placeholder="Mobile Number" name="mobile" value="<?php echo $mobile; ?>" maxlength="10">
<input type="text" class="form-control" id="mobile" name="mobile" placeholder="<?php echo $mobile; ?>" maxlength="10">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="role">Role</label>
</div>
</div>
</div>
</div><!-- /.box-body -->

Expand Down
15 changes: 15 additions & 0 deletions assets/js/editUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,19 @@ $(document).ready(function(){
role : { required : "This field is required", selected : "Please select atleast one option" }
}
});

var editProfileForm = $("#editProfile");

var validator = editProfileForm.validate({

rules:{
fname :{ required : true },
mobile : { required : true, digits : true },
},
messages:{
fname :{ required : "This field is required" },
mobile : { required : "This field is required", digits : "Please enter numbers only" },
}
});

});

0 comments on commit baacf53

Please sign in to comment.