quiz-klapek/score/tests/index.php
2025-06-15 22:04:08 +02:00

75 lines
No EOL
3.6 KiB
PHP

<?php
include $_SERVER["DOCUMENT_ROOT"] . "/php/pages.php";
redirectLogged();
?>
<!DOCTYPE html>
<html lang="pl-PL">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Zapisane testy - quiz.czem.eu</title>
<link rel="stylesheet" href="/styles/main.css">
</head>
<body>
<h1>Zapisane testy</h1>
<div class="wrap">
<main>
<?php
$conn = connectDB();
if (isset($_GET["TID"])) {
$stmt = $conn->prepare("SELECT testLength FROM tests WHERE UID = ? AND TID = ?");
$stmt->bind_param("ii", $_SESSION["UID"], $_GET["TID"]);
$stmt->execute();
$stmt->bind_result($testLength);
if (!$stmt->fetch()) {
exit("ID testu nie zgadza się z ID użytkownika");
}
$stmt->close();
$stmt = $conn->prepare("SELECT QID, answeredChar, correct FROM testanswers WHERE TID = ?");
$stmt->bind_param("i", $_GET["TID"]);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($QID, $answeredChar, $correct);
echo "<table><tr><th>Nr</th><th>Pytanie</th><th>Odpowiedzi</th><th>Twoja odpowiedź</th><th>Prawidłowa?</th><th>Prawidłowa odpowiedź</th></tr>";
$i = 0;
while ($stmt->fetch()) {
$stmtQuestion = $conn->prepare("SELECT content, answerA, answerB, answerC, answerD, answerChar FROM questions WHERE QID = ?");
$stmtQuestion->bind_param("i", $QID);
$stmtQuestion->execute();
$stmtQuestion->bind_result($content, $answerA, $answerB, $answerC, $answerD, $answerChar);
if ($stmtQuestion->fetch()) {
$i++;
$right = $correct ? "tak" : "nie";
echo "<tr><td rowspan='4'>$i/$testLength</td><td rowspan='4'>$content</td><td>A: $answerA</td><td rowspan='4'>$answeredChar</td><td rowspan='4'>$right</td><td rowspan='4'>$answerChar</td></tr>
<tr><td>B: $answerB</td></tr>
<tr><td>C: $answerC</td></tr>
<tr><td>D: $answerD</td></tr>";
}
$stmtQuestion->close();
}
$stmt->close();
echo "</table><h3><a href='../tests/'>Powrót</a></h3>";
} else {
$stmt = $conn->prepare("SELECT TID, rank, correctAnswers, testLength, testTime FROM tests WHERE UID = ?");
$stmt->bind_param("i", $_SESSION["UID"]);
$stmt->bind_result($TID, $rank, $correctAnswers, $testLength, $testTime);
$stmt->execute();
echo "<table><tr><th>Przejdź do opowiedzi na test</th><th>Zapisane w rankingu?</th><th>Poprawne odpowiedzi</th><th>Długość testu</th><th>Wynik testu</th><th>Czas zapisania testu</th></tr>";
while ($stmt->fetch()) {
$rankAns = $rank ? "W rankingu" : "Nie";
$pr = $correctAnswers / $testLength * 100;
echo "<tr><td><input type='button' onclick='window.location.href += `?TID=$TID`' value='Wyświetl'></td><td>$rankAns</td><td>$correctAnswers</td><td>$testLength</td><td>$pr%</td><td>$testTime</td></tr>";
}
$stmt->close();
echo "</table><h3><a href='../'>Powrót</a></h3>";
}
$conn->close();
?>
</main>
</div>
</body>
</html>