Skip to content

Commit

Permalink
push latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
svenbledt committed Feb 2, 2023
1 parent 96efbc6 commit 8e5834b
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 60 deletions.
2 changes: 1 addition & 1 deletion _pages/error.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<header class="header-2">
<div class="page-header min-vh-75 relative" style="background-image: url('./assets/img/bg2.jpg')">
<div class="page-header min-vh-75 relative" style="background-image: url('./assets/img/bg_main.jpg')">
<span class="mask bg-gradient-primary opacity-4"></span>
<div class="container">
<div class="row">
Expand Down
158 changes: 138 additions & 20 deletions _pages/index.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
<?php

// select all topics
$topics = $conn->query("SELECT topic FROM questions");
$topics = $topics->fetchAll(PDO::FETCH_ASSOC);
$topics = array_unique($topics, SORT_REGULAR);

if (!isset($_SESSION['score'])) {
$_SESSION['score'] = 0;
}
// set default Message
// set topic session

// initialize current question index if not set
if (!isset($_SESSION['current_question'])) {
$_SESSION['current_question'] = 0;
}

?>
<header class="header-2">
<div class="page-header min-vh-75 relative" style="background-image: url('./assets/img/bg2.jpg')">
<div class="page-header min-vh-75 relative" style="background-image: url('./assets/img/bg_main.jpg')">
<span class="mask bg-gradient-primary opacity-4"></span>
<div class="container">
<div class="row">
<div class="col-lg-7 text-center mx-auto">
<h1 class="text-white pt-3 mt-n5">Trivia Quiz</h1>
<p class="lead text-white mt-3">Are you ready for the Ultimate Quiz experience. <br /> Join the fun today. </p>
<p class="lead text-white mt-3">Are you ready for the Ultimate Quiz experience. <br /> Join the fun today.</p>
</div>
</div>
</div>
Expand All @@ -18,35 +37,134 @@
<div class="container mt-sm-5 mt-3">
<div class="row">
<div class="col-lg-3">
<div class="position-sticky pb-lg-5 pb-3 mt-lg-0 mt-5 ps-2" style="top: 100px">
<h3>Category</h3>
<h6 class="text-secondary font-weight-normal pe-3">Please choose the category of the quiz you wanna do!</h6>
</div>
<?php if (!isset($_SESSION['topic'])) { ?>
<div class="position-sticky pb-lg-5 pb-3 mt-lg-0 mt-5 ps-2" style="top: 100px">
<h3>Category</h3>
<h6 class="text-secondary font-weight-normal pe-3">Please choose the category of the quiz you wanna do!</h6>
</div>
<?php } else { ?>
<div class="position-sticky pb-lg-5 pb-3 mt-lg-0 mt-5 ps-2" style="top: 100px">
<h3>Have Fun</h3>
<h6 class="text-secondary font-weight-normal pe-3">Have fun answering the Questions of the quiz!</h6>
</div>
<?php } ?>
</div>
<div class="col-lg-9">
<div class="row mt-3">
<!-- Buttons color -->
<div class="col-12">
<div class="position-relative border-radius-xl overflow-hidden shadow-lg mb-7">
<div class="container border-bottom">
<div class="row justify-space-between py-2">
<div class="col-lg-3 me-auto">
<p class="lead text-dark pt-1 mb-0">// Frage Name</p>
<?php if (!isset($_SESSION['topic']) && isset($_SESSION['LOGGEDIN']) && $_SESSION['LOGGEDIN'] == true) { ?>
<!-- Questions -->
<form action="" method="post">
<div class="col-12">
<div class="position-relative border-radius-xl overflow-hidden shadow-lg mb-7">
<div class="container border-bottom">
<div class="row justify-space-between py-2">
<div class="col-lg-3 me-auto">
<p class="lead text-dark pt-1 mb-0"><?php if(!isset($result)) { echo'Choose your topic'; } else { echo $result;};?></p>
</div>
</div>
</div>
<div class="tab-content tab-space">
<div class="tab-pane active" id="preview-btn-color">
<div class="row text-center py-3 mt-3">
<div class="col-12 mx-auto">
<select name="topic" class="form-select form-select-lg mb-3" aria-label=".form-select-lg example">
<?php foreach ($topics as $topic) { ?>
<option value="<?php echo $topic['topic']; ?>"><?php echo $topic['topic']; ?></option>
<?php } ?>
</select>
<button type="submit" class="btn btn-secondary">Start Quiz</button>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
<?php } else if (isset($_SESSION['topic']) && $logged_in) { ?>
<!-- Questions -->
<div class="col-12">
<div class="position-relative border-radius-xl overflow-hidden shadow-lg mb-7">
<div class="container border-bottom">
<div class="row justify-space-between py-2">
<div class="col-lg-3 me-auto">
<p class="lead text-dark pt-1 mb-0">
<?php echo ucfirst($_SESSION['topic']); ?>
</p>
</div>
</div>
</div>
<div class="tab-content tab-space">
<div class="tab-pane active" id="preview-btn-color">
<div class="row text-center py-3 mt-3">
<div class="col-12 mx-auto">

<?php
if (isset($result)) {
echo '<p class="lead text-dark pt-1 mb-0">' . $result . '</p>';
} else if (isset($_SESSION['current_question'])) {
echo '<p class="lead text-dark pt-1 mb-0">' . $current_question['question_text'] . '</p>';
echo '<form method="post">';
echo '<div class="row text-center py-2 mt-3"><div class="col-3 mx-auto text-start">';
echo '<div class="form-check">';
echo '<input class="form-check-input" type="radio" name="answer" value="1" id="flexRadioDefault1" required>';
echo '<label class="form-check-label" for="flexRadioDefault1">' . $current_question['answer-1'] . '</label>';
echo '</div>';
echo '<div class="form-check">';
echo '<input class="form-check-input" type="radio" name="answer" value="2" id="flexRadioDefault2" required>';
echo '<label class="form-check-label" for="flexRadioDefault2">' . $current_question['answer-2'] . '</label>';
echo '</div>';
echo '<div class="form-check">';
echo '<input class="form-check-input" type="radio" name="answer" value="3" id="flexRadioDefault3" required>';
echo '<label class="form-check-label" for="flexRadioDefault3">' . $current_question['answer-3'] . '</label>';
echo '</div>';
echo '<div class="form-check">';
echo '<input class="form-check-input" type="radio" name="answer" value="4" id="flexRadioDefault4" required>';
echo '<label class="form-check-label" for="flexRadioDefault4">' . $current_question['answer-4'] . '</label>';
echo '</div>';
echo '<div class="form-check">';
echo '<input class="form-check-input" type="radio" name="answer" value="5" id="flexRadioDefault5" required>';
echo '<label class="form-check-label" for="flexRadioDefault5">' . $current_question['answer-5'] . '</label>';
echo '</div>';
echo '<button type="submit" name="next" class="btn btn-primary">Next Question</button>';
echo '<button type="submit" name="back" class="btn btn-primary">Last Question</button>';
echo '</div>';
echo '</div>';
echo '</form>';
}
?>
</div>
</div>
</div>
</div>
</div>
<div class="tab-content tab-space">
<div class="tab-pane active" id="preview-btn-color">
<div class="row text-center py-3 mt-3">
<div class="col-12 mx-auto">
// content here
</div>
<?php } else { ?>
<div class="col-12">
<div class="position-relative border-radius-xl overflow-hidden shadow-lg mb-7">
<div class="container border-bottom">
<div class="row justify-space-between py-2">
<div class="col-lg-3 me-auto">
<p class="lead text-dark pt-1 mb-0">
Not Loggedin
</p>
</div>
</div>
</div>
<div class="tab-content tab-space">
<div class="tab-pane active" id="preview-btn-color">
<div class="row text-center py-3 mt-3">
<div class="col-12 mx-auto">
<p class="lead text-dark pt-1 mb-0">
<?php echo "You need to be logged in to take the quiz!"; ?>
</p>
<a href="index.php?page=sign-in" class="btn btn-primary w-auto me-1 mb-0">Login</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</section>
2 changes: 1 addition & 1 deletion _pages/preset.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<header class="header-2">
<div class="page-header min-vh-75 relative" style="background-image: url('./assets/img/bg2.jpg')">
<div class="page-header min-vh-75 relative" style="background-image: url('./assets/img/bg_main.jpg')">
<span class="mask bg-gradient-primary opacity-4"></span>
<div class="container">
<div class="row">
Expand Down
1 change: 1 addition & 0 deletions _pages/sign-in.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
if ($user) {
if (sha256($_POST['password']) == $user['password_sha256'] && $_POST['email'] == $user['email']) {
login($conn, $_POST['email'], $_POST['password']);
updateUser($conn, $_POST['email']);
$_SESSION['LOGGEDIN'] = true;
$_SESSION['EMAIL'] = $user['email'];
$_SESSION['USERNAME'] = $user['username'];
Expand Down
Binary file added assets/img/bg_main.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 1 addition & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,7 @@ services:
test: mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD
interval: 5s
retries: 10

# PhpMyAdmin Service
phpmyadmin:
image: phpmyadmin/phpmyadmin:5
ports:
- 8080:80
environment:
PMA_HOST: mysql
depends_on:
mysql:
condition: service_healthy


volumes:
db_data:
driver: local
8 changes: 1 addition & 7 deletions inc/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,4 @@
// set the default timezone to use. Available since PHP 5.1
date_default_timezone_set('Europe/Berlin');

if (isset($_SESSION['LOGGEDIN'])) {
$logged_in = true;
} else {
$logged_in = false;
}


$logged_in = $_SESSION['LOGGEDIN']??false;
19 changes: 11 additions & 8 deletions inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@ function login($conn, $email, $password)
} catch (PDOException $e) {
echo $e->getMessage();
}
try {
$sql = "UPDATE users SET last_login, ip = :last_login, :ip WHERE email = :email";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':last_login', getTimestamp(), PDO::PARAM_STR);
$stmt->bindParam(':ip', getrealip(), PDO::PARAM_STR);
} catch (PDOException $e) {
echo $e->getMessage();
}
}

// update last login
function updateUser($conn, $email)
{
$sql = "UPDATE users SET last_login = :last_login, ip = :ip WHERE email = :email";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':last_login', getTimestamp(), PDO::PARAM_STR);
$stmt->bindParam(':ip', getrealip(), PDO::PARAM_STR);
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
$stmt->execute();
}

// logout
Expand Down
Loading

0 comments on commit 8e5834b

Please sign in to comment.