BBnepal-Accounts/account/application/views/users/list.php
Sampanna Rimal 9cd05ef3cb commitall
2024-07-10 18:28:19 +05:45

126 lines
4.1 KiB
PHP

<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse2">
View Users
</a>
</h4>
</div>
<div id="collapse2" class="panel-collapse collapse in">
<div class="panel-body">
<?php $value=getPrivilege('users'); ?>
<table class="table table-hover">
<thead>
<tr>
<th>S.no</th>
<th>Name</th>
<th>Email</th>
<?php if (isSuperAdmin()):?><th>Password</th><?php endif;?>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php $i=0;foreach ($Users as $user): $i++;?>
<tr>
<td><?php echo $i;?></td>
<td><?php echo $user->user_name;?></td>
<td><?php echo $user->user_email;?></td>
<?php if (isSuperAdmin()):?><td><?php echo $user->user_password;?></td><?php endif;?>
<td>
<?php if (isViewable('edit')){?>
<button type="button" onclick="changePrivilege(<?php echo $user->user_id;?>)" class="btn btn-primary">Change Privilege</button>
<button type="button" class="btn btn-primary" data-toggle="modal" onclick="passwordModal(<?php echo $user->user_id;?>)" data-target="#changePassword">Change Password</button>
<?php }?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</div>
</div>
</div>
<!-- The Modal -->
<div class="modal fade" id="changePrivilege" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div id="container_modal">
</div>
</div>
<div class="modal" id="changePassword">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Change Password</h4>
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<input type="password" id="password1">
<input type="password" id="password2">
</div>
<!-- Modal footer -->
<div class="modal-footer">
<a id="changeA">Close</a>
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php
function changePrivilege($name)
{
?>
<tr>
<td style="text-transform: capitalize"><?php echo $name; ?></td>
<td><label><input type="checkbox" value="1" name="<?php echo $name; ?>"> view</label></td>
<td><label><input type="checkbox" value="2" name="<?php echo $name; ?>"> add/update</label></td>
<td><label><input type="checkbox" value="3" name="<?php echo $name; ?>"> delete</label></td>
</tr>
<?php
}
?>
<script>
function passwordModal(id) {
$("#changeA").html("<button type='button' onclick='changePassword("+ id +")' class='btn btn-success' id='changeBtn'>Update</button>");
}
function changePassword(id) {
if ($('#password1').val() === $('#password2').val()) {
$.post("<?php echo base_url('ajax/changePassword/');?>"+id, {password: $('#password1').val()}, function(result){
alert('Password changed successfully');
window.location=window.location;
});
}
else {
alert('Passwords do not match');
}
}
function changePrivilege(id) {
$.ajax({
url:"<?php echo base_url('ajax/updatePrivilege/');?>"+ id,
success: function(data)
{
$("#container_modal").html(data);
$('#changePrivilege').modal();
}
});
}
</script>