This commit is contained in:
Markus Wang Halvorsen 2018-02-13 16:58:54 +01:00
parent af97383e01
commit 1db31b9e56
6 changed files with 151 additions and 7 deletions

View File

@ -20,4 +20,9 @@ CREATE TABLE "projects" (
CREATE TABLE "users" ( CREATE TABLE "users" (
"uname" TEXT, "uname" TEXT,
"groups" INT DEFAULT 0 "groups" INT DEFAULT 0
);
CREATE TABLE "motd" (
"title" TEXT,
"content" TEXT
); );

23
src/pvv/side/motd.php Normal file
View File

@ -0,0 +1,23 @@
<?php
namespace pvv\side;
use \PDO;
class MOTD{
private $pdo;
public function __construct($pdo){
$this->pdo = $pdo;
}
public function getMOTD(){
$query = 'SELECT * FROM motd LIMIT 1';
$statement = $this->pdo->prepare($query);
$statement->execute();
$data = $statement->fetch();
$motd = array("title" => $data[0], "content" => explode("\n", $data[1]));
return $motd;
}
}

View File

@ -50,6 +50,10 @@ if(!($isAdmin | $projectGroup | $activityGroup)){
echo '<li><a class="btn" href="prosjekter/">Prosjekter</a></li>'; echo '<li><a class="btn" href="prosjekter/">Prosjekter</a></li>';
} }
if($isAdmin) {
echo '<li><a class="btn" href="motd/">Dagens melding</a></li>';
}
if($isAdmin){ if($isAdmin){
echo '<li><a class="btn" href="brukere/">Brukere</a></li>'; echo '<li><a class="btn" href="brukere/">Brukere</a></li>';
} }

66
www/admin/motd/index.php Normal file
View File

@ -0,0 +1,66 @@
<?php
ini_set('display_errors', '1');
date_default_timezone_set('Europe/Oslo');
setlocale(LC_ALL, 'no_NO');
error_reporting(E_ALL);
require __DIR__ . '/../../../inc/navbar.php';
require __DIR__ . '/../../../src/_autoload.php';
require __DIR__ . '/../../../sql_config.php';
require_once(__DIR__ . '/../../../vendor/simplesamlphp/simplesamlphp/lib/_autoload.php');
$as = new SimpleSAML_Auth_Simple('default-sp');
$attrs = $as->getAttributes();
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$userManager = new \pvv\admin\UserManager($pdo);
require_once(__DIR__ . '/../../../vendor/simplesamlphp/simplesamlphp/lib/_autoload.php');
$as = new SimpleSAML_Auth_Simple('default-sp');
$as->requireAuth();
$attrs = $as->getAttributes();
$uname = $attrs['uid'][0];
if(!$userManager->isAdmin($uname)){
echo 'Her har du ikke lov\'t\'å\'værra!!!';
exit();
}
$motdfetcher = new \pvv\side\MOTD($pdo);
$motd = $motdfetcher->getMOTD();
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="../../css/normalize.css">
<link rel="stylesheet" href="../../css/style.css">
<link rel="stylesheet" href="../../css/nav.css">
<link rel="stylesheet" href="../../css/events.css">
<link rel="stylesheet" href="../../css/admin.css">
</head>
<body>
<nav>
<?php echo navbar(2, 'admin'); ?>
<?php echo loginbar(); ?>
</nav>
<main>
<h2>Dagens melding</h2>
<hr class="ruler">
<form action="update.php", method="post">
<p class="subtitle no-chin">Tittel</p>
<p class="subnote">Ikke nødvendig</p>
<input type="text" name="title" value="<?= $motd['title'] ?>" class="boxinput" style="width:66%;"><br>
<p class="subtitle no-chin">Innhold</p>
<textarea name="content" style="width:100%" rows="8" class="boxinput"><?= implode($motd["content"], "\n") ?></textarea>
<div style="margin-top: 2em;">
<hr class="ruler">
<?= '<input type="submit" class="btn" value="Lagre endringer"></a>'; ?>
</div>
</form>
</main>
</body>

39
www/admin/motd/update.php Normal file
View File

@ -0,0 +1,39 @@
<?php
ini_set('display_errors', '1');
date_default_timezone_set('Europe/Oslo');
setlocale(LC_ALL, 'no_NO');
error_reporting(E_ALL);
require __DIR__ . '/../../../src/_autoload.php';
require __DIR__ . '/../../../sql_config.php';
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$userManager = new \pvv\admin\UserManager($pdo);
require_once(__DIR__ . '/../../../vendor/simplesamlphp/simplesamlphp/lib/_autoload.php');
$as = new SimpleSAML_Auth_Simple('default-sp');
$as->requireAuth();
$attrs = $as->getAttributes();
$uname = $attrs['uid'][0];
if(!isset($_POST['title']) or !isset($_POST['content'])){
header('Location: ' . $_SERVER['HTTP_REFERER']);
exit();
}
if(!$userManager->isAdmin($uname)){
echo 'Her har du ikke lov\'t\'å\'værra!!!';
exit();
}
$query = 'UPDATE motd SET title=:title, content=:content';
$statement = $pdo->prepare($query);
$statement->bindParam(':title', $_POST['title'], PDO::PARAM_STR);
$statement->bindParam(':content', $_POST['content'], PDO::PARAM_STR);
$statement->execute();
header('Location: .');
?>
<a href=".">Om du ikke ble automatisk omdirigert tilbake klikk her</a>

