File: adminHeader.inc

package info (click to toggle)
ldap-account-manager 9.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 84,712 kB
  • sloc: php: 226,230; javascript: 83,487; pascal: 41,693; perl: 414; sh: 273; xml: 228; makefile: 188
file content (204 lines) | stat: -rw-r--r-- 7,478 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php

namespace LAM\HEADER;
/*

  This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
  Copyright (C) 2018 - 2024  Roland Gruber

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

use htmlContentLink;
use htmlDiv;
use htmlGroup;
use htmlImage;
use htmlLink;
use htmlOutputText;
use htmlResponsiveRow;
use htmlSpan;
use LAM\TYPES\TypeManager;
use LAMException;
use ServerProfilePersistenceManager;

/**
 * Head part of page which includes links to lists etc.
 *
 * @package main
 * @author Roland Gruber
 */

$headerPrefix = "";
if (is_file("login.php")) {
	$headerPrefix = "..";
}
elseif (is_file("../../templates/login.php")) {
	$headerPrefix = "../..";
}
elseif (is_file("../../../templates/login.php")) {
	$headerPrefix = "../../..";
}

/** tool definitions */
include_once(__DIR__ . "/tools.inc");

$pro = '';
if (isLAMProVersion()) {
	$pro = ' Pro';
}

// HTML header and title
echo $_SESSION['header'];
$title = "LDAP Account Manager" . $pro . " (" . str_replace(['ldap://', 'ldaps://'], ['', ''], $_SESSION['config']->get_ServerURL()) . ")";
printHeaderContents($title, $headerPrefix);
echo "</head><body>\n";

// include all JavaScript files
printJsIncludes($headerPrefix);

printHeader($headerPrefix);

