1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2003 Cajus Pollmeier
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 */
20 require "tabs_user.inc";
22 class userManagement extends plugin
23 {
24 /* Definitions */
25 var $plHeadline= "Users";
26 var $plDescription= "This does something";
28 /* Dialog attributes */
29 var $usertab= NULL;
30 var $userlist= array();
31 var $ui= NULL;
32 var $acl= "";
33 var $templates= array();
34 var $got_uid= false;
35 var $departments=array();
37 function userManagement ($config, $ui)
38 {
39 /* Save configuration for internal use */
40 $this->config= $config;
41 $this->ui= $ui;
44 /* Get global filter config */
45 if (!isset($_SESSION["userfilter"])){
46 $base= get_base_from_people($ui->dn);
47 $userfilter= array( "mailusers" => "checked",
48 "unixusers" => "checked",
49 "templates" => "",
50 "subsearch" => "",
51 "proxyusers" => "checked",
52 "sambausers" => "checked",
53 "faxusers" => "checked",
54 "functionalusers" => "checked",
55 "depselect" => $base,
56 "regex" => "*");
57 $_SESSION["userfilter"] = $userfilter;
58 }
59 }
61 function execute()
62 {
63 /* Call parent execute */
64 plugin::execute();
66 /* LOCK MESSAGE Vars */
67 $_SESSION['LOCK_VARS_TO_USE'] = array("/^act$/","/^id$/","/^user_edit_/","/^user_del_/");
70 $smarty = get_smarty(); // Smarty instance
71 $userfilter = get_global("userfilter"); // contains Filter Settings
72 $s_action = ""; // Contains the action to proceed
73 $s_entry = ""; // The value for s_action
74 $base_back = ""; // The Link for Backbutton
76 /* Start for New List Managment */
77 if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
78 $s_action="open";
79 $s_entry = base64_decode($_GET['dep_id']);
80 $userfilter['depselect']= "".$this->config->departments[trim($s_entry)];
81 }
83 /* Test Posts */
84 foreach($_POST as $key => $val){
85 // Post for delete
86 if(preg_match("/user_del.*/",$key)){
87 $s_action = "del";
88 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
89 // Post for edit
90 }elseif(preg_match("/user_edit_.*/",$key)){
91 $s_action="edit";
92 $s_entry = preg_replace("/user_".$s_action."_/i","",$key);
93 // Post for new
94 }elseif(preg_match("/dep_back.*/i",$key)){
95 $s_action="back";
96 }elseif(preg_match("/user_new.*/",$key)){
97 $s_action="new";
98 }elseif(preg_match("/dep_home.*/i",$key)){
99 $s_action="home";
100 }elseif(preg_match("/user_tplnew.*/i",$key)){
101 $s_action="new_tpl";
102 }elseif(preg_match("/user_chgpw.*/i",$key)){
103 $s_action="change_pw";
104 $s_entry = preg_replace("/user_chgpw_/i","",$key);
105 }elseif(preg_match("/dep_root.*/i",$key)){
106 $s_action="root";
107 }elseif(preg_match("/userfrom_tpl.*/i",$key)){
108 $s_action="create_user_from_tpl";
109 $s_entry = preg_replace("/userfrom_tpl_/i","",$key);
110 }
111 }
113 if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
114 $s_action = "edit";
115 $s_entry = $_GET['id'];
116 }
118 $s_entry = preg_replace("/_.$/","",$s_entry);
120 if(preg_match("/.*-.*/",$s_entry)){
121 $s_tab = preg_replace("/^.*-/i","",$s_entry);
122 $s_entry = preg_replace("/-.*$/i","",$s_entry);
123 }else{
124 $s_tab = "user";
125 };
127 /* Department changed? */
128 if(isset($_POST['depselect']) && $_POST['depselect']){
129 $userfilter['depselect']= $_POST['depselect'];
130 }
132 /* Homebutton is posted */
133 if($s_action=="home"){
134 $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
135 $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$userfilter['depselect']));
136 }
138 if($s_action=="root"){
139 $userfilter['depselect']=($this->config->current['BASE']);
140 }
143 /* If Backbutton is Posted */
144 if($s_action=="back"){
145 $base_back = preg_replace("/^[^,]+,/","",$userfilter['depselect']);
146 $base_back = convert_department_dn($base_back);
148 if(isset($this->config->departments[trim($base_back)])){
149 $userfilter['depselect']= $this->config->departments[trim($base_back)];
150 }else{
151 $userfilter['depselect']= $this->config->departments["/"];
152 }
153 }
155 /* End for new List Managment */
157 /* Save filter data if we are in the headpage */
158 if (!isset($this->usertab)){
159 if (isset($_POST['regexit'])){
160 $userfilter["regex"]= $_POST['regexit'];
161 }
162 }
163 if(isset($_POST['regexit'])){
164 foreach( array("functionalusers", "unixusers", "mailusers","sambausers", "proxyusers", "faxusers", "templates", "subsearch") as $type){
165 if (isset($_POST[$type])) {
166 $userfilter[$type]= "checked";
167 } else {
168 $userfilter[$type]= "";
169 }
170 }
171 }
172 if (isset($_GET['search'])){
173 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
174 if ($s == "**"){
175 $s= "*";
176 }
177 $userfilter['regex']= $s;
178 }
179 register_global("userfilter", $userfilter);
182 /* React on user interaction here */
183 if (($_SERVER["REQUEST_METHOD"] == "POST")||($_SERVER["REQUEST_METHOD"]== "GET")){
185 /* User wants to edit data? */
186 if ($s_action=="edit"){
188 /* Get 'dn' from posted 'uid', must be unique */
190 $this->dn= $this->list[trim($s_entry)]['dn'];
192 /* Check locking, save current plugin in 'back_plugin', so
193 the dialog knows where to return. */
194 if (($user= get_lock($this->dn)) != ""){
195 return(gen_locked_message ($user, $this->dn));
196 }
198 /* Lock the current entry, so everyone will get the
199 above dialog */
200 add_lock ($this->dn, $this->ui->dn);
202 /* Set up the users ACL's for this 'dn' */
203 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
205 /* Register usertab to trigger edit dialog */
206 $this->usertab= new usertabs($this->config,
207 $this->config->data['TABS']['USERTABS'], $this->dn);
208 // $_POST[$s_tab]=$s_tab;
210 // This would be better
211 $this->usertab->current = $s_tab;
212 $this->usertab->set_acl($acl);
214 $_SESSION['objectinfo']= $this->dn;
215 }
216 }
218 /* Reset requested? */
219 if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
220 if (isset($this->usertab)){
221 del_lock ($this->usertab->dn);
222 unset ($this->usertab);
223 }
224 $this->usertab= NULL;
225 $this->lognames= array();;
226 $this->sn= "";
227 $this->givenName= "";
228 $this->uid= "";
229 unset ($_SESSION['objectinfo']);
230 }
232 /* Password change requested */
233 if ($s_action=="change_pw"){
235 /* Get 'dn' from posted 'uid' */
236 $this->dn= $this->list[trim($s_entry)]['dn'];
238 /* Load permissions for selected 'dn' and check if
239 we're allowed to remove this 'dn' */
240 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
241 $acl= get_module_permission($acl, "user", $this->dn);
242 if (chkacl($acl, "password") == ""){
244 /* User is allowed to change passwords, save 'dn' and 'acl' for next
245 dialog. */
246 $this->acl= $acl;
247 $_SESSION['objectinfo']= $this->dn;
248 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
250 } else {
251 /* User is not allowed. Show message and cancel. */
252 print_red (_("You are not allowed to set this users password!"));
253 }
254 }
256 /* Perform password change */
257 if (isset($_POST['password_finish'])){
259 /* For security reasons, check if user is allowed to set password again */
260 if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
262 /* Check input and feed errors into 'message' */
263 $message= array();
265 /* Sanity checks... */
266 if ($_POST['new_password'] != $_POST['repeated_password']){
268 /* Matching passwords in new and repeated? */
269 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
270 } else {
272 /* Empty password is not permitted by default. */
273 if ($_POST['new_password'] == ""){
274 $message[]= _("The password you've entered as 'New password' is empty.");
275 }
276 }
278 /* Errors, or change password? */
279 if (count($message) != 0){
281 /* Show error message and continue editing */
282 show_errors ($message);
283 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
284 }
286 $config= $this->config;
287 $ldap_ui= $this->config->get_ldap_link();
288 if(isset($this->usertab->dn)){
289 $user = ($ldap_ui->fetch($ldap_ui->cat($this->usertab->dn)));
290 }else{
291 $user = ($ldap_ui->fetch($ldap_ui->cat($this->dn)));
292 }
293 if((is_array($user))&&(isset($user['uid']))){
294 $username= $user['uid'][0];
295 }
297 /* Set password, perform required steps */
298 if ($this->usertab){
299 if ($this->usertab->password_change_needed()){
300 $obj= $this->usertab->by_object['user'];
301 change_password ($this->usertab->dn, $_POST['new_password'],
302 0, $obj->pw_storage);
303 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
304 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
305 }
307 gosa_log ("Password for '".$this->usertab->dn."' has been changed");
308 unset($this->usertab);
309 $this->usertab= NULL;
310 }
311 } else {
312 change_password ($this->dn, $_POST['new_password']);
313 if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
314 exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
315 }
317 gosa_log ("Password for '".$this->dn."' has been changed");
318 }
319 } else {
321 /* Missing permissions, show message */
322 print_red (_("You are not allowed to set this users password!"));
323 }
325 /* Clean session, delete lock */
326 del_lock ($this->dn);
327 $this->reload();
328 unset ($this->usertab);
329 $this->usertab= NULL;
330 $this->lognames= array();;
331 $this->sn= "";
332 $this->givenName= "";
333 $this->uid= "";
334 unset ($_SESSION['objectinfo']);
335 }
338 /* Remove user was requested */
339 if ($s_action=="del"){
341 /* Get 'dn' from posted 'uid' */
342 $this->dn= $this->list[trim($s_entry)]['dn'];
344 /* Load permissions for selected 'dn' and check if
345 we're allowed to remove this 'dn' */
346 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
347 $this->acl= get_module_permission($acl, "user", $this->dn);
348 if (chkacl($this->acl, "delete") == ""){
350 /* Check locking, save current plugin in 'back_plugin', so
351 the dialog knows where to return. */
352 if (($user= get_lock($this->dn)) != ""){
353 return(gen_locked_message ($user, $this->dn));
354 }
356 /* Lock the current entry, so nobody will edit it during deletion */
357 add_lock ($this->dn, $this->ui->dn);
358 $smarty->assign("info", sprintf(_("You're about to delete the user %s."), LDAP::fix($this->dn)));
359 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
360 } else {
362 /* Obviously the user isn't allowed to delete. Show message and
363 clean session. */
364 print_red (_("You are not allowed to delete this user!"));
365 }
366 }
370 /* Confirmation for deletion has been passed. User should be deleted. */
371 if (isset($_POST['delete_user_confirm'])){
373 /* Some nice guy may send this as POST, so we've to check
374 for the permissions again. */
375 if (chkacl($this->acl, "delete") == ""){
377 /* Delete request is permitted, perform LDAP action */
378 $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
379 $this->dn);
380 $this->usertab->set_acl(array($this->acl));
381 $this->usertab->delete ();
382 gosa_log ("User object '".$this->dn."' has been removed");
383 unset ($this->usertab);
384 $this->usertab= NULL;
386 /* User list has changed, reload it. */
387 $this->reload ();
388 } else {
390 /* Normally this shouldn't be reached, send some extra
391 logs to notify the administrator */
392 print_red (_("You are not allowed to delete this user!"));
394 if(isset($this->ui->uid)){
395 gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
396 }
397 }
399 /* Remove lock file after successfull deletion */
400 del_lock ($this->dn);
401 }
404 /* Delete user canceled? */
405 if (isset($_POST['delete_cancel'])){
406 del_lock ($this->dn);
407 }
410 /* Finish user edit is triggered by the tabulator dialog, so
411 the user wants to save edited data. Check and save at this
412 point. */
413 if (isset($_POST['edit_finish'])){
415 /* Check tabs, will feed message array */
416 $this->usertab->last= $this->usertab->current;
417 $this->usertab->save_object();
418 $message= $this->usertab->check();
420 /* Save, or display error message? */
421 if (count($message) == 0){
423 /* No errors. Go ahead and prepare to ask for a password
424 in case we're creating a new user. 'dn' will be 'new'
425 in this case. It is set to the correct value later. */
426 if ($this->dn == "new"){
427 $set_pass= 1;
428 } else {
429 $set_pass= 0;
430 }
432 /* Save user data to ldap */
433 if($this->usertab->save() == 1){
434 gosa_log ("User object '".$this->dn."' saving failed.");
435 return;
436 }
437 gosa_log ("User object '".$this->dn."' has been saved");
439 /* User has been saved successfully, remove lock from
440 LDAP. */
441 if ($this->dn != "new"){
442 del_lock ($this->dn);
443 }
445 /* In case of new users, ask for a password */
446 if (($set_pass || $this->usertab->password_change_needed()) &&
447 !$this->is_template){
449 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
450 }
452 /* There's no page reload so we have to read new users at
453 this point. */
454 $this->reload ();
455 unset ($this->usertab);
456 $this->usertab= NULL;
457 unset ($_SESSION['objectinfo']);
459 } else {
460 /* Ok. There seem to be errors regarding to the tab data,
461 show message and continue as usual. */
462 show_errors($message);
463 }
464 }
466 /* Generate template list */
467 if (($s_action=="new")||($s_action=="create_user_from_tpl")){
469 $this->templates= array();
471 $ldap= $this->config->get_ldap_link();
473 /* Create list of tempaltes */
474 foreach ($this->config->departments as $key => $value){
476 /* Get acls from different ou's */
477 $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
478 $acl= get_module_permission($acl, "user", get_people_ou().$value);
480 /* If creation of a new user is allowed, append this template */
481 if (chkacl($acl, "create") == ""){
483 /* Search all templates from the current dn */
484 $ldap->cd (get_people_ou().$value);
485 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
487 /* Append */
488 if ($ldap->count() != 0){
489 while ($attrs= $ldap->fetch()){
490 $this->templates[$ldap->getDN()]=
491 $attrs['uid'][0]." - $key";
492 }
493 $this->templates['none']= _("none");
494 }
495 }
496 }
498 /* Sort templates */
499 natcasesort ($this->templates);
500 reset ($this->templates);
501 }
503 /* New user/template request */
504 if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
505 /* By default we set 'dn' to 'new', all relevant plugins will
506 react on this. */
507 $this->dn= "new";
508 if (isset($this->config->current['IDGEN'])){
509 $this->got_uid= false;
510 } else {
511 $this->got_uid= true;
512 }
514 /* Create new usertab object */
515 $this->usertab= new usertabs($this->config,
516 $this->config->data['TABS']['USERTABS'], $this->dn);
517 $this->usertab->set_acl(array(':all'));
518 $this->usertab->by_object['user']->base= $userfilter['depselect'];
520 /* Take care about templates */
521 if ($s_action=="new_tpl"){
522 $this->is_template= TRUE;
523 $this->usertab->set_template_mode ();
524 } else {
525 $this->is_template= FALSE;
526 }
528 /* Use template if there are any of them */
530 if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
531 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
532 $smarty->assign("$attr", $this->$attr);
533 }
534 if ($s_action=="create_user_from_tpl"){
535 $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
536 } else {
537 $smarty->assign("template", "none");
538 }
539 $smarty->assign("edit_uid", "");
540 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
541 }
542 }
544 /* Continue template editing */
545 if ((isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid']))){
546 $this->sn= $_POST['sn'];
547 $this->givenName= $_POST['givenName'];
549 /* Check for requred values */
550 $message= array();
551 if ($this->sn == "") {
552 $message[]= _("The required field 'Name' is not set.");
553 }
554 if ($this->givenName == "") {
555 $message[]= _("The required field 'Given name' is not set.");
556 }
558 /* Check if dn is used */
559 $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
560 $ldap= $this->config->get_ldap_link();
561 $ldap->cd ($dn);
562 $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
563 if ($ldap->count () != 0){
564 $message[]= _("A person with the choosen name is already used in this tree.");
565 }
567 /* Show error message / continue editing */
568 if (count($message) > 0){
569 show_errors ($message);
570 } else {
571 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
572 if (isset($this->config->current['IDGEN']) &&
573 $this->config->current['IDGEN'] != ""){
574 $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
575 if (count($uids)){
576 $smarty->assign("edit_uid", "false");
577 $smarty->assign("uids", $uids);
578 $this->uid= current($uids);
579 }
580 } else {
581 $smarty->assign("edit_uid", "");
582 $this->uid= "";
583 }
584 $this->got_uid= true;
585 }
587 foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
588 $smarty->assign("$attr", $this->$attr);
589 }
590 if (isset($_POST['template'])){
591 $smarty->assign("template", $_POST['template']);
592 }
593 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
594 }
596 /* No template. Ok. Lets fill data into the normal user dialog */
597 if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
598 foreach(array("sn", "givenName", "uid") as $attr){
599 if (isset($_POST[$attr])){
600 $this->usertab->by_object['user']->$attr= $_POST[$attr];
601 }
602 }
603 }
605 /* Finish template preamble */
606 if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
608 /* Might not be filled if IDGEN is unset */
609 $this->sn = $_POST['sn'];
610 $this->givenName = $_POST['givenName'];
612 /* Move user supplied data to sub plugins */
613 $this->uid = $_POST['uid'];
614 $this->usertab->uid = $this->uid;
615 $this->usertab->sn = $this->sn;
616 $this->usertab->givenName = $this->givenName;
617 $template_dn = $_POST['template'];
618 $this->usertab->adapt_from_template($template_dn);
619 $template_base = preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
620 $this->usertab->by_object['user']->base= $template_base;
622 /* Set up the users ACL's for this 'dn' */
623 $acl= get_permissions ($template_base, $this->ui->subtreeACL);
624 $this->usertab->set_acl($acl);
625 }
627 if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
628 $this->usertab->by_object['user']->base= $userfilter['depselect'];
629 }
631 /* Show tab dialog if object is present */
632 if ($this->usertab){
633 $display= $this->usertab->execute();
635 /* Don't show buttons if tab dialog requests this */
636 if (!$this->usertab->by_object[$this->usertab->current]->dialog){
637 $display.= "<p style=\"text-align:right\">\n";
638 $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
639 $display.= " \n";
640 $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
641 $display.= "</p>";
642 }
643 return ($display);
644 }
646 $smarty= get_smarty();
648 /* Check sorting variable */
649 if (!isset($this->usertab) &&
650 !isset($_POST['new_user']) &&
651 !isset($_POST['new_template']) &&
652 !isset($_POST['delete_user']) &&
653 !isset($_POST['setpass_user']) &&
654 !isset($_POST['select_user'])){
655 $this->reload();
656 }
658 /* Check for exeeded sizelimit */
659 if (($message= check_sizelimit()) != ""){
660 return($message);
661 }
663 /* Prepare departments */
664 $options= "";
665 foreach ($this->config->idepartments as $key => $value){
666 if ($userfilter['depselect'] == $key){
667 $options.= "<option selected value='$key'>$value</option>";
668 } else {
669 $options.= "<option value='$key'>$value</option>";
670 }
671 }
673 /* NEW LIST MANAGMENT */
674 $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
675 " <input class='center' type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'> ".
676 " <input class='center' type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'> ".
677 " <input class='center' type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'> ".
678 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
679 " <input class='center' type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'> ".
680 " <input class='center' type='image' align='middle' src='images/list_new.png' title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'> ".
681 " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'> ".
682 _("Base")." <select name='depselect' onChange='mainform.submit()' class='center'>$options</select>".
683 " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'> ".
684 "</div>";
686 $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."' name='user_edit_%KEY%' title='"._("Edit user")."'>";
687 $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."' name='user_chgpw_%KEY%' title='"._("Change password")."'>";
688 $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."' name='user_del_%KEY%' title='"._("Delete user")."'>";
692 $divlist = new divlist("userstab");
693 $divlist->SetHeader(array(
694 array("string" => " ", "attach" => "style='text-align:center;width:20px;'"),
695 array("string" => _("Username")." / "._("Department"), "attach" => "style=''"),
696 array("string" => _("Properties"), "attach" => "style='width:152px;'"),
697 array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
700 $divlist->SetSummary(_("This table displays all users, in the selected tree."));
701 $divlist->SetEntriesPerPage(0);
703 // Defining Links
704 $linkopen = "<a href='?plug=".$_GET['plug']."&act=dep_open&dep_id=%s'>%s</a>";
706 /* Insert departments in divlist*/
707 foreach($this->departments as $key=> $val){
709 if(!isset($this->config->departments[trim($key)])){
710 $this->config->departments[trim($key)]="";
711 }
713 $non_empty="";
714 $keys= str_replace("/","\/",$key);
715 foreach($this->config->departments as $keyd=>$vald ){
716 if(preg_match("/".$keys."\/.*/",$keyd)){
717 $non_empty="full";
718 }
719 }
721 $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
722 $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
723 $field3 = array("string" => " ", "attach" => "style='width:152px;'");
724 $field4 = array("string" => " ", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
727 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
728 }
730 /* Pictures for Extensions */
731 $usrimg ="<input class='center' type='image' src='images/penguin.png' alt='"._("GOsa")."'
732 name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
733 $posiximg = "<input class='center' type='image' src='images/select_user.png' alt='"._("Posix")."'
734 name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
735 $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'
736 name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
737 $mailimg = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
738 name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
739 $fonimg = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'
740 name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
741 $faximg = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'
742 name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
743 $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'
744 name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
745 $tplcreateuserimg = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
746 name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
749 $empty = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>";
751 // User and Template Images
752 $userimg = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";
753 $tplimg = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";
754 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
756 // Defines Arrays to save User and Templates
757 $tpls = array();
758 $users= array();
760 /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
761 * Read Sip Table for specified account (for each user with phoneAccount).
762 * Check the attributes ip port and regseconds.
763 * If regseconds is set and >0 , the phone is logged in.
764 * Else the phone is currently not logged.
765 * If we can't read any Data from the DB or there is no goFon DB specified
766 * show old style without status icons.
767 */
768 $r_db =false;
769 $r_con =false;
770 if (isset($_SESSION['config']->data['SERVERS']['FON'])){
771 $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
772 // Connect to DB server
774 /*
775 If you want to disable the status pictures, just comment out the next line
776 */
777 $r_con = false;
778 $r_db = false;
779 if(is_callable("mysql_pconnect")){
780 $r_con= @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
781 // Check if we are connected correctly
782 if($r_con){
783 $r_db = @mysql_select_db($a_SETUP['DB'],$r_con);
784 }
785 }
786 }
788 // Test Every Entry and generate divlist Array
789 foreach($this->list as $key => $val){
790 $connected = ""; // This string represents timestamp or offline status
791 $ip_port = ""; // String that will represent ip : port of the connected phone
792 if((in_array("goFonAccount" ,$val['objectClass']))){
794 /* Set defaults */
795 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
796 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
797 $fonac = preg_replace("/%title%/", "", $fonac);
799 /* Database connection is ok ?*/
800 if(($r_db)&&(is_callable("mysql_query"))){
801 $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
802 $mysql_entry = @mysql_fetch_row($res);
803 if(is_array($mysql_entry)){
804 if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
805 $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
806 $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
807 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
808 $fonac = preg_replace("/%title%/", $connected, $fonac);
809 $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
810 }
811 if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
812 $connected = " | "._("Offline");
813 $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
814 $fonac = preg_replace("/%KEY%/", "$key", $fonac);
815 $fonac = preg_replace("/%title%/", $connected, $fonac);
816 }
817 }
818 }
819 }else{
820 $fonac=$empty;
821 }
825 // Specify Pics for Extensions
826 if(in_array("posixAccount" ,$val['objectClass'])){
827 $posix = preg_replace("/%KEY%/", "$key", $posiximg);
828 }else{
829 $posix=$empty;
830 }
832 if(in_array("gotoEnvironment" ,$val['objectClass'])){
833 $enviro = preg_replace("/%KEY%/", "$key", $eviroimg);
834 }else{
835 $enviro =$empty;
836 }
838 if(in_array("gosaMailAccount" ,$val['objectClass'])){
839 $maila = preg_replace("/%KEY%/", "$key", $mailimg);
840 }else{
841 $maila=$empty;
842 }
844 if(in_array("goFaxAccount" ,$val['objectClass'])){
845 $faxac = preg_replace("/%KEY%/", "$key", $faximg);
846 }else{
847 $faxac=$empty;
848 }
850 if(in_array("sambaSamAccount" ,$val['objectClass'])){
851 $samba = preg_replace("/%KEY%/", "$key", $sambaimg);
852 }else{
853 $samba=$empty;
854 }
856 if(in_array("gosaUserTemplate",$val['objectClass'])){
857 $tpl = preg_replace("/%KEY%/", "$key", $tplimg);
858 $s_img_create_from_template = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
859 }else{
860 $s_img_create_from_template = "";
861 $tpl=$userimg;
862 }
864 $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
866 // Generate caption for rows
867 if (isset($val["sn"]) && isset($val["givenName"])){
868 $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
869 } else {
870 $display= "[".$val["uid"][0]."]";
871 }
873 /* Create each field */
874 $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
875 $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port, "attach" => "style='' title='".$val['dn']."'");
876 $field3 = array("string" => $usrimg2." ".$posix." ".$enviro." ".$maila." ".$fonac." ".$faxac." ".$samba." ".$s_img_create_from_template, "attach" => "style='width:152px;'");
877 $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='width:60px;border-right:0px;text-align:right;'");
879 $add = array($field1,$field2,$field3,$field4);
881 // Template or User
882 if(in_array("gosaUserTemplate",$val['objectClass'])){
883 $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
884 }else{
885 $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
886 }
887 }
889 // Sort Entries
890 ksort($users);
891 ksort($tpls);
893 // Append Templates
894 foreach($tpls as $key => $val){
895 $divlist->AddEntry( $val, array(""));
896 }
897 // Append Users
898 foreach($users as $key => $val){
899 $divlist->AddEntry( $val, array(""));
900 }
901 /* Show main page */
902 //$smarty->assign("userlist", nl2br(htmlentities($divlist->DrawList())));
903 $smarty->assign("userlist", $divlist->DrawList());
904 $smarty->assign("userlisthead", $listhead);
906 /* END NEW LIST MANAGMENT
907 */
908 $smarty->assign("search_image", get_template_path('images/search.png'));
909 $smarty->assign("tree_image", get_template_path('images/tree.png'));
910 $smarty->assign("infoimage", get_template_path('images/info.png'));
911 $smarty->assign("launchimage", get_template_path('images/launch.png'));
912 $smarty->assign("deplist", $this->config->idepartments);
913 foreach( array("depselect", "functionalusers", "unixusers",
914 "mailusers", "sambausers", "proxyusers",
915 "faxusers", "templates", "subsearch") as $type){
917 $smarty->assign("$type", $userfilter[$type]);
918 }
920 $smarty->assign("regex", $userfilter["regex"]);
921 /* Extend if we are not using javascript */
922 $smarty->assign("apply", apply_filter());
923 $smarty->assign("alphabet", generate_alphabet());
924 $smarty->assign("hint", print_sizelimit_warning());
926 if((is_callable("mysql_close"))&&($r_con)){
927 @mysql_close($r_con);
928 }
929 return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
930 }
933 function reload()
934 {
935 /* Get config */
936 $userfilter= get_global('userfilter');
938 /* Set base for all searches */
939 $base= $userfilter['depselect'];
941 /* Regex filter? */
942 if ($userfilter['regex'] != ""){
943 $regex= $userfilter['regex'];
944 } else {
945 $regex= "*";
946 }
948 /* Set filter depending on selection */
949 if ($this->config->current['SAMBAVERSION'] == 3){
950 $samba= "sambaSamAccount";
951 } else {
952 $samba= "sambaAccount";
953 }
955 $filter="";
956 if ($userfilter['functionalusers'] == "checked"){
957 $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)(objectClass=goFaxAccount)(objectClass=gosaProxyAccount))))";
958 }
959 if ($userfilter['unixusers'] == "checked"){
960 $filter.= "(objectClass=posixAccount)";
961 }
962 if ($userfilter['mailusers'] == "checked"){
963 $filter.= "(objectClass=gosaMailAccount)";
964 }
965 if ($userfilter['sambausers'] == "checked"){
966 $filter.= "(objectClass=$samba)";
967 }
968 if ($userfilter['proxyusers'] == "checked"){
969 $filter.= "(objectClass=gosaProxyAccount)";
970 }
971 if ($userfilter['faxusers'] == "checked"){
972 $filter.= "(objectClass=goFaxAccount)";
973 }
975 if ($userfilter['templates'] == "checked"){
976 $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
977 } else {
978 $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
979 }
980 $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
982 /* Generate userlist */
983 $ldap= $this->config->get_ldap_link(TRUE);
984 if ($userfilter['subsearch'] == "checked"){
985 $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
986 } else {
987 $base= get_people_ou().$base;
988 $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
989 }
993 /* NEW LIST MANAGMENT
994 * We also need to search for the departments
995 * So we are able to navigate like in konquerer
996 */
998 /* Create base to search in */
1000 $peopleOU = get_people_ou();
1001 if(empty($peopleOU)) {
1002 $base2 = $base;
1003 }else{
1004 $base2 = preg_replace("/".$peopleOU."/i","",$base);
1005 }
1007 /* Get all departments within this subtree */
1008 $res3 = get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
1009 TRUE, $base2, array("ou", "description"), TRUE);
1011 $this->departments= array();
1013 /* Create array with results */
1014 $tmp = array();
1015 foreach ($res3 as $value){
1016 $tmp[strtolower($value['dn']).$value['dn']]=$value;
1017 }
1019 /* Sort array */
1020 ksort($tmp);
1022 /* Create result array */
1023 foreach($tmp as $value){
1024 if(isset($value['description'][0])){
1025 $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
1026 }else{
1027 $this->departments[$value['dn']]=convert_department_dn2($value['dn']);
1028 }
1029 }
1030 /* END NEW LIST MANAGMENT
1031 */
1034 $this->userlist= array();
1036 foreach ($this->list as $value){
1037 if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
1038 if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
1039 $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
1040 continue;
1041 }
1042 if (isset($value["givenName"][0]) && isset($value["sn"][0])){
1043 $this->userlist[$value["dn"]]= $value["sn"][0].", ".
1044 $value["givenName"][0].
1045 " [".$value["uid"][0]."]";
1046 } else {
1047 $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
1048 }
1049 }
1050 }
1052 natcasesort ($this->userlist);
1053 reset ($this->userlist);
1054 }
1056 function remove_from_parent()
1057 {
1058 }
1061 /* Check values */
1062 function check()
1063 {
1064 }
1067 /* Save to LDAP */
1068 function save()
1069 {
1070 }
1072 function adapt_from_template($dn)
1073 {
1074 }
1076 function password_change_needed()
1077 {
1078 }
1080 function show_header($button_text, $text, $disabled= FALSE)
1081 {
1082 }
1084 function remove_lock()
1085 {
1086 if (isset($this->usertab->dn)){
1087 del_lock ($this->usertab->dn);
1088 }
1089 }
1091 }
1093 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1094 ?>