Code

Added some logging
[gosa.git] / plugins / admin / users / class_userManagement.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003-2006 - Cajus Pollmeier <pollmeier@gonicus.de>
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 /* Include user tab class */
22 require "tabs_user.inc";
25 class userManagement extends plugin
26 {
27   /* Plugin definitions */
28   var $plHeadline= "Users";
29   var $plDescription= "This does something";
31   /* Dialog attributes */
32   var $usertab              = NULL;
33   var $ui                   = NULL;
34   var $templates            = array();
35   var $got_uid              = false;
36   var $CopyPasteHandler     = NULL;
37   var $CPPasswordChange     = ""; // Contains the entry id which should get a new password
38   var $DivListUsers;
40   function userManagement($config, $ui)
41   {
42     /* Save configuration for internal use */
43     $this->config= $config;
44     $this->ui= $ui;
46     /* Copy & Paste handler */
47     if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
48       $this->CopyPasteHandler= new CopyPasteHandler($this->config);
49     }
51     /* Creat dialog object */
52     $this->DivListUsers = new divListUsers($this->config,$this);
54   }
57   function execute()
58   {
59     /* Call parent execute */
60     plugin::execute();
62     /* LOCK MESSAGE Vars */
63     $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/","/^item_selected/","/^remove_multiple_users/");
65     $smarty       = get_smarty();                 // Smarty instance
66     $s_action     = "";                           // Contains the action to be taken
67     $s_entry      = "";                           // The value for s_action
69     /* Edit entry button pressed? */
70     if( isset($_GET['act']) && $_GET['act'] == "edit_entry" ){
71       $s_action= "edit";
72       $s_entry= validate($_GET['id']);
73     }
75     /* Test relevant POST values */  
76     foreach($_POST as $key => $val){
78       /* Get every possible POST combination and set s_action/s_entry accordingly */
79       foreach(array("del"       => "user_del",    "edit"      => "user_edit",
80                     "new"       => "user_new",
81                     "new_tpl"   => "user_tplnew",
82                     "del_multiple" => "^remove_multiple_users",
83                     "create_user_from_tpl"          => "userfrom_tpl",
84                     "change_pw" => "user_chgpw", 
85                     "editPaste" => "editPaste",   "copy"      => "copy",
86                     "cut"       => "cut") as $act => $name){
88         if (preg_match("/".$name.".*/", $key)){
89           $s_action= $act;
90           $s_entry= preg_replace("/".$name."_/i", "", $key);
91           break;
92         }
93       }
94       
95     } /* ...Test POST */
97     /* Remove coordinate prefix from POST, required by some browsers */
98     $s_entry= preg_replace("/_.$/", "", $s_entry);
100     /* Seperate possibly encoded tab and entry, default to tab "user" */
101     if(preg_match("/.*-.*/", $s_entry)){
102       $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
103       $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
104     }else{
105       $s_tab= "user";
106     }
108     if(!search_config($this->config->data['TABS'], $s_tab , "CLASS")){
109       $s_tab = "user";
110     }
112     /* Display the copy & paste dialog, if it is currently open */
113     $ret = $this->copyPasteHandling($s_action,$s_entry);
114     if($ret){
115       return($ret);
116     }
119     /********************
120       Edit existing entry 
121      ********************/
123     /* User wants to edit data? */
124     if (($s_action=="edit") && (!isset($this->usertab->config))){
126       /* Get 'dn' from posted 'uid', must be unique */
127       $this->dn= $this->list[trim($s_entry)]['dn'];
129       /* Check locking, save current plugin in 'back_plugin', so
130          the dialog knows where to return. */
131       if (($user= get_lock($this->dn)) != ""){
132         return(gen_locked_message ($user, $this->dn));
133       }
135       /* Lock the current entry, so everyone will get the
136          above dialog */
137       add_lock ($this->dn, $this->ui->dn);
139       /* Register usertab to trigger edit dialog */
140       $this->usertab= new usertabs($this->config, 
141           $this->config->data['TABS']['USERTABS'], $this->dn);
143       /* Switch tab, if it was requested by the user */
144       $this->usertab->current = $s_tab;
146       /* Set ACL and move DN to the headline */
147       $this->usertab->set_acl_base($this->dn);
148       $_SESSION['objectinfo']= $this->dn;
149     }
152     /********************
153       Edit canceled 
154      ********************/
156     /* Reset all relevant data, if we get a _cancel request */
157     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
158       if (isset($this->usertab)){
159         del_lock ($this->usertab->dn);
160         unset ($this->usertab);
161       }
162       $this->usertab= NULL;
163       $this->lognames= array();;
164       $this->sn= "";
165       $this->givenName= "";
166       $this->uid= "";
167       unset ($_SESSION['objectinfo']);
168     }
171     /********************
172       Change password requested  
173      ********************/
175     /* Password change requested */
176     if (($s_action == "change_pw") || (!empty($this->CPPasswordChange))){
178       if(!empty($this->CPPasswordChange)){
179         $s_entry = $this->CPPasswordChange;
180         $this->CPPasswordChange = "";
181       }
183       /* Get 'dn' from posted 'uid' */
184       $this->dn= $this->list[trim($s_entry)]['dn'];
186       /* Load permissions for selected 'dn' and check if
187          we're allowed to remove this 'dn' */
188       if (preg_match("/w/",$this->ui->get_permissions($this->dn,"users/password"))){
190         /* User is allowed to change passwords, save 'dn' and 'acl' for next
191            dialog. */
192         $_SESSION['objectinfo']= $this->dn;
193         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
195       } else {
196         /* User is not allowed. Show message and cancel. */
197         print_red (_("You are not allowed to set this users password!"));
198       }
199     }
202     /********************
203       Change password confirmed
204      ********************/
206     /* Perform password change */
207     if (isset($_POST['password_finish'])){
209       /* For security reasons, check if user is allowed to set password again */
210       $dn  = $this->dn;
211       $acl = $this->ui->get_permissions($dn, "users/password");
212       $cacl= $this->ui->get_permissions($dn, "users/user");
214       if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
216         /* Check input and feed errors into 'message' */
217         $message= array();
219         /* Sanity checks... */
220         if ($_POST['new_password'] != $_POST['repeated_password']){
222           /* Matching passwords in new and repeated? */
223           $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
224         } else {
226           /* Empty password is not permitted by default. */
227           if ($_POST['new_password'] == ""){
228             $message[]= _("The password you've entered as 'New password' is empty.");
229           }
230         }
232         /* Errors, or password change? */
233         if (count($message) != 0){
235           /* Show error message and continue editing */
236           show_errors ($message);
237           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
238         }
240         $config= $this->config;
241         $ldap_ui= $this->config->get_ldap_link();
242         if(isset($this->usertab->dn)){
243           $ldap_ui->cat($this->usertab->dn,array("uid"));
244           $user = $ldap_ui->fetch();
245         }else{
246           $ldap_ui->cat($this->dn,array("uid"));
247           $user = $ldap_ui->fetch();
248         }
249         if((is_array($user))&&(isset($user['uid']))){
250           $username= $user['uid'][0];
251         }
253         /* Set password, perform required steps */
254         if ($this->usertab){
255           if ($this->usertab->password_change_needed()){
256             $obj= $this->usertab->by_object['user'];
257             change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
258             if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
259               exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
260             }
262             gosa_log ("Password for '".$this->usertab->dn."' has been changed");
263             unset($this->usertab);
264             $this->usertab= NULL;
265           }
266         } else {
267           change_password ($this->dn, $_POST['new_password']);
268           if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
269             exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
270           }
272           gosa_log ("Password for '".$this->dn."' has been changed");
273         }
274       } else {
276         /* Missing permissions, show message */
277         print_red (_("You are not allowed to set this users password!"));
278       }
279       /* Clean session, delete lock */
280       del_lock ($this->dn);
281       unset ($this->usertab);
282       $this->usertab= NULL;
283       $this->lognames= array();;
284       $this->sn= "";
285       $this->givenName= "";
286       $this->uid= "";
287       unset ($_SESSION['objectinfo']);
288     }
291     /********************
292       Delete MULTIPLE entries requested, display confirm dialog
293      ********************/
295     if ($s_action=="del_multiple"){
296       $ids = $this->list_get_selected_items();
298       if(count($ids)){
300         foreach($ids as $id){
301           $dn = $this->list[$id]['dn'];
302           if (($user= get_lock($dn)) != ""){
303             return(gen_locked_message ($user, $dn));
304           }
305           $this->dns[$id] = $dn; 
306         }
308         $dns_names = "<br><pre>";
309         foreach($this->dns as $dn){
310           add_lock ($dn, $this->ui->dn);
311           $dns_names .= $dn."\n";
312         }
313         $dns_names .="</pre>";
315         /* Lock the current entry, so nobody will edit it during deletion */
316         if (count($this->dns) == 1){
317           $smarty->assign("info",     sprintf(_("You're about to delete the following entry: %s"), @LDAP::fix($dns_names)));
318         } else {
319           $smarty->assign("info",     sprintf(_("You're about to delete the following entries: %s"), @LDAP::fix($dns_names)));
320         }
321         $smarty->assign("multiple", true);
322         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
323       }
324     }
327     /********************
328       Delete MULTIPLE entries confirmed 
329      ********************/
331       /* Confirmation for deletion has been passed. Users should be deleted. */
332       if (isset($_POST['delete_multiple_user_confirm'])){
334         /* Remove user by user and check acls before removeing them */
335         foreach($this->dns as $key => $dn){
337           $acl = $this->ui->get_permissions($dn, "users/user"); 
338           if (preg_match('/d/', $acl)){
340             /* Delete request is permitted, perform LDAP action */
341             $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn);
342             $this->usertab->set_acl_base();
343             $this->usertab->delete ();
344             gosa_log ("User object '".$dn."' has been removed");
345             unset ($this->usertab);
346             $this->usertab= NULL;
347           } else {
348             print_red (sprintf(_("You are not allowed to delete the user '%s'!"),$dn));
349             if(isset($this->ui->uid)){
350               gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
351             }
352           }
353           /* Remove lock file after successfull deletion */
354           del_lock ($dn);
355           unset($this->dns[$key]);
356       }
357     }
360     /********************
361       Delete MULTIPLE entries Canceled 
362      ********************/
364     /* Remove lock */
365     if(isset($_POST['delete_multiple_user_cancel'])){
366       foreach($this->dns as $key => $dn){
367         del_lock ($dn);
368         unset($this->dns[$key]);
369       }
370     }
371   
373     /********************
374       Delete entry requested, display confirm dialog
375      ********************/
377     /* Remove user was requested */
378     if ($s_action=="del"){
380       /* Get 'dn' from posted 'uid' */
381       $this->dn= $this->list[trim($s_entry)]['dn'];
383       /* Load permissions for selected 'dn' and check if
384          we're allowed to remove this 'dn' */
386       /* Check locking, save current plugin in 'back_plugin', so
387          the dialog knows where to return. */
388       if (($user= get_lock($this->dn)) != ""){
389         return(gen_locked_message ($user, $this->dn));
390       }
392       /* Lock the current entry, so nobody will edit it during deletion */
393       add_lock ($this->dn, $this->ui->dn);
394       $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
395       $smarty->assign("multiple", false);
396       return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
397     }
400     /********************
401       Delete entry confirmed 
402      ********************/
404     /* Confirmation for deletion has been passed. User should be deleted. */
405     if (isset($_POST['delete_user_confirm'])){
407       /* Some nice guy may send this as POST, so we've to check
408          for the permissions again. */
410       $acl = $this->ui->get_permissions($this->dn, "users/user"); 
411  
412       if (preg_match('/d/', $acl)){
414         /* Delete request is permitted, perform LDAP action */
415         $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
416         $this->usertab->set_acl_base();
417         $this->usertab->delete ();
418         gosa_log ("User object '".$this->dn."' has been removed");
419         unset ($this->usertab);
420         $this->usertab= NULL;
421       } else {
423         /* Normally this shouldn't be reached, send some extra
424            logs to notify the administrator */
425         print_red (_("You are not allowed to delete this user!"));
427         if(isset($this->ui->uid)){
428           gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
429         }
430       }
432       /* Remove lock file after successfull deletion */
433       del_lock ($this->dn);
434     }
436     
437     /********************
438       Delete entry Canceled 
439      ********************/
441     /* Delete user canceled? */
442     if (isset($_POST['delete_cancel'])){
443       del_lock ($this->dn);
444     }
447     /********************
448       Edit entry finished (Save) 
449      ********************/
451     /* Finish user edit is triggered by the tabulator dialog, so
452        the user wants to save edited data. Check and save at this
453        point. */
454     if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
456       /* Check tabs, will feed message array */
457       $this->usertab->last= $this->usertab->current;
458       $this->usertab->save_object();
459       $message= $this->usertab->check();
461       /* Save, or display error message? */
462       if (count($message) == 0){
464         /* No errors. Go ahead and prepare to ask for a password
465            in case we're creating a new user. 'dn' will be 'new'
466            in this case. It is set to the correct value later. */
467         if ($this->dn == "new"){
468           $set_pass= 1;
469         } else {
470           $set_pass= 0;
471         }
473         /* Save user data to ldap */
474         if($this->usertab->save() == 1){
475           gosa_log ("User object '".$this->dn."' saving failed.");
476           return;
477         }
478         gosa_log ("User object '".$this->dn."' has been saved");
480         if (!isset($_POST['edit_apply'])){
481           /* User has been saved successfully, remove lock from LDAP. */
482           if ($this->dn != "new"){
483             del_lock ($this->dn);
484           }
486           /* In case of new users, ask for a password, skip this for templates */
487           if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
488             $this->dn = $this->usertab->dn;
489             return($smarty->fetch(get_template_path('password.tpl', TRUE)));
490           }
492           unset ($this->usertab);
493           $this->usertab= NULL;
494           unset ($_SESSION['objectinfo']);
495         }
496       } else {
497         /* Ok. There seem to be errors regarding to the tab data,
498            show message and continue as usual. */
499         show_errors($message);
500       }
501     }
504     /********************
505       We want to create a new user, so fetch all available user templates 
506      ********************/
508     /* Generate template list */
509     if (($s_action=="new")||($s_action=="create_user_from_tpl")){
511       $this->templates= array();
512       $ldap= $this->config->get_ldap_link();
514       /* Create list of templates */
515       foreach ($this->config->departments as $key => $value){
516     
517         /* Get acls from different ou's */
518         $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user")       ; 
519  
520         /* If creation of a new user is allowed, append this template */
521         if (preg_match("/c/",$acl)){
522           
523           /* Search all templates from the current dn */
524           $ldap->cd (get_people_ou().$value);
525           $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
527           /* Append */
528           if ($ldap->count() != 0){
529             while ($attrs= $ldap->fetch()){
530               $this->templates[$ldap->getDN()]=
531                 $attrs['uid'][0]." - ".@LDAP::fix($key);
532             }
533             $this->templates['none']= _("none");
534           }
535         }
536       }
538       /* Sort templates */
539       natcasesort ($this->templates);
540       reset ($this->templates);
541     }
544     /********************
545       Create a new user,template, user from template 
546      ********************/
548     /* Check selected options for template */
549     if (isset($_POST['template_continue'])){
550       $message = array();
551       if(!isset($_POST['template']) || (empty($_POST['template']))){
552         $message[] = _("Please select a valid template.");
553       }
554       if(!isset($_POST['sn']) || (empty($_POST['sn']))){
555         $message[]= _("The required field 'Name' is not set.");
556       }
557       if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
558         $message[]= _("The required field 'Given name' is not set.");
559       }
560     
561       /* Show error message / continue editing */
562       if (count($message) > 0){
563         show_errors ($message);
565         foreach(array("sn", "givenName", "uid", "template") as $attr){
566           if(isset($_POST[$attr])){
567             $smarty->assign("$attr", $_POST[$attr]);
568           }else{
569             $smarty->assign("$attr", "");
570           }
571         }
572         $smarty->assign("templates",$this->templates);
573         $smarty->assign("got_uid",$this->got_uid);
574         $smarty->assign("edit_uid",false);
575         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
577       }
578     }
580     /* New user/template request */
581     if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
582       /* By default we set 'dn' to 'new', all relevant plugins will
583          react on this. */
584       $this->dn= "new";
585       
586       if (isset($this->config->current['IDGEN'])){
587         $this->got_uid= false;
588       } else {
589         $this->got_uid= true;
590       }
592       /* Create new usertab object */
593       $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
594       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
595       $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
597       /* Take care about templates */
598       if ($s_action=="new_tpl"){
599         $this->is_template= TRUE;
600         $this->usertab->set_template_mode ();
601       } else {
602         $this->is_template= FALSE;
603       }
605       /* Use template if there are any of them */
606       if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
607         foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
608           $smarty->assign("$attr", $this->$attr);
609         }
610         if ($s_action=="create_user_from_tpl"){
611           $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
612         } else {
613           $smarty->assign("template", "none");
614         }
615         $smarty->assign("edit_uid", "");
616         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
617       }
618     }
620     /********************
621       Template selected continue edit
622      ********************/
624     /* Continue template editing */
625     if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
627       $this->sn             = $_POST['sn'];
628       $this->givenName      = $_POST['givenName'];
630       /* Check for requred values */
631       $message= array();
632       if ($this->sn == "") {
633         $message[]= _("The required field 'Name' is not set.");
634       }
635       if ($this->givenName == "") {
636         $message[]= _("The required field 'Given name' is not set.");
637       }
639       /* Check if dn is used */
640       $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
641       $ldap= $this->config->get_ldap_link();
642       $ldap->cd ($dn);
643       $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
644       if ($ldap->count () != 0){
645         $message[]= _("A person with the choosen name is already used in this tree.");
646       }
648       /* Show error message / continue editing */
649       if (count($message) > 0){
650         show_errors ($message);
651       } else {
652         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
653         if (isset($this->config->current['IDGEN']) &&
654             $this->config->current['IDGEN'] != ""){
655           $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
656           if (count($uids)){
657             $smarty->assign("edit_uid", "false");
658             $smarty->assign("uids", $uids);
659             $this->uid= current($uids);
660           }
661         } else {
662           $smarty->assign("edit_uid", "");
663           $this->uid= "";
664         }
665         $this->got_uid= true;
666       }
668       foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
669         $smarty->assign("$attr", $this->$attr);
670       }
671       if (isset($_POST['template'])){
672         $smarty->assign("template", $_POST['template']);
673       }
674       return($smarty->fetch(get_template_path('template.tpl', TRUE)));
675     }
677     /********************
678       No template selected continue edit
679      ********************/
681     /* No template. Ok. Lets fill data into the normal user dialog */
682     if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
683       foreach(array("sn", "givenName", "uid") as $attr){
684         if (isset($_POST[$attr])){
685           $this->usertab->by_object['user']->$attr= $_POST[$attr];
686         }
687       }
688     }
691     /********************
692       Template selected continue edit
693      ********************/
695     /* Finish template preamble */
696     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
698       /* Might not be filled if IDGEN is unset */
699       $this->sn                 = $_POST['sn'];
700       $this->givenName          = $_POST['givenName'];
702       /* Move user supplied data to sub plugins */
703       $this->uid                = $_POST['uid'];
704       $this->usertab->uid       = $this->uid;
705       $this->usertab->sn        = $this->sn;
706       $this->usertab->givenName = $this->givenName;
707       $template_dn              = $_POST['template'];
708       $this->usertab->adapt_from_template($template_dn);
709       $template_base            = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
710       $this->usertab->by_object['user']->base= $template_base;
711     }
712    
713  
714     /********************
715       If no template was selected set base
716      ********************/
718     if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
719       $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
720     }
723     /********************
724       Display subdialog 
725      ********************/
727     /* Show tab dialog if object is present */
728     if(isset($this->usertab->config)){
729       $display= $this->usertab->execute();
731       /* Don't show buttons if tab dialog requests this */
732       if(isset($this->usertab->by_object)){
733         if (!$this->usertab->by_object[$this->usertab->current]->dialog){
734           $display.= "<p style=\"text-align:right\">\n";
735           $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
736           $display.= "&nbsp;\n";
737           if ($this->dn != "new"){
738             $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
739             $display.= "&nbsp;\n";
740           }
741           $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
742           $display.= "</p>";
743         }
744       }
745       return ($display);
746     }
747     
748     /* Check if there is a snapshot dialog open */
749     $base = $this->DivListUsers->selectedBase;
750     if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
751       return($str);
752     }
753   
754     /* Return rendered main page */
755         /* Display dialog with system list */
756     $this->DivListUsers->parent = $this;
757     $this->DivListUsers->execute();
759     /* Add departments if subsearch is disabled */
760     if(!$this->DivListUsers->SubSearch){
761       $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4,1);
762     }
763     $this->reload();
764     $this->DivListUsers->setEntries($this->list);
765     return($this->DivListUsers->Draw());
766   }
769   /* Return departments, that will be included within snapshot detection */
770   function get_used_snapshot_bases()
771   {
772     return(array(get_people_ou().$this->DivListUsers->selectedBase));
773   }  
776   function reload()
777   {
778     /* Set base for all searches */
779     $base= $this->DivListUsers->selectedBase;
780     $this->list =array();
782     /* Get filter configuration */
783     $Regex                = $this->DivListUsers->Regex;
784     $SubSearch            = $this->DivListUsers->SubSearch;
785     $ShowTemplates        = $this->DivListUsers->ShowTemplates;
786     $ShowFunctionalUsers  = $this->DivListUsers->ShowFunctionalUsers;
787     $ShowUnixUsers        = $this->DivListUsers->ShowUnixUsers;
788     $ShowMailUsers        = $this->DivListUsers->ShowMailUsers;
789     $ShowSambaUsers       = $this->DivListUsers->ShowSambaUsers;
790     $ShowProxyUsers       = $this->DivListUsers->ShowProxyUsers;
792     /* Setup filter depending on selection */
793     $filter="";
794     if ($this->config->current['SAMBAVERSION'] == 3){
795       $samba= "sambaSamAccount";
796     } else {
797       $samba= "sambaAccount";
798     }
800     if ($ShowFunctionalUsers){
801       $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
802                 "(objectClass=gosaMailAccount)(objectClass=$samba)".
803                 "(objectClass=gosaProxyAccount))))";
804     }
805     if ($ShowUnixUsers){
806       $filter.= "(objectClass=posixAccount)";
807     }
808     if ($ShowMailUsers){
809       $filter.= "(objectClass=gosaMailAccount)";
810     }
811     if ($ShowSambaUsers){
812       $filter.= "(objectClass=$samba)";
813     }
814     if ($ShowProxyUsers){
815       $filter.= "(objectClass=gosaProxyAccount)";
816     }
817     if ($ShowTemplates){
818       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
819     } else {
820       $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
821     }
822     $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
824     /* Generate userlist */
825     $ldap= $this->config->get_ldap_link(TRUE);
827     if ($SubSearch){
828       $ListTemp =  get_list($filter, "users", $base,
829                             array("uid", "givenName", "sn", "objectClass"), GL_SUBSEARCH | GL_SIZELIMIT);
830     } else {
831       $base= get_people_ou().$base;
832       $ListTemp = get_list($filter, "users", $base, 
833                             array("uid", "givenName", "sn", "objectClass"), GL_SIZELIMIT);
834     }
835     $SortTemp = array();
836     $List = array();
837     foreach($ListTemp as $Key => $Entry){
839       /* Skip entries that are not located under the people ou (normaly 'ou=people,')
840        * Else winstations will be listed too, if you use the subtree flag. 
841        */
842       if(!preg_match("/".normalizePreg(get_people_ou())."/i",$Entry['dn'])){
843         continue;
844       }else{
846         // Generate caption for rows
847         if (isset($Entry["sn"]) && isset($Entry["givenName"])){
848           $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
849         } else {
850           $display= "[".$Entry["uid"][0]."]";
851         }
853         $display = strtolower($display);
854         $List[$display] = $Entry;
855         $SortTemp[$display] = $display;
856       }
857     }
858     sort($SortTemp);
859     reset($SortTemp);
861     $this->list = array();
862     foreach($SortTemp as $Key){
863       $this->list[] = $List[$Key];
864     }
865   }
867   function remove_lock()
868   {
869     /* Remove user lock if a DN is marked as "currently edited" */
870     if (isset($this->usertab->dn)){
871       del_lock ($this->usertab->dn);
872     }
873   }
875  
876   /* Perform copy & paste requests
877       If copy&paste is in progress this returns a dialog to fix required attributes 
878    */ 
879   function copyPasteHandling($s_action,$s_entry)
880   {
881     /* Only perform copy/paste if it is enabled */
882     if($this->CopyPasteHandler){
884       /* Prepare current object to be pasted */
885       if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){
887         $this->CopyPasteHandler->save_object();
888         $this->CopyPasteHandler->SetVar("base", $this->DivListUsers->selectedBase);
890         /* Execute copy & paste dialog and display returned data, normaly a dialog which allows 
891             us to solve all attribute mismatches for this object.
892             If nothing is returned, copy & paste was succesfully or aborted */
893         if(($ret= $this->CopyPasteHandler->execute())){
894           return ($ret);
895         }
897         /* Use the last dn to search for it's ID in the newly generated list. */
898         $dn= $this->CopyPasteHandler->lastdn;
900         /* Get new user list */
901         $this->reload();
902         foreach($this->list as $id => $entry){
903           if($entry['dn'] == $dn){
904             $s_entry= $id;
905             break;
906           }
907         }
908        
909         /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
910         if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
911           $this->CPPasswordChange = $s_entry;
912         }
913       }
915       /* Copy selected object 
916          Create a new empty object and the current selected object. 
917          Send both to copy&paste class*/
918       if($s_action == "copy"){
919         $this->CopyPasteHandler->Clear();
920         $dn= $this->list[trim($s_entry)]['dn'];
922         /* Check acl */
923         $ui = get_userinfo();
924         $acl_all  = $ui->has_complete_category_acls($this->DivListUsers->selectedBase,"users") ;
925         if(preg_match("/(c.*w|w.*c)/",$acl_all)){
926           $obj    = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
927           $obj->set_acl_base($dn);
928           $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new");
929           $objNew->set_acl_base($dn);
931           $this->CopyPasteHandler->Copy($obj,$objNew);
932         }else{
933           print_red("You are not allowed to copy this entry.");
934         }
935       }
937       /* Cut selected object. 
938          Open user object and send it to the copy & paste handler */
939       if($s_action == "cut"){
940         $this->CopyPasteHandler->Clear();
941         $dn= $this->list[trim($s_entry)]['dn'];
943         /* Check acl */
944         $acl_all  = $ui->has_complete_category_acls($this->DivListUsers->selectedBase,"users") ;
945         if(preg_match("/(c.*w|w.*c)/",$acl_all)){
946           $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
947           $obj->set_acl_base($dn);
948           $this->CopyPasteHandler->Cut($obj);
949         }else{
950           print_red("You are not allowed to cut this entry.");
951         }
952       }
953     }
954   }
956   function save_object()
957   {
958     /* Handle divlist filter && department selection*/
959     if(!is_object($this->usertab)){
960       $this->DivListUsers->save_object();
961     }
962   }
964     
965   function list_get_selected_items()
966   {
967     $ids = array();
968     foreach($_POST as $name => $value){
969       if(preg_match("/^item_selected_[0-9]*$/",$name)){
970         $id   = preg_replace("/^item_selected_/","",$name);
971         $ids[$id] = $id;
972       }
973     }
974     return($ids);
975   }
976   
978   /* A set of disabled and therefore overloaded functions. They are
979      not needed in this class. */
980   function remove_from_parent() { } 
981   function check() { } 
982   function save() { } 
983   function adapt_from_template($dn) { } 
984   function password_change_needed() { } 
986 } /* ... class userManagement */
987 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
988 ?>