View File

@ -13,6 +13,9 @@ $agenda = new \pvv\side\Agenda([
new \pvv\side\social\AnimekveldActivity, new \pvv\side\social\AnimekveldActivity,
new \pvv\side\DBActivity($pdo), new \pvv\side\DBActivity($pdo),
]); ]);
$motdfetcher = new \pvv\side\MOTD($pdo);
$motd = $motdfetcher->getMOTD();
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
@ -92,16 +95,20 @@ $agenda = new \pvv\side\Agenda([
<br> <br>
<p><a class="btn" href="kalender/">Flere aktiviteter</a></p> <p><a class="btn" href="kalender/">Flere aktiviteter</a></p>
</div> </div>
<div class="gridl"> <div class="gridl">
<h2>Dagens melding</h2> <?php
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Odio tempor orci dapibus ultrices in. Et odio pellentesque diam volutpat commodo. Porttitor leo a diam sollicitudin. Nisl nisi scelerisque eu ultrices. Ipsum dolor sit amet consectetur. Mattis pellentesque id nibh tortor id. Quam adipiscing vitae proin sagittis nisl rhoncus mattis. Integer malesuada nunc vel risus commodo. Curabitur gravida arcu ac tortor dignissim. Mi sit amet mauris commodo quis imperdiet. Enim nulla aliquet porttitor lacus luctus accumsan tortor posuere. Pretium quam vulputate dignissim suspendisse in est. Velit egestas dui id ornare. Urna condimentum mattis pellentesque id nibh tortor id aliquet.<br><br> $title = $motd["title"];
$title_text = " - " . $title;
Maecenas pharetra convallis posuere morbi leo urna molestie. Egestas sed sed risus pretium. At erat pellentesque adipiscing commodo elit. Ut tortor pretium viverra suspendisse potenti nullam ac. Sit amet volutpat consequat mauris nunc congue nisi vitae suscipit. Faucibus purus in massa tempor nec feugiat nisl. Viverra tellus in hac habitasse platea dictumst vestibulum. Tincidunt vitae semper quis lectus nulla at. Id consectetur purus ut faucibus. Ultricies integer quis auctor elit sed vulputate. Suscipit adipiscing bibendum est ultricies integer quis auctor elit.<br><br> echo "<h2>Dagens melding";
if($title != ""){
echo $title_text;
}
echo "</h2>";
Nulla malesuada pellentesque elit eget. Odio tempor orci dapibus ultrices in iaculis nunc. Iaculis at erat pellentesque adipiscing. Volutpat ac tincidunt vitae semper. Posuere ac ut consequat semper viverra nam libero justo. Enim tortor at auctor urna nunc id cursus metus. Sit amet cursus sit amet. Eu non diam phasellus vestibulum lorem sed risus. Consequat interdum varius sit amet mattis vulputate enim nulla aliquet. Enim sed faucibus turpis in eu mi bibendum. Eu consequat ac felis donec et odio pellentesque. Cursus eget nunc scelerisque viverra mauris in aliquam sem. Accumsan in nisl nisi scelerisque eu ultrices vitae auctor eu. Quis commodo odio aenean sed adipiscing. Et ultrices neque ornare aenean euismod elementum nisi. Turpis in eu mi bibendum neque egestas congue. Sed arcu non odio euismod. Risus quis varius quam quisque.<br><br> echo "<p>" . implode($motd["content"], "</p>\n<p>") . "</p>";
?>
Consequat interdum varius sit amet mattis vulputate enim nulla. Tristique et egestas quis ipsum suspendisse. Amet massa vitae tortor condimentum lacinia quis vel eros donec. Varius vel pharetra vel turpis nunc eget. Convallis posuere morbi leo urna molestie at elementum eu facilisis. Congue eu consequat ac felis donec et odio pellentesque. Nunc sed velit dignissim sodales ut eu sem integer. Mattis enim ut tellus elementum sagittis. Molestie ac feugiat sed lectus. Cursus vitae congue mauris rhoncus aenean vel elit. Mauris augue neque gravida in. Velit sed ullamcorper morbi tincidunt ornare massa eget egestas purus. Et tortor at risus viverra adipiscing at in tellus integer.</p>
</div> </div>
</main> </main>
</body> </body>