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_user/");
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_user",
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 }
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 foreach($ids as $id){
299 $dn = $this->list[$id]['dn'];
300 if (($user= get_lock($dn)) != ""){
301 return(gen_locked_message ($user, $dn));
302 }
303 $this->dns[$id] = $dn;
304 }
306 $dns_names = "<br><pre>";
307 foreach($this->dns as $dn){
308 add_lock ($dn, $this->ui->dn);
309 $dns_names .= $dn."\n";
310 }
311 $dns_names .="</pre>";
313 /* Lock the current entry, so nobody will edit it during deletion */
314 $smarty->assign("info", sprintf(_("You're about to delete the following user(s) %s"), @LDAP::fix($dns_names)));
315 $smarty->assign("multiple", true);
316 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
317 }
320 /********************
321 Delete MULTIPLE entries confirmed
322 ********************/
324 /* Confirmation for deletion has been passed. Users should be deleted. */
325 if (isset($_POST['delete_multiple_user_confirm'])){
327 /* Remove user by user and check acls before removeing them */
328 foreach($this->dns as $key => $dn){
330 $acl = $this->ui->get_permissions($dn, "users/user");
331 if (preg_match('/d/', $acl)){
333 /* Delete request is permitted, perform LDAP action */
334 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn);
335 $this->usertab->set_acl_base();
336 $this->usertab->delete ();
337 gosa_log ("User object '".$dn."' has been removed");
338 unset ($this->usertab);
339 $this->usertab= NULL;
340 } else {
341 print_red (sprintf(_("You are not allowed to delete the user '%s'!"),$dn));
342 if(isset($this->ui->uid)){
343 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
344 }
345 }
346 /* Remove lock file after successfull deletion */
347 del_lock ($dn);
348 unset($this->dns[$key]);
349 }
350 }
353 /********************
354 Delete MULTIPLE entries Canceled
355 ********************/
357 /* Remove lock */
358 if(isset($_POST['delete_multiple_user_cancel'])){
359 foreach($this->dns as $key => $dn){
360 del_lock ($dn);
361 unset($this->dns[$key]);
362 }
363 }
366 /********************
367 Delete entry requested, display confirm dialog
368 ********************/
370 /* Remove user was requested */
371 if ($s_action=="del"){
373 /* Get 'dn' from posted 'uid' */
374 $this->dn= $this->list[trim($s_entry)]['dn'];
376 /* Load permissions for selected 'dn' and check if
377 we're allowed to remove this 'dn' */
379 /* Check locking, save current plugin in 'back_plugin', so
380 the dialog knows where to return. */
381 if (($user= get_lock($this->dn)) != ""){
382 return(gen_locked_message ($user, $this->dn));
383 }
385 /* Lock the current entry, so nobody will edit it during deletion */
386 add_lock ($this->dn, $this->ui->dn);
387 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
388 $smarty->assign("multiple", false);
389 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
390 }
393 /********************
394 Delete entry confirmed
395 ********************/
397 /* Confirmation for deletion has been passed. User should be deleted. */
398 if (isset($_POST['delete_user_confirm'])){
400 /* Some nice guy may send this as POST, so we've to check
401 for the permissions again. */
403 $acl = $this->ui->get_permissions($this->dn, "users/user");
405 if (preg_match('/d/', $acl)){
407 /* Delete request is permitted, perform LDAP action */
408 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
409 $this->usertab->set_acl_base();
410 $this->usertab->delete ();
411 gosa_log ("User object '".$this->dn."' has been removed");
412 unset ($this->usertab);
413 $this->usertab= NULL;
414 } else {
416 /* Normally this shouldn't be reached, send some extra
417 logs to notify the administrator */
418 print_red (_("You are not allowed to delete this user!"));
420 if(isset($this->ui->uid)){
421 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
422 }
423 }
425 /* Remove lock file after successfull deletion */
426 del_lock ($this->dn);
427 }
430 /********************
431 Delete entry Canceled
432 ********************/
434 /* Delete user canceled? */
435 if (isset($_POST['delete_cancel'])){
436 del_lock ($this->dn);
437 }
440 /********************
441 Edit entry finished (Save)
442 ********************/
444 /* Finish user edit is triggered by the tabulator dialog, so
445 the user wants to save edited data. Check and save at this
446 point. */
447 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
449 /* Check tabs, will feed message array */
450 $this->usertab->last= $this->usertab->current;
451 $this->usertab->save_object();
452 $message= $this->usertab->check();
454 /* Save, or display error message? */
455 if (count($message) == 0){
457 /* No errors. Go ahead and prepare to ask for a password
458 in case we're creating a new user. 'dn' will be 'new'
459 in this case. It is set to the correct value later. */
460 if ($this->dn == "new"){
461 $set_pass= 1;
462 } else {
463 $set_pass= 0;
464 }
466 /* Save user data to ldap */
467 if($this->usertab->save() == 1){
468 gosa_log ("User object '".$this->dn."' saving failed.");
469 return;
470 }
471 gosa_log ("User object '".$this->dn."' has been saved");
473 if (!isset($_POST['edit_apply'])){
474 /* User has been saved successfully, remove lock from LDAP. */
475 if ($this->dn != "new"){
476 del_lock ($this->dn);
477 }
479 /* In case of new users, ask for a password, skip this for templates */
480 if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
481 $this->dn = $this->usertab->dn;
482 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
483 }
485 unset ($this->usertab);
486 $this->usertab= NULL;
487 unset ($_SESSION['objectinfo']);
488 }
489 } else {
490 /* Ok. There seem to be errors regarding to the tab data,
491 show message and continue as usual. */
492 show_errors($message);
493 }
494 }
497 /********************
498 We want to create a new user, so fetch all available user templates
499 ********************/
501 /* Generate template list */
502 if (($s_action=="new")||($s_action=="create_user_from_tpl")){
504 $this->templates= array();
505 $ldap= $this->config->get_ldap_link();
507 /* Create list of templates */
508 foreach ($this->config->departments as $key => $value){
510 /* Get acls from different ou's */
511 $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user") ;
513 /* If creation of a new user is allowed, append this template */
514 if (preg_match("/c/",$acl)){
516 /* Search all templates from the current dn */
517 $ldap->cd (get_people_ou().$value);
518 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
520 /* Append */
521 if ($ldap->count() != 0){
522 while ($attrs= $ldap->fetch()){
523 $this->templates[$ldap->getDN()]=
524 $attrs['uid'][0]." - ".@LDAP::fix($key);
525 }
526 $this->templates['none']= _("none");
527 }
528 }
529 }
531 /* Sort templates */
532 natcasesort ($this->templates);
533 reset ($this->templates);
534 }
537 /********************
538 Create a new user,template, user from template
539 ********************/
541 /* Check selected options for template */
542 if (isset($_POST['template_continue'])){
543 $message = array();
544 if(!isset($_POST['template']) || (empty($_POST['template']))){
545 $message[] = _("Please select a valid template.");
546 }
547 if(!isset($_POST['sn']) || (empty($_POST['sn']))){
548 $message[]= _("The required field 'Name' is not set.");
549 }
550 if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
551 $message[]= _("The required field 'Given name' is not set.");
552 }
554 /* Show error message / continue editing */
555 if (count($message) > 0){
556 show_errors ($message);
558 foreach(array("sn", "givenName", "uid", "template") as $attr){
559 if(isset($_POST[$attr])){
560 $smarty->assign("$attr", $_POST[$attr]);
561 }else{
562 $smarty->assign("$attr", "");
563 }
564 }
565 $smarty->assign("templates",$this->templates);
566 $smarty->assign("got_uid",$this->got_uid);
567 $smarty->assign("edit_uid",false);
568 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
570 }
571 }
573 /* New user/template request */
574 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
575 /* By default we set 'dn' to 'new', all relevant plugins will
576 react on this. */
577 $this->dn= "new";
579 if (isset($this->config->current['IDGEN'])){
580 $this->got_uid= false;
581 } else {
582 $this->got_uid= true;
583 }
585 /* Create new usertab object */
586 $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
587 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
588 $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
590 /* Take care about templates */
591 if ($s_action=="new_tpl"){
592 $this->is_template= TRUE;
593 $this->usertab->set_template_mode ();
594 } else {
595 $this->is_template= FALSE;
596 }
598 /* Use template if there are any of them */
599 if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
600 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
601 $smarty->assign("$attr", $this->$attr);
602 }
603 if ($s_action=="create_user_from_tpl"){
604 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
605 } else {
606 $smarty->assign("template", "none");
607 }
608 $smarty->assign("edit_uid", "");
609 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
610 }
611 }
613 /********************
614 Template selected continue edit
615 ********************/
617 /* Continue template editing */
618 if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
620 $this->sn = $_POST['sn'];
621 $this->givenName = $_POST['givenName'];
623 /* Check for requred values */
624 $message= array();
625 if ($this->sn == "") {
626 $message[]= _("The required field 'Name' is not set.");
627 }
628 if ($this->givenName == "") {
629 $message[]= _("The required field 'Given name' is not set.");
630 }
632 /* Check if dn is used */
633 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
634 $ldap= $this->config->get_ldap_link();
635 $ldap->cd ($dn);
636 $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
637 if ($ldap->count () != 0){
638 $message[]= _("A person with the choosen name is already used in this tree.");
639 }
641 /* Show error message / continue editing */
642 if (count($message) > 0){
643 show_errors ($message);
644 } else {
645 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
646 if (isset($this->config->current['IDGEN']) &&
647 $this->config->current['IDGEN'] != ""){
648 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
649 if (count($uids)){
650 $smarty->assign("edit_uid", "false");
651 $smarty->assign("uids", $uids);
652 $this->uid= current($uids);
653 }
654 } else {
655 $smarty->assign("edit_uid", "");
656 $this->uid= "";
657 }
658 $this->got_uid= true;
659 }
661 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
662 $smarty->assign("$attr", $this->$attr);
663 }
664 if (isset($_POST['template'])){
665 $smarty->assign("template", $_POST['template']);
666 }
667 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
668 }
670 /********************
671 No template selected continue edit
672 ********************/
674 /* No template. Ok. Lets fill data into the normal user dialog */
675 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
676 foreach(array("sn", "givenName", "uid") as $attr){
677 if (isset($_POST[$attr])){
678 $this->usertab->by_object['user']->$attr= $_POST[$attr];
679 }
680 }
681 }
684 /********************
685 Template selected continue edit
686 ********************/
688 /* Finish template preamble */
689 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
691 /* Might not be filled if IDGEN is unset */
692 $this->sn = $_POST['sn'];
693 $this->givenName = $_POST['givenName'];
695 /* Move user supplied data to sub plugins */
696 $this->uid = $_POST['uid'];
697 $this->usertab->uid = $this->uid;
698 $this->usertab->sn = $this->sn;
699 $this->usertab->givenName = $this->givenName;
700 $template_dn = $_POST['template'];
701 $this->usertab->adapt_from_template($template_dn);
702 $template_base = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
703 $this->usertab->by_object['user']->base= $template_base;
704 }
707 /********************
708 If no template was selected set base
709 ********************/
711 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
712 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
713 }
716 /********************
717 Display subdialog
718 ********************/
720 /* Show tab dialog if object is present */
721 if(isset($this->usertab->config)){
722 $display= $this->usertab->execute();
724 /* Don't show buttons if tab dialog requests this */
725 if(isset($this->usertab->by_object)){
726 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
727 $display.= "<p style=\"text-align:right\">\n";
728 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
729 $display.= " \n";
730 if ($this->dn != "new"){
731 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
732 $display.= " \n";
733 }
734 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
735 $display.= "</p>";
736 }
737 }
738 return ($display);
739 }
741 /* Check if there is a snapshot dialog open */
742 $base = $this->DivListUsers->selectedBase;
743 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
744 return($str);
745 }
747 /* Return rendered main page */
748 /* Display dialog with system list */
749 $this->DivListUsers->parent = $this;
750 $this->DivListUsers->execute();
752 /* Add departments if subsearch is disabled */
753 if(!$this->DivListUsers->SubSearch){
754 $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4,1);
755 }
756 $this->reload();
757 $this->DivListUsers->setEntries($this->list);
758 return($this->DivListUsers->Draw());
759 }
762 /* Return departments, that will be included within snapshot detection */
763 function get_used_snapshot_bases()
764 {
765 return(array(get_people_ou().$this->DivListUsers->selectedBase));
766 }
769 function reload()
770 {
771 /* Set base for all searches */
772 $base= $this->DivListUsers->selectedBase;
773 $this->list =array();
775 /* Get filter configuration */
776 $Regex = $this->DivListUsers->Regex;
777 $SubSearch = $this->DivListUsers->SubSearch;
778 $ShowTemplates = $this->DivListUsers->ShowTemplates;
779 $ShowFunctionalUsers = $this->DivListUsers->ShowFunctionalUsers;
780 $ShowUnixUsers = $this->DivListUsers->ShowUnixUsers;
781 $ShowMailUsers = $this->DivListUsers->ShowMailUsers;
782 $ShowSambaUsers = $this->DivListUsers->ShowSambaUsers;
783 $ShowProxyUsers = $this->DivListUsers->ShowProxyUsers;
785 /* Setup filter depending on selection */
786 $filter="";
787 if ($this->config->current['SAMBAVERSION'] == 3){
788 $samba= "sambaSamAccount";
789 } else {
790 $samba= "sambaAccount";
791 }
793 if ($ShowFunctionalUsers){
794 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
795 "(objectClass=gosaMailAccount)(objectClass=$samba)".
796 "(objectClass=gosaProxyAccount))))";
797 }
798 if ($ShowUnixUsers){
799 $filter.= "(objectClass=posixAccount)";
800 }
801 if ($ShowMailUsers){
802 $filter.= "(objectClass=gosaMailAccount)";
803 }
804 if ($ShowSambaUsers){
805 $filter.= "(objectClass=$samba)";
806 }
807 if ($ShowProxyUsers){
808 $filter.= "(objectClass=gosaProxyAccount)";
809 }
810 if ($ShowTemplates){
811 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
812 } else {
813 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
814 }
815 $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
817 /* Generate userlist */
818 $ldap= $this->config->get_ldap_link(TRUE);
820 if ($SubSearch){
821 $ListTemp = get_list($filter, "users", $base,
822 array("uid", "givenName", "sn", "objectClass"), GL_SUBSEARCH | GL_SIZELIMIT);
823 } else {
824 $base= get_people_ou().$base;
825 $ListTemp = get_list($filter, "users", $base,
826 array("uid", "givenName", "sn", "objectClass"), GL_SIZELIMIT);
827 }
828 $SortTemp = array();
829 $List = array();
830 foreach($ListTemp as $Key => $Entry){
832 /* Skip entries that are not located under the people ou (normaly 'ou=people,')
833 * Else winstations will be listed too, if you use the subtree flag.
834 */
835 if(!preg_match("/".normalizePreg(get_people_ou())."/i",$Entry['dn'])){
836 continue;
837 }else{
839 // Generate caption for rows
840 if (isset($Entry["sn"]) && isset($Entry["givenName"])){
841 $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
842 } else {
843 $display= "[".$Entry["uid"][0]."]";
844 }
846 $display = strtolower($display);
847 $List[$display] = $Entry;
848 $SortTemp[$display] = $display;
849 }
850 }
851 sort($SortTemp);
852 reset($SortTemp);
854 $this->list = array();
855 foreach($SortTemp as $Key){
856 $this->list[] = $List[$Key];
857 }
858 }
860 function remove_lock()
861 {
862 /* Remove user lock if a DN is marked as "currently edited" */
863 if (isset($this->usertab->dn)){
864 del_lock ($this->usertab->dn);
865 }
866 }
869 /* Perform copy & paste requests
870 If copy&paste is in progress this returns a dialog to fix required attributes
871 */
872 function copyPasteHandling($s_action,$s_entry)
873 {
874 /* Only perform copy/paste if it is enabled */
875 if($this->CopyPasteHandler){
877 /* Prepare current object to be pasted */
878 if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){
880 $this->CopyPasteHandler->save_object();
881 $this->CopyPasteHandler->SetVar("base", $this->DivListUsers->selectedBase);
883 /* Execute copy & paste dialog and display returned data, normaly a dialog which allows
884 us to solve all attribute mismatches for this object.
885 If nothing is returned, copy & paste was succesfully or aborted */
886 if(($ret= $this->CopyPasteHandler->execute())){
887 return ($ret);
888 }
890 /* Use the last dn to search for it's ID in the newly generated list. */
891 $dn= $this->CopyPasteHandler->lastdn;
893 /* Get new user list */
894 $this->reload();
895 foreach($this->list as $id => $entry){
896 if($entry['dn'] == $dn){
897 $s_entry= $id;
898 break;
899 }
900 }
902 /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
903 if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
904 $this->CPPasswordChange = $s_entry;
905 }
906 }
908 /* Copy selected object
909 Create a new empty object and the current selected object.
910 Send both to copy&paste class*/
911 if($s_action == "copy"){
912 $this->CopyPasteHandler->Clear();
913 $dn= $this->list[trim($s_entry)]['dn'];
915 /* Check acl */
916 $ui = get_userinfo();
917 $acl_all = $ui->has_complete_category_acls($this->DivListUsers->selectedBase,"users") ;
918 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
919 $obj = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
920 $obj->set_acl_base($dn);
921 $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new");
922 $objNew->set_acl_base($dn);
924 $this->CopyPasteHandler->Copy($obj,$objNew);
925 }else{
926 print_red("You are not allowed to copy this entry.");
927 }
928 }
930 /* Cut selected object.
931 Open user object and send it to the copy & paste handler */
932 if($s_action == "cut"){
933 $this->CopyPasteHandler->Clear();
934 $dn= $this->list[trim($s_entry)]['dn'];
936 /* Check acl */
937 $acl_all = $ui->has_complete_category_acls($this->DivListUsers->selectedBase,"users") ;
938 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
939 $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
940 $obj->set_acl_base($dn);
941 $this->CopyPasteHandler->Cut($obj);
942 }else{
943 print_red("You are not allowed to cut this entry.");
944 }
945 }
946 }
947 }
949 function save_object()
950 {
951 /* Handle divlist filter && department selection*/
952 if(!is_object($this->usertab)){
953 $this->DivListUsers->save_object();
954 }
955 }
958 function list_get_selected_items()
959 {
960 $ids = array();
961 foreach($_POST as $name => $value){
962 if(preg_match("/^item_selected_[0-9]*$/",$name)){
963 $id = preg_replace("/^item_selected_/","",$name);
964 $ids[$id] = $id;
965 }
966 }
967 return($ids);
968 }
971 /* A set of disabled and therefore overloaded functions. They are
972 not needed in this class. */
973 function remove_from_parent() { }
974 function check() { }
975 function save() { }
976 function adapt_from_template($dn) { }
977 function password_change_needed() { }
979 } /* ... class userManagement */
980 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
981 ?>