Källkod
Följande filer och mappar finns under mappen webbserverprogrammering.
Mappar visas till vänster och filer till höger. Klicka på en fil eller mapp för att öppna nedan eller visa dess innehåll.
webbserverprogrammering/projects/quiz-extended/
26 filer
admin.php
confirm_account.php
create_account.php
create_quiz.php
css/
dbconnection.php
highscore.php
index.php
js/
logbook.php
login.php
mysql_create_table_options.php
mysql_create_table_questions.php
mysql_create_table_quizzes.php
mysql_create_table_results.php
mysql_create_table_submits.php
mysql_create_table_users.php
plan.php
planering.txt
profile.php
projektrapport.txt
quizzes.php
resources/
result.php
send_email.php
session_variable_array_check.php
confirm_account.php
create_account.php
create_quiz.php
css/
dbconnection.php
highscore.php
index.php
js/
logbook.php
login.php
mysql_create_table_options.php
mysql_create_table_questions.php
mysql_create_table_quizzes.php
mysql_create_table_results.php
mysql_create_table_submits.php
mysql_create_table_users.php
plan.php
planering.txt
profile.php
projektrapport.txt
quizzes.php
resources/
result.php
send_email.php
session_variable_array_check.php
quizzes.php
164 lines ASCII Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
<?php
error_reporting(-1); // Report all type of errors
ini_set('display_errors', 1); // Display all errors
ini_set('output_buffering', 0); // Do not buffer outputs, write directly
function dump($dump) {
echo "<pre>";
var_dump($dump);
echo "</pre>";
}
session_start();
include "session_variable_array_check.php";
include "dbconnection.php";
$sql = "SELECT * FROM quizext_quizzes";
$stmt = $dbconn->prepare($sql);
$stmt->execute();
$quizzes = $stmt->fetchAll(PDO::FETCH_UNIQUE | PDO::FETCH_ASSOC);
$sql = "SELECT user_id, displayname, username FROM quizext_users";
$stmt = $dbconn->prepare($sql);
$stmt->execute();
$users = $stmt->fetchAll(PDO::FETCH_UNIQUE | PDO::FETCH_ASSOC);
if (isset($_GET['q'])) {
$playingQuiz = true;
$quizId = $_GET['q'];
} else {
$playingQuiz = false;
}
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<title>Quizzes - CuriousQuizzes</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<a href="index.php" id="logo">
CuriousQuizzes
</a>
<?php
if ($playingQuiz) {
if (!isset($quizzes[$quizId])) { ?>
<h1>Invalid quiz ID - broken link</h1>
<main>
<a href="quizzes.php">return to quiz list</a>
<?php
} else {
$quizId = (int) $quizId;
if (isset($users[$quizzes[$quizId]['creator_user_id']])) {
$userId = $quizzes[$quizId]['creator_user_id'];
$displayname = "<a class='user' href='profile.php?user={$userId}'>{$users[$userId]['displayname']}</a>";
} else {
$displayname = "<span class='cursive'>deleted user</span>";
}
?>
<h1>Quiz: <?= $quizzes[$quizId]['quiz_name'] ?></h1>
<h3 class="subtitle">by <?= $displayname ?></h3>
<main>
<?php
if (!$_SESSION['quizExtended']['loggedIn']) { ?>
<p>Log in to save your results!</p>
<?php } ?>
<a href="quizzes.php">return to quiz list</a>
<form method="post" action="result.php">
<br>Mark the <strong>correct</strong> options using the radio buttons.<br><br>
<?php
$sql = "SELECT * FROM quizext_questions WHERE quiz_id=?";
$stmt = $dbconn->prepare($sql);
$stmt->execute([$quizId]);
$questions = $stmt->fetchAll(PDO::FETCH_ASSOC);
// unnecessary classes, should be removed but can't be bothered
foreach ($questions as $questionInfo) { ?>
<div class="questionContainer">
<h4>Question <?= $questionInfo['question_nr'] ?></h4>
<p class="question"><?= $questionInfo['question_txt'] ?></p>
<div class="optionsContainer">
<?php
$sql = "SELECT * FROM quizext_options WHERE question_id=?";
$stmt = $dbconn->prepare($sql);
$stmt->execute([$questionInfo['question_id']]);
$options = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($options as $optionInfo) { ?>
<div class="option">
<input type="radio" name="<?= $questionInfo['question_id'] ?>" value="<?= $optionInfo['option_id'] ?>" required>
<?= $optionInfo['option_txt'] ?>
</div>
<?php } ?>
</div>
</div>
<?php } ?>
<input type="hidden" name="quizId" value="<?= $quizId ?>">
<input type="submit" name="submitQuiz" value="Submit quiz">
</form>
<?php
}
} else {
?>
<h1>Play quizzes</h1>
<main>
<?php
if (!$_SESSION['quizExtended']['loggedIn']) { ?>
<p>Log in to save your results!</p>
<?php } ?>
<table>
<tr>
<th>Quiz Name</th>
<th>Creator</th>
<th>Question count</th>
<th>Link</th>
<th>Highscore</th>
</tr>
<?php
foreach ($quizzes as $id => $quizInfo) {
// if user has been deleted, print "deleted user"
if (isset($users[$quizInfo['creator_user_id']])) {
$userId = $quizInfo['creator_user_id'];
$displayname = "<a class='user' href='profile.php?user={$userId}'>{$users[$userId]['displayname']}</a>";
} else {
$displayname = "<span class='cursive'>deleted user</span>";
}
?>
<tr>
<td><?= $quizInfo['quiz_name'] ?></td>
<td><?= $displayname ?></td>
<td><?= $quizInfo['nr_of_questions'] ?> questions</td>
<td><a href="?q=<?= $id ?>">run quiz</a></td>
<td><a href="highscore.php?q=<?= $id ?>">highscore</a></td>
</tr>
<?php }
if (count($quizzes) < 1) { ?>
<td colspan="5">No quizzes to show</td><?php
} ?>
</table>
<?php
}
?>
</main>
</body>
</html>