4a4ec5aea60a54cefaf2e1503f7e79d9e5184ae5
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 $pwd_change_queue = array();
42 var $start_pasting_copied_objects = FALSE;
44 var $msg_dialog= NULL;
46 function userManagement(&$config, $ui)
47 {
48 /* Save configuration for internal use */
49 $this->config= &$config;
50 $this->ui= &$ui;
52 /* Copy & Paste handler */
53 if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
54 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
55 }
57 /* Creat dialog object */
58 $this->DivListUsers = new divListUsers($this->config,$this);
60 }
63 function execute()
64 {
65 /* Call parent execute */
66 plugin::execute();
68 /* LOCK MESSAGE Vars */
69 $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/","/^item_selected/","/^remove_multiple_users/");
71 $smarty = get_smarty(); // Smarty instance
72 $s_action = ""; // Contains the action to be taken
73 $s_entry = ""; // The value for s_action
75 /* Edit entry button pressed? */
76 if( isset($_GET['act']) && $_GET['act'] == "edit_entry" ){
77 $s_action= "edit";
78 $s_entry= validate($_GET['id']);
79 }
81 /* Test relevant POST values */
82 foreach($_POST as $key => $val){
84 /* Get every possible POST combination and set s_action/s_entry accordingly */
85 foreach(array("del" => "user_del", "edit" => "user_edit",
86 "new" => "user_new",
87 "new_tpl" => "user_tplnew",
88 "del_multiple" => "^remove_multiple_users",
89 "create_user_from_tpl" => "userfrom_tpl",
90 "change_pw" => "user_chgpw",
91 "editPaste" => "editPaste",
92 "copy_multiple" => "multiple_copy_users",
93 "cut_multiple" => "multiple_cut_users",
94 "multiple_password_change" => "multiple_password_change",
95 "copy" => "^copy",
96 "toggle_lock_status" => "toggle_lock_status",
97 "cut" => "^cut") as $act => $name){
99 if (preg_match("/".$name.".*/", $key)){
100 $s_action= $act;
101 $s_entry= preg_replace("/".$name."_/i", "", $key);
102 break;
103 }
104 }
106 } /* ...Test POST */
108 /* Remove coordinate prefix from POST, required by some browsers */
109 $s_entry= preg_replace("/_.$/", "", $s_entry);
111 /* Seperate possibly encoded tab and entry, default to tab "user" */
112 if(preg_match("/.*-.*/", $s_entry)){
113 $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
114 $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
115 }else{
116 $s_tab= "user";
117 }
119 if(!search_config($this->config->data['TABS'], $s_tab , "CLASS")){
120 $s_tab = "user";
121 }
124 /********************
125 Copy & Paste
126 ********************/
128 /* Display the copy & paste dialog, if it is currently open */
129 if($this->CPPasswordChange == ""){
130 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
131 if($ret){
132 return($ret);
133 }
134 }
137 /********************
138 Change password confirmed
139 ********************/
141 /* Perform password change */
142 if (isset($_POST['password_finish'])){
144 /* For security reasons, check if user is allowed to set password again */
145 $dn = $this->dn;
146 $acl = $this->ui->get_permissions($dn, "users/password");
147 $cacl= $this->ui->get_permissions($dn, "users/user");
149 if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
151 /* Check input and feed errors into 'message' */
152 $message= array();
154 /* Sanity checks... */
155 if ($_POST['new_password'] != $_POST['repeated_password']){
157 /* Matching passwords in new and repeated? */
158 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
159 } else {
161 /* Empty password is not permitted by default. */
162 if ($_POST['new_password'] == ""){
163 $message[]= _("The password you've entered as 'New password' is empty.");
164 }
165 }
167 /* Errors, or password change? */
168 if (count($message) != 0){
170 /* Show error message and continue editing */
171 show_errors ($message);
172 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
173 }
175 $config= $this->config;
176 $ldap_ui= $this->config->get_ldap_link();
177 if(isset($this->usertab->dn)){
178 $ldap_ui->cat($this->usertab->dn,array("uid"));
179 $user = $ldap_ui->fetch();
180 }else{
181 $ldap_ui->cat($this->dn,array("uid"));
182 $user = $ldap_ui->fetch();
183 }
184 if((is_array($user))&&(isset($user['uid']))){
185 $username= $user['uid'][0];
186 }
188 /* Set password, perform required steps */
189 if ($this->usertab){
190 if ($this->usertab->password_change_needed()){
191 $obj= $this->usertab->by_object['user'];
192 change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
193 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
194 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
195 }
196 new log("modify","users/".get_class($this),$this->usertab->dn,array(),"Password has been changed");
197 unset($this->usertab);
198 $this->usertab= NULL;
199 }
200 } else {
201 change_password ($this->dn, $_POST['new_password']);
202 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
203 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
204 }
205 new log("modify","users/".get_class($this),$this->dn,array(),"Password has been changed");
206 }
207 } else {
209 /* Missing permissions, show message */
210 print_red (_("You are not allowed to set this users password!"));
211 }
212 /* Clean session, delete lock */
213 del_lock ($this->dn);
214 unset ($this->usertab);
215 $this->usertab= NULL;
216 $this->lognames= array();;
217 $this->sn= "";
218 $this->givenName= "";
219 $this->uid= "";
220 unset ($_SESSION['objectinfo']);
221 }
224 /********************
225 Change multiple passwords requested
226 ********************/
228 if($s_action == "multiple_password_change"){
229 $this->pwd_change_queue = $this->list_get_selected_items();
230 }
233 /********************
234 Change password requested
235 ********************/
237 /* Password change requested */
238 if (($s_action == "change_pw") || (!empty($this->CPPasswordChange)) || count($this->pwd_change_queue)){
240 /* Get users whose passwords should be changed. */
241 if(count($this->pwd_change_queue)){
242 $s_entry= array_pop($this->pwd_change_queue);
243 }
245 if(!empty($this->CPPasswordChange)){
246 $s_entry = $this->CPPasswordChange;
247 $this->CPPasswordChange = "";
248 }
250 /* Get 'dn' from posted 'uid' */
251 $this->dn= $this->list[trim($s_entry)]['dn'];
253 /* Load permissions for selected 'dn' and check if
254 we're allowed to remove this 'dn' */
255 if (preg_match("/w/",$this->ui->get_permissions($this->dn,"users/password"))){
257 /* User is allowed to change passwords, save 'dn' and 'acl' for next
258 dialog. */
259 $_SESSION['objectinfo']= $this->dn;
260 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
262 } else {
263 /* User is not allowed. Show message and cancel. */
264 print_red (_("You are not allowed to set this users password!"));
265 }
266 }
271 /********************
272 Edit existing entry
273 ********************/
275 /* User wants to edit data? */
276 if (($s_action=="edit") && (!isset($this->usertab->config))){
278 /* Get 'dn' from posted 'uid', must be unique */
279 $this->dn= $this->list[trim($s_entry)]['dn'];
281 /* Check locking, save current plugin in 'back_plugin', so
282 the dialog knows where to return. */
283 if (($user= get_lock($this->dn)) != ""){
284 return(gen_locked_message ($user, $this->dn));
285 }
287 /* Lock the current entry, so everyone will get the
288 above dialog */
289 add_lock ($this->dn, $this->ui->dn);
291 /* Register usertab to trigger edit dialog */
292 $this->usertab= new usertabs($this->config,
293 $this->config->data['TABS']['USERTABS'], $this->dn);
295 /* Switch tab, if it was requested by the user */
296 $this->usertab->current = $s_tab;
298 /* Set ACL and move DN to the headline */
299 $this->usertab->set_acl_base($this->dn);
300 $_SESSION['objectinfo']= $this->dn;
301 }
304 /********************
305 Edit canceled
306 ********************/
308 /* Reset all relevant data, if we get a _cancel request */
309 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
310 if (isset($this->usertab)){
311 del_lock ($this->usertab->dn);
312 unset ($this->usertab);
313 }
314 $this->usertab= NULL;
315 $this->lognames= array();;
316 $this->sn= "";
317 $this->givenName= "";
318 $this->uid= "";
319 unset ($_SESSION['objectinfo']);
320 }
323 /********************
324 Delete MULTIPLE entries requested, display confirm dialog
325 ********************/
327 if ($s_action=="del_multiple"){
328 $ids = $this->list_get_selected_items();
330 if(count($ids)){
332 foreach($ids as $id){
333 $dn = $this->list[$id]['dn'];
334 if (($user= get_lock($dn)) != ""){
335 return(gen_locked_message ($user, $dn));
336 }
337 $this->dns[$id] = $dn;
338 }
340 $dns_names = "<br><pre>";
341 foreach($this->dns as $dn){
342 add_lock ($dn, $this->ui->dn);
343 $dns_names .= $dn."\n";
344 }
345 $dns_names .="</pre>";
347 /* Lock the current entry, so nobody will edit it during deletion */
348 if (count($this->dns) == 1){
349 $smarty->assign("info", sprintf(_("You're about to delete the following entry: %s"), @LDAP::fix($dns_names)));
350 } else {
351 $smarty->assign("info", sprintf(_("You're about to delete the following entries: %s"), @LDAP::fix($dns_names)));
352 }
353 $smarty->assign("multiple", true);
354 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
355 }
356 }
359 /********************
360 Delete MULTIPLE entries confirmed
361 ********************/
363 /* Confirmation for deletion has been passed. Users should be deleted. */
364 if (isset($_POST['delete_multiple_user_confirm'])){
366 /* Remove user by user and check acls before removeing them */
367 foreach($this->dns as $key => $dn){
369 $acl = $this->ui->get_permissions($dn, "users/user");
370 if (preg_match('/d/', $acl)){
372 /* Delete request is permitted, perform LDAP action */
373 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn);
374 $this->usertab->set_acl_base();
375 $this->usertab->delete ();
376 unset ($this->usertab);
377 $this->usertab= NULL;
378 } else {
379 print_red (sprintf(_("You are not allowed to delete the user '%s'!"),$dn));
380 if(isset($this->ui->uid)){
381 new log("security","users/".get_class($this),$dn,array(),"Tried to trick deletion.");
382 }
383 }
384 /* Remove lock file after successfull deletion */
385 del_lock ($dn);
386 unset($this->dns[$key]);
387 }
388 }
391 /********************
392 Delete MULTIPLE entries Canceled
393 ********************/
395 /* Remove lock */
396 if(isset($_POST['delete_multiple_user_cancel'])){
397 foreach($this->dns as $key => $dn){
398 del_lock ($dn);
399 unset($this->dns[$key]);
400 }
401 }
404 /********************
405 Toggle lock status for user
406 ********************/
408 if($s_action == "toggle_lock_status" && isset($this->list[$s_entry])){
410 /* Get entry check current status */
411 $val = $this->list[$s_entry];
412 $pwd = $val['userPassword'][0];
414 if(!preg_match("/^\{[^\}]/",$pwd)){
415 trigger_error("Can not deactivate user which is using clear password encryption.");
416 }else{
418 $locked = false;
419 if(preg_match("/^[^\}]*+\}!/",$pwd)){
420 $locked = true;
421 }
423 /* Create ldap array to update status */
424 $attrs = array("userPassword" => $pwd);
425 if($locked){
426 $attrs['userPassword'] = preg_replace("/(^[^\}]+\})!(.*$)/","\\1\\2",$attrs['userPassword']);
427 }else{
428 $attrs['userPassword'] = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$attrs['userPassword']);
429 }
431 /* Write new status back to ldap */
432 $ldap = $this->config->get_ldap_link();
433 $ldap->cd($val['dn']);
434 $ldap->modify($attrs);
435 if($locked){
436 show_ldap_error($ldap->get_error(),_("Could not set user status from locked to unlocked."));
437 }else{
438 show_ldap_error($ldap->get_error(),_("Could not set user status from unlocked to locked."));
439 }
440 }
441 }
444 /********************
445 Delete entry requested, display confirm dialog
446 ********************/
448 /* Remove user was requested */
449 if ($s_action=="del"){
451 /* Get 'dn' from posted 'uid' */
452 $this->dn= $this->list[trim($s_entry)]['dn'];
454 /* Load permissions for selected 'dn' and check if
455 we're allowed to remove this 'dn' */
457 /* Check locking, save current plugin in 'back_plugin', so
458 the dialog knows where to return. */
459 if (($user= get_lock($this->dn)) != ""){
460 return(gen_locked_message ($user, $this->dn));
461 }
464 /* Lock the current entry, so nobody will edit it during deletion */
465 # add_lock ($this->dn, $this->ui->dn);
466 # $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
467 # $smarty->assign("multiple", false);
468 # return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
469 $this->msg_dialog = new msg_dialog(_("Delete user"),sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)),CONFIRM_DIALOG);
470 }
473 /********************
474 Delete entry confirmed
475 ********************/
477 /* Confirmation for deletion has been passed. User should be deleted. */
478 if (is_object($this->msg_dialog) && $this->msg_dialog->is_confirmed()){
480 /* Some nice guy may send this as POST, so we've to check
481 for the permissions again. */
483 $acl = $this->ui->get_permissions($this->dn, "users/user");
485 if (preg_match('/d/', $acl)){
487 /* Delete request is permitted, perform LDAP action */
488 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
489 $this->usertab->set_acl_base();
490 $this->usertab->delete ();
491 unset ($this->usertab);
492 $this->usertab= NULL;
493 msg_dialog::display(_("User delted"),_("User successfully removed."),INFO_DIALOG);
494 } else {
496 /* Normally this shouldn't be reached, send some extra
497 logs to notify the administrator */
498 print_red (_("You are not allowed to delete this user!"));
500 if(isset($this->ui->uid)){
501 new log("security","users/".get_class($this),$this->dn,array(),"Tried to trick deletion.");
502 }
503 }
505 /* Remove lock file after successfull deletion */
506 del_lock ($this->dn);
507 }
510 /********************
511 Delete entry Canceled
512 ********************/
514 /* Delete user canceled? */
515 if (isset($_POST['delete_cancel'])){
516 del_lock ($this->dn);
517 }
520 /********************
521 Edit entry finished (Save)
522 ********************/
524 /* Finish user edit is triggered by the tabulator dialog, so
525 the user wants to save edited data. Check and save at this
526 point. */
527 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
529 /* Check tabs, will feed message array */
530 $this->usertab->last= $this->usertab->current;
531 $this->usertab->save_object();
532 $message= $this->usertab->check();
534 /* Save, or display error message? */
535 if (count($message) == 0){
537 /* No errors. Go ahead and prepare to ask for a password
538 in case we're creating a new user. 'dn' will be 'new'
539 in this case. It is set to the correct value later. */
540 if ($this->dn == "new"){
541 $set_pass= 1;
542 } else {
543 $set_pass= 0;
544 }
546 /* Save user data to ldap */
547 if($this->usertab->save() == 1){
548 return;
549 }
551 if (!isset($_POST['edit_apply'])){
552 /* User has been saved successfully, remove lock from LDAP. */
553 if ($this->dn != "new"){
554 del_lock ($this->dn);
555 }
557 /* In case of new users, ask for a password, skip this for templates */
558 if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
559 $this->dn = $this->usertab->dn;
560 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
561 }
563 unset ($this->usertab);
564 $this->usertab= NULL;
565 unset ($_SESSION['objectinfo']);
566 }
567 } else {
568 /* Ok. There seem to be errors regarding to the tab data,
569 show message and continue as usual. */
570 show_errors($message);
571 }
572 }
575 /********************
576 We want to create a new user, so fetch all available user templates
577 ********************/
579 /* Generate template list */
580 if (($s_action=="new")||($s_action=="create_user_from_tpl")){
582 $this->templates= array();
583 $ldap= $this->config->get_ldap_link();
585 /* Create list of templates */
586 foreach ($this->config->departments as $key => $value){
588 /* Get acls from different ou's */
589 $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user") ;
591 /* If creation of a new user is allowed, append this template */
592 if (preg_match("/c/",$acl)){
594 /* Search all templates from the current dn */
595 $ldap->cd (get_people_ou().$value);
596 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
598 /* Append */
599 if ($ldap->count() != 0){
600 while ($attrs= $ldap->fetch()){
601 $this->templates[$ldap->getDN()]=
602 $attrs['uid'][0]." - ".@LDAP::fix($key);
603 }
604 $this->templates['none']= _("none");
605 }
606 }
607 }
609 /* Sort templates */
610 natcasesort ($this->templates);
611 reset ($this->templates);
612 }
615 /********************
616 Create a new user,template, user from template
617 ********************/
619 /* Check selected options for template */
620 if (isset($_POST['template_continue'])){
621 $message = array();
622 if(!isset($_POST['template']) || (empty($_POST['template']))){
623 $message[] = _("Please select a valid template.");
624 }
625 if(!isset($_POST['sn']) || (empty($_POST['sn']))){
626 $message[]= _("The required field 'Name' is not set.");
627 }
628 if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
629 $message[]= _("The required field 'Given name' is not set.");
630 }
632 /* Show error message / continue editing */
633 if (count($message) > 0){
634 show_errors ($message);
636 foreach(array("sn", "givenName", "uid", "template") as $attr){
637 if(isset($_POST[$attr])){
638 $smarty->assign("$attr", $_POST[$attr]);
639 }else{
640 $smarty->assign("$attr", "");
641 }
642 }
643 $smarty->assign("templates",$this->templates);
644 $smarty->assign("got_uid",$this->got_uid);
645 $smarty->assign("edit_uid",false);
646 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
648 }
649 }
651 /* New user/template request */
652 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
653 /* By default we set 'dn' to 'new', all relevant plugins will
654 react on this. */
655 $this->dn= "new";
657 if (isset($this->config->current['IDGEN'])){
658 $this->got_uid= false;
659 } else {
660 $this->got_uid= true;
661 }
663 /* Create new usertab object */
664 $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
665 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
666 $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
668 /* Take care about templates */
669 if ($s_action=="new_tpl"){
670 $this->is_template= TRUE;
671 $this->usertab->set_template_mode ();
672 } else {
673 $this->is_template= FALSE;
674 }
676 /* Use template if there are any of them */
677 if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
678 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
679 $smarty->assign("$attr", $this->$attr);
680 }
681 if ($s_action=="create_user_from_tpl"){
682 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
683 } else {
684 $smarty->assign("template", "none");
685 }
686 $smarty->assign("edit_uid", "");
687 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
688 }
689 }
691 /********************
692 Template selected continue edit
693 ********************/
695 /* Continue template editing */
696 if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
698 $this->sn = $_POST['sn'];
699 $this->givenName = $_POST['givenName'];
701 /* Check for requred values */
702 $message= array();
703 if ($this->sn == "") {
704 $message[]= _("The required field 'Name' is not set.");
705 }
706 if ($this->givenName == "") {
707 $message[]= _("The required field 'Given name' is not set.");
708 }
710 /* Check if dn is used */
711 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
712 $ldap= $this->config->get_ldap_link();
713 $ldap->cd ($dn);
714 $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
715 if ($ldap->count () != 0){
716 $message[]= _("A person with the choosen name is already used in this tree.");
717 }
719 /* Show error message / continue editing */
720 if (count($message) > 0){
721 show_errors ($message);
722 } else {
723 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
724 if (isset($this->config->current['IDGEN']) &&
725 $this->config->current['IDGEN'] != ""){
726 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
727 if (count($uids)){
728 $smarty->assign("edit_uid", "false");
729 $smarty->assign("uids", $uids);
730 $this->uid= current($uids);
731 }
732 } else {
733 $smarty->assign("edit_uid", "");
734 $this->uid= "";
735 }
736 $this->got_uid= true;
737 }
739 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
740 $smarty->assign("$attr", $this->$attr);
741 }
742 if (isset($_POST['template'])){
743 $smarty->assign("template", $_POST['template']);
744 }
745 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
746 }
748 /********************
749 No template selected continue edit
750 ********************/
752 /* No template. Ok. Lets fill data into the normal user dialog */
753 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
754 foreach(array("sn", "givenName", "uid") as $attr){
755 if (isset($_POST[$attr])){
756 $this->usertab->by_object['user']->$attr= $_POST[$attr];
757 }
758 }
759 }
762 /********************
763 Template selected continue edit
764 ********************/
766 /* Finish template preamble */
767 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
769 /* Might not be filled if IDGEN is unset */
770 $this->sn = $_POST['sn'];
771 $this->givenName = $_POST['givenName'];
773 /* Move user supplied data to sub plugins */
774 $this->uid = $_POST['uid'];
775 $this->usertab->uid = $this->uid;
776 $this->usertab->sn = $this->sn;
777 $this->usertab->givenName = $this->givenName;
778 $template_dn = $_POST['template'];
779 $this->usertab->adapt_from_template($template_dn);
780 $template_base = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
781 $this->usertab->by_object['user']->base= $template_base;
782 }
785 /********************
786 If no template was selected set base
787 ********************/
789 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
790 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
791 }
794 /********************
795 Display subdialog
796 ********************/
798 /* Show tab dialog if object is present */
799 if(isset($this->usertab->config)){
800 $display= $this->usertab->execute();
802 /* Don't show buttons if tab dialog requests this */
803 if(isset($this->usertab->by_object)){
804 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
805 $display.= "<p style=\"text-align:right\">\n";
806 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
807 $display.= " \n";
808 if ($this->dn != "new"){
809 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
810 $display.= " \n";
811 }
812 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
813 $display.= "</p>";
814 }
815 }
816 return ($display);
817 }
819 /* Check if there is a snapshot dialog open */
820 $base = $this->DivListUsers->selectedBase;
821 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
822 return($str);
823 }
825 /* Return rendered main page */
826 /* Display dialog with system list */
827 $this->DivListUsers->parent = $this;
828 $this->DivListUsers->execute();
830 /* Add departments if subsearch is disabled */
831 if(!$this->DivListUsers->SubSearch){
832 $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4,1);
833 }
834 $this->reload();
835 $this->DivListUsers->setEntries($this->list);
836 return($this->DivListUsers->Draw());
837 }
840 /* Return departments, that will be included within snapshot detection */
841 function get_used_snapshot_bases()
842 {
843 return(array(get_people_ou().$this->DivListUsers->selectedBase));
844 }
847 function reload()
848 {
849 /* Set base for all searches */
850 $base= $this->DivListUsers->selectedBase;
851 $this->list =array();
853 /* Get filter configuration */
854 $Regex = $this->DivListUsers->Regex;
855 $SubSearch = $this->DivListUsers->SubSearch;
856 $ShowTemplates = $this->DivListUsers->ShowTemplates;
857 $ShowFunctionalUsers = $this->DivListUsers->ShowFunctionalUsers;
858 $ShowUnixUsers = $this->DivListUsers->ShowUnixUsers;
859 $ShowMailUsers = $this->DivListUsers->ShowMailUsers;
860 $ShowSambaUsers = $this->DivListUsers->ShowSambaUsers;
861 $ShowProxyUsers = $this->DivListUsers->ShowProxyUsers;
863 /* Setup filter depending on selection */
864 $filter="";
865 if ($this->config->current['SAMBAVERSION'] == 3){
866 $samba= "sambaSamAccount";
867 } else {
868 $samba= "sambaAccount";
869 }
871 if ($ShowFunctionalUsers){
872 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
873 "(objectClass=gosaMailAccount)(objectClass=$samba)".
874 "(objectClass=gosaProxyAccount))))";
875 }
876 if ($ShowUnixUsers){
877 $filter.= "(objectClass=posixAccount)";
878 }
879 if ($ShowMailUsers){
880 $filter.= "(objectClass=gosaMailAccount)";
881 }
882 if ($ShowSambaUsers){
883 $filter.= "(objectClass=$samba)";
884 }
885 if ($ShowProxyUsers){
886 $filter.= "(objectClass=gosaProxyAccount)";
887 }
888 if ($ShowTemplates){
889 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
890 } else {
891 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
892 }
893 $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
895 /* Generate userlist */
896 $ldap= $this->config->get_ldap_link(TRUE);
898 if ($SubSearch){
899 $ListTemp = get_list($filter, "users", $base,
900 array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SUBSEARCH | GL_SIZELIMIT);
901 } else {
902 $base= get_people_ou().$base;
903 $ListTemp = get_list($filter, "users", $base,
904 array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SIZELIMIT);
905 }
906 $SortTemp = array();
907 $List = array();
908 foreach($ListTemp as $Key => $Entry){
910 /* Skip entries that are not located under the people ou (normaly 'ou=people,')
911 * Else winstations will be listed too, if you use the subtree flag.
912 */
913 if(!preg_match("/".normalizePreg(get_people_ou())."/i",$Entry['dn'])){
914 continue;
915 }else{
917 // Generate caption for rows
918 if (isset($Entry["sn"]) && isset($Entry["givenName"])){
919 $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
920 } else {
921 $display= "[".$Entry["uid"][0]."]";
922 }
924 $display = strtolower($display);
925 $List[$display] = $Entry;
926 $SortTemp[$display] = $display;
927 }
928 }
929 sort($SortTemp);
930 reset($SortTemp);
932 $this->list = array();
933 foreach($SortTemp as $Key){
934 $this->list[] = $List[$Key];
935 }
936 }
938 function remove_lock()
939 {
940 /* Remove user lock if a DN is marked as "currently edited" */
941 if (isset($this->usertab->dn)){
942 del_lock ($this->usertab->dn);
943 }
944 }
947 function copyPasteHandling_from_queue($s_action,$s_entry)
948 {
949 /* Check if Copy & Paste is disabled */
950 if(!is_object($this->CopyPasteHandler)){
951 return("");
952 }
954 /* Add a single entry to queue */
955 if($s_action == "cut" || $s_action == "copy"){
956 /* Cleanup object queue */
957 $this->CopyPasteHandler->cleanup_queue();
958 $dn = $this->list[$s_entry]['dn'];
959 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"usertabs","USERTABS","users");
960 }
962 /* Add entries to queue */
963 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
965 /* Cleanup object queue */
966 $this->CopyPasteHandler->cleanup_queue();
968 /* Add new entries to CP queue */
969 foreach($this->list_get_selected_items() as $id){
970 $dn = $this->list[$id]['dn'];
972 if($s_action == "copy_multiple"){
973 $this->CopyPasteHandler->add_to_queue($dn,"copy","usertabs","USERTABS","users");
974 }
975 if($s_action == "cut_multiple"){
976 $this->CopyPasteHandler->add_to_queue($dn,"cut","usertabs","USERTABS","users");
977 }
978 }
979 }
981 /* Start pasting entries */
982 if($s_action == "editPaste"){
983 $this->start_pasting_copied_objects = TRUE;
984 }
986 /* Return C&P dialog */
987 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
989 /* Load entry from queue and set base */
990 $this->CopyPasteHandler->load_entry_from_queue();
991 $this->CopyPasteHandler->SetVar("base",$this->DivListUsers->selectedBase);
993 /* Get dialog */
994 $data = $this->CopyPasteHandler->execute();
996 /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
997 if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
998 $s_entry = $this->CopyPasteHandler->last_entry();
999 $this->reload();
1000 foreach($this->list as $key => $entry){
1001 if($entry['dn'] == $s_entry){
1002 $this->CPPasswordChange = $key;
1003 }
1004 }
1005 }
1007 /* Return dialog data */
1008 if(!empty($data) && $this->CPPasswordChange == ""){
1009 return($data);
1010 }
1011 }
1013 /* Automatically disable status for pasting */
1014 if(!$this->CopyPasteHandler->entries_queued()){
1015 $this->start_pasting_copied_objects = FALSE;
1016 }
1017 return("");
1018 }
1021 function save_object()
1022 {
1023 /* Handle divlist filter && department selection*/
1024 if(!is_object($this->usertab)){
1025 $this->DivListUsers->save_object();
1026 }
1027 }
1030 function list_get_selected_items()
1031 {
1032 $ids = array();
1033 foreach($_POST as $name => $value){
1034 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1035 $id = preg_replace("/^item_selected_/","",$name);
1036 $ids[$id] = $id;
1037 }
1038 }
1039 return($ids);
1040 }
1043 /* A set of disabled and therefore overloaded functions. They are
1044 not needed in this class. */
1045 function remove_from_parent() { }
1046 function check() { }
1047 function save() { }
1048 function adapt_from_template($dn) { }
1049 function password_change_needed() { }
1051 } /* ... class userManagement */
1052 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1053 ?>