Code

Fixed base selection for groups
[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       /* Register usertab to trigger edit dialog */
134       $this->usertab= new usertabs($this->config, 
135           $this->config->data['TABS']['USERTABS'], $this->dn);
137       /* Switch tab, if it was requested by the user */
138       $this->usertab->current = $s_tab;
140       /* Set ACL and move DN to the headline */
141       $this->usertab->set_acl_base();
142       $_SESSION['objectinfo']= $this->dn;
143     }
146     /********************
147       Edit canceled 
148      ********************/
150     /* Reset all relevant data, if we get a _cancel request */
151     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
152       if (isset($this->usertab)){
153         del_lock ($this->usertab->dn);
154         unset ($this->usertab);
155       }
156       $this->usertab= NULL;
157       $this->lognames= array();;
158       $this->sn= "";
159       $this->givenName= "";
160       $this->uid= "";
161       unset ($_SESSION['objectinfo']);
162     }
165     /********************
166       Change password requested  
167      ********************/
169     /* Password change requested */
170     if (($s_action == "change_pw") || (!empty($this->CPPasswordChange))){
172       if(!empty($this->CPPasswordChange)){
173         $s_entry = $this->CPPasswordChange;
174         $this->CPPasswordChange = "";
175       }
177       /* Get 'dn' from posted 'uid' */
178       $this->dn= $this->list[trim($s_entry)]['dn'];
180       /* Load permissions for selected 'dn' and check if
181          we're allowed to remove this 'dn' */
182       $ui = get_userinfo();
183       if (preg_match("/w/",$ui->get_permissions($this->dn,"users/password"))){
185         /* User is allowed to change passwords, save 'dn' and 'acl' for next
186            dialog. */
187         $_SESSION['objectinfo']= $this->dn;
188         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
190       } else {
191         /* User is not allowed. Show message and cancel. */
192         print_red (_("You are not allowed to set this users password!"));
193       }
194     }
197     /********************
198       Change password confirmed
199      ********************/
201     /* Perform password change */
202     if (isset($_POST['password_finish'])){
204       /* For security reasons, check if user is allowed to set password again */
205       $ui= get_userinfo();
206       $acl= $ui->get_permissions($this->dn, "users/user", 'userPassword');
207       $cacl= $ui->get_permissions($this->dn, "users/all");
209       if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
211         /* Check input and feed errors into 'message' */
212         $message= array();
214         /* Sanity checks... */
215         if ($_POST['new_password'] != $_POST['repeated_password']){
217           /* Matching passwords in new and repeated? */
218           $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
219         } else {
221           /* Empty password is not permitted by default. */
222           if ($_POST['new_password'] == ""){
223             $message[]= _("The password you've entered as 'New password' is empty.");
224           }
225         }
227         /* Errors, or password change? */
228         if (count($message) != 0){
230           /* Show error message and continue editing */
231           show_errors ($message);
232           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
233         }
235         $config= $this->config;
236         $ldap_ui= $this->config->get_ldap_link();
237         if(isset($this->usertab->dn)){
238           $ldap_ui->cat($this->usertab->dn,array("uid"));
239           $user = $ldap_ui->fetch();
240         }else{
241           $ldap_ui->cat($this->dn,array("uid"));
242           $user = $ldap_ui->fetch();
243         }
244         if((is_array($user))&&(isset($user['uid']))){
245           $username= $user['uid'][0];
246         }
248         /* Set password, perform required steps */
249         if ($this->usertab){
250           if ($this->usertab->password_change_needed()){
251             $obj= $this->usertab->by_object['user'];
252             change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
253             if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
254               exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
255             }
257             gosa_log ("Password for '".$this->usertab->dn."' has been changed");
258             unset($this->usertab);
259             $this->usertab= NULL;
260           }
261         } else {
262           change_password ($this->dn, $_POST['new_password']);
263           if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
264             exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
265           }
267           gosa_log ("Password for '".$this->dn."' has been changed");
268         }
269       } else {
271         /* Missing permissions, show message */
272         print_red (_("You are not allowed to set this users password!"));
273       }
275       /* Clean session, delete lock */
276       del_lock ($this->dn);
277       unset ($this->usertab);
278       $this->usertab= NULL;
279       $this->lognames= array();;
280       $this->sn= "";
281       $this->givenName= "";
282       $this->uid= "";
283       unset ($_SESSION['objectinfo']);
284     }
287     /********************
288       Delete entry requested, display confirm dialog
289      ********************/
291     /* Remove user was requested */
292     if ($s_action=="del"){
294       /* Get 'dn' from posted 'uid' */
295       $this->dn= $this->list[trim($s_entry)]['dn'];
297       /* Load permissions for selected 'dn' and check if
298          we're allowed to remove this 'dn' */
300       /* Check locking, save current plugin in 'back_plugin', so
301          the dialog knows where to return. */
302       if (($user= get_lock($this->dn)) != ""){
303         return(gen_locked_message ($user, $this->dn));
304       }
306       /* Lock the current entry, so nobody will edit it during deletion */
307       add_lock ($this->dn, $this->ui->dn);
308       $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
309       return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
310     }
313     /********************
314       Delete entry confirmed 
315      ********************/
317     /* Confirmation for deletion has been passed. User should be deleted. */
318     if (isset($_POST['delete_user_confirm'])){
320       /* Some nice guy may send this as POST, so we've to check
321          for the permissions again. */
323       $ui  = get_userinfo();
324       $acl = $ui->get_permissions($this->dn, "users/all"); 
325  
326       if (preg_match('/d/', $acl)){
328         /* Delete request is permitted, perform LDAP action */
329         $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
330         $this->usertab->set_acl_base();
331         $this->usertab->delete ();
332         gosa_log ("User object '".$this->dn."' has been removed");
333         unset ($this->usertab);
334         $this->usertab= NULL;
335       } else {
337         /* Normally this shouldn't be reached, send some extra
338            logs to notify the administrator */
339         print_red (_("You are not allowed to delete this user!"));
341         if(isset($this->ui->uid)){
342           gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
343         }
344       }
346       /* Remove lock file after successfull deletion */
347       del_lock ($this->dn);
348     }
350     
351     /********************
352       Delete entry Canceled 
353      ********************/
355     /* Delete user canceled? */
356     if (isset($_POST['delete_cancel'])){
357       del_lock ($this->dn);
358     }
361     /********************
362       Edit entry finished (Save) 
363      ********************/
365     /* Finish user edit is triggered by the tabulator dialog, so
366        the user wants to save edited data. Check and save at this
367        point. */
368     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
370       /* Check tabs, will feed message array */
371       $this->usertab->last= $this->usertab->current;
372       $this->usertab->save_object();
373       $message= $this->usertab->check();
375       /* Save, or display error message? */
376       if (count($message) == 0){
378         /* No errors. Go ahead and prepare to ask for a password
379            in case we're creating a new user. 'dn' will be 'new'
380            in this case. It is set to the correct value later. */
381         if ($this->dn == "new"){
382           $set_pass= 1;
383         } else {
384           $set_pass= 0;
385         }
387         /* Save user data to ldap */
388         if($this->usertab->save() == 1){
389           gosa_log ("User object '".$this->dn."' saving failed.");
390           return;
391         }
392         gosa_log ("User object '".$this->dn."' has been saved");
394         if (!isset($_POST['edit_apply'])){
395           /* User has been saved successfully, remove lock from LDAP. */
396           if ($this->dn != "new"){
397             del_lock ($this->dn);
398           }
400           /* In case of new users, ask for a password, skip this for templates */
401           if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
402             return($smarty->fetch(get_template_path('password.tpl', TRUE)));
403           }
405           unset ($this->usertab);
406           $this->usertab= NULL;
407           unset ($_SESSION['objectinfo']);
408         }
409       } else {
410         /* Ok. There seem to be errors regarding to the tab data,
411            show message and continue as usual. */
412         show_errors($message);
413       }
414     }
417     /********************
418       We want to create a new user, so fetch all available user templates 
419      ********************/
421     /* Generate template list */
422     if (($s_action=="new")||($s_action=="create_user_from_tpl")){
424       $this->templates= array();
425       $ldap= $this->config->get_ldap_link();
427       /* Create list of templates */
428       foreach ($this->config->departments as $key => $value){
429     
430         /* Get acls from different ou's */
431         $ui  = get_userinfo();
432         $acl = $ui->get_permissions("cn=dummy,".$this->DivListUsers->selectedBase,"users/user")       ; 
433  
434         /* If creation of a new user is allowed, append this template */
435         if (preg_match("/cw/",$acl)){
436           
437           /* Search all templates from the current dn */
438           $ldap->cd (get_people_ou().$value);
439           $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
441           /* Append */
442           if ($ldap->count() != 0){
443             while ($attrs= $ldap->fetch()){
444               $this->templates[$ldap->getDN()]=
445                 $attrs['uid'][0]." - ".@LDAP::fix($key);
446             }
447             $this->templates['none']= _("none");
448           }
449         }
450       }
452       /* Sort templates */
453       natcasesort ($this->templates);
454       reset ($this->templates);
455     }
458     /********************
459       Create a new user,template, user from template 
460      ********************/
462     /* New user/template request */
463     if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
464       /* By default we set 'dn' to 'new', all relevant plugins will
465          react on this. */
466       $this->dn= "new";
467       
468       if (isset($this->config->current['IDGEN'])){
469         $this->got_uid= false;
470       } else {
471         $this->got_uid= true;
472       }
474       /* Create new usertab object */
475       $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
476       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
477       $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
479       /* Take care about templates */
480       if ($s_action=="new_tpl"){
481         $this->is_template= TRUE;
482         $this->usertab->set_template_mode ();
483       } else {
484         $this->is_template= FALSE;
485       }
487       /* Use template if there are any of them */
488       if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
489         foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
490           $smarty->assign("$attr", $this->$attr);
491         }
492         if ($s_action=="create_user_from_tpl"){
493           $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
494         } else {
495           $smarty->assign("template", "none");
496         }
497         $smarty->assign("edit_uid", "");
498         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
499       }
500     }
502     /********************
503       Template selected continue edit
504      ********************/
506     /* Continue template editing */
507     if ((isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid']))){
508       $this->sn             = $_POST['sn'];
509       $this->givenName      = $_POST['givenName'];
511       /* Check for requred values */
512       $message= array();
513       if ($this->sn == "") {
514         $message[]= _("The required field 'Name' is not set.");
515       }
516       if ($this->givenName == "") {
517         $message[]= _("The required field 'Given name' is not set.");
518       }
520       /* Check if dn is used */
521       $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
522       $ldap= $this->config->get_ldap_link();
523       $ldap->cd ($dn);
524       $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
525       if ($ldap->count () != 0){
526         $message[]= _("A person with the choosen name is already used in this tree.");
527       }
529       /* Show error message / continue editing */
530       if (count($message) > 0){
531         show_errors ($message);
532       } else {
533         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
534         if (isset($this->config->current['IDGEN']) &&
535             $this->config->current['IDGEN'] != ""){
536           $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
537           if (count($uids)){
538             $smarty->assign("edit_uid", "false");
539             $smarty->assign("uids", $uids);
540             $this->uid= current($uids);
541           }
542         } else {
543           $smarty->assign("edit_uid", "");
544           $this->uid= "";
545         }
546         $this->got_uid= true;
547       }
549       foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
550         $smarty->assign("$attr", $this->$attr);
551       }
552       if (isset($_POST['template'])){
553         $smarty->assign("template", $_POST['template']);
554       }
555       return($smarty->fetch(get_template_path('template.tpl', TRUE)));
556     }
559     /********************
560       No template selected continue edit
561      ********************/
563     /* No template. Ok. Lets fill data into the normal user dialog */
564     if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
565       foreach(array("sn", "givenName", "uid") as $attr){
566         if (isset($_POST[$attr])){
567           $this->usertab->by_object['user']->$attr= $_POST[$attr];
568         }
569       }
570     }
573     /********************
574       Template selected continue edit
575      ********************/
577     /* Finish template preamble */
578     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
580       /* Might not be filled if IDGEN is unset */
581       $this->sn                 = $_POST['sn'];
582       $this->givenName          = $_POST['givenName'];
584       /* Move user supplied data to sub plugins */
585       $this->uid                = $_POST['uid'];
586       $this->usertab->uid       = $this->uid;
587       $this->usertab->sn        = $this->sn;
588       $this->usertab->givenName = $this->givenName;
589       $template_dn              = $_POST['template'];
590       $this->usertab->adapt_from_template($template_dn);
591       $template_base            = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
592       $this->usertab->by_object['user']->base= $template_base;
593     }
594    
595  
596     /********************
597       If no template was selected set base
598      ********************/
600     if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
601       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
602     }
605     /********************
606       Display subdialog 
607      ********************/
609     /* Show tab dialog if object is present */
610     if(isset($this->usertab->config)){
611       $display= $this->usertab->execute();
613       /* Don't show buttons if tab dialog requests this */
614       if(isset($this->usertab->by_object)){
615         if (!$this->usertab->by_object[$this->usertab->current]->dialog){
616           $display.= "<p style=\"text-align:right\">\n";
617           $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
618           $display.= "&nbsp;\n";
619           if ($this->dn != "new"){
620             $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
621             $display.= "&nbsp;\n";
622           }
623           $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
624           $display.= "</p>";
625         }
626       }
627       return ($display);
628     }
629     
630     /* Check if there is a snapshot dialog open */
631     $base = $this->DivListUsers->selectedBase;
632     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
633       return($str);
634     }
635   
636     /* Return rendered main page */
637         /* Display dialog with system list */
638     $this->DivListUsers->parent = $this;
639     $this->DivListUsers->execute();
641     /* Add departments if subsearch is disabled */
642     if(!$this->DivListUsers->SubSearch){
643       $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4);
644     }
645     $this->reload();
646     $this->DivListUsers->setEntries($this->list);
647     return($this->DivListUsers->Draw());
648   }
651   /* Return departments, that will be included within snapshot detection */
652   function get_used_snapshot_bases()
653   {
654     return(array(get_people_ou().$this->DivListUsers->selectedBase));
655   }  
658   function reload()
659   {
660     /* Set base for all searches */
661     $base= $this->DivListUsers->selectedBase;
662     $this->list =array();
664     /* Get filter configuration */
665     $Regex                = $this->DivListUsers->Regex;
666     $SubSearch            = $this->DivListUsers->SubSearch;
667     $ShowTemplates        = $this->DivListUsers->ShowTemplates;
668     $ShowFunctionalUsers  = $this->DivListUsers->ShowFunctionalUsers;
669     $ShowUnixUsers        = $this->DivListUsers->ShowUnixUsers;
670     $ShowMailUsers        = $this->DivListUsers->ShowMailUsers;
671     $ShowSambaUsers       = $this->DivListUsers->ShowSambaUsers;
672     $ShowProxyUsers       = $this->DivListUsers->ShowProxyUsers;
674     /* Setup filter depending on selection */
675     $filter="";
676     if ($this->config->current['SAMBAVERSION'] == 3){
677       $samba= "sambaSamAccount";
678     } else {
679       $samba= "sambaAccount";
680     }
682     if ($ShowFunctionalUsers){
683       $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
684                 "(objectClass=gosaMailAccount)(objectClass=$samba)".
685                 "(objectClass=gosaProxyAccount))))";
686     }
687     if ($ShowUnixUsers){
688       $filter.= "(objectClass=posixAccount)";
689     }
690     if ($ShowMailUsers){
691       $filter.= "(objectClass=gosaMailAccount)";
692     }
693     if ($ShowSambaUsers){
694       $filter.= "(objectClass=$samba)";
695     }
696     if ($ShowProxyUsers){
697       $filter.= "(objectClass=gosaProxyAccount)";
698     }
699     if ($ShowTemplates){
700       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
701     } else {
702       $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
703     }
704     $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
706     /* Generate userlist */
707     $ldap= $this->config->get_ldap_link(TRUE);
709     if ($SubSearch){
710       $ListTemp =  get_list($filter, "users", $base,
711                             array("uid", "givenName", "sn", "objectClass"), GL_SUBSEARCH | GL_SIZELIMIT);
712     } else {
713       $base= get_people_ou().$base;
714       $ListTemp = get_list($filter, "users", $base, 
715                             array("uid", "givenName", "sn", "objectClass"), GL_SIZELIMIT);
716     }
717     $SortTemp = array();
718     $List = array();
719     foreach($ListTemp as $Key => $Entry){
720        // Generate caption for rows
721       if (isset($Entry["sn"]) && isset($Entry["givenName"])){
722         $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
723       } else {
724         $display= "[".$Entry["uid"][0]."]";
725       }
727       $display = strtolower($display);
728       $List[$display] = $Entry;
729       $SortTemp[$display] = $display;
730     }
731     sort($SortTemp);
732     reset($SortTemp);
734     $this->list = array();
735     foreach($SortTemp as $Key){
736       $this->list[] = $List[$Key];
737     }
738   }
740   function remove_lock()
741   {
742     /* Remove user lock if a DN is marked as "currently edited" */
743     if (isset($this->usertab->dn)){
744       del_lock ($this->usertab->dn);
745     }
746   }
748  
749   /* Perform copy & paste requests
750       If copy&paste is in progress this returns a dialog to fix required attributes 
751    */ 
752   function copyPasteHandling($s_action,$s_entry)
753   {
754     /* Only perform copy/paste if it is enabled */
755     if($this->CopyPasteHandler){
757       /* Prepare current object to be pasted */
758       if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){
760         $this->CopyPasteHandler->save_object();
761         $this->CopyPasteHandler->SetVar("base", $this->DivListUsers->selectedBase);
763         /* Execute copy & paste dialog and display returned data, normaly a dialog which allows 
764             us to solve all attribute mismatches for this object.
765             If nothing is returned, copy & paste was succesfully or aborted */
766         if(($ret= $this->CopyPasteHandler->execute())){
767           return ($ret);
768         }
770         /* Use the last dn to search for it's ID in the newly generated list. */
771         $dn= $this->CopyPasteHandler->lastdn;
772         foreach($this->list as $id => $entry){
773           if($entry['dn'] == $dn){
774             $s_entry= $id;
775             break;
776           }
777         }
778        
779         /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
780         if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
781           $this->CPPasswordChange = $s_entry;
782         }
783       }
785       /* Copy selected object 
786          Create a new empty object and the current selected object. 
787          Send both to copy&paste class*/
788       if($s_action == "copy"){
789         $this->CopyPasteHandler->Clear();
790         $dn= $this->list[trim($s_entry)]['dn'];
791         $obj    = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
792         $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new");
793         $this->CopyPasteHandler->Copy($obj,$objNew);
794       }
796       /* Cut selected object. 
797          Open user object and send it to the copy & paste handler */
798       if($s_action == "cut"){
799         $this->CopyPasteHandler->Clear();
800         $dn= $this->list[trim($s_entry)]['dn'];
801         $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
802         $this->CopyPasteHandler->Cut($obj);
803       }
804     }
805   }
807   function save_object()
808   {
809     /* Handle divlist filter && department selection*/
810     if(!is_object($this->usertab)){
811       $this->DivListUsers->save_object();
812     }
813   }
815   /* A set of disabled and therefore overloaded functions. They are
816      not needed in this class. */
817   function remove_from_parent() { } 
818   function check() { } 
819   function save() { } 
820   function adapt_from_template($dn) { } 
821   function password_change_needed() { } 
823 } /* ... class userManagement */
824 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
825 ?>