~ubuntu-branches/ubuntu/karmic/ldap-account-manager/karmic

« back to all changes in this revision

Viewing changes to templates/lists/listusers.php

  • Committer: Bazaar Package Importer
  • Author(s): Roland Gruber
  • Date: 2006-05-14 14:00:29 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060514140029-chr2mf30u7bajebu
Tags: 1.0.2-1
Updated to new upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
$Id: listusers.php,v 1.74 2005/07/18 15:54:59 gruberroland Exp $
4
 
 
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
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 detaexils.
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
 
 
26
 
/**
27
 
* This page displays a list of all users.
28
 
*
29
 
* @package lists
30
 
* @author Roland Gruber
31
 
*/
32
 
 
33
 
 
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");
46
 
 
47
 
 
48
 
// start session
49
 
session_save_path("../../sess");
50
 
@session_start();
51
 
 
52
 
setlanguage();
53
 
 
54
 
$scope = 'user';
55
 
 
56
 
// copy HTTP-GET variables to HTTP-POST
57
 
$_POST = $_POST + $_GET;
58
 
 
59
 
$refresh = true;
60
 
if (isset($_GET['norefresh'])) $refresh = false;
61
 
if (isset($_POST['refresh'])) $refresh = true;
62
 
 
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);
75
 
        if ($sr) {
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];
80
 
                }
81
 
                $_SESSION['trans_primary_hash'] = $trans_primary_hash;
82
 
        }
83
 
}
84
 
 
85
 
 
86
 
if (isset($_SESSION[$scope . 'info'])) $info = $_SESSION[$scope . 'info'];
87
 
if (isset($_SESSION[$scope . '_units'])) $units = $_SESSION[$scope . '_units'];
88
 
 
89
 
listDoPost($scope);
90
 
 
91
 
echo $_SESSION['header'];
92
 
 
93
 
echo "<title>listusers</title>\n";
94
 
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../style/layout.css\">\n";
95
 
echo "</head><body>\n";
96
 
 
97
 
listPrintJavaScript();
98
 
 
99
 
// get current page
100
 
if (isset($_GET["page"])) $page = $_GET["page"];
101
 
else $page = 1;
102
 
 
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
106
 
}
107
 
else $max_page_entries = $_SESSION["config"]->get_MaxListEntries();
108
 
 
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
113
 
 
114
 
if (isset($_GET["sort"])) $sort = $_GET["sort"];
115
 
else $sort = strtolower($attr_array[0]);
116
 
 
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
121
 
 
122
 
 
123
 
// configure search filter for LDAP
124
 
$module_filter = get_ldap_filter($scope);  // basic filter is provided by modules
125
 
$filter = "(&" . $module_filter . ")";
126
 
 
127
 
if ($refresh) {
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."));
132
 
        }
133
 
        if ($sr) {
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;
140
 
                // save results
141
 
                $_SESSION[$scope . 'info'] = $info;
142
 
        }
143
 
        else {
144
 
                $_SESSION[$scope . 'info'] = array();
145
 
                $info = array();
146
 
                StatusMessage("ERROR",
147
 
                        _("LDAP Search failed! Please check your preferences."),
148
 
                        _("No users found!"));
149
 
        }
150
 
}
151
 
 
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)
156
 
if ($info) {
157
 
        $info = listSort($sort, $attr_array, $info);
158
 
}
159
 
 
160
 
// build filter URL
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'];
165
 
}
166
 
if (sizeof($searchFilter) > 0) {
167
 
        $searchFilter = "&amp;" . implode("&amp;", $searchFilter);
168
 
}
169
 
else {
170
 
        $searchFilter = "";
171
 
}
172
 
 
173
 
echo ("<form action=\"listusers.php?norefresh=true\" method=\"post\">\n");
174
 
 
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 . "&amp;trans_primary=" . $trans_primary, $scope, _("%s user(s) found"));
180
 
        echo ("<br />");
181
 
}
182
 
 
183
 
// account table head
184
 
