Code

386c3ae772132d897f61755542cc35930021d9ea
[gosa.git] / plugins / admin / users / class_userManagement.inc
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;
43     /* Get global filter config */
44     if (!isset($_SESSION["userfilter"])){
45       $base= get_base_from_people($ui->dn);
46       $userfilter= array( "mailusers"       => "checked",
47           "unixusers"       => "checked",
48           "templates"       => "",
49           "subsearch"       => "",
50           "proxyusers"      => "checked",
51           "sambausers"      => "checked",
52           "faxusers"        => "checked",
53           "functionalusers" => "checked",
54           "depselect"       => $base,
55           "regex"           => "*");
56       $_SESSION["userfilter"] = $userfilter;
57     }
58   }
60   function execute()
61   {
62     $smarty       = get_smarty();             // Smarty instance
63     $userfilter   = get_global("userfilter"); // contains Filter Settings
64     $s_action     = "";                       // Contains the action to proceed
65     $s_entry      = "";                       // The value for s_action
66     $base_back    = "";                       // The Link for Backbutton
68     /* Start for New List Managment */
69     if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
70       $s_action="open";
71       $s_entry = base64_decode($_GET['dep_id']);
72       $userfilter['depselect']= "".$this->config->departments[trim($s_entry)];
73     }
75     /* Test Posts */  
76     foreach($_POST as $key => $val){
77       // Post for delete
78       if(preg_match("/user_del.*/",$key)){
79         $s_action = "del";
80         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
81         // Post for edit
82       }elseif(preg_match("/user_edit_.*/",$key)){
83         $s_action="edit";
84         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
85         // Post for new
86       }elseif(preg_match("/dep_back.*/i",$key)){
87         $s_action="back";
88       }elseif(preg_match("/user_new.*/",$key)){
89         $s_action="new";
90       }elseif(preg_match("/dep_home.*/i",$key)){
91         $s_action="home";
92       }elseif(preg_match("/user_tplnew.*/i",$key)){
93         $s_action="new_tpl";
94       }elseif(preg_match("/user_chgpw.*/i",$key)){
95         $s_action="change_pw";
96         $s_entry  = preg_replace("/user_chgpw_/i","",$key);
97       }elseif(preg_match("/dep_root.*/i",$key)){
98         $s_action="root";
99       }elseif(preg_match("/userfrom_tpl.*/i",$key)){
100         $s_action="create_user_from_tpl";
101         $s_entry  = preg_replace("/userfrom_tpl_/i","",$key);
102       }
103     }
105     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
106       $s_action = "edit";
107       $s_entry  = $_GET['id'];
108     }
110     $s_entry  = preg_replace("/_.$/","",$s_entry);
112     if(preg_match("/.*-.*/",$s_entry)){
113       $s_tab   = preg_replace("/^.*-/i","",$s_entry);
114       $s_entry = preg_replace("/-.*$/i","",$s_entry);
115     }else{
116       $s_tab   = "user";
117     };
119     /* Department changed? */
120     if(isset($_POST['depselect']) && $_POST['depselect']){
121       $userfilter['depselect']= $_POST['depselect'];
122     }
124     /* Homebutton is posted */
125     if($s_action=="home"){
126       $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
127       $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$userfilter['depselect']));
128     }
130     if($s_action=="root"){
131       $userfilter['depselect']=($this->config->current['BASE']);
132     }
135     /* If Backbutton is Posted */
136     if($s_action=="back"){
137       $base_back          = preg_replace("/^[^,]+,/","",$userfilter['depselect']);
138       $base_back          = convert_department_dn($base_back);
140       if(isset($this->config->departments[trim($base_back)])){
141         $userfilter['depselect']= $this->config->departments[trim($base_back)];
142       }else{
143         $userfilter['depselect']= $this->config->departments["/"];
144       }
145     }
147     /* End for new List Managment */
149     /* Save filter data if we are in the headpage */
150     if (!isset($this->usertab)){
151       if (isset($_POST['regexit'])){
152         $userfilter["regex"]= $_POST['regexit'];
153       }
154     }
155     if(isset($_POST['regexit'])){
156       foreach( array("functionalusers", "unixusers", "mailusers","sambausers", "proxyusers", "faxusers", "templates", "subsearch") as $type){
157         if (isset($_POST[$type])) {
158           $userfilter[$type]= "checked";
159         } else {
160           $userfilter[$type]= "";
161         }
162       }
163     }
164     if (isset($_GET['search'])){
165       $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
166       if ($s == "**"){
167         $s= "*";
168       }
169       $userfilter['regex']= $s;
170     }
171     register_global("userfilter", $userfilter);
174     /* React on user interaction here */
175     if (($_SERVER["REQUEST_METHOD"] == "POST")||($_SERVER["REQUEST_METHOD"]== "GET")){
177       /* User wants to edit data? */
178       if ($s_action=="edit"){
180         /* Get 'dn' from posted 'uid', must be unique */
182         $this->dn= $this->list[trim($s_entry)]['dn'];
184         /* Check locking, save current plugin in 'back_plugin', so
185            the dialog knows where to return. */
186         if (($user= get_lock($this->dn)) != ""){
187           return(gen_locked_message ($user, $this->dn));
188         }
190         /* Lock the current entry, so everyone will get the
191            above dialog */
192         add_lock ($this->dn, $this->ui->dn);
194         /* Set up the users ACL's for this 'dn' */
195         $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
197         /* Register usertab to trigger edit dialog */
198         $this->usertab= new usertabs($this->config, 
199             $this->config->data['TABS']['USERTABS'], $this->dn);
200         //        $_POST[$s_tab]=$s_tab;
202         // This would be better
203         $this->usertab->current = $s_tab;
204         $this->usertab->set_acl($acl);
206         $_SESSION['objectinfo']= $this->dn;
207       }
208     }
210     /* Reset requested? */
211     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
212       if (isset($this->usertab)){
213         del_lock ($this->usertab->dn);
214         unset ($this->usertab);
215       }
216       $this->usertab= NULL;
217       $this->lognames= array();;
218       $this->sn= "";
219       $this->givenName= "";
220       $this->uid= "";
221       unset ($_SESSION['objectinfo']);
222     }
224     /* Password change requested */
225     if ($s_action=="change_pw"){
227       /* Get 'dn' from posted 'uid' */
228       $this->dn= $this->list[trim($s_entry)]['dn'];
230       /* Load permissions for selected 'dn' and check if
231          we're allowed to remove this 'dn' */
232       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
233       $acl= get_module_permission($acl, "user", $this->dn);
234       if (chkacl($acl, "password") == ""){
236         /* User is allowed to change passwords, save 'dn' and 'acl' for next
237            dialog. */
238         $this->acl= $acl;
239         $_SESSION['objectinfo']= $this->dn;
240         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
242       } else {
243         /* User is not allowed. Show message and cancel. */
244         print_red (_("You are not allowed to set this users password!"));
245       }
246     }
248     /* Perform password change */
249     if (isset($_POST['password_finish'])){
251       /* For security reasons, check if user is allowed to set password again */
252       if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
254         /* Check input and feed errors into 'message' */
255         $message= array();
257         /* Sanity checks... */
258         if ($_POST['new_password'] != $_POST['repeated_password']){
260           /* Matching passwords in new and repeated? */
261           $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
262         } else {
264           /* Empty password is not permitted by default. */
265           if ($_POST['new_password'] == ""){
266             $message[]= _("The password you've entered as 'New password' is empty.");
267           }
268         }
270         /* Errors, or change password? */
271         if (count($message) != 0){
273           /* Show error message and continue editing */
274           show_errors ($message);
275           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
276         }
278         $config= $this->config;
279         $ldap_ui= $this->config->get_ldap_link();
280         if(isset($this->usertab->dn)){
281           $user = ($ldap_ui->fetch($ldap_ui->cat($this->usertab->dn)));
282         }else{
283           $user = ($ldap_ui->fetch($ldap_ui->cat($this->dn)));
284         }
285         if((is_array($user))&&(isset($user['uid']))){
286           $username= $user['uid'][0];
287         }
289         /* Set password, perform required steps */
290         if ($this->usertab){
291           if ($this->usertab->password_change_needed()){
292             $obj= $this->usertab->by_object['user'];
293             change_password ($this->usertab->dn, $_POST['new_password'],
294                 0, $obj->pw_storage);
295             if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
296               exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
297             }
299             gosa_log ("Password for '".$this->usertab->dn."' has been changed");
300             unset($this->usertab);
301             $this->usertab= NULL;
302           }
303         } else {
304           change_password ($this->dn, $_POST['new_password']);
305           if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
306             exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
307           }
309           gosa_log ("Password for '".$this->dn."' has been changed");
310         }
311       } else {
313         /* Missing permissions, show message */
314         print_red (_("You are not allowed to set this users password!"));
315       }
317       /* Clean session, delete lock */
318       del_lock ($this->dn);
319       $this->reload();
320       unset ($this->usertab);
321       $this->usertab= NULL;
322       $this->lognames= array();;
323       $this->sn= "";
324       $this->givenName= "";
325       $this->uid= "";
326       unset ($_SESSION['objectinfo']);
327     }
330     /* Remove user was requested */
331     if ($s_action=="del"){
333       /* Get 'dn' from posted 'uid' */
334       $this->dn= $this->list[trim($s_entry)]['dn'];
336       /* Load permissions for selected 'dn' and check if
337          we're allowed to remove this 'dn' */
338       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
339       $this->acl= get_module_permission($acl, "user", $this->dn);
340       if (chkacl($this->acl, "delete") == ""){
342         /* Check locking, save current plugin in 'back_plugin', so
343            the dialog knows where to return. */
344         if (($user= get_lock($this->dn)) != ""){
345           return(gen_locked_message ($user, $this->dn));
346         }
348         /* Lock the current entry, so nobody will edit it during deletion */
349         add_lock ($this->dn, $this->ui->dn);
350         $smarty->assign("info", sprintf(_("You're about to delete the user %s."), $this->dn));
351         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
352       } else {
354         /* Obviously the user isn't allowed to delete. Show message and
355            clean session. */
356         print_red (_("You are not allowed to delete this user!"));
357       }
358     }
362     /* Confirmation for deletion has been passed. User should be deleted. */
363     if (isset($_POST['delete_user_confirm'])){
365       /* Some nice guy may send this as POST, so we've to check
366          for the permissions again. */
367       if (chkacl($this->acl, "delete") == ""){
369         /* Delete request is permitted, perform LDAP action */
370         $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
371             $this->dn);
372         $this->usertab->set_acl(array($this->acl));
373         $this->usertab->delete ();
374         gosa_log ("User object '".$this->dn."' has been removed");
375         unset ($this->usertab);
376         $this->usertab= NULL;
378         /* User list has changed, reload it. */
379         $this->reload ();
380       } else {
382         /* Normally this shouldn't be reached, send some extra
383            logs to notify the administrator */
384         print_red (_("You are not allowed to delete this user!"));
386         if(isset($this->ui->uid)){
387           gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
388         }
389       }
391       /* Remove lock file after successfull deletion */
392       del_lock ($this->dn);
393     }
396     /* Delete user canceled? */
397     if (isset($_POST['delete_cancel'])){
398       del_lock ($this->dn);
399     }
402     /* Finish user edit is triggered by the tabulator dialog, so
403        the user wants to save edited data. Check and save at this
404        point. */
405     if (isset($_POST['edit_finish'])){
407       /* Check tabs, will feed message array */
408       $this->usertab->last= $this->usertab->current;
409       $this->usertab->save_object();
410       $message= $this->usertab->check();
412       /* Save, or display error message? */
413       if (count($message) == 0){
415         /* No errors. Go ahead and prepare to ask for a password
416            in case we're creating a new user. 'dn' will be 'new'
417            in this case. It is set to the correct value later. */
418         if ($this->dn == "new"){
419           $set_pass= 1;
420         } else {
421           $set_pass= 0;
422         }
424         /* Save user data to ldap */
425         if($this->usertab->save() == 1){
426           gosa_log ("User object '".$this->dn."' saving failed.");
427           return;
428         }
429         gosa_log ("User object '".$this->dn."' has been saved");
431         /* User has been saved successfully, remove lock from
432            LDAP. */
433         if ($this->dn != "new"){
434           del_lock ($this->dn);
435         }
437         /* In case of new users, ask for a password */
438         if (($set_pass || $this->usertab->password_change_needed()) &&
439             !$this->is_template){
441           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
442         }
444         /* There's no page reload so we have to read new users at
445            this point. */
446         $this->reload ();
447         unset ($this->usertab);
448         $this->usertab= NULL;
449         unset ($_SESSION['objectinfo']);
451       } else {
452         /* Ok. There seem to be errors regarding to the tab data,
453            show message and continue as usual. */
454         show_errors($message);
455       }
456     }
458     /* Generate template list */
459     if (($s_action=="new")||($s_action=="create_user_from_tpl")){
460       $this->templates= array();
461       $ldap= $this->config->get_ldap_link();
462       foreach ($this->config->departments as $key => $value){
463         $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
464         $acl= get_module_permission($acl, "user", get_people_ou().$value);
465         if (chkacl($acl, "create") == ""){
466           $ldap->cd (get_people_ou().$value);
467           $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
469           if ($ldap->count() != 0){
470             while ($attrs= $ldap->fetch()){
471               $this->templates[$ldap->getDN()]=
472                 $attrs['uid'][0]." - $key";
473             }
474             $this->templates['none']= _("none");
475           }
476         }
477       }
478       natcasesort ($this->templates);
479       reset ($this->templates);
480     }
482     /* New user/template request */
483     if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
484       /* By default we set 'dn' to 'new', all relevant plugins will
485          react on this. */
486       $this->dn= "new";
487       if (isset($this->config->current['IDGEN'])){
488         $this->got_uid= false;
489       } else {
490         $this->got_uid= true;
491       }
493       /* Create new usertab object */
494       $this->usertab= new usertabs($this->config,
495           $this->config->data['TABS']['USERTABS'], $this->dn);
496       $this->usertab->set_acl(array(':all'));
497       $this->usertab->by_object['user']->base= $userfilter['depselect'];
499       /* Take care about templates */
500       if ($s_action=="new_tpl"){
501         $this->is_template= TRUE;
502         $this->usertab->set_template_mode ();
503       } else {
504         $this->is_template= FALSE;
505       }
507       /* Use template if there are any of them */
508       if ((count($this->templates) && !isset($_POST['new_template']))||($s_action=="create_user_from_tpl")){
509         foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
510           $smarty->assign("$attr", $this->$attr);
511         }
512         if ($s_action=="create_user_from_tpl"){
513           $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
514         } else {
515           $smarty->assign("template", "");
516         }
517         $smarty->assign("edit_uid", "");
518         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
519       }
520     }
522     /* Continue template editing */
523     if ((isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid']))){
524       $this->sn= $_POST['sn'];
525       $this->givenName= $_POST['givenName'];
527       /* Check for requred values */
528       $message= array();
529       if ($this->sn == "") {
530         $message[]= _("The required field 'Name' is not set.");
531       }
532       if ($this->givenName == "") {
533         $message[]= _("The required field 'Given name' is not set.");
534       }
536       /* Check if dn is used */
537       $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
538       $ldap= $this->config->get_ldap_link();
539       $ldap->cd ($dn);
540       $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
541       if ($ldap->count () != 0){
542         $message[]= _("A person with the choosen name is already used in this tree.");
543       }
545       /* Show error message / continue editing */
546       if (count($message) > 0){
547         show_errors ($message);
548       } else {
549         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
550         if (isset($this->config->current['IDGEN']) &&
551             $this->config->current['IDGEN'] != ""){
552           $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
553           if (count($uids)){
554             $smarty->assign("edit_uid", "false");
555             $smarty->assign("uids", $uids);
556             $this->uid= current($uids);
557           }
558         } else {
559           $smarty->assign("edit_uid", "");
560           $this->uid= "";
561         }
562         $this->got_uid= true;
563       }
565       foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
566         $smarty->assign("$attr", $this->$attr);
567       }
568       if (isset($_POST['template'])){
569         $smarty->assign("template", $_POST['template']);
570       }
571       return($smarty->fetch(get_template_path('template.tpl', TRUE)));
572     }
574     /* No template. Ok. Lets fill data into the normal user dialog */
575     if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
576       foreach(array("sn", "givenName", "uid") as $attr){
577         if (isset($_POST[$attr])){
578           $this->usertab->by_object['user']->$attr= $_POST[$attr];
579         }
580       }
581     }
583     /* Finish template preamble */
584     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
586       /* Might not be filled if IDGEN is unset */
587       $this->sn                 = $_POST['sn'];
588       $this->givenName          = $_POST['givenName'];
590       /* Move user supplied data to sub plugins */
591       $this->uid                = $_POST['uid'];
592       $this->usertab->uid       = $this->uid;
593       $this->usertab->sn        = $this->sn;
594       $this->usertab->givenName = $this->givenName;
595       $template_dn              = $_POST['template'];
596       $this->usertab->adapt_from_template($template_dn);
597       $template_base            = preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
598       $this->usertab->by_object['user']->base= $template_base;
600       /* Set up the users ACL's for this 'dn' */
601       $acl= get_permissions ($template_base, $this->ui->subtreeACL);
602       $this->usertab->set_acl($acl);
603     }
604     
605     if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
606       $this->usertab->by_object['user']->base= $userfilter['depselect'];
607     }
609     /* Show tab dialog if object is present */
610     if ($this->usertab){
611       $display= $this->usertab->execute();
613       /* Don't show buttons if tab dialog requests this */
614       if (!$this->usertab->by_object[$this->usertab->current]->dialog){
615         $display.= "<p style=\"text-align:right\">\n";
616         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
617         $display.= "&nbsp;\n";
618         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
619         $display.= "</p>";
620       }
621       return ($display);
622     }
624     $smarty= get_smarty();
626     /* Check sorting variable */
627     if (!isset($this->usertab) &&
628         !isset($_POST['new_user']) &&
629         !isset($_POST['new_template']) &&
630         !isset($_POST['delete_user']) &&
631         !isset($_POST['setpass_user']) &&
632         !isset($_POST['select_user'])){
633       $this->reload();
634     }
636     /* Check for exeeded sizelimit */
637     if (($message= check_sizelimit()) != ""){
638       return($message);
639     }
641     /* Prepare departments */
642     $options= "";
643     foreach ($this->config->idepartments as $key => $value){
644       if ($userfilter['depselect'] == $key){
645         $options.= "<option selected value='$key'>$value</option>";
646       } else {
647         $options.= "<option value='$key'>$value</option>";
648       }
649     }
651     /* NEW LIST MANAGMENT */
652     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
653       " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
654       " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
655       " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
656       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
657       " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'>&nbsp;".
658       " <input type='image' align='middle' src='images/list_new.png' title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'>&nbsp;".
659       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
660       _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
661       " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
662       "</div>";
664     $action= "<input type='image' src='images/edit.png' alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit user")."'>";
665     $action.= "<input type='image' src='images/list_password.png' alt='"._("password")."' name='user_chgpw_%KEY%' title='"._("Change password")."'>";
666     $action.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete user")."'>";
670     $divlist = new divlist("userstab");
671     $divlist->SetHeader(array(
672           array("string" => "&nbsp;"),
673           array("string" => _("Username")." / "._("Department")),
674           array("string" => _("Properties")),
675           array("string" => _("Actions"), "attach" => "style='border:none'" )));
678     $divlist->SetSummary(_("This table displays all users, in the selected tree."));
679     $divlist->SetEntriesPerPage(20);
681     // Defining Links 
682     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
684     /* Insert departments in divlist*/
685     foreach($this->departments as $key=> $val){
687       if(!isset($this->config->departments[trim($key)])){
688         $this->config->departments[trim($key)]="";
689       }
691       $non_empty="";
692       $keys= str_replace("/","\/",$key);
693       foreach($this->config->departments as $keyd=>$vald ){
694         if(preg_match("/".$keys."\/.*/",$keyd)){
695           $non_empty="full";
696         }
697       }
699       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>");
700       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
701       $field3 = array("string" => "&nbsp;");
702       $field4 = array("string" => "&nbsp;", "attach" => "style='border:none'");
705       $divlist->AddEntry(array($field1,$field2,$field3,$field4));
706     }
708     /* Pictures for Extensions */
709     $usrimg   ="<input type='image' src='images/penguin.png' alt='"._("GOsa")."'   
710                     name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
711     $posiximg = "<input type='image' src='images/select_user.png' alt='"._("Posix")."'  
712                     name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
713     $eviroimg = "<input type='image' src='images/smallenv.png' alt='"._("Environment")."'  
714                     name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
715     $mailimg  = "<input type='image' src='images/mailto.png' alt='"._("Mail")."'     
716                     name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
717     $fonimg   = "<input type='image' src='images/%image%' alt='"._("Phone")."'     
718                     name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
719     $faximg   = "<input type='image' src='images/fax_small.png' alt='"._("Fax")."'     
720                     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
721     $sambaimg = "<input type='image' src='images/select_winstation.png' alt='"._("Samba")."'     
722                     name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>"; 
723     $tplcreateuserimg  = "<input type='image' src='images/list_new.png' alt='"._("Create user from template")."'
724                     name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";   
725     
727     $empty    = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>"; 
729     // User and Template  Images  
730     $userimg  = "<img src='images/select_user.png' alt='User' title='%s'>";   
731     $tplimg   = "<img src='images/select_template.png' alt='Template' title='%s'>";   
732     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
734     // Defines Arrays to save User and Templates
735     $tpls = array();
736     $users= array();
738     /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
739      * Read Sip Table for specified account (for each user with phoneAccount).
740      * Check the attributes ip port and regseconds.
741      * If regseconds is set and >0 , the phone is logged in.
742      * Else the phone is currently not logged.
743      * If we can't read any Data from the DB or there is no goFon DB specified
744      * show old style without status icons.
745      */
746     $r_db   =false;
747     $r_con  =false;
748     if (isset($_SESSION['config']->data['SERVERS']['FON'])){
749       $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
750       // Connect to DB server
751   
752       /* 
753         If you want to disable the status pictures, just comment out the next line
754       */
755       $r_con= @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
756       // Check if we are  connected correctly
757       if($r_con){
758         $r_db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
759       }
760     }
762     // Test Every Entry and generate divlist Array  
763     foreach($this->list as $key => $val){
764       $connected  = ""; // This string represents timestamp or offline status 
765       $ip_port    = ""; // String that will represent ip : port of the connected phone
766       if((in_array("goFonAccount"    ,$val['objectClass']))){
767   
768         /* Set defaults */
769         $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
770         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
771         $fonac = preg_replace("/%title%/", "", $fonac);
773         /* Database connection is ok ?*/
774         if($r_db){
775           $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
776           $mysql_entry = @mysql_fetch_row($res);
777           if(is_array($mysql_entry)){
778             if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
779               $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
780               $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
781               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
782               $fonac = preg_replace("/%title%/", $connected, $fonac);
783               $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
784             }
785             if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
786               $connected = " | "._("Offline");
787               $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
788               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
789               $fonac = preg_replace("/%title%/", $connected, $fonac);
790             }
791           }
792         }
793       }else{
794         $fonac=$empty;
795       }
797     
799       // Specify Pics for Extensions  
800       if(in_array("posixAccount"    ,$val['objectClass'])){ 
801         $posix = preg_replace("/%KEY%/", "$key", $posiximg);
802       }else{ 
803         $posix=$empty;
804       }
805       
806       if(in_array("gotoEnvironment"    ,$val['objectClass'])){ 
807         $enviro = preg_replace("/%KEY%/", "$key", $eviroimg);
808       }else{ 
809         $enviro =$empty;
810       }
811    
812       if(in_array("gosaMailAccount" ,$val['objectClass'])){ 
813         $maila = preg_replace("/%KEY%/", "$key", $mailimg);   
814       }else{ 
815         $maila=$empty;
816       } 
817   
818       if(in_array("goFaxAccount"    ,$val['objectClass'])){ 
819         $faxac = preg_replace("/%KEY%/", "$key", $faximg);    
820       }else{ 
821         $faxac=$empty;
822       } 
824       if(in_array("sambaSamAccount" ,$val['objectClass'])){ 
825         $samba = preg_replace("/%KEY%/", "$key", $sambaimg);  
826       }else{ 
827         $samba=$empty;
828       } 
830       if(in_array("gosaUserTemplate",$val['objectClass'])){ 
831         $tpl                          = preg_replace("/%KEY%/", "$key", $tplimg);   
832         $s_img_create_from_template   = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
833       }else{ 
834         $s_img_create_from_template   = "";
835         $tpl=$userimg;
836       }
838       $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
840       // Generate caption for rows
841       if (isset($val["sn"]) && isset($val["givenName"])){
842         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
843       } else {
844         $display= "[".$val["uid"][0]."]";
845       }
847       /* Create each field */
848       $field1 = array("string" => sprintf($tpl,$val['dn']),"attach"=>"style='width:20px;align:middle;'");
849       $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port,"attach"=>"title='".$val['dn']."'");
850       $field3 = array("string" => $usrimg2."&nbsp;".$posix."&nbsp;".$enviro."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba."&nbsp;".$s_img_create_from_template, "attach" => "style='width:155px;'");
851       $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='border:none; text-align:right;width:48px'");
853       $add = array($field1,$field2,$field3,$field4);
855       // Template or User
856       if(in_array("gosaUserTemplate",$val['objectClass'])){
857         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
858       }else{
859         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
860       }
861     }
863     // Sort Entries 
864     ksort($users);
865     ksort($tpls);
867     // Append Templates
868     foreach($tpls as $key => $val){
869       $divlist->AddEntry( $val, array(""));
870     }
871     // Append Users 
872     foreach($users as $key => $val){
873       $divlist->AddEntry( $val, array(""));
874     }
875     /* Show main page */
876     //$smarty->assign("userlist",   nl2br(htmlentities($divlist->DrawList())));
877     $smarty->assign("userlist",   $divlist->DrawList());
878     $smarty->assign("userlisthead", $listhead);
880     /* END NEW LIST MANAGMENT
881      */  
882     $smarty->assign("search_image", get_template_path('images/search.png'));
883     $smarty->assign("tree_image", get_template_path('images/tree.png'));
884     $smarty->assign("infoimage", get_template_path('images/info.png'));
885     $smarty->assign("launchimage", get_template_path('images/launch.png'));
886     $smarty->assign("deplist", $this->config->idepartments);
887     foreach( array("depselect",  "functionalusers", "unixusers",
888           "mailusers", "sambausers", "proxyusers", 
889           "faxusers", "templates", "subsearch") as $type){
891       $smarty->assign("$type", $userfilter[$type]);
892     }
894     $smarty->assign("regex", $userfilter["regex"]);
895     /* Extend if we are not using javascript */
896     $smarty->assign("apply", apply_filter());
897     $smarty->assign("alphabet", generate_alphabet());
898     $smarty->assign("hint", print_sizelimit_warning());
900     @mysql_close($r_con);
901     return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
902   }
905   function reload()
906   {
907     /* Get config */
908     $userfilter= get_global('userfilter');
910     /* Set base for all searches */
911     $base= $userfilter['depselect'];
913     /* Regex filter? */
914     if ($userfilter['regex'] != ""){
915       $regex= $userfilter['regex'];
916     } else {
917       $regex= "*";
918     }
920     /* Set filter depending on selection */
921     if ($this->config->current['SAMBAVERSION'] == 3){
922       $samba= "sambaSamAccount";
923     } else {
924       $samba= "sambaAccount";
925     }
927     $filter="";
928     if ($userfilter['functionalusers'] == "checked"){
929       $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)(objectClass=goFaxAccount)(objectClass=gosaProxyAccount))))";
930     }
931     if ($userfilter['unixusers'] == "checked"){
932       $filter.= "(objectClass=posixAccount)";
933     }
934     if ($userfilter['mailusers'] == "checked"){
935       $filter.= "(objectClass=gosaMailAccount)";
936     }
937     if ($userfilter['sambausers'] == "checked"){
938       $filter.= "(objectClass=$samba)";
939     }
940     if ($userfilter['proxyusers'] == "checked"){
941       $filter.= "(objectClass=gosaProxyAccount)";
942     }
943     if ($userfilter['faxusers'] == "checked"){
944       $filter.= "(objectClass=goFaxAccount)";
945     }
947     if ($userfilter['templates'] == "checked"){
948       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
949     } else {
950       $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
951     }
952     $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
954     /* Generate userlist */
955     $ldap= $this->config->get_ldap_link(TRUE);
956     if ($userfilter['subsearch'] == "checked"){
957       $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
958     } else {
959       $base= get_people_ou().$base;
960       $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
961     }
965     /* NEW LIST MANAGMENT
966      * We also need to search for the departments
967      * So we are able to navigate like in konquerer 
968      */
969     $base2 = preg_replace("/ou=people,/i","",$base);
971     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
972         TRUE, $base2, array("ou", "description"), TRUE);
974     $this->departments= array();
976     $tmp = array();
977     foreach ($res3 as $value){
978       $tmp[strtolower($value['dn']).$value['dn']]=$value;
979     }
980     ksort($tmp);
981     foreach($tmp as $value){
982       if($value["description"][0]!=".."){
983         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
984       }else{
985         $this->departments[$value['dn']]=$value["description"][0];
986       }
987     }
988     /* END NEW LIST MANAGMENT 
989      */
992     $this->userlist= array();
994     foreach ($this->list as $value){
995       if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
996         if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
997           $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
998           continue;
999         }
1000         if (isset($value["givenName"][0]) && isset($value["sn"][0])){
1001           $this->userlist[$value["dn"]]= $value["sn"][0].", ".
1002             $value["givenName"][0].
1003             " [".$value["uid"][0]."]";
1004         } else {
1005           $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
1006         }
1007       }
1008     }
1010     natcasesort ($this->userlist);
1011     reset ($this->userlist);
1012   }
1014   function remove_from_parent()
1015   {
1016   }
1019   /* Check values */
1020   function check()
1021   {
1022   }
1025   /* Save to LDAP */
1026   function save()
1027   {
1028   }
1030   function adapt_from_template($dn)
1031   {
1032   }
1034   function password_change_needed()
1035   {
1036   }
1038   function show_header($button_text, $text, $disabled= FALSE)
1039   {
1040   }
1042   function remove_lock()
1043   {
1044     if (isset($this->usertab->dn)){
1045       del_lock ($this->usertab->dn);
1046     }
1047   }
1051 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1052 ?>