scoreStart

This commit is contained in:
Yarcio 2025-06-03 19:33:57 +02:00
parent 68e5c48831
commit b140f84fd4
4 changed files with 43 additions and 4 deletions

View file

@ -13,7 +13,8 @@ include $_SERVER["DOCUMENT_ROOT"] . "/php/pages.php";
</head>
<body>
<h1>Witaj<i><?php if (isset($_SESSION["username"])) echo " ".$_SESSION["username"];?> </i>na quiz.czem.eu</h1>
<h1>Witaj<i><?php if (isset($_SESSION["username"]))
echo " " . $_SESSION["username"]; ?> </i>na quiz.czem.eu</h1>
<div class="wrap">
<main>
<h2>Wybierz typ quizu</h2>
@ -38,7 +39,7 @@ include $_SERVER["DOCUMENT_ROOT"] . "/php/pages.php";
<main>
<h2>Inne</h2>
<article>
<div onclick="window.location.href = '/'">
<div onclick="window.location.href = '/score/'">
<h3>Twoje wyniki</h3>
</div>
<div onclick="window.location.href = '/'">

31
score/index.php Normal file
View file

@ -0,0 +1,31 @@
<?php
include $_SERVER["DOCUMENT_ROOT"] . "/php/pages.php";
?>
<!DOCTYPE html>
<html lang="pl-PL">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>quiz.czem.eu</title>
<link rel="stylesheet" href="/styles/main.css">
<link rel="stylesheet" href="score.css">
</head>
<body>
<h1>Twoje wyniki na testy i pytania</h1>
<div class="wrap">
<main>
<h3>Przejdź do zapisanych wyników</h3>
<div onclick="window.location.href = 'tests/'">
<h3>Zapisane Testy</h3>
</div>
<div onclick="window.location.href = 'questions/'">
<h3>Pojedyńcze pytania</h3>
</div>
<h3><a href="/">Wróć do strony głównej</a></h3>
</main>
</div>
</body>
</html>

0
score/score.css Normal file
View file

View file

@ -43,6 +43,7 @@ document.addEventListener("DOMContentLoaded", function () {
if (logged && !own) contentHTML += `<span style="visibility: hidden;" id="rank">Zapisać w rankingu? <input type="checkbox" name="rank"/></span>`;
contentHTML += `</p>
<input type="submit" value="Zakończ Test"/></div>
<p id="info"></p>
<p><a href="/">Wróc do strony głównej</a></p>
</form>`;
mainContent.innerHTML = contentHTML;
@ -71,13 +72,14 @@ document.addEventListener("DOMContentLoaded", function () {
if (result.status == "OK") {
window.scrollTo({ top: 0, behavior: 'smooth' });
Object.entries(result.answers).forEach(function ([key, arr]) {
if (!arr.correct && arr.answeredChar != "-") {
let correctLetter = ["A", "B", "C", "D"].includes(arr.answeredChar);
if (!arr.correct && correctLetter) {
document.getElementById(`q${key}`).innerHTML = `Nieprawidłowa odpowiedź, odpowiedziałeś ${arr.answeredChar}, prawidłowa odpowiedź to ${arr.correctChar}`;
document.getElementById(`q${key}`).style.color = "red";
document.getElementById(`${arr.answeredChar}${key}`).style.color = "red";
document.getElementById(`${arr.correctChar}${key}`).style.color = "green";
}
else if (arr.answeredChar == "-") {
else if (!correctLetter) {
document.getElementById(`q${key}`).innerHTML = `Nie odpowiedziałeś na pytanie, prawidłowa odpowiedź to ${arr.correctChar}`;
document.getElementById(`q${key}`).style.color = "red";
document.getElementById(`${arr.correctChar}${key}`).style.color = "green";
@ -88,6 +90,11 @@ document.addEventListener("DOMContentLoaded", function () {
}
});
const output = document.getElementById("info");
resultProcent = result.correctAnswers/result.testLength*100
output.innerHTML = `Prawidłowe odpowiedzi: ${result.correctAnswers}/${result.testLength} - ${resultProcent}%`;
if (resultProcent >= 50) output.style.color = "green";
output.style.display = "block";
document.getElementById("end").style.display = "none";
} else alert("Wystąpił błąd, spróbuj ponownie");
});