b1c2c1b2b519ec1cef8151cc422d19733a23ea76
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 $acl = "";
35 var $templates = array();
36 var $got_uid = false;
37 var $CopyPasteHandler = NULL;
38 var $CPPasswordChange = ""; // Contains the entry id which should get a new password
39 var $DivListUsers;
41 function userManagement($config, $ui)
42 {
43 /* Save configuration for internal use */
44 $this->config= $config;
45 $this->ui= $ui;
47 /* Copy & Paste handler */
48 if ($this->config->boolValueIsTrue("main", "enableCopyPaste")){
49 $this->CopyPasteHandler= new CopyPasteHandler($this->config);
50 }
52 /* Creat dialog object */
53 $this->DivListUsers = new divListUsers($this->config,$this);
55 }
58 function execute()
59 {
60 /* Call parent execute */
61 plugin::execute();
63 /* LOCK MESSAGE Vars */
64 $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/");
66 $smarty = get_smarty(); // Smarty instance
67 $s_action = ""; // Contains the action to be taken
68 $s_entry = ""; // The value for s_action
70 /* Edit entry button pressed? */
71 if( isset($_GET['act']) && $_GET['act'] == "edit_entry" ){
72 $s_action= "edit";
73 $s_entry= validate($_GET['id']);
74 }
76 /* Test relevant POST values */
77 foreach($_POST as $key => $val){
79 /* Get every possible POST combination and set s_action/s_entry accordingly */
80 foreach(array("del" => "user_del", "edit" => "user_edit",
81 "new" => "user_new",
82 "new_tpl" => "user_tplnew",
83 "create_user_from_tpl" => "userfrom_tpl",
84 "change_pw" => "user_chgpw",
85 "editPaste" => "editPaste", "copy" => "copy",
86 "cut" => "cut") as $act => $name){
88 if (preg_match("/".$name.".*/", $key)){
89 $s_action= $act;
90 $s_entry= preg_replace("/".$name."_/i", "", $key);
91 break;
92 }
93 }
95 } /* ...Test POST */
97 /* Remove coordinate prefix from POST, required by some browsers */
98 $s_entry= preg_replace("/_.$/", "", $s_entry);
100 /* Seperate possibly encoded tab and entry, default to tab "user" */
101 if(preg_match("/.*-.*/", $s_entry)){
102 $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
103 $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
104 }else{
105 $s_tab= "user";
106 }
108 /* Some may be active but diabled in gosa.conf. */
109 if(!search_config($this->config->data['TABS'], $s_tab , "CLASS")){
110 $s_tab = "user";
111 }
113 /* Get 'dn' from posted 'uid' */
114 if(in_array_ics($s_action,array("editPaste","cut","copy"))){
116 if(isset($this->list[trim($s_entry)]['dn'])){
117 $dn= $this->list[trim($s_entry)]['dn'];
118 }else{
119 $dn = $this->DivListUsers->selectedBase;
120 }
122 $acl= get_permissions ($dn, $this->ui->subtreeACL);
123 $acl= get_module_permission($acl, "user", $dn);
125 if($acl != "#all#"){
126 print_red (_("You are not allowed to execute this method!"));
127 }else{
128 /* Display the copy & paste dialog, if it is currently open */
129 $ret = $this->copyPasteHandling($s_action,$s_entry);
130 if($ret){
131 return($ret);
132 }
133 }
134 }
137 /********************
138 Edit existing entry
139 ********************/
141 /* User wants to edit data? */
142 if (($s_action=="edit") && (!isset($this->usertab->config))){
144 /* Get 'dn' from posted 'uid', must be unique */
145 $this->dn= $this->list[trim($s_entry)]['dn'];
147 /* Check locking, save current plugin in 'back_plugin', so
148 the dialog knows where to return. */
149 if (($user= get_lock($this->dn)) != ""){
150 return(gen_locked_message ($user, $this->dn));
151 }
153 /* Lock the current entry, so everyone will get the
154 above dialog */
155 add_lock ($this->dn, $this->ui->dn);
157 /* Set up the users ACL's for this 'dn' */
158 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
160 /* Register usertab to trigger edit dialog */
161 $this->usertab= new usertabs($this->config,
162 $this->config->data['TABS']['USERTABS'], $this->dn);
164 /* Switch tab, if it was requested by the user */
165 $this->usertab->current = $s_tab;
167 /* Set ACL and move DN to the headline */
168 $this->usertab->set_acl($acl);
169 $_SESSION['objectinfo']= $this->dn;
170 }
173 /********************
174 Edit canceled
175 ********************/
177 /* Reset all relevant data, if we get a _cancel request */
178 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
179 if (isset($this->usertab)){
180 del_lock ($this->usertab->dn);
181 unset ($this->usertab);
182 }
183 $this->usertab= NULL;
184 $this->lognames= array();;
185 $this->sn= "";
186 $this->givenName= "";
187 $this->uid= "";
188 unset ($_SESSION['objectinfo']);
189 }
192 /********************
193 Change password requested
194 ********************/
196 /* Password change requested */
197 if (($s_action == "change_pw") || (!empty($this->CPPasswordChange))){
199 if(!empty($this->CPPasswordChange)){
200 $s_entry = $this->CPPasswordChange;
201 $this->CPPasswordChange = "";
202 }
204 /* Get 'dn' from posted 'uid' */
205 $this->dn= $this->list[trim($s_entry)]['dn'];
207 /* Load permissions for selected 'dn' and check if
208 we're allowed to remove this 'dn' */
209 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
210 $acl= get_module_permission($acl, "user", $this->dn);
211 if (chkacl($acl, "password") == ""){
213 /* User is allowed to change passwords, save 'dn' and 'acl' for next
214 dialog. */
215 $this->acl= $acl;
216 $_SESSION['objectinfo']= $this->dn;
217 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
219 } else {
220 /* User is not allowed. Show message and cancel. */
221 print_red (_("You are not allowed to set this users password!"));
222 }
223 }
226 /********************
227 Change password confirmed
228 ********************/
230 /* Perform password change */
231 if (isset($_POST['password_finish'])){
233 /* For security reasons, check if user is allowed to set password again */
234 if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
236 /* Check input and feed errors into 'message' */
237 $message= array();
239 /* Sanity checks... */
240 if ($_POST['new_password'] != $_POST['repeated_password']){
242 /* Matching passwords in new and repeated? */
243 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
244 } else {
246 /* Empty password is not permitted by default. */
247 if ($_POST['new_password'] == ""){
248 $message[]= _("The password you've entered as 'New password' is empty.");
249 }
250 }
252 /* Errors, or password change? */
253 if (count($message) != 0){
255 /* Show error message and continue editing */
256 show_errors ($message);
257 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
258 }
260 $config= $this->config;
261 $ldap_ui= $this->config->get_ldap_link();
262 if(isset($this->usertab->dn)){
263 $ldap_ui->cat($this->usertab->dn,array("uid"));
264 $user = $ldap_ui->fetch();
265 }else{
266 $ldap_ui->cat($this->dn,array("uid"));
267 $user = $ldap_ui->fetch();
268 }
269 if((is_array($user))&&(isset($user['uid']))){
270 $username= $user['uid'][0];
271 }
273 /* Set password, perform required steps */
274 if ($this->usertab){
275 if ($this->usertab->password_change_needed()){
276 $obj= $this->usertab->by_object['user'];
277 change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
278 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
279 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
280 }
282 gosa_log ("Password for '".$this->usertab->dn."' has been changed");
283 unset($this->usertab);
284 $this->usertab= NULL;
285 }
286 } else {
287 change_password ($this->dn, $_POST['new_password']);
288 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
289 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
290 }
292 gosa_log ("Password for '".$this->dn."' has been changed");
293 }
294 } else {
296 /* Missing permissions, show message */
297 print_red (_("You are not allowed to set this users password!"));
298 }
300 /* Clean session, delete lock */
301 del_lock ($this->dn);
302 unset ($this->usertab);
303 $this->usertab= NULL;
304 $this->lognames= array();;
305 $this->sn= "";
306 $this->givenName= "";
307 $this->uid= "";
308 unset ($_SESSION['objectinfo']);
309 }
312 /********************
313 Delete entry requested, display confirm dialog
314 ********************/
316 /* Remove user was requested */
317 if ($s_action=="del"){
319 /* Get 'dn' from posted 'uid' */
320 $this->dn= $this->list[trim($s_entry)]['dn'];
322 /* Load permissions for selected 'dn' and check if
323 we're allowed to remove this 'dn' */
324 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
325 $this->acl= get_module_permission($acl, "user", $this->dn);
326 if (chkacl($this->acl, "delete") == ""){
328 /* Check locking, save current plugin in 'back_plugin', so
329 the dialog knows where to return. */
330 if (($user= get_lock($this->dn)) != ""){
331 return(gen_locked_message ($user, $this->dn));
332 }
334 /* Lock the current entry, so nobody will edit it during deletion */
335 add_lock ($this->dn, $this->ui->dn);
336 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
337 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
338 } else {
340 /* Obviously the user isn't allowed to delete. Show message and
341 clean session. */
342 print_red (_("You are not allowed to delete this user!"));
343 }
344 }
347 /********************
348 Delete entry confirmed
349 ********************/
351 /* Confirmation for deletion has been passed. User should be deleted. */
352 if (isset($_POST['delete_user_confirm'])){
354 /* Some nice guy may send this as POST, so we've to check
355 for the permissions again. */
356 if (chkacl($this->acl, "delete") == ""){
358 /* Delete request is permitted, perform LDAP action */
359 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
360 $this->usertab->set_acl(array($this->acl));
361 $this->usertab->delete ();
362 gosa_log ("User object '".$this->dn."' has been removed");
363 unset ($this->usertab);
364 $this->usertab= NULL;
365 } else {
367 /* Normally this shouldn't be reached, send some extra
368 logs to notify the administrator */
369 print_red (_("You are not allowed to delete this user!"));
371 if(isset($this->ui->uid)){
372 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
373 }
374 }
376 /* Remove lock file after successfull deletion */
377 del_lock ($this->dn);
378 }
381 /********************
382 Delete entry Canceled
383 ********************/
385 /* Delete user canceled? */
386 if (isset($_POST['delete_cancel'])){
387 del_lock ($this->dn);
388 }
391 /********************
392 Edit entry finished (Save)
393 ********************/
395 /* Finish user edit is triggered by the tabulator dialog, so
396 the user wants to save edited data. Check and save at this
397 point. */
398 if ((isset($_POST['edit_finish'])) && (isset($this->usertab->config))){
400 /* Check tabs, will feed message array */
401 $this->usertab->last= $this->usertab->current;
402 $this->usertab->save_object();
403 $message= $this->usertab->check();
405 /* Save, or display error message? */
406 if (count($message) == 0){
408 /* No errors. Go ahead and prepare to ask for a password
409 in case we're creating a new user. 'dn' will be 'new'
410 in this case. It is set to the correct value later. */
411 if ($this->dn == "new"){
412 $set_pass= 1;
413 } else {
414 $set_pass= 0;
415 }
417 /* Save user data to ldap */
418 if($this->usertab->save() == 1){
419 gosa_log ("User object '".$this->dn."' saving failed.");
420 return;
421 }
422 gosa_log ("User object '".$this->dn."' has been saved");
424 /* User has been saved successfully, remove lock from LDAP. */
425 if ($this->dn != "new"){
426 del_lock ($this->dn);
427 }
429 /* In case of new users, ask for a password, skip this for templates */
430 if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
431 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
432 }
434 unset ($this->usertab);
435 $this->usertab= NULL;
436 unset ($_SESSION['objectinfo']);
437 } else {
438 /* Ok. There seem to be errors regarding to the tab data,
439 show message and continue as usual. */
440 show_errors($message);
441 }
442 }
445 /********************
446 We want to create a new user, so fetch all available user templates
447 ********************/
449 /* Generate template list */
450 if (($s_action=="new")||($s_action=="create_user_from_tpl")){
452 $this->templates= array();
453 $ldap= $this->config->get_ldap_link();
455 /* Create list of templates */
456 foreach ($this->config->departments as $key => $value){
458 /* Get acls from different ou's */
459 $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
460 $acl= get_module_permission($acl, "user", get_people_ou().$value);
462 /* If creation of a new user is allowed, append this template */
463 if (chkacl($acl, "create") == ""){
465 /* Search all templates from the current dn */
466 $ldap->cd (get_people_ou().$value);
467 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
469 /* Append */
470 if ($ldap->count() != 0){
471 while ($attrs= $ldap->fetch()){
472 $this->templates[$ldap->getDN()]=
473 $attrs['uid'][0]." - ".@LDAP::fix($key);
474 }
475 $this->templates['none']= _("none");
476 }
477 }
478 }
480 /* Sort templates */
481 natcasesort ($this->templates);
482 reset ($this->templates);
483 }
486 /********************
487 Create a new user,template, user from template
488 ********************/
490 /* New user/template request */
491 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
492 /* By default we set 'dn' to 'new', all relevant plugins will
493 react on this. */
494 $this->dn= "new";
495 if (isset($this->config->current['IDGEN'])){
496 $this->got_uid= false;
497 } else {
498 $this->got_uid= true;
499 }
501 /* Create new usertab object */
502 $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
503 $this->usertab->set_acl(array(':all'));
504 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
506 /* Take care about templates */
507 if ($s_action=="new_tpl"){
508 $this->is_template= TRUE;
509 $this->usertab->set_template_mode ();
510 } else {
511 $this->is_template= FALSE;
512 }
514 /* Use template if there are any of them */
515 if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
516 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
517 $smarty->assign("$attr", $this->$attr);
518 }
519 if ($s_action=="create_user_from_tpl"){
520 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
521 } else {
522 $smarty->assign("template", "none");
523 }
524 $smarty->assign("edit_uid", "");
525 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
526 }
527 }
529 /********************
530 Template selected continue edit
531 ********************/
533 /* Continue template editing */
534 if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
535 $this->sn = $_POST['sn'];
536 $this->givenName = $_POST['givenName'];
538 /* Check for requred values */
539 $message= array();
540 if ($this->sn == "") {
541 $message[]= _("The required field 'Name' is not set.");
542 }
543 if ($this->givenName == "") {
544 $message[]= _("The required field 'Given name' is not set.");
545 }
547 /* Check if dn is used */
548 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
549 $ldap= $this->config->get_ldap_link();
550 $ldap->cd ($dn);
551 $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
552 if ($ldap->count () != 0){
553 $message[]= _("A person with the choosen name is already used in this tree.");
554 }
556 /* Show error message / continue editing */
557 if (count($message) > 0){
558 show_errors ($message);
559 } else {
560 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
561 if (isset($this->config->current['IDGEN']) &&
562 $this->config->current['IDGEN'] != ""){
563 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
564 if (count($uids)){
565 $smarty->assign("edit_uid", "false");
566 $smarty->assign("uids", $uids);
567 $this->uid= current($uids);
568 }
569 } else {
570 $smarty->assign("edit_uid", "");
571 $this->uid= "";
572 }
573 $this->got_uid= true;
574 }
576 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
577 $smarty->assign("$attr", $this->$attr);
578 }
579 if (isset($_POST['template'])){
580 $smarty->assign("template", $_POST['template']);
581 }
582 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
583 }
586 /********************
587 No template selected continue edit
588 ********************/
590 /* No template. Ok. Lets fill data into the normal user dialog */
591 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
592 foreach(array("sn", "givenName", "uid") as $attr){
593 if (isset($_POST[$attr])){
594 $this->usertab->by_object['user']->$attr= $_POST[$attr];
595 }
596 }
597 }
600 /********************
601 Template selected continue edit
602 ********************/
604 /* Finish template preamble */
605 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
607 /* Might not be filled if IDGEN is unset */
608 $this->sn = $_POST['sn'];
609 $this->givenName = $_POST['givenName'];
611 /* Move user supplied data to sub plugins */
612 $this->uid = $_POST['uid'];
613 $this->usertab->uid = $this->uid;
614 $this->usertab->sn = $this->sn;
615 $this->usertab->givenName = $this->givenName;
616 $template_dn = $_POST['template'];
617 $this->usertab->adapt_from_template($template_dn);
618 $template_base = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
619 $this->usertab->by_object['user']->base= $template_base;
621 /* Set up the users ACL's for this 'dn' */
622 $acl= get_permissions ($template_base, $this->ui->subtreeACL);
623 $this->usertab->set_acl($acl);
624 }
627 /********************
628 If no template was selected set base
629 ********************/
631 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
632 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
633 }
636 /********************
637 Display subdialog
638 ********************/
640 /* Show tab dialog if object is present */
641 if(isset($this->usertab->config)){
642 $display= $this->usertab->execute();
644 /* Don't show buttons if tab dialog requests this */
645 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
646 $display.= "<p style=\"text-align:right\">\n";
647 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Save")."\">\n";
648 $display.= " \n";
649 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
650 $display.= "</p>";
651 }
652 return ($display);
653 }
655 /* Return rendered main page */
656 /* Display dialog with system list */
657 $this->DivListUsers->parent = $this;
658 $this->DivListUsers->execute();
660 /* Add departments if subsearch is disabled */
661 if(!$this->DivListUsers->SubSearch){
662 $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4);
663 }
664 $this->reload();
665 $this->DivListUsers->setEntries($this->list);
666 return($this->DivListUsers->Draw());
667 }
670 function reload()
671 {
672 /* Set base for all searches */
673 $base= $this->DivListUsers->selectedBase;
674 $this->list =array();
676 /* Get filter configuration */
677 $Regex = $this->DivListUsers->Regex;
678 $SubSearch = $this->DivListUsers->SubSearch;
679 $ShowTemplates = $this->DivListUsers->ShowTemplates;
680 $ShowFunctionalUsers = $this->DivListUsers->ShowFunctionalUsers;
681 $ShowUnixUsers = $this->DivListUsers->ShowUnixUsers;
682 $ShowMailUsers = $this->DivListUsers->ShowMailUsers;
683 $ShowSambaUsers = $this->DivListUsers->ShowSambaUsers;
684 $ShowProxyUsers = $this->DivListUsers->ShowProxyUsers;
686 /* Setup filter depending on selection */
687 $filter="";
688 if ($this->config->current['SAMBAVERSION'] == 3){
689 $samba= "sambaSamAccount";
690 } else {
691 $samba= "sambaAccount";
692 }
694 if ($ShowFunctionalUsers){
695 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
696 "(objectClass=gosaMailAccount)(objectClass=$samba)".
697 "(objectClass=gosaProxyAccount))))";
698 }
699 if ($ShowUnixUsers){
700 $filter.= "(objectClass=posixAccount)";
701 }
702 if ($ShowMailUsers){
703 $filter.= "(objectClass=gosaMailAccount)";
704 }
705 if ($ShowSambaUsers){
706 $filter.= "(objectClass=$samba)";
707 }
708 if ($ShowProxyUsers){
709 $filter.= "(objectClass=gosaProxyAccount)";
710 }
711 if ($ShowTemplates){
712 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
713 } else {
714 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
715 }
716 $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
718 /* Generate userlist */
719 $ldap= $this->config->get_ldap_link(TRUE);
720 if ($SubSearch){
721 $ListTemp = get_list($filter, $this->ui->subtreeACL, $base,
722 array("uid", "givenName", "sn", "objectClass"), GL_SUBSEARCH | GL_SIZELIMIT);
723 } else {
724 $base= get_people_ou().$base;
725 $ListTemp = get_list($filter, $this->ui->subtreeACL, $base,
726 array("uid", "givenName", "sn", "objectClass"), GL_SIZELIMIT);
727 }
728 $SortTemp = array();
729 $List = array();
730 foreach($ListTemp as $Key => $Entry){
731 // Generate caption for rows
732 if (isset($Entry["sn"]) && isset($Entry["givenName"])){
733 $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
734 } else {
735 $display= "[".$Entry["uid"][0]."]";
736 }
738 $display = strtolower($display);
739 $List[$display] = $Entry;
740 $SortTemp[$display] = $display;
741 }
742 sort($SortTemp);
743 reset($SortTemp);
745 $this->list = array();
746 foreach($SortTemp as $Key){
747 $this->list[] = $List[$Key];
748 }
749 }
751 function remove_lock()
752 {
753 /* Remove user lock if a DN is marked as "currently edited" */
754 if (isset($this->usertab->dn)){
755 del_lock ($this->usertab->dn);
756 }
757 }
760 /* Perform copy & paste requests
761 If copy&paste is in progress this returns a dialog to fix required attributes
762 */
763 function copyPasteHandling($s_action,$s_entry)
764 {
765 /* Only perform copy/paste if it is enabled */
766 if($this->CopyPasteHandler){
768 /* Prepare current object to be pasted */
769 if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){
771 $this->CopyPasteHandler->save_object();
772 $this->CopyPasteHandler->SetVar("base", $this->DivListUsers->selectedBase);
774 /* Execute copy & paste dialog and display returned data, normaly a dialog which allows
775 us to solve all attribute mismatches for this object.
776 If nothing is returned, copy & paste was succesfully or aborted */
777 if(($ret= $this->CopyPasteHandler->execute())){
778 return ($ret);
779 }
781 /* Use the last dn to search for it's ID in the newly generated list. */
782 $dn= $this->CopyPasteHandler->lastdn;
784 /* Get new user list */
785 $this->reload();
786 foreach($this->list as $id => $entry){
787 if($entry['dn'] == $dn){
788 $s_entry= $id;
789 break;
790 }
791 }
793 /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
794 if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
795 $this->CPPasswordChange = $s_entry;
796 }
797 }
799 /* Copy selected object
800 Create a new empty object and the current selected object.
801 Send both to copy&paste class*/
802 if($s_action == "copy"){
803 $this->CopyPasteHandler->Clear();
804 $dn= $this->list[trim($s_entry)]['dn'];
805 $acl= get_permissions ($dn, $this->ui->subtreeACL);
806 $obj = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
807 $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new");
808 $obj-> set_acl($acl);
809 $objNew-> set_acl($acl);
810 $this->CopyPasteHandler->Copy($obj,$objNew);
811 }
813 /* Cut selected object.
814 Open user object and send it to the copy & paste handler */
815 if($s_action == "cut"){
816 $this->CopyPasteHandler->Clear();
817 $dn= $this->list[trim($s_entry)]['dn'];
818 $acl= get_permissions ($dn, $this->ui->subtreeACL);
819 $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
820 $obj->set_acl($acl);
821 $this->CopyPasteHandler->Cut($obj);
822 }
823 }
824 }
826 function save_object()
827 {
828 /* Handle divlist filter && department selection*/
829 if(!is_object($this->usertab)){
830 $this->DivListUsers->save_object();
831 }
832 }
834 /* A set of disabled and therefore overloaded functions. They are
835 not needed in this class. */
836 function remove_from_parent() { }
837 function check() { }
838 function save() { }
839 function adapt_from_template($dn) { }
840 function password_change_needed() { }
841 function show_header($button_text, $text, $disabled= FALSE) { }
843 } /* ... class userManagement */
844 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
845 ?>