listPrintTableHeader($scope, $searchFilter . "&amp;trans_primary=" . $trans_primary, $desc_array, $attr_array, $_POST, $sort);
185
 
 
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);
190
 
 
191
 
if (sizeof($info) != 0) {
192
 
        // translate GIDs and resort array if selected
193
 
        if ($trans_primary == "on") {
194
 
                // translate GIDs
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]];
198
 
                        }
199
 
                }
200
 
                // resort if needed
201
 
                if ($sort == "gidnumber") {
202
 
                        $info = listSort($sort, $attr_array, $info);
203
 
                }
204
 
        }
205
 
        // print user list
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&amp;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";
215
 
                }
216
 
                else {
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";
219
 
                }
220
 
                echo ("<td align='center'>\n<a href=\"../account/edit.php?type=user&amp;DN='" . $info[$i]['dn'] . "'\">" .
221
 
                        _("Edit") . "</a>\n</td>\n");
222
 
                for ($k = 0; $k < sizeof($attr_array); $k++) {
223
 
                        echo ("<td>\n");
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']);
230
 
                                        // sort array
231
 
                                        sort($info[$i][$attrName]);
232
 
                                        // print all attribute entries seperated by "; "
233
 
                                        echo implode("; ", $info[$i][$attrName]) . "\n";
234
 
                                }
235
 
                                else echo $info[$i][$attrName] . "\n";
236
 
                        }
237
 
                echo ("</td>\n");
238
 
                }
239
 
        echo("</tr>\n");
240
 
        }
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>&nbsp;<a href=\"listusers.php?norefresh=1&amp;page=" . $page . "&amp;sort=" . $sort .
246
 
                $searchFilter . "&amp;trans_primary=" . $trans_primary . "&amp;selectall=yes\">" .
247
 
                "<font color=\"black\"><b>" . _("Select all") . "</b></font></a></td>\n";
248
 
        echo "</tr>\n";
249
 
}
250
 
echo ("</table>\n");
251
 
 
252
 
echo ("<br>");
253
 
if (sizeof($info) != 0) {
254
 
        listDrawNavigationBar(sizeof($info), $max_page_entries, $page, $sort,
255
 
                $searchFilter . "&amp;trans_primary=" . $trans_primary, $scope, _("%s user(s) found"));
256
 
        echo ("<br>");
257
 
}
258
 
 
259
 
if ($refresh) {
260
 
        // generate list of possible suffixes
261
 
        $units = $_SESSION['ldap']->search_units($_SESSION["config"]->get_Suffix($scope));
262
 
}
263
 
 
264
 
// print combobox with possible sub-DNs
265
 
listShowOUSelection($units, $suffix);
266
 
 
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>";
273
 
        }
274
 
        else echo "<input type=\"checkbox\" name=\"trans_primary\">";
275
 
        echo ("&nbsp;&nbsp;<input type=\"submit\" name=\"apply\" value=\"" . _("Apply") . "\">");
276
 
        echo "</p>\n";
277
 
}
278
 
 
279
 
echo ("<p>&nbsp;</p>\n");
280
 
 
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>&nbsp;&nbsp;<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>";
291
 
        }
292
 
        echo "</select>&nbsp;&nbsp;&nbsp;&nbsp;\n";
293
 
        echo ("<input type=\"submit\" name=\"pdf\" value=\"" . _("Create PDF for selected user(s)") . "\">\n");
294
 
        echo "&nbsp;";
295
 
        echo ("<input type=\"submit\" name=\"pdf_all\" value=\"" . _("Create PDF for all users") . "\">\n");
296
 
        echo "</fieldset>";
297
 
}
298
 
 
299
 
echo ("<p>&nbsp;</p>\n");
300
 
 
301
 
echo ("</form>\n");
302
 
echo "</body></html>\n";
303
 
 
304
 
 
305
 
// save variables to session
306
 
$_SESSION[$scope . '_units'] = $units;
307
 
$_SESSION[$scope . '_suffix'] = $suffix;
308
 
 
309
 
?>