function printHeader(string $headerPrefix): void {
	// get tool list
	$availableTools = getTools();
	// sort tools
	$toSort = [];
	foreach ($availableTools as $myTool) {
		if ($myTool->getRequiresWriteAccess() && !checkIfWriteAccessIsAllowed()) {
			continue;
		}
		if ($myTool->getRequiresPasswordChangeRights() && !checkIfPasswordChangeIsAllowed()) {
			continue;
		}
		// check visibility
		if (!$myTool->isVisible()) {
			continue;
		}
		// check if hidden by config
		$toolClass = $myTool::class;
		$toolName = substr($toolClass, strrpos($toolClass, '\\') + 1);
		if (!$_SESSION['config']->isToolActive($toolName)) {
			continue;
		}
		$toSort[$toolClass] = $myTool->getPosition();
	}
	asort($toSort);
	$tools = [];
	foreach ($toSort as $key => $value) {
		$tools[] = new $key();
	}
	$userData = $_SESSION['ldap']->getUserName();
	$userName = extractRDNValue($userData);
	?>

    <div id="lam-topnav" class="lam-header">
        <div class="lam-header-left lam-menu-stay">
            <a href="https://www.ldap-account-manager.org/" target="new_window">
                <img class="align-middle" width="24" height="24" alt="help"
                     src="<?php echo $headerPrefix; ?>/graphics/logo24.png">
                <span class="hide-on-tablet">&nbsp;&nbsp;<?php echo $userName ?></span>
                <span class="hide-on-mobile-and-tablet">
                        <?php
						echo getLAMVersionText();
						?>
                </span>
            </a>
            <span class="hide-on-mobile lam-margin-small">&nbsp;&nbsp;
                    <?php
					$serverProfileLabel = $_SESSION['config']->getName() . ' - ';
					$serverProfilesPersistenceManager = new ServerProfilePersistenceManager();
					try {
						$serverProfileNames = $serverProfilesPersistenceManager->getProfiles();
						if (sizeof($serverProfileNames) < 2) {
							$serverProfileLabel = '';
						}
					}
					catch (LAMException $e) {
						logNewMessage(LOG_ERR, 'Unable to read server profiles: ' . $e->getTitle());
					}
					echo $serverProfileLabel . $userName;
					?>
                </span>
        </div>
        <a class="lam-header-right lam-menu-icon hide-on-tablet" href="javascript:void(0);" class="icon"
           onclick="window.lam.topmenu.toggle();">
            <img class="align-middle" width="16" height="16" alt="menu"
                 src="<?php echo $headerPrefix; ?>/graphics/menu.svg">
            <span class="padding0"></span>
        </a>
        <div class="lam-header-right lam-header-menublock">
			<?php
			$typeManager = new TypeManager();
			$types = $typeManager->getConfiguredTypes();
			if (!empty($types)) {
				$accountTypesGroup = new htmlGroup();
				$accountTypesLink = new htmlLink(_('Accounts'), "javascript:void(0);");
				$accountTypesLink->setOnClick("window.lam.topmenu.openSubmenu(event, 'lam-navigation-types', window.lam.topmenu.subMenuCloseListenerTypes);");
				$accountTypesLink->setOnMouseOver("window.lam.topmenu.openSubmenu(event, 'lam-navigation-types', window.lam.topmenu.subMenuCloseListenerTypes);");
				$accountTypesLink->setCSSClasses(['lam-menu-entry']);
				$accountTypesGroup->addElement($accountTypesLink);
				$accountList = new htmlGroup();
				foreach ($types as $type) {
					if ($type->isHidden()) {
						continue;
					}
					$link = $headerPrefix . '/templates/lists/list.php?type=' . $type->getId();
					$accountTypeLink = new htmlLink($type->getAlias(), $link, $headerPrefix . '/graphics/' . $type->getIcon());
					$accountTypeLink->setCSSClasses(['lam-menu-entry icon']);
					$accountList->addElement($accountTypeLink);
				}
				$accountTypeEntriesDiv = new htmlDiv(null, $accountList, ['lam-navigation-layer-content']);
				$accountTypesDiv = new htmlDiv('lam-navigation-types', $accountTypeEntriesDiv, ['lam-navigation-layer zeroHeight']);
				$accountTypesGroup->addElement($accountTypesDiv);

				parseHtml(null, $accountTypesGroup, [], false, null);
			}
			if (sizeof($tools) > 0) {
				$toolGroup = new htmlGroup();
				$toolLink = new htmlLink(_('Tools'), "javascript:void(0);");
				$toolLink->setOnClick("window.lam.topmenu.openSubmenu(event, 'lam-navigation-tools', window.lam.topmenu.subMenuCloseListenerTools);");
				$toolLink->setOnMouseOver("window.lam.topmenu.openSubmenu(event, 'lam-navigation-tools', window.lam.topmenu.subMenuCloseListenerTools);");
				$toolLink->setCSSClasses(['lam-menu-entry']);
				$toolGroup->addElement($toolLink);
				$toolList = new htmlGroup();
				foreach ($tools as $tool) {
					$link = $headerPrefix . '/templates/' . $tool->getLink();
					$toolLink = new htmlLink($tool->getName(), $link, $headerPrefix . '/graphics/' . $tool->getImageLink());
					$toolLink->setCSSClasses(['lam-menu-entry icon']);
					$toolList->addElement($toolLink);
				}
				$toolEntriesDiv = new htmlDiv(null, $toolList, ['lam-navigation-layer-content']);
				$toolDiv = new htmlDiv('lam-navigation-tools', $toolEntriesDiv, ['lam-navigation-layer zeroHeight']);
				$toolGroup->addElement($toolDiv);

				parseHtml(null, $toolGroup, [], false, null);
			}
			if (is_dir(__DIR__ . '/../docs/manual')) {
				?>
                <a class="lam-menu-entry" target="_blank" href="<?php echo $headerPrefix; ?>/docs/manual/index.html">
                    <span class="padding0"><?php echo _("Help") ?></span>
                </a>
				<?php
			}
			?>

            <a class="lam-menu-entry" href="<?php echo $headerPrefix; ?>/templates/logout.php" target="_top">
                <span class="padding0"><?php echo _("Logout") ?></span>
            </a>
        </div>
    </div>
	<?php
}