diff --git a/game_manager_frame.php b/game_manager_frame.php index e990caf..37c4a8e 100644 --- a/game_manager_frame.php +++ b/game_manager_frame.php @@ -100,6 +100,14 @@ if (!get_autologin_state() || (($user_data["privilege"] !== PRIVILEGE_CREATOR) & + + + Eredmények: + + + + + @@ -110,6 +118,15 @@ if (!get_autologin_state() || (($user_data["privilege"] !== PRIVILEGE_CREATOR) & +
+
+
+ +
+ +
+
+ diff --git a/interface.php b/interface.php index 4b6a4c2..1a5521a 100644 --- a/interface.php +++ b/interface.php @@ -47,6 +47,7 @@ if ((session_status() != PHP_SESSION_ACTIVE) || (!isset($_SESSION["nickname"])) $user_data = get_user($_SESSION["nickname"]); $nickname = $user_data["nickname"]; $privilege = $user_data["privilege"]; +$is_quizmaster = $privilege === QUIZMASTER_NICKNAME; // login-requiring actions switch ($action) { @@ -160,7 +161,7 @@ if (($privilege !== PRIVILEGE_CREATOR) && ($privilege !== PRIVILEGE_QUIZMASTER)) goto print_result; } -$requester_nickname = ($privilege === PRIVILEGE_QUIZMASTER) ? "*" : $nickname; // "*" means every game +$requester_nickname = $is_quizmaster ? "*" : $nickname; // "*" means every game switch ($action) { case "create_game": @@ -184,7 +185,7 @@ switch ($action) { // remove group ID's this user cannot edit $groupids_with_editor_access = []; foreach ($groupids as $groupid) { - if (is_user_editor_to_group($groupid, $nickname) || ($privilege === PRIVILEGE_QUIZMASTER)) { + if (is_user_editor_to_group($groupid, $nickname) || $is_quizmaster) { $groupids_with_editor_access[] = $groupid; } } @@ -192,7 +193,7 @@ switch ($action) { // create or update if (!$update) { create_game($name, $owner, $description); - } else if (is_user_contributor_to_game($gameid, $nickname) || ($privilege === PRIVILEGE_QUIZMASTER)) { + } else if (is_user_contributor_to_game($gameid, $nickname) || $is_quizmaster) { $game_data = get_game($gameid); if (count($game_data) !== 0) { // group management @@ -271,7 +272,7 @@ switch ($action) { { $gameid = ($_REQUEST["gameid"] ?: ""); $game_data = get_game($gameid); - if ((count($game_data) > 0) && (($requester_nickname === "*") || (is_user_contributor_to_game($gameid, $requester_nickname)))) { + if ((count($game_data) > 0) && ($is_quizmaster || (is_user_contributor_to_game($gameid, $requester_nickname)))) { $result = file_get_contents(get_game_file_by_gameid($gameid)); } } @@ -299,6 +300,14 @@ switch ($action) { } } break; + case "get_results_by_gameid": + { + $gameid = trim($_REQUEST["gameid"] ?: ""); + if (($gameid !== "") && (is_user_contributor_to_game($gameid, $nickname) || $is_quizmaster)) { + $result = json_encode(get_results_by_gameid($gameid)); + } + } + break; } // quizmaster actions diff --git a/js/gamemgr.js b/js/gamemgr.js index d02b835..c7ffa61 100644 --- a/js/gamemgr.js +++ b/js/gamemgr.js @@ -211,6 +211,54 @@ function edit_challenges(game) { }); } +function list_results_by_game(game) { + let req = {action: "get_results_by_gameid", gameid: game["_id"]}; + request(req).then(resp => { + let rd = document.getElementById("results_display"); + let results = JSON.parse(resp); + if (results.length === 0) { + return; + } + + rd.innerHTML = ""; + let n = results.length; + + results.sort((a, b) => { + return Number(b["testid"]) - Number(a["testid"]) + }); // sort records by ID + + results.forEach((record) => { + console.log(record); + + let test_summary_record = document.createElement("section"); + test_summary_record.classList.add("test-summary-record"); + + let sequence_number_sec = document.createElement("section"); + sequence_number_sec.classList.add("summary-name-id-block"); + sequence_number_sec.innerText = record["nickname"] + "#" + n; + let duration_sec = document.createElement("section"); + duration_sec.classList.add("summary-duration"); + let start_time = unix_time_to_human_readable(record["start_time"]); + let end_time = unix_time_to_human_readable(record["end_time"]); + + let summary = record["summary"]; + duration_sec.innerHTML = `${start_time}-
${end_time}
${summary["correct_answer_n"]}/${summary["challenge_n"]}`; + + let percentage = document.createElement("section"); + percentage.classList.add("summary-percentage"); + let r = Math.floor((summary["correct_answer_n"] / summary["challenge_n"]) * 100); + percentage.innerHTML = `${r}%`; + + test_summary_record.append(sequence_number_sec, duration_sec, percentage); + rd.appendChild(test_summary_record); + + n--; + + }); + show("results_viewer_window"); + }); +} + // function hint_all_groups(target_element_id) { // const hintbox_insert_fn = (record) => { // let targetF = document.getElementById(target_element_id); diff --git a/main.php b/main.php index b7e4790..66a72a6 100644 --- a/main.php +++ b/main.php @@ -35,6 +35,9 @@ $privilege = $user_data["privilege"];
+ +
+
diff --git a/style/quizmaster_area.css b/style/quizmaster_area.css index c262dd1..84a62bd 100644 --- a/style/quizmaster_area.css +++ b/style/quizmaster_area.css @@ -60,4 +60,22 @@ section.window-inner td { section.window-inner tr td:first-of-type { min-width: 10em; text-align: right !important; +} + +.summary-name-id-block { + display: inline-block; + position: relative; + background-color: #176767; + color: whitesmoke; + padding: 0.5em; + height: 3.5em; + top: -1.1em; + box-shadow: 5px 0 #d3e5e5; + min-width: 12em; +} + +.test-summary-record { + min-width: 25em; + height: 3.5em; + overflow: clip; } \ No newline at end of file diff --git a/style/spreadquiz.css b/style/spreadquiz.css index 4e6cd08..838f512 100644 --- a/style/spreadquiz.css +++ b/style/spreadquiz.css @@ -97,7 +97,7 @@ section#user_info { } section#user_info:hover { - height: 5em; + height: 6em; border-width: 0.5em; } @@ -337,7 +337,7 @@ section.test-summary-record { background-color: #176767; color: whitesmoke; padding: 0.5em; - width: 1.5em; + /*width: 1.5em;*/ box-shadow: 5px 0 #d3e5e5; } diff --git a/testmgr.php b/testmgr.php index 8fd7699..6f21673 100644 --- a/testmgr.php +++ b/testmgr.php @@ -179,4 +179,11 @@ function conclude_test(string $testid) { ]; update_test($test_data); +} + +function get_results_by_gameid(string $gameid) : array { + global $testdb; + $fetch_criteria = ["gameid", "=", (int)$gameid]; + $test_data_array = $testdb->findBy($fetch_criteria); + return $test_data_array; } \ No newline at end of file