Show admin page link to admins
This commit is contained in:
parent
56e6766520
commit
32aa9e077c
@ -1,5 +1,9 @@
|
||||
<?php
|
||||
function navbar($depth, $active = NULL) {
|
||||
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';
|
||||
|
||||
$result = '<img class="logo" src="' . rtrim(str_repeat('../', $depth)) . "/css/logo-disk-white.png\"/>\n";
|
||||
$result .= "\t\t<ul>\n";
|
||||
$menuItems = [
|
||||
@ -10,6 +14,25 @@ function navbar($depth, $active = NULL) {
|
||||
'Kontakt' => 'kontakt',
|
||||
'Wiki' => 'pvv'
|
||||
];
|
||||
|
||||
$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) {
|
||||
$result .= "\t\t\t<a href=\"" . rtrim(str_repeat('../', $depth) . $link, '/') . "/\"" . ($active === $link ? ' class="active"' : '') . ">"
|
||||
. "<li>" . $caption . "</li></a>\n"
|
||||
@ -20,8 +43,9 @@ function navbar($depth, $active = NULL) {
|
||||
}
|
||||
|
||||
function loginBar($sp = 'default-sp') {
|
||||
require_once __DIR__ . '/../vendor/simplesamlphp/simplesamlphp/lib/_autoload.php';
|
||||
|
||||
$result = "\n";
|
||||
require_once(__DIR__ . '/../vendor/simplesamlphp/simplesamlphp/lib/_autoload.php');
|
||||
$as = new SimpleSAML_Auth_Simple($sp);
|
||||
|
||||
$attr = $as->getAttributes();
|
||||
|
Loading…
Reference in New Issue
Block a user