- ...
This commit is contained in:
parent
b7bca5c6c1
commit
c5dbb9ff87
@ -87,7 +87,7 @@ if (!get_autologin_state() || (($user_data["privilege"] !== PRIVILEGE_CREATOR) &
|
||||
<td><label for="time_limited">Időkorlátos:</label></td>
|
||||
<td>
|
||||
<input type="checkbox" id="time_limited" oninput="handle_time_limit_chkbox()">
|
||||
<input type="time" id="time_limit" step="1">
|
||||
<input type="text" pattern="(([01][0-9])|([2][0-3])):[0-5][0-9]:[0-5][0-9]" id="time_limit">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -56,6 +56,8 @@ if (!get_autologin_state() || ($user_data["privilege"] !== PRIVILEGE_QUIZMASTER)
|
||||
<td><label for="group_owner">Tulajdonos:</label></td>
|
||||
<td><input type="text" id="group_owner"></td>
|
||||
</tr>
|
||||
</table>
|
||||
<table id="group_editor_additional_fields">
|
||||
<tr>
|
||||
<td><label for="group_editors">Szerkesztők:</label></td>
|
||||
<td><input type="text" id="group_editors"></td>
|
||||
|
10
groupmgr.php
10
groupmgr.php
@ -6,12 +6,12 @@ require_once "usermgr.php";
|
||||
|
||||
$groupdb = new \SleekDB\Store(GROUPDB, DATADIR, ["timeout" => false]);
|
||||
|
||||
function create_group(string $groupname, string $owner, string $description = "", array $editors = []): bool
|
||||
function create_group(string $groupname, string $owner, string $description = ""): bool
|
||||
{
|
||||
global $groupdb;
|
||||
|
||||
// test name uniqueness
|
||||
$unique = clear_unique_in_siblings($groupname);
|
||||
$unique = manage_unique_in_siblings(0, $groupname);
|
||||
|
||||
// initialize group data
|
||||
$group_data = [
|
||||
@ -19,7 +19,7 @@ function create_group(string $groupname, string $owner, string $description = ""
|
||||
"unique" => $unique,
|
||||
"owner" => $owner,
|
||||
"description" => $description,
|
||||
"editors" => $editors,
|
||||
"editors" => [],
|
||||
"users" => [],
|
||||
"games" => []
|
||||
];
|
||||
@ -122,11 +122,11 @@ function search_groups(string $needle): array
|
||||
return $results;
|
||||
}
|
||||
|
||||
function clear_unique_in_siblings($groupname): bool
|
||||
function manage_unique_in_siblings(int $current_gid, $groupname): bool
|
||||
{
|
||||
// make test on name uniqueness
|
||||
global $groupdb;
|
||||
$twins = $groupdb->findBy(["groupname", "=", "$groupname"]);
|
||||
$twins = $groupdb->findBy([["groupname", "=", "$groupname"], "AND", ["_id", "!=", $current_gid]]);
|
||||
$unique = count($twins) == 0;
|
||||
if (count($twins) === 1) { // if fails, then also indicate in the original group that its name is no longer unique
|
||||
$twins[0]["unique"] = false;
|
||||
|
@ -268,14 +268,14 @@ switch ($action) {
|
||||
if ($groupname != "") {
|
||||
switch ($action) {
|
||||
case "create_group":
|
||||
create_group($groupname, $owner, $description, $editors);
|
||||
create_group($groupname, $owner, $description);
|
||||
break;
|
||||
case "update_group":
|
||||
{
|
||||
$gid = $_REQUEST["id"];
|
||||
$group = get_group($gid);
|
||||
if (count($group) !== 0) {
|
||||
$group["unique"] = clear_unique_in_siblings($groupname); // manage unique flag in case of renaming
|
||||
$group["unique"] = manage_unique_in_siblings($gid, $groupname); // manage unique flag in case of renaming
|
||||
$group["groupname"] = $groupname;
|
||||
$group["description"] = $description;
|
||||
$group["editors"] = array_intersect($editors, $group["users"]); // a user cannot be an editor if not part of the group
|
||||
|
@ -95,6 +95,10 @@ function create_edit_game(game = null) {
|
||||
|
||||
submit_btn.onclick = () => {
|
||||
let game_name = document.getElementById("game_name").value.trim();
|
||||
if (updating && time_limitedChk.checked && time_limitF.validity.patternMismatch) {
|
||||
alert("Hibás időformátum!")
|
||||
return;
|
||||
}
|
||||
if (game_name !== "") {
|
||||
let reqData = {
|
||||
name: game_name,
|
||||
|
@ -49,6 +49,7 @@ function create_edit_group(group = null) {
|
||||
group_ownerF.readOnly = true;
|
||||
group_editorsF.value = "";
|
||||
group_membersF.value = "";
|
||||
hide("group_editor_additional_fields");
|
||||
} else { // update and existing one
|
||||
groupnameF.value = group["groupname"];
|
||||
group_descriptionF.value = group["description"];
|
||||
@ -57,6 +58,7 @@ function create_edit_group(group = null) {
|
||||
group_ownerF.readOnly = false;
|
||||
group_editorsF.value = group["editors"].join(", ");
|
||||
group_membersF.value = group["users"].join(", ");
|
||||
show("group_editor_additional_fields");
|
||||
}
|
||||
|
||||
submit_btn.onclick = () => {
|
||||
|
@ -9,7 +9,7 @@ const PRIVILEGE_PLAYER = "player";
|
||||
const PRIVILEGE_CREATOR = "creator";
|
||||
const PRIVILEGE_QUIZMASTER = "admin"; // TODO: refactor!
|
||||
|
||||
function add_user(string $nickname, string $password, string $realname, array $groups = [], string $privilege = PRIVILEGE_PLAYER): bool
|
||||
function add_user(string $nickname, string $password, string $realname, array $groupids = [], string $privilege = PRIVILEGE_PLAYER): bool
|
||||
{
|
||||
global $userdb;
|
||||
if (count(get_user($nickname)) != 0) { // user exists
|
||||
@ -20,9 +20,12 @@ function add_user(string $nickname, string $password, string $realname, array $g
|
||||
"nickname" => $nickname,
|
||||
"password" => password_hash($password, PASSWORD_DEFAULT),
|
||||
"realname" => $realname,
|
||||
"groups" => $groups,
|
||||
"groups" => $groupids,
|
||||
"privilege" => $privilege
|
||||
];
|
||||
foreach ($groupids as $groupid) {
|
||||
change_group_user_assignments($groupid, $nickname, null);
|
||||
}
|
||||
$userdb->insert($user_data);
|
||||
return true; // user registration successful
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user