Code

Fixed detection of already used object names
[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($acl);
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       if (isset($this->config->current['IDGEN'])){
474         $this->got_uid= false;
475       } else {
476         $this->got_uid= true;
477       }
479       /* Create new usertab object */
480       $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
481       $this->usertab->set_acl(array(':all'));
482       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
484       /* Take care about templates */
485       if ($s_action=="new_tpl"){
486         $this->is_template= TRUE;
487         $this->usertab->set_template_mode ();
488       } else {
489         $this->is_template= FALSE;
490       }
492       /* Use template if there are any of them */
493       if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
494         foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
495           $smarty->assign("$attr", $this->$attr);
496         }
497         if ($s_action=="create_user_from_tpl"){
498           $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
499         } else {
500           $smarty->assign("template", "none");
501         }
502         $smarty->assign("edit_uid", "");
503         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
504       }
505     }
507     /********************
508       Template selected continue edit
509      ********************/
511     /* Continue template editing */
512     if ((isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid']))){
513       $this->sn             = $_POST['sn'];
514       $this->givenName      = $_POST['givenName'];
516       /* Check for requred values */
517       $message= array();
518       if ($this->sn == "") {
519         $message[]= _("The required field 'Name' is not set.");
520       }
521       if ($this->givenName == "") {
522         $message[]= _("The required field 'Given name' is not set.");
523       }
525       /* Check if dn is used */
526       $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
527       $ldap= $this->config->get_ldap_link();
528       $ldap->cd ($dn);
529       $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
530       if ($ldap->count () != 0){
531         $message[]= _("A person with the choosen name is already used in this tree.");
532       }
534       /* Show error message / continue editing */
535       if (count($message) > 0){
536         show_errors ($message);
537       } else {
538         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
539         if (isset($this->config->current['IDGEN']) &&
540             $this->config->current['IDGEN'] != ""){
541           $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
542           if (count($uids)){
543             $smarty->assign("edit_uid", "false");
544             $smarty->assign("uids", $uids);
545             $this->uid= current($uids);
546           }
547         } else {
548           $smarty->assign("edit_uid", "");
549           $this->uid= "";
550         }
551         $this->got_uid= true;
552       }
554       foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
555         $smarty->assign("$attr", $this->$attr);
556       }
557       if (isset($_POST['template'])){
558         $smarty->assign("template", $_POST['template']);
559       }
560       return($smarty->fetch(get_template_path('template.tpl', TRUE)));
561     }
564     /********************
565       No template selected continue edit
566      ********************/
568     /* No template. Ok. Lets fill data into the normal user dialog */
569     if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
570       foreach(array("sn", "givenName", "uid") as $attr){
571         if (isset($_POST[$attr])){
572           $this->usertab->by_object['user']->$attr= $_POST[$attr];
573         }
574       }
575     }
578     /********************
579       Template selected continue edit
580      ********************/
582     /* Finish template preamble */
583     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
585       /* Might not be filled if IDGEN is unset */
586       $this->sn                 = $_POST['sn'];
587       $this->givenName          = $_POST['givenName'];
589       /* Move user supplied data to sub plugins */
590       $this->uid                = $_POST['uid'];
591       $this->usertab->uid       = $this->uid;
592       $this->usertab->sn        = $this->sn;
593       $this->usertab->givenName = $this->givenName;
594       $template_dn              = $_POST['template'];
595       $this->usertab->adapt_from_template($template_dn);
596       $template_base            = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
597       $this->usertab->by_object['user']->base= $template_base;
599       /* Set up the users ACL's for this 'dn' */
600       $acl= get_permissions ($template_base, $this->ui->subtreeACL);
601       $this->usertab->set_acl($acl);
602     }
603    
604  
605     /********************
606       If no template was selected set base
607      ********************/
609     if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
610       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
611     }
614     /********************
615       Display subdialog 
616      ********************/
618     /* Show tab dialog if object is present */
619     if(isset($this->usertab->config)){
620       $display= $this->usertab->execute();
622       /* Don't show buttons if tab dialog requests this */
623       if(isset($this->usertab->by_object)){
624         if (!$this->usertab->by_object[$this->usertab->current]->dialog){
625           $display.= "<p style=\"text-align:right\">\n";
626           $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
627           $display.= "&nbsp;\n";
628           if ($this->dn != "new"){
629             $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
630             $display.= "&nbsp;\n";
631           }
632           $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
633           $display.= "</p>";
634         }
635       }
636       return ($display);
637     }
638     
639     /* Check if there is a snapshot dialog open */
640     $base = $this->DivListUsers->selectedBase;
641     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
642       return($str);
643     }
644   
645     /* Return rendered main page */
646         /* Display dialog with system list */
647     $this->DivListUsers->parent = $this;
648     $this->DivListUsers->execute();
650     /* Add departments if subsearch is disabled */
651     if(!$this->DivListUsers->SubSearch){
652       $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4);
653     }
654     $this->reload();
655     $this->DivListUsers->setEntries($this->list);
656     return($this->DivListUsers->Draw());
657   }
660   /* Return departments, that will be included within snapshot detection */
661   function get_used_snapshot_bases()
662   {
663     return(array(get_people_ou().$this->DivListUsers->selectedBase));
664   }  
667   function reload()
668   {
669     /* Set base for all searches */
670     $base= $this->DivListUsers->selectedBase;
671     $this->list =array();
673     /* Get filter configuration */
674     $Regex                = $this->DivListUsers->Regex;
675     $SubSearch            = $this->DivListUsers->SubSearch;
676     $ShowTemplates        = $this->DivListUsers->ShowTemplates;
677     $ShowFunctionalUsers  = $this->DivListUsers->ShowFunctionalUsers;
678     $ShowUnixUsers        = $this->DivListUsers->ShowUnixUsers;
679     $ShowMailUsers        = $this->DivListUsers->ShowMailUsers;
680     $ShowSambaUsers       = $this->DivListUsers->ShowSambaUsers;
681     $ShowProxyUsers       = $this->DivListUsers->ShowProxyUsers;
683     /* Setup filter depending on selection */
684     $filter="";
685     if ($this->config->current['SAMBAVERSION'] == 3){
686       $samba= "sambaSamAccount";
687     } else {
688       $samba= "sambaAccount";
689     }
691     if ($ShowFunctionalUsers){
692       $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
693                 "(objectClass=gosaMailAccount)(objectClass=$samba)".
694                 "(objectClass=gosaProxyAccount))))";
695     }
696     if ($ShowUnixUsers){
697       $filter.= "(objectClass=posixAccount)";
698     }
699     if ($ShowMailUsers){
700       $filter.= "(objectClass=gosaMailAccount)";
701     }
702     if ($ShowSambaUsers){
703       $filter.= "(objectClass=$samba)";
704     }
705     if ($ShowProxyUsers){
706       $filter.= "(objectClass=gosaProxyAccount)";
707     }
708     if ($ShowTemplates){
709       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
710     } else {
711       $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
712     }
713     $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
715     /* Generate userlist */
716     $ldap= $this->config->get_ldap_link(TRUE);
718     if ($SubSearch){
719       $ListTemp =  get_list($filter, $this->ui->subtreeACL, $base,
720                             array("uid", "givenName", "sn", "objectClass"), GL_SUBSEARCH | GL_SIZELIMIT);
721     } else {
722       $base= get_people_ou().$base;
723       $ListTemp = get_list($filter, $this->ui->subtreeACL, $base, 
724                             array("uid", "givenName", "sn", "objectClass"), GL_SIZELIMIT);
725     }
726     $SortTemp = array();
727     $List = array();
728     foreach($ListTemp as $Key => $Entry){
729        // Generate caption for rows
730       if (isset($Entry["sn"]) && isset($Entry["givenName"])){
731         $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
732       } else {
733         $display= "[".$Entry["uid"][0]."]";
734       }
736       $display = strtolower($display);
737       $List[$display] = $Entry;
738       $SortTemp[$display] = $display;
739     }
740     sort($SortTemp);
741     reset($SortTemp);
743     $this->list = array();
744     foreach($SortTemp as $Key){
745       $this->list[] = $List[$Key];
746     }
747   }
749   function remove_lock()
750   {
751     /* Remove user lock if a DN is marked as "currently edited" */
752     if (isset($this->usertab->dn)){
753       del_lock ($this->usertab->dn);
754     }
755   }
757  
758   /* Perform copy & paste requests
759       If copy&paste is in progress this returns a dialog to fix required attributes 
760    */ 
761   function copyPasteHandling($s_action,$s_entry)
762   {
763     /* Only perform copy/paste if it is enabled */
764     if($this->CopyPasteHandler){
766       /* Prepare current object to be pasted */
767       if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){
769         $this->CopyPasteHandler->save_object();
770         $this->CopyPasteHandler->SetVar("base", $this->DivListUsers->selectedBase);
772         /* Execute copy & paste dialog and display returned data, normaly a dialog which allows 
773             us to solve all attribute mismatches for this object.
774             If nothing is returned, copy & paste was succesfully or aborted */
775         if(($ret= $this->CopyPasteHandler->execute())){
776           return ($ret);
777         }
779         /* Use the last dn to search for it's ID in the newly generated list. */
780         $dn= $this->CopyPasteHandler->lastdn;
781         foreach($this->list as $id => $entry){
782           if($entry['dn'] == $dn){
783             $s_entry= $id;
784             break;
785           }
786         }
787        
788         /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
789         if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
790           $this->CPPasswordChange = $s_entry;
791         }
792       }
794       /* Copy selected object 
795          Create a new empty object and the current selected object. 
796          Send both to copy&paste class*/
797       if($s_action == "copy"){
798         $this->CopyPasteHandler->Clear();
799         $dn= $this->list[trim($s_entry)]['dn'];
800         $acl= get_permissions ($dn, $this->ui->subtreeACL);
801         $obj    = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
802         $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new");
803         $obj->    set_acl($acl);
804         $objNew-> set_acl($acl);
805         $this->CopyPasteHandler->Copy($obj,$objNew);
806       }
808       /* Cut selected object. 
809          Open user object and send it to the copy & paste handler */
810       if($s_action == "cut"){
811         $this->CopyPasteHandler->Clear();
812         $dn= $this->list[trim($s_entry)]['dn'];
813         $acl= get_permissions ($dn, $this->ui->subtreeACL);
814         $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
815         $obj->set_acl($acl);
816         $this->CopyPasteHandler->Cut($obj);
817       }
818     }
819   }
821   function save_object()
822   {
823     /* Handle divlist filter && department selection*/
824     $this->DivListUsers->save_object();
825   }
827   /* A set of disabled and therefore overloaded functions. They are
828      not needed in this class. */
829   function remove_from_parent() { } 
830   function check() { } 
831   function save() { } 
832   function adapt_from_template($dn) { } 
833   function password_change_needed() { } 
834   function show_header($button_text, $text, $disabled= FALSE) { }
836 } /* ... class userManagement */
837 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
838 ?>