nettsiden/inc/navbar.php

61 lines
1.9 KiB
PHP
Raw Normal View History

<?php
2018-02-10 15:42:01 +01:00
function navbar($depth, $active = NULL, $sp = 'default-sp') {
require __DIR__ . '/../src/_autoload.php';
require_once __DIR__ . '/../vendor/simplesamlphp/simplesamlphp/lib/_autoload.php';
require __DIR__ . '/../sql_config.php';
2017-11-13 23:13:24 +01:00
$result = '<img class="logo" src="' . rtrim(str_repeat('../', $depth)) . "/css/logo-disk-white.png\"/>\n";
$result .= "\t\t<ul>\n";
$menuItems = [
2017-11-13 23:13:24 +01:00
'Hjem' => '',
'Kalender' => 'kalender',
'Aktiviteter' => 'aktiviteter',
'Prosjekter' => 'prosjekt',
'Kontakt' => 'kontakt',
'Wiki' => 'pvv'
];
2018-02-10 15:42:01 +01:00
$as = new SimpleSAML_Auth_Simple($sp);
$attr = $as->getAttributes();
if($attr) {
$uname = $attr['uid'][0];
$pdo = new \PDO($dbDsn, $dbUser, $dbPass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$userManager = new \pvv\admin\UserManager($pdo);
$isAdmin = $userManager->isAdmin($uname);
$projectGroup = $userManager->hasGroup($uname, 'prosjekt');
$activityGroup = $userManager->hasGroup($uname, 'aktiviteter');
if($isAdmin | $projectGroup | $activityGroup) {
$menuItems['Admin'] = 'admin';
}
}
foreach($menuItems as $caption => $link) {
2017-11-13 13:21:51 +01:00
$result .= "\t\t\t<a href=\"" . rtrim(str_repeat('../', $depth) . $link, '/') . "/\"" . ($active === $link ? ' class="active"' : '') . ">"
. "<li>" . $caption . "</li></a>\n"
;
}
2017-11-13 23:13:24 +01:00
$result .= "\t\t\t" . '<a href="javascript:void(0);" style="font-size:15px;" id="navopen" onclick="navbar()">&#9776;</a>' . "\n";
2017-11-13 13:21:51 +01:00
return $result . "\t\t</ul>\n";
}
function loginBar($sp = 'default-sp') {
2018-02-10 15:42:01 +01:00
require_once __DIR__ . '/../vendor/simplesamlphp/simplesamlphp/lib/_autoload.php';
$result = "\n";
$as = new SimpleSAML_Auth_Simple($sp);
$attr = $as->getAttributes();
if($attr) {
$uname = $attr['uid'][0];
2017-11-13 23:13:24 +01:00
$result .= "\t\t<p class=\"login\">Logget inn som: " . htmlspecialchars($uname) . "</p>\n";
} else {
2017-11-13 23:13:24 +01:00
$result .= "\t\t<a class=\"login\" href=\"" . htmlspecialchars($as->getLoginURL()) . "\">Logg inn</a>\n";
}
return $result;
}