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
admin.php
144 lines ASCII Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
<?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";
if (!$_SESSION['quizExtended']['loggedIn']) {
header("Location:login.php");
}
if (!$_SESSION['quizExtended']['admin']) {
header("Location:index.php");
}
include "dbconnection.php";
if (isset($_POST['deleteQuiz'])) {
$deleteQuizId = (int) $_POST['deleteQuiz'];
// delete specified quiz as well as questions and options of that quiz
$tables = ["quizext_quizzes", "quizext_questions", "quizext_options"];
foreach ($tables as $tableName) {
$sql = "DELETE FROM {$tableName} WHERE quiz_id=?";
$stmt = $dbconn->prepare($sql);
$stmt->execute([$deleteQuizId]);
}
}
if (isset($_POST['deleteUser'])) {
$deleteUserId = (int) $_POST['deleteUser'];
// delete specified user
$sql = "DELETE FROM quizext_users WHERE user_id=?";
$stmt = $dbconn->prepare($sql);
$stmt->execute([$deleteUserId]);
}
// select all quizzes for showing in table
$sql = "SELECT * FROM quizext_quizzes";
$stmt = $dbconn->prepare($sql);
$stmt->execute();
$quizzes = $stmt->fetchAll(PDO::FETCH_ASSOC);
// select all users
$sql = "SELECT user_id, displayname, username, user_level FROM quizext_users";
$stmt = $dbconn->prepare($sql);
$stmt->execute();
$users = $stmt->fetchAll(PDO::FETCH_ASSOC | PDO::FETCH_UNIQUE);
?>
<!DOCTYPE html>
<html lang="sv">
<head>
<title>Administration</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>
<h1>Administration</h1>
<?php
if (isset($quizId)) { ?>
<h4>Successfully deleted quiz! (ID: <?= $quizId ?>)</h4><?php
} ?>
<main class="wideMain">
<table>
<tr>
<th>Quiz Name</th>
<th>Creator</th>
<th>Question count</th>
<th>Link</th>
<th>Delete</th>
</tr>
<?php
foreach ($quizzes as $quizInfo) {?>
<tr>
<td><?= $quizInfo['quiz_name'] ?></td>
<td><?php
if (isset($users[$quizInfo['creator_user_id']])) {
$userId = $quizInfo['creator_user_id'];
echo "<a class='user' href='profile.php?user={$userId}'>{$users[$userId]['displayname']}</a>";
} else {
echo "<span class='cursive'>deleted user</span>";
}
?></td>
<td><?= $quizInfo['nr_of_questions'] ?> questions</td>
<td><a href="quizzes.php?q=<?= $quizInfo['quiz_id'] ?>">run quiz</a></td>
<td class="centerCell">
<form method="post" action="">
<input type="hidden" name="deleteQuiz" value="<?= $quizInfo['quiz_id'] ?>">
<input type="submit" name="deleteQuizSubmit" value="delete">
</form>
</td>
</tr>
<?php }
if (count($quizzes) < 1) { ?>
<td colspan="5">No quizzes to show</td><?php
} ?>
</table>
<table>
<tr>
<th>Display name</th>
<th>Username</th>
<th>User level</th>
<th>Delete</th>
</tr>
<?php
foreach ($users as $userId => $user) {?>
<tr>
<td><?= $user['displayname'] ?></td>
<td><?= $user['username'] ?></td>
<td><?= $user['user_level'] ?></td>
<td class="centerCell">
<form method="post" action="">
<input type="hidden" name="deleteUser" value="<?= $userId ?>">
<input type="submit" name="deleteUserSubmit" value="delete">
</form>
</td>
</tr>
<?php }
if (count($quizzes) < 1) { ?>
<td colspan="4">No quizzes to show</td><?php
} ?>
</table>
</main>
</body>
</html>