3
$Id: listusers.php,v 1.74 2005/07/18 15:54:59 gruberroland Exp $
5
This code is part of LDAP Account Manager (http://www.sourceforge.net/projects/lam)
6
Copyright (C) 2003 Roland Gruber, Leonhard Walchsh�usl
7
Copyright (C) 2004 Roland Gruber
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.
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 detaexils.
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
27
* This page displays a list of all users.
30
* @author Roland Gruber
34
/** Access to configuration options */
35
include_once ("../../lib/config.inc");
36
/** Access to LDAP connection */
37
include_once ("../../lib/ldap.inc");
38
/** Used to print status messages */
39
include_once ("../../lib/status.inc");
40
/** Used to create PDF files */
41
include_once("../../lib/pdf.inc");
42
/** Access to account modules */
43
include_once("../../lib/modules.inc");
44
/** Basic list functions */
45
include_once("../../lib/lists.inc");
49
session_save_path("../../sess");
56
// copy HTTP-GET variables to HTTP-POST
57
$_POST = $_POST + $_GET;
60
if (isset($_GET['norefresh'])) $refresh = false;
61
if (isset($_POST['refresh'])) $refresh = true;
63
// check if primary group should be translated
64
if (isset($_POST['trans_primary']) && ($_POST['trans_primary'] == 'on')) $trans_primary = "on";
65
else $trans_primary = "off";
66
if (isset($_SESSION['trans_primary_hash'])) $trans_primary_hash = $_SESSION['trans_primary_hash'];
67
else $trans_primary_hash = array();
68
// generate hash table for group translation
69
if ($trans_primary == "on" && ($refresh || (sizeof($trans_primary_hash) == 0))) {
70
$trans_primary_hash = array();
71
$grp_suffix = $_SESSION['config']->get_Suffix('group');
72
$filter = "objectClass=posixGroup";
73
$attrs = array("cn", "gidNumber");
74
$sr = @ldap_search($_SESSION["ldap"]->server(), $grp_suffix, $filter, $attrs);
76
$info = @ldap_get_entries($_SESSION["ldap"]->server(), $sr);
77
unset($info['count']); // delete count entry
78
for ($i = 0; $i < sizeof($info); $i++) {
79
$trans_primary_hash[$info[$i]['gidnumber'][0]] = $info[$i]['cn'][0];
81
$_SESSION['trans_primary_hash'] = $trans_primary_hash;
86
if (isset($_SESSION[$scope . 'info'])) $info = $_SESSION[$scope . 'info'];
87
if (isset($_SESSION[$scope . '_units'])) $units = $_SESSION[$scope . '_units'];
91
echo $_SESSION['header'];
93
echo "<title>listusers</title>\n";
94
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style/layout.css\">\n";
95
echo "</head><body>\n";
97
listPrintJavaScript();
100
if (isset($_GET["page"])) $page = $_GET["page"];
103
// take maximum count of user entries shown on one page out of session
104
if ($_SESSION["config"]->get_MaxListEntries() <= 0) {
105
$max_page_entries = 10; // default setting, if not yet set
107
else $max_page_entries = $_SESSION["config"]->get_MaxListEntries();
109
// generate attribute-description table
110
$temp_array = listGetAttributeDescriptionList($scope);
111
$attr_array = array_keys($temp_array); // list of LDAP attributes to show
112
$desc_array = array_values($temp_array); // list of descriptions for the attributes
114
if (isset($_GET["sort"])) $sort = $_GET["sort"];
115
else $sort = strtolower($attr_array[0]);
117
// check search suffix
118
if (isset($_POST['suffix'])) $suffix = $_POST['suffix']; // new suffix selected via combobox
119
elseif (isset($_SESSION[$scope . '_suffix'])) $suffix = $_SESSION[$scope . '_suffix']; // old suffix from session
120
else $suffix = $_SESSION["config"]->get_Suffix($scope); // default suffix
123
// configure search filter for LDAP
124
$module_filter = get_ldap_filter($scope); // basic filter is provided by modules
125
$filter = "(&" . $module_filter . ")";
128
$attrs = $attr_array;
129
$sr = @ldap_search($_SESSION["ldap"]->server(), $suffix, $filter, $attrs);
130
if (ldap_errno($_SESSION["ldap"]->server()) == 4) {
131
StatusMessage("WARN", _("LDAP sizelimit exceeded, not all entries are shown."), _("See README.openldap.txt to solve this problem."));
134
$info = ldap_get_entries ($_SESSION["ldap"]->server, $sr);
135
ldap_free_result ($sr);
136
// delete first array entry which is "count"
137
unset($info['count']);
138
// save position in original $info
139
for ($i = 0; $i < sizeof($info); $i++) $info[$i]['LAM_ID'] = $i;
141
$_SESSION[$scope . 'info'] = $info;
144
$_SESSION[$scope . 'info'] = array();
146
StatusMessage("ERROR",
147
_("LDAP Search failed! Please check your preferences."),
148
_("No users found!"));
152
$filter = listBuildFilter($attr_array);
153
$info = listFilterAccounts($info, $filter);
154
if (sizeof($info) == 0) StatusMessage("WARN", "", _("No users found!"));
155
// sort rows by sort column ($sort)
157
$info = listSort($sort, $attr_array, $info);
161
$searchFilter = array();
162
$filterAttributes = array_keys($filter);
163
for ($i = 0; $i < sizeof($filterAttributes); $i++) {
164
$searchFilter[] = "filter" . $filterAttributes[$i] . "=" . $filter[$filterAttributes[$i]]['original'];
166
if (sizeof($searchFilter) > 0) {
167
$searchFilter = "&" . implode("&", $searchFilter);
173
echo ("<form action=\"listusers.php?norefresh=true\" method=\"post\">\n");
175
// display table only if users exist in LDAP
176
if (sizeof($info) != 0) {
177
// create navigation bar on top of user table
178
listDrawNavigationBar(sizeof($info), $max_page_entries, $page, $sort,
179
$searchFilter . "&trans_primary=" . $trans_primary, $scope, _("%s user(s) found"));
183
// account table head
184
listPrintTableHeader($scope, $searchFilter . "&trans_primary=" . $trans_primary, $desc_array, $attr_array, $_POST, $sort);
186
// calculate which rows to show
187
$table_begin = ($page - 1) * $max_page_entries;
188
if (($page * $max_page_entries) > sizeof($info)) $table_end = sizeof($info);
189
else $table_end = ($page * $max_page_entries);
191
if (sizeof($info) != 0) {
192
// translate GIDs and resort array if selected
193
if ($trans_primary == "on") {
195
for ($i = 0; $i < sizeof($info); $i++) {
196
if (isset($trans_primary_hash[$info[$i]['gidnumber'][0]])) {
197
$info[$i]['gidnumber'][0] = $trans_primary_hash[$info[$i]['gidnumber'][0]];
201
if ($sort == "gidnumber") {
202
$info = listSort($sort, $attr_array, $info);
206
for ($i = $table_begin; $i < $table_end; $i++) {
207
echo("<tr class=\"userlist\"\nonMouseOver=\"list_over(this, '" . $info[$i]['LAM_ID'] . "', '" . $scope . "')\"\n" .
208
"onMouseOut=\"list_out(this, '" . $info[$i]['LAM_ID'] . "', '" . $scope . "')\"\n" .
209
"onClick=\"list_click(this, '" . $info[$i]['LAM_ID'] . "', '" . $scope . "')\"\n" .
210
"onDblClick=\"parent.frames[1].location.href='../account/edit.php?type=user&DN=" . $info[$i]['dn'] . "'\">\n");
211
// checkboxes if selectall = "yes"
212
if (isset($_GET['selectall'])) {
213
echo "<td height=22 align=\"center\">\n<input onClick=\"list_click(this, '" . $info[$i]['LAM_ID'] . "', '" . $scope . "')\" type=\"checkbox\" name=\"" .
214
$info[$i]['LAM_ID'] . "\" checked>\n</td>\n";
217
echo "<td height=22 align=\"center\">\n<input onClick=\"list_click(this, '" . $info[$i]['LAM_ID'] . "', '" . $scope . "')\" type=\"checkbox\" name=\"" .
218
$info[$i]['LAM_ID'] . "\">\n</td>\n";
220
echo ("<td align='center'>\n<a href=\"../account/edit.php?type=user&DN='" . $info[$i]['dn'] . "'\">" .
221
_("Edit") . "</a>\n</td>\n");
222
for ($k = 0; $k < sizeof($attr_array); $k++) {
224
// print attribute values
225
$attrName = strtolower($attr_array[$k]);
226
if (isset($info[$i][$attrName]) && sizeof($info[$i][$attrName]) > 0) {
227
if (is_array($info[$i][$attrName])) {
228
// delete first array entry which is "count"
229
unset($info[$i][$attrName]['count']);
231
sort($info[$i][$attrName]);
232
// print all attribute entries seperated by "; "
233
echo implode("; ", $info[$i][$attrName]) . "\n";
235
else echo $info[$i][$attrName] . "\n";
241
// display select all link
242
$colspan = sizeof($attr_array) + 1;
243
echo "<tr class=\"userlist\">\n";
244
echo "<td align=\"center\"><img src=\"../../graphics/select.png\" alt=\"select all\"></td>\n";
245
echo "<td colspan=$colspan> <a href=\"listusers.php?norefresh=1&page=" . $page . "&sort=" . $sort .
246
$searchFilter . "&trans_primary=" . $trans_primary . "&selectall=yes\">" .
247
"<font color=\"black\"><b>" . _("Select all") . "</b></font></a></td>\n";
253
if (sizeof($info) != 0) {
254
listDrawNavigationBar(sizeof($info), $max_page_entries, $page, $sort,
255
$searchFilter . "&trans_primary=" . $trans_primary, $scope, _("%s user(s) found"));
260
// generate list of possible suffixes
261
$units = $_SESSION['ldap']->search_units($_SESSION["config"]->get_Suffix($scope));
264
// print combobox with possible sub-DNs
265
listShowOUSelection($units, $suffix);
267
// show translate GID to group name box if there is a column with gidnumber
268
if (in_array("gidnumber", $attr_array)) {
269
echo "<p align=\"left\">\n";
270
echo "<b>" . _("Translate GID number to group name") . ": </b>";
271
if ($trans_primary == "on") {
272
echo "<input type=\"checkbox\" name=\"trans_primary\" checked>";
274
else echo "<input type=\"checkbox\" name=\"trans_primary\">";
275
echo (" <input type=\"submit\" name=\"apply\" value=\"" . _("Apply") . "\">");
279
echo ("<p> </p>\n");
281
// new/delete/PDF buttons
282
echo ("<input type=\"submit\" name=\"new\" value=\"" . _("New user") . "\">\n");
283
if (sizeof($info) != 0) {
284
echo ("<input type=\"submit\" name=\"del\" value=\"" . _("Delete user(s)") . "\">\n");
285
echo ("<br><br><br>\n");
286
echo "<fieldset><legend><b>PDF</b></legend>\n";
287
echo ("<b>" . _('PDF structure') . ":</b> <select name=\"pdf_structure\">\n");
288
$pdf_structures = getPDFStructureDefinitions($scope);
289
foreach($pdf_structures as $pdf_structure) {
290
echo "<option " . (($pdf_structure == 'default') ? " selected" : "") . ">" . $pdf_structure . "</option>";
292
echo "</select> \n";
293
echo ("<input type=\"submit\" name=\"pdf\" value=\"" . _("Create PDF for selected user(s)") . "\">\n");
295
echo ("<input type=\"submit\" name=\"pdf_all\" value=\"" . _("Create PDF for all users") . "\">\n");
299
echo ("<p> </p>\n");
302
echo "</body></html>\n";
305
// save variables to session
306
$_SESSION[$scope . '_units'] = $units;
307
$_SESSION[$scope . '_suffix'] = $suffix;