Add group editor
This commit is contained in:
parent
5b7770bda4
commit
17be02a521
37
action.php
37
action.php
@ -165,7 +165,7 @@ switch ($VARS['action']) {
|
|||||||
if (!$database->has('permissions', ['permcode' => $perm])) {
|
if (!$database->has('permissions', ['permcode' => $perm])) {
|
||||||
returnToSender("permission_not_exists", htmlentities($perm));
|
returnToSender("permission_not_exists", htmlentities($perm));
|
||||||
}
|
}
|
||||||
|
|
||||||
$permid = $database->get('permissions', 'permid', ['permcode' => $perm]);
|
$permid = $database->get('permissions', 'permid', ['permcode' => $perm]);
|
||||||
$permids[] = $permid;
|
$permids[] = $permid;
|
||||||
$already_assigned = array_diff($already_assigned, [$permid]); // Remove permission from old list
|
$already_assigned = array_diff($already_assigned, [$permid]); // Remove permission from old list
|
||||||
@ -211,6 +211,41 @@ switch ($VARS['action']) {
|
|||||||
}
|
}
|
||||||
$data = $database->select('permissions', ['permcode (name)', 'perminfo (info)'], ["OR" => ['permcode[~]' => $VARS['q'], 'perminfo[~]' => $VARS['q']], "LIMIT" => 10]);
|
$data = $database->select('permissions', ['permcode (name)', 'perminfo (info)'], ["OR" => ['permcode[~]' => $VARS['q'], 'perminfo[~]' => $VARS['q']], "LIMIT" => 10]);
|
||||||
exit(json_encode($data));
|
exit(json_encode($data));
|
||||||
|
case "assigngroup":
|
||||||
|
if (!$database->has('groups', ['groupid' => $VARS['gid']])) {
|
||||||
|
returnToSender("invalid_group");
|
||||||
|
}
|
||||||
|
$gid = $VARS['gid'];
|
||||||
|
$already_assigned = $database->select('assigned_groups', 'uid', ['groupid' => $gid]);
|
||||||
|
|
||||||
|
require_once __DIR__ . "/lib/userinfo.php";
|
||||||
|
foreach ($VARS['users'] as $u) {
|
||||||
|
if (!user_exists($u)) {
|
||||||
|
returnToSender("user_not_exists", htmlentities($u));
|
||||||
|
}
|
||||||
|
$uid = getUserByUsername($u)['uid'];
|
||||||
|
$database->insert('assigned_groups', ['groupid' => $gid, 'uid' => $uid]);
|
||||||
|
$already_assigned = array_diff($already_assigned, [$uid]); // Remove user from old list
|
||||||
|
}
|
||||||
|
foreach ($already_assigned as $uid) {
|
||||||
|
$database->delete('assigned_groups', ["AND" => ['uid' => $uid, 'groupid' => $gid]]);
|
||||||
|
}
|
||||||
|
returnToSender("group_assigned", "", ["gid" => $gid]);
|
||||||
|
break;
|
||||||
|
case "addgroup":
|
||||||
|
$group = htmlspecialchars(strip_tags($VARS['group']), ENT_HTML5);
|
||||||
|
if ($database->has('groups', ['groupname' => $group])) {
|
||||||
|
returnToSender("group_exists");
|
||||||
|
}
|
||||||
|
$database->insert('groups', ['groupname' => $group]);
|
||||||
|
returnToSender("group_added");
|
||||||
|
case "rmgroup":
|
||||||
|
if (!$database->has('groups', ['groupid' => $VARS['gid']])) {
|
||||||
|
returnToSender("invalid_group");
|
||||||
|
}
|
||||||
|
$database->delete('assigned_groups', ['groupid' => $VARS['gid']]);
|
||||||
|
$database->delete('groups', ['groupid' => $VARS['gid']]);
|
||||||
|
returnToSender("group_deleted");
|
||||||
case "export":
|
case "export":
|
||||||
require_once __DIR__ . "/lib/reports.php";
|
require_once __DIR__ . "/lib/reports.php";
|
||||||
generateReport($VARS['type'], $VARS['format']);
|
generateReport($VARS['type'], $VARS['format']);
|
||||||
|
@ -116,5 +116,21 @@ define("STRINGS", [
|
|||||||
"permissions assigned" => "Permissions assigned.",
|
"permissions assigned" => "Permissions assigned.",
|
||||||
"type to select a user" => "Type to select a user",
|
"type to select a user" => "Type to select a user",
|
||||||
"type to add a permission" => "Type to add a permission",
|
"type to add a permission" => "Type to add a permission",
|
||||||
"select a user to view or edit permissions" => "Select a user to view or edit the assigned permissions."
|
"select a user to view or edit permissions" => "Select a user to view or edit the assigned permissions.",
|
||||||
|
"group" => "Group",
|
||||||
|
"groups" => "Groups",
|
||||||
|
"group does not exist" => "That group does not exist.",
|
||||||
|
"group members updated" => "Group members updated.",
|
||||||
|
"group added" => "Group added.",
|
||||||
|
"group deleted" => "Group deleted.",
|
||||||
|
"group already exists" => "A group with that name already exists.",
|
||||||
|
"save" => "Save",
|
||||||
|
"next" => "Next",
|
||||||
|
"add" => "Add",
|
||||||
|
"delete" => "Delete",
|
||||||
|
"new group" => "New group",
|
||||||
|
"delete group" => "Delete group",
|
||||||
|
"enter group name" => "Group name",
|
||||||
|
"group management" => "Group Management",
|
||||||
|
"group assignments" => "Group Assignments",
|
||||||
]);
|
]);
|
@ -74,4 +74,24 @@ define("MESSAGES", [
|
|||||||
"string" => "manager does not exist",
|
"string" => "manager does not exist",
|
||||||
"type" => "danger"
|
"type" => "danger"
|
||||||
],
|
],
|
||||||
|
"invalid_group" => [
|
||||||
|
"string" => "group does not exist",
|
||||||
|
"type" => "danger"
|
||||||
|
],
|
||||||
|
"group_assigned" => [
|
||||||
|
"string" => "group members updated",
|
||||||
|
"type" => "success"
|
||||||
|
],
|
||||||
|
"group_added" => [
|
||||||
|
"string" => "group added",
|
||||||
|
"type" => "success"
|
||||||
|
],
|
||||||
|
"group_deleted" => [
|
||||||
|
"string" => "group deleted",
|
||||||
|
"type" => "success"
|
||||||
|
],
|
||||||
|
"group_exists" => [
|
||||||
|
"string" => "group already exists",
|
||||||
|
"type" => "danger"
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
|
14
pages.php
14
pages.php
@ -36,6 +36,18 @@ define("PAGES", [
|
|||||||
"title" => "delete user",
|
"title" => "delete user",
|
||||||
"navbar" => false
|
"navbar" => false
|
||||||
],
|
],
|
||||||
|
"groups" => [
|
||||||
|
"title" => "groups",
|
||||||
|
"navbar" => true,
|
||||||
|
"icon" => "object-group",
|
||||||
|
"styles" => [
|
||||||
|
"static/css/easy-autocomplete.min.css"
|
||||||
|
],
|
||||||
|
"scripts" => [
|
||||||
|
"static/js/jquery.easy-autocomplete.min.js",
|
||||||
|
"static/js/groups.js"
|
||||||
|
],
|
||||||
|
],
|
||||||
"authlog" => [
|
"authlog" => [
|
||||||
"title" => "security log",
|
"title" => "security log",
|
||||||
"navbar" => true,
|
"navbar" => true,
|
||||||
@ -88,4 +100,4 @@ define("PAGES", [
|
|||||||
"404" => [
|
"404" => [
|
||||||
"title" => "404 error"
|
"title" => "404 error"
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
133
pages/groups.php
Normal file
133
pages/groups.php
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
<?php
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../required.php';
|
||||||
|
|
||||||
|
redirectifnotloggedin();
|
||||||
|
|
||||||
|
|
||||||
|
$groupselected = false;
|
||||||
|
$user = "";
|
||||||
|
$users = [];
|
||||||
|
if ($VARS['gid'] && $database->has('groups', ['groupid' => $VARS['gid']])) {
|
||||||
|
$gid = $VARS['gid'];
|
||||||
|
$users = $database->select('assigned_groups', ["[>]accounts" => ["uid" => "uid"]], 'username', ['groupid' => $gid]);
|
||||||
|
$groupselected = true;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<div class="panel panel-brown">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<i class="fa fa-object-group"></i> <?php lang("group management"); ?>
|
||||||
|
</div>
|
||||||
|
<div class="row panel-body">
|
||||||
|
<form role="form" action="action.php" method="POST" class="col-xs-12 col-sm-6">
|
||||||
|
<label for="addgroupbox"><i class="fa fa-plus"></i> <?php lang("new group"); ?></label>
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="text" name="group" placeholder="<?php lang("enter group name"); ?>" class="form-control" />
|
||||||
|
<div class="input-group-btn">
|
||||||
|
<button type="submit" class="btn btn-success"><i class="fa fa-plus"></i> <?php lang("add"); ?></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<input type="hidden" name="action" value="addgroup" />
|
||||||
|
<input type="hidden" name="source" value="groups" />
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form role="form" action="action.php" method="POST" class="col-xs-12 col-sm-6">
|
||||||
|
<label for="addgroupbox"><i class="fa fa-trash-o"></i> <?php lang("delete group"); ?></label>
|
||||||
|
<div class="input-group">
|
||||||
|
<select name="gid" class="form-control">
|
||||||
|
<?php
|
||||||
|
$groups = $database->select('groups', ['groupid (id)', 'groupname (name)']);
|
||||||
|
foreach ($groups as $g) {
|
||||||
|
echo '<option value="' . $g['id'] . '">' . $g['name'] . '</option>';
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
<div class="input-group-btn">
|
||||||
|
<button type="submit" class="btn btn-danger"><i class="fa fa-times"></i> <?php lang("delete"); ?></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<input type="hidden" name="action" value="rmgroup" />
|
||||||
|
<input type="hidden" name="source" value="groups" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<hr />
|
||||||
|
<div class="panel panel-brown">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<i class="fa fa-users"></i> <?php lang("group assignments"); ?>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<?php if ($groupselected !== false) { ?>
|
||||||
|
<form role="form" action="action.php" method="POST">
|
||||||
|
<?php } ?>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12 col-md-6">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="group-box"><i class="fa fa-object-group"></i> <?php lang("group"); ?></label><br />
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-8 col-sm-10 col-md-9 col-lg-10">
|
||||||
|
<select <?php if ($groupselected === false) { ?>id="group-box"<?php } ?> class="form-control" value="<?php echo $gid ?>" name="gid" <?php echo ($groupselected !== false ? "readonly" : ""); ?>>
|
||||||
|
<?php
|
||||||
|
$groups = $database->select('groups', ['groupid (id)', 'groupname (name)']);
|
||||||
|
foreach ($groups as $g) {
|
||||||
|
if ($groupselected && $g['id'] == $gid) {
|
||||||
|
echo '<option value="' . $g['id'] . '" selected>' . $g['name'] . '</option>';
|
||||||
|
} else {
|
||||||
|
echo '<option value="' . $g['id'] . '">' . $g['name'] . '</option>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-4 col-sm-2 col-md-3 col-lg-2">
|
||||||
|
<?php if ($groupselected === false) { ?>
|
||||||
|
<button class="btn btn-default" type="button" id="selectgroupbtn"><i class="fa fa-chevron-right"></i> <?php lang("next") ?></button>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
if ($groupselected !== false) {
|
||||||
|
?>
|
||||||
|
<div class="col-xs-12 col-md-6">
|
||||||
|
<label for="people-box"><i class="fa fa-users"></i> <?php lang("users"); ?></label><br />
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-8 col-sm-10 col-md-9 col-lg-10">
|
||||||
|
<input type="text" id="people-box" class="form-control" placeholder="<?php lang("type to add a person") ?>" />
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-4 col-sm-2 col-md-3 col-lg-2">
|
||||||
|
<button class="btn btn-default" type="button" id="addpersonbtn"><i class="fa fa-plus"></i> <?php lang("add") ?></button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="panel" id="peoplelist-panel">
|
||||||
|
<div class="list-group" id="peoplelist">
|
||||||
|
<?php
|
||||||
|
foreach ($users as $user) {
|
||||||
|
?>
|
||||||
|
<div class="list-group-item" data-user="<?php echo $user; ?>">
|
||||||
|
<?php echo $user; ?> <div class="btn btn-danger btn-sm pull-right rmperson"><i class="fa fa-trash-o"></i></div><input type="hidden" name="users[]" value="<?php echo $user; ?>" />
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="hidden" name="action" value="assigngroup" />
|
||||||
|
<input type="hidden" name="source" value="groups" />
|
||||||
|
|
||||||
|
<?php if ($groupselected !== false) { ?>
|
||||||
|
<button type="submit" class="btn btn-success pull-right" id="save-btn"><i class="fa fa-floppy-o"></i> <?php lang("save"); ?></button>
|
||||||
|
</form>
|
||||||
|
<?php } ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
86
static/js/groups.js
Normal file
86
static/js/groups.js
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
function addPerson(p) {
|
||||||
|
p = p.trim();
|
||||||
|
if (p == "") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ($("#peoplelist div[data-user=" + p + "]").length) {
|
||||||
|
$("#peoplelist .list-group-item[data-user=" + p + "]").animate({
|
||||||
|
backgroundColor: "#ff0000",
|
||||||
|
}, 500, "linear", function () {
|
||||||
|
$("#peoplelist .list-group-item[data-user=" + p + "]").animate({
|
||||||
|
backgroundColor: "#ffffff",
|
||||||
|
}, 500);
|
||||||
|
});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$('#peoplelist').append("<div class=\"list-group-item\" data-user=\"" + p + "\">" + p + "<div class=\"btn btn-danger btn-sm pull-right rmperson\"><i class=\"fa fa-trash-o\"></i></div><input type=\"hidden\" name=\"users[]\" value=\"" + p + "\" /></div>");
|
||||||
|
$("#people-box").val("");
|
||||||
|
}
|
||||||
|
|
||||||
|
function removePerson(p) {
|
||||||
|
$("#peoplelist div[data-user=" + p + "]").remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
var options = {
|
||||||
|
url: "action.php",
|
||||||
|
ajaxSettings: {
|
||||||
|
dataType: "json",
|
||||||
|
method: "GET",
|
||||||
|
data: {
|
||||||
|
action: "autocomplete_user"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
preparePostData: function (data) {
|
||||||
|
data.q = $("#people-box").val();
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
getValue: function (element) {
|
||||||
|
return element.username;
|
||||||
|
},
|
||||||
|
template: {
|
||||||
|
type: "custom",
|
||||||
|
method: function (value, item) {
|
||||||
|
return item.name + " <i class=\"small\">" + item.username + "</i>";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
list: {
|
||||||
|
onClickEvent: function () {
|
||||||
|
var value = $("#people-box").getSelectedItemData().username;
|
||||||
|
addPerson(value);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
requestDelay: 500
|
||||||
|
};
|
||||||
|
|
||||||
|
$("#people-box").easyAutocomplete(options);
|
||||||
|
|
||||||
|
|
||||||
|
$("#selectgroupbtn").click(function () {
|
||||||
|
document.location.href = "app.php?page=groups&gid=" + $("#group-box").val();
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#people-box").keyup(function (event) {
|
||||||
|
if (event.keyCode == 13) {
|
||||||
|
$("#addpersonbtn").click();
|
||||||
|
event.preventDefault();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$("#people-box").keydown(function (event) {
|
||||||
|
if (event.keyCode == 13) {
|
||||||
|
event.preventDefault();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#addpersonbtn").click(function () {
|
||||||
|
addPerson($("#people-box").val());
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#peoplelist').on("click", ".rmperson", function () {
|
||||||
|
removePerson($(this).parent().data("user"));
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user