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/");
67 $smarty = get_smarty(); // Smarty instance
68 $s_action = ""; // Contains the action to be taken
69 $s_entry = ""; // The value for s_action
71 /* Edit entry button pressed? */
72 if( isset($_GET['act']) && $_GET['act'] == "edit_entry" ){
73 $s_action= "edit";
74 $s_entry= validate($_GET['id']);
75 }
77 /* Test relevant POST values */
78 foreach($_POST as $key => $val){
80 /* Get every possible POST combination and set s_action/s_entry accordingly */
81 foreach(array("del" => "user_del", "edit" => "user_edit",
82 "new" => "user_new",
83 "new_tpl" => "user_tplnew",
84 "del_multiple" => "^remove_multiple_users",
85 "create_user_from_tpl" => "userfrom_tpl",
86 "change_pw" => "user_chgpw",
87 "editPaste" => "editPaste",
88 "copy_multiple" => "multiple_copy_users",
89 "cut_multiple" => "multiple_cut_users",
90 "multiple_password_change" => "multiple_password_change",
91 "copy" => "^copy",
92 "toggle_lock_status" => "toggle_lock_status",
93 "cut" => "^cut") as $act => $name){
95 if (preg_match("/".$name.".*/", $key)){
96 $s_action= $act;
97 $s_entry= preg_replace("/".$name."_/i", "", $key);
98 break;
99 }
100 }
102 } /* ...Test POST */
104 /* Remove coordinate prefix from POST, required by some browsers */
105 $s_entry= preg_replace("/_.$/", "", $s_entry);
107 /* Seperate possibly encoded tab and entry, default to tab "user" */
108 if(preg_match("/.*-.*/", $s_entry)){
109 $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
110 $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
111 }else{
112 $s_tab= "user";
113 }
115 if(!$this->config->search($s_tab, 'class',array('tabs'))){
116 $s_tab = "user";
117 }
119 /********************
120 Copy & Paste
121 ********************/
123 /* Display the copy & paste dialog, if it is currently open */
124 if($this->CPPasswordChange == ""){
125 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
126 if($ret){
127 return($ret);
128 }
129 }
132 /********************
133 Change password confirmed
134 ********************/
136 /* Perform password change */
137 if (isset($_POST['password_finish'])){
139 /* For security reasons, check if user is allowed to set password again */
140 $dn = $this->dn;
141 $acl = $this->ui->get_permissions($dn, "users/password");
142 $cacl= $this->ui->get_permissions($dn, "users/user");
144 if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
146 /* Check input and feed errors into 'message' */
147 $message= array();
149 /* Sanity checks... */
150 if ($_POST['new_password'] != $_POST['repeated_password']){
152 /* Matching passwords in new and repeated? */
153 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
154 } else {
156 /* Empty password is not permitted by default. */
157 if ($_POST['new_password'] == ""){
158 $message[]= _("The password you've entered as 'New password' is empty.");
159 }
160 }
162 /* Errors, or password change? */
163 if (count($message) != 0){
165 /* Show error message and continue editing */
166 show_errors ($message);
167 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
168 }
170 $config= $this->config;
171 $ldap_ui= $this->config->get_ldap_link();
172 if(isset($this->usertab->dn)){
173 $ldap_ui->cat($this->usertab->dn,array("uid"));
174 $user = $ldap_ui->fetch();
175 }else{
176 $ldap_ui->cat($this->dn,array("uid"));
177 $user = $ldap_ui->fetch();
178 }
179 if((is_array($user))&&(isset($user['uid']))){
180 $username= $user['uid'][0];
181 }
183 /* Set password, perform required steps */
184 if ($this->usertab){
185 if ($this->usertab->password_change_needed()){
186 $obj= $this->usertab->by_object['user'];
187 change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
188 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
189 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
190 }
191 new log("modify","users/".get_class($this),$this->usertab->dn,array(),"Password has been changed");
192 unset($this->usertab);
193 $this->usertab= NULL;
194 }
195 } else {
196 change_password ($this->dn, $_POST['new_password']);
197 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
198 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
199 }
200 new log("modify","users/".get_class($this),$this->dn,array(),"Password has been changed");
201 }
202 } else {
204 /* Missing permissions, show message */
205 msg_dialog::display(_("Password change failed."),_("You are not allowed to set this users password!"),WARNING_DIALOG);
206 }
207 /* Clean session, delete lock */
208 del_lock ($this->dn);
209 unset ($this->usertab);
210 $this->usertab= NULL;
211 $this->lognames= array();;
212 $this->sn= "";
213 $this->givenName= "";
214 $this->uid= "";
215 unset ($_SESSION['objectinfo']);
216 }
219 /********************
220 Change multiple passwords requested
221 ********************/
223 if($s_action == "multiple_password_change"){
224 $this->pwd_change_queue = $this->list_get_selected_items();
225 }
228 /********************
229 Change password requested
230 ********************/
232 /* Password change requested */
233 if (($s_action == "change_pw") || (!empty($this->CPPasswordChange)) || count($this->pwd_change_queue)){
235 /* Get users whose passwords should be changed. */
236 if(count($this->pwd_change_queue)){
237 $s_entry= array_pop($this->pwd_change_queue);
238 }
240 if(!empty($this->CPPasswordChange)){
241 $s_entry = $this->CPPasswordChange;
242 $this->CPPasswordChange = "";
243 }
245 /* Get 'dn' from posted 'uid' */
246 $this->dn= $this->list[trim($s_entry)]['dn'];
248 /* Load permissions for selected 'dn' and check if
249 we're allowed to remove this 'dn' */
250 if (preg_match("/w/",$this->ui->get_permissions($this->dn,"users/password"))){
252 /* User is allowed to change passwords, save 'dn' and 'acl' for next
253 dialog. */
254 $_SESSION['objectinfo']= $this->dn;
255 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
258 } else {
259 /* User is not allowed. Show message and cancel. */
260 msg_dialog::display(_("Password change"),_("You are not allowed to set this users password!"),WARNING_DIALOG);
261 }
262 }
267 /********************
268 Edit existing entry
269 ********************/
271 /* User wants to edit data? */
272 if (($s_action=="edit") && (!isset($this->usertab->config))){
274 /* Get 'dn' from posted 'uid', must be unique */
275 $this->dn= $this->list[trim($s_entry)]['dn'];
277 /* Check locking, save current plugin in 'back_plugin', so
278 the dialog knows where to return. */
279 if (($user= get_lock($this->dn)) != ""){
280 return(gen_locked_message ($user, $this->dn));
281 }
283 /* Lock the current entry, so everyone will get the
284 above dialog */
285 add_lock ($this->dn, $this->ui->dn);
287 /* Register usertab to trigger edit dialog */
288 $this->usertab= new usertabs($this->config,
289 $this->config->data['TABS']['USERTABS'], $this->dn);
291 /* Switch tab, if it was requested by the user */
292 $this->usertab->current = $s_tab;
294 /* Set ACL and move DN to the headline */
295 $this->usertab->set_acl_base($this->dn);
296 $_SESSION['objectinfo']= $this->dn;
297 }
300 /********************
301 Edit canceled
302 ********************/
304 /* Reset all relevant data, if we get a _cancel request */
305 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
306 if (isset($this->usertab)){
307 del_lock ($this->usertab->dn);
308 unset ($this->usertab);
309 }
310 $this->usertab= NULL;
311 $this->lognames= array();;
312 $this->sn= "";
313 $this->givenName= "";
314 $this->uid= "";
315 unset ($_SESSION['objectinfo']);
316 }
319 /********************
320 Delete MULTIPLE entries requested, display confirm dialog
321 ********************/
323 if ($s_action=="del_multiple"){
324 $ids = $this->list_get_selected_items();
325 $this->dns = array();
326 if(count($ids)){
328 foreach($ids as $id){
329 $dn = $this->list[$id]['dn'];
330 if (($user= get_lock($dn)) != ""){
331 return(gen_locked_message ($user, $dn));
332 }
333 $this->dns[$id] = $dn;
334 }
336 $dns_names = "<br><pre>";
337 foreach($this->dns as $dn){
338 $dns_names .= $dn."\n";
339 }
340 $dns_names .="</pre>";
342 /* Lock the current entry, so nobody will edit it during deletion */
343 if (count($this->dns) == 1){
344 $info = sprintf(_("You're about to delete the following entry: %s"), @LDAP::fix($dns_names));
345 } else {
346 $info = sprintf(_("You're about to delete the following entries: %s"), @LDAP::fix($dns_names));
347 }
348 $this->msg_dialog = new msg_dialog(_("Delete users"),$info,CONFIRM_DIALOG);
349 $this->current_action = $s_action;
350 }
351 }
354 /********************
355 Delete MULTIPLE entries confirmed
356 ********************/
358 /* Confirmation for deletion has been passed. Users should be deleted. */
359 if ($this->current_action == "del_multiple" && is_object($this->msg_dialog) && $this->msg_dialog->is_confirmed()){
361 /* Remove user by user and check acls before removeing them */
362 foreach($this->dns as $key => $dn){
364 $acl = $this->ui->get_permissions($dn, "users/user");
365 if (preg_match('/d/', $acl)){
367 /* Delete request is permitted, perform LDAP action */
368 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn);
369 $this->usertab->set_acl_base();
370 $this->usertab->delete ();
371 unset ($this->usertab);
372 $this->usertab= NULL;
373 } else {
374 msg_dialog::display(_("User delete"),sprintf(_("You are not allowed to delete the user '%s'!"),$dn),WARNING_DIALOG);
375 if(isset($this->ui->uid)){
376 new log("security","users/".get_class($this),$dn,array(),"Tried to trick deletion.");
377 }
378 }
379 /* Remove lock file after successfull deletion */
380 del_lock ($dn);
381 unset($this->dns[$key]);
382 }
383 }
386 /********************
387 Delete MULTIPLE entries Canceled
388 ********************/
390 /* Remove lock */
391 if(isset($_POST['delete_multiple_user_cancel'])){
392 foreach($this->dns as $key => $dn){
393 del_lock ($dn);
394 unset($this->dns[$key]);
395 }
396 }
399 /********************
400 Toggle lock status for user
401 ********************/
403 if($s_action == "toggle_lock_status" && isset($this->list[$s_entry])){
405 /* Get entry check current status */
406 $val = $this->list[$s_entry];
407 $pwd = $val['userPassword'][0];
409 if(!preg_match("/^\{[^\}]/",$pwd)){
410 trigger_error("Can not deactivate user which is using clear password encryption.");
411 }else{
413 $locked = false;
414 if(preg_match("/^[^\}]*+\}!/",$pwd)){
415 $locked = true;
416 }
418 /* Create ldap array to update status */
419 $attrs = array("userPassword" => $pwd);
420 if($locked){
421 $attrs['userPassword'] = preg_replace("/(^[^\}]+\})!(.*$)/","\\1\\2",$attrs['userPassword']);
422 }else{
423 $attrs['userPassword'] = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$attrs['userPassword']);
424 }
426 /* Write new status back to ldap */
427 $ldap = $this->config->get_ldap_link();
428 $ldap->cd($val['dn']);
429 $ldap->modify($attrs);
430 if($locked){
431 show_ldap_error($ldap->get_error(),_("Could not set user status from locked to unlocked."));
432 }else{
433 show_ldap_error($ldap->get_error(),_("Could not set user status from unlocked to locked."));
434 }
435 }
436 }
439 /********************
440 Delete entry requested, display confirm dialog
441 ********************/
443 /* Remove user was requested */
444 if ($s_action=="del"){
446 /* Get 'dn' from posted 'uid' */
447 $this->dn= $this->list[trim($s_entry)]['dn'];
449 /* Load permissions for selected 'dn' and check if
450 we're allowed to remove this 'dn' */
452 /* Check locking, save current plugin in 'back_plugin', so
453 the dialog knows where to return. */
454 if (($user= get_lock($this->dn)) != ""){
455 return(gen_locked_message ($user, $this->dn));
456 }
459 /* Lock the current entry, so nobody will edit it during deletion */
460 # add_lock ($this->dn, $this->ui->dn);
461 # $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
462 # $smarty->assign("multiple", false);
463 # return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
464 $this->msg_dialog = new msg_dialog( _("Delete user"),sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)),CONFIRM_DIALOG);
465 $this->current_action = $s_action;
466 }
469 /********************
470 Delete entry confirmed
471 ********************/
473 /* Confirmation for deletion has been passed. User should be deleted. */
474 if ($this->current_action == "del" && is_object($this->msg_dialog) && $this->msg_dialog->is_confirmed()){
476 /* Some nice guy may send this as POST, so we've to check
477 for the permissions again. */
479 $acl = $this->ui->get_permissions($this->dn, "users/user");
481 if (preg_match('/d/', $acl)){
483 /* Delete request is permitted, perform LDAP action */
484 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
485 $this->usertab->set_acl_base();
486 $this->usertab->delete ();
487 unset ($this->usertab);
488 $this->usertab= NULL;
489 msg_dialog::display(_("User delted"),_("User successfully removed."),INFO_DIALOG);
490 } else {
492 /* Normally this shouldn't be reached, send some extra
493 logs to notify the administrator */
494 msg_dialog::display(_("User delete"),_("You are not allowed to delete this user!"),WARNING_DIALOG);
496 if(isset($this->ui->uid)){
497 new log("security","users/".get_class($this),$this->dn,array(),"Tried to trick deletion.");
498 }
499 }
501 /* Remove lock file after successfull deletion */
502 del_lock ($this->dn);
503 }
506 /********************
507 Delete entry Canceled
508 ********************/
510 /* Delete user canceled? */
511 if (isset($_POST['delete_cancel'])){
512 del_lock ($this->dn);
513 }
516 /********************
517 Edit entry finished (Save)
518 ********************/
520 /* Finish user edit is triggered by the tabulator dialog, so
521 the user wants to save edited data. Check and save at this
522 point. */
523 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
525 /* Check tabs, will feed message array */
526 $this->usertab->last= $this->usertab->current;
527 $this->usertab->save_object();
528 $message= $this->usertab->check();
530 /* Save, or display error message? */
531 if (count($message) == 0){
533 /* No errors. Go ahead and prepare to ask for a password
534 in case we're creating a new user. 'dn' will be 'new'
535 in this case. It is set to the correct value later. */
536 if ($this->dn == "new"){
537 $set_pass= 1;
538 } else {
539 $set_pass= 0;
540 }
542 /* Save user data to ldap */
543 if($this->usertab->save() == 1){
544 return;
545 }
547 if (!isset($_POST['edit_apply'])){
548 /* User has been saved successfully, remove lock from LDAP. */
549 if ($this->dn != "new"){
550 del_lock ($this->dn);
551 }
553 /* In case of new users, ask for a password, skip this for templates */
554 if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
555 $this->dn = $this->usertab->dn;
556 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
557 }
559 unset ($this->usertab);
560 $this->usertab= NULL;
561 unset ($_SESSION['objectinfo']);
562 }
563 } else {
564 /* Ok. There seem to be errors regarding to the tab data,
565 show message and continue as usual. */
566 show_errors($message);
567 }
568 }
571 /********************
572 We want to create a new user, so fetch all available user templates
573 ********************/
575 /* Generate template list */
576 if (($s_action=="new")||($s_action=="create_user_from_tpl")){
578 $this->templates= array();
579 $ldap= $this->config->get_ldap_link();
581 /* Create list of templates */
582 foreach ($this->config->departments as $key => $value){
584 /* Get acls from different ou's */
585 $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user") ;
587 /* If creation of a new user is allowed, append this template */
588 if (preg_match("/c/",$acl)){
590 /* Search all templates from the current dn */
591 $ldap->cd (get_people_ou().$value);
592 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
594 /* Append */
595 if ($ldap->count() != 0){
596 while ($attrs= $ldap->fetch()){
597 $this->templates[$ldap->getDN()]=
598 $attrs['uid'][0]." - ".@LDAP::fix($key);
599 }
600 $this->templates['none']= _("none");
601 }
602 }
603 }
605 /* Sort templates */
606 natcasesort ($this->templates);
607 reset ($this->templates);
608 }
611 /********************
612 Create a new user,template, user from template
613 ********************/
615 /* Check selected options for template */
616 if (isset($_POST['template_continue'])){
617 $message = array();
618 if(!isset($_POST['template']) || (empty($_POST['template']))){
619 $message[] = _("Please select a valid template.");
620 }
621 if(!isset($_POST['sn']) || (empty($_POST['sn']))){
622 $message[]= _("The required field 'Name' is not set.");
623 }
624 if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
625 $message[]= _("The required field 'Given name' is not set.");
626 }
628 /* Show error message / continue editing */
629 if (count($message) > 0){
630 show_errors ($message);
632 foreach(array("sn", "givenName", "uid", "template") as $attr){
633 if(isset($_POST[$attr])){
634 $smarty->assign("$attr", $_POST[$attr]);
635 }else{
636 $smarty->assign("$attr", "");
637 }
638 }
639 $smarty->assign("templates",$this->templates);
640 $smarty->assign("got_uid",$this->got_uid);
641 $smarty->assign("edit_uid",false);
642 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
644 }
645 }
647 /* New user/template request */
648 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
649 /* By default we set 'dn' to 'new', all relevant plugins will
650 react on this. */
651 $this->dn= "new";
653 if (isset($this->config->current['IDGEN'])){
654 $this->got_uid= false;
655 } else {
656 $this->got_uid= true;
657 }
659 /* Create new usertab object */
660 $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
661 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
662 $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
664 /* Take care about templates */
665 if ($s_action=="new_tpl"){
666 $this->is_template= TRUE;
667 $this->usertab->set_template_mode ();
668 } else {
669 $this->is_template= FALSE;
670 }
672 /* Use template if there are any of them */
673 if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
674 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
675 $smarty->assign("$attr", $this->$attr);
676 }
677 if ($s_action=="create_user_from_tpl"){
678 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
679 } else {
680 $smarty->assign("template", "none");
681 }
682 $smarty->assign("edit_uid", "");
683 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
684 }
685 }
687 /********************
688 Template selected continue edit
689 ********************/
691 /* Continue template editing */
692 if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
694 $this->sn = $_POST['sn'];
695 $this->givenName = $_POST['givenName'];
697 /* Check for requred values */
698 $message= array();
699 if ($this->sn == "") {
700 $message[]= _("The required field 'Name' is not set.");
701 }
702 if ($this->givenName == "") {
703 $message[]= _("The required field 'Given name' is not set.");
704 }
706 /* Check if dn is used */
707 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
708 $ldap= $this->config->get_ldap_link();
709 $ldap->cd ($dn);
710 $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
711 if ($ldap->count () != 0){
712 $message[]= _("A person with the choosen name is already used in this tree.");
713 }
715 /* Show error message / continue editing */
716 if (count($message) > 0){
717 show_errors ($message);
718 } else {
719 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
720 if (isset($this->config->current['IDGEN']) &&
721 $this->config->current['IDGEN'] != ""){
722 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
723 if (count($uids)){
724 $smarty->assign("edit_uid", "false");
725 $smarty->assign("uids", $uids);
726 $this->uid= current($uids);
727 }
728 } else {
729 $smarty->assign("edit_uid", "");
730 $this->uid= "";
731 }
732 $this->got_uid= true;
733 }
735 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
736 $smarty->assign("$attr", $this->$attr);
737 }
738 if (isset($_POST['template'])){
739 $smarty->assign("template", $_POST['template']);
740 }
741 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
742 }
744 /********************
745 No template selected continue edit
746 ********************/
748 /* No template. Ok. Lets fill data into the normal user dialog */
749 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
750 foreach(array("sn", "givenName", "uid") as $attr){
751 if (isset($_POST[$attr])){
752 $this->usertab->by_object['user']->$attr= $_POST[$attr];
753 }
754 }
755 }
758 /********************
759 Template selected continue edit
760 ********************/
762 /* Finish template preamble */
763 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
765 /* Might not be filled if IDGEN is unset */
766 $this->sn = $_POST['sn'];
767 $this->givenName = $_POST['givenName'];
769 /* Move user supplied data to sub plugins */
770 $this->uid = $_POST['uid'];
771 $this->usertab->uid = $this->uid;
772 $this->usertab->sn = $this->sn;
773 $this->usertab->givenName = $this->givenName;
774 $template_dn = $_POST['template'];
775 $this->usertab->adapt_from_template($template_dn);
776 $template_base = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
777 $this->usertab->by_object['user']->base= $template_base;
778 }
781 /********************
782 If no template was selected set base
783 ********************/
785 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
786 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
787 }
790 /********************
791 Display subdialog
792 ********************/
794 /* Show tab dialog if object is present */
795 if(isset($this->usertab->config)){
796 $display= $this->usertab->execute();
798 /* Don't show buttons if tab dialog requests this */
799 if(isset($this->usertab->by_object)){
801 $dia = FALSE;
802 if(isset($this->usertab->by_object[$this->usertab->current]->dialog)){
803 $dia = $this->usertab->by_object[$this->usertab->current]->dialog;
804 }
806 if(!is_object($dia) && $dia != TRUE){
807 $display.= "<p style=\"text-align:right\">\n";
808 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
809 $display.= " \n";
810 if ($this->dn != "new"){
811 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
812 $display.= " \n";
813 }
814 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
815 $display.= "</p>";
816 }
817 }
818 return ($display);
819 }
821 /* Check if there is a snapshot dialog open */
822 $base = $this->DivListUsers->selectedBase;
823 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
824 return($str);
825 }
827 /* Return rendered main page */
828 /* Display dialog with system list */
829 $this->DivListUsers->parent = $this;
830 $this->DivListUsers->execute();
832 /* Add departments if subsearch is disabled */
833 if(!$this->DivListUsers->SubSearch){
834 $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4,1);
835 }
836 $this->reload();
837 $this->DivListUsers->setEntries($this->list);
838 return($this->DivListUsers->Draw());
839 }
842 /* Return departments, that will be included within snapshot detection */
843 function get_used_snapshot_bases()
844 {
845 return(array(get_people_ou().$this->DivListUsers->selectedBase));
846 }
849 function reload()
850 {
851 /* Set base for all searches */
852 $base= $this->DivListUsers->selectedBase;
853 $this->list =array();
855 /* Get filter configuration */
856 $Regex = $this->DivListUsers->Regex;
857 $SubSearch = $this->DivListUsers->SubSearch;
858 $ShowTemplates = $this->DivListUsers->ShowTemplates;
859 $ShowFunctionalUsers = $this->DivListUsers->ShowFunctionalUsers;
860 $ShowUnixUsers = $this->DivListUsers->ShowUnixUsers;
861 $ShowMailUsers = $this->DivListUsers->ShowMailUsers;
862 $ShowSambaUsers = $this->DivListUsers->ShowSambaUsers;
863 $ShowProxyUsers = $this->DivListUsers->ShowProxyUsers;
865 /* Setup filter depending on selection */
866 $filter="";
867 if ($this->config->current['SAMBAVERSION'] == 3){
868 $samba= "sambaSamAccount";
869 } else {
870 $samba= "sambaAccount";
871 }
873 if ($ShowFunctionalUsers){
874 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
875 "(objectClass=gosaMailAccount)(objectClass=$samba)".
876 "(objectClass=gosaProxyAccount))))";
877 }
878 if ($ShowUnixUsers){
879 $filter.= "(objectClass=posixAccount)";
880 }
881 if ($ShowMailUsers){
882 $filter.= "(objectClass=gosaMailAccount)";
883 }
884 if ($ShowSambaUsers){
885 $filter.= "(objectClass=$samba)";
886 }
887 if ($ShowProxyUsers){
888 $filter.= "(objectClass=gosaProxyAccount)";
889 }
890 if ($ShowTemplates){
891 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
892 } else {
893 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
894 }
895 $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
897 /* Generate userlist */
898 $ldap= $this->config->get_ldap_link(TRUE);
900 if ($SubSearch){
901 $ListTemp = get_list($filter, "users", $base,
902 array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SUBSEARCH | GL_SIZELIMIT);
903 } else {
904 $base= get_people_ou().$base;
905 $ListTemp = get_list($filter, "users", $base,
906 array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SIZELIMIT);
907 }
908 $SortTemp = array();
909 $List = array();
910 foreach($ListTemp as $Key => $Entry){
912 /* Skip entries that are not located under the people ou (normaly 'ou=people,')
913 * Else winstations will be listed too, if you use the subtree flag.
914 */
915 if(!preg_match("/".normalizePreg(get_people_ou())."/i",$Entry['dn'])){
916 continue;
917 }else{
919 // Generate caption for rows
920 if (isset($Entry["sn"]) && isset($Entry["givenName"])){
921 $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
922 } else {
923 $display= "[".$Entry["uid"][0]."]";
924 }
926 $display = strtolower($display);
927 $List[$display] = $Entry;
928 $SortTemp[$display] = $display;
929 }
930 }
931 sort($SortTemp);
932 reset($SortTemp);
934 $this->list = array();
935 foreach($SortTemp as $Key){
936 $this->list[] = $List[$Key];
937 }
938 }
940 function remove_lock()
941 {
942 /* Remove user lock if a DN is marked as "currently edited" */
943 if (isset($this->usertab->dn)){
944 del_lock ($this->usertab->dn);
945 }
946 }
949 function copyPasteHandling_from_queue($s_action,$s_entry)
950 {
951 /* Check if Copy & Paste is disabled */
952 if(!is_object($this->CopyPasteHandler)){
953 return("");
954 }
956 /* Add a single entry to queue */
957 if($s_action == "cut" || $s_action == "copy"){
958 /* Cleanup object queue */
959 $this->CopyPasteHandler->cleanup_queue();
960 $dn = $this->list[$s_entry]['dn'];
961 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"usertabs","USERTABS","users");
962 }
964 /* Add entries to queue */
965 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
967 /* Cleanup object queue */
968 $this->CopyPasteHandler->cleanup_queue();
970 /* Add new entries to CP queue */
971 foreach($this->list_get_selected_items() as $id){
972 $dn = $this->list[$id]['dn'];
974 if($s_action == "copy_multiple"){
975 $this->CopyPasteHandler->add_to_queue($dn,"copy","usertabs","USERTABS","users");
976 }
977 if($s_action == "cut_multiple"){
978 $this->CopyPasteHandler->add_to_queue($dn,"cut","usertabs","USERTABS","users");
979 }
980 }
981 }
983 /* Start pasting entries */
984 if($s_action == "editPaste"){
985 $this->start_pasting_copied_objects = TRUE;
986 }
988 /* Return C&P dialog */
989 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
991 /* Load entry from queue and set base */
992 $this->CopyPasteHandler->load_entry_from_queue();
993 $this->CopyPasteHandler->SetVar("base",$this->DivListUsers->selectedBase);
995 /* Get dialog */
996 $data = $this->CopyPasteHandler->execute();
998 /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
999 if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
1000 $s_entry = $this->CopyPasteHandler->last_entry();
1001 $this->reload();
1002 foreach($this->list as $key => $entry){
1003 if($entry['dn'] == $s_entry){
1004 $this->CPPasswordChange = $key;
1005 }
1006 }
1007 }
1009 /* Return dialog data */
1010 if(!empty($data) && $this->CPPasswordChange == ""){
1011 return($data);
1012 }
1013 }
1015 /* Automatically disable status for pasting */
1016 if(!$this->CopyPasteHandler->entries_queued()){
1017 $this->start_pasting_copied_objects = FALSE;
1018 }
1019 return("");
1020 }
1023 function save_object()
1024 {
1025 /* Handle divlist filter && department selection*/
1026 if(!is_object($this->usertab)){
1027 $this->DivListUsers->save_object();
1028 }
1029 }
1032 function list_get_selected_items()
1033 {
1034 $ids = array();
1035 foreach($_POST as $name => $value){
1036 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1037 $id = preg_replace("/^item_selected_/","",$name);
1038 $ids[$id] = $id;
1039 }
1040 }
1041 return($ids);
1042 }
1045 /* A set of disabled and therefore overloaded functions. They are
1046 not needed in this class. */
1047 function remove_from_parent() { }
1048 function check() { }
1049 function save() { }
1050 function adapt_from_template($dn) { }
1051 function password_change_needed() { }
1053 } /* ... class userManagement */
1054 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1055 ?>