a031e89d9f783a2cbb19272ea867938b1bde2c65
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 class userManagement extends plugin
22 {
23 /* Plugin definitions */
24 var $plHeadline= "Users";
25 var $plDescription= "This does something";
27 /* Dialog attributes */
28 var $usertab = NULL;
29 var $ui = NULL;
30 var $templates = array();
31 var $got_uid = false;
32 var $CopyPasteHandler = NULL;
33 var $CPPasswordChange = ""; // Contains the entry id which should get a new password
34 var $DivListUsers;
36 var $pwd_change_queue = array();
38 var $start_pasting_copied_objects = FALSE;
39 var $current_action ="";
40 var $msg_dialog= NULL;
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/","/^multiple_edit/","/menu_action/");
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",
82 "edit" => "user_edit",
83 "new" => "user_new",
84 "new_tpl" => "user_tplnew",
85 "del_multiple" => "^remove_multiple_users",
86 "create_user_from_tpl" => "userfrom_tpl",
87 "change_pw" => "user_chgpw",
88 "editPaste" => "editPaste",
89 "copy_multiple" => "multiple_copy_users",
90 "multiple_edit" => "multiple_edit",
91 "cut_multiple" => "multiple_cut_users",
92 "multiple_password_change" => "multiple_password_change",
93 "copy" => "^copy",
94 "toggle_lock_status" => "toggle_lock_status",
95 "cut" => "^cut") as $act => $name){
97 if (preg_match("/".$name.".*/", $key)){
98 $s_action= $act;
99 $s_entry= preg_replace("/".$name."_/i", "", $key);
100 break;
101 }
102 }
104 } /* ...Test POST */
106 /* Remove coordinate prefix from POST, required by some browsers */
107 $s_entry= preg_replace("/_.$/", "", $s_entry);
109 /* Seperate possibly encoded tab and entry, default to tab "user" */
110 if(preg_match("/.*-.*/", $s_entry)){
111 $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
112 $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
113 }else{
114 $s_tab= "user";
115 }
117 if(!$this->config->search($s_tab, 'class',array('tabs'))){
118 $s_tab = "user";
119 }
122 /* handle C&P from layers menu */
123 if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){
124 $s_action = "copy_multiple";
125 }
126 if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){
127 $s_action = "cut_multiple";
128 }
129 if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){
130 $s_action = "editPaste";
131 }
133 /* Create options */
134 if(isset($_POST['menu_action']) && $_POST['menu_action'] == "user_new"){
135 $s_action = "new";
136 }
137 if(isset($_POST['menu_action']) && $_POST['menu_action'] == "user_tplnew"){
138 $s_action = "new_tpl";
139 }
140 if(isset($_POST['menu_action']) && $_POST['menu_action'] == "multiple_edit"){
141 $s_action = "multiple_edit";
142 }
144 /* handle remove from layers menu */
145 if(isset($_POST['menu_action']) && preg_match("/^multiple_password_change/",$_POST['menu_action'])){
146 $s_action = "multiple_password_change";
147 }
149 /* handle remove from layers menu */
150 if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){
151 $s_action = "del_multiple";
152 }
155 /********************
156 Copy & Paste
157 ********************/
159 /* Display the copy & paste dialog, if it is currently open */
160 if($this->CPPasswordChange == ""){
161 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
162 if($ret){
163 return($ret);
164 }
165 }
168 /********************
169 Change password confirmed
170 ********************/
172 /* Perform password change */
173 if (isset($_POST['password_finish'])){
175 /* For security reasons, check if user is allowed to set password again */
176 $dn = $this->dn;
177 $acl = $this->ui->get_permissions($dn, "users/password");
178 $cacl= $this->ui->get_permissions($dn, "users/user");
180 if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
182 /* Check input and feed errors into 'message' */
183 $message= array();
185 /* Sanity checks... */
186 if ($_POST['new_password'] != $_POST['repeated_password']){
188 /* Matching passwords in new and repeated? */
189 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
190 } else {
192 /* Empty password is not permitted by default. */
193 if ($_POST['new_password'] == ""){
194 $message[]= _("The password you've entered as 'New password' is empty.");
195 }
196 }
198 /* Errors, or password change? */
199 if (count($message) != 0){
201 /* Show error message and continue editing */
202 show_errors ($message);
203 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
204 }
206 $config= $this->config;
207 $ldap_ui= $this->config->get_ldap_link();
208 if(isset($this->usertab->dn)){
209 $ldap_ui->cat($this->usertab->dn,array("uid"));
210 $user = $ldap_ui->fetch();
211 }else{
212 $ldap_ui->cat($this->dn,array("uid"));
213 $user = $ldap_ui->fetch();
214 }
215 if((is_array($user))&&(isset($user['uid']))){
216 $username= $user['uid'][0];
217 }
219 /* Set password, perform required steps */
220 if ($this->usertab){
221 if ($this->usertab->password_change_needed()){
222 $obj= $this->usertab->by_object['user'];
223 change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
224 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
225 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
226 }
227 new log("modify","users/".get_class($this),$this->usertab->dn,array(),"Password has been changed");
228 unset($this->usertab);
229 $this->usertab= NULL;
230 }
231 } else {
232 change_password ($this->dn, $_POST['new_password']);
233 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
234 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
235 }
236 new log("modify","users/".get_class($this),$this->dn,array(),"Password has been changed");
237 }
238 } else {
240 /* Missing permissions, show message */
241 msg_dialog::display(_("Password change failed."),_("You are not allowed to set this users password!"),WARNING_DIALOG);
242 }
243 /* Clean session, delete lock */
244 del_lock ($this->dn);
245 unset ($this->usertab);
246 $this->usertab= NULL;
247 $this->lognames= array();;
248 $this->sn= "";
249 $this->givenName= "";
250 $this->uid= "";
251 unset ($_SESSION['objectinfo']);
252 }
255 /********************
256 Change multiple passwords requested
257 ********************/
259 if($s_action == "multiple_password_change"){
260 $this->pwd_change_queue = $this->list_get_selected_items();
261 }
264 /********************
265 Change password requested
266 ********************/
268 /* Password change requested */
269 if (($s_action == "change_pw") || (!empty($this->CPPasswordChange)) || count($this->pwd_change_queue)){
271 /* Get users whose passwords should be changed. */
272 if(count($this->pwd_change_queue)){
273 $s_entry= array_pop($this->pwd_change_queue);
274 }
276 if(!empty($this->CPPasswordChange)){
277 $s_entry = $this->CPPasswordChange;
278 $this->CPPasswordChange = "";
279 }
281 /* Get 'dn' from posted 'uid' */
282 $this->dn= $this->list[trim($s_entry)]['dn'];
284 /* Load permissions for selected 'dn' and check if
285 we're allowed to remove this 'dn' */
286 if (preg_match("/w/",$this->ui->get_permissions($this->dn,"users/password"))){
288 /* User is allowed to change passwords, save 'dn' and 'acl' for next
289 dialog. */
290 $_SESSION['objectinfo']= $this->dn;
291 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
294 } else {
295 /* User is not allowed. Show message and cancel. */
296 msg_dialog::display(_("Password change"),_("You are not allowed to set this users password!"),WARNING_DIALOG);
297 }
298 }
302 /********************
303 Edit existing entry
304 ********************/
306 /* User wants to edit data? */
307 if (($s_action=="edit") && (!isset($this->usertab->config))){
309 /* Get 'dn' from posted 'uid', must be unique */
310 $this->dn= $this->list[trim($s_entry)]['dn'];
312 /* Check locking, save current plugin in 'back_plugin', so
313 the dialog knows where to return. */
314 if (($user= get_lock($this->dn)) != ""){
315 return(gen_locked_message ($user, $this->dn));
316 }
318 /* Lock the current entry, so everyone will get the
319 above dialog */
320 add_lock ($this->dn, $this->ui->dn);
322 /* Register usertab to trigger edit dialog */
323 $this->usertab= new usertabs($this->config,
324 $this->config->data['TABS']['USERTABS'], $this->dn);
326 /* Switch tab, if it was requested by the user */
327 $this->usertab->current = $s_tab;
329 /* Set ACL and move DN to the headline */
330 $this->usertab->set_acl_base($this->dn);
331 $_SESSION['objectinfo']= $this->dn;
332 }
335 /********************
336 Edit multiple entries
337 ********************/
339 /* User wants to edit data? */
340 if ($s_action == "multiple_edit" && !isset($this->usertab->config)){
342 $this->dn = array();
343 foreach($this->list_get_selected_items() as $id){
344 $this->dn[] = $this->list[$id]['dn'];;
345 }
346 $tmp = new multi_plug($this->config,"usertabs",$this->config->data['TABS']['USERTABS'],
347 $this->dn,$this->DivListUsers->selectedBase,"user");
348 if ($tmp->entries_locked()){
349 return($tmp->display_lock_message());
350 }
351 $tmp->lock_entries($this->ui->dn);
352 if($tmp->multiple_available()){
353 $this->usertab = $tmp;
354 $this->usertab->set_active_tab($s_tab);
355 $_SESSION['objectinfo']= $this->usertab->get_object_info();
356 }
357 }
360 /********************
361 Edit canceled
362 ********************/
364 /* Reset all relevant data, if we get a _cancel request */
365 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
366 if (isset($this->usertab)){
367 del_lock ($this->usertab->dn);
368 unset ($this->usertab);
369 }
370 $this->usertab= NULL;
371 $this->lognames= array();;
372 $this->sn= "";
373 $this->givenName= "";
374 $this->uid= "";
375 unset ($_SESSION['objectinfo']);
376 }
379 /********************
380 Delete MULTIPLE entries requested, display confirm dialog
381 ********************/
383 if ($s_action=="del_multiple"){
384 $ids = $this->list_get_selected_items();
385 $this->dns = array();
386 if(count($ids)){
388 foreach($ids as $id){
389 $dn = $this->list[$id]['dn'];
390 if (($user= get_lock($dn)) != ""){
391 return(gen_locked_message ($user, $dn));
392 }
393 $this->dns[$id] = $dn;
394 }
396 $dns_names = "<br><pre>";
397 foreach($this->dns as $dn){
398 $dns_names .= $dn."\n";
399 }
400 $dns_names .="</pre>";
402 /* Lock the current entry, so nobody will edit it during deletion */
403 if (count($this->dns) == 1){
404 $info = sprintf(_("You're about to delete the following entry: %s"), @LDAP::fix($dns_names));
405 } else {
406 $info = sprintf(_("You're about to delete the following entries: %s"), @LDAP::fix($dns_names));
407 }
408 $this->msg_dialog = new msg_dialog(_("Delete users"),$info,CONFIRM_DIALOG);
409 $this->current_action = $s_action;
410 }
411 }
414 /********************
415 Delete MULTIPLE entries confirmed
416 ********************/
418 /* Confirmation for deletion has been passed. Users should be deleted. */
419 if ($this->current_action == "del_multiple" && is_object($this->msg_dialog) && $this->msg_dialog->is_confirmed()){
421 $this->current_action = "";
423 /* Remove user by user and check acls before removeing them */
424 foreach($this->dns as $key => $dn){
426 $acl = $this->ui->get_permissions($dn, "users/user");
427 if (preg_match('/d/', $acl)){
429 /* Delete request is permitted, perform LDAP action */
430 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn);
431 $this->usertab->set_acl_base();
432 $this->usertab->delete ();
433 unset ($this->usertab);
434 $this->usertab= NULL;
435 } else {
436 msg_dialog::display(_("User delete"),sprintf(_("You are not allowed to delete the user '%s'!"),$dn),WARNING_DIALOG);
437 if(isset($this->ui->uid)){
438 new log("security","users/".get_class($this),$dn,array(),"Tried to trick deletion.");
439 }
440 }
441 /* Remove lock file after successfull deletion */
442 del_lock ($dn);
443 unset($this->dns[$key]);
444 }
445 }
448 /********************
449 Delete MULTIPLE entries Canceled
450 ********************/
452 /* Remove lock */
453 if(isset($_POST['delete_multiple_user_cancel'])){
454 foreach($this->dns as $key => $dn){
455 del_lock ($dn);
456 unset($this->dns[$key]);
457 }
458 }
461 /********************
462 Toggle lock status for user
463 ********************/
465 if($s_action == "toggle_lock_status" && isset($this->list[$s_entry])){
467 /* Get entry check current status */
468 $val = $this->list[$s_entry];
469 $pwd = $val['userPassword'][0];
471 if(!preg_match("/^\{[^\}]/",$pwd)){
472 trigger_error("Can not deactivate user which is using clear password encryption.");
473 }else{
475 $locked = false;
476 if(preg_match("/^[^\}]*+\}!/",$pwd)){
477 $locked = true;
478 }
480 /* Create ldap array to update status */
481 $attrs = array("userPassword" => $pwd);
482 if($locked){
483 $attrs['userPassword'] = preg_replace("/(^[^\}]+\})!(.*$)/","\\1\\2",$attrs['userPassword']);
484 }else{
485 $attrs['userPassword'] = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$attrs['userPassword']);
486 }
488 /* Write new status back to ldap */
489 $ldap = $this->config->get_ldap_link();
490 $ldap->cd($val['dn']);
491 $ldap->modify($attrs);
492 if($locked){
493 show_ldap_error($ldap->get_error(),_("Could not set user status from locked to unlocked."));
494 }else{
495 show_ldap_error($ldap->get_error(),_("Could not set user status from unlocked to locked."));
496 }
497 }
498 }
501 /********************
502 Delete entry requested, display confirm dialog
503 ********************/
505 /* Remove user was requested */
506 if ($s_action=="del"){
508 /* Get 'dn' from posted 'uid' */
509 $this->dn= $this->list[trim($s_entry)]['dn'];
511 /* Load permissions for selected 'dn' and check if
512 we're allowed to remove this 'dn' */
514 /* Check locking, save current plugin in 'back_plugin', so
515 the dialog knows where to return. */
516 if (($user= get_lock($this->dn)) != ""){
517 return(gen_locked_message ($user, $this->dn));
518 }
521 /* Lock the current entry, so nobody will edit it during deletion */
522 # add_lock ($this->dn, $this->ui->dn);
523 # $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
524 # $smarty->assign("multiple", false);
525 # return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
526 $this->msg_dialog = new msg_dialog( _("Delete user"),sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)),CONFIRM_DIALOG);
527 $this->current_action = $s_action;
528 }
531 /********************
532 Delete entry confirmed
533 ********************/
535 /* Confirmation for deletion has been passed. User should be deleted. */
536 if ($this->current_action == "del" && is_object($this->msg_dialog) && $this->msg_dialog->is_confirmed()){
538 $this->current_action = "";
540 /* Some nice guy may send this as POST, so we've to check
541 for the permissions again. */
543 $acl = $this->ui->get_permissions($this->dn, "users/user");
545 if (preg_match('/d/', $acl)){
547 /* Delete request is permitted, perform LDAP action */
548 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
549 $this->usertab->set_acl_base();
550 $this->usertab->delete ();
551 unset ($this->usertab);
552 $this->usertab= NULL;
553 msg_dialog::display(_("User delted"),_("User successfully removed."),INFO_DIALOG);
554 } else {
556 /* Normally this shouldn't be reached, send some extra
557 logs to notify the administrator */
558 msg_dialog::display(_("User delete"),_("You are not allowed to delete this user!"),WARNING_DIALOG);
560 if(isset($this->ui->uid)){
561 new log("security","users/".get_class($this),$this->dn,array(),"Tried to trick deletion.");
562 }
563 }
565 /* Remove lock file after successfull deletion */
566 del_lock ($this->dn);
567 }
570 /********************
571 Delete entry Canceled
572 ********************/
574 /* Delete user canceled? */
575 if (isset($_POST['delete_cancel'])){
576 del_lock ($this->dn);
577 }
580 /********************
581 Edit entry finished (Save)
582 ********************/
584 /* Finish user edit is triggered by the tabulator dialog, so
585 the user wants to save edited data. Check and save at this
586 point. */
587 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
589 /* Check tabs, will feed message array */
590 $this->usertab->last= $this->usertab->current;
591 $this->usertab->save_object();
592 $message= $this->usertab->check();
594 /* Save, or display error message? */
595 if (count($message) == 0){
597 /* No errors. Go ahead and prepare to ask for a password
598 in case we're creating a new user. 'dn' will be 'new'
599 in this case. It is set to the correct value later. */
600 if ($this->dn == "new"){
601 $set_pass= 1;
602 } else {
603 $set_pass= 0;
604 }
606 /* Save user data to ldap */
607 if($this->usertab->save() == 1){
608 return;
609 }
611 if (!isset($_POST['edit_apply'])){
612 /* User has been saved successfully, remove lock from LDAP. */
613 if ($this->dn != "new"){
614 del_lock ($this->dn);
615 }
617 /* In case of new users, ask for a password, skip this for templates */
618 if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
619 $this->dn = $this->usertab->dn;
620 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
621 }
623 unset ($this->usertab);
624 $this->usertab= NULL;
625 unset ($_SESSION['objectinfo']);
626 }
627 } else {
628 /* Ok. There seem to be errors regarding to the tab data,
629 show message and continue as usual. */
630 show_errors($message);
631 }
632 }
635 /********************
636 We want to create a new user, so fetch all available user templates
637 ********************/
639 /* Generate template list */
640 if (($s_action=="new")||($s_action=="create_user_from_tpl")){
642 $this->templates= array();
643 $ldap= $this->config->get_ldap_link();
645 /* Create list of templates */
646 foreach ($this->config->departments as $key => $value){
648 /* Get acls from different ou's */
649 $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user") ;
651 /* If creation of a new user is allowed, append this template */
652 if (preg_match("/c/",$acl)){
654 /* Search all templates from the current dn */
655 $ldap->cd (get_people_ou().$value);
656 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
658 /* Append */
659 if ($ldap->count() != 0){
660 while ($attrs= $ldap->fetch()){
661 $this->templates[$ldap->getDN()]=
662 $attrs['uid'][0]." - ".@LDAP::fix($key);
663 }
664 $this->templates['none']= _("none");
665 }
666 }
667 }
669 /* Sort templates */
670 natcasesort ($this->templates);
671 reset ($this->templates);
672 }
675 /********************
676 Create a new user,template, user from template
677 ********************/
679 /* Check selected options for template */
680 if (isset($_POST['template_continue'])){
681 $message = array();
682 if(!isset($_POST['template']) || (empty($_POST['template']))){
683 $message[] = _("Please select a valid template.");
684 }
685 if(!isset($_POST['sn']) || (empty($_POST['sn']))){
686 $message[]= _("The required field 'Name' is not set.");
687 }
688 if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
689 $message[]= _("The required field 'Given name' is not set.");
690 }
692 /* Show error message / continue editing */
693 if (count($message) > 0){
694 show_errors ($message);
696 foreach(array("sn", "givenName", "uid", "template") as $attr){
697 if(isset($_POST[$attr])){
698 $smarty->assign("$attr", $_POST[$attr]);
699 }else{
700 $smarty->assign("$attr", "");
701 }
702 }
703 $smarty->assign("templates",$this->templates);
704 $smarty->assign("got_uid",$this->got_uid);
705 $smarty->assign("edit_uid",false);
706 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
708 }
709 }
711 /* New user/template request */
712 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
713 /* By default we set 'dn' to 'new', all relevant plugins will
714 react on this. */
715 $this->dn= "new";
717 if (isset($this->config->current['IDGEN'])){
718 $this->got_uid= false;
719 } else {
720 $this->got_uid= true;
721 }
723 /* Create new usertab object */
724 $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
725 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
726 $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
728 /* Take care about templates */
729 if ($s_action=="new_tpl"){
730 $this->is_template= TRUE;
731 $this->usertab->set_template_mode ();
732 } else {
733 $this->is_template= FALSE;
734 }
736 /* Use template if there are any of them */
737 if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
738 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
739 $smarty->assign("$attr", $this->$attr);
740 }
741 if ($s_action=="create_user_from_tpl"){
742 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
743 } else {
744 $smarty->assign("template", "none");
745 }
746 $smarty->assign("edit_uid", "");
747 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
748 }
749 }
751 /********************
752 Template selected continue edit
753 ********************/
755 /* Continue template editing */
756 if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
758 $this->sn = $_POST['sn'];
759 $this->givenName = $_POST['givenName'];
761 /* Check for requred values */
762 $message= array();
763 if ($this->sn == "") {
764 $message[]= _("The required field 'Name' is not set.");
765 }
766 if ($this->givenName == "") {
767 $message[]= _("The required field 'Given name' is not set.");
768 }
770 /* Check if dn is used */
771 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
772 $ldap= $this->config->get_ldap_link();
773 $ldap->cd ($dn);
774 $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
775 if ($ldap->count () != 0){
776 $message[]= _("A person with the choosen name is already used in this tree.");
777 }
779 /* Show error message / continue editing */
780 if (count($message) > 0){
781 show_errors ($message);
782 } else {
783 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
784 if (isset($this->config->current['IDGEN']) &&
785 $this->config->current['IDGEN'] != ""){
786 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
787 if (count($uids)){
788 $smarty->assign("edit_uid", "false");
789 $smarty->assign("uids", $uids);
790 $this->uid= current($uids);
791 }
792 } else {
793 $smarty->assign("edit_uid", "");
794 $this->uid= "";
795 }
796 $this->got_uid= true;
797 }
799 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
800 $smarty->assign("$attr", $this->$attr);
801 }
802 if (isset($_POST['template'])){
803 $smarty->assign("template", $_POST['template']);
804 }
805 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
806 }
808 /********************
809 No template selected continue edit
810 ********************/
812 /* No template. Ok. Lets fill data into the normal user dialog */
813 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
814 foreach(array("sn", "givenName", "uid") as $attr){
815 if (isset($_POST[$attr])){
816 $this->usertab->by_object['user']->$attr= $_POST[$attr];
817 }
818 }
819 }
822 /********************
823 Template selected continue edit
824 ********************/
826 /* Finish template preamble */
827 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
829 /* Might not be filled if IDGEN is unset */
830 $this->sn = $_POST['sn'];
831 $this->givenName = $_POST['givenName'];
833 /* Move user supplied data to sub plugins */
834 $this->uid = $_POST['uid'];
835 $this->usertab->uid = $this->uid;
836 $this->usertab->sn = $this->sn;
837 $this->usertab->givenName = $this->givenName;
838 $template_dn = $_POST['template'];
839 $this->usertab->adapt_from_template($template_dn);
840 $template_base = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
841 $this->usertab->by_object['user']->base= $template_base;
842 }
845 /********************
846 If no template was selected set base
847 ********************/
849 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
850 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
851 }
854 /********************
855 Display subdialog
856 ********************/
858 /* Show tab dialog if object is present */
859 if(isset($this->usertab->config)){
860 $display= $this->usertab->execute();
862 /* Don't show buttons if tab dialog requests this */
864 $dia = FALSE;
865 if(isset($this->usertab->by_object[$this->usertab->current]->dialog)){
866 $dia = $this->usertab->by_object[$this->usertab->current]->dialog;
867 }
869 if(!is_object($dia) && $dia != TRUE){
870 $display.= "<p style=\"text-align:right\">\n";
871 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
872 $display.= " \n";
873 if ($this->dn != "new"){
874 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
875 $display.= " \n";
876 }
877 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
878 $display.= "</p>";
879 }
880 return ($display);
881 }
883 /* Check if there is a snapshot dialog open */
884 $base = $this->DivListUsers->selectedBase;
885 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
886 return($str);
887 }
889 /* Return rendered main page */
890 /* Display dialog with system list */
891 $this->DivListUsers->parent = $this;
892 $this->DivListUsers->execute();
894 /* Add departments if subsearch is disabled */
895 if(!$this->DivListUsers->SubSearch){
896 $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4,1);
897 }
898 $this->reload();
899 $this->DivListUsers->setEntries($this->list);
900 return($this->DivListUsers->Draw());
901 }
904 /* Return departments, that will be included within snapshot detection */
905 function get_used_snapshot_bases()
906 {
907 return(array(get_people_ou().$this->DivListUsers->selectedBase));
908 }
911 function reload()
912 {
913 /* Set base for all searches */
914 $base= $this->DivListUsers->selectedBase;
915 $this->list =array();
917 /* Get filter configuration */
918 $Regex = $this->DivListUsers->Regex;
919 $SubSearch = $this->DivListUsers->SubSearch;
920 $ShowTemplates = $this->DivListUsers->ShowTemplates;
921 $ShowFunctionalUsers = $this->DivListUsers->ShowFunctionalUsers;
922 $ShowUnixUsers = $this->DivListUsers->ShowUnixUsers;
923 $ShowMailUsers = $this->DivListUsers->ShowMailUsers;
924 $ShowSambaUsers = $this->DivListUsers->ShowSambaUsers;
925 $ShowProxyUsers = $this->DivListUsers->ShowProxyUsers;
927 /* Setup filter depending on selection */
928 $filter="";
929 if ($this->config->current['SAMBAVERSION'] == 3){
930 $samba= "sambaSamAccount";
931 } else {
932 $samba= "sambaAccount";
933 }
935 if ($ShowFunctionalUsers){
936 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
937 "(objectClass=gosaMailAccount)(objectClass=$samba)".
938 "(objectClass=gosaProxyAccount))))";
939 }
940 if ($ShowUnixUsers){
941 $filter.= "(objectClass=posixAccount)";
942 }
943 if ($ShowMailUsers){
944 $filter.= "(objectClass=gosaMailAccount)";
945 }
946 if ($ShowSambaUsers){
947 $filter.= "(objectClass=$samba)";
948 }
949 if ($ShowProxyUsers){
950 $filter.= "(objectClass=gosaProxyAccount)";
951 }
952 if ($ShowTemplates){
953 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
954 } else {
955 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
956 }
957 $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
959 /* Generate userlist */
960 $ldap= $this->config->get_ldap_link(TRUE);
962 if ($SubSearch){
963 $ListTemp = get_list($filter, "users", $base,
964 array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SUBSEARCH | GL_SIZELIMIT);
965 } else {
966 $base= get_people_ou().$base;
967 $ListTemp = get_list($filter, "users", $base,
968 array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SIZELIMIT);
969 }
970 $SortTemp = array();
971 $List = array();
972 foreach($ListTemp as $Key => $Entry){
974 /* Skip entries that are not located under the people ou (normaly 'ou=people,')
975 * Else winstations will be listed too, if you use the subtree flag.
976 */
977 if(!preg_match("/".normalizePreg(get_people_ou())."/i",$Entry['dn'])){
978 continue;
979 }else{
981 // Generate caption for rows
982 if (isset($Entry["sn"]) && isset($Entry["givenName"])){
983 $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
984 } else {
985 $display= "[".$Entry["uid"][0]."]";
986 }
988 $display = strtolower($display);
989 $List[$display] = $Entry;
990 $SortTemp[$display] = $display;
991 }
992 }
993 sort($SortTemp);
994 reset($SortTemp);
996 $this->list = array();
997 foreach($SortTemp as $Key){
998 $this->list[] = $List[$Key];
999 }
1000 }
1002 function remove_lock()
1003 {
1004 /* Remove user lock if a DN is marked as "currently edited" */
1005 if (isset($this->usertab->dn)){
1006 del_lock ($this->usertab->dn);
1007 }
1008 }
1011 function copyPasteHandling_from_queue($s_action,$s_entry)
1012 {
1013 /* Check if Copy & Paste is disabled */
1014 if(!is_object($this->CopyPasteHandler)){
1015 return("");
1016 }
1018 /* Add a single entry to queue */
1019 if($s_action == "cut" || $s_action == "copy"){
1020 /* Cleanup object queue */
1021 $this->CopyPasteHandler->cleanup_queue();
1022 $dn = $this->list[$s_entry]['dn'];
1023 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"usertabs","USERTABS","users");
1024 }
1026 /* Add entries to queue */
1027 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
1029 /* Cleanup object queue */
1030 $this->CopyPasteHandler->cleanup_queue();
1032 /* Add new entries to CP queue */
1033 foreach($this->list_get_selected_items() as $id){
1034 $dn = $this->list[$id]['dn'];
1036 if($s_action == "copy_multiple"){
1037 $this->CopyPasteHandler->add_to_queue($dn,"copy","usertabs","USERTABS","users");
1038 }
1039 if($s_action == "cut_multiple"){
1040 $this->CopyPasteHandler->add_to_queue($dn,"cut","usertabs","USERTABS","users");
1041 }
1042 }
1043 }
1045 /* Start pasting entries */
1046 if($s_action == "editPaste"){
1047 $this->start_pasting_copied_objects = TRUE;
1048 }
1050 /* Return C&P dialog */
1051 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1053 /* Load entry from queue and set base */
1054 $this->CopyPasteHandler->load_entry_from_queue();
1055 $this->CopyPasteHandler->SetVar("base",$this->DivListUsers->selectedBase);
1057 /* Get dialog */
1058 $data = $this->CopyPasteHandler->execute();
1060 /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
1061 if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
1062 $s_entry = $this->CopyPasteHandler->last_entry();
1063 $this->reload();
1064 foreach($this->list as $key => $entry){
1065 if($entry['dn'] == $s_entry){
1066 $this->CPPasswordChange = $key;
1067 }
1068 }
1069 }
1071 /* Return dialog data */
1072 if(!empty($data) && $this->CPPasswordChange == ""){
1073 return($data);
1074 }
1075 }
1077 /* Automatically disable status for pasting */
1078 if(!$this->CopyPasteHandler->entries_queued()){
1079 $this->start_pasting_copied_objects = FALSE;
1080 }
1081 return("");
1082 }
1085 function save_object()
1086 {
1087 /* Handle divlist filter && department selection*/
1088 if(!is_object($this->usertab)){
1089 $this->DivListUsers->save_object();
1090 }
1091 }
1094 function list_get_selected_items()
1095 {
1096 $ids = array();
1097 foreach($_POST as $name => $value){
1098 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1099 $id = preg_replace("/^item_selected_/","",$name);
1100 $ids[$id] = $id;
1101 }
1102 }
1103 return($ids);
1104 }
1107 /* A set of disabled and therefore overloaded functions. They are
1108 not needed in this class. */
1109 function remove_from_parent() { }
1110 function check() { }
1111 function save() { }
1112 function adapt_from_template($dn) { }
1113 function password_change_needed() { }
1115 } /* ... class userManagement */
1116 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1117 ?>