From 3cc069773f4a1eca969e648246e457b24201d0ee Mon Sep 17 00:00:00 2001 From: William Date: Mon, 11 Oct 2021 09:37:39 +0200 Subject: [PATCH] Add janky ass alerts --- example.php | 6 ++++++ login.php | 6 +++--- template/_header.php | 31 +++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/example.php b/example.php index 6c6c2cd..6f68b50 100644 --- a/example.php +++ b/example.php @@ -6,6 +6,12 @@ require_once("app/common.php"); // For more options and explanations, check the 'app/template.php' file $templateParameters["title"] = "Eksempel side"; +// Alerts which will be executed from the template +$_SESSION['alert'][] = ['info', 'Eksempel!']; +$_SESSION['alert'][] = ['success', 'Eksempel!']; +$_SESSION['alert'][] = ['warning', 'Eksempel!']; +$_SESSION['alert'][] = ['danger', 'Eksempel!']; + // Include the top of page require_once("template/_header.php"); ?> diff --git a/login.php b/login.php index dacfc8e..17e30ce 100644 --- a/login.php +++ b/login.php @@ -6,11 +6,11 @@ if ((isset($_POST['username'])) && (isset($_POST['password']))) { if (($_POST['username'] === 'VG3') && ($_POST['password'] === '3ELDEA')) { $_SESSION['logged_in'] = TRUE; $_SESSION['username'] = $_POST['username']; + $_SESSION['alert'][] = ['info', 'Velkommen '.htmlspecialchars($_SESSION['username']).'!']; header("Location: index.php"); - exit; + exit(); } else { - $loginFormError = "Feil påloggingsinformasjon. Prøv igjen."; - //$loginFormError = "Noe gikk visst galt, prøv igjen senere."; + $_SESSION['alert'][] = ['danger', 'Feil påloggingsinformasjon. Prøv igjen.']; } } diff --git a/template/_header.php b/template/_header.php index c5785c2..1b5c7b3 100644 --- a/template/_header.php +++ b/template/_header.php @@ -53,4 +53,35 @@ if ($templateParameters["render"] === FALSE) {
+ 0)) { + foreach ($_SESSION['alert'] as $alert) { + switch ($alert[0]) { + case 'success': + $prefix = 'Suksess:'; + break; + + case 'info': + $prefix = 'Info:'; + break; + + case 'warning': + $prefix = 'Advarsel:'; + break; + + case 'danger': + $prefix = 'Error:'; + break; + + default: + $alert[0] = 'danger'; + $prefix = 'Ukjent:'; + break; + } + echo('
'.$prefix.' '.$alert[1].'
'); + } + $_SESSION['alert'] = []; + } + ?>