1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003-2006 - Cajus Pollmeier <pollmeier@gonicus.de>
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 */
21 /* Include user tab class */
22 require "tabs_user.inc";
25 class userManagement extends plugin
26 {
27 /* Plugin definitions */
28 var $plHeadline= "Users";
29 var $plDescription= "This does something";
31 /* Dialog attributes */
32 var $usertab = NULL;
33 var $ui = NULL;
34 var $acl = "";
35 var $templates = array();
36 var $got_uid = false;
37 var $CopyPasteHandler = NULL;
38 var $CPPasswordChange = ""; // Contains the entry id which should get a new password
39 var $DivListUsers;
41 function userManagement($config, $ui)
42 {
43 /* Save configuration for internal use */
44 $this->config= $config;
45 $this->ui= $ui;
47 /* Copy & Paste handler */
48 if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
49 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
50 }
52 /* Creat dialog object */
53 $this->DivListUsers = new divListUsers($this->config,$this);
55 /* LOCK MESSAGE Vars */
56 $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/");
57 }
60 function execute()
61 {
62 /* Call parent execute */
63 plugin::execute();
65 $smarty = get_smarty(); // Smarty instance
66 $s_action = ""; // Contains the action to be taken
67 $s_entry = ""; // The value for s_action
69 /* Edit entry button pressed? */
70 if( isset($_GET['act']) && $_GET['act'] == "edit_entry" ){
71 $s_action= "edit";
72 $s_entry= validate($_GET['id']);
73 }
75 /* Test relevant POST values */
76 foreach($_POST as $key => $val){
78 /* Get every possible POST combination and set s_action/s_entry accordingly */
79 foreach(array("del" => "user_del", "edit" => "user_edit",
80 "new" => "user_new",
81 "new_tpl" => "user_tplnew",
82 "create_user_from_tpl" => "userfrom_tpl",
83 "change_pw" => "user_chgpw",
84 "editPaste" => "editPaste", "copy" => "copy",
85 "cut" => "cut") as $act => $name){
87 if (preg_match("/".$name.".*/", $key)){
88 $s_action= $act;
89 $s_entry= preg_replace("/".$name."_/i", "", $key);
90 break;
91 }
92 }
94 } /* ...Test POST */
96 /* Remove coordinate prefix from POST, required by some browsers */
97 $s_entry= preg_replace("/_.$/", "", $s_entry);
99 /* Seperate possibly encoded tab and entry, default to tab "user" */
100 if(preg_match("/.*-.*/", $s_entry)){
101 $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
102 $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
103 }else{
104 $s_tab= "user";
105 }
107 /* Display the copy & paste dialog, if it is currently open */
108 $ret = $this->copyPasteHandling($s_action,$s_entry);
109 if($ret){
110 return($ret);
111 }
114 /********************
115 Edit existing entry
116 ********************/
118 /* User wants to edit data? */
119 if (($s_action=="edit") && (!isset($this->usertab->config))){
121 /* Get 'dn' from posted 'uid', must be unique */
122 $this->dn= $this->list[trim($s_entry)]['dn'];
124 /* Check locking, save current plugin in 'back_plugin', so
125 the dialog knows where to return. */
126 if (($user= get_lock($this->dn)) != ""){
127 return(gen_locked_message ($user, $this->dn));
128 }
130 /* Lock the current entry, so everyone will get the
131 above dialog */
132 add_lock ($this->dn, $this->ui->dn);
134 /* Register usertab to trigger edit dialog */
135 $this->usertab= new usertabs($this->config,
136 $this->config->data['TABS']['USERTABS'], $this->dn);
138 /* Switch tab, if it was requested by the user */
139 $this->usertab->current = $s_tab;
141 /* Set ACL and move DN to the headline */
142 $this->usertab->set_acl_base();
143 $_SESSION['objectinfo']= $this->dn;
144 }
147 /********************
148 Edit canceled
149 ********************/
151 /* Reset all relevant data, if we get a _cancel request */
152 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
153 if (isset($this->usertab)){
154 del_lock ($this->usertab->dn);
155 unset ($this->usertab);
156 }
157 $this->usertab= NULL;
158 $this->lognames= array();;
159 $this->sn= "";
160 $this->givenName= "";
161 $this->uid= "";
162 unset ($_SESSION['objectinfo']);
163 }
166 /********************
167 Change password requested
168 ********************/
170 /* Password change requested */
171 if (($s_action == "change_pw") || (!empty($this->CPPasswordChange))){
173 if(!empty($this->CPPasswordChange)){
174 $s_entry = $this->CPPasswordChange;
175 $this->CPPasswordChange = "";
176 }
178 /* Get 'dn' from posted 'uid' */
179 $this->dn= $this->list[trim($s_entry)]['dn'];
181 /* Load permissions for selected 'dn' and check if
182 we're allowed to remove this 'dn' */
183 $ui = get_userinfo();
184 if (preg_match("/w/",$ui->get_permissions($this->dn,"users/password"))){
186 /* User is allowed to change passwords, save 'dn' and 'acl' for next
187 dialog. */
188 $_SESSION['objectinfo']= $this->dn;
189 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
191 } else {
192 /* User is not allowed. Show message and cancel. */
193 print_red (_("You are not allowed to set this users password!"));
194 }
195 }
198 /********************
199 Change password confirmed
200 ********************/
202 /* Perform password change */
203 if (isset($_POST['password_finish'])){
205 /* For security reasons, check if user is allowed to set password again */
206 $ui = get_userinfo();
207 $dn = $this->usertab->dn;
208 $acl = $ui->get_permissions($dn, "users/password");
209 $cacl= $ui->get_permissions($dn, "users/user");
212 if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
214 /* Check input and feed errors into 'message' */
215 $message= array();
217 /* Sanity checks... */
218 if ($_POST['new_password'] != $_POST['repeated_password']){
220 /* Matching passwords in new and repeated? */
221 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
222 } else {
224 /* Empty password is not permitted by default. */
225 if ($_POST['new_password'] == ""){
226 $message[]= _("The password you've entered as 'New password' is empty.");
227 }
228 }
230 /* Errors, or password change? */
231 if (count($message) != 0){
233 /* Show error message and continue editing */
234 show_errors ($message);
235 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
236 }
238 $config= $this->config;
239 $ldap_ui= $this->config->get_ldap_link();
240 if(isset($this->usertab->dn)){
241 $ldap_ui->cat($this->usertab->dn,array("uid"));
242 $user = $ldap_ui->fetch();
243 }else{
244 $ldap_ui->cat($this->dn,array("uid"));
245 $user = $ldap_ui->fetch();
246 }
247 if((is_array($user))&&(isset($user['uid']))){
248 $username= $user['uid'][0];
249 }
251 /* Set password, perform required steps */
252 if ($this->usertab){
253 if ($this->usertab->password_change_needed()){
254 $obj= $this->usertab->by_object['user'];
255 change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
256 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
257 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
258 }
260 gosa_log ("Password for '".$this->usertab->dn."' has been changed");
261 unset($this->usertab);
262 $this->usertab= NULL;
263 }
264 } else {
265 change_password ($this->dn, $_POST['new_password']);
266 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
267 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
268 }
270 gosa_log ("Password for '".$this->dn."' has been changed");
271 }
272 } else {
274 /* Missing permissions, show message */
275 print_red (_("You are not allowed to set this users password!"));
276 }
277 /* Clean session, delete lock */
278 del_lock ($this->dn);
279 unset ($this->usertab);
280 $this->usertab= NULL;
281 $this->lognames= array();;
282 $this->sn= "";
283 $this->givenName= "";
284 $this->uid= "";
285 unset ($_SESSION['objectinfo']);
286 }
289 /********************
290 Delete entry requested, display confirm dialog
291 ********************/
293 /* Remove user was requested */
294 if ($s_action=="del"){
296 /* Get 'dn' from posted 'uid' */
297 $this->dn= $this->list[trim($s_entry)]['dn'];
299 /* Load permissions for selected 'dn' and check if
300 we're allowed to remove this 'dn' */
302 /* Check locking, save current plugin in 'back_plugin', so
303 the dialog knows where to return. */
304 if (($user= get_lock($this->dn)) != ""){
305 return(gen_locked_message ($user, $this->dn));
306 }
308 /* Lock the current entry, so nobody will edit it during deletion */
309 add_lock ($this->dn, $this->ui->dn);
310 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
311 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
312 }
315 /********************
316 Delete entry confirmed
317 ********************/
319 /* Confirmation for deletion has been passed. User should be deleted. */
320 if (isset($_POST['delete_user_confirm'])){
322 /* Some nice guy may send this as POST, so we've to check
323 for the permissions again. */
325 $ui = get_userinfo();
326 $acl = $ui->get_permissions($this->dn, "users/user");
328 if (preg_match('/d/', $acl)){
330 /* Delete request is permitted, perform LDAP action */
331 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
332 $this->usertab->set_acl_base();
333 $this->usertab->delete ();
334 gosa_log ("User object '".$this->dn."' has been removed");
335 unset ($this->usertab);
336 $this->usertab= NULL;
337 } else {
339 /* Normally this shouldn't be reached, send some extra
340 logs to notify the administrator */
341 print_red (_("You are not allowed to delete this user!"));
343 if(isset($this->ui->uid)){
344 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
345 }
346 }
348 /* Remove lock file after successfull deletion */
349 del_lock ($this->dn);
350 }
353 /********************
354 Delete entry Canceled
355 ********************/
357 /* Delete user canceled? */
358 if (isset($_POST['delete_cancel'])){
359 del_lock ($this->dn);
360 }
363 /********************
364 Edit entry finished (Save)
365 ********************/
367 /* Finish user edit is triggered by the tabulator dialog, so
368 the user wants to save edited data. Check and save at this
369 point. */
370 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
372 /* Check tabs, will feed message array */
373 $this->usertab->last= $this->usertab->current;
374 $this->usertab->save_object();
375 $message= $this->usertab->check();
377 /* Save, or display error message? */
378 if (count($message) == 0){
380 /* No errors. Go ahead and prepare to ask for a password
381 in case we're creating a new user. 'dn' will be 'new'
382 in this case. It is set to the correct value later. */
383 if ($this->dn == "new"){
384 $set_pass= 1;
385 } else {
386 $set_pass= 0;
387 }
389 /* Save user data to ldap */
390 if($this->usertab->save() == 1){
391 gosa_log ("User object '".$this->dn."' saving failed.");
392 return;
393 }
394 gosa_log ("User object '".$this->dn."' has been saved");
396 if (!isset($_POST['edit_apply'])){
397 /* User has been saved successfully, remove lock from LDAP. */
398 if ($this->dn != "new"){
399 del_lock ($this->dn);
400 }
402 /* In case of new users, ask for a password, skip this for templates */
403 if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
404 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
405 }
407 unset ($this->usertab);
408 $this->usertab= NULL;
409 unset ($_SESSION['objectinfo']);
410 }
411 } else {
412 /* Ok. There seem to be errors regarding to the tab data,
413 show message and continue as usual. */
414 show_errors($message);
415 }
416 }
419 /********************
420 We want to create a new user, so fetch all available user templates
421 ********************/
423 /* Generate template list */
424 if (($s_action=="new")||($s_action=="create_user_from_tpl")){
426 $this->templates= array();
427 $ldap= $this->config->get_ldap_link();
429 /* Create list of templates */
430 foreach ($this->config->departments as $key => $value){
432 /* Get acls from different ou's */
433 $ui = get_userinfo();
434 $acl = $ui->get_permissions("cn=dummy,".$this->DivListUsers->selectedBase,"users/user") ;
436 /* If creation of a new user is allowed, append this template */
437 if (preg_match("/r/",$acl)){
439 /* Search all templates from the current dn */
440 $ldap->cd (get_people_ou().$value);
441 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
443 /* Append */
444 if ($ldap->count() != 0){
445 while ($attrs= $ldap->fetch()){
446 $this->templates[$ldap->getDN()]=
447 $attrs['uid'][0]." - ".@LDAP::fix($key);
448 }
449 $this->templates['none']= _("none");
450 }
451 }
452 }
454 /* Sort templates */
455 natcasesort ($this->templates);
456 reset ($this->templates);
457 }
460 /********************
461 Create a new user,template, user from template
462 ********************/
464 /* Check selected options for template */
465 if (isset($_POST['template_continue'])){
466 $message = array();
467 if(!isset($_POST['template']) || (empty($_POST['template']))){
468 $message[] = _("Please select a valid template.");
469 }
470 if(!isset($_POST['sn']) || (empty($_POST['sn']))){
471 $message[]= _("The required field 'Name' is not set.");
472 }
473 if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
474 $message[]= _("The required field 'Given name' is not set.");
475 }
477 /* Show error message / continue editing */
478 if (count($message) > 0){
479 show_errors ($message);
481 foreach(array("sn", "givenName", "uid", "template") as $attr){
482 if(isset($_POST[$attr])){
483 $smarty->assign("$attr", $_POST[$attr]);
484 }else{
485 $smarty->assign("$attr", "");
486 }
487 }
488 $smarty->assign("templates",$this->templates);
489 $smarty->assign("got_uid",$this->got_uid);
490 $smarty->assign("edit_uid",false);
491 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
493 }
494 }
496 /* New user/template request */
497 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
498 /* By default we set 'dn' to 'new', all relevant plugins will
499 react on this. */
500 $this->dn= "new";
502 if (isset($this->config->current['IDGEN'])){
503 $this->got_uid= false;
504 } else {
505 $this->got_uid= true;
506 }
508 /* Create new usertab object */
509 $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
510 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
511 $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
513 /* Take care about templates */
514 if ($s_action=="new_tpl"){
515 $this->is_template= TRUE;
516 $this->usertab->set_template_mode ();
517 } else {
518 $this->is_template= FALSE;
519 }
521 /* Use template if there are any of them */
522 if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
523 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
524 $smarty->assign("$attr", $this->$attr);
525 }
526 if ($s_action=="create_user_from_tpl"){
527 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
528 } else {
529 $smarty->assign("template", "none");
530 }
531 $smarty->assign("edit_uid", "");
532 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
533 }
534 }
536 /********************
537 Template selected continue edit
538 ********************/
540 /* Continue template editing */
541 if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
543 $this->sn = $_POST['sn'];
544 $this->givenName = $_POST['givenName'];
546 /* Check for requred values */
547 $message= array();
548 if ($this->sn == "") {
549 $message[]= _("The required field 'Name' is not set.");
550 }
551 if ($this->givenName == "") {
552 $message[]= _("The required field 'Given name' is not set.");
553 }
555 /* Check if dn is used */
556 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
557 $ldap= $this->config->get_ldap_link();
558 $ldap->cd ($dn);
559 $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
560 if ($ldap->count () != 0){
561 $message[]= _("A person with the choosen name is already used in this tree.");
562 }
564 /* Show error message / continue editing */
565 if (count($message) > 0){
566 show_errors ($message);
567 } else {
568 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
569 if (isset($this->config->current['IDGEN']) &&
570 $this->config->current['IDGEN'] != ""){
571 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
572 if (count($uids)){
573 $smarty->assign("edit_uid", "false");
574 $smarty->assign("uids", $uids);
575 $this->uid= current($uids);
576 }
577 } else {
578 $smarty->assign("edit_uid", "");
579 $this->uid= "";
580 }
581 $this->got_uid= true;
582 }
584 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
585 $smarty->assign("$attr", $this->$attr);
586 }
587 if (isset($_POST['template'])){
588 $smarty->assign("template", $_POST['template']);
589 }
590 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
591 }
593 /********************
594 No template selected continue edit
595 ********************/
597 /* No template. Ok. Lets fill data into the normal user dialog */
598 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
599 foreach(array("sn", "givenName", "uid") as $attr){
600 if (isset($_POST[$attr])){
601 $this->usertab->by_object['user']->$attr= $_POST[$attr];
602 }
603 }
604 }
607 /********************
608 Template selected continue edit
609 ********************/
611 /* Finish template preamble */
612 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
614 /* Might not be filled if IDGEN is unset */
615 $this->sn = $_POST['sn'];
616 $this->givenName = $_POST['givenName'];
618 /* Move user supplied data to sub plugins */
619 $this->uid = $_POST['uid'];
620 $this->usertab->uid = $this->uid;
621 $this->usertab->sn = $this->sn;
622 $this->usertab->givenName = $this->givenName;
623 $template_dn = $_POST['template'];
624 $this->usertab->adapt_from_template($template_dn);
625 $template_base = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
626 $this->usertab->by_object['user']->base= $template_base;
627 }
630 /********************
631 If no template was selected set base
632 ********************/
634 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
635 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
636 }
639 /********************
640 Display subdialog
641 ********************/
643 /* Show tab dialog if object is present */
644 if(isset($this->usertab->config)){
645 $display= $this->usertab->execute();
647 /* Don't show buttons if tab dialog requests this */
648 if(isset($this->usertab->by_object)){
649 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
650 $display.= "<p style=\"text-align:right\">\n";
651 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
652 $display.= " \n";
653 if ($this->dn != "new"){
654 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
655 $display.= " \n";
656 }
657 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
658 $display.= "</p>";
659 }
660 }
661 return ($display);
662 }
664 /* Check if there is a snapshot dialog open */
665 $base = $this->DivListUsers->selectedBase;
666 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
667 return($str);
668 }
670 /* Return rendered main page */
671 /* Display dialog with system list */
672 $this->DivListUsers->parent = $this;
673 $this->DivListUsers->execute();
675 /* Add departments if subsearch is disabled */
676 if(!$this->DivListUsers->SubSearch){
677 $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4);
678 }
679 $this->reload();
680 $this->DivListUsers->setEntries($this->list);
681 return($this->DivListUsers->Draw());
682 }
685 /* Return departments, that will be included within snapshot detection */
686 function get_used_snapshot_bases()
687 {
688 return(array(get_people_ou().$this->DivListUsers->selectedBase));
689 }
692 function reload()
693 {
694 /* Set base for all searches */
695 $base= $this->DivListUsers->selectedBase;
696 $this->list =array();
698 /* Get filter configuration */
699 $Regex = $this->DivListUsers->Regex;
700 $SubSearch = $this->DivListUsers->SubSearch;
701 $ShowTemplates = $this->DivListUsers->ShowTemplates;
702 $ShowFunctionalUsers = $this->DivListUsers->ShowFunctionalUsers;
703 $ShowUnixUsers = $this->DivListUsers->ShowUnixUsers;
704 $ShowMailUsers = $this->DivListUsers->ShowMailUsers;
705 $ShowSambaUsers = $this->DivListUsers->ShowSambaUsers;
706 $ShowProxyUsers = $this->DivListUsers->ShowProxyUsers;
708 /* Setup filter depending on selection */
709 $filter="";
710 if ($this->config->current['SAMBAVERSION'] == 3){
711 $samba= "sambaSamAccount";
712 } else {
713 $samba= "sambaAccount";
714 }
716 if ($ShowFunctionalUsers){
717 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
718 "(objectClass=gosaMailAccount)(objectClass=$samba)".
719 "(objectClass=gosaProxyAccount))))";
720 }
721 if ($ShowUnixUsers){
722 $filter.= "(objectClass=posixAccount)";
723 }
724 if ($ShowMailUsers){
725 $filter.= "(objectClass=gosaMailAccount)";
726 }
727 if ($ShowSambaUsers){
728 $filter.= "(objectClass=$samba)";
729 }
730 if ($ShowProxyUsers){
731 $filter.= "(objectClass=gosaProxyAccount)";
732 }
733 if ($ShowTemplates){
734 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
735 } else {
736 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
737 }
738 $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
740 /* Generate userlist */
741 $ldap= $this->config->get_ldap_link(TRUE);
743 if ($SubSearch){
744 $ListTemp = get_list($filter, "users", $base,
745 array("uid", "givenName", "sn", "objectClass"), GL_SUBSEARCH | GL_SIZELIMIT);
746 } else {
747 $base= get_people_ou().$base;
748 $ListTemp = get_list($filter, "users", $base,
749 array("uid", "givenName", "sn", "objectClass"), GL_SIZELIMIT);
750 }
751 $SortTemp = array();
752 $List = array();
753 foreach($ListTemp as $Key => $Entry){
754 // Generate caption for rows
755 if (isset($Entry["sn"]) && isset($Entry["givenName"])){
756 $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
757 } else {
758 $display= "[".$Entry["uid"][0]."]";
759 }
761 $display = strtolower($display);
762 $List[$display] = $Entry;
763 $SortTemp[$display] = $display;
764 }
765 sort($SortTemp);
766 reset($SortTemp);
768 $this->list = array();
769 foreach($SortTemp as $Key){
770 $this->list[] = $List[$Key];
771 }
772 }
774 function remove_lock()
775 {
776 /* Remove user lock if a DN is marked as "currently edited" */
777 if (isset($this->usertab->dn)){
778 del_lock ($this->usertab->dn);
779 }
780 }
783 /* Perform copy & paste requests
784 If copy&paste is in progress this returns a dialog to fix required attributes
785 */
786 function copyPasteHandling($s_action,$s_entry)
787 {
788 /* Only perform copy/paste if it is enabled */
789 if($this->CopyPasteHandler){
791 /* Prepare current object to be pasted */
792 if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){
794 $this->CopyPasteHandler->save_object();
795 $this->CopyPasteHandler->SetVar("base", $this->DivListUsers->selectedBase);
797 /* Execute copy & paste dialog and display returned data, normaly a dialog which allows
798 us to solve all attribute mismatches for this object.
799 If nothing is returned, copy & paste was succesfully or aborted */
800 if(($ret= $this->CopyPasteHandler->execute())){
801 return ($ret);
802 }
804 /* Use the last dn to search for it's ID in the newly generated list. */
805 $dn= $this->CopyPasteHandler->lastdn;
806 foreach($this->list as $id => $entry){
807 if($entry['dn'] == $dn){
808 $s_entry= $id;
809 break;
810 }
811 }
813 /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
814 if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
815 $this->CPPasswordChange = $s_entry;
816 }
817 }
819 /* Copy selected object
820 Create a new empty object and the current selected object.
821 Send both to copy&paste class*/
822 if($s_action == "copy"){
823 $this->CopyPasteHandler->Clear();
824 $dn= $this->list[trim($s_entry)]['dn'];
825 $obj = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
826 $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new");
827 $this->CopyPasteHandler->Copy($obj,$objNew);
828 }
830 /* Cut selected object.
831 Open user object and send it to the copy & paste handler */
832 if($s_action == "cut"){
833 $this->CopyPasteHandler->Clear();
834 $dn= $this->list[trim($s_entry)]['dn'];
835 $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
836 $this->CopyPasteHandler->Cut($obj);
837 }
838 }
839 }
841 function save_object()
842 {
843 /* Handle divlist filter && department selection*/
844 if(!is_object($this->usertab)){
845 $this->DivListUsers->save_object();
846 }
847 }
849 /* A set of disabled and therefore overloaded functions. They are
850 not needed in this class. */
851 function remove_from_parent() { }
852 function check() { }
853 function save() { }
854 function adapt_from_template($dn) { }
855 function password_change_needed() { }
857 } /* ... class userManagement */
858 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
859 ?>