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 "cut" => "^cut") as $act => $name){
93 if (preg_match("/".$name.".*/", $key)){
94 $s_action= $act;
95 $s_entry= preg_replace("/".$name."_/i", "", $key);
96 break;
97 }
98 }
100 } /* ...Test POST */
102 /* Remove coordinate prefix from POST, required by some browsers */
103 $s_entry= preg_replace("/_.$/", "", $s_entry);
105 /* Seperate possibly encoded tab and entry, default to tab "user" */
106 if(preg_match("/.*-.*/", $s_entry)){
107 $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
108 $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
109 }else{
110 $s_tab= "user";
111 }
113 if(!search_config($this->config->data['TABS'], $s_tab , "CLASS")){
114 $s_tab = "user";
115 }
117 /* Display the copy & paste dialog, if it is currently open */
118 $ret = $this->copyPasteHandling_from_queue($s_action);
119 if($ret){
120 return($ret);
121 }
124 /********************
125 Edit existing entry
126 ********************/
128 /* User wants to edit data? */
129 if (($s_action=="edit") && (!isset($this->usertab->config))){
131 /* Get 'dn' from posted 'uid', must be unique */
132 $this->dn= $this->list[trim($s_entry)]['dn'];
134 /* Check locking, save current plugin in 'back_plugin', so
135 the dialog knows where to return. */
136 if (($user= get_lock($this->dn)) != ""){
137 return(gen_locked_message ($user, $this->dn));
138 }
140 /* Lock the current entry, so everyone will get the
141 above dialog */
142 add_lock ($this->dn, $this->ui->dn);
144 /* Register usertab to trigger edit dialog */
145 $this->usertab= new usertabs($this->config,
146 $this->config->data['TABS']['USERTABS'], $this->dn);
148 /* Switch tab, if it was requested by the user */
149 $this->usertab->current = $s_tab;
151 /* Set ACL and move DN to the headline */
152 $this->usertab->set_acl_base($this->dn);
153 $_SESSION['objectinfo']= $this->dn;
154 }
157 /********************
158 Edit canceled
159 ********************/
161 /* Reset all relevant data, if we get a _cancel request */
162 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
163 if (isset($this->usertab)){
164 del_lock ($this->usertab->dn);
165 unset ($this->usertab);
166 }
167 $this->usertab= NULL;
168 $this->lognames= array();;
169 $this->sn= "";
170 $this->givenName= "";
171 $this->uid= "";
172 unset ($_SESSION['objectinfo']);
173 }
176 /********************
177 Change password requested
178 ********************/
180 /* Password change requested */
181 if (($s_action == "change_pw") || (!empty($this->CPPasswordChange))){
183 if(!empty($this->CPPasswordChange)){
184 $s_entry = $this->CPPasswordChange;
185 $this->CPPasswordChange = "";
186 }
188 /* Get 'dn' from posted 'uid' */
189 $this->dn= $this->list[trim($s_entry)]['dn'];
191 /* Load permissions for selected 'dn' and check if
192 we're allowed to remove this 'dn' */
193 if (preg_match("/w/",$this->ui->get_permissions($this->dn,"users/password"))){
195 /* User is allowed to change passwords, save 'dn' and 'acl' for next
196 dialog. */
197 $_SESSION['objectinfo']= $this->dn;
198 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
200 } else {
201 /* User is not allowed. Show message and cancel. */
202 print_red (_("You are not allowed to set this users password!"));
203 }
204 }
207 /********************
208 Change password confirmed
209 ********************/
211 /* Perform password change */
212 if (isset($_POST['password_finish'])){
214 /* For security reasons, check if user is allowed to set password again */
215 $dn = $this->dn;
216 $acl = $this->ui->get_permissions($dn, "users/password");
217 $cacl= $this->ui->get_permissions($dn, "users/user");
219 if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
221 /* Check input and feed errors into 'message' */
222 $message= array();
224 /* Sanity checks... */
225 if ($_POST['new_password'] != $_POST['repeated_password']){
227 /* Matching passwords in new and repeated? */
228 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
229 } else {
231 /* Empty password is not permitted by default. */
232 if ($_POST['new_password'] == ""){
233 $message[]= _("The password you've entered as 'New password' is empty.");
234 }
235 }
237 /* Errors, or password change? */
238 if (count($message) != 0){
240 /* Show error message and continue editing */
241 show_errors ($message);
242 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
243 }
245 $config= $this->config;
246 $ldap_ui= $this->config->get_ldap_link();
247 if(isset($this->usertab->dn)){
248 $ldap_ui->cat($this->usertab->dn,array("uid"));
249 $user = $ldap_ui->fetch();
250 }else{
251 $ldap_ui->cat($this->dn,array("uid"));
252 $user = $ldap_ui->fetch();
253 }
254 if((is_array($user))&&(isset($user['uid']))){
255 $username= $user['uid'][0];
256 }
258 /* Set password, perform required steps */
259 if ($this->usertab){
260 if ($this->usertab->password_change_needed()){
261 $obj= $this->usertab->by_object['user'];
262 change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
263 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
264 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
265 }
266 new log("modify","users/".get_class($this),$this->usertab->dn,array(),"Password has been changed");
267 unset($this->usertab);
268 $this->usertab= NULL;
269 }
270 } else {
271 change_password ($this->dn, $_POST['new_password']);
272 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
273 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
274 }
276 new log("modify","users/".get_class($this),$this->dn,array(),"Password has been changed");
277 }
278 } else {
280 /* Missing permissions, show message */
281 print_red (_("You are not allowed to set this users password!"));
282 }
283 /* Clean session, delete lock */
284 del_lock ($this->dn);
285 unset ($this->usertab);
286 $this->usertab= NULL;
287 $this->lognames= array();;
288 $this->sn= "";
289 $this->givenName= "";
290 $this->uid= "";
291 unset ($_SESSION['objectinfo']);
292 }
295 /********************
296 Delete MULTIPLE entries requested, display confirm dialog
297 ********************/
299 if ($s_action=="del_multiple"){
300 $ids = $this->list_get_selected_items();
302 if(count($ids)){
304 foreach($ids as $id){
305 $dn = $this->list[$id]['dn'];
306 if (($user= get_lock($dn)) != ""){
307 return(gen_locked_message ($user, $dn));
308 }
309 $this->dns[$id] = $dn;
310 }
312 $dns_names = "<br><pre>";
313 foreach($this->dns as $dn){
314 add_lock ($dn, $this->ui->dn);
315 $dns_names .= $dn."\n";
316 }
317 $dns_names .="</pre>";
319 /* Lock the current entry, so nobody will edit it during deletion */
320 if (count($this->dns) == 1){
321 $smarty->assign("info", sprintf(_("You're about to delete the following entry: %s"), @LDAP::fix($dns_names)));
322 } else {
323 $smarty->assign("info", sprintf(_("You're about to delete the following entries: %s"), @LDAP::fix($dns_names)));
324 }
325 $smarty->assign("multiple", true);
326 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
327 }
328 }
331 /********************
332 Delete MULTIPLE entries confirmed
333 ********************/
335 /* Confirmation for deletion has been passed. Users should be deleted. */
336 if (isset($_POST['delete_multiple_user_confirm'])){
338 /* Remove user by user and check acls before removeing them */
339 foreach($this->dns as $key => $dn){
341 $acl = $this->ui->get_permissions($dn, "users/user");
342 if (preg_match('/d/', $acl)){
344 /* Delete request is permitted, perform LDAP action */
345 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn);
346 $this->usertab->set_acl_base();
347 $this->usertab->delete ();
348 unset ($this->usertab);
349 $this->usertab= NULL;
350 } else {
351 print_red (sprintf(_("You are not allowed to delete the user '%s'!"),$dn));
352 if(isset($this->ui->uid)){
353 new log("security","users/".get_class($this),$dn,array(),"Tried to trick deletion.");
354 }
355 }
356 /* Remove lock file after successfull deletion */
357 del_lock ($dn);
358 unset($this->dns[$key]);
359 }
360 }
363 /********************
364 Delete MULTIPLE entries Canceled
365 ********************/
367 /* Remove lock */
368 if(isset($_POST['delete_multiple_user_cancel'])){
369 foreach($this->dns as $key => $dn){
370 del_lock ($dn);
371 unset($this->dns[$key]);
372 }
373 }
376 /********************
377 Delete entry requested, display confirm dialog
378 ********************/
380 /* Remove user was requested */
381 if ($s_action=="del"){
383 /* Get 'dn' from posted 'uid' */
384 $this->dn= $this->list[trim($s_entry)]['dn'];
386 /* Load permissions for selected 'dn' and check if
387 we're allowed to remove this 'dn' */
389 /* Check locking, save current plugin in 'back_plugin', so
390 the dialog knows where to return. */
391 if (($user= get_lock($this->dn)) != ""){
392 return(gen_locked_message ($user, $this->dn));
393 }
395 /* Lock the current entry, so nobody will edit it during deletion */
396 add_lock ($this->dn, $this->ui->dn);
397 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
398 $smarty->assign("multiple", false);
399 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
400 }
403 /********************
404 Delete entry confirmed
405 ********************/
407 /* Confirmation for deletion has been passed. User should be deleted. */
408 if (isset($_POST['delete_user_confirm'])){
410 /* Some nice guy may send this as POST, so we've to check
411 for the permissions again. */
413 $acl = $this->ui->get_permissions($this->dn, "users/user");
415 if (preg_match('/d/', $acl)){
417 /* Delete request is permitted, perform LDAP action */
418 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
419 $this->usertab->set_acl_base();
420 $this->usertab->delete ();
421 unset ($this->usertab);
422 $this->usertab= NULL;
423 } else {
425 /* Normally this shouldn't be reached, send some extra
426 logs to notify the administrator */
427 print_red (_("You are not allowed to delete this user!"));
429 if(isset($this->ui->uid)){
430 new log("security","users/".get_class($this),$this->dn,array(),"Tried to trick deletion.");
431 }
432 }
434 /* Remove lock file after successfull deletion */
435 del_lock ($this->dn);
436 }
439 /********************
440 Delete entry Canceled
441 ********************/
443 /* Delete user canceled? */
444 if (isset($_POST['delete_cancel'])){
445 del_lock ($this->dn);
446 }
449 /********************
450 Edit entry finished (Save)
451 ********************/
453 /* Finish user edit is triggered by the tabulator dialog, so
454 the user wants to save edited data. Check and save at this
455 point. */
456 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
458 /* Check tabs, will feed message array */
459 $this->usertab->last= $this->usertab->current;
460 $this->usertab->save_object();
461 $message= $this->usertab->check();
463 /* Save, or display error message? */
464 if (count($message) == 0){
466 /* No errors. Go ahead and prepare to ask for a password
467 in case we're creating a new user. 'dn' will be 'new'
468 in this case. It is set to the correct value later. */
469 if ($this->dn == "new"){
470 $set_pass= 1;
471 } else {
472 $set_pass= 0;
473 }
475 /* Save user data to ldap */
476 if($this->usertab->save() == 1){
477 return;
478 }
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){
517 /* Get acls from different ou's */
518 $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user") ;
520 /* If creation of a new user is allowed, append this template */
521 if (preg_match("/c/",$acl)){
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 }
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";
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 }
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.= " \n";
737 if ($this->dn != "new"){
738 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
739 $display.= " \n";
740 }
741 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
742 $display.= "</p>";
743 }
744 }
745 return ($display);
746 }
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 }
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 }
876 function copyPasteHandling_from_queue($s_action)
877 {
878 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
880 /* Cleanup object queue */
881 $this->CopyPasteHandler->cleanup_queue();
883 /* Add new entries to CP queue */
884 foreach($this->list_get_selected_items() as $id){
885 $dn = $this->list[$id]['dn'];
887 if($s_action == "copy_multiple"){
888 $this->CopyPasteHandler->add_to_queue($dn,"copy","usertabs","USERTABS");
889 }
890 if($s_action == "cut_multiple"){
891 $this->CopyPasteHandler->add_to_queue($dn,"cut","usertabs","USERTABS");
892 }
893 }
894 }
896 if($s_action == "editPaste"){
897 $this->start_pasting_copied_objects = TRUE;
898 }
900 /* Return C&P dialog */
901 if($this->start_pasting_copied_objects &&
902 ($this->CopyPasteHandler->entries_queued() || $this->CopyPasteHandler->current)){
904 $this->CopyPasteHandler->SetVar("base",$this->DivListUsers->selectedBase);
905 $data = $this->CopyPasteHandler->paste_entries();
907 /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
908 if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
909 $s_entry = $this->CopyPasteHandler->last_entry();
910 $this->reload();
911 foreach($this->list as $key => $entry){
912 if($entry['dn'] == $s_entry){
913 $this->CPPasswordChange = $key;
914 }
915 }
916 }
918 /* Return dialog data */
919 if(!empty($data)){
920 return($data);
921 }
922 }
924 $this->start_pasting_copied_objects = FALSE;
925 return("");
926 }
929 function save_object()
930 {
931 /* Handle divlist filter && department selection*/
932 if(!is_object($this->usertab)){
933 $this->DivListUsers->save_object();
934 }
935 }
938 function list_get_selected_items()
939 {
940 $ids = array();
941 foreach($_POST as $name => $value){
942 if(preg_match("/^item_selected_[0-9]*$/",$name)){
943 $id = preg_replace("/^item_selected_/","",$name);
944 $ids[$id] = $id;
945 }
946 }
947 return($ids);
948 }
951 /* A set of disabled and therefore overloaded functions. They are
952 not needed in this class. */
953 function remove_from_parent() { }
954 function check() { }
955 function save() { }
956 function adapt_from_template($dn) { }
957 function password_change_needed() { }
959 } /* ... class userManagement */
960 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
961 ?>