Code

Fixed userPassword change
[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 $templates            = array();
35   var $got_uid              = false;
36   var $CopyPasteHandler     = NULL;
37   var $CPPasswordChange     = ""; // Contains the entry id which should get a new password
38   var $DivListUsers;
40   function userManagement($config, $ui)
41   {
42     /* Save configuration for internal use */
43     $this->config= $config;
44     $this->ui= $ui;
46     /* Copy & Paste handler */
47     if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
48       $this->CopyPasteHandler= new CopyPasteHandler($this->config);
49     }
51     /* Creat dialog object */
52     $this->DivListUsers = new divListUsers($this->config,$this);
54   }
57   function execute()
58   {
59     /* Call parent execute */
60     plugin::execute();
62     /* LOCK MESSAGE Vars */
63     $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/");
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     if(!search_config($this->config->data['TABS'], $s_tab , "CLASS")){
108       $s_tab = "user";
109     }
111     /* Display the copy & paste dialog, if it is currently open */
112     $ret = $this->copyPasteHandling($s_action,$s_entry);
113     if($ret){
114       return($ret);
115     }
118     /********************
119       Edit existing entry 
120      ********************/
122     /* User wants to edit data? */
123     if (($s_action=="edit") && (!isset($this->usertab->config))){
125       /* Get 'dn' from posted 'uid', must be unique */
126       $this->dn= $this->list[trim($s_entry)]['dn'];
128       /* Check locking, save current plugin in 'back_plugin', so
129          the dialog knows where to return. */
130       if (($user= get_lock($this->dn)) != ""){
131         return(gen_locked_message ($user, $this->dn));
132       }
134       /* Lock the current entry, so everyone will get the
135          above dialog */
136       add_lock ($this->dn, $this->ui->dn);
138       /* Register usertab to trigger edit dialog */
139       $this->usertab= new usertabs($this->config, 
140           $this->config->data['TABS']['USERTABS'], $this->dn);
142       /* Switch tab, if it was requested by the user */
143       $this->usertab->current = $s_tab;
145       /* Set ACL and move DN to the headline */
146       $this->usertab->set_acl_base($this->dn);
147       $_SESSION['objectinfo']= $this->dn;
148     }
151     /********************
152       Edit canceled 
153      ********************/
155     /* Reset all relevant data, if we get a _cancel request */
156     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
157       if (isset($this->usertab)){
158         del_lock ($this->usertab->dn);
159         unset ($this->usertab);
160       }
161       $this->usertab= NULL;
162       $this->lognames= array();;
163       $this->sn= "";
164       $this->givenName= "";
165       $this->uid= "";
166       unset ($_SESSION['objectinfo']);
167     }
170     /********************
171       Change password requested  
172      ********************/
174     /* Password change requested */
175     if (($s_action == "change_pw") || (!empty($this->CPPasswordChange))){
177       if(!empty($this->CPPasswordChange)){
178         $s_entry = $this->CPPasswordChange;
179         $this->CPPasswordChange = "";
180       }
182       /* Get 'dn' from posted 'uid' */
183       $this->dn= $this->list[trim($s_entry)]['dn'];
185       /* Load permissions for selected 'dn' and check if
186          we're allowed to remove this 'dn' */
187       if (preg_match("/w/",$this->ui->get_permissions($this->dn,"users/password"))){
189         /* User is allowed to change passwords, save 'dn' and 'acl' for next
190            dialog. */
191         $_SESSION['objectinfo']= $this->dn;
192         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
194       } else {
195         /* User is not allowed. Show message and cancel. */
196         print_red (_("You are not allowed to set this users password!"));
197       }
198     }
201     /********************
202       Change password confirmed
203      ********************/
205     /* Perform password change */
206     if (isset($_POST['password_finish'])){
208       /* For security reasons, check if user is allowed to set password again */
209       $dn  = $this->dn;
210       $acl = $this->ui->get_permissions($dn, "users/password");
211       $cacl= $this->ui->get_permissions($dn, "users/user");
213       if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
215         /* Check input and feed errors into 'message' */
216         $message= array();
218         /* Sanity checks... */
219         if ($_POST['new_password'] != $_POST['repeated_password']){
221           /* Matching passwords in new and repeated? */
222           $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
223         } else {
225           /* Empty password is not permitted by default. */
226           if ($_POST['new_password'] == ""){
227             $message[]= _("The password you've entered as 'New password' is empty.");
228           }
229         }
231         /* Errors, or password change? */
232         if (count($message) != 0){
234           /* Show error message and continue editing */
235           show_errors ($message);
236           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
237         }
239         $config= $this->config;
240         $ldap_ui= $this->config->get_ldap_link();
241         if(isset($this->usertab->dn)){
242           $ldap_ui->cat($this->usertab->dn,array("uid"));
243           $user = $ldap_ui->fetch();
244         }else{
245           $ldap_ui->cat($this->dn,array("uid"));
246           $user = $ldap_ui->fetch();
247         }
248         if((is_array($user))&&(isset($user['uid']))){
249           $username= $user['uid'][0];
250         }
252         /* Set password, perform required steps */
253         if ($this->usertab){
254           if ($this->usertab->password_change_needed()){
255             $obj= $this->usertab->by_object['user'];
256             change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
257             if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
258               exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
259             }
261             gosa_log ("Password for '".$this->usertab->dn."' has been changed");
262             unset($this->usertab);
263             $this->usertab= NULL;
264           }
265         } else {
266           change_password ($this->dn, $_POST['new_password']);
267           if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
268             exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
269           }
271           gosa_log ("Password for '".$this->dn."' has been changed");
272         }
273       } else {
275         /* Missing permissions, show message */
276         print_red (_("You are not allowed to set this users password!"));
277       }
278       /* Clean session, delete lock */
279       del_lock ($this->dn);
280       unset ($this->usertab);
281       $this->usertab= NULL;
282       $this->lognames= array();;
283       $this->sn= "";
284       $this->givenName= "";
285       $this->uid= "";
286       unset ($_SESSION['objectinfo']);
287     }
290     /********************
291       Delete entry requested, display confirm dialog
292      ********************/
294     /* Remove user was requested */
295     if ($s_action=="del"){
297       /* Get 'dn' from posted 'uid' */
298       $this->dn= $this->list[trim($s_entry)]['dn'];
300       /* Load permissions for selected 'dn' and check if
301          we're allowed to remove this 'dn' */
303       /* Check locking, save current plugin in 'back_plugin', so
304          the dialog knows where to return. */
305       if (($user= get_lock($this->dn)) != ""){
306         return(gen_locked_message ($user, $this->dn));
307       }
309       /* Lock the current entry, so nobody will edit it during deletion */
310       add_lock ($this->dn, $this->ui->dn);
311       $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
312       return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
313     }
316     /********************
317       Delete entry confirmed 
318      ********************/
320     /* Confirmation for deletion has been passed. User should be deleted. */
321     if (isset($_POST['delete_user_confirm'])){
323       /* Some nice guy may send this as POST, so we've to check
324          for the permissions again. */
326       $acl = $this->ui->get_permissions($this->dn, "users/user"); 
327  
328       if (preg_match('/d/', $acl)){
330         /* Delete request is permitted, perform LDAP action */
331         $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
332         $this->usertab->set_acl_base();
333         $this->usertab->delete ();
334         gosa_log ("User object '".$this->dn."' has been removed");
335         unset ($this->usertab);
336         $this->usertab= NULL;
337       } else {
339         /* Normally this shouldn't be reached, send some extra
340            logs to notify the administrator */
341         print_red (_("You are not allowed to delete this user!"));
343         if(isset($this->ui->uid)){
344           gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
345         }
346       }
348       /* Remove lock file after successfull deletion */
349       del_lock ($this->dn);
350     }
352     
353     /********************
354       Delete entry Canceled 
355      ********************/
357     /* Delete user canceled? */
358     if (isset($_POST['delete_cancel'])){
359       del_lock ($this->dn);
360     }
363     /********************
364       Edit entry finished (Save) 
365      ********************/
367     /* Finish user edit is triggered by the tabulator dialog, so
368        the user wants to save edited data. Check and save at this
369        point. */
370     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
372       /* Check tabs, will feed message array */
373       $this->usertab->last= $this->usertab->current;
374       $this->usertab->save_object();
375       $message= $this->usertab->check();
377       /* Save, or display error message? */
378       if (count($message) == 0){
380         /* No errors. Go ahead and prepare to ask for a password
381            in case we're creating a new user. 'dn' will be 'new'
382            in this case. It is set to the correct value later. */
383         if ($this->dn == "new"){
384           $set_pass= 1;
385         } else {
386           $set_pass= 0;
387         }
389         /* Save user data to ldap */
390         if($this->usertab->save() == 1){
391           gosa_log ("User object '".$this->dn."' saving failed.");
392           return;
393         }
394         gosa_log ("User object '".$this->dn."' has been saved");
396         if (!isset($_POST['edit_apply'])){
397           /* User has been saved successfully, remove lock from LDAP. */
398           if ($this->dn != "new"){
399             del_lock ($this->dn);
400           }
402           /* In case of new users, ask for a password, skip this for templates */
403           if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
404             $this->dn = $this->usertab->dn;
405             return($smarty->fetch(get_template_path('password.tpl', TRUE)));
406           }
408           unset ($this->usertab);
409           $this->usertab= NULL;
410           unset ($_SESSION['objectinfo']);
411         }
412       } else {
413         /* Ok. There seem to be errors regarding to the tab data,
414            show message and continue as usual. */
415         show_errors($message);
416       }
417     }
420     /********************
421       We want to create a new user, so fetch all available user templates 
422      ********************/
424     /* Generate template list */
425     if (($s_action=="new")||($s_action=="create_user_from_tpl")){
427       $this->templates= array();
428       $ldap= $this->config->get_ldap_link();
430       /* Create list of templates */
431       foreach ($this->config->departments as $key => $value){
432     
433         /* Get acls from different ou's */
434         $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user")       ; 
435  
436         /* If creation of a new user is allowed, append this template */
437         if (preg_match("/c/",$acl)){
438           
439           /* Search all templates from the current dn */
440           $ldap->cd (get_people_ou().$value);
441           $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
443           /* Append */
444           if ($ldap->count() != 0){
445             while ($attrs= $ldap->fetch()){
446               $this->templates[$ldap->getDN()]=
447                 $attrs['uid'][0]." - ".@LDAP::fix($key);
448             }
449             $this->templates['none']= _("none");
450           }
451         }
452       }
454       /* Sort templates */
455       natcasesort ($this->templates);
456       reset ($this->templates);
457     }
460     /********************
461       Create a new user,template, user from template 
462      ********************/
464     /* Check selected options for template */
465     if (isset($_POST['template_continue'])){
466       $message = array();
467       if(!isset($_POST['template']) || (empty($_POST['template']))){
468         $message[] = _("Please select a valid template.");
469       }
470       if(!isset($_POST['sn']) || (empty($_POST['sn']))){
471         $message[]= _("The required field 'Name' is not set.");
472       }
473       if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
474         $message[]= _("The required field 'Given name' is not set.");
475       }
476     
477       /* Show error message / continue editing */
478       if (count($message) > 0){
479         show_errors ($message);
481         foreach(array("sn", "givenName", "uid", "template") as $attr){
482           if(isset($_POST[$attr])){
483             $smarty->assign("$attr", $_POST[$attr]);
484           }else{
485             $smarty->assign("$attr", "");
486           }
487         }
488         $smarty->assign("templates",$this->templates);
489         $smarty->assign("got_uid",$this->got_uid);
490         $smarty->assign("edit_uid",false);
491         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
493       }
494     }
496     /* New user/template request */
497     if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
498       /* By default we set 'dn' to 'new', all relevant plugins will
499          react on this. */
500       $this->dn= "new";
501       
502       if (isset($this->config->current['IDGEN'])){
503         $this->got_uid= false;
504       } else {
505         $this->got_uid= true;
506       }
508       /* Create new usertab object */
509       $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
510       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
511       $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
513       /* Take care about templates */
514       if ($s_action=="new_tpl"){
515         $this->is_template= TRUE;
516         $this->usertab->set_template_mode ();
517       } else {
518         $this->is_template= FALSE;
519       }
521       /* Use template if there are any of them */
522       if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
523         foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
524           $smarty->assign("$attr", $this->$attr);
525         }
526         if ($s_action=="create_user_from_tpl"){
527           $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
528         } else {
529           $smarty->assign("template", "none");
530         }
531         $smarty->assign("edit_uid", "");
532         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
533       }
534     }
536     /********************
537       Template selected continue edit
538      ********************/
540     /* Continue template editing */
541     if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
543       $this->sn             = $_POST['sn'];
544       $this->givenName      = $_POST['givenName'];
546       /* Check for requred values */
547       $message= array();
548       if ($this->sn == "") {
549         $message[]= _("The required field 'Name' is not set.");
550       }
551       if ($this->givenName == "") {
552         $message[]= _("The required field 'Given name' is not set.");
553       }
555       /* Check if dn is used */
556       $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
557       $ldap= $this->config->get_ldap_link();
558       $ldap->cd ($dn);
559       $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
560       if ($ldap->count () != 0){
561         $message[]= _("A person with the choosen name is already used in this tree.");
562       }
564       /* Show error message / continue editing */
565       if (count($message) > 0){
566         show_errors ($message);
567       } else {
568         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
569         if (isset($this->config->current['IDGEN']) &&
570             $this->config->current['IDGEN'] != ""){
571           $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
572           if (count($uids)){
573             $smarty->assign("edit_uid", "false");
574             $smarty->assign("uids", $uids);
575             $this->uid= current($uids);
576           }
577         } else {
578           $smarty->assign("edit_uid", "");
579           $this->uid= "";
580         }
581         $this->got_uid= true;
582       }
584       foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
585         $smarty->assign("$attr", $this->$attr);
586       }
587       if (isset($_POST['template'])){
588         $smarty->assign("template", $_POST['template']);
589       }
590       return($smarty->fetch(get_template_path('template.tpl', TRUE)));
591     }
593     /********************
594       No template selected continue edit
595      ********************/
597     /* No template. Ok. Lets fill data into the normal user dialog */
598     if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
599       foreach(array("sn", "givenName", "uid") as $attr){
600         if (isset($_POST[$attr])){
601           $this->usertab->by_object['user']->$attr= $_POST[$attr];
602         }
603       }
604     }
607     /********************
608       Template selected continue edit
609      ********************/
611     /* Finish template preamble */
612     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
614       /* Might not be filled if IDGEN is unset */
615       $this->sn                 = $_POST['sn'];
616       $this->givenName          = $_POST['givenName'];
618       /* Move user supplied data to sub plugins */
619       $this->uid                = $_POST['uid'];
620       $this->usertab->uid       = $this->uid;
621       $this->usertab->sn        = $this->sn;
622       $this->usertab->givenName = $this->givenName;
623       $template_dn              = $_POST['template'];
624       $this->usertab->adapt_from_template($template_dn);
625       $template_base            = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
626       $this->usertab->by_object['user']->base= $template_base;
627     }
628    
629  
630     /********************
631       If no template was selected set base
632      ********************/
634     if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
635       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
636     }
639     /********************
640       Display subdialog 
641      ********************/
643     /* Show tab dialog if object is present */
644     if(isset($this->usertab->config)){
645       $display= $this->usertab->execute();
647       /* Don't show buttons if tab dialog requests this */
648       if(isset($this->usertab->by_object)){
649         if (!$this->usertab->by_object[$this->usertab->current]->dialog){
650           $display.= "<p style=\"text-align:right\">\n";
651           $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
652           $display.= "&nbsp;\n";
653           if ($this->dn != "new"){
654             $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
655             $display.= "&nbsp;\n";
656           }
657           $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
658           $display.= "</p>";
659         }
660       }
661       return ($display);
662     }
663     
664     /* Check if there is a snapshot dialog open */
665     $base = $this->DivListUsers->selectedBase;
666     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
667       return($str);
668     }
669   
670     /* Return rendered main page */
671         /* Display dialog with system list */
672     $this->DivListUsers->parent = $this;
673     $this->DivListUsers->execute();
675     /* Add departments if subsearch is disabled */
676     if(!$this->DivListUsers->SubSearch){
677       $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4);
678     }
679     $this->reload();
680     $this->DivListUsers->setEntries($this->list);
681     return($this->DivListUsers->Draw());
682   }
685   /* Return departments, that will be included within snapshot detection */
686   function get_used_snapshot_bases()
687   {
688     return(array(get_people_ou().$this->DivListUsers->selectedBase));
689   }  
692   function reload()
693   {
694     /* Set base for all searches */
695     $base= $this->DivListUsers->selectedBase;
696     $this->list =array();
698     /* Get filter configuration */
699     $Regex                = $this->DivListUsers->Regex;
700     $SubSearch            = $this->DivListUsers->SubSearch;
701     $ShowTemplates        = $this->DivListUsers->ShowTemplates;
702     $ShowFunctionalUsers  = $this->DivListUsers->ShowFunctionalUsers;
703     $ShowUnixUsers        = $this->DivListUsers->ShowUnixUsers;
704     $ShowMailUsers        = $this->DivListUsers->ShowMailUsers;
705     $ShowSambaUsers       = $this->DivListUsers->ShowSambaUsers;
706     $ShowProxyUsers       = $this->DivListUsers->ShowProxyUsers;
708     /* Setup filter depending on selection */
709     $filter="";
710     if ($this->config->current['SAMBAVERSION'] == 3){
711       $samba= "sambaSamAccount";
712     } else {
713       $samba= "sambaAccount";
714     }
716     if ($ShowFunctionalUsers){
717       $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
718                 "(objectClass=gosaMailAccount)(objectClass=$samba)".
719                 "(objectClass=gosaProxyAccount))))";
720     }
721     if ($ShowUnixUsers){
722       $filter.= "(objectClass=posixAccount)";
723     }
724     if ($ShowMailUsers){
725       $filter.= "(objectClass=gosaMailAccount)";
726     }
727     if ($ShowSambaUsers){
728       $filter.= "(objectClass=$samba)";
729     }
730     if ($ShowProxyUsers){
731       $filter.= "(objectClass=gosaProxyAccount)";
732     }
733     if ($ShowTemplates){
734       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
735     } else {
736       $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
737     }
738     $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
740     /* Generate userlist */
741     $ldap= $this->config->get_ldap_link(TRUE);
743     if ($SubSearch){
744       $ListTemp =  get_list($filter, "users", $base,
745                             array("uid", "givenName", "sn", "objectClass"), GL_SUBSEARCH | GL_SIZELIMIT);
746     } else {
747       $base= get_people_ou().$base;
748       $ListTemp = get_list($filter, "users", $base, 
749                             array("uid", "givenName", "sn", "objectClass"), GL_SIZELIMIT);
750     }
751     $SortTemp = array();
752     $List = array();
753     foreach($ListTemp as $Key => $Entry){
754        // Generate caption for rows
755       if (isset($Entry["sn"]) && isset($Entry["givenName"])){
756         $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
757       } else {
758         $display= "[".$Entry["uid"][0]."]";
759       }
761       $display = strtolower($display);
762       $List[$display] = $Entry;
763       $SortTemp[$display] = $display;
764     }
765     sort($SortTemp);
766     reset($SortTemp);
768     $this->list = array();
769     foreach($SortTemp as $Key){
770       $this->list[] = $List[$Key];
771     }
772   }
774   function remove_lock()
775   {
776     /* Remove user lock if a DN is marked as "currently edited" */
777     if (isset($this->usertab->dn)){
778       del_lock ($this->usertab->dn);
779     }
780   }
782  
783   /* Perform copy & paste requests
784       If copy&paste is in progress this returns a dialog to fix required attributes 
785    */ 
786   function copyPasteHandling($s_action,$s_entry)
787   {
788     /* Only perform copy/paste if it is enabled */
789     if($this->CopyPasteHandler){
791       /* Prepare current object to be pasted */
792       if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){
794         $this->CopyPasteHandler->save_object();
795         $this->CopyPasteHandler->SetVar("base", $this->DivListUsers->selectedBase);
797         /* Execute copy & paste dialog and display returned data, normaly a dialog which allows 
798             us to solve all attribute mismatches for this object.
799             If nothing is returned, copy & paste was succesfully or aborted */
800         if(($ret= $this->CopyPasteHandler->execute())){
801           return ($ret);
802         }
804         /* Use the last dn to search for it's ID in the newly generated list. */
805         $dn= $this->CopyPasteHandler->lastdn;
807         /* Get new user list */
808         $this->reload();
809         foreach($this->list as $id => $entry){
810           if($entry['dn'] == $dn){
811             $s_entry= $id;
812             break;
813           }
814         }
815        
816         /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
817         if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
818           $this->CPPasswordChange = $s_entry;
819         }
820       }
822       /* Copy selected object 
823          Create a new empty object and the current selected object. 
824          Send both to copy&paste class*/
825       if($s_action == "copy"){
826         $this->CopyPasteHandler->Clear();
827         $dn= $this->list[trim($s_entry)]['dn'];
829         /* Check acl */
830         $acl = $this->ui->get_permissions($dn,"users/user");
831         if(preg_match("/(c.*w|w.*c)/",$acl)){
832           $obj    = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
833           $obj->set_acl_base($dn);
834           $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new");
835           $objNew->set_acl_base($dn);
837           $this->CopyPasteHandler->Copy($obj,$objNew);
838         }else{
839           print_red("You are not allowed to copy this entry.");
840         }
841       }
843       /* Cut selected object. 
844          Open user object and send it to the copy & paste handler */
845       if($s_action == "cut"){
846         $this->CopyPasteHandler->Clear();
847         $dn= $this->list[trim($s_entry)]['dn'];
849         /* Check acl */
850         $acl = $this->ui->get_permissions($dn,"users/user");
851         if(preg_match("/(c.*w|w.*c)/",$acl)){
852           $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
853           $obj->set_acl_base($dn);
854           $this->CopyPasteHandler->Cut($obj);
855         }else{
856           print_red("You are not allowed to cut this entry.");
857         }
858       }
859     }
860   }
862   function save_object()
863   {
864     /* Handle divlist filter && department selection*/
865     if(!is_object($this->usertab)){
866       $this->DivListUsers->save_object();
867     }
868   }
870   /* A set of disabled and therefore overloaded functions. They are
871      not needed in this class. */
872   function remove_from_parent() { } 
873   function check() { } 
874   function save() { } 
875   function adapt_from_template($dn) { } 
876   function password_change_needed() { } 
878 } /* ... class userManagement */
879 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
880 ?>