Browse Source

Added role modification for user management

tags/v1.3^2
Teknikode 5 years ago
parent
commit
cb682fcf91
4 changed files with 82 additions and 3 deletions
  1. 0
    0
      admin/New Text Document.txt
  2. 62
    0
      admin/get_user.php
  3. 16
    0
      includes/classes/Role.class.php
  4. 4
    3
      templates/default/js/admin.js

+ 0
- 0
admin/New Text Document.txt View File


+ 62
- 0
admin/get_user.php View File

@@ -0,0 +1,62 @@
<?php
require_once('../includes/config.php');
if(isset($_POST))
{
$query = rawurldecode($_POST['query']);
$user_list = $db->select('users', "username LIKE ?", array('%'.$query.'%'));

$users = array();
foreach ($user_list as $user)
{
if (!is_array($user))
{
$users = array($user_list);
break;
}
array_push($users, $user);
}
if ($users)
{
foreach ($users as $parsed_user)
{
$user = $userTools->getUser($parsed_user['username']);
?>
<div class="row">
<div class="col-sm-12">
<div class="row"><h3 class="text-center"><strong><?php echo $user->username; ?></strong></h3></div>
<div class="row">
<h4>Roles</h4>
<?php
foreach ($user->roles as $role => $perm)
{
?>
<div class="form-group">
<label class="sr-only" for="<?php echo $user->id; ?>_<?php echo $role; ?>"><?php echo $role; ?></label>
<button type="button" class="btn btn-danger" id="<?php echo $user->id; ?>_<?php echo $role; ?>">Remove</button>
</div>
<?php
}
?>
</div>
<div class="row">
<select class="form-control" name="role_select">
<?php
$roles = Role::getRoles();
foreach ($roles as $role)
{
echo "<option>".$role['role_name']."</option>";
}
?>
</select>
<button class="btn btn-default pull-right" id="<?php echo $user->id; ?>">Add Role</button>
</div>
</div>
</div>
<?php
}
}
}
?>

+ 16
- 0
includes/classes/Role.class.php View File

@@ -23,5 +23,21 @@ class Role
public function hasPerm($permission) {
return isset($this->permissions[$permission]);
}
public function getRoles()
{
$role_list = $db->select('roles', "1=?", array(1));
$roles = array();
foreach ($role_list as $role)
{
if (!is_array($role))
{
$roles = array($role_list);
break;
}
array_push($roles, $role);
}
return $roles;
}
}
?>

+ 4
- 3
templates/default/js/admin.js View File

@@ -1,6 +1,5 @@
function update_user_list(search)
{
blog_id=encodeURIComponent($(".blog-main").attr("id"));
$.ajax({
type: "POST",
url: "../../../get_user.php",
@@ -9,8 +8,10 @@ function update_user_list(search)
{
if(html)
{
$(".user_list").append(obj.result);
linkUserUpdate('.user_update');
$(".user_list").html(html);
//linkAddRole('.add_role');
//linkRemoveRole('.remove_role');
//linkUserDelete('.user_delete');
}
}
});

Loading…
Cancel
Save