Show sourcecode
The following files exists in this folder. Click to view.
css/
dashboard.php
inc/
index.php
js/
login.php
logout.php
profile.php
quizzes.php
register.php
results.php
results.php
81 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
<?php
/* =========================
Inkludera konfiguration,
databas och login
========================= */
include("inc/config.php");
include("inc/connect_db.php");
include("inc/db_manager.php");
$mode = "strict";
include("inc/login_check.php");
/* =========================
Hämta försök baserat på ID
========================= */
$attempt_id = $_GET['id'] ?? null;
$attempt = getAttempt($conn, "id", $attempt_id);
// Kontrollera att användaren får se resultatet
if (!$attempt || ($attempt['user_id'] !== $id && !$user['admin'])) {
header("Location: index.php");
exit();
}
/* =========================
Hämta quiz och frågor
========================= */
$quiz = getQuiz($conn, "id", $attempt['quiz_id']);
$questions = getQuestions($conn, "quiz_id", $quiz['id']);
/* =========================
Sidtitel
========================= */
$page_title = $quiz['title'] . " - Resultat - Quizzeria";
?>
<!DOCTYPE html>
<html lang="sv">
<?php include("inc/head.php"); ?>
<body>
<?php include("inc/header.php"); ?>
<h1 class="quiz_title"><?php echo htmlspecialchars($quiz['title']); ?></h1>
<p class="quiz_points_eval"><i>Du fick totalt <b><?php echo $attempt['score']; ?></b> poäng</i></p>
<p class="quiz_desc"><?php echo htmlspecialchars($quiz['description']); ?></p>
<?php
/* =========================
Visa resultat per fråga
========================= */
foreach ($questions as $question):
$choices = getChoices($conn, "question_id", $question['id']);
$answer = getAnswer($conn, "question_id", $question['id'], $attempt_id);
$selected_choice = getChoice($conn, "id", $answer['choice_id']);
$is_correct = $selected_choice['is_correct'] == 1;
?>
<div class="question_result <?php echo $is_correct ? 'correct' : 'wrong'; ?>">
<h3><?php echo htmlspecialchars($question['text']); ?></h3>
<?php foreach ($choices as $choice):
$color = $choice['is_correct'] ? 'green' : ($choice['id'] == $answer['choice_id'] ? 'red' : 'black');
?>
<label style="color: <?php echo $color; ?>;">
<input type="radio"
name="q<?php echo $question['id']; ?>"
value="<?php echo $choice['id']; ?>"
<?php echo $choice['id'] == $answer['choice_id'] ? 'checked' : ''; ?>
disabled>
<?php echo htmlspecialchars($choice['text']); ?>
</label>
<?php endforeach; ?>
<p>Du fick <b><?php echo $is_correct ? $question['points'] : 0; ?></b> poäng</p>
</div>
<?php endforeach; ?>
<?php include("inc/footer.php"); ?>
</body>
</html>