2017-11-11 15:20:58 +01:00
|
|
|
<?php
|
|
|
|
function navbar($depth, $active = NULL) {
|
2018-02-13 15:23:38 +01:00
|
|
|
$result = "\n\t<ul id=\"menu\">\n";
|
2017-11-11 15:20:58 +01:00
|
|
|
$menuItems = [
|
2017-11-13 23:13:24 +01:00
|
|
|
'Hjem' => '',
|
2018-08-06 23:29:44 +02:00
|
|
|
'Hendelser' => 'hendelser',
|
|
|
|
//'Kalender' => 'kalender',
|
|
|
|
//'Aktiviteter' => 'aktiviteter',
|
2017-11-13 23:13:24 +01:00
|
|
|
'Prosjekter' => 'prosjekt',
|
|
|
|
'Kontakt' => 'kontakt',
|
2024-08-21 16:16:54 +02:00
|
|
|
'Webmail' => 'mail',
|
2022-01-24 16:12:31 +01:00
|
|
|
'Galleri' => 'galleri',
|
2024-04-08 23:43:06 +02:00
|
|
|
'Wiki' => 'https://wiki.pvv.ntnu.no/',
|
2019-04-08 19:34:31 +02:00
|
|
|
'Git' => 'https://git.pvv.ntnu.no/',
|
2022-09-17 17:09:35 +02:00
|
|
|
'Tjenester' => 'tjenester',
|
2017-11-11 15:20:58 +01:00
|
|
|
];
|
|
|
|
foreach($menuItems as $caption => $link) {
|
2018-02-13 14:53:33 +01:00
|
|
|
$isActive = $active === $link;
|
2019-04-08 19:34:31 +02:00
|
|
|
if (substr( $link, 0, 4 ) != "http") {
|
2017-11-13 20:35:25 +01:00
|
|
|
$link = rtrim(str_repeat('../', $depth) . $link, '/') . '/';
|
2019-04-08 19:34:31 +02:00
|
|
|
}
|
2018-08-09 00:33:14 +02:00
|
|
|
|
|
|
|
//if ($isActive) $link = '#';
|
|
|
|
|
2018-02-13 14:53:33 +01:00
|
|
|
$result .= "\t\t<li" . ($isActive ? ' class="active"' : '') . '>'
|
2017-11-13 20:35:25 +01:00
|
|
|
. '<a href="' . $link . '">'
|
2017-11-11 15:20:58 +01:00
|
|
|
. $caption
|
|
|
|
. "</a></li>\n"
|
|
|
|
;
|
|
|
|
}
|
|
|
|
return $result . "\t</ul>\n";
|
|
|
|
}
|
|
|
|
|
2018-02-13 18:30:49 +01:00
|
|
|
function loginBar($sp = null, $pdo = null) {
|
|
|
|
if (is_null($sp)) $sp = 'default-sp';
|
2017-11-11 15:20:58 +01:00
|
|
|
$result = "\n";
|
|
|
|
require_once(__DIR__ . '/../vendor/simplesamlphp/simplesamlphp/lib/_autoload.php');
|
2024-04-08 22:11:43 +02:00
|
|
|
$as = new \SimpleSAML\Auth\Simple($sp);
|
2017-11-11 15:20:58 +01:00
|
|
|
|
2018-02-13 18:44:36 +01:00
|
|
|
$svg = '<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 64 64">
|
|
|
|
<circle cx="32" cy="27" r="14" stroke-width="0" />
|
|
|
|
<ellipse cx="32" cy="66" rx="24" ry="28" stroke-width="0" />
|
2018-02-13 16:46:01 +01:00
|
|
|
</svg>
|
2018-02-13 16:24:16 +01:00
|
|
|
';
|
|
|
|
|
2017-11-11 15:20:58 +01:00
|
|
|
$attr = $as->getAttributes();
|
|
|
|
if($attr) {
|
|
|
|
$uname = $attr['uid'][0];
|
2018-02-24 16:53:17 +01:00
|
|
|
$isAdmin = false;
|
2018-02-13 18:30:49 +01:00
|
|
|
if (isset($pdo)) {
|
|
|
|
$userManager = new \pvv\admin\UserManager($pdo);
|
|
|
|
$isAdmin = $userManager->isAdmin($uname);
|
|
|
|
}
|
2023-01-19 11:28:29 +01:00
|
|
|
$result .= "\t<a id=\"login\" href=\"#usermenu\" aria-hidden=\"true\">{$svg}" . htmlspecialchars($uname) . "</a>\n";
|
2018-08-10 22:30:01 +02:00
|
|
|
|
2018-02-13 16:51:43 +01:00
|
|
|
$result .= "\n\t<ul id=\"usermenu\">\n";
|
2023-01-19 11:28:29 +01:00
|
|
|
$result .= "\n\t\t<li><a id=\"login\" href=\"#\">{$svg}" . htmlspecialchars($uname) . "</a></li>\n";
|
2018-02-13 18:30:49 +01:00
|
|
|
if ($isAdmin) {
|
|
|
|
$result .= "\n\t\t<li><a href=\"/admin/\">Admin</a></li>\n";
|
|
|
|
}
|
2018-02-13 16:51:43 +01:00
|
|
|
$result .= "\n\t\t<li><a href=\"" . htmlspecialchars($as->getLogoutURL()) . "\">Logg ut</a></li>\n";
|
|
|
|
$result .= "\n\t</ul>\n";
|
2017-11-11 15:20:58 +01:00
|
|
|
} else {
|
2023-01-19 11:28:29 +01:00
|
|
|
$result .= "\t<a id=\"login\" href=\"" . htmlspecialchars($as->getLoginURL()) . "\">{$svg}Logg inn</a>\n";
|
2017-11-11 15:20:58 +01:00
|
|
|
}
|
|
|
|
|
2018-02-13 16:46:01 +01:00
|
|
|
$result .= "\n\t<a href=\"#menu\" id=\"menu_toggle\" aria-hidden=\"true\"><big>☰ </big>MENU</a>\n";
|
2017-11-11 15:20:58 +01:00
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|