| 1 |
<?php |
| 2 |
|
| 3 |
namespace LAM\HEADER; |
| 4 |
/* |
| 5 |
|
| 6 |
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) |
| 7 |
Copyright (C) 2018 - 2026 Roland Gruber |
| 8 |
|
| 9 |
This program is free software; you can redistribute it and/or modify |
| 10 |
it under the terms of the GNU General Public License as published by |
| 11 |
the Free Software Foundation; either version 2 of the License, or |
| 12 |
(at your option) any later version. |
| 13 |
|
| 14 |
This program is distributed in the hope that it will be useful, |
| 15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
GNU General Public License for more details. |
| 18 |
|
| 19 |
You should have received a copy of the GNU General Public License |
| 20 |
along with this program; if not, write to the Free Software |
| 21 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 |
|
| 23 |
*/ |
| 24 |
|
| 25 |
use htmlDiv; |
| 26 |
use htmlGroup; |
| 27 |
use htmlLink; |
| 28 |
use LAM\TYPES\TypeManager; |
| 29 |
use LAMException; |
| 30 |
use ServerProfilePersistenceManager; |
| 31 |
|
| 32 |
/** |
| 33 |
* Head part of page which includes links to lists etc. |
| 34 |
* |
| 35 |
* @package main |
| 36 |
* @author Roland Gruber |
| 37 |
*/ |
| 38 |
|
| 39 |
$headerPrefix = ""; |
| 40 |
if (is_file("login.php")) { |
| 41 |
$headerPrefix = ".."; |
| 42 |
} |
| 43 |
elseif (is_file("../../templates/login.php")) { |
| 44 |
$headerPrefix = "../.."; |
| 45 |
} |
| 46 |
elseif (is_file("../../../templates/login.php")) { |
| 47 |
$headerPrefix = "../../.."; |
| 48 |
} |
| 49 |
|
| 50 |
/** tool definitions */ |
| 51 |
include_once(__DIR__ . "/tools.inc"); |
| 52 |
|
| 53 |
$pro = ''; |
| 54 |
if (isLAMProVersion()) { |
| 55 |
$pro = ' Pro'; |
| 56 |
} |
| 57 |
|
| 58 |
// HTML header and title |
| 59 |
echo $_SESSION['header']; |
| 60 |
$title = "LDAP Account Manager" . $pro . " (" . str_replace(['ldap://', 'ldaps://'], ['', ''], $_SESSION['config']->get_ServerURL()) . ")"; |
| 61 |
printHeaderContents($title, $headerPrefix); |
| 62 |
echo "</head><body>\n"; |
| 63 |
|
| 64 |
// include all JavaScript files |
| 65 |
printJsIncludes($headerPrefix); |
| 66 |
|
| 67 |
printHeader($headerPrefix); |
| 68 |
|
| 69 |
function printHeader(string $headerPrefix): void { |
| 70 |
// get tool list |
| 71 |
$availableTools = getTools(); |
| 72 |
// sort tools |
| 73 |
$toSort = []; |
| 74 |
foreach ($availableTools as $myTool) { |
| 75 |
if ($myTool->getRequiresWriteAccess() && !checkIfWriteAccessIsAllowed()) { |
| 76 |
continue; |
| 77 |
} |
| 78 |
if ($myTool->getRequiresPasswordChangeRights() && !checkIfPasswordChangeIsAllowed()) { |
| 79 |
continue; |
| 80 |
} |
| 81 |
// check visibility |
| 82 |
if (!$myTool->isVisible()) { |
| 83 |
continue; |
| 84 |
} |
| 85 |
// check if hidden by config |
| 86 |
$toolClass = $myTool::class; |
| 87 |
$toolName = substr($toolClass, strrpos($toolClass, '\\') + 1); |
| 88 |
if (!$_SESSION['config']->isToolActive($toolName)) { |
| 89 |
continue; |
| 90 |
} |
| 91 |
$toSort[$toolClass] = $myTool->getPosition(); |
| 92 |
} |
| 93 |
asort($toSort); |
| 94 |
$tools = []; |
| 95 |
foreach (array_keys($toSort) as $key) { |
| 96 |
$tools[] = new $key(); |
| 97 |
} |
| 98 |
$userData = $_SESSION['ldap']->getUserName(); |
| 99 |
$userName = extractRDNValue($userData); |
| 100 |
?> |
| 101 |
|
| 102 |
<div id="lam-topnav" class="lam-header"> |
| 103 |
<div class="lam-header-left lam-menu-stay"> |
| 104 |
<a href="https://www.ldap-account-manager.org/" target="new_window"> |
| 105 |
<img class="align-middle" width="24" height="24" alt="help" |
| 106 |
src="<?php echo $headerPrefix; ?>/graphics/logo.svg"> |
| 107 |
<span class="hide-on-tablet"> <?php echo $userName ?></span> |
| 108 |
<span class="hide-on-mobile-and-tablet"> |
| 109 |
<?php |
| 110 |
echo getLAMVersionText(); |
| 111 |
?> |
| 112 |
</span> |
| 113 |
</a> |
| 114 |
<span class="hide-on-mobile lam-margin-small"> |
| 115 |
<?php |
| 116 |
$serverProfileLabel = $_SESSION['config']->getName() . ' - '; |
| 117 |
$serverProfilesPersistenceManager = new ServerProfilePersistenceManager(); |
| 118 |
try { |
| 119 |
$serverProfileNames = $serverProfilesPersistenceManager->getProfiles(); |
| 120 |
if (count($serverProfileNames) < 2) { |
| 121 |
$serverProfileLabel = ''; |
| 122 |
} |
| 123 |
} |
| 124 |
catch (LAMException $e) { |
| 125 |
logNewMessage(LOG_ERR, 'Unable to read server profiles: ' . $e->getTitle()); |
| 126 |
} |
| 127 |
echo $serverProfileLabel . $userName; |
| 128 |
?> |
| 129 |
</span> |
| 130 |
</div> |
| 131 |
<a class="lam-header-right lam-menu-icon hide-on-tablet" href="javascript:void(0);" class="icon" |
| 132 |
onclick="window.lam.topmenu.toggle();"> |
| 133 |
<img class="align-middle" width="16" height="16" alt="menu" |
| 134 |
src="<?php echo $headerPrefix; ?>/graphics/menu.svg"> |
| 135 |
<span class="padding0"></span> |
| 136 |
</a> |
| 137 |
<div class="lam-header-right lam-header-menublock"> |
| 138 |
<?php |
| 139 |
$typeManager = new TypeManager(); |
| 140 |
$types = $typeManager->getConfiguredTypes(); |
| 141 |
if (!empty($types)) { |
| 142 |
$accountTypesGroup = new htmlGroup(); |
| 143 |
$accountTypesLink = new htmlLink(_('Accounts'), "javascript:void(0);"); |
| 144 |
$accountTypesLink->setOnClick("window.lam.topmenu.openSubmenu(event, 'lam-navigation-types', window.lam.topmenu.subMenuCloseListenerTypes);"); |
| 145 |
$accountTypesLink->setOnMouseOver("window.lam.topmenu.openSubmenu(event, 'lam-navigation-types', window.lam.topmenu.subMenuCloseListenerTypes);"); |
| 146 |
$accountTypesLink->setCSSClasses(['lam-menu-entry']); |
| 147 |
$accountTypesGroup->addElement($accountTypesLink); |
| 148 |
$accountList = new htmlGroup(); |
| 149 |
foreach ($types as $type) { |
| 150 |
if ($type->isHidden()) { |
| 151 |
continue; |
| 152 |
} |
| 153 |
$link = $headerPrefix . '/templates/lists/list.php?type=' . $type->getId(); |
| 154 |
$accountTypeLink = new htmlLink($type->getAlias(), $link, $headerPrefix . '/graphics/' . $type->getIcon()); |
| 155 |
$accountTypeLink->setCSSClasses(['lam-menu-entry icon']); |
| 156 |
$accountList->addElement($accountTypeLink); |
| 157 |
} |
| 158 |
$accountTypeEntriesDiv = new htmlDiv(null, $accountList, ['lam-navigation-layer-content']); |
| 159 |
$accountTypesDiv = new htmlDiv('lam-navigation-types', $accountTypeEntriesDiv, ['lam-navigation-layer zeroHeight']); |
| 160 |
$accountTypesGroup->addElement($accountTypesDiv); |
| 161 |
|
| 162 |
parseHtml(null, $accountTypesGroup, [], false); |
| 163 |
} |
| 164 |
if ($tools !== []) { |
| 165 |
$toolGroup = new htmlGroup(); |
| 166 |
$toolLink = new htmlLink(_('Tools'), "javascript:void(0);"); |
| 167 |
$toolLink->setOnClick("window.lam.topmenu.openSubmenu(event, 'lam-navigation-tools', window.lam.topmenu.subMenuCloseListenerTools);"); |
| 168 |
$toolLink->setOnMouseOver("window.lam.topmenu.openSubmenu(event, 'lam-navigation-tools', window.lam.topmenu.subMenuCloseListenerTools);"); |
| 169 |
$toolLink->setCSSClasses(['lam-menu-entry']); |
| 170 |
$toolGroup->addElement($toolLink); |
| 171 |
$toolList = new htmlGroup(); |
| 172 |
foreach ($tools as $tool) { |
| 173 |
$link = $headerPrefix . '/templates/' . $tool->getLink(); |
| 174 |
$toolLink = new htmlLink($tool->getName(), $link, $headerPrefix . '/graphics/' . $tool->getImageLink()); |
| 175 |
$toolLink->setCSSClasses(['lam-menu-entry icon']); |
| 176 |
$toolList->addElement($toolLink); |
| 177 |
} |
| 178 |
$toolEntriesDiv = new htmlDiv(null, $toolList, ['lam-navigation-layer-content']); |
| 179 |
$toolDiv = new htmlDiv('lam-navigation-tools', $toolEntriesDiv, ['lam-navigation-layer zeroHeight']); |
| 180 |
$toolGroup->addElement($toolDiv); |
| 181 |
|
| 182 |
parseHtml(null, $toolGroup, [], false); |
| 183 |
} |
| 184 |
if (is_dir(__DIR__ . '/../docs/manual')) { |
| 185 |
?> |
| 186 |
<a class="lam-menu-entry" target="_blank" href="<?php echo $headerPrefix; ?>/docs/manual/index.html"> |
| 187 |
<span class="padding0"><?php echo _("Help") ?></span> |
| 188 |
</a> |
| 189 |
<?php |
| 190 |
} |
| 191 |
?> |
| 192 |
|
| 193 |
<a class="lam-menu-entry" href="<?php echo $headerPrefix; ?>/templates/logout.php" target="_top"> |
| 194 |
<span class="padding0"><?php echo _("Logout") ?></span> |
| 195 |
</a> |
| 196 |
</div> |
| 197 |
</div> |
| 198 |
<?php |
| 199 |
} |