Code

Fixed search_config stuff in user tabs
[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 class userManagement extends plugin
22 {
23   /* Plugin definitions */
24   var $plHeadline= "Users";
25   var $plDescription= "This does something";
27   /* Dialog attributes */
28   var $usertab              = NULL;
29   var $ui                   = NULL;
30   var $templates            = array();
31   var $got_uid              = false;
32   var $CopyPasteHandler     = NULL;
33   var $CPPasswordChange     = ""; // Contains the entry id which should get a new password
34   var $DivListUsers;
36   var $pwd_change_queue     = array();
38   var $start_pasting_copied_objects = FALSE;
40   var $msg_dialog= NULL;
41   
42   function userManagement(&$config, $ui)
43   {
44     /* Save configuration for internal use */
45     $this->config= &$config;
46     $this->ui= &$ui;
48     /* Copy & Paste handler */
49     if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
50       $this->CopyPasteHandler= new CopyPasteHandler($this->config);
51     }
53     /* Creat dialog object */
54     $this->DivListUsers = new divListUsers($this->config,$this);
56   }
59   function execute()
60   {
61     /* Call parent execute */
62     plugin::execute();
64     /* LOCK MESSAGE Vars */
65     $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/","/^item_selected/","/^remove_multiple_users/");
67     $smarty       = get_smarty();                 // Smarty instance
68     $s_action     = "";                           // Contains the action to be taken
69     $s_entry      = "";                           // The value for s_action
71     /* Edit entry button pressed? */
72     if( isset($_GET['act']) && $_GET['act'] == "edit_entry" ){
73       $s_action= "edit";
74       $s_entry= validate($_GET['id']);
75     }
77     /* Test relevant POST values */  
78     foreach($_POST as $key => $val){
80       /* Get every possible POST combination and set s_action/s_entry accordingly */
81       foreach(array("del"       => "user_del",    "edit"      => "user_edit",
82                     "new"       => "user_new",
83                     "new_tpl"   => "user_tplnew",
84                     "del_multiple" => "^remove_multiple_users",
85                     "create_user_from_tpl"          => "userfrom_tpl",
86                     "change_pw" => "user_chgpw", 
87                     "editPaste" => "editPaste",  
88                     "copy_multiple" => "multiple_copy_users",
89                     "cut_multiple" => "multiple_cut_users",
90                     "multiple_password_change" => "multiple_password_change",
91                     "copy"      => "^copy",
92                     "toggle_lock_status" => "toggle_lock_status",
93                     "cut"       => "^cut") as $act => $name){
95         if (preg_match("/".$name.".*/", $key)){
96           $s_action= $act;
97           $s_entry= preg_replace("/".$name."_/i", "", $key);
98           break;
99         }
100       }
101       
102     } /* ...Test POST */
104     /* Remove coordinate prefix from POST, required by some browsers */
105     $s_entry= preg_replace("/_.$/", "", $s_entry);
107     /* Seperate possibly encoded tab and entry, default to tab "user" */
108     if(preg_match("/.*-.*/", $s_entry)){
109       $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
110       $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
111     }else{
112       $s_tab= "user";
113     }
115     if(!$this->config->search($s_tab, 'class',array('tabs'))){
116       $s_tab = "user";
117     }
119     /********************
120       Copy & Paste 
121      ********************/
123     /* Display the copy & paste dialog, if it is currently open */
124     if($this->CPPasswordChange == ""){
125       $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
126       if($ret){
127         return($ret);
128       }
129     }
132     /********************
133       Change password confirmed
134      ********************/
136     /* Perform password change */
137     if (isset($_POST['password_finish'])){
139       /* For security reasons, check if user is allowed to set password again */
140       $dn  = $this->dn;
141       $acl = $this->ui->get_permissions($dn, "users/password");
142       $cacl= $this->ui->get_permissions($dn, "users/user");
144       if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
146         /* Check input and feed errors into 'message' */
147         $message= array();
149         /* Sanity checks... */
150         if ($_POST['new_password'] != $_POST['repeated_password']){
152           /* Matching passwords in new and repeated? */
153           $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
154         } else {
156           /* Empty password is not permitted by default. */
157           if ($_POST['new_password'] == ""){
158             $message[]= _("The password you've entered as 'New password' is empty.");
159           }
160         }
162         /* Errors, or password change? */
163         if (count($message) != 0){
165           /* Show error message and continue editing */
166           show_errors ($message);
167           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
168         }
170         $config= $this->config;
171         $ldap_ui= $this->config->get_ldap_link();
172         if(isset($this->usertab->dn)){
173           $ldap_ui->cat($this->usertab->dn,array("uid"));
174           $user = $ldap_ui->fetch();
175         }else{
176           $ldap_ui->cat($this->dn,array("uid"));
177           $user = $ldap_ui->fetch();
178         }
179         if((is_array($user))&&(isset($user['uid']))){
180           $username= $user['uid'][0];
181         }
183         /* Set password, perform required steps */
184         if ($this->usertab){
185           if ($this->usertab->password_change_needed()){
186             $obj= $this->usertab->by_object['user'];
187             change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
188             if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
189               exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
190             }
191             new log("modify","users/".get_class($this),$this->usertab->dn,array(),"Password has been changed");
192             unset($this->usertab);
193             $this->usertab= NULL;
194           }
195         } else {
196           change_password ($this->dn, $_POST['new_password']);
197           if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
198             exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
199           }
200           new log("modify","users/".get_class($this),$this->dn,array(),"Password has been changed");
201         }
202       } else {
204         /* Missing permissions, show message */
205         print_red (_("You are not allowed to set this users password!"));
206       }
207       /* Clean session, delete lock */
208       del_lock ($this->dn);
209       unset ($this->usertab);
210       $this->usertab= NULL;
211       $this->lognames= array();;
212       $this->sn= "";
213       $this->givenName= "";
214       $this->uid= "";
215       unset ($_SESSION['objectinfo']);
216     }
219     /********************
220      Change multiple passwords requested 
221      ********************/
222   
223     if($s_action == "multiple_password_change"){
224       $this->pwd_change_queue = $this->list_get_selected_items();
225     }    
228     /********************
229       Change password requested  
230      ********************/
232     /* Password change requested */
233     if (($s_action == "change_pw") || (!empty($this->CPPasswordChange)) || count($this->pwd_change_queue)){
235       /* Get users whose passwords should be changed. */
236       if(count($this->pwd_change_queue)){
237         $s_entry= array_pop($this->pwd_change_queue);
238       }
240       if(!empty($this->CPPasswordChange)){
241         $s_entry = $this->CPPasswordChange;
242         $this->CPPasswordChange = "";
243       }
245       /* Get 'dn' from posted 'uid' */
246       $this->dn= $this->list[trim($s_entry)]['dn'];
248       /* Load permissions for selected 'dn' and check if
249          we're allowed to remove this 'dn' */
250       if (preg_match("/w/",$this->ui->get_permissions($this->dn,"users/password"))){
252         /* User is allowed to change passwords, save 'dn' and 'acl' for next
253            dialog. */
254         $_SESSION['objectinfo']= $this->dn;
255         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
257       } else {
258         /* User is not allowed. Show message and cancel. */
259         print_red (_("You are not allowed to set this users password!"));
260       }
261     }
266     /********************
267       Edit existing entry 
268      ********************/
270     /* User wants to edit data? */
271     if (($s_action=="edit") && (!isset($this->usertab->config))){
273       /* Get 'dn' from posted 'uid', must be unique */
274       $this->dn= $this->list[trim($s_entry)]['dn'];
276       /* Check locking, save current plugin in 'back_plugin', so
277          the dialog knows where to return. */
278       if (($user= get_lock($this->dn)) != ""){
279         return(gen_locked_message ($user, $this->dn));
280       }
282       /* Lock the current entry, so everyone will get the
283          above dialog */
284       add_lock ($this->dn, $this->ui->dn);
286       /* Register usertab to trigger edit dialog */
287       $this->usertab= new usertabs($this->config, 
288           $this->config->data['TABS']['USERTABS'], $this->dn);
290       /* Switch tab, if it was requested by the user */
291       $this->usertab->current = $s_tab;
293       /* Set ACL and move DN to the headline */
294       $this->usertab->set_acl_base($this->dn);
295       $_SESSION['objectinfo']= $this->dn;
296     }
299     /********************
300       Edit canceled 
301      ********************/
303     /* Reset all relevant data, if we get a _cancel request */
304     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
305       if (isset($this->usertab)){
306         del_lock ($this->usertab->dn);
307         unset ($this->usertab);
308       }
309       $this->usertab= NULL;
310       $this->lognames= array();;
311       $this->sn= "";
312       $this->givenName= "";
313       $this->uid= "";
314       unset ($_SESSION['objectinfo']);
315     }
318     /********************
319       Delete MULTIPLE entries requested, display confirm dialog
320      ********************/
322     if ($s_action=="del_multiple"){
323       $ids = $this->list_get_selected_items();
325       if(count($ids)){
327         foreach($ids as $id){
328           $dn = $this->list[$id]['dn'];
329           if (($user= get_lock($dn)) != ""){
330             return(gen_locked_message ($user, $dn));
331           }
332           $this->dns[$id] = $dn; 
333         }
335         $dns_names = "<br><pre>";
336         foreach($this->dns as $dn){
337           add_lock ($dn, $this->ui->dn);
338           $dns_names .= $dn."\n";
339         }
340         $dns_names .="</pre>";
342         /* Lock the current entry, so nobody will edit it during deletion */
343         if (count($this->dns) == 1){
344           $smarty->assign("info",     sprintf(_("You're about to delete the following entry: %s"), @LDAP::fix($dns_names)));
345         } else {
346           $smarty->assign("info",     sprintf(_("You're about to delete the following entries: %s"), @LDAP::fix($dns_names)));
347         }
348         $smarty->assign("multiple", true);
349         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
350       }
351     }
354     /********************
355       Delete MULTIPLE entries confirmed 
356      ********************/
358       /* Confirmation for deletion has been passed. Users should be deleted. */
359       if (isset($_POST['delete_multiple_user_confirm'])){
361         /* Remove user by user and check acls before removeing them */
362         foreach($this->dns as $key => $dn){
364           $acl = $this->ui->get_permissions($dn, "users/user"); 
365           if (preg_match('/d/', $acl)){
367             /* Delete request is permitted, perform LDAP action */
368             $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn);
369             $this->usertab->set_acl_base();
370             $this->usertab->delete ();
371             unset ($this->usertab);
372             $this->usertab= NULL;
373           } else {
374             print_red (sprintf(_("You are not allowed to delete the user '%s'!"),$dn));
375             if(isset($this->ui->uid)){
376               new log("security","users/".get_class($this),$dn,array(),"Tried to trick deletion.");
377             }
378           }
379           /* Remove lock file after successfull deletion */
380           del_lock ($dn);
381           unset($this->dns[$key]);
382       }
383     }
386     /********************
387       Delete MULTIPLE entries Canceled 
388      ********************/
390     /* Remove lock */
391     if(isset($_POST['delete_multiple_user_cancel'])){
392       foreach($this->dns as $key => $dn){
393         del_lock ($dn);
394         unset($this->dns[$key]);
395       }
396     }
397   
398   
399     /********************
400       Toggle lock status for user
401      ********************/
402   
403     if($s_action == "toggle_lock_status" && isset($this->list[$s_entry])){
405       /* Get entry check current status */
406       $val = $this->list[$s_entry];
407       $pwd = $val['userPassword'][0];
409       if(!preg_match("/^\{[^\}]/",$pwd)){
410         trigger_error("Can not deactivate user which is using clear password encryption.");
411       }else{
413         $locked = false;
414         if(preg_match("/^[^\}]*+\}!/",$pwd)){
415           $locked = true;
416         }
418         /* Create ldap array to update status */
419         $attrs = array("userPassword" => $pwd);
420         if($locked){
421           $attrs['userPassword'] = preg_replace("/(^[^\}]+\})!(.*$)/","\\1\\2",$attrs['userPassword']);
422         }else{
423           $attrs['userPassword'] = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$attrs['userPassword']);
424         }
426         /* Write new status back to ldap */
427         $ldap = $this->config->get_ldap_link();
428         $ldap->cd($val['dn']);
429         $ldap->modify($attrs);
430         if($locked){
431           show_ldap_error($ldap->get_error(),_("Could not set user status from locked to unlocked."));
432         }else{
433           show_ldap_error($ldap->get_error(),_("Could not set user status from unlocked to locked."));
434         }
435       }
436     }
439     /********************
440       Delete entry requested, display confirm dialog
441      ********************/
443     /* Remove user was requested */
444     if ($s_action=="del"){
446       /* Get 'dn' from posted 'uid' */
447       $this->dn= $this->list[trim($s_entry)]['dn'];
449       /* Load permissions for selected 'dn' and check if
450          we're allowed to remove this 'dn' */
452       /* Check locking, save current plugin in 'back_plugin', so
453          the dialog knows where to return. */
454       if (($user= get_lock($this->dn)) != ""){
455         return(gen_locked_message ($user, $this->dn));
456       }
458   
459       /* Lock the current entry, so nobody will edit it during deletion */
460 #      add_lock ($this->dn, $this->ui->dn);
461 #      $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
462 #      $smarty->assign("multiple", false);
463 #      return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
464       $this->msg_dialog = new msg_dialog(_("Delete user"),sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)),CONFIRM_DIALOG);
465     }
468     /********************
469       Delete entry confirmed 
470      ********************/
472     /* Confirmation for deletion has been passed. User should be deleted. */
473     if (is_object($this->msg_dialog) && $this->msg_dialog->is_confirmed()){
475       /* Some nice guy may send this as POST, so we've to check
476          for the permissions again. */
478       $acl = $this->ui->get_permissions($this->dn, "users/user"); 
479  
480       if (preg_match('/d/', $acl)){
482         /* Delete request is permitted, perform LDAP action */
483         $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
484         $this->usertab->set_acl_base();
485         $this->usertab->delete ();
486         unset ($this->usertab);
487         $this->usertab= NULL;
488         msg_dialog::display(_("User delted"),_("User successfully removed."),INFO_DIALOG);
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 ?>