diff --git a/game_manager_frame.php b/game_manager_frame.php index 3381425..e5dc3e7 100644 --- a/game_manager_frame.php +++ b/game_manager_frame.php @@ -87,7 +87,7 @@ if (!get_autologin_state() || (($user_data["privilege"] !== PRIVILEGE_CREATOR) & - + diff --git a/group_manager_frame.php b/group_manager_frame.php index d71650d..9a95a1f 100644 --- a/group_manager_frame.php +++ b/group_manager_frame.php @@ -56,6 +56,8 @@ if (!get_autologin_state() || ($user_data["privilege"] !== PRIVILEGE_QUIZMASTER) + + diff --git a/groupmgr.php b/groupmgr.php index 729f239..bb467a6 100644 --- a/groupmgr.php +++ b/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; diff --git a/interface.php b/interface.php index a5b87d2..7fc3f24 100644 --- a/interface.php +++ b/interface.php @@ -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 diff --git a/js/gamemgr.js b/js/gamemgr.js index ba09e1d..f53e16d 100644 --- a/js/gamemgr.js +++ b/js/gamemgr.js @@ -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, diff --git a/js/groupmgr.js b/js/groupmgr.js index 892993e..c489886 100644 --- a/js/groupmgr.js +++ b/js/groupmgr.js @@ -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 = () => { diff --git a/usermgr.php b/usermgr.php index 1062229..bf009fa 100644 --- a/usermgr.php +++ b/usermgr.php @@ -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 }