Code

8e7f6415f5d3211649881503dfbdf87600bf5d9c
[gosa.git] / plugins / admin / users / class_userManagement.inc
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                     "change_pw" => "user_chgpw", 
83                     "editPaste" => "editPaste",   "copy"      => "copy",
84                     "cut"       => "cut") as $act => $name){
86         if (preg_match("/".$name.".*/", $key)){
87           $s_action= $act;
88           $s_entry= preg_replace("/".$name."_/i", "", $key);
89           break;
90         }
91       }
92       
93     } /* ...Test POST */
95     /* Remove coordinate prefix from POST, required by some browsers */
96     $s_entry= preg_replace("/_.$/", "", $s_entry);
98     /* Seperate possibly encoded tab and entry, default to tab "user" */
99     if(preg_match("/.*-.*/", $s_entry)){
100       $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
101       $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
102     }else{
103       $s_tab= "user";
104     }
106     /* Display the copy & paste dialog, if it is currently open */
107     $ret = $this->copyPasteHandling($s_action,$s_entry);
108     if($ret){
109       return($ret);
110     }
113     /********************
114       Edit existing entry 
115      ********************/
117     /* User wants to edit data? */
118     if (($s_action=="edit") && (!isset($this->usertab->config))){
120       /* Get 'dn' from posted 'uid', must be unique */
121       $this->dn= $this->list[trim($s_entry)]['dn'];
123       /* Check locking, save current plugin in 'back_plugin', so
124          the dialog knows where to return. */
125       if (($user= get_lock($this->dn)) != ""){
126         return(gen_locked_message ($user, $this->dn));
127       }
129       /* Lock the current entry, so everyone will get the
130          above dialog */
131       add_lock ($this->dn, $this->ui->dn);
133       /* Set up the users ACL's for this 'dn' */
134       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
136       /* Register usertab to trigger edit dialog */
137       $this->usertab= new usertabs($this->config, 
138           $this->config->data['TABS']['USERTABS'], $this->dn);
140       /* Switch tab, if it was requested by the user */
141       $this->usertab->current = $s_tab;
143       /* Set ACL and move DN to the headline */
144 #      $this->usertab->set_acl_base();
145       $_SESSION['objectinfo']= $this->dn;
146     }
149     /********************
150       Edit canceled 
151      ********************/
153     /* Reset all relevant data, if we get a _cancel request */
154     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
155       if (isset($this->usertab)){
156         del_lock ($this->usertab->dn);
157         unset ($this->usertab);
158       }
159       $this->usertab= NULL;
160       $this->lognames= array();;
161       $this->sn= "";
162       $this->givenName= "";
163       $this->uid= "";
164       unset ($_SESSION['objectinfo']);
165     }
168     /********************
169       Change password requested  
170      ********************/
172     /* Password change requested */
173     if (($s_action == "change_pw") || (!empty($this->CPPasswordChange))){
175       if(!empty($this->CPPasswordChange)){
176         $s_entry = $this->CPPasswordChange;
177         $this->CPPasswordChange = "";
178       }
180       /* Get 'dn' from posted 'uid' */
181       $this->dn= $this->list[trim($s_entry)]['dn'];
183       /* Load permissions for selected 'dn' and check if
184          we're allowed to remove this 'dn' */
185       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
186       $acl= get_module_permission($acl, "user", $this->dn);
187       if (chkacl($acl, "password") == ""){
189         /* User is allowed to change passwords, save 'dn' and 'acl' for next
190            dialog. */
191         $this->acl= $acl;
192         $_SESSION['objectinfo']= $this->dn;
193         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
195       } else {
196         /* User is not allowed. Show message and cancel. */
197         print_red (_("You are not allowed to set this users password!"));
198       }
199     }
202     /********************
203       Change password confirmed
204      ********************/
206     /* Perform password change */
207     if (isset($_POST['password_finish'])){
209       /* For security reasons, check if user is allowed to set password again */
210       if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
212         /* Check input and feed errors into 'message' */
213         $message= array();
215         /* Sanity checks... */
216         if ($_POST['new_password'] != $_POST['repeated_password']){
218           /* Matching passwords in new and repeated? */
219           $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
220         } else {
222           /* Empty password is not permitted by default. */
223           if ($_POST['new_password'] == ""){
224             $message[]= _("The password you've entered as 'New password' is empty.");
225           }
226         }
228         /* Errors, or password change? */
229         if (count($message) != 0){
231           /* Show error message and continue editing */
232           show_errors ($message);
233           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
234         }
236         $config= $this->config;
237         $ldap_ui= $this->config->get_ldap_link();
238         if(isset($this->usertab->dn)){
239           $ldap_ui->cat($this->usertab->dn,array("uid"));
240           $user = $ldap_ui->fetch();
241         }else{
242           $ldap_ui->cat($this->dn,array("uid"));
243           $user = $ldap_ui->fetch();
244         }
245         if((is_array($user))&&(isset($user['uid']))){
246           $username= $user['uid'][0];
247         }
249         /* Set password, perform required steps */
250         if ($this->usertab){
251           if ($this->usertab->password_change_needed()){
252             $obj= $this->usertab->by_object['user'];
253             change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
254             if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
255               exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
256             }
258             gosa_log ("Password for '".$this->usertab->dn."' has been changed");
259             unset($this->usertab);
260             $this->usertab= NULL;
261           }
262         } else {
263           change_password ($this->dn, $_POST['new_password']);
264           if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
265             exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
266           }
268           gosa_log ("Password for '".$this->dn."' has been changed");
269         }
270       } else {
272         /* Missing permissions, show message */
273         print_red (_("You are not allowed to set this users password!"));
274       }
276       /* Clean session, delete lock */
277       del_lock ($this->dn);
278       unset ($this->usertab);
279       $this->usertab= NULL;
280       $this->lognames= array();;
281       $this->sn= "";
282       $this->givenName= "";
283       $this->uid= "";
284       unset ($_SESSION['objectinfo']);
285     }
288     /********************
289       Delete entry requested, display confirm dialog
290      ********************/
292     /* Remove user was requested */
293     if ($s_action=="del"){
295       /* Get 'dn' from posted 'uid' */
296       $this->dn= $this->list[trim($s_entry)]['dn'];
298       /* Load permissions for selected 'dn' and check if
299          we're allowed to remove this 'dn' */
300       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
301       $this->acl= get_module_permission($acl, "user", $this->dn);
302       if (chkacl($this->acl, "delete") == ""){
304         /* Check locking, save current plugin in 'back_plugin', so
305            the dialog knows where to return. */
306         if (($user= get_lock($this->dn)) != ""){
307           return(gen_locked_message ($user, $this->dn));
308         }
310         /* Lock the current entry, so nobody will edit it during deletion */
311         add_lock ($this->dn, $this->ui->dn);
312         $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
313         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
314       } else {
316         /* Obviously the user isn't allowed to delete. Show message and
317            clean session. */
318         print_red (_("You are not allowed to delete this user!"));
319       }
320     }
323     /********************
324       Delete entry confirmed 
325      ********************/
327     /* Confirmation for deletion has been passed. User should be deleted. */
328     if (isset($_POST['delete_user_confirm'])){
330       /* Some nice guy may send this as POST, so we've to check
331          for the permissions again. */
332       if (chkacl($this->acl, "delete") == ""){
334         /* Delete request is permitted, perform LDAP action */
335         $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
336         $this->usertab->set_acl(array($this->acl));
337         $this->usertab->delete ();
338         gosa_log ("User object '".$this->dn."' has been removed");
339         unset ($this->usertab);
340         $this->usertab= NULL;
341       } else {
343         /* Normally this shouldn't be reached, send some extra
344            logs to notify the administrator */
345         print_red (_("You are not allowed to delete this user!"));
347         if(isset($this->ui->uid)){
348           gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
349         }
350       }
352       /* Remove lock file after successfull deletion */
353       del_lock ($this->dn);
354     }
356     
357     /********************
358       Delete entry Canceled 
359      ********************/
361     /* Delete user canceled? */
362     if (isset($_POST['delete_cancel'])){
363       del_lock ($this->dn);
364     }
367     /********************
368       Edit entry finished (Save) 
369      ********************/
371     /* Finish user edit is triggered by the tabulator dialog, so
372        the user wants to save edited data. Check and save at this
373        point. */
374     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
376       /* Check tabs, will feed message array */
377       $this->usertab->last= $this->usertab->current;
378       $this->usertab->save_object();
379       $message= $this->usertab->check();
381       /* Save, or display error message? */
382       if (count($message) == 0){
384         /* No errors. Go ahead and prepare to ask for a password
385            in case we're creating a new user. 'dn' will be 'new'
386            in this case. It is set to the correct value later. */
387         if ($this->dn == "new"){
388           $set_pass= 1;
389         } else {
390           $set_pass= 0;
391         }
393         /* Save user data to ldap */
394         if($this->usertab->save() == 1){
395           gosa_log ("User object '".$this->dn."' saving failed.");
396           return;
397         }
398         gosa_log ("User object '".$this->dn."' has been saved");
400         if (!isset($_POST['edit_apply'])){
401           /* User has been saved successfully, remove lock from LDAP. */
402           if ($this->dn != "new"){
403             del_lock ($this->dn);
404           }
406           /* In case of new users, ask for a password, skip this for templates */
407           if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
408             return($smarty->fetch(get_template_path('password.tpl', TRUE)));
409           }
411           unset ($this->usertab);
412           $this->usertab= NULL;
413           unset ($_SESSION['objectinfo']);
414         }
415       } else {
416         /* Ok. There seem to be errors regarding to the tab data,
417            show message and continue as usual. */
418         show_errors($message);
419       }
420     }
423     /********************
424       We want to create a new user, so fetch all available user templates 
425      ********************/
427     /* Generate template list */
428     if (($s_action=="new")||($s_action=="create_user_from_tpl")){
430       $this->templates= array();
431       $ldap= $this->config->get_ldap_link();
433       /* Create list of templates */
434       foreach ($this->config->departments as $key => $value){
435     
436         /* Get acls from different ou's */
437         $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
438         $acl= get_module_permission($acl, "user", get_people_ou().$value);
439   
440         /* If creation of a new user is allowed, append this template */
441         if (chkacl($acl, "create") == ""){
442           
443           /* Search all templates from the current dn */
444           $ldap->cd (get_people_ou().$value);
445           $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
447           /* Append */
448           if ($ldap->count() != 0){
449             while ($attrs= $ldap->fetch()){
450               $this->templates[$ldap->getDN()]=
451                 $attrs['uid'][0]." - ".@LDAP::fix($key);
452             }
453             $this->templates['none']= _("none");
454           }
455         }
456       }
458       /* Sort templates */
459       natcasesort ($this->templates);
460       reset ($this->templates);
461     }
464     /********************
465       Create a new user,template, user from template 
466      ********************/
468     /* New user/template request */
469     if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
470       /* By default we set 'dn' to 'new', all relevant plugins will
471          react on this. */
472       $this->dn= "new";
473       
474       if (isset($this->config->current['IDGEN'])){
475         $this->got_uid= false;
476       } else {
477         $this->got_uid= true;
478       }
480       /* Create new usertab object */
481       $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
482       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
483       $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
485       /* Take care about templates */
486       if ($s_action=="new_tpl"){
487         $this->is_template= TRUE;
488         $this->usertab->set_template_mode ();
489       } else {
490         $this->is_template= FALSE;
491       }
493       /* Use template if there are any of them */
494       if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
495         foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
496           $smarty->assign("$attr", $this->$attr);
497         }
498         if ($s_action=="create_user_from_tpl"){
499           $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
500         } else {
501           $smarty->assign("template", "none");
502         }
503         $smarty->assign("edit_uid", "");
504         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
505       }
506     }
508     /********************
509       Template selected continue edit
510      ********************/
512     /* Continue template editing */
513     if ((isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid']))){
514       $this->sn             = $_POST['sn'];
515       $this->givenName      = $_POST['givenName'];
517       /* Check for requred values */
518       $message= array();
519       if ($this->sn == "") {
520         $message[]= _("The required field 'Name' is not set.");
521       }
522       if ($this->givenName == "") {
523         $message[]= _("The required field 'Given name' is not set.");
524       }
526       /* Check if dn is used */
527       $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
528       $ldap= $this->config->get_ldap_link();
529       $ldap->cd ($dn);
530       $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
531       if ($ldap->count () != 0){
532         $message[]= _("A person with the choosen name is already used in this tree.");
533       }
535       /* Show error message / continue editing */
536       if (count($message) > 0){
537         show_errors ($message);
538       } else {
539         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
540         if (isset($this->config->current['IDGEN']) &&
541             $this->config->current['IDGEN'] != ""){
542           $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
543           if (count($uids)){
544             $smarty->assign("edit_uid", "false");
545             $smarty->assign("uids", $uids);
546             $this->uid= current($uids);
547           }
548         } else {
549           $smarty->assign("edit_uid", "");
550           $this->uid= "";
551         }
552         $this->got_uid= true;
553       }
555       foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
556         $smarty->assign("$attr", $this->$attr);
557       }
558       if (isset($_POST['template'])){
559         $smarty->assign("template", $_POST['template']);
560       }
561       return($smarty->fetch(get_template_path('template.tpl', TRUE)));
562     }
565     /********************
566       No template selected continue edit
567      ********************/
569     /* No template. Ok. Lets fill data into the normal user dialog */
570     if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
571       foreach(array("sn", "givenName", "uid") as $attr){
572         if (isset($_POST[$attr])){
573           $this->usertab->by_object['user']->$attr= $_POST[$attr];
574         }
575       }
576     }
579     /********************
580       Template selected continue edit
581      ********************/
583     /* Finish template preamble */
584     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
586       /* Might not be filled if IDGEN is unset */
587       $this->sn                 = $_POST['sn'];
588       $this->givenName          = $_POST['givenName'];
590       /* Move user supplied data to sub plugins */
591       $this->uid                = $_POST['uid'];
592       $this->usertab->uid       = $this->uid;
593       $this->usertab->sn        = $this->sn;
594       $this->usertab->givenName = $this->givenName;
595       $template_dn              = $_POST['template'];
596       $this->usertab->adapt_from_template($template_dn);
597       $template_base            = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
598       $this->usertab->by_object['user']->base= $template_base;
600       /* Set up the users ACL's for this 'dn' */
601       $acl= get_permissions ($template_base, $this->ui->subtreeACL);
602       $this->usertab->set_acl($acl);
603     }
604    
605  
606     /********************
607       If no template was selected set base
608      ********************/
610     if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
611       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
612     }
615     /********************
616       Display subdialog 
617      ********************/
619     /* Show tab dialog if object is present */
620     if(isset($this->usertab->config)){
621       $display= $this->usertab->execute();
623       /* Don't show buttons if tab dialog requests this */
624       if(isset($this->usertab->by_object)){
625         if (!$this->usertab->by_object[$this->usertab->current]->dialog){
626           $display.= "<p style=\"text-align:right\">\n";
627           $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
628           $display.= "&nbsp;\n";
629           if ($this->dn != "new"){
630             $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
631             $display.= "&nbsp;\n";
632           }
633           $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
634           $display.= "</p>";
635         }
636       }
637       return ($display);
638     }
639     
640     /* Check if there is a snapshot dialog open */
641     $base = $this->DivListUsers->selectedBase;
642     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
643       return($str);
644     }
645   
646     /* Return rendered main page */
647         /* Display dialog with system list */
648     $this->DivListUsers->parent = $this;
649     $this->DivListUsers->execute();
651     /* Add departments if subsearch is disabled */
652     if(!$this->DivListUsers->SubSearch){
653       $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4);
654     }
655     $this->reload();
656     $this->DivListUsers->setEntries($this->list);
657     return($this->DivListUsers->Draw());
658   }
661   /* Return departments, that will be included within snapshot detection */
662   function get_used_snapshot_bases()
663   {
664     return(array(get_people_ou().$this->DivListUsers->selectedBase));
665   }  
668   function reload()
669   {
670     /* Set base for all searches */
671     $base= $this->DivListUsers->selectedBase;
672     $this->list =array();
674     /* Get filter configuration */
675     $Regex                = $this->DivListUsers->Regex;
676     $SubSearch            = $this->DivListUsers->SubSearch;
677     $ShowTemplates        = $this->DivListUsers->ShowTemplates;
678     $ShowFunctionalUsers  = $this->DivListUsers->ShowFunctionalUsers;
679     $ShowUnixUsers        = $this->DivListUsers->ShowUnixUsers;
680     $ShowMailUsers        = $this->DivListUsers->ShowMailUsers;
681     $ShowSambaUsers       = $this->DivListUsers->ShowSambaUsers;
682     $ShowProxyUsers       = $this->DivListUsers->ShowProxyUsers;
684     /* Setup filter depending on selection */
685     $filter="";
686     if ($this->config->current['SAMBAVERSION'] == 3){
687       $samba= "sambaSamAccount";
688     } else {
689       $samba= "sambaAccount";
690     }
692     if ($ShowFunctionalUsers){
693       $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
694                 "(objectClass=gosaMailAccount)(objectClass=$samba)".
695                 "(objectClass=gosaProxyAccount))))";
696     }
697     if ($ShowUnixUsers){
698       $filter.= "(objectClass=posixAccount)";
699     }
700     if ($ShowMailUsers){
701       $filter.= "(objectClass=gosaMailAccount)";
702     }
703     if ($ShowSambaUsers){
704       $filter.= "(objectClass=$samba)";
705     }
706     if ($ShowProxyUsers){
707       $filter.= "(objectClass=gosaProxyAccount)";
708     }
709     if ($ShowTemplates){
710       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
711     } else {
712       $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
713     }
714     $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
716     /* Generate userlist */
717     $ldap= $this->config->get_ldap_link(TRUE);
719     if ($SubSearch){
720       $ListTemp =  get_list($filter, "users", $base,
721                             array("uid", "givenName", "sn", "objectClass"), GL_SUBSEARCH | GL_SIZELIMIT);
722     } else {
723       $base= get_people_ou().$base;
724       $ListTemp = get_list($filter, "users", $base, 
725                             array("uid", "givenName", "sn", "objectClass"), GL_SIZELIMIT);
726     }
727     $SortTemp = array();
728     $List = array();
729     foreach($ListTemp as $Key => $Entry){
730        // Generate caption for rows
731       if (isset($Entry["sn"]) && isset($Entry["givenName"])){
732         $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
733       } else {
734         $display= "[".$Entry["uid"][0]."]";
735       }
737       $display = strtolower($display);
738       $List[$display] = $Entry;
739       $SortTemp[$display] = $display;
740     }
741     sort($SortTemp);
742     reset($SortTemp);
744     $this->list = array();
745     foreach($SortTemp as $Key){
746       $this->list[] = $List[$Key];
747     }
748   }
750   function remove_lock()
751   {
752     /* Remove user lock if a DN is marked as "currently edited" */
753     if (isset($this->usertab->dn)){
754       del_lock ($this->usertab->dn);
755     }
756   }
758  
759   /* Perform copy & paste requests
760       If copy&paste is in progress this returns a dialog to fix required attributes 
761    */ 
762   function copyPasteHandling($s_action,$s_entry)
763   {
764     /* Only perform copy/paste if it is enabled */
765     if($this->CopyPasteHandler){
767       /* Prepare current object to be pasted */
768       if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){
770         $this->CopyPasteHandler->save_object();
771         $this->CopyPasteHandler->SetVar("base", $this->DivListUsers->selectedBase);
773         /* Execute copy & paste dialog and display returned data, normaly a dialog which allows 
774             us to solve all attribute mismatches for this object.
775             If nothing is returned, copy & paste was succesfully or aborted */
776         if(($ret= $this->CopyPasteHandler->execute())){
777           return ($ret);
778         }
780         /* Use the last dn to search for it's ID in the newly generated list. */
781         $dn= $this->CopyPasteHandler->lastdn;
782         foreach($this->list as $id => $entry){
783           if($entry['dn'] == $dn){
784             $s_entry= $id;
785             break;
786           }
787         }
788        
789         /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
790         if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
791           $this->CPPasswordChange = $s_entry;
792         }
793       }
795       /* Copy selected object 
796          Create a new empty object and the current selected object. 
797          Send both to copy&paste class*/
798       if($s_action == "copy"){
799         $this->CopyPasteHandler->Clear();
800         $dn= $this->list[trim($s_entry)]['dn'];
801         $acl= get_permissions ($dn, $this->ui->subtreeACL);
802         $obj    = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
803         $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new");
804         $obj->set_acl($acl);
805         $objNew->set_acl($acl);
806         $this->CopyPasteHandler->Copy($obj,$objNew);
807       }
809       /* Cut selected object. 
810          Open user object and send it to the copy & paste handler */
811       if($s_action == "cut"){
812         $this->CopyPasteHandler->Clear();
813         $dn= $this->list[trim($s_entry)]['dn'];
814         $acl= get_permissions ($dn, $this->ui->subtreeACL);
815         $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
816         $obj->set_acl($acl);
817         $this->CopyPasteHandler->Cut($obj);
818       }
819     }
820   }
822   function save_object()
823   {
824     /* Handle divlist filter && department selection*/
825     if(!is_object($this->usertab)){
826       $this->DivListUsers->save_object();
827     }
828   }
830   /* A set of disabled and therefore overloaded functions. They are
831      not needed in this class. */
832   function remove_from_parent() { } 
833   function check() { } 
834   function save() { } 
835   function adapt_from_template($dn) { } 
836   function password_change_needed() { } 
838 } /* ... class userManagement */
839 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
840 ?>