Commit some shit
This commit is contained in:
parent
d8b3913310
commit
716dea87b2
23
app/class/DatabaseHandler.php
Normal file
23
app/class/DatabaseHandler.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
// This is the first step towards actually doing work with the database
|
||||
// Encapsulate a single connection to a particular database
|
||||
|
||||
Class DatabaseHandler {
|
||||
public function connect(): object {
|
||||
$host = '127.0.0.1';
|
||||
$db = 'test';
|
||||
$user = 'root';
|
||||
$pass = '';
|
||||
$charset = 'utf8mb4';
|
||||
|
||||
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
|
||||
$options = [
|
||||
PDO::ATTR_PERSISTENT => true,
|
||||
];
|
||||
try {
|
||||
return new PDO($dsn, $user, $pass, $options);
|
||||
} catch (PDOException $e) {
|
||||
throw new PDOException($e->getMessage(), (int)$e->getCode());
|
||||
}
|
||||
}
|
||||
}
|
24
app/class/Template.php
Normal file
24
app/class/Template.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
class Template {
|
||||
// Generates a dynamic URL to the given path.
|
||||
private function urlFor($path): string
|
||||
{
|
||||
// TODO: Make this WORK!!
|
||||
$url = dirname(dirname(str_replace(realpath($_SERVER['DOCUMENT_ROOT']), '', realpath(__DIR__))));
|
||||
if ((strlen($url) > 1)) {
|
||||
$url = htmlspecialchars($url . '/');
|
||||
}
|
||||
|
||||
|
||||
//FUUUUUCKKK
|
||||
echo($_SERVER['DOCUMENT_ROOT'] . ' ' . __DIR__);
|
||||
die();
|
||||
return($url.$path);
|
||||
}
|
||||
|
||||
public function render($name): void
|
||||
{
|
||||
require(__DIR__ . '/../template/' . $name . '.php');
|
||||
}
|
||||
}
|
9
app/common.php
Normal file
9
app/common.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
// This is the main file to be included on every page
|
||||
session_start();
|
||||
|
||||
spl_autoload_register(function ($class_name) {
|
||||
require(__DIR__ . '/class/' . $class_name . '.php');
|
||||
});
|
||||
|
||||
$template = new Template();
|
14
app/template/footer.php
Normal file
14
app/template/footer.php
Normal file
@ -0,0 +1,14 @@
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<footer>
|
||||
<div class="footer">
|
||||
<div class="inner">
|
||||
<small>Kopieringsrettigheter © 2021-2022 <a target="_blank" href="http://willy.club">WillySoft Solutions</a></small>
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</body>
|
||||
</html>
|
80
app/template/header.php
Normal file
80
app/template/header.php
Normal file
@ -0,0 +1,80 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?=htmlspecialchars($this->params["title"]);?> – Stafett for livet</title>
|
||||
|
||||
<link rel="stylesheet" href="<?=$this->urlFor('static/style/main.css');?>">
|
||||
<link rel="icon" href="<?=$this->urlFor('static/img/cropped-kf-propell-ikon-32x32.png');?>" sizes="32x32">
|
||||
<body>
|
||||
|
||||
<header>
|
||||
<div class="navbar-top">
|
||||
<div class="inner">
|
||||
<a href="<?=$this->urlFor('/');?>" style="display: block; max-width: max-content;">
|
||||
<img style="display: block; height: 32px;" src="<?=$this->urlFor('static/img/cropped-kf-propell-ikon-32x32.png');?>" alt="">
|
||||
<div style="margin-left: 44px;">
|
||||
<div style="font-size: 24px; margin-top: -38px;">Stafett for livet</div>
|
||||
<div style="font-size: 10px; margin-top: -6px;"><b>KREFT</b>FORENINGEN</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<?php if ((isset($_SESSION['logged_in'])) && ($_SESSION['logged_in'] === TRUE)) : ?>
|
||||
<div class="login-statusbar">
|
||||
<div class="inner">
|
||||
<a href="<?=$this->urlFor('logout.php');?>" style="float: right;">Logg ut</a>
|
||||
<div>Inlogget som: <?=htmlspecialchars($_SESSION['username'])?></div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="grid-container">
|
||||
|
||||
<div>
|
||||
<nav class="nav-links">
|
||||
<ul>
|
||||
<li><a href="<?=$this->urlFor('/');?>">Forside</a></li>
|
||||
<li><a href="<?=$this->urlFor('login.php');?>">Logg inn</a></li>
|
||||
<li><a href="<?=$this->urlFor('example.php');?>">Eksempel</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<?php
|
||||
// is my implementation of alerts janky? maybe...
|
||||
if ((isset($_SESSION['alert'])) && (count($_SESSION['alert']) > 0)) {
|
||||
foreach ($_SESSION['alert'] as $alert) {
|
||||
switch ($alert[0]) {
|
||||
case 'success':
|
||||
$prefix = 'Suksess –';
|
||||
break;
|
||||
|
||||
case 'info':
|
||||
$prefix = 'Info –';
|
||||
break;
|
||||
|
||||
case 'warning':
|
||||
$prefix = 'Varsel –';
|
||||
break;
|
||||
|
||||
case 'danger':
|
||||
$prefix = 'Error –';
|
||||
break;
|
||||
|
||||
default:
|
||||
$alert[0] = 'danger';
|
||||
$prefix = 'Ukjent –';
|
||||
break;
|
||||
}
|
||||
echo('<div class="alert alert-'.$alert[0].'"><b>'.$prefix.'</b> '.$alert[1].'</div>');
|
||||
}
|
||||
$_SESSION['alert'] = [];
|
||||
}
|
||||
?>
|
||||
<main>
|
3
index.php
Normal file
3
index.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
// Redirect
|
||||
header('Location: ' . 'public/');
|
15
public/example.php
Normal file
15
public/example.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
// This file should serve as an example showing current implemented features.
|
||||
require("../app/common.php");
|
||||
|
||||
// Include the top of page
|
||||
$template->render("header");
|
||||
?>
|
||||
|
||||
<h1>Eksempel side</h1>
|
||||
<p>Dette er en eksempel side</p>
|
||||
|
||||
<?php
|
||||
// Include the bottom of the page
|
||||
$template->render("footer");
|
||||
?>
|
13
public/index.php
Normal file
13
public/index.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
require("../app/common.php");
|
||||
|
||||
$template->render("header");
|
||||
?>
|
||||
|
||||
<h1>Forsida!</h1>
|
||||
<p>Vi planlegger for Kreftforeningens Stafett for livet Kristiansand i juni 2021 og håper du blir med.</p>
|
||||
<p>Stafettene i 2021 tilpasses nasjonale og lokale smittevernsråd, og det vil være lokale variasjoner i hvordan stafettene gjennomføres. Men målet er likt: Vi skal hedre fighterne, vise vår støtte, minnes de vi har mistet, gi håp og feire livet. </p>
|
||||
|
||||
<?php
|
||||
$template->render("footer");
|
||||
?>
|
25
public/login.php
Normal file
25
public/login.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
require("../app/common.php");
|
||||
|
||||
$template->render("header");
|
||||
?>
|
||||
|
||||
<h1>Logg inn</h1>
|
||||
<p>Fyll ut legitimasjonen din for å logge inn.</p>
|
||||
|
||||
<form method="post">
|
||||
<label for="username">Brukernavn:</label>
|
||||
<br>
|
||||
<input type="text" id="username" name="username">
|
||||
<br>
|
||||
<label for="password">Passord:</label>
|
||||
<br>
|
||||
<input type="password" id="password" name="password">
|
||||
<br>
|
||||
<br>
|
||||
<input type="submit" value="Bekreft">
|
||||
</form>
|
||||
|
||||
<?php
|
||||
$template->render("footer");
|
||||
?>
|
16
public/logout.php
Normal file
16
public/logout.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
// Initialize the session
|
||||
session_start();
|
||||
|
||||
// Unset all of the session variables
|
||||
session_unset();
|
||||
|
||||
// Destroy the session.
|
||||
session_destroy();
|
||||
|
||||
session_start();
|
||||
|
||||
// Redirect to login page
|
||||
header("location: login.php");
|
||||
exit;
|
||||
?>
|
BIN
public/static/img/cropped-kf-propell-ikon-32x32.png
Normal file
BIN
public/static/img/cropped-kf-propell-ikon-32x32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
126
public/static/style/main.css
Normal file
126
public/static/style/main.css
Normal file
@ -0,0 +1,126 @@
|
||||
body {
|
||||
background: #eee;
|
||||
color: #222;
|
||||
font-size: 14px;
|
||||
font-family: "Liberation Sans", Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4 {
|
||||
margin: 0;
|
||||
border-bottom: 1px solid #aaa;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.navbar-top {
|
||||
padding: 12px;
|
||||
background: #472987;
|
||||
/*background: linear-gradient(0deg, rgba(71,40,134,1) 0%, rgba(81,24,195,1) 100%);*/
|
||||
}
|
||||
.navbar-top .inner {
|
||||
max-width: 900px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.navbar-top .inner a {
|
||||
color: #f8f8f8;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.login-statusbar {
|
||||
border-top: 2px solid #f8f8f8;
|
||||
background: rgb(54,148,37);
|
||||
background: linear-gradient(0deg, rgba(54,148,37,1) 0%, rgba(62,162,34,1) 50%, rgba(63,177,43,1) 100%);
|
||||
}
|
||||
.login-statusbar .inner {
|
||||
max-width: 900px;
|
||||
margin: 0 auto;
|
||||
color: #f8f8f8;
|
||||
font-weight: bold;
|
||||
font-size: 12px;
|
||||
padding-left: 12px;
|
||||
padding-right: 12px;
|
||||
padding-top: 4px;
|
||||
padding-bottom: 4px;
|
||||
text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
.login-statusbar .inner > a {
|
||||
color: #f8f8f8;
|
||||
}
|
||||
|
||||
.footer {
|
||||
background: #d8d8d8;
|
||||
border-top: 1px solid #aaa;
|
||||
padding: 12px;
|
||||
max-width: 888px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.grid-container {
|
||||
background: #fff;
|
||||
|
||||
display: grid;
|
||||
grid-template-columns: max-content auto;
|
||||
grid-gap: 12px;
|
||||
|
||||
max-width: 888px;
|
||||
margin: 0 auto;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.grid-container main img {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
border: 1px solid #aaa;
|
||||
}
|
||||
|
||||
.grid-container .nav-links {
|
||||
background: #eee;
|
||||
border: 1px solid #aaa;
|
||||
padding: 12px;
|
||||
}
|
||||
.grid-container .nav-links ul {
|
||||
margin: 0;
|
||||
padding-left: 12px;
|
||||
}
|
||||
|
||||
a {
|
||||
color: rgb(0, 0, 255);
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 600px) {
|
||||
.grid-container {
|
||||
grid-template-columns: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.alert {
|
||||
padding: 8px;
|
||||
margin-bottom: 8px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 2px;
|
||||
}
|
||||
.alert-info {
|
||||
color: #0c5460;
|
||||
background-color: #d1ecf1;
|
||||
border-color: #62b1bd;
|
||||
background: linear-gradient(0deg, rgba(167,223,232,1) 0%, rgba(209,236,241,1) 100%);
|
||||
}
|
||||
.alert-success {
|
||||
color: #155724;
|
||||
background-color: #d4edda;
|
||||
border-color: #56bf6e;
|
||||
background: linear-gradient(0deg, rgba(165,227,180,1) 0%, rgba(212,237,218,1) 100%);
|
||||
}
|
||||
.alert-danger {
|
||||
color: #721c24;
|
||||
background-color: #f8d7da;
|
||||
border-color: #c8848c;
|
||||
background: linear-gradient(0deg, rgb(249, 180, 186) 0%, rgb(248, 215, 218) 100%);
|
||||
}
|
||||
.alert-warning {
|
||||
color: #856404;
|
||||
background: #fff3cd;
|
||||
border-color: #dfc678;
|
||||
background: linear-gradient(0deg, rgb(251, 229, 161) 0%, rgb(255, 243, 205) 100%);
|
||||
}
|
15
public/subdir/index.php
Normal file
15
public/subdir/index.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
// This file should serve as an example showing current implemented features.
|
||||
require("../../app/common.php");
|
||||
|
||||
// Include the top of page
|
||||
$template->render("header");
|
||||
?>
|
||||
|
||||
<h1>Eksempel side</h1>
|
||||
<p>Dette er en eksempel side</p>
|
||||
|
||||
<?php
|
||||
// Include the bottom of the page
|
||||
$template->render("footer");
|
||||
?>
|
Reference in New Issue
Block a user