Webbserver - Love Blomberg

Show sourcecode

The following files exists in this folder. Click to view.

public_html/exercises/quizproject/

admin/
createtable.php
dbconnection.php
icons/
index.php
login.php
logout.php
quiz/
quiz_styles.css
register.php

index.php

85 lines UTF-8 Windows (CRLF)
<?php
session_start
();

// Auth så att användare är inloggad och/eller admin
$loggedIn = isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == 1;
$isAdmin = isset($_SESSION['is_admin']) && $_SESSION['is_admin'] == 1;
// Hämta namn från session, annars Guest
$name $loggedIn && isset($_SESSION['name']) ? htmlspecialchars($_SESSION['name']) : 'Guest';
?>

<!DOCTYPE html>
<html lang="en">

<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Quizzer | Dashboard</title>
 <link rel="stylesheet" href="quiz_styles.css">
 <link rel="shortcut icon" href="./icons/home-icon.svg" type="image/x-icon">
</head>

<body>
 <div class="page">
  <?php if ($loggedIn): ?>
  <div class="page-header">
   <div>
    <h1 class="page-title">Quizzer Dashboard</h1>
    <p class="page-subtitle">Welcome <?= $name?>. Create and manage your quizzes here.</p>
   </div>
   <div class="actions">
    <a class="btn btn-ghost" href="logout.php">Log out</a>
   </div>
  </div>
  <?php endif; ?>

  <?php
      
if (!$loggedIn || $loggedIn != 1) {
    
$url "https://example.com";
    
header('Location: '."./login.php");
    die();
      }
  
?>
  <div class="card">
   <h2>Quizzes</h2>
   <p class="meta">Create and view quizzes or take existing ones.</p>
   <div class="actions">
    <a class="btn" href="quiz/createquiz.php"><svg xmlns="http://www.w3.org/2000/svg" height="24px"
      viewBox="0 -960 960 960" width="24px" fill="#e3e3e3">
      <path d="M440-440H200v-80h240v-240h80v240h240v80H520v240h-80v-240Z" />
     </svg>Create Quiz</a>
    <a class="btn btn-secondary" href="quiz/viewquizzes.php"><svg xmlns="http://www.w3.org/2000/svg" height="24px"
      viewBox="0 -960 960 960" width="24px" fill="#e3e3e3">
      <path
       d="M320-280q17 0 28.5-11.5T360-320q0-17-11.5-28.5T320-360q-17 0-28.5 11.5T280-320q0 17 11.5 28.5T320-280Zm0-160q17 0 28.5-11.5T360-480q0-17-11.5-28.5T320-520q-17 0-28.5 11.5T280-480q0 17 11.5 28.5T320-440Zm0-160q17 0 28.5-11.5T360-640q0-17-11.5-28.5T320-680q-17 0-28.5 11.5T280-640q0 17 11.5 28.5T320-600Zm120 320h240v-80H440v80Zm0-160h240v-80H440v80Zm0-160h240v-80H440v80ZM200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm0-560v560-560Z" />
     </svg>Your Quizzes</a>
   </div>
  </div>

  <?php if ($isAdmin): ?>
  <div class="card">
   <h2>Admin Dashboard</h2>
   <p class="meta">Manage user accounts.</p>
   <div class="actions">
    <a class="btn btn-secondary" href="admin/adduser.php"><svg xmlns="http://www.w3.org/2000/svg" height="24px"
      viewBox="0 -960 960 960" width="24px" fill="#e3e3e3">
      <path
       d="M720-400v-120H600v-80h120v-120h80v120h120v80H800v120h-80Zm-360-80q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 66-47 113t-113 47ZM40-160v-112q0-34 17.5-62.5T104-378q62-31 126-46.5T360-440q66 0 130 15.5T616-378q29 15 46.5 43.5T680-272v112H40Zm80-80h480v-32q0-11-5.5-20T580-306q-54-27-109-40.5T360-360q-56 0-111 13.5T140-306q-9 5-14.5 14t-5.5 20v32Zm240-320q33 0 56.5-23.5T440-640q0-33-23.5-56.5T360-720q-33 0-56.5 23.5T280-640q0 33 23.5 56.5T360-560Zm0-80Zm0 400Z" />
     </svg>Add User</a>
    <a class="btn btn-secondary" href="admin/edituser.php"><svg xmlns="http://www.w3.org/2000/svg" height="24px"
      viewBox="0 -960 960 960" width="24px" fill="#e3e3e3">
      <path
       d="M480-240Zm-320 80v-112q0-34 17.5-62.5T224-378q62-31 126-46.5T480-440q37 0 73 4.5t72 14.5l-67 68q-20-3-39-5t-39-2q-56 0-111 13.5T260-306q-9 5-14.5 14t-5.5 20v32h240v80H160Zm400 40v-123l221-220q9-9 20-13t22-4q12 0 23 4.5t20 13.5l37 37q8 9 12.5 20t4.5 22q0 11-4 22.5T903-340L683-120H560Zm300-263-37-37 37 37ZM620-180h38l121-122-18-19-19-18-122 121v38Zm141-141-19-18 37 37-18-19ZM480-480q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 66-47 113t-113 47Zm0-80q33 0 56.5-23.5T560-640q0-33-23.5-56.5T480-720q-33 0-56.5 23.5T400-640q0 33 23.5 56.5T480-560Zm0-80Z" />
     </svg>Edit User</a>
    <a class="btn btn-danger" href="admin/deleteuser.php"><svg xmlns="http://www.w3.org/2000/svg" height="24px"
      viewBox="0 -960 960 960" width="24px" fill="#e3e3e3">
      <path
       d="M640-520v-80h240v80H640Zm-280 40q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 66-47 113t-113 47ZM40-160v-112q0-34 17.5-62.5T104-378q62-31 126-46.5T360-440q66 0 130 15.5T616-378q29 15 46.5 43.5T680-272v112H40Zm80-80h480v-32q0-11-5.5-20T580-306q-54-27-109-40.5T360-360q-56 0-111 13.5T140-306q-9 5-14.5 14t-5.5 20v32Zm240-320q33 0 56.5-23.5T440-640q0-33-23.5-56.5T360-720q-33 0-56.5 23.5T280-640q0 33 23.5 56.5T360-560Zm0-80Zm0 400Z" />
     </svg>Delete User</a>
   </div>
  </div>
  <?php endif; ?>
 </div>
</body>

</html>