401 lines
No EOL
12 KiB
Text
401 lines
No EOL
12 KiB
Text
<?php
|
|
|
|
error_reporting(E_ALL); //Debuging
|
|
require_once 'include/DBConnection.inc.php';
|
|
function autoloader($classname)
|
|
{
|
|
include 'class/' . $classname . '.php';
|
|
}
|
|
spl_autoload_register('autoloader');
|
|
|
|
$session = new Session();
|
|
$db = new Datenbank($dbname, $username, $password, $servername);
|
|
|
|
/*===============================*/
|
|
$nutzername = filter_input(INPUT_POST, "name", FILTER_SANITIZE_STRING);
|
|
$password = filter_input(INPUT_POST, "passwort", FILTER_SANITIZE_NUMBER_INT);
|
|
$check = filter_input(INPUT_POST, "check", FILTER_SANITIZE_STRING);
|
|
|
|
|
|
if ($check) {
|
|
if ($nutzername && $password) {
|
|
if ($db->checkLogin($nutzername, $password)) {
|
|
$session->set("name", $nutzername);
|
|
$session->set("login", 1);
|
|
$session->set("status", "ok");
|
|
$session->set("message", "Erfolgreich eingeloggt!");
|
|
$session->set("site", "index");
|
|
$url = "wahl.php";
|
|
header("Location: $url");
|
|
echo '<script type="text/javascript">';
|
|
echo 'window.location.href="'.$url.'";';
|
|
echo '</script>';
|
|
echo '<noscript>';
|
|
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
|
|
echo '</noscript>'; exit;
|
|
} else {
|
|
$errorMessage = "Logindaten fehlerhaft!";
|
|
}
|
|
} else {
|
|
$errorMessage = ($nutzername || $password) ? "Logindaten fehlerhaft!" : "Logindaten fehlen!";
|
|
}
|
|
}
|
|
|
|
if (isset($_SESSION["status"]) && $session->get("status") == "error") {
|
|
$errorMessage = $session->get("message");
|
|
$session->set("message");
|
|
$session->set("status");
|
|
$session->destroy();
|
|
}
|
|
|
|
if (isset($_SESSION["finished"]) && $session->get("finished")) {
|
|
$message = "Du kannst das Fenster jetzt schließen!";
|
|
$session->destroy();
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Sportwahlen | Login</title>
|
|
<link rel="stylesheet" href="assets/css/main.css">
|
|
</head>
|
|
|
|
<body>
|
|
<?php if (isset($errorMessage) && $errorMessage != ""): ?>
|
|
<div class="modal">
|
|
<div class="message error">
|
|
<!-- Ausgabe einer eventuellen Fehlermeldung -->
|
|
<p><?php echo $errorMessage; ?></p>
|
|
</div>
|
|
</div>
|
|
<?php endif;?>
|
|
<?php if (isset($message) && $message != ""): ?>
|
|
<div class="modal">
|
|
<div class="message sucsses">
|
|
<!-- Ausgabe einer eventuellen Statusmeldung -->
|
|
<p><?php echo $message; ?></p>
|
|
</div>
|
|
</div>
|
|
<?php endif;?>
|
|
<form action="index.php" method="POST">
|
|
<input type="text" name="name" value="">
|
|
<input type="password" name="passwort" value="">
|
|
<input type="hidden" name="check" value="ja">
|
|
<button>Login</button>
|
|
</form>
|
|
<noscript>
|
|
<p>
|
|
JavaScript wird für Annehmlichkeiten verwendet, um diese nutzen zu können, sollten Sie dies auch aktivieren.
|
|
</p>
|
|
</noscript>
|
|
<script src="assets/js/main.js"></script>
|
|
</body>
|
|
|
|
</html>
|
|
----------------------------------------------
|
|
<?php
|
|
|
|
error_reporting(E_ALL); //Debuging
|
|
require_once 'include/DBConnection.inc.php';
|
|
function autoloader($classname)
|
|
{
|
|
include 'class/' . $classname . '.php';
|
|
}
|
|
spl_autoload_register('autoloader');
|
|
|
|
$session = new Session();
|
|
$db = new Datenbank($dbname, $username, $password, $servername);
|
|
|
|
/*===============================*/
|
|
function convertName(string $name) {
|
|
$suchmuster = array('/([A-Za-z]+)\.([A-Za-z]+)/');
|
|
$ersetzungen = array('<span style="text-transform: capitalize;">\1 \2</span>');
|
|
$convertedName = preg_replace($suchmuster, $ersetzungen, $name);
|
|
return $convertedName;
|
|
}
|
|
function convertUmlauteFrom(string $text) {
|
|
$suchmuster = array();
|
|
$suchmuster[0] = '/ae/';
|
|
$suchmuster[1] = '/ue/';
|
|
$suchmuster[2] = '/oe/';
|
|
|
|
$ersetzungen = array();
|
|
$ersetzungen[2] = 'ä';
|
|
$ersetzungen[1] = 'ü';
|
|
$ersetzungen[0] = 'ö';
|
|
|
|
$replacedtext = preg_replace($suchmuster, $ersetzungen, $text);
|
|
return $replacedtext;
|
|
}
|
|
/*===============================*/
|
|
|
|
if (isset($_SESSION["name"])) {
|
|
$nutzername = $_SESSION["name"];
|
|
}
|
|
$check = filter_input(INPUT_POST, "check", FILTER_SANITIZE_STRING);
|
|
|
|
if (isset($_SESSION["login"]) && $session->get("login") == 1) {
|
|
if (isset($_SESSION["status"]) && $session->get("status") == "ok") {
|
|
$message = $session->get("message");
|
|
}
|
|
} else {
|
|
$session->set("status", "error");
|
|
$session->set("message", "Nicht eingeloggt");
|
|
$url = "index.php";
|
|
header("Location: $url");
|
|
echo '<script type="text/javascript">';
|
|
echo 'window.location.href="'.$url.'";';
|
|
echo '</script>';
|
|
echo '<noscript>';
|
|
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
|
|
echo '</noscript>'; exit;
|
|
}
|
|
|
|
$wahl = array();
|
|
for ($i = 0; $i < (count($_POST) - 1); $i++) { //-1 Wegen hidden-Feld
|
|
$wahl[$i] = filter_input(INPUT_POST, "wahl" . $i);
|
|
}
|
|
if ($check) {
|
|
if (count($wahl) == 3) {
|
|
if ($db->hasAlredySelected($nutzername)) {
|
|
$message = "";
|
|
$session->set("status", "error");
|
|
$session->set("message", "Schon eingetragen!");
|
|
$url = "index.php";
|
|
header("Location: $url");
|
|
echo '<script type="text/javascript">';
|
|
echo 'window.location.href="'.$url.'";';
|
|
echo '</script>';
|
|
echo '<noscript>';
|
|
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
|
|
echo '</noscript>'; exit;
|
|
} else {
|
|
if ($db->insertSelection($nutzername, $wahl)){
|
|
$session->set("status", "ok");
|
|
$session->set("message", "Du bist jetzt eingetragen!<br>Du wirst in 3 Sekunden wietergeleitet.");
|
|
$url = "check.php";
|
|
header("Location: $url");
|
|
echo '<script type="text/javascript">';
|
|
echo 'window.location.href="'.$url.'";';
|
|
echo '</script>';
|
|
echo '<noscript>';
|
|
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
|
|
echo '</noscript>'; exit;
|
|
} else {
|
|
$session->set("status", "error");
|
|
$session->set("message", "Beim Eintragen ist etwas schief gelaufen, versuche es später nochmal oder wende dich an den Admin.");
|
|
$url = "index.php";
|
|
header("Location: $url");
|
|
echo '<script type="text/javascript">';
|
|
echo 'window.location.href="'.$url.'";';
|
|
echo '</script>';
|
|
echo '<noscript>';
|
|
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
|
|
echo '</noscript>'; exit;
|
|
}
|
|
}
|
|
} else {
|
|
$message = "";
|
|
$errorMessage = "Fehlerhafte Auswahl!";
|
|
}
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Sportwahlen | Wahl</title>
|
|
<link rel="stylesheet" href="assets/css/main.css">
|
|
</head>
|
|
|
|
<body>
|
|
<?php if (isset($errorMessage) && $errorMessage != ""): ?>
|
|
<div class="modal">
|
|
<div class="message error">
|
|
<!-- Ausgabe einer eventuellen Fehlermeldung -->
|
|
<p><?php echo $errorMessage; ?></p>
|
|
</div>
|
|
</div>
|
|
<?php endif;?>
|
|
<?php if (isset($message) && $message != ""): ?>
|
|
<div class="modal">
|
|
<div class="message sucsses">
|
|
<!-- Ausgabe einer eventuellen Statusmeldung -->
|
|
<p><?php echo $message; ?></p>
|
|
</div>
|
|
</div>
|
|
<?php endif;?>
|
|
<?php
|
|
$kurse = $db->selectKurse();
|
|
echo '<form action="wahl.php" method="post">';
|
|
?>
|
|
<p class="name"><?php echo 'Hallo, ' . convertName(convertUmlauteFrom($nutzername)) . ', bitte auswählen:'; ?></p>
|
|
<?php
|
|
echo '<table border="1"><tr><td></td>';
|
|
for ($i = 0; $i < count($kurse); $i++) {
|
|
echo "<td>" . convertUmlauteFrom($kurse[$i]["name"]) . "</td>";
|
|
}
|
|
|
|
for ($j = 0; $j < 3; $j++) {
|
|
echo "<tr>";
|
|
echo "<td>Wahl " . ($j + 1) . "</td>";
|
|
for ($k = 0; $k < count($kurse); $k++) {
|
|
echo "<td>";
|
|
echo '<input type="radio" id="' . $j . '/' . $k . '" name="wahl' . $j . '" value="' . convertUmlauteFrom($kurse[$k]["name"]) . ';' . $kurse[$k]["stunde"] . '">';
|
|
echo '<label for="' . $j . '/' . $k . '">' . $kurse[$k]["stunde"] . '</label>';
|
|
echo "</td>";
|
|
}
|
|
echo "</tr>";
|
|
}
|
|
echo '<tr><td colspan="' . (count($kurse) + 1) . '"><input type="submit" value="Wählen"></td></tr></table>';
|
|
?>
|
|
<input type="hidden" name="check" value="ja">
|
|
<?php
|
|
echo "</form>";
|
|
?>
|
|
<noscript>
|
|
<p>
|
|
JavaScript wird für Annehmlichkeiten verwendet, um diese nutzen zu können, sollten Sie dies auch aktivieren.
|
|
</p>
|
|
</noscript>
|
|
<script src="assets/js/main.js"></script>
|
|
</body>
|
|
|
|
</html>
|
|
------------------------------
|
|
<?php
|
|
|
|
error_reporting(E_ALL); //Debuging
|
|
require_once 'include/DBConnection.inc.php';
|
|
function autoloader($classname)
|
|
{
|
|
include 'class/' . $classname . '.php';
|
|
}
|
|
spl_autoload_register('autoloader');
|
|
|
|
$session = new Session();
|
|
$db = new Datenbank($dbname, $username, $password, $servername);
|
|
|
|
/*===============================*/
|
|
|
|
if (isset($_SESSION["login"]) && $session->get("login") == 1) {
|
|
if (isset($_SESSION["reload"]) && $session->get("reload") == 1) {
|
|
$session->destroy();
|
|
$session->start();
|
|
$session->set("finished", 1);
|
|
$url = "index.php";
|
|
header("Location: $url");
|
|
echo '<script type="text/javascript">';
|
|
echo 'window.location.href="'.$url.'";';
|
|
echo '</script>';
|
|
echo '<noscript>';
|
|
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
|
|
echo '</noscript>'; exit;
|
|
} else {
|
|
$session->set("reload", 1);
|
|
}
|
|
if (isset($_SESSION["status"]) && $session->get("status") == "ok") {
|
|
$message = $session->get("message");
|
|
}
|
|
} else {
|
|
$session->set("status", "error");
|
|
$session->set("message", "Nicht eingeloggt");
|
|
$url = "index.php";
|
|
header("Location: $url");
|
|
echo '<script type="text/javascript">';
|
|
echo 'window.location.href="'.$url.'";';
|
|
echo '</script>';
|
|
echo '<noscript>';
|
|
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
|
|
echo '</noscript>'; exit;
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Sportwahlen | Check</title>
|
|
<link rel="stylesheet" href="assets/css/main.css">
|
|
</head>
|
|
|
|
<body>
|
|
<?php if (isset($message) && $message != ""): ?>
|
|
<div class="modal">
|
|
<div class="message sucsses">
|
|
<!-- Ausgabe einer eventuellen Statusmeldung -->
|
|
<p><?php echo $message; ?></p>
|
|
</div>
|
|
</div>
|
|
<?php endif;?>
|
|
<noscript>
|
|
<p>
|
|
Bitte einmal Neuladen (F5-Taste)
|
|
</p>
|
|
</noscript>
|
|
<script src="assets/js/main.js"></script>
|
|
</body>
|
|
|
|
</html>
|
|
--------------------------------------
|
|
document.addEventListener('DOMContentLoaded', init);
|
|
|
|
function init() {
|
|
//forceHttps();
|
|
actrivateMessage();
|
|
setTimeout(hideMessage, 3000);
|
|
windowReload();
|
|
}
|
|
|
|
function forceHttps() {
|
|
if (location.protocol != 'https:') {
|
|
location.href = 'https://' + location.hostname + location.pathname;
|
|
}
|
|
}
|
|
|
|
function actrivateMessage() {
|
|
document.querySelectorAll('.modal').forEach((modal)=>{modal.style.position = 'fixed'});
|
|
}
|
|
|
|
function getFileName() {
|
|
let pathname = location.pathname;
|
|
let fileNameRegEx = /[a-z]+\.[a-z]+/i;
|
|
let fileName = pathname.match(fileNameRegEx);
|
|
return (fileName === null)?'index.php':fileName[0];
|
|
}
|
|
|
|
function hideMessage() {
|
|
if (getFileName() != 'check.php') {
|
|
document.querySelectorAll('.modal').forEach((modal) => { modal.style.display = 'none' });
|
|
}
|
|
}
|
|
|
|
function windowReload() {
|
|
if (getFileName() == 'check.php') {
|
|
let message = document.querySelector('.message p').innerHTML;
|
|
let timeRegEx = /[0-9]/;
|
|
let time = message.match(timeRegEx);
|
|
time = time[0];
|
|
setTimeout(updateMessage, 1000, time, message);//Starte Countdown
|
|
}
|
|
}
|
|
|
|
function updateMessage(time, message) {
|
|
let newTime = time-1;
|
|
message = message.replace(time, newTime);
|
|
document.querySelector('.message p').innerHTML = message;
|
|
if (newTime == 1) {
|
|
setTimeout(() => {location.reload()}, 1000);
|
|
return;
|
|
}
|
|
setTimeout(updateMessage, 1000, newTime, message);
|
|
} |