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 }
118 /********************
119 Copy & Paste
120 ********************/
122 /* Display the copy & paste dialog, if it is currently open */
123 if($this->CPPasswordChange == ""){
124 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
125 if($ret){
126 return($ret);
127 }
128 }
131 /********************
132 Change password requested
133 ********************/
135 /* Password change requested */
136 if (($s_action == "change_pw") || (!empty($this->CPPasswordChange))){
138 if(!empty($this->CPPasswordChange)){
139 $s_entry = $this->CPPasswordChange;
140 $this->CPPasswordChange = "";
141 }
143 /* Get 'dn' from posted 'uid' */
144 $this->dn= $this->list[trim($s_entry)]['dn'];
146 /* Load permissions for selected 'dn' and check if
147 we're allowed to remove this 'dn' */
148 if (preg_match("/w/",$this->ui->get_permissions($this->dn,"users/password"))){
150 /* User is allowed to change passwords, save 'dn' and 'acl' for next
151 dialog. */
152 $_SESSION['objectinfo']= $this->dn;
153 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
155 } else {
156 /* User is not allowed. Show message and cancel. */
157 print_red (_("You are not allowed to set this users password!"));
158 }
159 }
162 /********************
163 Change password confirmed
164 ********************/
166 /* Perform password change */
167 if (isset($_POST['password_finish'])){
169 /* For security reasons, check if user is allowed to set password again */
170 $dn = $this->dn;
171 $acl = $this->ui->get_permissions($dn, "users/password");
172 $cacl= $this->ui->get_permissions($dn, "users/user");
174 if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
176 /* Check input and feed errors into 'message' */
177 $message= array();
179 /* Sanity checks... */
180 if ($_POST['new_password'] != $_POST['repeated_password']){
182 /* Matching passwords in new and repeated? */
183 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
184 } else {
186 /* Empty password is not permitted by default. */
187 if ($_POST['new_password'] == ""){
188 $message[]= _("The password you've entered as 'New password' is empty.");
189 }
190 }
192 /* Errors, or password change? */
193 if (count($message) != 0){
195 /* Show error message and continue editing */
196 show_errors ($message);
197 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
198 }
200 $config= $this->config;
201 $ldap_ui= $this->config->get_ldap_link();
202 if(isset($this->usertab->dn)){
203 $ldap_ui->cat($this->usertab->dn,array("uid"));
204 $user = $ldap_ui->fetch();
205 }else{
206 $ldap_ui->cat($this->dn,array("uid"));
207 $user = $ldap_ui->fetch();
208 }
209 if((is_array($user))&&(isset($user['uid']))){
210 $username= $user['uid'][0];
211 }
213 /* Set password, perform required steps */
214 if ($this->usertab){
215 if ($this->usertab->password_change_needed()){
216 $obj= $this->usertab->by_object['user'];
217 change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
218 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
219 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
220 }
221 new log("modify","users/".get_class($this),$this->usertab->dn,array(),"Password has been changed");
222 unset($this->usertab);
223 $this->usertab= NULL;
224 }
225 } else {
226 change_password ($this->dn, $_POST['new_password']);
227 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
228 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
229 }
230 new log("modify","users/".get_class($this),$this->dn,array(),"Password has been changed");
231 }
232 } else {
234 /* Missing permissions, show message */
235 print_red (_("You are not allowed to set this users password!"));
236 }
237 /* Clean session, delete lock */
238 del_lock ($this->dn);
239 unset ($this->usertab);
240 $this->usertab= NULL;
241 $this->lognames= array();;
242 $this->sn= "";
243 $this->givenName= "";
244 $this->uid= "";
245 unset ($_SESSION['objectinfo']);
246 }
249 /********************
250 Edit existing entry
251 ********************/
253 /* User wants to edit data? */
254 if (($s_action=="edit") && (!isset($this->usertab->config))){
256 /* Get 'dn' from posted 'uid', must be unique */
257 $this->dn= $this->list[trim($s_entry)]['dn'];
259 /* Check locking, save current plugin in 'back_plugin', so
260 the dialog knows where to return. */
261 if (($user= get_lock($this->dn)) != ""){
262 return(gen_locked_message ($user, $this->dn));
263 }
265 /* Lock the current entry, so everyone will get the
266 above dialog */
267 add_lock ($this->dn, $this->ui->dn);
269 /* Register usertab to trigger edit dialog */
270 $this->usertab= new usertabs($this->config,
271 $this->config->data['TABS']['USERTABS'], $this->dn);
273 /* Switch tab, if it was requested by the user */
274 $this->usertab->current = $s_tab;
276 /* Set ACL and move DN to the headline */
277 $this->usertab->set_acl_base($this->dn);
278 $_SESSION['objectinfo']= $this->dn;
279 }
282 /********************
283 Edit canceled
284 ********************/
286 /* Reset all relevant data, if we get a _cancel request */
287 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
288 if (isset($this->usertab)){
289 del_lock ($this->usertab->dn);
290 unset ($this->usertab);
291 }
292 $this->usertab= NULL;
293 $this->lognames= array();;
294 $this->sn= "";
295 $this->givenName= "";
296 $this->uid= "";
297 unset ($_SESSION['objectinfo']);
298 }
301 /********************
302 Delete MULTIPLE entries requested, display confirm dialog
303 ********************/
305 if ($s_action=="del_multiple"){
306 $ids = $this->list_get_selected_items();
308 if(count($ids)){
310 foreach($ids as $id){
311 $dn = $this->list[$id]['dn'];
312 if (($user= get_lock($dn)) != ""){
313 return(gen_locked_message ($user, $dn));
314 }
315 $this->dns[$id] = $dn;
316 }
318 $dns_names = "<br><pre>";
319 foreach($this->dns as $dn){
320 add_lock ($dn, $this->ui->dn);
321 $dns_names .= $dn."\n";
322 }
323 $dns_names .="</pre>";
325 /* Lock the current entry, so nobody will edit it during deletion */
326 if (count($this->dns) == 1){
327 $smarty->assign("info", sprintf(_("You're about to delete the following entry: %s"), @LDAP::fix($dns_names)));
328 } else {
329 $smarty->assign("info", sprintf(_("You're about to delete the following entries: %s"), @LDAP::fix($dns_names)));
330 }
331 $smarty->assign("multiple", true);
332 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
333 }
334 }
337 /********************
338 Delete MULTIPLE entries confirmed
339 ********************/
341 /* Confirmation for deletion has been passed. Users should be deleted. */
342 if (isset($_POST['delete_multiple_user_confirm'])){
344 /* Remove user by user and check acls before removeing them */
345 foreach($this->dns as $key => $dn){
347 $acl = $this->ui->get_permissions($dn, "users/user");
348 if (preg_match('/d/', $acl)){
350 /* Delete request is permitted, perform LDAP action */
351 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn);
352 $this->usertab->set_acl_base();
353 $this->usertab->delete ();
354 unset ($this->usertab);
355 $this->usertab= NULL;
356 } else {
357 print_red (sprintf(_("You are not allowed to delete the user '%s'!"),$dn));
358 if(isset($this->ui->uid)){
359 new log("security","users/".get_class($this),$dn,array(),"Tried to trick deletion.");
360 }
361 }
362 /* Remove lock file after successfull deletion */
363 del_lock ($dn);
364 unset($this->dns[$key]);
365 }
366 }
369 /********************
370 Delete MULTIPLE entries Canceled
371 ********************/
373 /* Remove lock */
374 if(isset($_POST['delete_multiple_user_cancel'])){
375 foreach($this->dns as $key => $dn){
376 del_lock ($dn);
377 unset($this->dns[$key]);
378 }
379 }
382 /********************
383 Delete entry requested, display confirm dialog
384 ********************/
386 /* Remove user was requested */
387 if ($s_action=="del"){
389 /* Get 'dn' from posted 'uid' */
390 $this->dn= $this->list[trim($s_entry)]['dn'];
392 /* Load permissions for selected 'dn' and check if
393 we're allowed to remove this 'dn' */
395 /* Check locking, save current plugin in 'back_plugin', so
396 the dialog knows where to return. */
397 if (($user= get_lock($this->dn)) != ""){
398 return(gen_locked_message ($user, $this->dn));
399 }
401 /* Lock the current entry, so nobody will edit it during deletion */
402 add_lock ($this->dn, $this->ui->dn);
403 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
404 $smarty->assign("multiple", false);
405 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
406 }
409 /********************
410 Delete entry confirmed
411 ********************/
413 /* Confirmation for deletion has been passed. User should be deleted. */
414 if (isset($_POST['delete_user_confirm'])){
416 /* Some nice guy may send this as POST, so we've to check
417 for the permissions again. */
419 $acl = $this->ui->get_permissions($this->dn, "users/user");
421 if (preg_match('/d/', $acl)){
423 /* Delete request is permitted, perform LDAP action */
424 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
425 $this->usertab->set_acl_base();
426 $this->usertab->delete ();
427 unset ($this->usertab);
428 $this->usertab= NULL;
429 } else {
431 /* Normally this shouldn't be reached, send some extra
432 logs to notify the administrator */
433 print_red (_("You are not allowed to delete this user!"));
435 if(isset($this->ui->uid)){
436 new log("security","users/".get_class($this),$this->dn,array(),"Tried to trick deletion.");
437 }
438 }
440 /* Remove lock file after successfull deletion */
441 del_lock ($this->dn);
442 }
445 /********************
446 Delete entry Canceled
447 ********************/
449 /* Delete user canceled? */
450 if (isset($_POST['delete_cancel'])){
451 del_lock ($this->dn);
452 }
455 /********************
456 Edit entry finished (Save)
457 ********************/
459 /* Finish user edit is triggered by the tabulator dialog, so
460 the user wants to save edited data. Check and save at this
461 point. */
462 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
464 /* Check tabs, will feed message array */
465 $this->usertab->last= $this->usertab->current;
466 $this->usertab->save_object();
467 $message= $this->usertab->check();
469 /* Save, or display error message? */
470 if (count($message) == 0){
472 /* No errors. Go ahead and prepare to ask for a password
473 in case we're creating a new user. 'dn' will be 'new'
474 in this case. It is set to the correct value later. */
475 if ($this->dn == "new"){
476 $set_pass= 1;
477 } else {
478 $set_pass= 0;
479 }
481 /* Save user data to ldap */
482 if($this->usertab->save() == 1){
483 return;
484 }
486 if (!isset($_POST['edit_apply'])){
487 /* User has been saved successfully, remove lock from LDAP. */
488 if ($this->dn != "new"){
489 del_lock ($this->dn);
490 }
492 /* In case of new users, ask for a password, skip this for templates */
493 if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
494 $this->dn = $this->usertab->dn;
495 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
496 }
498 unset ($this->usertab);
499 $this->usertab= NULL;
500 unset ($_SESSION['objectinfo']);
501 }
502 } else {
503 /* Ok. There seem to be errors regarding to the tab data,
504 show message and continue as usual. */
505 show_errors($message);
506 }
507 }
510 /********************
511 We want to create a new user, so fetch all available user templates
512 ********************/
514 /* Generate template list */
515 if (($s_action=="new")||($s_action=="create_user_from_tpl")){
517 $this->templates= array();
518 $ldap= $this->config->get_ldap_link();
520 /* Create list of templates */
521 foreach ($this->config->departments as $key => $value){
523 /* Get acls from different ou's */
524 $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user") ;
526 /* If creation of a new user is allowed, append this template */
527 if (preg_match("/c/",$acl)){
529 /* Search all templates from the current dn */
530 $ldap->cd (get_people_ou().$value);
531 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
533 /* Append */
534 if ($ldap->count() != 0){
535 while ($attrs= $ldap->fetch()){
536 $this->templates[$ldap->getDN()]=
537 $attrs['uid'][0]." - ".@LDAP::fix($key);
538 }
539 $this->templates['none']= _("none");
540 }
541 }
542 }
544 /* Sort templates */
545 natcasesort ($this->templates);
546 reset ($this->templates);
547 }
550 /********************
551 Create a new user,template, user from template
552 ********************/
554 /* Check selected options for template */
555 if (isset($_POST['template_continue'])){
556 $message = array();
557 if(!isset($_POST['template']) || (empty($_POST['template']))){
558 $message[] = _("Please select a valid template.");
559 }
560 if(!isset($_POST['sn']) || (empty($_POST['sn']))){
561 $message[]= _("The required field 'Name' is not set.");
562 }
563 if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
564 $message[]= _("The required field 'Given name' is not set.");
565 }
567 /* Show error message / continue editing */
568 if (count($message) > 0){
569 show_errors ($message);
571 foreach(array("sn", "givenName", "uid", "template") as $attr){
572 if(isset($_POST[$attr])){
573 $smarty->assign("$attr", $_POST[$attr]);
574 }else{
575 $smarty->assign("$attr", "");
576 }
577 }
578 $smarty->assign("templates",$this->templates);
579 $smarty->assign("got_uid",$this->got_uid);
580 $smarty->assign("edit_uid",false);
581 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
583 }
584 }
586 /* New user/template request */
587 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
588 /* By default we set 'dn' to 'new', all relevant plugins will
589 react on this. */
590 $this->dn= "new";
592 if (isset($this->config->current['IDGEN'])){
593 $this->got_uid= false;
594 } else {
595 $this->got_uid= true;
596 }
598 /* Create new usertab object */
599 $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
600 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
601 $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
603 /* Take care about templates */
604 if ($s_action=="new_tpl"){
605 $this->is_template= TRUE;
606 $this->usertab->set_template_mode ();
607 } else {
608 $this->is_template= FALSE;
609 }
611 /* Use template if there are any of them */
612 if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
613 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
614 $smarty->assign("$attr", $this->$attr);
615 }
616 if ($s_action=="create_user_from_tpl"){
617 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
618 } else {
619 $smarty->assign("template", "none");
620 }
621 $smarty->assign("edit_uid", "");
622 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
623 }
624 }
626 /********************
627 Template selected continue edit
628 ********************/
630 /* Continue template editing */
631 if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
633 $this->sn = $_POST['sn'];
634 $this->givenName = $_POST['givenName'];
636 /* Check for requred values */
637 $message= array();
638 if ($this->sn == "") {
639 $message[]= _("The required field 'Name' is not set.");
640 }
641 if ($this->givenName == "") {
642 $message[]= _("The required field 'Given name' is not set.");
643 }
645 /* Check if dn is used */
646 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
647 $ldap= $this->config->get_ldap_link();
648 $ldap->cd ($dn);
649 $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
650 if ($ldap->count () != 0){
651 $message[]= _("A person with the choosen name is already used in this tree.");
652 }
654 /* Show error message / continue editing */
655 if (count($message) > 0){
656 show_errors ($message);
657 } else {
658 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
659 if (isset($this->config->current['IDGEN']) &&
660 $this->config->current['IDGEN'] != ""){
661 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
662 if (count($uids)){
663 $smarty->assign("edit_uid", "false");
664 $smarty->assign("uids", $uids);
665 $this->uid= current($uids);
666 }
667 } else {
668 $smarty->assign("edit_uid", "");
669 $this->uid= "";
670 }
671 $this->got_uid= true;
672 }
674 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
675 $smarty->assign("$attr", $this->$attr);
676 }
677 if (isset($_POST['template'])){
678 $smarty->assign("template", $_POST['template']);
679 }
680 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
681 }
683 /********************
684 No template selected continue edit
685 ********************/
687 /* No template. Ok. Lets fill data into the normal user dialog */
688 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
689 foreach(array("sn", "givenName", "uid") as $attr){
690 if (isset($_POST[$attr])){
691 $this->usertab->by_object['user']->$attr= $_POST[$attr];
692 }
693 }
694 }
697 /********************
698 Template selected continue edit
699 ********************/
701 /* Finish template preamble */
702 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
704 /* Might not be filled if IDGEN is unset */
705 $this->sn = $_POST['sn'];
706 $this->givenName = $_POST['givenName'];
708 /* Move user supplied data to sub plugins */
709 $this->uid = $_POST['uid'];
710 $this->usertab->uid = $this->uid;
711 $this->usertab->sn = $this->sn;
712 $this->usertab->givenName = $this->givenName;
713 $template_dn = $_POST['template'];
714 $this->usertab->adapt_from_template($template_dn);
715 $template_base = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
716 $this->usertab->by_object['user']->base= $template_base;
717 }
720 /********************
721 If no template was selected set base
722 ********************/
724 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
725 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
726 }
729 /********************
730 Display subdialog
731 ********************/
733 /* Show tab dialog if object is present */
734 if(isset($this->usertab->config)){
735 $display= $this->usertab->execute();
737 /* Don't show buttons if tab dialog requests this */
738 if(isset($this->usertab->by_object)){
739 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
740 $display.= "<p style=\"text-align:right\">\n";
741 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
742 $display.= " \n";
743 if ($this->dn != "new"){
744 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
745 $display.= " \n";
746 }
747 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
748 $display.= "</p>";
749 }
750 }
751 return ($display);
752 }
754 /* Check if there is a snapshot dialog open */
755 $base = $this->DivListUsers->selectedBase;
756 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
757 return($str);
758 }
760 /* Return rendered main page */
761 /* Display dialog with system list */
762 $this->DivListUsers->parent = $this;
763 $this->DivListUsers->execute();
765 /* Add departments if subsearch is disabled */
766 if(!$this->DivListUsers->SubSearch){
767 $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4,1);
768 }
769 $this->reload();
770 $this->DivListUsers->setEntries($this->list);
771 return($this->DivListUsers->Draw());
772 }
775 /* Return departments, that will be included within snapshot detection */
776 function get_used_snapshot_bases()
777 {
778 return(array(get_people_ou().$this->DivListUsers->selectedBase));
779 }
782 function reload()
783 {
784 /* Set base for all searches */
785 $base= $this->DivListUsers->selectedBase;
786 $this->list =array();
788 /* Get filter configuration */
789 $Regex = $this->DivListUsers->Regex;
790 $SubSearch = $this->DivListUsers->SubSearch;
791 $ShowTemplates = $this->DivListUsers->ShowTemplates;
792 $ShowFunctionalUsers = $this->DivListUsers->ShowFunctionalUsers;
793 $ShowUnixUsers = $this->DivListUsers->ShowUnixUsers;
794 $ShowMailUsers = $this->DivListUsers->ShowMailUsers;
795 $ShowSambaUsers = $this->DivListUsers->ShowSambaUsers;
796 $ShowProxyUsers = $this->DivListUsers->ShowProxyUsers;
798 /* Setup filter depending on selection */
799 $filter="";
800 if ($this->config->current['SAMBAVERSION'] == 3){
801 $samba= "sambaSamAccount";
802 } else {
803 $samba= "sambaAccount";
804 }
806 if ($ShowFunctionalUsers){
807 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
808 "(objectClass=gosaMailAccount)(objectClass=$samba)".
809 "(objectClass=gosaProxyAccount))))";
810 }
811 if ($ShowUnixUsers){
812 $filter.= "(objectClass=posixAccount)";
813 }
814 if ($ShowMailUsers){
815 $filter.= "(objectClass=gosaMailAccount)";
816 }
817 if ($ShowSambaUsers){
818 $filter.= "(objectClass=$samba)";
819 }
820 if ($ShowProxyUsers){
821 $filter.= "(objectClass=gosaProxyAccount)";
822 }
823 if ($ShowTemplates){
824 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
825 } else {
826 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
827 }
828 $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
830 /* Generate userlist */
831 $ldap= $this->config->get_ldap_link(TRUE);
833 if ($SubSearch){
834 $ListTemp = get_list($filter, "users", $base,
835 array("uid", "givenName", "sn", "objectClass"), GL_SUBSEARCH | GL_SIZELIMIT);
836 } else {
837 $base= get_people_ou().$base;
838 $ListTemp = get_list($filter, "users", $base,
839 array("uid", "givenName", "sn", "objectClass"), GL_SIZELIMIT);
840 }
841 $SortTemp = array();
842 $List = array();
843 foreach($ListTemp as $Key => $Entry){
845 /* Skip entries that are not located under the people ou (normaly 'ou=people,')
846 * Else winstations will be listed too, if you use the subtree flag.
847 */
848 if(!preg_match("/".normalizePreg(get_people_ou())."/i",$Entry['dn'])){
849 continue;
850 }else{
852 // Generate caption for rows
853 if (isset($Entry["sn"]) && isset($Entry["givenName"])){
854 $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
855 } else {
856 $display= "[".$Entry["uid"][0]."]";
857 }
859 $display = strtolower($display);
860 $List[$display] = $Entry;
861 $SortTemp[$display] = $display;
862 }
863 }
864 sort($SortTemp);
865 reset($SortTemp);
867 $this->list = array();
868 foreach($SortTemp as $Key){
869 $this->list[] = $List[$Key];
870 }
871 }
873 function remove_lock()
874 {
875 /* Remove user lock if a DN is marked as "currently edited" */
876 if (isset($this->usertab->dn)){
877 del_lock ($this->usertab->dn);
878 }
879 }
882 function copyPasteHandling_from_queue($s_action,$s_entry)
883 {
884 /* Check if Copy & Paste is disabled */
885 if(!is_object($this->CopyPasteHandler)){
886 return("");
887 }
889 /* Add a single entry to queue */
890 if($s_action == "cut" || $s_action == "copy"){
891 /* Cleanup object queue */
892 $this->CopyPasteHandler->cleanup_queue();
893 $dn = $this->list[$s_entry]['dn'];
894 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"usertabs","USERTABS","users");
895 }
897 /* Add entries to queue */
898 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
900 /* Cleanup object queue */
901 $this->CopyPasteHandler->cleanup_queue();
903 /* Add new entries to CP queue */
904 foreach($this->list_get_selected_items() as $id){
905 $dn = $this->list[$id]['dn'];
907 if($s_action == "copy_multiple"){
908 $this->CopyPasteHandler->add_to_queue($dn,"copy","usertabs","USERTABS","users");
909 }
910 if($s_action == "cut_multiple"){
911 $this->CopyPasteHandler->add_to_queue($dn,"cut","usertabs","USERTABS","users");
912 }
913 }
914 }
916 /* Start pasting entries */
917 if($s_action == "editPaste"){
918 $this->start_pasting_copied_objects = TRUE;
919 }
921 /* Return C&P dialog */
922 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
924 /* Load entry from queue and set base */
925 $this->CopyPasteHandler->load_entry_from_queue();
926 $this->CopyPasteHandler->SetVar("base",$this->DivListUsers->selectedBase);
928 /* Get dialog */
929 $data = $this->CopyPasteHandler->execute();
931 /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
932 if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
933 $s_entry = $this->CopyPasteHandler->last_entry();
934 $this->reload();
935 foreach($this->list as $key => $entry){
936 if($entry['dn'] == $s_entry){
937 $this->CPPasswordChange = $key;
938 }
939 }
940 }
942 /* Return dialog data */
943 if(!empty($data) && $this->CPPasswordChange == ""){
944 return($data);
945 }
946 }
948 /* Automatically disable status for pasting */
949 if(!$this->CopyPasteHandler->entries_queued()){
950 $this->start_pasting_copied_objects = FALSE;
951 }
952 return("");
953 }
956 function save_object()
957 {
958 /* Handle divlist filter && department selection*/
959 if(!is_object($this->usertab)){
960 $this->DivListUsers->save_object();
961 }
962 }
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 }
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 ?>