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/");
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 }
121 /********************
122 Copy & Paste
123 ********************/
125 /* Display the copy & paste dialog, if it is currently open */
126 if($this->CPPasswordChange == ""){
127 $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry);
128 if($ret){
129 return($ret);
130 }
131 }
134 /********************
135 Change password confirmed
136 ********************/
138 /* Perform password change */
139 if (isset($_POST['password_finish'])){
141 /* For security reasons, check if user is allowed to set password again */
142 $dn = $this->dn;
143 $acl = $this->ui->get_permissions($dn, "users/password");
144 $cacl= $this->ui->get_permissions($dn, "users/user");
146 if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
148 /* Check input and feed errors into 'message' */
149 $message= array();
151 /* Sanity checks... */
152 if ($_POST['new_password'] != $_POST['repeated_password']){
154 /* Matching passwords in new and repeated? */
155 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
156 } else {
158 /* Empty password is not permitted by default. */
159 if ($_POST['new_password'] == ""){
160 $message[]= _("The password you've entered as 'New password' is empty.");
161 }
162 }
164 /* Errors, or password change? */
165 if (count($message) != 0){
167 /* Show error message and continue editing */
168 show_errors ($message);
169 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
170 }
172 $config= $this->config;
173 $ldap_ui= $this->config->get_ldap_link();
174 if(isset($this->usertab->dn)){
175 $ldap_ui->cat($this->usertab->dn,array("uid"));
176 $user = $ldap_ui->fetch();
177 }else{
178 $ldap_ui->cat($this->dn,array("uid"));
179 $user = $ldap_ui->fetch();
180 }
181 if((is_array($user))&&(isset($user['uid']))){
182 $username= $user['uid'][0];
183 }
185 /* Set password, perform required steps */
186 if ($this->usertab){
187 if ($this->usertab->password_change_needed()){
188 $obj= $this->usertab->by_object['user'];
189 change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
190 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
191 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
192 }
193 new log("modify","users/".get_class($this),$this->usertab->dn,array(),"Password has been changed");
194 unset($this->usertab);
195 $this->usertab= NULL;
196 }
197 } else {
198 change_password ($this->dn, $_POST['new_password']);
199 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
200 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
201 }
202 new log("modify","users/".get_class($this),$this->dn,array(),"Password has been changed");
203 }
204 } else {
206 /* Missing permissions, show message */
207 msg_dialog::display(_("Password change failed."),_("You are not allowed to set this users password!"),WARNING_DIALOG);
208 }
209 /* Clean session, delete lock */
210 del_lock ($this->dn);
211 unset ($this->usertab);
212 $this->usertab= NULL;
213 $this->lognames= array();;
214 $this->sn= "";
215 $this->givenName= "";
216 $this->uid= "";
217 unset ($_SESSION['objectinfo']);
218 }
221 /********************
222 Change multiple passwords requested
223 ********************/
225 if($s_action == "multiple_password_change"){
226 $this->pwd_change_queue = $this->list_get_selected_items();
227 }
230 /********************
231 Change password requested
232 ********************/
234 /* Password change requested */
235 if (($s_action == "change_pw") || (!empty($this->CPPasswordChange)) || count($this->pwd_change_queue)){
237 /* Get users whose passwords should be changed. */
238 if(count($this->pwd_change_queue)){
239 $s_entry= array_pop($this->pwd_change_queue);
240 }
242 if(!empty($this->CPPasswordChange)){
243 $s_entry = $this->CPPasswordChange;
244 $this->CPPasswordChange = "";
245 }
247 /* Get 'dn' from posted 'uid' */
248 $this->dn= $this->list[trim($s_entry)]['dn'];
250 /* Load permissions for selected 'dn' and check if
251 we're allowed to remove this 'dn' */
252 if (preg_match("/w/",$this->ui->get_permissions($this->dn,"users/password"))){
254 /* User is allowed to change passwords, save 'dn' and 'acl' for next
255 dialog. */
256 $_SESSION['objectinfo']= $this->dn;
257 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
260 } else {
261 /* User is not allowed. Show message and cancel. */
262 msg_dialog::display(_("Password change"),_("You are not allowed to set this users password!"),WARNING_DIALOG);
263 }
264 }
269 /********************
270 Edit existing entry
271 ********************/
273 /* User wants to edit data? */
274 if (($s_action == "multiple_edit" || $s_action=="edit") && (!isset($this->usertab->config))){
276 $this->dn = array();
277 /* Get 'dn' from posted 'uid', must be unique */
278 if($s_action == "multiple_edit"){
279 foreach($this->list_get_selected_items() as $id){
280 $this->dn[] = $this->list[trim($id)]['dn'];
281 }
282 }else{
283 $this->dn= array($this->list[trim($s_entry)]['dn']);
284 }
286 /* Check locking, save current plugin in 'back_plugin', so
287 the dialog knows where to return. */
288 $users= get_multiple_locks($this->dn);
289 if (count($users)){
290 return(gen_locked_message($users, $this->dn));
291 }
293 /* Lock the current entry, so everyone will get the
294 above dialog */
295 add_lock ($this->dn, $this->ui->dn);
297 /* Register usertab to trigger edit dialog */
298 $tbs = new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
300 if($tbs){
301 $this->usertab = $tbs;
303 /* Switch tab, if it was requested by the user */
304 $this->usertab->current = $s_tab;
306 /* Set ACL and move DN to the headline */
307 if(count($this->dn) == 1){
308 reset($this->dn) ;
309 $dn = current($this->dn);
310 $this->usertab->set_acl_base($dn);
311 $_SESSION['objectinfo'] = $dn;
312 }else{
313 $_SESSION['objectinfo']= _("Multiple edit");
314 }
315 }
316 }
319 /********************
320 Edit canceled
321 ********************/
323 /* Reset all relevant data, if we get a _cancel request */
324 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
325 if (isset($this->usertab)){
326 del_lock ($this->usertab->dn);
327 unset ($this->usertab);
328 }
329 $this->usertab= NULL;
330 $this->lognames= array();;
331 $this->sn= "";
332 $this->givenName= "";
333 $this->uid= "";
334 unset ($_SESSION['objectinfo']);
335 }
338 /********************
339 Delete MULTIPLE entries requested, display confirm dialog
340 ********************/
342 if ($s_action=="del_multiple"){
343 $ids = $this->list_get_selected_items();
344 $this->dns = array();
345 if(count($ids)){
347 foreach($ids as $id){
348 $dn = $this->list[$id]['dn'];
349 if (($user= get_lock($dn)) != ""){
350 return(gen_locked_message ($user, $dn));
351 }
352 $this->dns[$id] = $dn;
353 }
355 $dns_names = "<br><pre>";
356 foreach($this->dns as $dn){
357 $dns_names .= $dn."\n";
358 }
359 $dns_names .="</pre>";
361 /* Lock the current entry, so nobody will edit it during deletion */
362 if (count($this->dns) == 1){
363 $info = sprintf(_("You're about to delete the following entry: %s"), @LDAP::fix($dns_names));
364 } else {
365 $info = sprintf(_("You're about to delete the following entries: %s"), @LDAP::fix($dns_names));
366 }
367 $this->msg_dialog = new msg_dialog(_("Delete users"),$info,CONFIRM_DIALOG);
368 $this->current_action = $s_action;
369 }
370 }
373 /********************
374 Delete MULTIPLE entries confirmed
375 ********************/
377 /* Confirmation for deletion has been passed. Users should be deleted. */
378 if ($this->current_action == "del_multiple" && is_object($this->msg_dialog) && $this->msg_dialog->is_confirmed()){
380 $this->current_action = "";
382 /* Remove user by user and check acls before removeing them */
383 foreach($this->dns as $key => $dn){
385 $acl = $this->ui->get_permissions($dn, "users/user");
386 if (preg_match('/d/', $acl)){
388 /* Delete request is permitted, perform LDAP action */
389 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$dn);
390 $this->usertab->set_acl_base();
391 $this->usertab->delete ();
392 unset ($this->usertab);
393 $this->usertab= NULL;
394 } else {
395 msg_dialog::display(_("User delete"),sprintf(_("You are not allowed to delete the user '%s'!"),$dn),WARNING_DIALOG);
396 if(isset($this->ui->uid)){
397 new log("security","users/".get_class($this),$dn,array(),"Tried to trick deletion.");
398 }
399 }
400 /* Remove lock file after successfull deletion */
401 del_lock ($dn);
402 unset($this->dns[$key]);
403 }
404 }
407 /********************
408 Delete MULTIPLE entries Canceled
409 ********************/
411 /* Remove lock */
412 if(isset($_POST['delete_multiple_user_cancel'])){
413 foreach($this->dns as $key => $dn){
414 del_lock ($dn);
415 unset($this->dns[$key]);
416 }
417 }
420 /********************
421 Toggle lock status for user
422 ********************/
424 if($s_action == "toggle_lock_status" && isset($this->list[$s_entry])){
426 /* Get entry check current status */
427 $val = $this->list[$s_entry];
428 $pwd = $val['userPassword'][0];
430 if(!preg_match("/^\{[^\}]/",$pwd)){
431 trigger_error("Can not deactivate user which is using clear password encryption.");
432 }else{
434 $locked = false;
435 if(preg_match("/^[^\}]*+\}!/",$pwd)){
436 $locked = true;
437 }
439 /* Create ldap array to update status */
440 $attrs = array("userPassword" => $pwd);
441 if($locked){
442 $attrs['userPassword'] = preg_replace("/(^[^\}]+\})!(.*$)/","\\1\\2",$attrs['userPassword']);
443 }else{
444 $attrs['userPassword'] = preg_replace("/(^[^\}]+\})(.*$)/","\\1!\\2",$attrs['userPassword']);
445 }
447 /* Write new status back to ldap */
448 $ldap = $this->config->get_ldap_link();
449 $ldap->cd($val['dn']);
450 $ldap->modify($attrs);
451 if($locked){
452 show_ldap_error($ldap->get_error(),_("Could not set user status from locked to unlocked."));
453 }else{
454 show_ldap_error($ldap->get_error(),_("Could not set user status from unlocked to locked."));
455 }
456 }
457 }
460 /********************
461 Delete entry requested, display confirm dialog
462 ********************/
464 /* Remove user was requested */
465 if ($s_action=="del"){
467 /* Get 'dn' from posted 'uid' */
468 $this->dn= $this->list[trim($s_entry)]['dn'];
470 /* Load permissions for selected 'dn' and check if
471 we're allowed to remove this 'dn' */
473 /* Check locking, save current plugin in 'back_plugin', so
474 the dialog knows where to return. */
475 if (($user= get_lock($this->dn)) != ""){
476 return(gen_locked_message ($user, $this->dn));
477 }
480 /* Lock the current entry, so nobody will edit it during deletion */
481 # add_lock ($this->dn, $this->ui->dn);
482 # $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
483 # $smarty->assign("multiple", false);
484 # return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
485 $this->msg_dialog = new msg_dialog( _("Delete user"),sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)),CONFIRM_DIALOG);
486 $this->current_action = $s_action;
487 }
490 /********************
491 Delete entry confirmed
492 ********************/
494 /* Confirmation for deletion has been passed. User should be deleted. */
495 if ($this->current_action == "del" && is_object($this->msg_dialog) && $this->msg_dialog->is_confirmed()){
497 $this->current_action = "";
499 /* Some nice guy may send this as POST, so we've to check
500 for the permissions again. */
502 $acl = $this->ui->get_permissions($this->dn, "users/user");
504 if (preg_match('/d/', $acl)){
506 /* Delete request is permitted, perform LDAP action */
507 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
508 $this->usertab->set_acl_base();
509 $this->usertab->delete ();
510 unset ($this->usertab);
511 $this->usertab= NULL;
512 msg_dialog::display(_("User delted"),_("User successfully removed."),INFO_DIALOG);
513 } else {
515 /* Normally this shouldn't be reached, send some extra
516 logs to notify the administrator */
517 msg_dialog::display(_("User delete"),_("You are not allowed to delete this user!"),WARNING_DIALOG);
519 if(isset($this->ui->uid)){
520 new log("security","users/".get_class($this),$this->dn,array(),"Tried to trick deletion.");
521 }
522 }
524 /* Remove lock file after successfull deletion */
525 del_lock ($this->dn);
526 }
529 /********************
530 Delete entry Canceled
531 ********************/
533 /* Delete user canceled? */
534 if (isset($_POST['delete_cancel'])){
535 del_lock ($this->dn);
536 }
539 /********************
540 Edit entry finished (Save)
541 ********************/
543 /* Finish user edit is triggered by the tabulator dialog, so
544 the user wants to save edited data. Check and save at this
545 point. */
546 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
548 /* Check tabs, will feed message array */
549 $this->usertab->last= $this->usertab->current;
550 $this->usertab->save_object();
551 $message= $this->usertab->check();
553 /* Save, or display error message? */
554 if (count($message) == 0){
556 /* No errors. Go ahead and prepare to ask for a password
557 in case we're creating a new user. 'dn' will be 'new'
558 in this case. It is set to the correct value later. */
559 if ($this->dn == "new"){
560 $set_pass= 1;
561 } else {
562 $set_pass= 0;
563 }
565 /* Save user data to ldap */
566 if($this->usertab->save() == 1){
567 return;
568 }
570 if (!isset($_POST['edit_apply'])){
571 /* User has been saved successfully, remove lock from LDAP. */
572 if ($this->dn != "new"){
573 del_lock ($this->dn);
574 }
576 /* In case of new users, ask for a password, skip this for templates */
577 if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
578 $this->dn = $this->usertab->dn;
579 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
580 }
582 unset ($this->usertab);
583 $this->usertab= NULL;
584 unset ($_SESSION['objectinfo']);
585 }
586 } else {
587 /* Ok. There seem to be errors regarding to the tab data,
588 show message and continue as usual. */
589 show_errors($message);
590 }
591 }
594 /********************
595 We want to create a new user, so fetch all available user templates
596 ********************/
598 /* Generate template list */
599 if (($s_action=="new")||($s_action=="create_user_from_tpl")){
601 $this->templates= array();
602 $ldap= $this->config->get_ldap_link();
604 /* Create list of templates */
605 foreach ($this->config->departments as $key => $value){
607 /* Get acls from different ou's */
608 $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user") ;
610 /* If creation of a new user is allowed, append this template */
611 if (preg_match("/c/",$acl)){
613 /* Search all templates from the current dn */
614 $ldap->cd (get_people_ou().$value);
615 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
617 /* Append */
618 if ($ldap->count() != 0){
619 while ($attrs= $ldap->fetch()){
620 $this->templates[$ldap->getDN()]=
621 $attrs['uid'][0]." - ".@LDAP::fix($key);
622 }
623 $this->templates['none']= _("none");
624 }
625 }
626 }
628 /* Sort templates */
629 natcasesort ($this->templates);
630 reset ($this->templates);
631 }
634 /********************
635 Create a new user,template, user from template
636 ********************/
638 /* Check selected options for template */
639 if (isset($_POST['template_continue'])){
640 $message = array();
641 if(!isset($_POST['template']) || (empty($_POST['template']))){
642 $message[] = _("Please select a valid template.");
643 }
644 if(!isset($_POST['sn']) || (empty($_POST['sn']))){
645 $message[]= _("The required field 'Name' is not set.");
646 }
647 if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
648 $message[]= _("The required field 'Given name' is not set.");
649 }
651 /* Show error message / continue editing */
652 if (count($message) > 0){
653 show_errors ($message);
655 foreach(array("sn", "givenName", "uid", "template") as $attr){
656 if(isset($_POST[$attr])){
657 $smarty->assign("$attr", $_POST[$attr]);
658 }else{
659 $smarty->assign("$attr", "");
660 }
661 }
662 $smarty->assign("templates",$this->templates);
663 $smarty->assign("got_uid",$this->got_uid);
664 $smarty->assign("edit_uid",false);
665 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
667 }
668 }
670 /* New user/template request */
671 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
672 /* By default we set 'dn' to 'new', all relevant plugins will
673 react on this. */
674 $this->dn= "new";
676 if (isset($this->config->current['IDGEN'])){
677 $this->got_uid= false;
678 } else {
679 $this->got_uid= true;
680 }
682 /* Create new usertab object */
683 $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
684 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
685 $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
687 /* Take care about templates */
688 if ($s_action=="new_tpl"){
689 $this->is_template= TRUE;
690 $this->usertab->set_template_mode ();
691 } else {
692 $this->is_template= FALSE;
693 }
695 /* Use template if there are any of them */
696 if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
697 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
698 $smarty->assign("$attr", $this->$attr);
699 }
700 if ($s_action=="create_user_from_tpl"){
701 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
702 } else {
703 $smarty->assign("template", "none");
704 }
705 $smarty->assign("edit_uid", "");
706 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
707 }
708 }
710 /********************
711 Template selected continue edit
712 ********************/
714 /* Continue template editing */
715 if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
717 $this->sn = $_POST['sn'];
718 $this->givenName = $_POST['givenName'];
720 /* Check for requred values */
721 $message= array();
722 if ($this->sn == "") {
723 $message[]= _("The required field 'Name' is not set.");
724 }
725 if ($this->givenName == "") {
726 $message[]= _("The required field 'Given name' is not set.");
727 }
729 /* Check if dn is used */
730 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
731 $ldap= $this->config->get_ldap_link();
732 $ldap->cd ($dn);
733 $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
734 if ($ldap->count () != 0){
735 $message[]= _("A person with the choosen name is already used in this tree.");
736 }
738 /* Show error message / continue editing */
739 if (count($message) > 0){
740 show_errors ($message);
741 } else {
742 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
743 if (isset($this->config->current['IDGEN']) &&
744 $this->config->current['IDGEN'] != ""){
745 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
746 if (count($uids)){
747 $smarty->assign("edit_uid", "false");
748 $smarty->assign("uids", $uids);
749 $this->uid= current($uids);
750 }
751 } else {
752 $smarty->assign("edit_uid", "");
753 $this->uid= "";
754 }
755 $this->got_uid= true;
756 }
758 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
759 $smarty->assign("$attr", $this->$attr);
760 }
761 if (isset($_POST['template'])){
762 $smarty->assign("template", $_POST['template']);
763 }
764 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
765 }
767 /********************
768 No template selected continue edit
769 ********************/
771 /* No template. Ok. Lets fill data into the normal user dialog */
772 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
773 foreach(array("sn", "givenName", "uid") as $attr){
774 if (isset($_POST[$attr])){
775 $this->usertab->by_object['user']->$attr= $_POST[$attr];
776 }
777 }
778 }
781 /********************
782 Template selected continue edit
783 ********************/
785 /* Finish template preamble */
786 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
788 /* Might not be filled if IDGEN is unset */
789 $this->sn = $_POST['sn'];
790 $this->givenName = $_POST['givenName'];
792 /* Move user supplied data to sub plugins */
793 $this->uid = $_POST['uid'];
794 $this->usertab->uid = $this->uid;
795 $this->usertab->sn = $this->sn;
796 $this->usertab->givenName = $this->givenName;
797 $template_dn = $_POST['template'];
798 $this->usertab->adapt_from_template($template_dn);
799 $template_base = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
800 $this->usertab->by_object['user']->base= $template_base;
801 }
804 /********************
805 If no template was selected set base
806 ********************/
808 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
809 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
810 }
813 /********************
814 Display subdialog
815 ********************/
817 /* Show tab dialog if object is present */
818 if(isset($this->usertab->config)){
819 $display= $this->usertab->execute();
821 /* Don't show buttons if tab dialog requests this */
822 if(isset($this->usertab->by_object)){
824 $dia = FALSE;
825 if(isset($this->usertab->by_object[$this->usertab->current]->dialog)){
826 $dia = $this->usertab->by_object[$this->usertab->current]->dialog;
827 }
829 if(!is_object($dia) && $dia != TRUE){
830 $display.= "<p style=\"text-align:right\">\n";
831 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
832 $display.= " \n";
833 if ($this->dn != "new"){
834 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
835 $display.= " \n";
836 }
837 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
838 $display.= "</p>";
839 }
840 }
841 return ($display);
842 }
844 /* Check if there is a snapshot dialog open */
845 $base = $this->DivListUsers->selectedBase;
846 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
847 return($str);
848 }
850 /* Return rendered main page */
851 /* Display dialog with system list */
852 $this->DivListUsers->parent = $this;
853 $this->DivListUsers->execute();
855 /* Add departments if subsearch is disabled */
856 if(!$this->DivListUsers->SubSearch){
857 $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4,1);
858 }
859 $this->reload();
860 $this->DivListUsers->setEntries($this->list);
861 return($this->DivListUsers->Draw());
862 }
865 /* Return departments, that will be included within snapshot detection */
866 function get_used_snapshot_bases()
867 {
868 return(array(get_people_ou().$this->DivListUsers->selectedBase));
869 }
872 function reload()
873 {
874 /* Set base for all searches */
875 $base= $this->DivListUsers->selectedBase;
876 $this->list =array();
878 /* Get filter configuration */
879 $Regex = $this->DivListUsers->Regex;
880 $SubSearch = $this->DivListUsers->SubSearch;
881 $ShowTemplates = $this->DivListUsers->ShowTemplates;
882 $ShowFunctionalUsers = $this->DivListUsers->ShowFunctionalUsers;
883 $ShowUnixUsers = $this->DivListUsers->ShowUnixUsers;
884 $ShowMailUsers = $this->DivListUsers->ShowMailUsers;
885 $ShowSambaUsers = $this->DivListUsers->ShowSambaUsers;
886 $ShowProxyUsers = $this->DivListUsers->ShowProxyUsers;
888 /* Setup filter depending on selection */
889 $filter="";
890 if ($this->config->current['SAMBAVERSION'] == 3){
891 $samba= "sambaSamAccount";
892 } else {
893 $samba= "sambaAccount";
894 }
896 if ($ShowFunctionalUsers){
897 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
898 "(objectClass=gosaMailAccount)(objectClass=$samba)".
899 "(objectClass=gosaProxyAccount))))";
900 }
901 if ($ShowUnixUsers){
902 $filter.= "(objectClass=posixAccount)";
903 }
904 if ($ShowMailUsers){
905 $filter.= "(objectClass=gosaMailAccount)";
906 }
907 if ($ShowSambaUsers){
908 $filter.= "(objectClass=$samba)";
909 }
910 if ($ShowProxyUsers){
911 $filter.= "(objectClass=gosaProxyAccount)";
912 }
913 if ($ShowTemplates){
914 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
915 } else {
916 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
917 }
918 $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
920 /* Generate userlist */
921 $ldap= $this->config->get_ldap_link(TRUE);
923 if ($SubSearch){
924 $ListTemp = get_list($filter, "users", $base,
925 array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SUBSEARCH | GL_SIZELIMIT);
926 } else {
927 $base= get_people_ou().$base;
928 $ListTemp = get_list($filter, "users", $base,
929 array("uid", "givenName", "sn", "objectClass","userPassword"), GL_SIZELIMIT);
930 }
931 $SortTemp = array();
932 $List = array();
933 foreach($ListTemp as $Key => $Entry){
935 /* Skip entries that are not located under the people ou (normaly 'ou=people,')
936 * Else winstations will be listed too, if you use the subtree flag.
937 */
938 if(!preg_match("/".normalizePreg(get_people_ou())."/i",$Entry['dn'])){
939 continue;
940 }else{
942 // Generate caption for rows
943 if (isset($Entry["sn"]) && isset($Entry["givenName"])){
944 $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
945 } else {
946 $display= "[".$Entry["uid"][0]."]";
947 }
949 $display = strtolower($display);
950 $List[$display] = $Entry;
951 $SortTemp[$display] = $display;
952 }
953 }
954 sort($SortTemp);
955 reset($SortTemp);
957 $this->list = array();
958 foreach($SortTemp as $Key){
959 $this->list[] = $List[$Key];
960 }
961 }
963 function remove_lock()
964 {
965 /* Remove user lock if a DN is marked as "currently edited" */
966 if (isset($this->usertab->dn)){
967 del_lock ($this->usertab->dn);
968 }
969 }
972 function copyPasteHandling_from_queue($s_action,$s_entry)
973 {
974 /* Check if Copy & Paste is disabled */
975 if(!is_object($this->CopyPasteHandler)){
976 return("");
977 }
979 /* Add a single entry to queue */
980 if($s_action == "cut" || $s_action == "copy"){
981 /* Cleanup object queue */
982 $this->CopyPasteHandler->cleanup_queue();
983 $dn = $this->list[$s_entry]['dn'];
984 $this->CopyPasteHandler->add_to_queue($dn,$s_action,"usertabs","USERTABS","users");
985 }
987 /* Add entries to queue */
988 if($s_action == "copy_multiple" || $s_action == "cut_multiple"){
990 /* Cleanup object queue */
991 $this->CopyPasteHandler->cleanup_queue();
993 /* Add new entries to CP queue */
994 foreach($this->list_get_selected_items() as $id){
995 $dn = $this->list[$id]['dn'];
997 if($s_action == "copy_multiple"){
998 $this->CopyPasteHandler->add_to_queue($dn,"copy","usertabs","USERTABS","users");
999 }
1000 if($s_action == "cut_multiple"){
1001 $this->CopyPasteHandler->add_to_queue($dn,"cut","usertabs","USERTABS","users");
1002 }
1003 }
1004 }
1006 /* Start pasting entries */
1007 if($s_action == "editPaste"){
1008 $this->start_pasting_copied_objects = TRUE;
1009 }
1011 /* Return C&P dialog */
1012 if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){
1014 /* Load entry from queue and set base */
1015 $this->CopyPasteHandler->load_entry_from_queue();
1016 $this->CopyPasteHandler->SetVar("base",$this->DivListUsers->selectedBase);
1018 /* Get dialog */
1019 $data = $this->CopyPasteHandler->execute();
1021 /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
1022 if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
1023 $s_entry = $this->CopyPasteHandler->last_entry();
1024 $this->reload();
1025 foreach($this->list as $key => $entry){
1026 if($entry['dn'] == $s_entry){
1027 $this->CPPasswordChange = $key;
1028 }
1029 }
1030 }
1032 /* Return dialog data */
1033 if(!empty($data) && $this->CPPasswordChange == ""){
1034 return($data);
1035 }
1036 }
1038 /* Automatically disable status for pasting */
1039 if(!$this->CopyPasteHandler->entries_queued()){
1040 $this->start_pasting_copied_objects = FALSE;
1041 }
1042 return("");
1043 }
1046 function save_object()
1047 {
1048 /* Handle divlist filter && department selection*/
1049 if(!is_object($this->usertab)){
1050 $this->DivListUsers->save_object();
1051 }
1052 }
1055 function list_get_selected_items()
1056 {
1057 $ids = array();
1058 foreach($_POST as $name => $value){
1059 if(preg_match("/^item_selected_[0-9]*$/",$name)){
1060 $id = preg_replace("/^item_selected_/","",$name);
1061 $ids[$id] = $id;
1062 }
1063 }
1064 return($ids);
1065 }
1068 /* A set of disabled and therefore overloaded functions. They are
1069 not needed in this class. */
1070 function remove_from_parent() { }
1071 function check() { }
1072 function save() { }
1073 function adapt_from_template($dn) { }
1074 function password_change_needed() { }
1076 } /* ... class userManagement */
1077 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1078 ?>