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
profile.php
129 lines ASCII Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
<?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";
if (!$_SESSION['quizExtended']['loggedIn']) {
header("Location:login.php");
}
// default is logged in user
$displayname = $_SESSION['quizExtended']['displayname'];
$username = $_SESSION['quizExtended']['username'];
$userId = $_SESSION['quizExtended']['userId'];
$self = true;
if (isset($_GET['user'])) {
$requestedUserId = $_GET['user'];
$sql = "SELECT * FROM quizext_users WHERE user_id=?";
$stmt = $dbconn->prepare($sql);
$stmt->execute([$requestedUserId]);
$requestedUsers = $stmt->fetch(PDO::FETCH_ASSOC);
// if user id matches a user, that user's quizzes are shown instead
if (!empty($requestedUsers)) {
$displayname = $requestedUsers['displayname'];
$username = $requestedUsers['username'];
$userId = (int) $requestedUsers['user_id'];
$self = false;
}
}
// retrieves quizzes where user is the creator
$sql = "SELECT * FROM quizext_quizzes WHERE creator_user_id=?";
$stmt = $dbconn->prepare($sql);
$stmt->execute([$userId]);
$myQuizzes = $stmt->fetchAll(PDO::FETCH_ASSOC);
// retrieves results by user
$sql = "
SELECT
result_id,
quizext_quizzes.quiz_name,
user_points,
max_points
FROM quizext_results
INNER JOIN quizext_quizzes ON quizext_results.quiz_id = quizext_quizzes.quiz_id
WHERE user_id=? ORDER BY result_id DESC";
$stmt = $dbconn->prepare($sql);
$stmt->execute([$userId]);
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<title><?= $displayname ?> - CuriousQuizzes</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<meta charset="utf-8">
</head>
<body>
<a href="index.php" id="logo">
CuriousQuizzes
</a>
<main>
<header id="profileHeader">
<img id="profileImage" src="resources/profile.png">
<p id="profileDisplayname"><?= $displayname ?></p>
<p id="profileUsername"><?= $username ?></p>
</header>
<h4><?= $self ? "My" : $displayname . "'s" ?> quizzes</h4>
<table>
<tr>
<th>Quiz Name</th>
<th>Question count</th>
<th>Link</th>
</tr>
<?php
foreach ($myQuizzes as $quizInfo) {?>
<tr>
<td><?= $quizInfo['quiz_name'] ?></td>
<td><?= $quizInfo['nr_of_questions'] ?> questions</td>
<td><a href="quizzes.php?q=<?= $quizInfo['quiz_id'] ?>">run quiz</a></td>
</tr>
<?php }
if (count($myQuizzes) < 1) { ?>
<td colspan="3">No quizzes to show</td><?php
} ?>
</table>
<h4>Detailed results</h4>
<table>
<tr>
<th>Quiz name</th>
<th>Points</th>
<th>Details</th>
</tr>
<?php
foreach ($results as $resultInfo) { ?>
<tr>
<td><?= $resultInfo['quiz_name'] ?></td>
<td><?= $resultInfo['user_points'] ?> (of <?= $resultInfo['max_points'] ?>)</td>
<td><a href="result.php?r=<?= $resultInfo['result_id'] ?>">details</a></td>
</tr>
<?php }
if (count($results) < 1) { ?>
<td colspan="3">No results to show</td><?php
} ?>
</table>
</main>
</body>
</html>