diff --git a/action.php b/action.php index b473d05..2dee2a3 100644 --- a/action.php +++ b/action.php @@ -165,7 +165,7 @@ switch ($VARS['action']) { if (!$database->has('permissions', ['permcode' => $perm])) { returnToSender("permission_not_exists", htmlentities($perm)); } - + $permid = $database->get('permissions', 'permid', ['permcode' => $perm]); $permids[] = $permid; $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]); 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": require_once __DIR__ . "/lib/reports.php"; generateReport($VARS['type'], $VARS['format']); diff --git a/lang/en_us.php b/lang/en_us.php index b834ba2..b06c3b0 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -116,5 +116,21 @@ define("STRINGS", [ "permissions assigned" => "Permissions assigned.", "type to select a user" => "Type to select a user", "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", ]); \ No newline at end of file diff --git a/lang/messages.php b/lang/messages.php index 95030b4..1ec171f 100644 --- a/lang/messages.php +++ b/lang/messages.php @@ -74,4 +74,24 @@ define("MESSAGES", [ "string" => "manager does not exist", "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" + ], ]); diff --git a/pages.php b/pages.php index b30f118..7e2c125 100644 --- a/pages.php +++ b/pages.php @@ -36,6 +36,18 @@ define("PAGES", [ "title" => "delete user", "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" => [ "title" => "security log", "navbar" => true, @@ -88,4 +100,4 @@ define("PAGES", [ "404" => [ "title" => "404 error" ] -]); \ No newline at end of file +]); diff --git a/pages/groups.php b/pages/groups.php new file mode 100644 index 0000000..d7ae7ae --- /dev/null +++ b/pages/groups.php @@ -0,0 +1,133 @@ +has('groups', ['groupid' => $VARS['gid']])) { + $gid = $VARS['gid']; + $users = $database->select('assigned_groups', ["[>]accounts" => ["uid" => "uid"]], 'username', ['groupid' => $gid]); + $groupselected = true; +} +?> +
+
+ +
+
+
+ +
+ " class="form-control" /> +
+ +
+
+ + +
+ +
+ +
+ +
+ +
+
+ + +
+
+
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+
+ +
+
+ + + +
+
+
+
+ +
+
+
+
+ " /> +
+
+ +
+
+
+
+ +
+
+
+ +
+
+
+ +
+ + + + + + +
+ +
+
\ No newline at end of file diff --git a/static/js/groups.js b/static/js/groups.js new file mode 100644 index 0000000..cc61254 --- /dev/null +++ b/static/js/groups.js @@ -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("
" + p + "
"); + $("#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 + " " + item.username + ""; + } + }, + 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")); +}); \ No newline at end of file