cd3d5a39246042ecb4fe756431cf6c0270382294
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 }
57 function execute()
58 {
59 /* Call parent execute */
60 plugin::execute();
62 /* LOCK MESSAGE Vars */
63 $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/");
65 $smarty = get_smarty(); // Smarty instance
66 $s_action = ""; // Contains the action to be taken
67 $s_entry = ""; // The value for s_action
69 /* Edit entry button pressed? */
70 if( isset($_GET['act']) && $_GET['act'] == "edit_entry" ){
71 $s_action= "edit";
72 $s_entry= validate($_GET['id']);
73 }
75 /* Test relevant POST values */
76 foreach($_POST as $key => $val){
78 /* Get every possible POST combination and set s_action/s_entry accordingly */
79 foreach(array("del" => "user_del", "edit" => "user_edit",
80 "new" => "user_new",
81 "new_tpl" => "user_tplnew",
82 "create_user_from_tpl" => "userfrom_tpl",
83 "change_pw" => "user_chgpw",
84 "editPaste" => "editPaste", "copy" => "copy",
85 "cut" => "cut") as $act => $name){
87 if (preg_match("/".$name.".*/", $key)){
88 $s_action= $act;
89 $s_entry= preg_replace("/".$name."_/i", "", $key);
90 break;
91 }
92 }
94 } /* ...Test POST */
96 /* Remove coordinate prefix from POST, required by some browsers */
97 $s_entry= preg_replace("/_.$/", "", $s_entry);
99 /* Seperate possibly encoded tab and entry, default to tab "user" */
100 if(preg_match("/.*-.*/", $s_entry)){
101 $s_tab= preg_replace("/^[^-]*-/i", "" ,$s_entry);
102 $s_entry= preg_replace("/-[^-]*$/i", "", $s_entry);
103 }else{
104 $s_tab= "user";
105 }
107 /* Display the copy & paste dialog, if it is currently open */
108 $ret = $this->copyPasteHandling($s_action,$s_entry);
109 if($ret){
110 return($ret);
111 }
114 /********************
115 Edit existing entry
116 ********************/
118 /* User wants to edit data? */
119 if (($s_action=="edit") && (!isset($this->usertab->config))){
121 /* Get 'dn' from posted 'uid', must be unique */
122 $this->dn= $this->list[trim($s_entry)]['dn'];
124 /* Check locking, save current plugin in 'back_plugin', so
125 the dialog knows where to return. */
126 if (($user= get_lock($this->dn)) != ""){
127 return(gen_locked_message ($user, $this->dn));
128 }
130 /* Lock the current entry, so everyone will get the
131 above dialog */
132 add_lock ($this->dn, $this->ui->dn);
134 /* Register usertab to trigger edit dialog */
135 $this->usertab= new usertabs($this->config,
136 $this->config->data['TABS']['USERTABS'], $this->dn);
138 /* Switch tab, if it was requested by the user */
139 $this->usertab->current = $s_tab;
141 /* Set ACL and move DN to the headline */
142 $this->usertab->set_acl_base($this->dn);
143 $_SESSION['objectinfo']= $this->dn;
144 }
147 /********************
148 Edit canceled
149 ********************/
151 /* Reset all relevant data, if we get a _cancel request */
152 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
153 if (isset($this->usertab)){
154 del_lock ($this->usertab->dn);
155 unset ($this->usertab);
156 }
157 $this->usertab= NULL;
158 $this->lognames= array();;
159 $this->sn= "";
160 $this->givenName= "";
161 $this->uid= "";
162 unset ($_SESSION['objectinfo']);
163 }
166 /********************
167 Change password requested
168 ********************/
170 /* Password change requested */
171 if (($s_action == "change_pw") || (!empty($this->CPPasswordChange))){
173 if(!empty($this->CPPasswordChange)){
174 $s_entry = $this->CPPasswordChange;
175 $this->CPPasswordChange = "";
176 }
178 /* Get 'dn' from posted 'uid' */
179 $this->dn= $this->list[trim($s_entry)]['dn'];
181 /* Load permissions for selected 'dn' and check if
182 we're allowed to remove this 'dn' */
183 if (preg_match("/w/",$this->ui->get_permissions($this->dn,"users/password"))){
185 /* User is allowed to change passwords, save 'dn' and 'acl' for next
186 dialog. */
187 $_SESSION['objectinfo']= $this->dn;
188 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
190 } else {
191 /* User is not allowed. Show message and cancel. */
192 print_red (_("You are not allowed to set this users password!"));
193 }
194 }
197 /********************
198 Change password confirmed
199 ********************/
201 /* Perform password change */
202 if (isset($_POST['password_finish'])){
204 /* For security reasons, check if user is allowed to set password again */
205 $dn = $this->dn;
206 $acl = $this->ui->get_permissions($dn, "users/password");
207 $cacl= $this->ui->get_permissions($dn, "users/user");
210 if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
212 /* Check input and feed errors into 'message' */
213 $message= array();
215 /* Sanity checks... */
216 if ($_POST['new_password'] != $_POST['repeated_password']){
218 /* Matching passwords in new and repeated? */
219 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
220 } else {
222 /* Empty password is not permitted by default. */
223 if ($_POST['new_password'] == ""){
224 $message[]= _("The password you've entered as 'New password' is empty.");
225 }
226 }
228 /* Errors, or password change? */
229 if (count($message) != 0){
231 /* Show error message and continue editing */
232 show_errors ($message);
233 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
234 }
236 $config= $this->config;
237 $ldap_ui= $this->config->get_ldap_link();
238 if(isset($this->usertab->dn)){
239 $ldap_ui->cat($this->usertab->dn,array("uid"));
240 $user = $ldap_ui->fetch();
241 }else{
242 $ldap_ui->cat($this->dn,array("uid"));
243 $user = $ldap_ui->fetch();
244 }
245 if((is_array($user))&&(isset($user['uid']))){
246 $username= $user['uid'][0];
247 }
249 /* Set password, perform required steps */
250 if ($this->usertab){
251 if ($this->usertab->password_change_needed()){
252 $obj= $this->usertab->by_object['user'];
253 change_password ($this->usertab->dn, $_POST['new_password'],0, $obj->pw_storage);
254 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
255 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
256 }
258 gosa_log ("Password for '".$this->usertab->dn."' has been changed");
259 unset($this->usertab);
260 $this->usertab= NULL;
261 }
262 } else {
263 change_password ($this->dn, $_POST['new_password']);
264 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
265 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
266 }
268 gosa_log ("Password for '".$this->dn."' has been changed");
269 }
270 } else {
272 /* Missing permissions, show message */
273 print_red (_("You are not allowed to set this users password!"));
274 }
275 /* Clean session, delete lock */
276 del_lock ($this->dn);
277 unset ($this->usertab);
278 $this->usertab= NULL;
279 $this->lognames= array();;
280 $this->sn= "";
281 $this->givenName= "";
282 $this->uid= "";
283 unset ($_SESSION['objectinfo']);
284 }
287 /********************
288 Delete entry requested, display confirm dialog
289 ********************/
291 /* Remove user was requested */
292 if ($s_action=="del"){
294 /* Get 'dn' from posted 'uid' */
295 $this->dn= $this->list[trim($s_entry)]['dn'];
297 /* Load permissions for selected 'dn' and check if
298 we're allowed to remove this 'dn' */
300 /* Check locking, save current plugin in 'back_plugin', so
301 the dialog knows where to return. */
302 if (($user= get_lock($this->dn)) != ""){
303 return(gen_locked_message ($user, $this->dn));
304 }
306 /* Lock the current entry, so nobody will edit it during deletion */
307 add_lock ($this->dn, $this->ui->dn);
308 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), @LDAP::fix($this->dn)));
309 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
310 }
313 /********************
314 Delete entry confirmed
315 ********************/
317 /* Confirmation for deletion has been passed. User should be deleted. */
318 if (isset($_POST['delete_user_confirm'])){
320 /* Some nice guy may send this as POST, so we've to check
321 for the permissions again. */
323 $acl = $this->ui->get_permissions($this->dn, "users/user");
325 if (preg_match('/d/', $acl)){
327 /* Delete request is permitted, perform LDAP action */
328 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],$this->dn);
329 $this->usertab->set_acl_base();
330 $this->usertab->delete ();
331 gosa_log ("User object '".$this->dn."' has been removed");
332 unset ($this->usertab);
333 $this->usertab= NULL;
334 } else {
336 /* Normally this shouldn't be reached, send some extra
337 logs to notify the administrator */
338 print_red (_("You are not allowed to delete this user!"));
340 if(isset($this->ui->uid)){
341 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
342 }
343 }
345 /* Remove lock file after successfull deletion */
346 del_lock ($this->dn);
347 }
350 /********************
351 Delete entry Canceled
352 ********************/
354 /* Delete user canceled? */
355 if (isset($_POST['delete_cancel'])){
356 del_lock ($this->dn);
357 }
360 /********************
361 Edit entry finished (Save)
362 ********************/
364 /* Finish user edit is triggered by the tabulator dialog, so
365 the user wants to save edited data. Check and save at this
366 point. */
367 if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->usertab->config))){
369 /* Check tabs, will feed message array */
370 $this->usertab->last= $this->usertab->current;
371 $this->usertab->save_object();
372 $message= $this->usertab->check();
374 /* Save, or display error message? */
375 if (count($message) == 0){
377 /* No errors. Go ahead and prepare to ask for a password
378 in case we're creating a new user. 'dn' will be 'new'
379 in this case. It is set to the correct value later. */
380 if ($this->dn == "new"){
381 $set_pass= 1;
382 } else {
383 $set_pass= 0;
384 }
386 /* Save user data to ldap */
387 if($this->usertab->save() == 1){
388 gosa_log ("User object '".$this->dn."' saving failed.");
389 return;
390 }
391 gosa_log ("User object '".$this->dn."' has been saved");
393 if (!isset($_POST['edit_apply'])){
394 /* User has been saved successfully, remove lock from LDAP. */
395 if ($this->dn != "new"){
396 del_lock ($this->dn);
397 }
399 /* In case of new users, ask for a password, skip this for templates */
400 if (($set_pass || $this->usertab->password_change_needed()) && !$this->is_template){
401 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
402 }
404 unset ($this->usertab);
405 $this->usertab= NULL;
406 unset ($_SESSION['objectinfo']);
407 }
408 } else {
409 /* Ok. There seem to be errors regarding to the tab data,
410 show message and continue as usual. */
411 show_errors($message);
412 }
413 }
416 /********************
417 We want to create a new user, so fetch all available user templates
418 ********************/
420 /* Generate template list */
421 if (($s_action=="new")||($s_action=="create_user_from_tpl")){
423 $this->templates= array();
424 $ldap= $this->config->get_ldap_link();
426 /* Create list of templates */
427 foreach ($this->config->departments as $key => $value){
429 /* Get acls from different ou's */
430 $acl = $this->ui->get_permissions("cn=dummy,".get_people_ou().$value,"users/user") ;
432 /* If creation of a new user is allowed, append this template */
433 if (preg_match("/c/",$acl)){
435 /* Search all templates from the current dn */
436 $ldap->cd (get_people_ou().$value);
437 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
439 /* Append */
440 if ($ldap->count() != 0){
441 while ($attrs= $ldap->fetch()){
442 $this->templates[$ldap->getDN()]=
443 $attrs['uid'][0]." - ".@LDAP::fix($key);
444 }
445 $this->templates['none']= _("none");
446 }
447 }
448 }
450 /* Sort templates */
451 natcasesort ($this->templates);
452 reset ($this->templates);
453 }
456 /********************
457 Create a new user,template, user from template
458 ********************/
460 /* Check selected options for template */
461 if (isset($_POST['template_continue'])){
462 $message = array();
463 if(!isset($_POST['template']) || (empty($_POST['template']))){
464 $message[] = _("Please select a valid template.");
465 }
466 if(!isset($_POST['sn']) || (empty($_POST['sn']))){
467 $message[]= _("The required field 'Name' is not set.");
468 }
469 if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
470 $message[]= _("The required field 'Given name' is not set.");
471 }
473 /* Show error message / continue editing */
474 if (count($message) > 0){
475 show_errors ($message);
477 foreach(array("sn", "givenName", "uid", "template") as $attr){
478 if(isset($_POST[$attr])){
479 $smarty->assign("$attr", $_POST[$attr]);
480 }else{
481 $smarty->assign("$attr", "");
482 }
483 }
484 $smarty->assign("templates",$this->templates);
485 $smarty->assign("got_uid",$this->got_uid);
486 $smarty->assign("edit_uid",false);
487 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
489 }
490 }
492 /* New user/template request */
493 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
494 /* By default we set 'dn' to 'new', all relevant plugins will
495 react on this. */
496 $this->dn= "new";
498 if (isset($this->config->current['IDGEN'])){
499 $this->got_uid= false;
500 } else {
501 $this->got_uid= true;
502 }
504 /* Create new usertab object */
505 $this->usertab= new usertabs($this->config,$this->config->data['TABS']['USERTABS'], $this->dn);
506 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
507 $this->usertab->set_acl_base('dummy,'.$this->DivListUsers->selectedBase);
509 /* Take care about templates */
510 if ($s_action=="new_tpl"){
511 $this->is_template= TRUE;
512 $this->usertab->set_template_mode ();
513 } else {
514 $this->is_template= FALSE;
515 }
517 /* Use template if there are any of them */
518 if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
519 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
520 $smarty->assign("$attr", $this->$attr);
521 }
522 if ($s_action=="create_user_from_tpl"){
523 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
524 } else {
525 $smarty->assign("template", "none");
526 }
527 $smarty->assign("edit_uid", "");
528 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
529 }
530 }
532 /********************
533 Template selected continue edit
534 ********************/
536 /* Continue template editing */
537 if ((isset($_POST['template_continue'])) && ($_POST['template'] != 'none') && (!isset($_POST['uid']))){
539 $this->sn = $_POST['sn'];
540 $this->givenName = $_POST['givenName'];
542 /* Check for requred values */
543 $message= array();
544 if ($this->sn == "") {
545 $message[]= _("The required field 'Name' is not set.");
546 }
547 if ($this->givenName == "") {
548 $message[]= _("The required field 'Given name' is not set.");
549 }
551 /* Check if dn is used */
552 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
553 $ldap= $this->config->get_ldap_link();
554 $ldap->cd ($dn);
555 $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
556 if ($ldap->count () != 0){
557 $message[]= _("A person with the choosen name is already used in this tree.");
558 }
560 /* Show error message / continue editing */
561 if (count($message) > 0){
562 show_errors ($message);
563 } else {
564 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
565 if (isset($this->config->current['IDGEN']) &&
566 $this->config->current['IDGEN'] != ""){
567 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
568 if (count($uids)){
569 $smarty->assign("edit_uid", "false");
570 $smarty->assign("uids", $uids);
571 $this->uid= current($uids);
572 }
573 } else {
574 $smarty->assign("edit_uid", "");
575 $this->uid= "";
576 }
577 $this->got_uid= true;
578 }
580 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
581 $smarty->assign("$attr", $this->$attr);
582 }
583 if (isset($_POST['template'])){
584 $smarty->assign("template", $_POST['template']);
585 }
586 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
587 }
589 /********************
590 No template selected continue edit
591 ********************/
593 /* No template. Ok. Lets fill data into the normal user dialog */
594 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
595 foreach(array("sn", "givenName", "uid") as $attr){
596 if (isset($_POST[$attr])){
597 $this->usertab->by_object['user']->$attr= $_POST[$attr];
598 }
599 }
600 }
603 /********************
604 Template selected continue edit
605 ********************/
607 /* Finish template preamble */
608 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
610 /* Might not be filled if IDGEN is unset */
611 $this->sn = $_POST['sn'];
612 $this->givenName = $_POST['givenName'];
614 /* Move user supplied data to sub plugins */
615 $this->uid = $_POST['uid'];
616 $this->usertab->uid = $this->uid;
617 $this->usertab->sn = $this->sn;
618 $this->usertab->givenName = $this->givenName;
619 $template_dn = $_POST['template'];
620 $this->usertab->adapt_from_template($template_dn);
621 $template_base = preg_replace("/^[^,]+,".normalizePreg(get_people_ou())."/", '', $template_dn);
622 $this->usertab->by_object['user']->base= $template_base;
623 }
626 /********************
627 If no template was selected set base
628 ********************/
630 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
631 $this->usertab->by_object['user']->base= $this->DivListUsers->selectedBase;
632 }
635 /********************
636 Display subdialog
637 ********************/
639 /* Show tab dialog if object is present */
640 if(isset($this->usertab->config)){
641 $display= $this->usertab->execute();
643 /* Don't show buttons if tab dialog requests this */
644 if(isset($this->usertab->by_object)){
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\" style=\"width:80px\" value=\""._("Ok")."\">\n";
648 $display.= " \n";
649 if ($this->dn != "new"){
650 $display.= "<input type=submit name=\"edit_apply\" value=\""._("Apply")."\">\n";
651 $display.= " \n";
652 }
653 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
654 $display.= "</p>";
655 }
656 }
657 return ($display);
658 }
660 /* Check if there is a snapshot dialog open */
661 $base = $this->DivListUsers->selectedBase;
662 if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){
663 return($str);
664 }
666 /* Return rendered main page */
667 /* Display dialog with system list */
668 $this->DivListUsers->parent = $this;
669 $this->DivListUsers->execute();
671 /* Add departments if subsearch is disabled */
672 if(!$this->DivListUsers->SubSearch){
673 $this->DivListUsers->AddDepartments($this->DivListUsers->selectedBase,4);
674 }
675 $this->reload();
676 $this->DivListUsers->setEntries($this->list);
677 return($this->DivListUsers->Draw());
678 }
681 /* Return departments, that will be included within snapshot detection */
682 function get_used_snapshot_bases()
683 {
684 return(array(get_people_ou().$this->DivListUsers->selectedBase));
685 }
688 function reload()
689 {
690 /* Set base for all searches */
691 $base= $this->DivListUsers->selectedBase;
692 $this->list =array();
694 /* Get filter configuration */
695 $Regex = $this->DivListUsers->Regex;
696 $SubSearch = $this->DivListUsers->SubSearch;
697 $ShowTemplates = $this->DivListUsers->ShowTemplates;
698 $ShowFunctionalUsers = $this->DivListUsers->ShowFunctionalUsers;
699 $ShowUnixUsers = $this->DivListUsers->ShowUnixUsers;
700 $ShowMailUsers = $this->DivListUsers->ShowMailUsers;
701 $ShowSambaUsers = $this->DivListUsers->ShowSambaUsers;
702 $ShowProxyUsers = $this->DivListUsers->ShowProxyUsers;
704 /* Setup filter depending on selection */
705 $filter="";
706 if ($this->config->current['SAMBAVERSION'] == 3){
707 $samba= "sambaSamAccount";
708 } else {
709 $samba= "sambaAccount";
710 }
712 if ($ShowFunctionalUsers){
713 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)".
714 "(objectClass=gosaMailAccount)(objectClass=$samba)".
715 "(objectClass=gosaProxyAccount))))";
716 }
717 if ($ShowUnixUsers){
718 $filter.= "(objectClass=posixAccount)";
719 }
720 if ($ShowMailUsers){
721 $filter.= "(objectClass=gosaMailAccount)";
722 }
723 if ($ShowSambaUsers){
724 $filter.= "(objectClass=$samba)";
725 }
726 if ($ShowProxyUsers){
727 $filter.= "(objectClass=gosaProxyAccount)";
728 }
729 if ($ShowTemplates){
730 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
731 } else {
732 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
733 }
734 $filter= "(&(|(uid=".normalizeLdap($Regex).")(sn=".normalizeLdap($Regex).")(givenName=".normalizeLdap($Regex)."))$filter)";
736 /* Generate userlist */
737 $ldap= $this->config->get_ldap_link(TRUE);
739 if ($SubSearch){
740 $ListTemp = get_list($filter, "users", $base,
741 array("uid", "givenName", "sn", "objectClass"), GL_SUBSEARCH | GL_SIZELIMIT);
742 } else {
743 $base= get_people_ou().$base;
744 $ListTemp = get_list($filter, "users", $base,
745 array("uid", "givenName", "sn", "objectClass"), GL_SIZELIMIT);
746 }
747 $SortTemp = array();
748 $List = array();
749 foreach($ListTemp as $Key => $Entry){
750 // Generate caption for rows
751 if (isset($Entry["sn"]) && isset($Entry["givenName"])){
752 $display= $Entry["sn"][0].", ".$Entry["givenName"][0]." [".$Entry["uid"][0]."]";
753 } else {
754 $display= "[".$Entry["uid"][0]."]";
755 }
757 $display = strtolower($display);
758 $List[$display] = $Entry;
759 $SortTemp[$display] = $display;
760 }
761 sort($SortTemp);
762 reset($SortTemp);
764 $this->list = array();
765 foreach($SortTemp as $Key){
766 $this->list[] = $List[$Key];
767 }
768 }
770 function remove_lock()
771 {
772 /* Remove user lock if a DN is marked as "currently edited" */
773 if (isset($this->usertab->dn)){
774 del_lock ($this->usertab->dn);
775 }
776 }
779 /* Perform copy & paste requests
780 If copy&paste is in progress this returns a dialog to fix required attributes
781 */
782 function copyPasteHandling($s_action,$s_entry)
783 {
784 /* Only perform copy/paste if it is enabled */
785 if($this->CopyPasteHandler){
787 /* Prepare current object to be pasted */
788 if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){
790 $this->CopyPasteHandler->save_object();
791 $this->CopyPasteHandler->SetVar("base", $this->DivListUsers->selectedBase);
793 /* Execute copy & paste dialog and display returned data, normaly a dialog which allows
794 us to solve all attribute mismatches for this object.
795 If nothing is returned, copy & paste was succesfully or aborted */
796 if(($ret= $this->CopyPasteHandler->execute())){
797 return ($ret);
798 }
800 /* Use the last dn to search for it's ID in the newly generated list. */
801 $dn= $this->CopyPasteHandler->lastdn;
803 /* Get new user list */
804 $this->reload();
805 foreach($this->list as $id => $entry){
806 if($entry['dn'] == $dn){
807 $s_entry= $id;
808 break;
809 }
810 }
812 /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */
813 if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){
814 $this->CPPasswordChange = $s_entry;
815 }
816 }
818 /* Copy selected object
819 Create a new empty object and the current selected object.
820 Send both to copy&paste class*/
821 if($s_action == "copy"){
822 $this->CopyPasteHandler->Clear();
823 $dn= $this->list[trim($s_entry)]['dn'];
825 /* Check acl */
826 $acl = $this->ui->get_permissions($dn,"users/user");
827 if(preg_match("/(c.*w|w.*c)/",$acl)){
828 $obj = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
829 $obj->set_acl_base($dn);
830 $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new");
831 $objNew->set_acl_base($dn);
833 $this->CopyPasteHandler->Copy($obj,$objNew);
834 }else{
835 print_red("You are not allowed to copy this entry.");
836 }
837 }
839 /* Cut selected object.
840 Open user object and send it to the copy & paste handler */
841 if($s_action == "cut"){
842 $this->CopyPasteHandler->Clear();
843 $dn= $this->list[trim($s_entry)]['dn'];
845 /* Check acl */
846 $acl = $this->ui->get_permissions($dn,"users/user");
847 if(preg_match("/(c.*w|w.*c)/",$acl)){
848 $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn);
849 $obj->set_acl_base($dn);
850 $this->CopyPasteHandler->Cut($obj);
851 }else{
852 print_red("You are not allowed to cut this entry.");
853 }
854 }
855 }
856 }
858 function save_object()
859 {
860 /* Handle divlist filter && department selection*/
861 if(!is_object($this->usertab)){
862 $this->DivListUsers->save_object();
863 }
864 }
866 /* A set of disabled and therefore overloaded functions. They are
867 not needed in this class. */
868 function remove_from_parent() { }
869 function check() { }
870 function save() { }
871 function adapt_from_template($dn) { }
872 function password_change_needed() { }
874 } /* ... class userManagement */
875 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
876 ?>