Code

8987b6a76919080739e7b11a7e59406276ed186a
[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       /* Register usertab to trigger edit dialog */
135       $this->usertab= new usertabs($this->config, 
136           $this->config->data['TABS']['USERTABS'], $this->dn);
138       /* Switch tab, if it was requested by the user */
139       $this->usertab->current = $s_tab;
141       /* Set ACL and move DN to the headline */
142       $this->usertab->set_acl_base();
143       $_SESSION['objectinfo']= $this->dn;
144     }
147     /********************
148       Edit canceled 
149      ********************/
151     /* Reset all relevant data, if we get a _cancel request */
152     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
153       if (isset($this->usertab)){
154         del_lock ($this->usertab->dn);
155         unset ($this->usertab);
156       }
157       $this->usertab= NULL;
158       $this->lognames= array();;
159       $this->sn= "";
160       $this->givenName= "";
161       $this->uid= "";
162       unset ($_SESSION['objectinfo']);
163     }
166     /********************
167       Change password requested  
168      ********************/
170     /* Password change requested */
171     if (($s_action == "change_pw") || (!empty($this->CPPasswordChange))){
173       if(!empty($this->CPPasswordChange)){
174         $s_entry = $this->CPPasswordChange;
175         $this->CPPasswordChange = "";
176       }
178       /* Get 'dn' from posted 'uid' */
179       $this->dn= $this->list[trim($s_entry)]['dn'];
181       /* Load permissions for selected 'dn' and check if
182          we're allowed to remove this 'dn' */
183       $ui = get_userinfo();
184       if (preg_match("/w/",$ui->get_permissions($this->dn,"users/password"))){
186         /* User is allowed to change passwords, save 'dn' and 'acl' for next
187            dialog. */
188         $_SESSION['objectinfo']= $this->dn;
189         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
191       } else {
192         /* User is not allowed. Show message and cancel. */
193         print_red (_("You are not allowed to set this users password!"));
194       }
195     }
198     /********************
199       Change password confirmed
200      ********************/
202     /* Perform password change */
203     if (isset($_POST['password_finish'])){
205       /* For security reasons, check if user is allowed to set password again */
206       $ui= get_userinfo();
207       $acl= $ui->get_permissions($this->dn, "users/user", 'userPassword');
208       $cacl= $ui->get_permissions($this->dn, "users/all");
210       if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
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' */
301       /* Check locking, save current plugin in 'back_plugin', so
302          the dialog knows where to return. */
303       if (($user= get_lock($this->dn)) != ""){
304         return(gen_locked_message ($user, $this->dn));
305       }
307       /* Lock the current entry, so nobody will edit it during deletion */
308       add_lock ($this->dn, $this->ui->dn);
309       $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
310       return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
311     }
314     /********************
315       Delete entry confirmed 
316      ********************/
318     /* Confirmation for deletion has been passed. User should be deleted. */
319     if (isset($_POST['delete_user_confirm'])){
321       /* Some nice guy may send this as POST, so we've to check
322          for the permissions again. */
324       $ui  = get_userinfo();
325       $acl = $ui->get_permissions($this->dn, "users/all"); 
326  
327       if (preg_match('/d/', $acl)){
329         /* Delete request is permitted, perform LDAP action */
330         $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
331         $this->usertab->set_acl_base();
332         $this->usertab->delete ();
333         gosa_log ("User object '".$this->dn."' has been removed");
334         unset ($this->usertab);
335         $this->usertab= NULL;
336       } else {
338         /* Normally this shouldn't be reached, send some extra
339            logs to notify the administrator */
340         print_red (_("You are not allowed to delete this user!"));
342         if(isset($this->ui->uid)){
343           gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
344         }
345       }
347       /* Remove lock file after successfull deletion */
348       del_lock ($this->dn);
349     }
351     
352     /********************
353       Delete entry Canceled 
354      ********************/
356     /* Delete user canceled? */
357     if (isset($_POST['delete_cancel'])){
358       del_lock ($this->dn);
359     }
362     /********************
363       Edit entry finished (Save) 
364      ********************/
366     /* Finish user edit is triggered by the tabulator dialog, so
367        the user wants to save edited data. Check and save at this
368        point. */
369     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
371       /* Check tabs, will feed message array */
372       $this->usertab->last= $this->usertab->current;
373       $this->usertab->save_object();
374       $message= $this->usertab->check();
376       /* Save, or display error message? */
377       if (count($message) == 0){
379         /* No errors. Go ahead and prepare to ask for a password
380            in case we're creating a new user. 'dn' will be 'new'
381            in this case. It is set to the correct value later. */
382         if ($this->dn == "new"){
383           $set_pass= 1;
384         } else {
385           $set_pass= 0;
386         }
388         /* Save user data to ldap */
389         if($this->usertab->save() == 1){
390           gosa_log ("User object '".$this->dn."' saving failed.");
391           return;
392         }
393         gosa_log ("User object '".$this->dn."' has been saved");
395         if (!isset($_POST['edit_apply'])){
396           /* User has been saved successfully, remove lock from LDAP. */
397           if ($this->dn != "new"){
398             del_lock ($this->dn);
399           }
401           /* In case of new users, ask for a password, skip this for templates */
402           if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
403             return($smarty->fetch(get_template_path('password.tpl', TRUE)));
404           }
406           unset ($this->usertab);
407           $this->usertab= NULL;
408           unset ($_SESSION['objectinfo']);
409         }
410       } else {
411         /* Ok. There seem to be errors regarding to the tab data,
412            show message and continue as usual. */
413         show_errors($message);
414       }
415     }
418     /********************
419       We want to create a new user, so fetch all available user templates 
420      ********************/
422     /* Generate template list */
423     if (($s_action=="new")||($s_action=="create_user_from_tpl")){
425       $this->templates= array();
426       $ldap= $this->config->get_ldap_link();
428       /* Create list of templates */
429       foreach ($this->config->departments as $key => $value){
430     
431         /* Get acls from different ou's */
432         $ui  = get_userinfo();
433         $acl = $ui->get_permissions("cn=dummy,".$this->DivListUsers->selectedBase,"users/user")       ; 
434  
435         /* If creation of a new user is allowed, append this template */
436         if (preg_match("/r/",$acl)){
437           
438           /* Search all templates from the current dn */
439           $ldap->cd (get_people_ou().$value);
440           $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
442           /* Append */
443           if ($ldap->count() != 0){
444             while ($attrs= $ldap->fetch()){
445               $this->templates[$ldap->getDN()]=
446                 $attrs['uid'][0]." - ".@LDAP::fix($key);
447             }
448             $this->templates['none']= _("none");
449           }
450         }
451       }
453       /* Sort templates */
454       natcasesort ($this->templates);
455       reset ($this->templates);
456     }
459     /********************
460       Create a new user,template, user from template 
461      ********************/
463     /* Check selected options for template */
464     if (isset($_POST['template_continue'])){
465       $message = array();
466       if(!isset($_POST['template']) || (empty($_POST['template']))){
467         $message[] = _("Please select a valid template.");
468       }
469       if(!isset($_POST['sn']) || (empty($_POST['sn']))){
470         $message[]= _("The required field 'Name' is not set.");
471       }
472       if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
473         $message[]= _("The required field 'Given name' is not set.");
474       }
475     
476       /* Show error message / continue editing */
477       if (count($message) > 0){
478         show_errors ($message);
480         foreach(array("sn", "givenName", "uid", "template") as $attr){
481           if(isset($_POST[$attr])){
482             $smarty->assign("$attr", $_POST[$attr]);
483           }else{
484             $smarty->assign("$attr", "");
485           }
486         }
487         $smarty->assign("templates",$this->templates);
488         $smarty->assign("got_uid",$this->got_uid);
489         $smarty->assign("edit_uid",false);
490         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
492       }
493     }
495     /* New user/template request */
496     if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
497       /* By default we set 'dn' to 'new', all relevant plugins will
498          react on this. */
499       $this->dn= "new";
500       
501       if (isset($this->config->current['IDGEN'])){
502         $this->got_uid= false;
503       } else {
504         $this->got_uid= true;
505       }
507       /* Create new usertab object */
508       $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
509       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
510       $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
512       /* Take care about templates */
513       if ($s_action=="new_tpl"){
514         $this->is_template= TRUE;
515         $this->usertab->set_template_mode ();
516       } else {
517         $this->is_template= FALSE;
518       }
520       /* Use template if there are any of them */
521       if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
522         foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
523           $smarty->assign("$attr", $this->$attr);
524         }
525         if ($s_action=="create_user_from_tpl"){
526           $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
527         } else {
528           $smarty->assign("template", "none");
529         }
530         $smarty->assign("edit_uid", "");
531         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
532       }
533     }
535     /********************
536       Template selected continue edit
537      ********************/
539     /* Continue template editing */
540     if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
542       $this->sn             = $_POST['sn'];
543       $this->givenName      = $_POST['givenName'];
545       /* Check for requred values */
546       $message= array();
547       if ($this->sn == "") {
548         $message[]= _("The required field 'Name' is not set.");
549       }
550       if ($this->givenName == "") {
551         $message[]= _("The required field 'Given name' is not set.");
552       }
554       /* Check if dn is used */
555       $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
556       $ldap= $this->config->get_ldap_link();
557       $ldap->cd ($dn);
558       $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
559       if ($ldap->count () != 0){
560         $message[]= _("A person with the choosen name is already used in this tree.");
561       }
563       /* Show error message / continue editing */
564       if (count($message) > 0){
565         show_errors ($message);
566       } else {
567         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
568         if (isset($this->config->current['IDGEN']) &&
569             $this->config->current['IDGEN'] != ""){
570           $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
571           if (count($uids)){
572             $smarty->assign("edit_uid", "false");
573             $smarty->assign("uids", $uids);
574             $this->uid= current($uids);
575           }
576         } else {
577           $smarty->assign("edit_uid", "");
578           $this->uid= "";
579         }
580         $this->got_uid= true;
581       }
583       foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
584         $smarty->assign("$attr", $this->$attr);
585       }
586       if (isset($_POST['template'])){
587         $smarty->assign("template", $_POST['template']);
588       }
589       return($smarty->fetch(get_template_path('template.tpl', TRUE)));
590     }
592     /********************
593       No template selected continue edit
594      ********************/
596     /* No template. Ok. Lets fill data into the normal user dialog */
597     if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
598       foreach(array("sn", "givenName", "uid") as $attr){
599         if (isset($_POST[$attr])){
600           $this->usertab->by_object['user']->$attr= $_POST[$attr];
601         }
602       }
603     }
606     /********************
607       Template selected continue edit
608      ********************/
610     /* Finish template preamble */
611     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
613       /* Might not be filled if IDGEN is unset */
614       $this->sn                 = $_POST['sn'];
615       $this->givenName          = $_POST['givenName'];
617       /* Move user supplied data to sub plugins */
618       $this->uid                = $_POST['uid'];
619       $this->usertab->uid       = $this->uid;
620       $this->usertab->sn        = $this->sn;
621       $this->usertab->givenName = $this->givenName;
622       $template_dn              = $_POST['template'];
623       $this->usertab->adapt_from_template($template_dn);
624       $template_base            = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
625       $this->usertab->by_object['user']->base= $template_base;
626     }
627    
628  
629     /********************
630       If no template was selected set base
631      ********************/
633     if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
634       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
635     }
638     /********************
639       Display subdialog 
640      ********************/
642     /* Show tab dialog if object is present */
643     if(isset($this->usertab->config)){
644       $display= $this->usertab->execute();
646       /* Don't show buttons if tab dialog requests this */
647       if(isset($this->usertab->by_object)){
648         if (!$this->usertab->by_object[$this->usertab->current]->dialog){
649           $display.= "<p style=\"text-align:right\">\n";
650           $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
651           $display.= "&nbsp;\n";
652           if ($this->dn != "new"){
653             $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
654             $display.= "&nbsp;\n";
655           }
656           $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
657           $display.= "</p>";
658         }
659       }
660       return ($display);
661     }
662     
663     /* Check if there is a snapshot dialog open */
664     $base = $this->DivListUsers->selectedBase;
665     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
666       return($str);
667     }
668   
669     /* Return rendered main page */
670         /* Display dialog with system list */
671     $this->DivListUsers->parent = $this;
672     $this->DivListUsers->execute();
674     /* Add departments if subsearch is disabled */
675     if(!$this->DivListUsers->SubSearch){
676       $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4);
677     }
678     $this->reload();
679     $this->DivListUsers->setEntries($this->list);
680     return($this->DivListUsers->Draw());
681   }
684   /* Return departments, that will be included within snapshot detection */
685   function get_used_snapshot_bases()
686   {
687     return(array(get_people_ou().$this->DivListUsers->selectedBase));
688   }  
691   function reload()
692   {
693     /* Set base for all searches */
694     $base= $this->DivListUsers->selectedBase;
695     $this->list =array();
697     /* Get filter configuration */
698     $Regex                = $this->DivListUsers->Regex;
699     $SubSearch            = $this->DivListUsers->SubSearch;
700     $ShowTemplates        = $this->DivListUsers->ShowTemplates;
701     $ShowFunctionalUsers  = $this->DivListUsers->ShowFunctionalUsers;
702     $ShowUnixUsers        = $this->DivListUsers->ShowUnixUsers;
703     $ShowMailUsers        = $this->DivListUsers->ShowMailUsers;
704     $ShowSambaUsers       = $this->DivListUsers->ShowSambaUsers;
705     $ShowProxyUsers       = $this->DivListUsers->ShowProxyUsers;
707     /* Setup filter depending on selection */
708     $filter="";
709     if ($this->config->current['SAMBAVERSION'] == 3){
710       $samba= "sambaSamAccount";
711     } else {
712       $samba= "sambaAccount";
713     }
715     if ($ShowFunctionalUsers){
716       $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
717                 "(objectClass=gosaMailAccount)(objectClass=$samba)".
718                 "(objectClass=gosaProxyAccount))))";
719     }
720     if ($ShowUnixUsers){
721       $filter.= "(objectClass=posixAccount)";
722     }
723     if ($ShowMailUsers){
724       $filter.= "(objectClass=gosaMailAccount)";
725     }
726     if ($ShowSambaUsers){
727       $filter.= "(objectClass=$samba)";
728     }
729     if ($ShowProxyUsers){
730       $filter.= "(objectClass=gosaProxyAccount)";
731     }
732     if ($ShowTemplates){
733       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
734     } else {
735       $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
736     }
737     $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
739     /* Generate userlist */
740     $ldap= $this->config->get_ldap_link(TRUE);
742     if ($SubSearch){
743       $ListTemp =  get_list($filter, "users", $base,
744                             array("uid", "givenName", "sn", "objectClass"), GL_SUBSEARCH | GL_SIZELIMIT);
745     } else {
746       $base= get_people_ou().$base;
747       $ListTemp = get_list($filter, "users", $base, 
748                             array("uid", "givenName", "sn", "objectClass"), GL_SIZELIMIT);
749     }
750     $SortTemp = array();
751     $List = array();
752     foreach($ListTemp as $Key => $Entry){
753        // Generate caption for rows
754       if (isset($Entry["sn"]) && isset($Entry["givenName"])){
755         $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
756       } else {
757         $display= "[".$Entry["uid"][0]."]";
758       }
760       $display = strtolower($display);
761       $List[$display] = $Entry;
762       $SortTemp[$display] = $display;
763     }
764     sort($SortTemp);
765     reset($SortTemp);
767     $this->list = array();
768     foreach($SortTemp as $Key){
769       $this->list[] = $List[$Key];
770     }
771   }
773   function remove_lock()
774   {
775     /* Remove user lock if a DN is marked as "currently edited" */
776     if (isset($this->usertab->dn)){
777       del_lock ($this->usertab->dn);
778     }
779   }
781  
782   /* Perform copy & paste requests
783       If copy&paste is in progress this returns a dialog to fix required attributes 
784    */ 
785   function copyPasteHandling($s_action,$s_entry)
786   {
787     /* Only perform copy/paste if it is enabled */
788     if($this->CopyPasteHandler){
790       /* Prepare current object to be pasted */
791       if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){
793         $this->CopyPasteHandler->save_object();
794         $this->CopyPasteHandler->SetVar("base", $this->DivListUsers->selectedBase);
796         /* Execute copy & paste dialog and display returned data, normaly a dialog which allows 
797             us to solve all attribute mismatches for this object.
798             If nothing is returned, copy & paste was succesfully or aborted */
799         if(($ret= $this->CopyPasteHandler->execute())){
800           return ($ret);
801         }
803         /* Use the last dn to search for it's ID in the newly generated list. */
804         $dn= $this->CopyPasteHandler->lastdn;
805         foreach($this->list as $id => $entry){
806           if($entry['dn'] == $dn){
807             $s_entry= $id;
808             break;
809           }
810         }
811        
812         /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
813         if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
814           $this->CPPasswordChange = $s_entry;
815         }
816       }
818       /* Copy selected object 
819          Create a new empty object and the current selected object. 
820          Send both to copy&paste class*/
821       if($s_action == "copy"){
822         $this->CopyPasteHandler->Clear();
823         $dn= $this->list[trim($s_entry)]['dn'];
824         $obj    = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
825         $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new");
826         $this->CopyPasteHandler->Copy($obj,$objNew);
827       }
829       /* Cut selected object. 
830          Open user object and send it to the copy & paste handler */
831       if($s_action == "cut"){
832         $this->CopyPasteHandler->Clear();
833         $dn= $this->list[trim($s_entry)]['dn'];
834         $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
835         $this->CopyPasteHandler->Cut($obj);
836       }
837     }
838   }
840   function save_object()
841   {
842     /* Handle divlist filter && department selection*/
843     if(!is_object($this->usertab)){
844       $this->DivListUsers->save_object();
845     }
846   }
848   /* A set of disabled and therefore overloaded functions. They are
849      not needed in this class. */
850   function remove_from_parent() { } 
851   function check() { } 
852   function save() { } 
853   function adapt_from_template($dn) { } 
854   function password_change_needed() { } 
856 } /* ... class userManagement */
857 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
858 ?>