Code

Added lock/unlock button to user management list
[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 $start_pasting_copied_objects = FALSE;
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                     "copy"      => "^copy",
91                     "toggle_lock_status" => "toggle_lock_status",
92                     "cut"       => "^cut") as $act => $name){
94         if (preg_match("/".$name.".*/", $key)){
95           $s_action= $act;
96           $s_entry= preg_replace("/".$name."_/i", "", $key);
97           break;
98         }
99       }
100       
101     } /* ...Test POST */
103     /* Remove coordinate prefix from POST, required by some browsers */
104     $s_entry= preg_replace("/_.$/", "", $s_entry);
106     /* Seperate possibly encoded tab and entry, default to tab "user" */
107     if(preg_match("/.*-.*/", $s_entry)){
108       $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
109       $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
110     }else{
111       $s_tab= "user";
112     }
114     if(!search_config($this->config->data['TABS'], $s_tab , "CLASS")){
115       $s_tab = "user";
116     }
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 requested  
134      ********************/
136     /* Password change requested */
137     if (($s_action == "change_pw") || (!empty($this->CPPasswordChange))){
139       if(!empty($this->CPPasswordChange)){
140         $s_entry = $this->CPPasswordChange;
141         $this->CPPasswordChange = "";
142       }
144       /* Get 'dn' from posted 'uid' */
145       $this->dn= $this->list[trim($s_entry)]['dn'];
147       /* Load permissions for selected 'dn' and check if
148          we're allowed to remove this 'dn' */
149       if (preg_match("/w/",$this->ui->get_permissions($this->dn,"users/password"))){
151         /* User is allowed to change passwords, save 'dn' and 'acl' for next
152            dialog. */
153         $_SESSION['objectinfo']= $this->dn;
154         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
156       } else {
157         /* User is not allowed. Show message and cancel. */
158         print_red (_("You are not allowed to set this users password!"));
159       }
160     }
163     /********************
164       Change password confirmed
165      ********************/
167     /* Perform password change */
168     if (isset($_POST['password_finish'])){
170       /* For security reasons, check if user is allowed to set password again */
171       $dn  = $this->dn;
172       $acl = $this->ui->get_permissions($dn, "users/password");
173       $cacl= $this->ui->get_permissions($dn, "users/user");
175       if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
177         /* Check input and feed errors into 'message' */
178         $message= array();
180         /* Sanity checks... */
181         if ($_POST['new_password'] != $_POST['repeated_password']){
183           /* Matching passwords in new and repeated? */
184           $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
185         } else {
187           /* Empty password is not permitted by default. */
188           if ($_POST['new_password'] == ""){
189             $message[]= _("The password you've entered as 'New password' is empty.");
190           }
191         }
193         /* Errors, or password change? */
194         if (count($message) != 0){
196           /* Show error message and continue editing */
197           show_errors ($message);
198           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
199         }
201         $config= $this->config;
202         $ldap_ui= $this->config->get_ldap_link();
203         if(isset($this->usertab->dn)){
204           $ldap_ui->cat($this->usertab->dn,array("uid"));
205           $user = $ldap_ui->fetch();
206         }else{
207           $ldap_ui->cat($this->dn,array("uid"));
208           $user = $ldap_ui->fetch();
209         }
210         if((is_array($user))&&(isset($user['uid']))){
211           $username= $user['uid'][0];
212         }
214         /* Set password, perform required steps */
215         if ($this->usertab){
216           if ($this->usertab->password_change_needed()){
217             $obj= $this->usertab->by_object['user'];
218             change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
219             if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
220               exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
221             }
222             new log("modify","users/".get_class($this),$this->usertab->dn,array(),"Password has been changed");
223             unset($this->usertab);
224             $this->usertab= NULL;
225           }
226         } else {
227           change_password ($this->dn, $_POST['new_password']);
228           if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
229             exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
230           }
231           new log("modify","users/".get_class($this),$this->dn,array(),"Password has been changed");
232         }
233       } else {
235         /* Missing permissions, show message */
236         print_red (_("You are not allowed to set this users password!"));
237       }
238       /* Clean session, delete lock */
239       del_lock ($this->dn);
240       unset ($this->usertab);
241       $this->usertab= NULL;
242       $this->lognames= array();;
243       $this->sn= "";
244       $this->givenName= "";
245       $this->uid= "";
246       unset ($_SESSION['objectinfo']);
247     }
250     /********************
251       Edit existing entry 
252      ********************/
254     /* User wants to edit data? */
255     if (($s_action=="edit") && (!isset($this->usertab->config))){
257       /* Get 'dn' from posted 'uid', must be unique */
258       $this->dn= $this->list[trim($s_entry)]['dn'];
260       /* Check locking, save current plugin in 'back_plugin', so
261          the dialog knows where to return. */
262       if (($user= get_lock($this->dn)) != ""){
263         return(gen_locked_message ($user, $this->dn));
264       }
266       /* Lock the current entry, so everyone will get the
267          above dialog */
268       add_lock ($this->dn, $this->ui->dn);
270       /* Register usertab to trigger edit dialog */
271       $this->usertab= new usertabs($this->config, 
272           $this->config->data['TABS']['USERTABS'], $this->dn);
274       /* Switch tab, if it was requested by the user */
275       $this->usertab->current = $s_tab;
277       /* Set ACL and move DN to the headline */
278       $this->usertab->set_acl_base($this->dn);
279       $_SESSION['objectinfo']= $this->dn;
280     }
283     /********************
284       Edit canceled 
285      ********************/
287     /* Reset all relevant data, if we get a _cancel request */
288     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
289       if (isset($this->usertab)){
290         del_lock ($this->usertab->dn);
291         unset ($this->usertab);
292       }
293       $this->usertab= NULL;
294       $this->lognames= array();;
295       $this->sn= "";
296       $this->givenName= "";
297       $this->uid= "";
298       unset ($_SESSION['objectinfo']);
299     }
302     /********************
303       Delete MULTIPLE entries requested, display confirm dialog
304      ********************/
306     if ($s_action=="del_multiple"){
307       $ids = $this->list_get_selected_items();
309       if(count($ids)){
311         foreach($ids as $id){
312           $dn = $this->list[$id]['dn'];
313           if (($user= get_lock($dn)) != ""){
314             return(gen_locked_message ($user, $dn));
315           }
316           $this->dns[$id] = $dn; 
317         }
319         $dns_names = "<br><pre>";
320         foreach($this->dns as $dn){
321           add_lock ($dn, $this->ui->dn);
322           $dns_names .= $dn."\n";
323         }
324         $dns_names .="</pre>";
326         /* Lock the current entry, so nobody will edit it during deletion */
327         if (count($this->dns) == 1){
328           $smarty->assign("info",     sprintf(_("You're about to delete the following entry: %s"), @LDAP::fix($dns_names)));
329         } else {
330           $smarty->assign("info",     sprintf(_("You're about to delete the following entries: %s"), @LDAP::fix($dns_names)));
331         }
332         $smarty->assign("multiple", true);
333         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
334       }
335     }
338     /********************
339       Delete MULTIPLE entries confirmed 
340      ********************/
342       /* Confirmation for deletion has been passed. Users should be deleted. */
343       if (isset($_POST['delete_multiple_user_confirm'])){
345         /* Remove user by user and check acls before removeing them */
346         foreach($this->dns as $key => $dn){
348           $acl = $this->ui->get_permissions($dn, "users/user"); 
349           if (preg_match('/d/', $acl)){
351             /* Delete request is permitted, perform LDAP action */
352             $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn);
353             $this->usertab->set_acl_base();
354             $this->usertab->delete ();
355             unset ($this->usertab);
356             $this->usertab= NULL;
357           } else {
358             print_red (sprintf(_("You are not allowed to delete the user '%s'!"),$dn));
359             if(isset($this->ui->uid)){
360               new log("security","users/".get_class($this),$dn,array(),"Tried to trick deletion.");
361             }
362           }
363           /* Remove lock file after successfull deletion */
364           del_lock ($dn);
365           unset($this->dns[$key]);
366       }
367     }
370     /********************
371       Delete MULTIPLE entries Canceled 
372      ********************/
374     /* Remove lock */
375     if(isset($_POST['delete_multiple_user_cancel'])){
376       foreach($this->dns as $key => $dn){
377         del_lock ($dn);
378         unset($this->dns[$key]);
379       }
380     }
381   
382   
383     /********************
384       Toggle lock status for user
385      ********************/
386   
387     if($s_action == "toggle_lock_status" && isset($this->list[$s_entry])){
389       /* Get entry check current status */
390       $val = $this->list[$s_entry];
391       $pwd = $val['userPassword'][0];
393       if(!preg_match("/^\{[^\}]/",$pwd)){
394         trigger_error("Can not deactivate user which is using clear password encryption.");
395       }else{
397         $locked = false;
398         if(preg_match("/^[^\}]*+\}!/",$pwd)){
399           $locked = true;
400         }
402         /* Create ldap array to update status */
403         $attrs = array("userPassword" => $pwd);
404         if($locked){
405           $attrs['userPassword'] = preg_replace("/(^[^\}]+\})!(.*$)/","\\1\\2",$attrs['userPassword']);
406         }else{
407           $attrs['userPassword'] = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$attrs['userPassword']);
408         }
410         /* Write new status back to ldap */
411         $ldap = $this->config->get_ldap_link();
412         $ldap->cd($val['dn']);
413         $ldap->modify($attrs);
414         if($locked){
415           show_ldap_error($ldap->get_error(),_("Could not set user status from locked to unlocked."));
416         }else{
417           show_ldap_error($ldap->get_error(),_("Could not set user status from unlocked to locked."));
418         }
419       }
420     }
423     /********************
424       Delete entry requested, display confirm dialog
425      ********************/
427     /* Remove user was requested */
428     if ($s_action=="del"){
430       /* Get 'dn' from posted 'uid' */
431       $this->dn= $this->list[trim($s_entry)]['dn'];
433       /* Load permissions for selected 'dn' and check if
434          we're allowed to remove this 'dn' */
436       /* Check locking, save current plugin in 'back_plugin', so
437          the dialog knows where to return. */
438       if (($user= get_lock($this->dn)) != ""){
439         return(gen_locked_message ($user, $this->dn));
440       }
442       /* Lock the current entry, so nobody will edit it during deletion */
443       add_lock ($this->dn, $this->ui->dn);
444       $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
445       $smarty->assign("multiple", false);
446       return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
447     }
450     /********************
451       Delete entry confirmed 
452      ********************/
454     /* Confirmation for deletion has been passed. User should be deleted. */
455     if (isset($_POST['delete_user_confirm'])){
457       /* Some nice guy may send this as POST, so we've to check
458          for the permissions again. */
460       $acl = $this->ui->get_permissions($this->dn, "users/user"); 
461  
462       if (preg_match('/d/', $acl)){
464         /* Delete request is permitted, perform LDAP action */
465         $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
466         $this->usertab->set_acl_base();
467         $this->usertab->delete ();
468         unset ($this->usertab);
469         $this->usertab= NULL;
470       } else {
472         /* Normally this shouldn't be reached, send some extra
473            logs to notify the administrator */
474         print_red (_("You are not allowed to delete this user!"));
476         if(isset($this->ui->uid)){
477           new log("security","users/".get_class($this),$this->dn,array(),"Tried to trick deletion.");
478         }
479       }
481       /* Remove lock file after successfull deletion */
482       del_lock ($this->dn);
483     }
485     
486     /********************
487       Delete entry Canceled 
488      ********************/
490     /* Delete user canceled? */
491     if (isset($_POST['delete_cancel'])){
492       del_lock ($this->dn);
493     }
496     /********************
497       Edit entry finished (Save) 
498      ********************/
500     /* Finish user edit is triggered by the tabulator dialog, so
501        the user wants to save edited data. Check and save at this
502        point. */
503     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
505       /* Check tabs, will feed message array */
506       $this->usertab->last= $this->usertab->current;
507       $this->usertab->save_object();
508       $message= $this->usertab->check();
510       /* Save, or display error message? */
511       if (count($message) == 0){
513         /* No errors. Go ahead and prepare to ask for a password
514            in case we're creating a new user. 'dn' will be 'new'
515            in this case. It is set to the correct value later. */
516         if ($this->dn == "new"){
517           $set_pass= 1;
518         } else {
519           $set_pass= 0;
520         }
522         /* Save user data to ldap */
523         if($this->usertab->save() == 1){
524           return;
525         }
527         if (!isset($_POST['edit_apply'])){
528           /* User has been saved successfully, remove lock from LDAP. */
529           if ($this->dn != "new"){
530             del_lock ($this->dn);
531           }
533           /* In case of new users, ask for a password, skip this for templates */
534           if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
535             $this->dn = $this->usertab->dn;
536             return($smarty->fetch(get_template_path('password.tpl', TRUE)));
537           }
539           unset ($this->usertab);
540           $this->usertab= NULL;
541           unset ($_SESSION['objectinfo']);
542         }
543       } else {
544         /* Ok. There seem to be errors regarding to the tab data,
545            show message and continue as usual. */
546         show_errors($message);
547       }
548     }
551     /********************
552       We want to create a new user, so fetch all available user templates 
553      ********************/
555     /* Generate template list */
556     if (($s_action=="new")||($s_action=="create_user_from_tpl")){
558       $this->templates= array();
559       $ldap= $this->config->get_ldap_link();
561       /* Create list of templates */
562       foreach ($this->config->departments as $key => $value){
563     
564         /* Get acls from different ou's */
565         $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user")       ; 
566  
567         /* If creation of a new user is allowed, append this template */
568         if (preg_match("/c/",$acl)){
569           
570           /* Search all templates from the current dn */
571           $ldap->cd (get_people_ou().$value);
572           $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
574           /* Append */
575           if ($ldap->count() != 0){
576             while ($attrs= $ldap->fetch()){
577               $this->templates[$ldap->getDN()]=
578                 $attrs['uid'][0]." - ".@LDAP::fix($key);
579             }
580             $this->templates['none']= _("none");
581           }
582         }
583       }
585       /* Sort templates */
586       natcasesort ($this->templates);
587       reset ($this->templates);
588     }
591     /********************
592       Create a new user,template, user from template 
593      ********************/
595     /* Check selected options for template */
596     if (isset($_POST['template_continue'])){
597       $message = array();
598       if(!isset($_POST['template']) || (empty($_POST['template']))){
599         $message[] = _("Please select a valid template.");
600       }
601       if(!isset($_POST['sn']) || (empty($_POST['sn']))){
602         $message[]= _("The required field 'Name' is not set.");
603       }
604       if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
605         $message[]= _("The required field 'Given name' is not set.");
606       }
607     
608       /* Show error message / continue editing */
609       if (count($message) > 0){
610         show_errors ($message);
612         foreach(array("sn", "givenName", "uid", "template") as $attr){
613           if(isset($_POST[$attr])){
614             $smarty->assign("$attr", $_POST[$attr]);
615           }else{
616             $smarty->assign("$attr", "");
617           }
618         }
619         $smarty->assign("templates",$this->templates);
620         $smarty->assign("got_uid",$this->got_uid);
621         $smarty->assign("edit_uid",false);
622         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
624       }
625     }
627     /* New user/template request */
628     if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
629       /* By default we set 'dn' to 'new', all relevant plugins will
630          react on this. */
631       $this->dn= "new";
632       
633       if (isset($this->config->current['IDGEN'])){
634         $this->got_uid= false;
635       } else {
636         $this->got_uid= true;
637       }
639       /* Create new usertab object */
640       $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
641       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
642       $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
644       /* Take care about templates */
645       if ($s_action=="new_tpl"){
646         $this->is_template= TRUE;
647         $this->usertab->set_template_mode ();
648       } else {
649         $this->is_template= FALSE;
650       }
652       /* Use template if there are any of them */
653       if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
654         foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
655           $smarty->assign("$attr", $this->$attr);
656         }
657         if ($s_action=="create_user_from_tpl"){
658           $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
659         } else {
660           $smarty->assign("template", "none");
661         }
662         $smarty->assign("edit_uid", "");
663         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
664       }
665     }
667     /********************
668       Template selected continue edit
669      ********************/
671     /* Continue template editing */
672     if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
674       $this->sn             = $_POST['sn'];
675       $this->givenName      = $_POST['givenName'];
677       /* Check for requred values */
678       $message= array();
679       if ($this->sn == "") {
680         $message[]= _("The required field 'Name' is not set.");
681       }
682       if ($this->givenName == "") {
683         $message[]= _("The required field 'Given name' is not set.");
684       }
686       /* Check if dn is used */
687       $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
688       $ldap= $this->config->get_ldap_link();
689       $ldap->cd ($dn);
690       $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
691       if ($ldap->count () != 0){
692         $message[]= _("A person with the choosen name is already used in this tree.");
693       }
695       /* Show error message / continue editing */
696       if (count($message) > 0){
697         show_errors ($message);
698       } else {
699         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
700         if (isset($this->config->current['IDGEN']) &&
701             $this->config->current['IDGEN'] != ""){
702           $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
703           if (count($uids)){
704             $smarty->assign("edit_uid", "false");
705             $smarty->assign("uids", $uids);
706             $this->uid= current($uids);
707           }
708         } else {
709           $smarty->assign("edit_uid", "");
710           $this->uid= "";
711         }
712         $this->got_uid= true;
713       }
715       foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
716         $smarty->assign("$attr", $this->$attr);
717       }
718       if (isset($_POST['template'])){
719         $smarty->assign("template", $_POST['template']);
720       }
721       return($smarty->fetch(get_template_path('template.tpl', TRUE)));
722     }
724     /********************
725       No template selected continue edit
726      ********************/
728     /* No template. Ok. Lets fill data into the normal user dialog */
729     if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
730       foreach(array("sn", "givenName", "uid") as $attr){
731         if (isset($_POST[$attr])){
732           $this->usertab->by_object['user']->$attr= $_POST[$attr];
733         }
734       }
735     }
738     /********************
739       Template selected continue edit
740      ********************/
742     /* Finish template preamble */
743     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
745       /* Might not be filled if IDGEN is unset */
746       $this->sn                 = $_POST['sn'];
747       $this->givenName          = $_POST['givenName'];
749       /* Move user supplied data to sub plugins */
750       $this->uid                = $_POST['uid'];
751       $this->usertab->uid       = $this->uid;
752       $this->usertab->sn        = $this->sn;
753       $this->usertab->givenName = $this->givenName;
754       $template_dn              = $_POST['template'];
755       $this->usertab->adapt_from_template($template_dn);
756       $template_base            = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
757       $this->usertab->by_object['user']->base= $template_base;
758     }
759    
760  
761     /********************
762       If no template was selected set base
763      ********************/
765     if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
766       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
767     }
770     /********************
771       Display subdialog 
772      ********************/
774     /* Show tab dialog if object is present */
775     if(isset($this->usertab->config)){
776       $display= $this->usertab->execute();
778       /* Don't show buttons if tab dialog requests this */
779       if(isset($this->usertab->by_object)){
780         if (!$this->usertab->by_object[$this->usertab->current]->dialog){
781           $display.= "<p style=\"text-align:right\">\n";
782           $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
783           $display.= "&nbsp;\n";
784           if ($this->dn != "new"){
785             $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
786             $display.= "&nbsp;\n";
787           }
788           $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
789           $display.= "</p>";
790         }
791       }
792       return ($display);
793     }
794     
795     /* Check if there is a snapshot dialog open */
796     $base = $this->DivListUsers->selectedBase;
797     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
798       return($str);
799     }
800   
801     /* Return rendered main page */
802         /* Display dialog with system list */
803     $this->DivListUsers->parent = $this;
804     $this->DivListUsers->execute();
806     /* Add departments if subsearch is disabled */
807     if(!$this->DivListUsers->SubSearch){
808       $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4,1);
809     }
810     $this->reload();
811     $this->DivListUsers->setEntries($this->list);
812     return($this->DivListUsers->Draw());
813   }
816   /* Return departments, that will be included within snapshot detection */
817   function get_used_snapshot_bases()
818   {
819     return(array(get_people_ou().$this->DivListUsers->selectedBase));
820   }  
823   function reload()
824   {
825     /* Set base for all searches */
826     $base= $this->DivListUsers->selectedBase;
827     $this->list =array();
829     /* Get filter configuration */
830     $Regex                = $this->DivListUsers->Regex;
831     $SubSearch            = $this->DivListUsers->SubSearch;
832     $ShowTemplates        = $this->DivListUsers->ShowTemplates;
833     $ShowFunctionalUsers  = $this->DivListUsers->ShowFunctionalUsers;
834     $ShowUnixUsers        = $this->DivListUsers->ShowUnixUsers;
835     $ShowMailUsers        = $this->DivListUsers->ShowMailUsers;
836     $ShowSambaUsers       = $this->DivListUsers->ShowSambaUsers;
837     $ShowProxyUsers       = $this->DivListUsers->ShowProxyUsers;
839     /* Setup filter depending on selection */
840     $filter="";
841     if ($this->config->current['SAMBAVERSION'] == 3){
842       $samba= "sambaSamAccount";
843     } else {
844       $samba= "sambaAccount";
845     }
847     if ($ShowFunctionalUsers){
848       $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
849                 "(objectClass=gosaMailAccount)(objectClass=$samba)".
850                 "(objectClass=gosaProxyAccount))))";
851     }
852     if ($ShowUnixUsers){
853       $filter.= "(objectClass=posixAccount)";
854     }
855     if ($ShowMailUsers){
856       $filter.= "(objectClass=gosaMailAccount)";
857     }
858     if ($ShowSambaUsers){
859       $filter.= "(objectClass=$samba)";
860     }
861     if ($ShowProxyUsers){
862       $filter.= "(objectClass=gosaProxyAccount)";
863     }
864     if ($ShowTemplates){
865       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
866     } else {
867       $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
868     }
869     $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
871     /* Generate userlist */
872     $ldap= $this->config->get_ldap_link(TRUE);
874     if ($SubSearch){
875       $ListTemp =  get_list($filter, "users", $base,
876                             array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SUBSEARCH | GL_SIZELIMIT);
877     } else {
878       $base= get_people_ou().$base;
879       $ListTemp = get_list($filter, "users", $base, 
880                             array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SIZELIMIT);
881     }
882     $SortTemp = array();
883     $List = array();
884     foreach($ListTemp as $Key => $Entry){
886       /* Skip entries that are not located under the people ou (normaly 'ou=people,')
887        * Else winstations will be listed too, if you use the subtree flag. 
888        */
889       if(!preg_match("/".normalizePreg(get_people_ou())."/i",$Entry['dn'])){
890         continue;
891       }else{
893         // Generate caption for rows
894         if (isset($Entry["sn"]) && isset($Entry["givenName"])){
895           $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
896         } else {
897           $display= "[".$Entry["uid"][0]."]";
898         }
900         $display = strtolower($display);
901         $List[$display] = $Entry;
902         $SortTemp[$display] = $display;
903       }
904     }
905     sort($SortTemp);
906     reset($SortTemp);
908     $this->list = array();
909     foreach($SortTemp as $Key){
910       $this->list[] = $List[$Key];
911     }
912   }
914   function remove_lock()
915   {
916     /* Remove user lock if a DN is marked as "currently edited" */
917     if (isset($this->usertab->dn)){
918       del_lock ($this->usertab->dn);
919     }
920   }
923   function copyPasteHandling_from_queue($s_action,$s_entry)
924   {
925     /* Check if Copy & Paste is disabled */
926     if(!is_object($this->CopyPasteHandler)){
927       return("");
928     }
930     /* Add a single entry to queue */
931     if($s_action == "cut" || $s_action == "copy"){
932       /* Cleanup object queue */
933       $this->CopyPasteHandler->cleanup_queue();
934       $dn = $this->list[$s_entry]['dn'];
935       $this->CopyPasteHandler->add_to_queue($dn,$s_action,"usertabs","USERTABS","users");
936     }
938     /* Add entries to queue */
939     if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
941       /* Cleanup object queue */
942       $this->CopyPasteHandler->cleanup_queue();
944       /* Add new entries to CP queue */
945       foreach($this->list_get_selected_items() as $id){
946         $dn = $this->list[$id]['dn'];
948         if($s_action == "copy_multiple"){
949           $this->CopyPasteHandler->add_to_queue($dn,"copy","usertabs","USERTABS","users");
950         }
951         if($s_action == "cut_multiple"){
952           $this->CopyPasteHandler->add_to_queue($dn,"cut","usertabs","USERTABS","users");
953         }
954       }
955     }
956     
957     /* Start pasting entries */
958     if($s_action == "editPaste"){
959       $this->start_pasting_copied_objects = TRUE;
960     }
962     /* Return C&P dialog */ 
963     if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
964    
965       /* Load entry from queue and set base */
966       $this->CopyPasteHandler->load_entry_from_queue();
967       $this->CopyPasteHandler->SetVar("base",$this->DivListUsers->selectedBase); 
969       /* Get dialog */
970       $data = $this->CopyPasteHandler->execute();
972       /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
973       if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
974         $s_entry = $this->CopyPasteHandler->last_entry();
975         $this->reload();
976         foreach($this->list as $key => $entry){
977           if($entry['dn'] == $s_entry){
978             $this->CPPasswordChange = $key;
979           }
980         }
981       }
983       /* Return dialog data */
984       if(!empty($data) && $this->CPPasswordChange == ""){
985         return($data);
986       }
987     }
989     /* Automatically disable status for pasting */ 
990     if(!$this->CopyPasteHandler->entries_queued()){
991       $this->start_pasting_copied_objects = FALSE;
992     }
993     return("");
994   }
997   function save_object()
998   {
999     /* Handle divlist filter && department selection*/
1000     if(!is_object($this->usertab)){
1001       $this->DivListUsers->save_object();
1002     }
1003   }
1005     
1006   function list_get_selected_items()
1007   {
1008     $ids = array();
1009     foreach($_POST as $name => $value){
1010       if(preg_match("/^item_selected_[0-9]*$/",$name)){
1011         $id   = preg_replace("/^item_selected_/","",$name);
1012         $ids[$id] = $id;
1013       }
1014     }
1015     return($ids);
1016   }
1017   
1019   /* A set of disabled and therefore overloaded functions. They are
1020      not needed in this class. */
1021   function remove_from_parent() { } 
1022   function check() { } 
1023   function save() { } 
1024   function adapt_from_template($dn) { } 
1025   function password_change_needed() { } 
1027 } /* ... class userManagement */
1028 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1029 ?>