Browse Source

Added 'Remove User Role'

tags/v1.3^2
Teknikode 6 years ago
parent
commit
3131f1fb73

+ 3
- 3
admin/get_user.php View File

@@ -33,9 +33,9 @@ if(isset($_POST))
{
?>
<div class="form-group">
<label class="col-sm-8 control-label" for="<?php echo $user->id; ?>_<?php echo $role; ?>"><?php echo $role; ?></label>
<div class="col-sm-4">
<button type="button" class="btn btn-danger" id="<?php echo $user->id; ?>_<?php echo $role; ?>">Remove</button>
<label class="col-sm-3 control-label" for="<?php echo $user->id; ?>_<?php echo $role; ?>"><?php echo $role; ?></label>
<div class="col-sm-9">
<button type="button" class="btn btn-danger btn-sm remove_user_role" id="<?php echo $user->id; ?>_<?php echo $role; ?>">Remove</button>
</div>
</div>
<?php

+ 20
- 0
admin/remove_user_role.php View File

@@ -0,0 +1,20 @@
<?php
require_once('../includes/config.php');
if(isset($_POST))
{
if ($logged_in)
{
$user_id = rawurldecode($_POST['id']);
$role_id = rawurldecode($_POST['role']);
$userTools->deleteUserRoles($user_id, array($role_id));
}
else
{
echo "You need to be logged in";
}
}
else
{
echo "POST not set";
}
?>

+ 13
- 3
includes/classes/UserTools.class.php View File

@@ -192,10 +192,20 @@ class UserTools {
return true;
}
// delete ALL roles for specified user id
public static function deleteUserRoles($user_id)
// delete specified or ALL roles for specified user id
public static function deleteUserRoles($user_id, $roles=null)
{
$db->delete('user_role', 'user_id=?', array($user_id));
if ($roles != null)
{
foreach ($roles as $role_id)
{
$db->delete('user_role', 'user_id=? AND role_id=?', array($user_id, $role_id));
}
}
else
{
$db->delete('user_role', 'user_id=?', array($user_id));
}
return true;
}
}

+ 29
- 1
templates/default/js/admin.js View File

@@ -8,7 +8,7 @@ function update_user_list(search)
{
$(".user_list").html(html);
linkUserAddRole('.add_user_role');
//linkUserRemoveRole('.remove_role');
linkUserRemoveRole('.remove_user_role');
//linkUserDelete('.user_delete');
}
});
@@ -41,6 +41,34 @@ function linkUserAddRole(selector)
});
}

function linkUserRemoveRole(selector)
{
$(selector).click(function() {
var object = $(this);
role_info=encodeURIComponent(object.attr("id"));
info = role_info.split("_");
user_id = info[0];
role = info[1];
$.ajax({
type: "POST",
url: "../../../admin/remove_user_role.php",
data: "id="+user_id+"&role="+role,
success: function(html)
{
if(!html)
{
update_user_list($('#userSearch').val());
}
else
{
$("#top_msg").css('display', 'inline', 'important');
$("#top_msg").html('<div class="alert alert-danger alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>'+html+'</div>');
}
}
});
});
}

function linkUserUpdate(selector)
{
$(selector).click(function() {

Loading…
Cancel
Save