1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003-2006 - Cajus Pollmeier <pollmeier@gonicus.de>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 /* Include user tab class */
22 require "tabs_user.inc";
25 class userManagement extends plugin
26 {
27 /* Plugin definitions */
28 var $plHeadline= "Users";
29 var $plDescription= "This does something";
31 /* Dialog attributes */
32 var $usertab = NULL;
33 var $ui = NULL;
34 var $templates = array();
35 var $got_uid = false;
36 var $CopyPasteHandler = NULL;
37 var $CPPasswordChange = ""; // Contains the entry id which should get a new password
38 var $DivListUsers;
40 function userManagement($config, $ui)
41 {
42 /* Save configuration for internal use */
43 $this->config= $config;
44 $this->ui= $ui;
46 /* Copy & Paste handler */
47 if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
48 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
49 }
51 /* Creat dialog object */
52 $this->DivListUsers = new divListUsers($this->config,$this);
54 /* LOCK MESSAGE Vars */
55 $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/");
56 }
59 function execute()
60 {
61 /* Call parent execute */
62 plugin::execute();
64 $smarty = get_smarty(); // Smarty instance
65 $s_action = ""; // Contains the action to be taken
66 $s_entry = ""; // The value for s_action
68 /* Edit entry button pressed? */
69 if( isset($_GET['act']) && $_GET['act'] == "edit_entry" ){
70 $s_action= "edit";
71 $s_entry= validate($_GET['id']);
72 }
74 /* Test relevant POST values */
75 foreach($_POST as $key => $val){
77 /* Get every possible POST combination and set s_action/s_entry accordingly */
78 foreach(array("del" => "user_del", "edit" => "user_edit",
79 "new" => "user_new",
80 "new_tpl" => "user_tplnew",
81 "create_user_from_tpl" => "userfrom_tpl",
82 "change_pw" => "user_chgpw",
83 "editPaste" => "editPaste", "copy" => "copy",
84 "cut" => "cut") as $act => $name){
86 if (preg_match("/".$name.".*/", $key)){
87 $s_action= $act;
88 $s_entry= preg_replace("/".$name."_/i", "", $key);
89 break;
90 }
91 }
93 } /* ...Test POST */
95 /* Remove coordinate prefix from POST, required by some browsers */
96 $s_entry= preg_replace("/_.$/", "", $s_entry);
98 /* Seperate possibly encoded tab and entry, default to tab "user" */
99 if(preg_match("/.*-.*/", $s_entry)){
100 $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
101 $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
102 }else{
103 $s_tab= "user";
104 }
106 /* Display the copy & paste dialog, if it is currently open */
107 $ret = $this->copyPasteHandling($s_action,$s_entry);
108 if($ret){
109 return($ret);
110 }
113 /********************
114 Edit existing entry
115 ********************/
117 /* User wants to edit data? */
118 if (($s_action=="edit") && (!isset($this->usertab->config))){
120 /* Get 'dn' from posted 'uid', must be unique */
121 $this->dn= $this->list[trim($s_entry)]['dn'];
123 /* Check locking, save current plugin in 'back_plugin', so
124 the dialog knows where to return. */
125 if (($user= get_lock($this->dn)) != ""){
126 return(gen_locked_message ($user, $this->dn));
127 }
129 /* Lock the current entry, so everyone will get the
130 above dialog */
131 add_lock ($this->dn, $this->ui->dn);
133 /* Register usertab to trigger edit dialog */
134 $this->usertab= new usertabs($this->config,
135 $this->config->data['TABS']['USERTABS'], $this->dn);
137 /* Switch tab, if it was requested by the user */
138 $this->usertab->current = $s_tab;
140 /* Set ACL and move DN to the headline */
141 $this->usertab->set_acl_base($this->dn);
142 $_SESSION['objectinfo']= $this->dn;
143 }
146 /********************
147 Edit canceled
148 ********************/
150 /* Reset all relevant data, if we get a _cancel request */
151 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
152 if (isset($this->usertab)){
153 del_lock ($this->usertab->dn);
154 unset ($this->usertab);
155 }
156 $this->usertab= NULL;
157 $this->lognames= array();;
158 $this->sn= "";
159 $this->givenName= "";
160 $this->uid= "";
161 unset ($_SESSION['objectinfo']);
162 }
165 /********************
166 Change password requested
167 ********************/
169 /* Password change requested */
170 if (($s_action == "change_pw") || (!empty($this->CPPasswordChange))){
172 if(!empty($this->CPPasswordChange)){
173 $s_entry = $this->CPPasswordChange;
174 $this->CPPasswordChange = "";
175 }
177 /* Get 'dn' from posted 'uid' */
178 $this->dn= $this->list[trim($s_entry)]['dn'];
180 /* Load permissions for selected 'dn' and check if
181 we're allowed to remove this 'dn' */
182 if (preg_match("/w/",$this->ui->get_permissions($this->dn,"users/password"))){
184 /* User is allowed to change passwords, save 'dn' and 'acl' for next
185 dialog. */
186 $_SESSION['objectinfo']= $this->dn;
187 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
189 } else {
190 /* User is not allowed. Show message and cancel. */
191 print_red (_("You are not allowed to set this users password!"));
192 }
193 }
196 /********************
197 Change password confirmed
198 ********************/
200 /* Perform password change */
201 if (isset($_POST['password_finish'])){
203 /* For security reasons, check if user is allowed to set password again */
204 $dn = $this->usertab->dn;
205 $acl = $this->ui->get_permissions($dn, "users/password");
206 $cacl= $this->ui->get_permissions($dn, "users/user");
209 if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
211 /* Check input and feed errors into 'message' */
212 $message= array();
214 /* Sanity checks... */
215 if ($_POST['new_password'] != $_POST['repeated_password']){
217 /* Matching passwords in new and repeated? */
218 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
219 } else {
221 /* Empty password is not permitted by default. */
222 if ($_POST['new_password'] == ""){
223 $message[]= _("The password you've entered as 'New password' is empty.");
224 }
225 }
227 /* Errors, or password change? */
228 if (count($message) != 0){
230 /* Show error message and continue editing */
231 show_errors ($message);
232 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
233 }
235 $config= $this->config;
236 $ldap_ui= $this->config->get_ldap_link();
237 if(isset($this->usertab->dn)){
238 $ldap_ui->cat($this->usertab->dn,array("uid"));
239 $user = $ldap_ui->fetch();
240 }else{
241 $ldap_ui->cat($this->dn,array("uid"));
242 $user = $ldap_ui->fetch();
243 }
244 if((is_array($user))&&(isset($user['uid']))){
245 $username= $user['uid'][0];
246 }
248 /* Set password, perform required steps */
249 if ($this->usertab){
250 if ($this->usertab->password_change_needed()){
251 $obj= $this->usertab->by_object['user'];
252 change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
253 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
254 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
255 }
257 gosa_log ("Password for '".$this->usertab->dn."' has been changed");
258 unset($this->usertab);
259 $this->usertab= NULL;
260 }
261 } else {
262 change_password ($this->dn, $_POST['new_password']);
263 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
264 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
265 }
267 gosa_log ("Password for '".$this->dn."' has been changed");
268 }
269 } else {
271 /* Missing permissions, show message */
272 print_red (_("You are not allowed to set this users password!"));
273 }
274 /* Clean session, delete lock */
275 del_lock ($this->dn);
276 unset ($this->usertab);
277 $this->usertab= NULL;
278 $this->lognames= array();;
279 $this->sn= "";
280 $this->givenName= "";
281 $this->uid= "";
282 unset ($_SESSION['objectinfo']);
283 }
286 /********************
287 Delete entry requested, display confirm dialog
288 ********************/
290 /* Remove user was requested */
291 if ($s_action=="del"){
293 /* Get 'dn' from posted 'uid' */
294 $this->dn= $this->list[trim($s_entry)]['dn'];
296 /* Load permissions for selected 'dn' and check if
297 we're allowed to remove this 'dn' */
299 /* Check locking, save current plugin in 'back_plugin', so
300 the dialog knows where to return. */
301 if (($user= get_lock($this->dn)) != ""){
302 return(gen_locked_message ($user, $this->dn));
303 }
305 /* Lock the current entry, so nobody will edit it during deletion */
306 add_lock ($this->dn, $this->ui->dn);
307 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
308 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
309 }
312 /********************
313 Delete entry confirmed
314 ********************/
316 /* Confirmation for deletion has been passed. User should be deleted. */
317 if (isset($_POST['delete_user_confirm'])){
319 /* Some nice guy may send this as POST, so we've to check
320 for the permissions again. */
322 $acl = $this->ui->get_permissions($this->dn, "users/user");
324 if (preg_match('/d/', $acl)){
326 /* Delete request is permitted, perform LDAP action */
327 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
328 $this->usertab->set_acl_base();
329 $this->usertab->delete ();
330 gosa_log ("User object '".$this->dn."' has been removed");
331 unset ($this->usertab);
332 $this->usertab= NULL;
333 } else {
335 /* Normally this shouldn't be reached, send some extra
336 logs to notify the administrator */
337 print_red (_("You are not allowed to delete this user!"));
339 if(isset($this->ui->uid)){
340 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
341 }
342 }
344 /* Remove lock file after successfull deletion */
345 del_lock ($this->dn);
346 }
349 /********************
350 Delete entry Canceled
351 ********************/
353 /* Delete user canceled? */
354 if (isset($_POST['delete_cancel'])){
355 del_lock ($this->dn);
356 }
359 /********************
360 Edit entry finished (Save)
361 ********************/
363 /* Finish user edit is triggered by the tabulator dialog, so
364 the user wants to save edited data. Check and save at this
365 point. */
366 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
368 /* Check tabs, will feed message array */
369 $this->usertab->last= $this->usertab->current;
370 $this->usertab->save_object();
371 $message= $this->usertab->check();
373 /* Save, or display error message? */
374 if (count($message) == 0){
376 /* No errors. Go ahead and prepare to ask for a password
377 in case we're creating a new user. 'dn' will be 'new'
378 in this case. It is set to the correct value later. */
379 if ($this->dn == "new"){
380 $set_pass= 1;
381 } else {
382 $set_pass= 0;
383 }
385 /* Save user data to ldap */
386 if($this->usertab->save() == 1){
387 gosa_log ("User object '".$this->dn."' saving failed.");
388 return;
389 }
390 gosa_log ("User object '".$this->dn."' has been saved");
392 if (!isset($_POST['edit_apply'])){
393 /* User has been saved successfully, remove lock from LDAP. */
394 if ($this->dn != "new"){
395 del_lock ($this->dn);
396 }
398 /* In case of new users, ask for a password, skip this for templates */
399 if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
400 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
401 }
403 unset ($this->usertab);
404 $this->usertab= NULL;
405 unset ($_SESSION['objectinfo']);
406 }
407 } else {
408 /* Ok. There seem to be errors regarding to the tab data,
409 show message and continue as usual. */
410 show_errors($message);
411 }
412 }
415 /********************
416 We want to create a new user, so fetch all available user templates
417 ********************/
419 /* Generate template list */
420 if (($s_action=="new")||($s_action=="create_user_from_tpl")){
422 $this->templates= array();
423 $ldap= $this->config->get_ldap_link();
425 /* Create list of templates */
426 foreach ($this->config->departments as $key => $value){
428 /* Get acls from different ou's */
429 $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user") ;
431 /* If creation of a new user is allowed, append this template */
432 if (preg_match("/c/",$acl)){
434 /* Search all templates from the current dn */
435 $ldap->cd (get_people_ou().$value);
436 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
438 /* Append */
439 if ($ldap->count() != 0){
440 while ($attrs= $ldap->fetch()){
441 $this->templates[$ldap->getDN()]=
442 $attrs['uid'][0]." - ".@LDAP::fix($key);
443 }
444 $this->templates['none']= _("none");
445 }
446 }
447 }
449 /* Sort templates */
450 natcasesort ($this->templates);
451 reset ($this->templates);
452 }
455 /********************
456 Create a new user,template, user from template
457 ********************/
459 /* Check selected options for template */
460 if (isset($_POST['template_continue'])){
461 $message = array();
462 if(!isset($_POST['template']) || (empty($_POST['template']))){
463 $message[] = _("Please select a valid template.");
464 }
465 if(!isset($_POST['sn']) || (empty($_POST['sn']))){
466 $message[]= _("The required field 'Name' is not set.");
467 }
468 if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
469 $message[]= _("The required field 'Given name' is not set.");
470 }
472 /* Show error message / continue editing */
473 if (count($message) > 0){
474 show_errors ($message);
476 foreach(array("sn", "givenName", "uid", "template") as $attr){
477 if(isset($_POST[$attr])){
478 $smarty->assign("$attr", $_POST[$attr]);
479 }else{
480 $smarty->assign("$attr", "");
481 }
482 }
483 $smarty->assign("templates",$this->templates);
484 $smarty->assign("got_uid",$this->got_uid);
485 $smarty->assign("edit_uid",false);
486 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
488 }
489 }
491 /* New user/template request */
492 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
493 /* By default we set 'dn' to 'new', all relevant plugins will
494 react on this. */
495 $this->dn= "new";
497 if (isset($this->config->current['IDGEN'])){
498 $this->got_uid= false;
499 } else {
500 $this->got_uid= true;
501 }
503 /* Create new usertab object */
504 $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
505 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
506 $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
508 /* Take care about templates */
509 if ($s_action=="new_tpl"){
510 $this->is_template= TRUE;
511 $this->usertab->set_template_mode ();
512 } else {
513 $this->is_template= FALSE;
514 }
516 /* Use template if there are any of them */
517 if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
518 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
519 $smarty->assign("$attr", $this->$attr);
520 }
521 if ($s_action=="create_user_from_tpl"){
522 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
523 } else {
524 $smarty->assign("template", "none");
525 }
526 $smarty->assign("edit_uid", "");
527 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
528 }
529 }
531 /********************
532 Template selected continue edit
533 ********************/
535 /* Continue template editing */
536 if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
538 $this->sn = $_POST['sn'];
539 $this->givenName = $_POST['givenName'];
541 /* Check for requred values */
542 $message= array();
543 if ($this->sn == "") {
544 $message[]= _("The required field 'Name' is not set.");
545 }
546 if ($this->givenName == "") {
547 $message[]= _("The required field 'Given name' is not set.");
548 }
550 /* Check if dn is used */
551 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
552 $ldap= $this->config->get_ldap_link();
553 $ldap->cd ($dn);
554 $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
555 if ($ldap->count () != 0){
556 $message[]= _("A person with the choosen name is already used in this tree.");
557 }
559 /* Show error message / continue editing */
560 if (count($message) > 0){
561 show_errors ($message);
562 } else {
563 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
564 if (isset($this->config->current['IDGEN']) &&
565 $this->config->current['IDGEN'] != ""){
566 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
567 if (count($uids)){
568 $smarty->assign("edit_uid", "false");
569 $smarty->assign("uids", $uids);
570 $this->uid= current($uids);
571 }
572 } else {
573 $smarty->assign("edit_uid", "");
574 $this->uid= "";
575 }
576 $this->got_uid= true;
577 }
579 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
580 $smarty->assign("$attr", $this->$attr);
581 }
582 if (isset($_POST['template'])){
583 $smarty->assign("template", $_POST['template']);
584 }
585 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
586 }
588 /********************
589 No template selected continue edit
590 ********************/
592 /* No template. Ok. Lets fill data into the normal user dialog */
593 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
594 foreach(array("sn", "givenName", "uid") as $attr){
595 if (isset($_POST[$attr])){
596 $this->usertab->by_object['user']->$attr= $_POST[$attr];
597 }
598 }
599 }
602 /********************
603 Template selected continue edit
604 ********************/
606 /* Finish template preamble */
607 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
609 /* Might not be filled if IDGEN is unset */
610 $this->sn = $_POST['sn'];
611 $this->givenName = $_POST['givenName'];
613 /* Move user supplied data to sub plugins */
614 $this->uid = $_POST['uid'];
615 $this->usertab->uid = $this->uid;
616 $this->usertab->sn = $this->sn;
617 $this->usertab->givenName = $this->givenName;
618 $template_dn = $_POST['template'];
619 $this->usertab->adapt_from_template($template_dn);
620 $template_base = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
621 $this->usertab->by_object['user']->base= $template_base;
622 }
625 /********************
626 If no template was selected set base
627 ********************/
629 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
630 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
631 }
634 /********************
635 Display subdialog
636 ********************/
638 /* Show tab dialog if object is present */
639 if(isset($this->usertab->config)){
640 $display= $this->usertab->execute();
642 /* Don't show buttons if tab dialog requests this */
643 if(isset($this->usertab->by_object)){
644 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
645 $display.= "<p style=\"text-align:right\">\n";
646 $display.= "<input type=submit name=\"edit_finish\" style=\"width:80px\" value=\""._("Ok")."\">\n";
647 $display.= " \n";
648 if ($this->dn != "new"){
649 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
650 $display.= " \n";
651 }
652 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
653 $display.= "</p>";
654 }
655 }
656 return ($display);
657 }
659 /* Check if there is a snapshot dialog open */
660 $base = $this->DivListUsers->selectedBase;
661 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
662 return($str);
663 }
665 /* Return rendered main page */
666 /* Display dialog with system list */
667 $this->DivListUsers->parent = $this;
668 $this->DivListUsers->execute();
670 /* Add departments if subsearch is disabled */
671 if(!$this->DivListUsers->SubSearch){
672 $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4);
673 }
674 $this->reload();
675 $this->DivListUsers->setEntries($this->list);
676 return($this->DivListUsers->Draw());
677 }
680 /* Return departments, that will be included within snapshot detection */
681 function get_used_snapshot_bases()
682 {
683 return(array(get_people_ou().$this->DivListUsers->selectedBase));
684 }
687 function reload()
688 {
689 /* Set base for all searches */
690 $base= $this->DivListUsers->selectedBase;
691 $this->list =array();
693 /* Get filter configuration */
694 $Regex = $this->DivListUsers->Regex;
695 $SubSearch = $this->DivListUsers->SubSearch;
696 $ShowTemplates = $this->DivListUsers->ShowTemplates;
697 $ShowFunctionalUsers = $this->DivListUsers->ShowFunctionalUsers;
698 $ShowUnixUsers = $this->DivListUsers->ShowUnixUsers;
699 $ShowMailUsers = $this->DivListUsers->ShowMailUsers;
700 $ShowSambaUsers = $this->DivListUsers->ShowSambaUsers;
701 $ShowProxyUsers = $this->DivListUsers->ShowProxyUsers;
703 /* Setup filter depending on selection */
704 $filter="";
705 if ($this->config->current['SAMBAVERSION'] == 3){
706 $samba= "sambaSamAccount";
707 } else {
708 $samba= "sambaAccount";
709 }
711 if ($ShowFunctionalUsers){
712 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
713 "(objectClass=gosaMailAccount)(objectClass=$samba)".
714 "(objectClass=gosaProxyAccount))))";
715 }
716 if ($ShowUnixUsers){
717 $filter.= "(objectClass=posixAccount)";
718 }
719 if ($ShowMailUsers){
720 $filter.= "(objectClass=gosaMailAccount)";
721 }
722 if ($ShowSambaUsers){
723 $filter.= "(objectClass=$samba)";
724 }
725 if ($ShowProxyUsers){
726 $filter.= "(objectClass=gosaProxyAccount)";
727 }
728 if ($ShowTemplates){
729 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
730 } else {
731 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
732 }
733 $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
735 /* Generate userlist */
736 $ldap= $this->config->get_ldap_link(TRUE);
738 if ($SubSearch){
739 $ListTemp = get_list($filter, "users", $base,
740 array("uid", "givenName", "sn", "objectClass"), GL_SUBSEARCH | GL_SIZELIMIT);
741 } else {
742 $base= get_people_ou().$base;
743 $ListTemp = get_list($filter, "users", $base,
744 array("uid", "givenName", "sn", "objectClass"), GL_SIZELIMIT);
745 }
746 $SortTemp = array();
747 $List = array();
748 foreach($ListTemp as $Key => $Entry){
749 // Generate caption for rows
750 if (isset($Entry["sn"]) && isset($Entry["givenName"])){
751 $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
752 } else {
753 $display= "[".$Entry["uid"][0]."]";
754 }
756 $display = strtolower($display);
757 $List[$display] = $Entry;
758 $SortTemp[$display] = $display;
759 }
760 sort($SortTemp);
761 reset($SortTemp);
763 $this->list = array();
764 foreach($SortTemp as $Key){
765 $this->list[] = $List[$Key];
766 }
767 }
769 function remove_lock()
770 {
771 /* Remove user lock if a DN is marked as "currently edited" */
772 if (isset($this->usertab->dn)){
773 del_lock ($this->usertab->dn);
774 }
775 }
778 /* Perform copy & paste requests
779 If copy&paste is in progress this returns a dialog to fix required attributes
780 */
781 function copyPasteHandling($s_action,$s_entry)
782 {
783 /* Only perform copy/paste if it is enabled */
784 if($this->CopyPasteHandler){
786 /* Prepare current object to be pasted */
787 if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){
789 $this->CopyPasteHandler->save_object();
790 $this->CopyPasteHandler->SetVar("base", $this->DivListUsers->selectedBase);
792 /* Execute copy & paste dialog and display returned data, normaly a dialog which allows
793 us to solve all attribute mismatches for this object.
794 If nothing is returned, copy & paste was succesfully or aborted */
795 if(($ret= $this->CopyPasteHandler->execute())){
796 return ($ret);
797 }
799 /* Use the last dn to search for it's ID in the newly generated list. */
800 $dn= $this->CopyPasteHandler->lastdn;
801 foreach($this->list as $id => $entry){
802 if($entry['dn'] == $dn){
803 $s_entry= $id;
804 break;
805 }
806 }
808 /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
809 if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
810 $this->CPPasswordChange = $s_entry;
811 }
812 }
814 /* Copy selected object
815 Create a new empty object and the current selected object.
816 Send both to copy&paste class*/
817 if($s_action == "copy"){
818 $this->CopyPasteHandler->Clear();
819 $dn= $this->list[trim($s_entry)]['dn'];
821 /* Check acl */
822 $acl = $this->ui->get_permissions($dn,"users/user");
823 if(preg_match("/(c.*w|w.*c)/",$acl)){
824 $obj = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
825 $obj->set_acl_base($dn);
826 $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new");
827 $objNew->set_acl_base($dn);
829 $this->CopyPasteHandler->Copy($obj,$objNew);
830 }else{
831 print_red("You are not allowed to copy this entry.");
832 }
833 }
835 /* Cut selected object.
836 Open user object and send it to the copy & paste handler */
837 if($s_action == "cut"){
838 $this->CopyPasteHandler->Clear();
839 $dn= $this->list[trim($s_entry)]['dn'];
841 /* Check acl */
842 $acl = $this->ui->get_permissions($dn,"users/user");
843 if(preg_match("/(c.*w|w.*c)/",$acl)){
844 $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
845 $obj->set_acl_base($dn);
846 $this->CopyPasteHandler->Cut($obj);
847 }else{
848 print_red("You are not allowed to cut this entry.");
849 }
850 }
851 }
852 }
854 function save_object()
855 {
856 /* Handle divlist filter && department selection*/
857 if(!is_object($this->usertab)){
858 $this->DivListUsers->save_object();
859 }
860 }
862 /* A set of disabled and therefore overloaded functions. They are
863 not needed in this class. */
864 function remove_from_parent() { }
865 function check() { }
866 function save() { }
867 function adapt_from_template($dn) { }
868 function password_change_needed() { }
870 } /* ... class userManagement */
871 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
872 ?>