This commit is contained in:
Willy 2021-09-11 20:12:29 +02:00
parent 0eadd8977d
commit d6baa603dc
6 changed files with 31 additions and 20 deletions

View File

@ -1,15 +1,17 @@
<?php <?php
// This file should serve as an example showing all the current implemented features. // This file should serve as an example showing current implemented features
// Parameters that will be used in the template file // Parameters that will be used in the template files
$templateParameters["render"] = true; // Whether or not to render the template // For more options and explanations, check the 'templateParameters.php' file from the 'template' folder
$templateParameters["title"] = "Eksempel side"; // Sets the page title $templateParameters["title"] = "Eksempel side";
// Include the top of page // Include the top of page
include_once("template/_header.php"); include_once("template/_header.php");
?> ?>
<h1>Eksempel side</h1>
<h1>Eksempel side.</h1>
<p>Dette er en eksempel side</p> <p>Dette er en eksempel side</p>
<?php <?php
// Include the rest of the page // Include the rest of the page
include_once("template/_footer.php"); include_once("template/_footer.php");

View File

@ -1,8 +1,6 @@
<?php <?php
// Parameters that will be used in the template file
$templateParameters["title"] = "Forside"; $templateParameters["title"] = "Forside";
// Include the top of page
include_once("template/_header.php"); include_once("template/_header.php");
?> ?>
@ -12,6 +10,5 @@ include_once("template/_header.php");
<a href="img/stafett.jpg"><img src="img/stafett-cropped.jpg" alt="Bilde av folk som løper på banen"></a> <a href="img/stafett.jpg"><img src="img/stafett-cropped.jpg" alt="Bilde av folk som løper på banen"></a>
<?php <?php
// Include the rest of the page
include_once("template/_footer.php"); include_once("template/_footer.php");
?> ?>

View File

@ -3,7 +3,7 @@
if ((isset($_POST['username'])) && (isset($_POST['password']))) { if ((isset($_POST['username'])) && (isset($_POST['password']))) {
if (($_POST['username'] === 'VG3') && ($_POST['password'] === '3ELDEA')) { if (($_POST['username'] === 'VG3') && ($_POST['password'] === '3ELDEA')) {
session_start(); session_start();
$_SESSION['logged_in'] = true; $_SESSION['logged_in'] = TRUE;
$_SESSION['username'] = $_POST['username']; $_SESSION['username'] = $_POST['username'];
header("Location: index.php"); header("Location: index.php");
exit; exit;
@ -13,10 +13,8 @@ if ((isset($_POST['username'])) && (isset($_POST['password']))) {
} }
} }
// Parameters that will be used in the template file $templateParameters["title"] = "Logg inn";
$templateParameters["title"] = "Logg inn"; // Sets the page title
// Include the top of page
include_once("template/_header.php"); include_once("template/_header.php");
?> ?>
<h1>Logg inn</h1> <h1>Logg inn</h1>
@ -27,7 +25,6 @@ include_once("template/_header.php");
?> ?>
<form method="post"> <form method="post">
<!-- Hvorfor bry seg om CSRF? -->
<label for="username">Brukernavn:</label> <label for="username">Brukernavn:</label>
<br> <br>
<input type="text" id="username" name="username"> <input type="text" id="username" name="username">
@ -41,6 +38,5 @@ include_once("template/_header.php");
</form> </form>
<?php <?php
// Include the rest of the page
include_once("template/_footer.php"); include_once("template/_footer.php");
?> ?>

View File

@ -1,5 +1,8 @@
<?php <?php
if ($templateParameters["render"] === false) { if(!isset($_SESSION)) session_start();
include_once("templateParameters.php");
if ($templateParameters["render"] === FALSE) {
return; return;
} }
?> ?>

View File

@ -1,5 +1,6 @@
<?php <?php
session_start(); if(!isset($_SESSION)) session_start();
include_once("templateParameters.php");
// When including this template from other directories, using relative url paths is not sufficient. Therefore we use a prefix to ensure that the correct url path is given. // When including this template from other directories, using relative url paths is not sufficient. Therefore we use a prefix to ensure that the correct url path is given.
// Typically we put this before any local urls, such as navigation, icons etc to ensure that they use the correct path. // Typically we put this before any local urls, such as navigation, icons etc to ensure that they use the correct path.
@ -8,7 +9,7 @@ if ((strlen($templateUrlPrefix) > 1)) {
$templateUrlPrefix = htmlspecialchars($templateUrlPrefix . DIRECTORY_SEPARATOR); $templateUrlPrefix = htmlspecialchars($templateUrlPrefix . DIRECTORY_SEPARATOR);
} }
if ($templateParameters["render"] === false) { if ($templateParameters["render"] === FALSE) {
return; return;
} }
?> ?>
@ -26,7 +27,6 @@ if ($templateParameters["render"] === false) {
<div class="navbar-top-head"> <div class="navbar-top-head">
<div class="navbar-top-inner"> <div class="navbar-top-inner">
<!-- Jalla løsning -->
<a href="<?=$templateUrlPrefix;?>" style="display: block; max-width: max-content;"> <a href="<?=$templateUrlPrefix;?>" style="display: block; max-width: max-content;">
<img style="display: block; height: 32px;" src="<?=$templateUrlPrefix;?>img/cropped-kf-propell-ikon-32x32.png" alt=""> <img style="display: block; height: 32px;" src="<?=$templateUrlPrefix;?>img/cropped-kf-propell-ikon-32x32.png" alt="">
<div style="margin-left: 44px;"> <div style="margin-left: 44px;">
@ -37,13 +37,15 @@ if ($templateParameters["render"] === false) {
</div> </div>
</div> </div>
<?php if ($_SESSION['logged_in'] === true) : ?> <?php if ((isset($_SESSION['logged_in'])) && ($_SESSION['logged_in'] === TRUE)) : ?>
<div class="login-statusbar"> <div class="login-statusbar">
<div class="login-statusbar-inner"> <div class="login-statusbar-inner">
<a href="<?=$templateUrlPrefix;?>logout.php" style="float: right;">Logg ut</a> <a href="<?=$templateUrlPrefix;?>logout.php" style="float: right;">Logg ut</a>
<div>Inlogget som: <?=htmlspecialchars($_SESSION['username'])?></div> <div>Inlogget som: <?=htmlspecialchars($_SESSION['username'])?></div>
</div> </div>
</div> </div>
<?php endif; ?> <?php endif; ?>
<div class="grid-container"> <div class="grid-container">

View File

@ -0,0 +1,11 @@
<?php
// Default parameter values if none is defined
$defaultTemplateParameters = [
"title" => "Document", // Set page title
"render" => TRUE, // Whether or not to render the template
];
// Initialize default parameter values
foreach(array_keys($defaultTemplateParameters) as $key) {
if (!isset($templateParameters[$key])) $templateParameters[$key] = $defaultTemplateParameters[$key];
}