Code

9159587ac5a6f2ca516b62a921282d70a4ce9128
[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                     "create_user_from_tpl"          => "userfrom_tpl",
83                     "change_pw" => "user_chgpw", 
84                     "editPaste" => "editPaste",   "copy"      => "copy",
85                     "cut"       => "cut") as $act => $name){
87         if (preg_match("/".$name.".*/", $key)){
88           $s_action= $act;
89           $s_entry= preg_replace("/".$name."_/i", "", $key);
90           break;
91         }
92       }
93       
94     } /* ...Test POST */
96     /* Remove coordinate prefix from POST, required by some browsers */
97     $s_entry= preg_replace("/_.$/", "", $s_entry);
99     /* Seperate possibly encoded tab and entry, default to tab "user" */
100     if(preg_match("/.*-.*/", $s_entry)){
101       $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
102       $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
103     }else{
104       $s_tab= "user";
105     }
107     /* Display the copy & paste dialog, if it is currently open */
108     $ret = $this->copyPasteHandling($s_action,$s_entry);
109     if($ret){
110       return($ret);
111     }
114     /********************
115       Edit existing entry 
116      ********************/
118     /* User wants to edit data? */
119     if (($s_action=="edit") && (!isset($this->usertab->config))){
121       /* Get 'dn' from posted 'uid', must be unique */
122       $this->dn= $this->list[trim($s_entry)]['dn'];
124       /* Check locking, save current plugin in 'back_plugin', so
125          the dialog knows where to return. */
126       if (($user= get_lock($this->dn)) != ""){
127         return(gen_locked_message ($user, $this->dn));
128       }
130       /* Lock the current entry, so everyone will get the
131          above dialog */
132       add_lock ($this->dn, $this->ui->dn);
134       /* Set up the users ACL's for this 'dn' */
135       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
137       /* Register usertab to trigger edit dialog */
138       $this->usertab= new usertabs($this->config, 
139           $this->config->data['TABS']['USERTABS'], $this->dn);
141       /* Switch tab, if it was requested by the user */
142       $this->usertab->current = $s_tab;
144       /* Set ACL and move DN to the headline */
145       $this->usertab->set_acl($acl);
146       $_SESSION['objectinfo']= $this->dn;
147     }
150     /********************
151       Edit canceled 
152      ********************/
154     /* Reset all relevant data, if we get a _cancel request */
155     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
156       if (isset($this->usertab)){
157         del_lock ($this->usertab->dn);
158         unset ($this->usertab);
159       }
160       $this->usertab= NULL;
161       $this->lognames= array();;
162       $this->sn= "";
163       $this->givenName= "";
164       $this->uid= "";
165       unset ($_SESSION['objectinfo']);
166     }
169     /********************
170       Change password requested  
171      ********************/
173     /* Password change requested */
174     if (($s_action == "change_pw") || (!empty($this->CPPasswordChange))){
176       if(!empty($this->CPPasswordChange)){
177         $s_entry = $this->CPPasswordChange;
178         $this->CPPasswordChange = "";
179       }
181       /* Get 'dn' from posted 'uid' */
182       $this->dn= $this->list[trim($s_entry)]['dn'];
184       /* Load permissions for selected 'dn' and check if
185          we're allowed to remove this 'dn' */
186       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
187       $acl= get_module_permission($acl, "user", $this->dn);
188       if (chkacl($acl, "password") == ""){
190         /* User is allowed to change passwords, save 'dn' and 'acl' for next
191            dialog. */
192         $this->acl= $acl;
193         $_SESSION['objectinfo']= $this->dn;
194         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
196       } else {
197         /* User is not allowed. Show message and cancel. */
198         print_red (_("You are not allowed to set this users password!"));
199       }
200     }
203     /********************
204       Change password confirmed
205      ********************/
207     /* Perform password change */
208     if (isset($_POST['password_finish'])){
210       /* For security reasons, check if user is allowed to set password again */
211       if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
213         /* Check input and feed errors into 'message' */
214         $message= array();
216         /* Sanity checks... */
217         if ($_POST['new_password'] != $_POST['repeated_password']){
219           /* Matching passwords in new and repeated? */
220           $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
221         } else {
223           /* Empty password is not permitted by default. */
224           if ($_POST['new_password'] == ""){
225             $message[]= _("The password you've entered as 'New password' is empty.");
226           }
227         }
229         /* Errors, or password change? */
230         if (count($message) != 0){
232           /* Show error message and continue editing */
233           show_errors ($message);
234           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
235         }
237         $config= $this->config;
238         $ldap_ui= $this->config->get_ldap_link();
239         if(isset($this->usertab->dn)){
240           $ldap_ui->cat($this->usertab->dn,array("uid"));
241           $user = $ldap_ui->fetch();
242         }else{
243           $ldap_ui->cat($this->dn,array("uid"));
244           $user = $ldap_ui->fetch();
245         }
246         if((is_array($user))&&(isset($user['uid']))){
247           $username= $user['uid'][0];
248         }
250         /* Set password, perform required steps */
251         if ($this->usertab){
252           if ($this->usertab->password_change_needed()){
253             $obj= $this->usertab->by_object['user'];
254             change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
255             if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
256               exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
257             }
259             gosa_log ("Password for '".$this->usertab->dn."' has been changed");
260             unset($this->usertab);
261             $this->usertab= NULL;
262           }
263         } else {
264           change_password ($this->dn, $_POST['new_password']);
265           if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
266             exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
267           }
269           gosa_log ("Password for '".$this->dn."' has been changed");
270         }
271       } else {
273         /* Missing permissions, show message */
274         print_red (_("You are not allowed to set this users password!"));
275       }
277       /* Clean session, delete lock */
278       del_lock ($this->dn);
279       unset ($this->usertab);
280       $this->usertab= NULL;
281       $this->lognames= array();;
282       $this->sn= "";
283       $this->givenName= "";
284       $this->uid= "";
285       unset ($_SESSION['objectinfo']);
286     }
289     /********************
290       Delete entry requested, display confirm dialog
291      ********************/
293     /* Remove user was requested */
294     if ($s_action=="del"){
296       /* Get 'dn' from posted 'uid' */
297       $this->dn= $this->list[trim($s_entry)]['dn'];
299       /* Load permissions for selected 'dn' and check if
300          we're allowed to remove this 'dn' */
301       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
302       $this->acl= get_module_permission($acl, "user", $this->dn);
303       if (chkacl($this->acl, "delete") == ""){
305         /* Check locking, save current plugin in 'back_plugin', so
306            the dialog knows where to return. */
307         if (($user= get_lock($this->dn)) != ""){
308           return(gen_locked_message ($user, $this->dn));
309         }
311         /* Lock the current entry, so nobody will edit it during deletion */
312         add_lock ($this->dn, $this->ui->dn);
313         $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
314         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
315       } else {
317         /* Obviously the user isn't allowed to delete. Show message and
318            clean session. */
319         print_red (_("You are not allowed to delete this user!"));
320       }
321     }
324     /********************
325       Delete entry confirmed 
326      ********************/
328     /* Confirmation for deletion has been passed. User should be deleted. */
329     if (isset($_POST['delete_user_confirm'])){
331       /* Some nice guy may send this as POST, so we've to check
332          for the permissions again. */
333       if (chkacl($this->acl, "delete") == ""){
335         /* Delete request is permitted, perform LDAP action */
336         $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
337         $this->usertab->set_acl(array($this->acl));
338         $this->usertab->delete ();
339         gosa_log ("User object '".$this->dn."' has been removed");
340         unset ($this->usertab);
341         $this->usertab= NULL;
342       } else {
344         /* Normally this shouldn't be reached, send some extra
345            logs to notify the administrator */
346         print_red (_("You are not allowed to delete this user!"));
348         if(isset($this->ui->uid)){
349           gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
350         }
351       }
353       /* Remove lock file after successfull deletion */
354       del_lock ($this->dn);
355     }
357     
358     /********************
359       Delete entry Canceled 
360      ********************/
362     /* Delete user canceled? */
363     if (isset($_POST['delete_cancel'])){
364       del_lock ($this->dn);
365     }
368     /********************
369       Edit entry finished (Save) 
370      ********************/
372     /* Finish user edit is triggered by the tabulator dialog, so
373        the user wants to save edited data. Check and save at this
374        point. */
375     if ((isset($_POST['edit_finish'])) && (isset($this->usertab->config))){
377       /* Check tabs, will feed message array */
378       $this->usertab->last= $this->usertab->current;
379       $this->usertab->save_object();
380       $message= $this->usertab->check();
382       /* Save, or display error message? */
383       if (count($message) == 0){
385         /* No errors. Go ahead and prepare to ask for a password
386            in case we're creating a new user. 'dn' will be 'new'
387            in this case. It is set to the correct value later. */
388         if ($this->dn == "new"){
389           $set_pass= 1;
390         } else {
391           $set_pass= 0;
392         }
394         /* Save user data to ldap */
395         if($this->usertab->save() == 1){
396           gosa_log ("User object '".$this->dn."' saving failed.");
397           return;
398         }
399         gosa_log ("User object '".$this->dn."' has been saved");
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       } else {
415         /* Ok. There seem to be errors regarding to the tab data,
416            show message and continue as usual. */
417         show_errors($message);
418       }
419     }
422     /********************
423       We want to create a new user, so fetch all available user templates 
424      ********************/
426     /* Generate template list */
427     if (($s_action=="new")||($s_action=="create_user_from_tpl")){
429       $this->templates= array();
430       $ldap= $this->config->get_ldap_link();
432       /* Create list of templates */
433       foreach ($this->config->departments as $key => $value){
434     
435         /* Get acls from different ou's */
436         $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
437         $acl= get_module_permission($acl, "user", get_people_ou().$value);
438   
439         /* If creation of a new user is allowed, append this template */
440         if (chkacl($acl, "create") == ""){
441           
442           /* Search all templates from the current dn */
443           $ldap->cd (get_people_ou().$value);
444           $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
446           /* Append */
447           if ($ldap->count() != 0){
448             while ($attrs= $ldap->fetch()){
449               $this->templates[$ldap->getDN()]=
450                 $attrs['uid'][0]." - ".@LDAP::fix($key);
451             }
452             $this->templates['none']= _("none");
453           }
454         }
455       }
457       /* Sort templates */
458       natcasesort ($this->templates);
459       reset ($this->templates);
460     }
463     /********************
464       Create a new user,template, user from template 
465      ********************/
467     /* New user/template request */
468     if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
469       /* By default we set 'dn' to 'new', all relevant plugins will
470          react on this. */
471       $this->dn= "new";
472       if (isset($this->config->current['IDGEN'])){
473         $this->got_uid= false;
474       } else {
475         $this->got_uid= true;
476       }
478       /* Create new usertab object */
479       $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
480       $this->usertab->set_acl(array(':all'));
481       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
483       /* Take care about templates */
484       if ($s_action=="new_tpl"){
485         $this->is_template= TRUE;
486         $this->usertab->set_template_mode ();
487       } else {
488         $this->is_template= FALSE;
489       }
491       /* Use template if there are any of them */
492       if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
493         foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
494           $smarty->assign("$attr", $this->$attr);
495         }
496         if ($s_action=="create_user_from_tpl"){
497           $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
498         } else {
499           $smarty->assign("template", "none");
500         }
501         $smarty->assign("edit_uid", "");
502         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
503       }
504     }
506     /********************
507       Template selected continue edit
508      ********************/
510     /* Continue template editing */
511     if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
512       $this->sn             = $_POST['sn'];
513       $this->givenName      = $_POST['givenName'];
515       /* Check for requred values */
516       $message= array();
517       if ($this->sn == "") {
518         $message[]= _("The required field 'Name' is not set.");
519       }
520       if ($this->givenName == "") {
521         $message[]= _("The required field 'Given name' is not set.");
522       }
524       /* Check if dn is used */
525       $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
526       $ldap= $this->config->get_ldap_link();
527       $ldap->cd ($dn);
528       $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
529       if ($ldap->count () != 0){
530         $message[]= _("A person with the choosen name is already used in this tree.");
531       }
533       /* Show error message / continue editing */
534       if (count($message) > 0){
535         show_errors ($message);
536       } else {
537         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
538         if (isset($this->config->current['IDGEN']) &&
539             $this->config->current['IDGEN'] != ""){
540           $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
541           if (count($uids)){
542             $smarty->assign("edit_uid", "false");
543             $smarty->assign("uids", $uids);
544             $this->uid= current($uids);
545           }
546         } else {
547           $smarty->assign("edit_uid", "");
548           $this->uid= "";
549         }
550         $this->got_uid= true;
551       }
553       foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
554         $smarty->assign("$attr", $this->$attr);
555       }
556       if (isset($_POST['template'])){
557         $smarty->assign("template", $_POST['template']);
558       }
559       return($smarty->fetch(get_template_path('template.tpl', TRUE)));
560     }
563     /********************
564       No template selected continue edit
565      ********************/
567     /* No template. Ok. Lets fill data into the normal user dialog */
568     if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
569       foreach(array("sn", "givenName", "uid") as $attr){
570         if (isset($_POST[$attr])){
571           $this->usertab->by_object['user']->$attr= $_POST[$attr];
572         }
573       }
574     }
577     /********************
578       Template selected continue edit
579      ********************/
581     /* Finish template preamble */
582     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
584       /* Might not be filled if IDGEN is unset */
585       $this->sn                 = $_POST['sn'];
586       $this->givenName          = $_POST['givenName'];
588       /* Move user supplied data to sub plugins */
589       $this->uid                = $_POST['uid'];
590       $this->usertab->uid       = $this->uid;
591       $this->usertab->sn        = $this->sn;
592       $this->usertab->givenName = $this->givenName;
593       $template_dn              = $_POST['template'];
594       $this->usertab->adapt_from_template($template_dn);
595       $template_base            = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
596       $this->usertab->by_object['user']->base= $template_base;
598       /* Set up the users ACL's for this 'dn' */
599       $acl= get_permissions ($template_base, $this->ui->subtreeACL);
600       $this->usertab->set_acl($acl);
601     }
602    
603  
604     /********************
605       If no template was selected set base
606      ********************/
608     if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
609       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
610     }
613     /********************
614       Display subdialog 
615      ********************/
617     /* Show tab dialog if object is present */
618     if(isset($this->usertab->config)){
619       $display= $this->usertab->execute();
621       /* Don't show buttons if tab dialog requests this */
622       if (!$this->usertab->by_object[$this->usertab->current]->dialog){
623         $display.= "<p style=\"text-align:right\">\n";
624         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Save")."\">\n";
625         $display.= "&nbsp;\n";
626         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
627         $display.= "</p>";
628       }
629       return ($display);
630     }
631       
632     /* Return rendered main page */
633         /* Display dialog with system list */
634     $this->DivListUsers->parent = $this;
635     $this->DivListUsers->execute();
637     /* Add departments if subsearch is disabled */
638     if(!$this->DivListUsers->SubSearch){
639       $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4);
640     }
641     $this->reload();
642     $this->DivListUsers->setEntries($this->list);
643     return($this->DivListUsers->Draw());
644   }
647   function reload()
648   {
649     /* Set base for all searches */
650     $base= $this->DivListUsers->selectedBase;
651     $this->list =array();
653     /* Get filter configuration */
654     $Regex                = $this->DivListUsers->Regex;
655     $SubSearch            = $this->DivListUsers->SubSearch;
656     $ShowTemplates        = $this->DivListUsers->ShowTemplates;
657     $ShowFunctionalUsers  = $this->DivListUsers->ShowFunctionalUsers;
658     $ShowUnixUsers        = $this->DivListUsers->ShowUnixUsers;
659     $ShowMailUsers        = $this->DivListUsers->ShowMailUsers;
660     $ShowSambaUsers       = $this->DivListUsers->ShowSambaUsers;
661     $ShowProxyUsers       = $this->DivListUsers->ShowProxyUsers;
663     /* Setup filter depending on selection */
664     $filter="";
665     if ($this->config->current['SAMBAVERSION'] == 3){
666       $samba= "sambaSamAccount";
667     } else {
668       $samba= "sambaAccount";
669     }
671     if ($ShowFunctionalUsers){
672       $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
673                 "(objectClass=gosaMailAccount)(objectClass=$samba)".
674                 "(objectClass=gosaProxyAccount))))";
675     }
676     if ($ShowUnixUsers){
677       $filter.= "(objectClass=posixAccount)";
678     }
679     if ($ShowMailUsers){
680       $filter.= "(objectClass=gosaMailAccount)";
681     }
682     if ($ShowSambaUsers){
683       $filter.= "(objectClass=$samba)";
684     }
685     if ($ShowProxyUsers){
686       $filter.= "(objectClass=gosaProxyAccount)";
687     }
688     if ($ShowTemplates){
689       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
690     } else {
691       $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
692     }
693     $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
695     /* Generate userlist */
696     $ldap= $this->config->get_ldap_link(TRUE);
697     if ($SubSearch){
698       $ListTemp =  get_list($filter, $this->ui->subtreeACL, $base,
699                             array("uid", "givenName", "sn", "objectClass"), GL_SUBSEARCH | GL_SIZELIMIT);
700     } else {
701       $base= get_people_ou().$base;
702       $ListTemp = get_list($filter, $this->ui->subtreeACL, $base, 
703                             array("uid", "givenName", "sn", "objectClass"), GL_SIZELIMIT);
704     }
705     $SortTemp = array();
706     $List = array();
707     foreach($ListTemp as $Key => $Entry){
708        // Generate caption for rows
709       if (isset($Entry["sn"]) && isset($Entry["givenName"])){
710         $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
711       } else {
712         $display= "[".$Entry["uid"][0]."]";
713       }
715       $display = strtolower($display);
716       $List[$display] = $Entry;
717       $SortTemp[$display] = $display;
718     }
719     sort($SortTemp);
720     reset($SortTemp);
722     $this->list = array();
723     foreach($SortTemp as $Key){
724       $this->list[] = $List[$Key];
725     }
726   }
728   function remove_lock()
729   {
730     /* Remove user lock if a DN is marked as "currently edited" */
731     if (isset($this->usertab->dn)){
732       del_lock ($this->usertab->dn);
733     }
734   }
736  
737   /* Perform copy & paste requests
738       If copy&paste is in progress this returns a dialog to fix required attributes 
739    */ 
740   function copyPasteHandling($s_action,$s_entry)
741   {
742     /* Only perform copy/paste if it is enabled */
743     if($this->CopyPasteHandler){
745       /* Prepare current object to be pasted */
746       if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){
748         $this->CopyPasteHandler->save_object();
749         $this->CopyPasteHandler->SetVar("base", $this->DivListUsers->selectedBase);
751         /* Execute copy & paste dialog and display returned data, normaly a dialog which allows 
752             us to solve all attribute mismatches for this object.
753             If nothing is returned, copy & paste was succesfully or aborted */
754         if(($ret= $this->CopyPasteHandler->execute())){
755           return ($ret);
756         }
758         /* Use the last dn to search for it's ID in the newly generated list. */
759         $dn= $this->CopyPasteHandler->lastdn;
761         /* Get new user list */
762         $this->reload();
763         foreach($this->list as $id => $entry){
764           if($entry['dn'] == $dn){
765             $s_entry= $id;
766             break;
767           }
768         }
769        
770         /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
771         if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
772           $this->CPPasswordChange = $s_entry;
773         }
774       }
776       /* Copy selected object 
777           Create a new empty object and the current selected object. 
778           Send both to copy&paste class*/
779       if($s_action == "copy"){
780         $this->CopyPasteHandler->Clear();
781         $dn= $this->list[trim($s_entry)]['dn'];
782         $acl= get_permissions ($dn, $this->ui->subtreeACL);
783         $obj    = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
784         $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new");
785         $obj->    set_acl($acl);
786         $objNew-> set_acl($acl);
787         $this->CopyPasteHandler->Copy($obj,$objNew);
788       }
790       /* Cut selected object. 
791           Open user object and send it to the copy & paste handler */
792       if($s_action == "cut"){
793         $this->CopyPasteHandler->Clear();
794         $dn= $this->list[trim($s_entry)]['dn'];
795         $acl= get_permissions ($dn, $this->ui->subtreeACL);
796         $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
797         $obj->set_acl($acl);
798         $this->CopyPasteHandler->Cut($obj);
799       }
800     }
801   }
803   function save_object()
804   {
805     /* Handle divlist filter && department selection*/
806     if(!is_object($this->usertab)){
807       $this->DivListUsers->save_object();
808     }
809   }
811   /* A set of disabled and therefore overloaded functions. They are
812      not needed in this class. */
813   function remove_from_parent() { } 
814   function check() { } 
815   function save() { } 
816   function adapt_from_template($dn) { } 
817   function password_change_needed() { } 
818   function show_header($button_text, $text, $disabled= FALSE) { }
820 } /* ... class userManagement */
821 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
822 ?>