Code

Updated user list, allow multiple password changes.
[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   var $pwd_change_queue     = array();
42   var $start_pasting_copied_objects = FALSE;
44   function userManagement($config, $ui)
45   {
46     /* Save configuration for internal use */
47     $this->config= $config;
48     $this->ui= $ui;
50     /* Copy & Paste handler */
51     if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
52       $this->CopyPasteHandler= new CopyPasteHandler($this->config);
53     }
55     /* Creat dialog object */
56     $this->DivListUsers = new divListUsers($this->config,$this);
58   }
61   function execute()
62   {
63     /* Call parent execute */
64     plugin::execute();
66     /* LOCK MESSAGE Vars */
67     $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/","/^item_selected/","/^remove_multiple_users/");
69     $smarty       = get_smarty();                 // Smarty instance
70     $s_action     = "";                           // Contains the action to be taken
71     $s_entry      = "";                           // The value for s_action
73     /* Edit entry button pressed? */
74     if( isset($_GET['act']) && $_GET['act'] == "edit_entry" ){
75       $s_action= "edit";
76       $s_entry= validate($_GET['id']);
77     }
79     /* Test relevant POST values */  
80     foreach($_POST as $key => $val){
82       /* Get every possible POST combination and set s_action/s_entry accordingly */
83       foreach(array("del"       => "user_del",    "edit"      => "user_edit",
84                     "new"       => "user_new",
85                     "new_tpl"   => "user_tplnew",
86                     "del_multiple" => "^remove_multiple_users",
87                     "create_user_from_tpl"          => "userfrom_tpl",
88                     "change_pw" => "user_chgpw", 
89                     "editPaste" => "editPaste",  
90                     "copy_multiple" => "multiple_copy_users",
91                     "cut_multiple" => "multiple_cut_users",
92                     "multiple_password_change" => "multiple_password_change",
93                     "copy"      => "^copy",
94                     "toggle_lock_status" => "toggle_lock_status",
95                     "cut"       => "^cut") as $act => $name){
97         if (preg_match("/".$name.".*/", $key)){
98           $s_action= $act;
99           $s_entry= preg_replace("/".$name."_/i", "", $key);
100           break;
101         }
102       }
103       
104     } /* ...Test POST */
106     /* Remove coordinate prefix from POST, required by some browsers */
107     $s_entry= preg_replace("/_.$/", "", $s_entry);
109     /* Seperate possibly encoded tab and entry, default to tab "user" */
110     if(preg_match("/.*-.*/", $s_entry)){
111       $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
112       $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
113     }else{
114       $s_tab= "user";
115     }
117     if(!search_config($this->config->data['TABS'], $s_tab , "CLASS")){
118       $s_tab = "user";
119     }
122     /********************
123       Copy & Paste 
124      ********************/
126     /* Display the copy & paste dialog, if it is currently open */
127     if($this->CPPasswordChange == ""){
128       $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
129       if($ret){
130         return($ret);
131       }
132     }
135     /********************
136       Change password confirmed
137      ********************/
139     /* Perform password change */
140     if (isset($_POST['password_finish'])){
142       /* For security reasons, check if user is allowed to set password again */
143       $dn  = $this->dn;
144       $acl = $this->ui->get_permissions($dn, "users/password");
145       $cacl= $this->ui->get_permissions($dn, "users/user");
147       if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
149         /* Check input and feed errors into 'message' */
150         $message= array();
152         /* Sanity checks... */
153         if ($_POST['new_password'] != $_POST['repeated_password']){
155           /* Matching passwords in new and repeated? */
156           $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
157         } else {
159           /* Empty password is not permitted by default. */
160           if ($_POST['new_password'] == ""){
161             $message[]= _("The password you've entered as 'New password' is empty.");
162           }
163         }
165         /* Errors, or password change? */
166         if (count($message) != 0){
168           /* Show error message and continue editing */
169           show_errors ($message);
170           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
171         }
173         $config= $this->config;
174         $ldap_ui= $this->config->get_ldap_link();
175         if(isset($this->usertab->dn)){
176           $ldap_ui->cat($this->usertab->dn,array("uid"));
177           $user = $ldap_ui->fetch();
178         }else{
179           $ldap_ui->cat($this->dn,array("uid"));
180           $user = $ldap_ui->fetch();
181         }
182         if((is_array($user))&&(isset($user['uid']))){
183           $username= $user['uid'][0];
184         }
186         /* Set password, perform required steps */
187         if ($this->usertab){
188           if ($this->usertab->password_change_needed()){
189             $obj= $this->usertab->by_object['user'];
190             change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
191             if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
192               exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
193             }
194             new log("modify","users/".get_class($this),$this->usertab->dn,array(),"Password has been changed");
195             unset($this->usertab);
196             $this->usertab= NULL;
197           }
198         } else {
199           change_password ($this->dn, $_POST['new_password']);
200           if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
201             exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
202           }
203           new log("modify","users/".get_class($this),$this->dn,array(),"Password has been changed");
204         }
205       } else {
207         /* Missing permissions, show message */
208         print_red (_("You are not allowed to set this users password!"));
209       }
210       /* Clean session, delete lock */
211       del_lock ($this->dn);
212       unset ($this->usertab);
213       $this->usertab= NULL;
214       $this->lognames= array();;
215       $this->sn= "";
216       $this->givenName= "";
217       $this->uid= "";
218       unset ($_SESSION['objectinfo']);
219     }
222     /********************
223      Change multiple passwords requested 
224      ********************/
225   
226     if($s_action == "multiple_password_change"){
227       $this->pwd_change_queue = $this->list_get_selected_items();
228     }    
231     /********************
232       Change password requested  
233      ********************/
235     /* Password change requested */
236     if (($s_action == "change_pw") || (!empty($this->CPPasswordChange)) || count($this->pwd_change_queue)){
238       /* Get users whose passwords should be changed. */
239       if(count($this->pwd_change_queue)){
240         $s_entry= array_pop($this->pwd_change_queue);
241       }
243       if(!empty($this->CPPasswordChange)){
244         $s_entry = $this->CPPasswordChange;
245         $this->CPPasswordChange = "";
246       }
248       /* Get 'dn' from posted 'uid' */
249       $this->dn= $this->list[trim($s_entry)]['dn'];
251       /* Load permissions for selected 'dn' and check if
252          we're allowed to remove this 'dn' */
253       if (preg_match("/w/",$this->ui->get_permissions($this->dn,"users/password"))){
255         /* User is allowed to change passwords, save 'dn' and 'acl' for next
256            dialog. */
257         $_SESSION['objectinfo']= $this->dn;
258         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
260       } else {
261         /* User is not allowed. Show message and cancel. */
262         print_red (_("You are not allowed to set this users password!"));
263       }
264     }
269     /********************
270       Edit existing entry 
271      ********************/
273     /* User wants to edit data? */
274     if (($s_action=="edit") && (!isset($this->usertab->config))){
276       /* Get 'dn' from posted 'uid', must be unique */
277       $this->dn= $this->list[trim($s_entry)]['dn'];
279       /* Check locking, save current plugin in 'back_plugin', so
280          the dialog knows where to return. */
281       if (($user= get_lock($this->dn)) != ""){
282         return(gen_locked_message ($user, $this->dn));
283       }
285       /* Lock the current entry, so everyone will get the
286          above dialog */
287       add_lock ($this->dn, $this->ui->dn);
289       /* Register usertab to trigger edit dialog */
290       $this->usertab= new usertabs($this->config, 
291           $this->config->data['TABS']['USERTABS'], $this->dn);
293       /* Switch tab, if it was requested by the user */
294       $this->usertab->current = $s_tab;
296       /* Set ACL and move DN to the headline */
297       $this->usertab->set_acl_base($this->dn);
298       $_SESSION['objectinfo']= $this->dn;
299     }
302     /********************
303       Edit canceled 
304      ********************/
306     /* Reset all relevant data, if we get a _cancel request */
307     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
308       if (isset($this->usertab)){
309         del_lock ($this->usertab->dn);
310         unset ($this->usertab);
311       }
312       $this->usertab= NULL;
313       $this->lognames= array();;
314       $this->sn= "";
315       $this->givenName= "";
316       $this->uid= "";
317       unset ($_SESSION['objectinfo']);
318     }
321     /********************
322       Delete MULTIPLE entries requested, display confirm dialog
323      ********************/
325     if ($s_action=="del_multiple"){
326       $ids = $this->list_get_selected_items();
328       if(count($ids)){
330         foreach($ids as $id){
331           $dn = $this->list[$id]['dn'];
332           if (($user= get_lock($dn)) != ""){
333             return(gen_locked_message ($user, $dn));
334           }
335           $this->dns[$id] = $dn; 
336         }
338         $dns_names = "<br><pre>";
339         foreach($this->dns as $dn){
340           add_lock ($dn, $this->ui->dn);
341           $dns_names .= $dn."\n";
342         }
343         $dns_names .="</pre>";
345         /* Lock the current entry, so nobody will edit it during deletion */
346         if (count($this->dns) == 1){
347           $smarty->assign("info",     sprintf(_("You're about to delete the following entry: %s"), @LDAP::fix($dns_names)));
348         } else {
349           $smarty->assign("info",     sprintf(_("You're about to delete the following entries: %s"), @LDAP::fix($dns_names)));
350         }
351         $smarty->assign("multiple", true);
352         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
353       }
354     }
357     /********************
358       Delete MULTIPLE entries confirmed 
359      ********************/
361       /* Confirmation for deletion has been passed. Users should be deleted. */
362       if (isset($_POST['delete_multiple_user_confirm'])){
364         /* Remove user by user and check acls before removeing them */
365         foreach($this->dns as $key => $dn){
367           $acl = $this->ui->get_permissions($dn, "users/user"); 
368           if (preg_match('/d/', $acl)){
370             /* Delete request is permitted, perform LDAP action */
371             $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn);
372             $this->usertab->set_acl_base();
373             $this->usertab->delete ();
374             unset ($this->usertab);
375             $this->usertab= NULL;
376           } else {
377             print_red (sprintf(_("You are not allowed to delete the user '%s'!"),$dn));
378             if(isset($this->ui->uid)){
379               new log("security","users/".get_class($this),$dn,array(),"Tried to trick deletion.");
380             }
381           }
382           /* Remove lock file after successfull deletion */
383           del_lock ($dn);
384           unset($this->dns[$key]);
385       }
386     }
389     /********************
390       Delete MULTIPLE entries Canceled 
391      ********************/
393     /* Remove lock */
394     if(isset($_POST['delete_multiple_user_cancel'])){
395       foreach($this->dns as $key => $dn){
396         del_lock ($dn);
397         unset($this->dns[$key]);
398       }
399     }
400   
401   
402     /********************
403       Toggle lock status for user
404      ********************/
405   
406     if($s_action == "toggle_lock_status" && isset($this->list[$s_entry])){
408       /* Get entry check current status */
409       $val = $this->list[$s_entry];
410       $pwd = $val['userPassword'][0];
412       if(!preg_match("/^\{[^\}]/",$pwd)){
413         trigger_error("Can not deactivate user which is using clear password encryption.");
414       }else{
416         $locked = false;
417         if(preg_match("/^[^\}]*+\}!/",$pwd)){
418           $locked = true;
419         }
421         /* Create ldap array to update status */
422         $attrs = array("userPassword" => $pwd);
423         if($locked){
424           $attrs['userPassword'] = preg_replace("/(^[^\}]+\})!(.*$)/","\\1\\2",$attrs['userPassword']);
425         }else{
426           $attrs['userPassword'] = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$attrs['userPassword']);
427         }
429         /* Write new status back to ldap */
430         $ldap = $this->config->get_ldap_link();
431         $ldap->cd($val['dn']);
432         $ldap->modify($attrs);
433         if($locked){
434           show_ldap_error($ldap->get_error(),_("Could not set user status from locked to unlocked."));
435         }else{
436           show_ldap_error($ldap->get_error(),_("Could not set user status from unlocked to locked."));
437         }
438       }
439     }
442     /********************
443       Delete entry requested, display confirm dialog
444      ********************/
446     /* Remove user was requested */
447     if ($s_action=="del"){
449       /* Get 'dn' from posted 'uid' */
450       $this->dn= $this->list[trim($s_entry)]['dn'];
452       /* Load permissions for selected 'dn' and check if
453          we're allowed to remove this 'dn' */
455       /* Check locking, save current plugin in 'back_plugin', so
456          the dialog knows where to return. */
457       if (($user= get_lock($this->dn)) != ""){
458         return(gen_locked_message ($user, $this->dn));
459       }
461       /* Lock the current entry, so nobody will edit it during deletion */
462       add_lock ($this->dn, $this->ui->dn);
463       $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
464       $smarty->assign("multiple", false);
465       return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
466     }
469     /********************
470       Delete entry confirmed 
471      ********************/
473     /* Confirmation for deletion has been passed. User should be deleted. */
474     if (isset($_POST['delete_user_confirm'])){
476       /* Some nice guy may send this as POST, so we've to check
477          for the permissions again. */
479       $acl = $this->ui->get_permissions($this->dn, "users/user"); 
480  
481       if (preg_match('/d/', $acl)){
483         /* Delete request is permitted, perform LDAP action */
484         $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
485         $this->usertab->set_acl_base();
486         $this->usertab->delete ();
487         unset ($this->usertab);
488         $this->usertab= NULL;
489       } else {
491         /* Normally this shouldn't be reached, send some extra
492            logs to notify the administrator */
493         print_red (_("You are not allowed to delete this user!"));
495         if(isset($this->ui->uid)){
496           new log("security","users/".get_class($this),$this->dn,array(),"Tried to trick deletion.");
497         }
498       }
500       /* Remove lock file after successfull deletion */
501       del_lock ($this->dn);
502     }
504     
505     /********************
506       Delete entry Canceled 
507      ********************/
509     /* Delete user canceled? */
510     if (isset($_POST['delete_cancel'])){
511       del_lock ($this->dn);
512     }
515     /********************
516       Edit entry finished (Save) 
517      ********************/
519     /* Finish user edit is triggered by the tabulator dialog, so
520        the user wants to save edited data. Check and save at this
521        point. */
522     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
524       /* Check tabs, will feed message array */
525       $this->usertab->last= $this->usertab->current;
526       $this->usertab->save_object();
527       $message= $this->usertab->check();
529       /* Save, or display error message? */
530       if (count($message) == 0){
532         /* No errors. Go ahead and prepare to ask for a password
533            in case we're creating a new user. 'dn' will be 'new'
534            in this case. It is set to the correct value later. */
535         if ($this->dn == "new"){
536           $set_pass= 1;
537         } else {
538           $set_pass= 0;
539         }
541         /* Save user data to ldap */
542         if($this->usertab->save() == 1){
543           return;
544         }
546         if (!isset($_POST['edit_apply'])){
547           /* User has been saved successfully, remove lock from LDAP. */
548           if ($this->dn != "new"){
549             del_lock ($this->dn);
550           }
552           /* In case of new users, ask for a password, skip this for templates */
553           if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
554             $this->dn = $this->usertab->dn;
555             return($smarty->fetch(get_template_path('password.tpl', TRUE)));
556           }
558           unset ($this->usertab);
559           $this->usertab= NULL;
560           unset ($_SESSION['objectinfo']);
561         }
562       } else {
563         /* Ok. There seem to be errors regarding to the tab data,
564            show message and continue as usual. */
565         show_errors($message);
566       }
567     }
570     /********************
571       We want to create a new user, so fetch all available user templates 
572      ********************/
574     /* Generate template list */
575     if (($s_action=="new")||($s_action=="create_user_from_tpl")){
577       $this->templates= array();
578       $ldap= $this->config->get_ldap_link();
580       /* Create list of templates */
581       foreach ($this->config->departments as $key => $value){
582     
583         /* Get acls from different ou's */
584         $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user")       ; 
585  
586         /* If creation of a new user is allowed, append this template */
587         if (preg_match("/c/",$acl)){
588           
589           /* Search all templates from the current dn */
590           $ldap->cd (get_people_ou().$value);
591           $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
593           /* Append */
594           if ($ldap->count() != 0){
595             while ($attrs= $ldap->fetch()){
596               $this->templates[$ldap->getDN()]=
597                 $attrs['uid'][0]." - ".@LDAP::fix($key);
598             }
599             $this->templates['none']= _("none");
600           }
601         }
602       }
604       /* Sort templates */
605       natcasesort ($this->templates);
606       reset ($this->templates);
607     }
610     /********************
611       Create a new user,template, user from template 
612      ********************/
614     /* Check selected options for template */
615     if (isset($_POST['template_continue'])){
616       $message = array();
617       if(!isset($_POST['template']) || (empty($_POST['template']))){
618         $message[] = _("Please select a valid template.");
619       }
620       if(!isset($_POST['sn']) || (empty($_POST['sn']))){
621         $message[]= _("The required field 'Name' is not set.");
622       }
623       if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
624         $message[]= _("The required field 'Given name' is not set.");
625       }
626     
627       /* Show error message / continue editing */
628       if (count($message) > 0){
629         show_errors ($message);
631         foreach(array("sn", "givenName", "uid", "template") as $attr){
632           if(isset($_POST[$attr])){
633             $smarty->assign("$attr", $_POST[$attr]);
634           }else{
635             $smarty->assign("$attr", "");
636           }
637         }
638         $smarty->assign("templates",$this->templates);
639         $smarty->assign("got_uid",$this->got_uid);
640         $smarty->assign("edit_uid",false);
641         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
643       }
644     }
646     /* New user/template request */
647     if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
648       /* By default we set 'dn' to 'new', all relevant plugins will
649          react on this. */
650       $this->dn= "new";
651       
652       if (isset($this->config->current['IDGEN'])){
653         $this->got_uid= false;
654       } else {
655         $this->got_uid= true;
656       }
658       /* Create new usertab object */
659       $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
660       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
661       $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
663       /* Take care about templates */
664       if ($s_action=="new_tpl"){
665         $this->is_template= TRUE;
666         $this->usertab->set_template_mode ();
667       } else {
668         $this->is_template= FALSE;
669       }
671       /* Use template if there are any of them */
672       if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
673         foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
674           $smarty->assign("$attr", $this->$attr);
675         }
676         if ($s_action=="create_user_from_tpl"){
677           $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
678         } else {
679           $smarty->assign("template", "none");
680         }
681         $smarty->assign("edit_uid", "");
682         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
683       }
684     }
686     /********************
687       Template selected continue edit
688      ********************/
690     /* Continue template editing */
691     if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
693       $this->sn             = $_POST['sn'];
694       $this->givenName      = $_POST['givenName'];
696       /* Check for requred values */
697       $message= array();
698       if ($this->sn == "") {
699         $message[]= _("The required field 'Name' is not set.");
700       }
701       if ($this->givenName == "") {
702         $message[]= _("The required field 'Given name' is not set.");
703       }
705       /* Check if dn is used */
706       $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
707       $ldap= $this->config->get_ldap_link();
708       $ldap->cd ($dn);
709       $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
710       if ($ldap->count () != 0){
711         $message[]= _("A person with the choosen name is already used in this tree.");
712       }
714       /* Show error message / continue editing */
715       if (count($message) > 0){
716         show_errors ($message);
717       } else {
718         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
719         if (isset($this->config->current['IDGEN']) &&
720             $this->config->current['IDGEN'] != ""){
721           $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
722           if (count($uids)){
723             $smarty->assign("edit_uid", "false");
724             $smarty->assign("uids", $uids);
725             $this->uid= current($uids);
726           }
727         } else {
728           $smarty->assign("edit_uid", "");
729           $this->uid= "";
730         }
731         $this->got_uid= true;
732       }
734       foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
735         $smarty->assign("$attr", $this->$attr);
736       }
737       if (isset($_POST['template'])){
738         $smarty->assign("template", $_POST['template']);
739       }
740       return($smarty->fetch(get_template_path('template.tpl', TRUE)));
741     }
743     /********************
744       No template selected continue edit
745      ********************/
747     /* No template. Ok. Lets fill data into the normal user dialog */
748     if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
749       foreach(array("sn", "givenName", "uid") as $attr){
750         if (isset($_POST[$attr])){
751           $this->usertab->by_object['user']->$attr= $_POST[$attr];
752         }
753       }
754     }
757     /********************
758       Template selected continue edit
759      ********************/
761     /* Finish template preamble */
762     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
764       /* Might not be filled if IDGEN is unset */
765       $this->sn                 = $_POST['sn'];
766       $this->givenName          = $_POST['givenName'];
768       /* Move user supplied data to sub plugins */
769       $this->uid                = $_POST['uid'];
770       $this->usertab->uid       = $this->uid;
771       $this->usertab->sn        = $this->sn;
772       $this->usertab->givenName = $this->givenName;
773       $template_dn              = $_POST['template'];
774       $this->usertab->adapt_from_template($template_dn);
775       $template_base            = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
776       $this->usertab->by_object['user']->base= $template_base;
777     }
778    
779  
780     /********************
781       If no template was selected set base
782      ********************/
784     if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
785       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
786     }
789     /********************
790       Display subdialog 
791      ********************/
793     /* Show tab dialog if object is present */
794     if(isset($this->usertab->config)){
795       $display= $this->usertab->execute();
797       /* Don't show buttons if tab dialog requests this */
798       if(isset($this->usertab->by_object)){
799         if (!$this->usertab->by_object[$this->usertab->current]->dialog){
800           $display.= "<p style=\"text-align:right\">\n";
801           $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
802           $display.= "&nbsp;\n";
803           if ($this->dn != "new"){
804             $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
805             $display.= "&nbsp;\n";
806           }
807           $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
808           $display.= "</p>";
809         }
810       }
811       return ($display);
812     }
813     
814     /* Check if there is a snapshot dialog open */
815     $base = $this->DivListUsers->selectedBase;
816     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
817       return($str);
818     }
819   
820     /* Return rendered main page */
821         /* Display dialog with system list */
822     $this->DivListUsers->parent = $this;
823     $this->DivListUsers->execute();
825     /* Add departments if subsearch is disabled */
826     if(!$this->DivListUsers->SubSearch){
827       $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4,1);
828     }
829     $this->reload();
830     $this->DivListUsers->setEntries($this->list);
831     return($this->DivListUsers->Draw());
832   }
835   /* Return departments, that will be included within snapshot detection */
836   function get_used_snapshot_bases()
837   {
838     return(array(get_people_ou().$this->DivListUsers->selectedBase));
839   }  
842   function reload()
843   {
844     /* Set base for all searches */
845     $base= $this->DivListUsers->selectedBase;
846     $this->list =array();
848     /* Get filter configuration */
849     $Regex                = $this->DivListUsers->Regex;
850     $SubSearch            = $this->DivListUsers->SubSearch;
851     $ShowTemplates        = $this->DivListUsers->ShowTemplates;
852     $ShowFunctionalUsers  = $this->DivListUsers->ShowFunctionalUsers;
853     $ShowUnixUsers        = $this->DivListUsers->ShowUnixUsers;
854     $ShowMailUsers        = $this->DivListUsers->ShowMailUsers;
855     $ShowSambaUsers       = $this->DivListUsers->ShowSambaUsers;
856     $ShowProxyUsers       = $this->DivListUsers->ShowProxyUsers;
858     /* Setup filter depending on selection */
859     $filter="";
860     if ($this->config->current['SAMBAVERSION'] == 3){
861       $samba= "sambaSamAccount";
862     } else {
863       $samba= "sambaAccount";
864     }
866     if ($ShowFunctionalUsers){
867       $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
868                 "(objectClass=gosaMailAccount)(objectClass=$samba)".
869                 "(objectClass=gosaProxyAccount))))";
870     }
871     if ($ShowUnixUsers){
872       $filter.= "(objectClass=posixAccount)";
873     }
874     if ($ShowMailUsers){
875       $filter.= "(objectClass=gosaMailAccount)";
876     }
877     if ($ShowSambaUsers){
878       $filter.= "(objectClass=$samba)";
879     }
880     if ($ShowProxyUsers){
881       $filter.= "(objectClass=gosaProxyAccount)";
882     }
883     if ($ShowTemplates){
884       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
885     } else {
886       $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
887     }
888     $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
890     /* Generate userlist */
891     $ldap= $this->config->get_ldap_link(TRUE);
893     if ($SubSearch){
894       $ListTemp =  get_list($filter, "users", $base,
895                             array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SUBSEARCH | GL_SIZELIMIT);
896     } else {
897       $base= get_people_ou().$base;
898       $ListTemp = get_list($filter, "users", $base, 
899                             array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SIZELIMIT);
900     }
901     $SortTemp = array();
902     $List = array();
903     foreach($ListTemp as $Key => $Entry){
905       /* Skip entries that are not located under the people ou (normaly 'ou=people,')
906        * Else winstations will be listed too, if you use the subtree flag. 
907        */
908       if(!preg_match("/".normalizePreg(get_people_ou())."/i",$Entry['dn'])){
909         continue;
910       }else{
912         // Generate caption for rows
913         if (isset($Entry["sn"]) && isset($Entry["givenName"])){
914           $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
915         } else {
916           $display= "[".$Entry["uid"][0]."]";
917         }
919         $display = strtolower($display);
920         $List[$display] = $Entry;
921         $SortTemp[$display] = $display;
922       }
923     }
924     sort($SortTemp);
925     reset($SortTemp);
927     $this->list = array();
928     foreach($SortTemp as $Key){
929       $this->list[] = $List[$Key];
930     }
931   }
933   function remove_lock()
934   {
935     /* Remove user lock if a DN is marked as "currently edited" */
936     if (isset($this->usertab->dn)){
937       del_lock ($this->usertab->dn);
938     }
939   }
942   function copyPasteHandling_from_queue($s_action,$s_entry)
943   {
944     /* Check if Copy & Paste is disabled */
945     if(!is_object($this->CopyPasteHandler)){
946       return("");
947     }
949     /* Add a single entry to queue */
950     if($s_action == "cut" || $s_action == "copy"){
951       /* Cleanup object queue */
952       $this->CopyPasteHandler->cleanup_queue();
953       $dn = $this->list[$s_entry]['dn'];
954       $this->CopyPasteHandler->add_to_queue($dn,$s_action,"usertabs","USERTABS","users");
955     }
957     /* Add entries to queue */
958     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
960       /* Cleanup object queue */
961       $this->CopyPasteHandler->cleanup_queue();
963       /* Add new entries to CP queue */
964       foreach($this->list_get_selected_items() as $id){
965         $dn = $this->list[$id]['dn'];
967         if($s_action == "copy_multiple"){
968           $this->CopyPasteHandler->add_to_queue($dn,"copy","usertabs","USERTABS","users");
969         }
970         if($s_action == "cut_multiple"){
971           $this->CopyPasteHandler->add_to_queue($dn,"cut","usertabs","USERTABS","users");
972         }
973       }
974     }
975     
976     /* Start pasting entries */
977     if($s_action == "editPaste"){
978       $this->start_pasting_copied_objects = TRUE;
979     }
981     /* Return C&P dialog */ 
982     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
983    
984       /* Load entry from queue and set base */
985       $this->CopyPasteHandler->load_entry_from_queue();
986       $this->CopyPasteHandler->SetVar("base",$this->DivListUsers->selectedBase); 
988       /* Get dialog */
989       $data = $this->CopyPasteHandler->execute();
991       /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
992       if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
993         $s_entry = $this->CopyPasteHandler->last_entry();
994         $this->reload();
995         foreach($this->list as $key => $entry){
996           if($entry['dn'] == $s_entry){
997             $this->CPPasswordChange = $key;
998           }
999         }
1000       }
1002       /* Return dialog data */
1003       if(!empty($data) && $this->CPPasswordChange == ""){
1004         return($data);
1005       }
1006     }
1008     /* Automatically disable status for pasting */ 
1009     if(!$this->CopyPasteHandler->entries_queued()){
1010       $this->start_pasting_copied_objects = FALSE;
1011     }
1012     return("");
1013   }
1016   function save_object()
1017   {
1018     /* Handle divlist filter && department selection*/
1019     if(!is_object($this->usertab)){
1020       $this->DivListUsers->save_object();
1021     }
1022   }
1024     
1025   function list_get_selected_items()
1026   {
1027     $ids = array();
1028     foreach($_POST as $name => $value){
1029       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1030         $id   = preg_replace("/^item_selected_/","",$name);
1031         $ids[$id] = $id;
1032       }
1033     }
1034     return($ids);
1035   }
1036   
1038   /* A set of disabled and therefore overloaded functions. They are
1039      not needed in this class. */
1040   function remove_from_parent() { } 
1041   function check() { } 
1042   function save() { } 
1043   function adapt_from_template($dn) { } 
1044   function password_change_needed() { } 
1046 } /* ... class userManagement */
1047 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1048 ?>