1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 require "tabs_user.inc";
22 class userManagement extends plugin
23 {
24 /* Definitions */
25 var $plHeadline= "Users";
26 var $plDescription= "This does something";
28 /* Dialog attributes */
29 var $usertab= NULL;
30 var $userlist= array();
31 var $ui= NULL;
32 var $acl= "";
33 var $templates= array();
34 var $got_uid= false;
35 var $departments=array();
37 function userManagement ($config, $ui)
38 {
39 /* Save configuration for internal use */
40 $this->config= $config;
41 $this->ui= $ui;
43 /* Get global filter config */
44 if (!is_global("userfilter")){
45 $base= get_base_from_people($ui->dn);
46 $userfilter= array( "mailusers" => "checked",
47 "unixusers" => "checked",
48 "templates" => "",
49 "subsearch" => "",
50 "proxyusers" => "checked",
51 "sambausers" => "checked",
52 "faxusers" => "checked",
53 "functionalusers" => "checked",
54 "depselect" => $base,
55 "regex" => "*");
56 register_global("userfilter", $userfilter);
57 }
58 }
60 function execute()
61 {
62 $smarty = get_smarty(); // Smarty instance
63 $userfilter = get_global("userfilter"); // contains Filter Settings
64 $s_action = ""; // Contains the action to proceed
65 $s_entry = ""; // The value for s_action
66 $base_back = ""; // The Link for Backbutton
68 /* Start for New List Managment */
69 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
70 $s_action="open";
71 $s_entry = base64_decode($_GET['dep_id']);
72 $userfilter['depselect']= "".$this->config->departments[trim($s_entry)];
73 $this->reload();
74 }
76 /* Test Posts */
77 foreach($_POST as $key => $val){
78 // Post for delete
79 if(preg_match("/user_del.*/",$key)){
80 $s_action = "del";
81 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
82 // Post for edit
83 }elseif(preg_match("/user_edit_.*/",$key)){
84 $s_action="edit";
85 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
86 // Post for new
87 }elseif(preg_match("/dep_back.*/i",$key)){
88 $s_action="back";
89 }elseif(preg_match("/user_new.*/",$key)){
90 $s_action="new";
91 }elseif(preg_match("/dep_home.*/i",$key)){
92 $s_action="home";
93 }elseif(preg_match("/user_tplnew.*/i",$key)){
94 $s_action="new_tpl";
95 }elseif(preg_match("/user_chgpw.*/i",$key)){
96 $s_action="change_pw";
97 $s_entry = preg_replace("/user_chgpw_/i","",$key);
98 }elseif(preg_match("/dep_root.*/i",$key)){
99 $s_action="root";
100 }
101 }
103 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
104 $s_action ="edit";
105 $s_entry = $_GET['id'];
106 }
108 $s_entry = preg_replace("/_.$/","",$s_entry);
110 /* Department changed? */
111 if(isset($_POST['depselect']) && $_POST['depselect']){
112 $userfilter['depselect']= $_POST['depselect'];
113 $this->reload();
114 }
116 /* Homebutton is posted */
117 if($s_action=="home"){
118 $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
119 $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$userfilter['depselect']));
120 $this->reload();
121 }
123 if($s_action=="root"){
124 $userfilter['depselect']=($this->config->current['BASE']);
125 $this->reload();
126 }
129 /* If Backbutton is Posted */
130 if($s_action=="back"){
131 $base_back = preg_replace("/^[^,]+,/","",$userfilter['depselect']);
132 $base_back = convert_department_dn($base_back);
134 if(isset($this->config->departments[trim($base_back)])){
135 $userfilter['depselect']= $this->config->departments[trim($base_back)];
136 }else{
137 $userfilter['depselect']= $this->config->departments["/"];
138 }
139 $this->reload();
140 }
142 /* End for new List Managment */
144 /* Save filter data if we are in the headpage */
145 if (!isset($this->usertab)){
146 foreach( array("regex") as $type){
147 if (isset($_POST[$type])){
148 $userfilter[$type]= $_POST[$type];
149 }
150 }
151 }
152 if(isset($_POST['regex'])){
153 foreach( array("functionalusers", "unixusers", "mailusers","sambausers", "proxyusers", "faxusers", "templates", "subsearch") as $type){
154 if (isset($_POST[$type])) {
155 $userfilter[$type]= "checked";
156 } else {
157 $userfilter[$type]= "";
158 }
159 }
160 }
161 if (isset($_GET['search'])){
162 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
163 if ($s == "**"){
164 $s= "*";
165 }
166 $userfilter['regex']= $s;
167 }
168 register_global("userfilter", $userfilter);
171 /* React on user interaction here */
172 if (($_SERVER["REQUEST_METHOD"] == "POST")||($_SERVER["REQUEST_METHOD"]== "GET")){
174 /* User wants to edit data? */
175 if ($s_action=="edit"){
177 /* Get 'dn' from posted 'uid', must be unique */
179 $this->dn= $this->list[trim($s_entry)]['dn'];
181 /* Check locking, save current plugin in 'back_plugin', so
182 the dialog knows where to return. */
183 if (($user= get_lock($this->dn)) != ""){
184 return(gen_locked_message ($user, $this->dn));
185 }
187 /* Lock the current entry, so everyone will get the
188 above dialog */
189 add_lock ($this->dn, $this->ui->dn);
191 /* Set up the users ACL's for this 'dn' */
192 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
194 /* Register usertab to trigger edit dialog */
195 $this->usertab= new usertabs($this->config,
196 $this->config->data['TABS']['USERTABS'], $this->dn);
197 $this->usertab->set_acl($acl);
199 $_SESSION['objectinfo']= $this->dn;
200 }
201 }
203 /* Reset requested? */
204 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
205 if (isset($this->usertab)){
206 del_lock ($this->usertab->dn);
207 unset ($this->usertab);
208 }
209 $this->usertab= NULL;
210 $this->lognames= array();;
211 $this->sn= "";
212 $this->givenName= "";
213 $this->uid= "";
214 unset ($_SESSION['objectinfo']);
215 }
217 /* Password change requested */
218 if ($s_action=="change_pw"){
220 /* Get 'dn' from posted 'uid' */
221 $this->dn= $this->list[trim($s_entry)]['dn'];
223 /* Load permissions for selected 'dn' and check if
224 we're allowed to remove this 'dn' */
225 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
226 $acl= get_module_permission($acl, "user", $this->dn);
227 if (chkacl($acl, "password") == ""){
229 /* User is allowed to change passwords, save 'dn' and 'acl' for next
230 dialog. */
231 $this->acl= $acl;
232 $_SESSION['objectinfo']= $this->dn;
233 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
235 } else {
236 /* User is not allowed. Show message and cancel. */
237 print_red (_("You are not allowed to set this users password!"));
238 }
239 }
241 /* Perform password change */
242 if (isset($_POST['password_finish'])){
244 /* For security reasons, check if user is allowed to set password again */
245 if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
247 /* Check input and feed errors into 'message' */
248 $message= array();
250 /* Sanity checks... */
251 if ($_POST['new_password'] != $_POST['repeated_password']){
253 /* Matching passwords in new and repeated? */
254 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
255 } else {
257 /* Empty password is not permitted by default. */
258 if ($_POST['new_password'] == ""){
259 $message[]= _("The password you've entered as 'New password' is empty.");
260 }
261 }
263 /* Errors, or change password? */
264 if (count($message) != 0){
266 /* Show error message and continue editing */
267 show_errors ($message);
268 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
269 }
271 /* Set password, perform required steps */
272 if ($this->usertab){
273 if ($this->usertab->password_change_needed()){
274 $obj= $this->usertab->by_object['user'];
275 change_password ($this->usertab->dn, $_POST['new_password'],
276 0, $obj->pw_storage);
277 gosa_log ("Password for '".$this->usertab->dn."' has been changed");
278 unset($this->usertab);
279 $this->usertab= NULL;
280 }
281 } else {
282 change_password ($this->dn, $_POST['new_password']);
283 gosa_log ("Password for '".$this->dn."' has been changed");
284 }
285 } else {
287 /* Missing permissions, show message */
288 print_red (_("You are not allowed to set this users password!"));
289 }
291 /* Clean session, delete lock */
292 del_lock ($this->dn);
293 $this->reload();
294 unset ($this->usertab);
295 $this->usertab= NULL;
296 $this->lognames= array();;
297 $this->sn= "";
298 $this->givenName= "";
299 $this->uid= "";
300 unset ($_SESSION['objectinfo']);
301 }
304 /* Remove user was requested */
305 if ($s_action=="del"){
307 /* Get 'dn' from posted 'uid' */
308 $this->dn= $this->list[trim($s_entry)]['dn'];
310 /* Load permissions for selected 'dn' and check if
311 we're allowed to remove this 'dn' */
312 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
313 $this->acl= get_module_permission($acl, "user", $this->dn);
314 if (chkacl($this->acl, "delete") == ""){
316 /* Check locking, save current plugin in 'back_plugin', so
317 the dialog knows where to return. */
318 if (($user= get_lock($this->dn)) != ""){
319 return(gen_locked_message ($user, $this->dn));
320 }
322 /* Lock the current entry, so nobody will edit it during deletion */
323 add_lock ($this->dn, $this->ui->dn);
324 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), $this->dn));
325 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
326 } else {
328 /* Obviously the user isn't allowed to delete. Show message and
329 clean session. */
330 print_red (_("You are not allowed to delete this user!"));
331 }
332 }
336 /* Confirmation for deletion has been passed. User should be deleted. */
337 if (isset($_POST['delete_user_confirm'])){
339 /* Some nice guy may send this as POST, so we've to check
340 for the permissions again. */
341 if (chkacl($this->acl, "delete") == ""){
343 /* Delete request is permitted, perform LDAP action */
344 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
345 $this->dn);
346 $this->usertab->set_acl(array($this->acl));
347 $this->usertab->delete ();
348 gosa_log ("User object '".$this->dn."' has been removed");
349 unset ($this->usertab);
350 $this->usertab= NULL;
352 /* User list has changed, reload it. */
353 $this->reload ();
354 } else {
356 /* Normally this shouldn't be reached, send some extra
357 logs to notify the administrator */
358 print_red (_("You are not allowed to delete this user!"));
360 if(isset($this->ui->uid)){
361 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
362 }
363 }
365 /* Remove lock file after successfull deletion */
366 del_lock ($this->dn);
367 }
370 /* Delete user canceled? */
371 if (isset($_POST['delete_cancel'])){
372 del_lock ($this->dn);
373 }
376 /* Finish user edit is triggered by the tabulator dialog, so
377 the user wants to save edited data. Check and save at this
378 point. */
379 if (isset($_POST['edit_finish'])){
381 /* Check tabs, will feed message array */
382 $this->usertab->last= $this->usertab->current;
383 $this->usertab->save_object();
384 $message= $this->usertab->check();
386 /* Save, or display error message? */
387 if (count($message) == 0){
389 /* No errors. Go ahead and prepare to ask for a password
390 in case we're creating a new user. 'dn' will be 'new'
391 in this case. It is set to the correct value later. */
392 if ($this->dn == "new"){
393 $set_pass= 1;
394 } else {
395 $set_pass= 0;
396 }
398 /* Save user data to ldap */
399 if($this->usertab->save() == 1){
400 gosa_log ("User object '".$this->dn."' saving failed.");
401 return;
402 }
403 gosa_log ("User object '".$this->dn."' has been saved");
405 /* User has been saved successfully, remove lock from
406 LDAP. */
407 if ($this->dn != "new"){
408 del_lock ($this->dn);
409 }
411 /* In case of new users, ask for a password */
412 if (($set_pass || $this->usertab->password_change_needed()) &&
413 !$this->is_template){
415 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
416 }
418 /* There's no page reload so we have to read new users at
419 this point. */
420 $this->reload ();
421 unset ($this->usertab);
422 $this->usertab= NULL;
423 unset ($_SESSION['objectinfo']);
425 } else {
426 /* Ok. There seem to be errors regarding to the tab data,
427 show message and continue as usual. */
428 show_errors($message);
429 }
430 }
432 /* Generate template list */
433 if ($s_action=="new"){
434 $this->templates= array();
435 $ldap= $this->config->get_ldap_link();
436 foreach ($this->config->departments as $key => $value){
437 $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
438 $acl= get_module_permission($acl, "user", get_people_ou().$value);
439 if (chkacl($acl, "create") == ""){
440 $ldap->cd (get_people_ou().$value);
441 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
443 if ($ldap->count() != 0){
444 while ($attrs= $ldap->fetch()){
445 $this->templates[$ldap->getDN()]=
446 $attrs['uid'][0]." - $key";
447 }
448 $this->templates['none']= _("none");
449 }
450 }
451 }
452 natcasesort ($this->templates);
453 reset ($this->templates);
454 }
456 /* New user/template request */
457 if (($s_action=="new") || ($s_action=="new_tpl")){
458 /* By default we set 'dn' to 'new', all relevant plugins will
459 react on this. */
460 $this->dn= "new";
461 if (isset($this->config->current['IDGEN'])){
462 $this->got_uid= false;
463 } else {
464 $this->got_uid= true;
465 }
467 /* Create new usertab object */
468 $this->usertab= new usertabs($this->config,
469 $this->config->data['TABS']['USERTABS'], $this->dn);
470 $this->usertab->set_acl(array(':all'));
472 /* Take care about templates */
473 if ($s_action=="new_tpl"){
474 $this->is_template= TRUE;
475 $this->usertab->set_template_mode ();
476 } else {
477 $this->is_template= FALSE;
478 }
480 /* Use template if there are any of them */
481 if (count($this->templates) && !isset($_POST['new_template'])){
482 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
483 $smarty->assign("$attr", $this->$attr);
484 }
485 if (isset($_POST['template'])){
486 $smarty->assign("template", $_POST['template']);
487 } else {
488 $smarty->assign("template", "");
489 }
490 $smarty->assign("edit_uid", "");
491 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
492 }
493 }
495 /* Continue template editing */
496 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid'])){
497 $this->sn= $_POST['sn'];
498 $this->givenName= $_POST['givenName'];
500 /* Check for requred values */
501 $message= array();
502 if ($this->sn == "") {
503 $message[]= _("The required field 'Name' is not set.");
504 }
505 if ($this->givenName == "") {
506 $message[]= _("The required field 'Given name' is not set.");
507 }
509 /* Check if dn is used */
510 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
511 $ldap= $this->config->get_ldap_link();
512 $ldap->cd ($dn);
513 $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
514 if ($ldap->count () != 0){
515 $message[]= _("A person with the choosen name is already used in this tree.");
516 }
518 /* Show error message / continue editing */
519 if (count($message) > 0){
520 show_errors ($message);
521 } else {
522 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
523 if (isset($this->config->current['IDGEN']) &&
524 $this->config->current['IDGEN'] != ""){
525 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
526 if (count($uids)){
527 $smarty->assign("edit_uid", "false");
528 $smarty->assign("uids", $uids);
529 $this->uid= current($uids);
530 }
531 } else {
532 $smarty->assign("edit_uid", "");
533 $this->uid= "";
534 }
535 $this->got_uid= true;
536 }
538 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
539 $smarty->assign("$attr", $this->$attr);
540 }
541 if (isset($_POST['template'])){
542 $smarty->assign("template", $_POST['template']);
543 }
544 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
545 }
547 /* No template. Ok. Lets fill data into the normal user dialog */
548 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
549 foreach(array("sn", "givenName", "uid") as $attr){
550 if (isset($_POST[$attr])){
551 $this->usertab->by_object['user']->$attr= $_POST[$attr];
552 }
553 }
554 }
556 /* Finish template preamble */
557 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
559 /* Might not be filled if IDGEN is unset */
560 $this->sn= $_POST['sn'];
561 $this->givenName= $_POST['givenName'];
563 /* Move user supplied data to sub plugins */
564 $this->uid= $_POST['uid'];
565 $this->usertab->uid= $this->uid;
566 $this->usertab->sn= $this->sn;
567 $this->usertab->givenName= $this->givenName;
568 $template_dn= $_POST['template'];
569 $this->usertab->adapt_from_template($template_dn);
570 $template_base= $userfilter['depselect'];//preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
571 $this->usertab->by_object['user']->base= $template_base;
573 /* Set up the users ACL's for this 'dn' */
574 $acl= get_permissions ($template_base, $this->ui->subtreeACL);
575 $this->usertab->set_acl($acl);
576 }
578 /* Show tab dialog if object is present */
579 if ($this->usertab){
580 $display= $this->usertab->execute();
582 /* Don't show buttons if tab dialog requests this */
583 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
584 $display.= "<p style=\"text-align:right\">\n";
585 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
586 $display.= " \n";
587 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
588 $display.= "</p>";
589 }
590 return ($display);
591 }
593 $smarty= get_smarty();
595 /* Check sorting variable */
596 if (!isset($this->usertab) &&
597 !isset($_POST['new_user']) &&
598 !isset($_POST['new_template']) &&
599 !isset($_POST['delete_user']) &&
600 !isset($_POST['setpass_user']) &&
601 !isset($_POST['select_user'])){
602 $this->reload();
603 }
605 /* Check for exeeded sizelimit */
606 if (($message= check_sizelimit()) != ""){
607 return($message);
608 }
610 /* Prepare departments */
611 $options= "";
612 foreach ($this->config->idepartments as $key => $value){
613 if ($userfilter['depselect'] == $key){
614 $options.= "<option selected value='$key'>$value</option>";
615 } else {
616 $options.= "<option value='$key'>$value</option>";
617 }
618 }
620 /* NEW LIST MANAGMENT */
621 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
622 " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
623 " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
624 " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
625 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
626 " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'> ".
627 " <input type='image' align='middle' src='images/list_new.png' title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'> ".
628 " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
629 _("Current base")." <select name='depselect' onChange='mainform.submit()'>$options</select>".
630 " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
631 "</div>";
633 $action= "<input type='image' src='images/edit.png' alt='"._("edit")."' name='user_edit_%KEY%' title='"._("Edit user")."'>";
634 $action.= "<input type='image' src='images/list_password.png' alt='"._("password")."' name='user_chgpw_%KEY%' title='"._("Change password")."'>";
635 $action.= "<input type='image' src='images/editdelete.png' alt='"._("delete")."' name='user_del_%KEY%' title='"._("Delete user")."'>";
639 $divlist = new divlist();
640 $divlist->SetHeader(array(
641 array("string" => " "),
642 array("string" => _("Username")." / "._("Department")),
643 array("string" => _("Properties")),
644 array("string" => _("Actions"), "attach" => "style='border:none'" )));
647 $divlist->SetSummary(_("This table displays all users, in the selected tree."));
648 $divlist->SetEntriesPerPage(20);
650 // Defining Links
651 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
653 foreach($this->departments as $key=> $val){
655 $field1 = array("string" => "<img src='images/folder.png' alt='department'>");
656 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
657 $field3 = array("string" => " ");
658 $field4 = array("string" => " ", "attach" => "style='border:none'");
661 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
662 }
664 // Pictures for Extensions
665 $usrimg = "<img src='images/penguin.png' alt='U' title='"._("GOsa") ."'>";
666 $posiximg = "<img src='images/select_user.png' alt='P' title='"._("Posix") ."'>";
667 $mailimg = "<img src='images/mailto.png' alt='M' title='"._("Mail") ."'>";
668 $fonimg = "<img src='images/select_phone.png' alt='T' title='"._("Phone") ."'>";
669 $faximg = "<img src='images/fax_small.png' alt='F' title='"._("Fax") ."'>";
670 $sambaimg = "<img src='images/select_winstation.png' alt='S' title='"._("Samba") ."'>";
672 // Space
673 $empty = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>";
675 // User and Template Images
676 $userimg = "<img src='images/select_user.png' alt='User' title='%s'>";
677 $tplimg = "<img src='images/select_template.png' alt='Template' title='%s'>";
679 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
681 // Defines Arrays to save User and Templates
682 $tpls = array();
683 $users= array();
685 // Test Every Entry and generate divlist Array
686 foreach($this->list as $key => $val){
688 // Specify Pics for Extensions
689 if(in_array("posixAccount" ,$val['objectClass'])) $posix = $posiximg; else $posix=$empty;
690 if(in_array("gosaMailAccount" ,$val['objectClass'])) $maila = $mailimg; else $maila=$empty;
691 if(in_array("goFonAccount" ,$val['objectClass'])) $fonac = $fonimg; else $fonac=$empty;
692 if(in_array("goFaxAccount" ,$val['objectClass'])) $faxac = $faximg; else $faxac=$empty;
693 if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = $sambaimg; else $samba=$empty;
694 if(in_array("gosaUserTemplate",$val['objectClass'])) $tpl = $tplimg; else $tpl=$userimg;
696 // Generate Array to Add
697 if (isset($val["sn"]) && isset($val["givenName"])){
698 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
699 } else {
700 $display= "[".$val["uid"][0]."]";
701 }
703 $field1 = array("string" => sprintf($tpl,$val['dn']),"attach"=>"style='width:20px;align:middle;'");
704 $field2 = array("string" => sprintf($editlink,$key,$display),"attach"=>"title='".$val['dn']."'");
705 $field3 = array("string" => $usrimg." ".$posix." ".$maila." ".$fonac." ".$faxac." ".$samba,"attach" => "style='width:118px;'");
706 $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='border:none; text-align:right;width:48px'");
708 $add = array($field1,$field2,$field3,$field4);
710 // Template or User
711 if(in_array("gosaUserTemplate",$val['objectClass'])){
712 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
713 }else{
714 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
715 }
716 }
718 // Sort Entries
719 ksort($users);
720 ksort($tpls);
722 // Append Templates
723 foreach($tpls as $key => $val){
724 $divlist->AddEntry( $val, array(""));
725 }
726 // Append Users
727 foreach($users as $key => $val){
728 $divlist->AddEntry( $val, array(""));
729 }
730 /* Show main page */
731 //$smarty->assign("userlist", nl2br(htmlentities($divlist->DrawList())));
732 $smarty->assign("userlist", $divlist->DrawList());
733 $smarty->assign("userlisthead", $listhead);
735 /* END NEW LIST MANAGMENT
736 */
737 $smarty->assign("search_image", get_template_path('images/search.png'));
738 $smarty->assign("tree_image", get_template_path('images/tree.png'));
739 $smarty->assign("infoimage", get_template_path('images/info.png'));
740 $smarty->assign("launchimage", get_template_path('images/launch.png'));
741 $smarty->assign("deplist", $this->config->idepartments);
742 foreach( array("depselect", "regex", "functionalusers", "unixusers",
743 "mailusers", "sambausers", "proxyusers",
744 "faxusers", "templates", "subsearch") as $type){
746 $smarty->assign("$type", $userfilter[$type]);
747 }
749 /* Extend if we are not using javascript */
750 $smarty->assign("apply", apply_filter());
751 $smarty->assign("alphabet", generate_alphabet());
752 $smarty->assign("hint", print_sizelimit_warning());
754 return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
755 }
758 function reload()
759 {
760 /* Get config */
761 $userfilter= get_global('userfilter');
763 /* Set base for all searches */
764 $base= $userfilter['depselect'];
766 /* Regex filter? */
767 if ($userfilter['regex'] != ""){
768 $regex= $userfilter['regex'];
769 } else {
770 $regex= "*";
771 }
773 /* Set filter depending on selection */
774 if ($this->config->current['SAMBAVERSION'] == 3){
775 $samba= "sambaSamAccount";
776 } else {
777 $samba= "sambaAccount";
778 }
780 $filter="";
781 if ($userfilter['functionalusers'] == "checked"){
782 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)(objectClass=goFaxAccount)(objectClass=gosaProxyAccount))))";
783 }
784 if ($userfilter['unixusers'] == "checked"){
785 $filter.= "(objectClass=posixAccount)";
786 }
787 if ($userfilter['mailusers'] == "checked"){
788 $filter.= "(objectClass=gosaMailAccount)";
789 }
790 if ($userfilter['sambausers'] == "checked"){
791 $filter.= "(objectClass=$samba)";
792 }
793 if ($userfilter['proxyusers'] == "checked"){
794 $filter.= "(objectClass=gosaProxyAccount)";
795 }
796 if ($userfilter['faxusers'] == "checked"){
797 $filter.= "(objectClass=goFaxAccount)";
798 }
800 if ($userfilter['templates'] == "checked"){
801 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
802 } else {
803 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
804 }
805 $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
807 /* Generate userlist */
808 $ldap= $this->config->get_ldap_link(TRUE);
809 if ($userfilter['subsearch'] == "checked"){
810 $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
811 } else {
812 $base= get_people_ou().$base;
813 $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
814 }
818 /* NEW LIST MANAGMENT
819 * We also need to search for the departments
820 * So we are able to navigate like in konquerer
821 */
822 $base2 = preg_replace("/ou=people,/i","",$base);
824 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
825 TRUE, $base2, array("ou", "description"), TRUE);
827 $this->departments= array();
829 $tmp = array();
830 foreach ($res3 as $value){
831 $tmp[strtolower($value['dn']).$value['dn']]=$value;
832 }
833 ksort($tmp);
834 foreach($tmp as $value){
835 if($value["description"][0]!=".."){
836 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
837 }else{
838 $this->departments[$value['dn']]=$value["description"][0];
839 }
840 }
841 /* END NEW LIST MANAGMENT
842 */
845 $this->userlist= array();
847 foreach ($this->list as $value){
848 if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
849 if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
850 $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
851 continue;
852 }
853 if (isset($value["givenName"][0]) && isset($value["sn"][0])){
854 $this->userlist[$value["dn"]]= $value["sn"][0].", ".
855 $value["givenName"][0].
856 " [".$value["uid"][0]."]";
857 } else {
858 $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
859 }
860 }
861 }
863 natcasesort ($this->userlist);
864 reset ($this->userlist);
865 }
867 function remove_from_parent()
868 {
869 }
872 /* Check values */
873 function check()
874 {
875 }
878 /* Save to LDAP */
879 function save()
880 {
881 }
883 function adapt_from_template($dn)
884 {
885 }
887 function password_change_needed()
888 {
889 }
891 function show_header($button_text, $text, $disabled= FALSE)
892 {
893 }
895 function remove_lock()
896 {
897 if (isset($this->usertab->dn)){
898 del_lock ($this->usertab->dn);
899 }
900 }
902 }
904 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
905 ?>