Code

Set default selection for template to none
[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")){
461       $this->templates= array();
463       $ldap= $this->config->get_ldap_link();
465       /* Create list of tempaltes */
466       foreach ($this->config->departments as $key => $value){
467     
468         /* Get acls from different ou's */
469         $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
470         $acl= get_module_permission($acl, "user", get_people_ou().$value);
471   
472         /* If creation of a new user is allowed, append this template */
473         if (chkacl($acl, "create") == ""){
474           
475           /* Search all templates from the current dn */
476           $ldap->cd (get_people_ou().$value);
477           $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
479           /* Append */
480           if ($ldap->count() != 0){
481             while ($attrs= $ldap->fetch()){
482               $this->templates[$ldap->getDN()]=
483                 $attrs['uid'][0]." - $key";
484             }
485             $this->templates['none']= _("none");
486           }
487         }
488       }
490       /* Sort templates */
491       natcasesort ($this->templates);
492       reset ($this->templates);
493     }
495     /* New user/template request */
496     if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
497       /* By default we set 'dn' to 'new', all relevant plugins will
498          react on this. */
499       $this->dn= "new";
500       if (isset($this->config->current['IDGEN'])){
501         $this->got_uid= false;
502       } else {
503         $this->got_uid= true;
504       }
506       /* Create new usertab object */
507       $this->usertab= new usertabs($this->config,
508           $this->config->data['TABS']['USERTABS'], $this->dn);
509       $this->usertab->set_acl(array(':all'));
510       $this->usertab->by_object['user']->base= $userfilter['depselect'];
512       /* Take care about templates */
513       if ($s_action=="new_tpl"){
514         $this->is_template= TRUE;
515         $this->usertab->set_template_mode ();
516       } else {
517         $this->is_template= FALSE;
518       }
520       /* Use template if there are any of them */
521       if ((count($this->templates) && !isset($_POST['new_template']))||($s_action=="create_user_from_tpl")){
522         foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
523           $smarty->assign("$attr", $this->$attr);
524         }
525         if ($s_action=="create_user_from_tpl"){
526           $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
527         } else {
528           $smarty->assign("template", "none");
529         }
530         $smarty->assign("edit_uid", "");
531         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
532       }
533     }
535     /* Continue template editing */
536     if ((isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid']))){
537       $this->sn= $_POST['sn'];
538       $this->givenName= $_POST['givenName'];
540       /* Check for requred values */
541       $message= array();
542       if ($this->sn == "") {
543         $message[]= _("The required field 'Name' is not set.");
544       }
545       if ($this->givenName == "") {
546         $message[]= _("The required field 'Given name' is not set.");
547       }
549       /* Check if dn is used */
550       $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
551       $ldap= $this->config->get_ldap_link();
552       $ldap->cd ($dn);
553       $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
554       if ($ldap->count () != 0){
555         $message[]= _("A person with the choosen name is already used in this tree.");
556       }
558       /* Show error message / continue editing */
559       if (count($message) > 0){
560         show_errors ($message);
561       } else {
562         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
563         if (isset($this->config->current['IDGEN']) &&
564             $this->config->current['IDGEN'] != ""){
565           $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
566           if (count($uids)){
567             $smarty->assign("edit_uid", "false");
568             $smarty->assign("uids", $uids);
569             $this->uid= current($uids);
570           }
571         } else {
572           $smarty->assign("edit_uid", "");
573           $this->uid= "";
574         }
575         $this->got_uid= true;
576       }
578       foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
579         $smarty->assign("$attr", $this->$attr);
580       }
581       if (isset($_POST['template'])){
582         $smarty->assign("template", $_POST['template']);
583       }
584       return($smarty->fetch(get_template_path('template.tpl', TRUE)));
585     }
587     /* No template. Ok. Lets fill data into the normal user dialog */
588     if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
589       foreach(array("sn", "givenName", "uid") as $attr){
590         if (isset($_POST[$attr])){
591           $this->usertab->by_object['user']->$attr= $_POST[$attr];
592         }
593       }
594     }
596     /* Finish template preamble */
597     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
599       /* Might not be filled if IDGEN is unset */
600       $this->sn                 = $_POST['sn'];
601       $this->givenName          = $_POST['givenName'];
603       /* Move user supplied data to sub plugins */
604       $this->uid                = $_POST['uid'];
605       $this->usertab->uid       = $this->uid;
606       $this->usertab->sn        = $this->sn;
607       $this->usertab->givenName = $this->givenName;
608       $template_dn              = $_POST['template'];
609       $this->usertab->adapt_from_template($template_dn);
610       $template_base            = preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
611       $this->usertab->by_object['user']->base= $template_base;
613       /* Set up the users ACL's for this 'dn' */
614       $acl= get_permissions ($template_base, $this->ui->subtreeACL);
615       $this->usertab->set_acl($acl);
616     }
617     
618     if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
619       $this->usertab->by_object['user']->base= $userfilter['depselect'];
620     }
622     /* Show tab dialog if object is present */
623     if ($this->usertab){
624       $display= $this->usertab->execute();
626       /* Don't show buttons if tab dialog requests this */
627       if (!$this->usertab->by_object[$this->usertab->current]->dialog){
628         $display.= "<p style=\"text-align:right\">\n";
629         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
630         $display.= "&nbsp;\n";
631         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
632         $display.= "</p>";
633       }
634       return ($display);
635     }
637     $smarty= get_smarty();
639     /* Check sorting variable */
640     if (!isset($this->usertab) &&
641         !isset($_POST['new_user']) &&
642         !isset($_POST['new_template']) &&
643         !isset($_POST['delete_user']) &&
644         !isset($_POST['setpass_user']) &&
645         !isset($_POST['select_user'])){
646       $this->reload();
647     }
649     /* Check for exeeded sizelimit */
650     if (($message= check_sizelimit()) != ""){
651       return($message);
652     }
654     /* Prepare departments */
655     $options= "";
656     foreach ($this->config->idepartments as $key => $value){
657       if ($userfilter['depselect'] == $key){
658         $options.= "<option selected value='$key'>$value</option>";
659       } else {
660         $options.= "<option value='$key'>$value</option>";
661       }
662     }
664     /* NEW LIST MANAGMENT */
665     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
666       " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
667       " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
668       " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
669       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
670       " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'>&nbsp;".
671       " <input type='image' align='middle' src='images/list_new.png' title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'>&nbsp;".
672       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
673       _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
674       " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
675       "</div>";
677     $action= "<input type='image' src='images/edit.png' alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit user")."'>";
678     $action.= "<input type='image' src='images/list_password.png' alt='"._("password")."' name='user_chgpw_%KEY%' title='"._("Change password")."'>";
679     $action.= "<input type='image' src='images/edittrash.png' alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete user")."'>";
683     $divlist = new divlist("userstab");
684     $divlist->SetHeader(array(
685           array("string" => "&nbsp;"),
686           array("string" => _("Username")." / "._("Department")),
687           array("string" => _("Properties")),
688           array("string" => _("Actions"), "attach" => "style='border:none'" )));
691     $divlist->SetSummary(_("This table displays all users, in the selected tree."));
692     $divlist->SetEntriesPerPage(20);
694     // Defining Links 
695     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
697     /* Insert departments in divlist*/
698     foreach($this->departments as $key=> $val){
700       if(!isset($this->config->departments[trim($key)])){
701         $this->config->departments[trim($key)]="";
702       }
704       $non_empty="";
705       $keys= str_replace("/","\/",$key);
706       foreach($this->config->departments as $keyd=>$vald ){
707         if(preg_match("/".$keys."\/.*/",$keyd)){
708           $non_empty="full";
709         }
710       }
712       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>");
713       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
714       $field3 = array("string" => "&nbsp;");
715       $field4 = array("string" => "&nbsp;", "attach" => "style='border:none'");
718       $divlist->AddEntry(array($field1,$field2,$field3,$field4));
719     }
721     /* Pictures for Extensions */
722     $usrimg   ="<input type='image' src='images/penguin.png' alt='"._("GOsa")."'   
723                     name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
724     $posiximg = "<input type='image' src='images/select_user.png' alt='"._("Posix")."'  
725                     name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
726     $eviroimg = "<input type='image' src='images/smallenv.png' alt='"._("Environment")."'  
727                     name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
728     $mailimg  = "<input type='image' src='images/mailto.png' alt='"._("Mail")."'     
729                     name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
730     $fonimg   = "<input type='image' src='images/%image%' alt='"._("Phone")."'     
731                     name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
732     $faximg   = "<input type='image' src='images/fax_small.png' alt='"._("Fax")."'     
733                     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
734     $sambaimg = "<input type='image' src='images/select_winstation.png' alt='"._("Samba")."'     
735                     name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>"; 
736     $tplcreateuserimg  = "<input type='image' src='images/list_new.png' alt='"._("Create user from template")."'
737                     name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";   
738     
740     $empty    = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>"; 
742     // User and Template  Images  
743     $userimg  = "<img src='images/select_user.png' alt='User' title='%s'>";   
744     $tplimg   = "<img src='images/select_template.png' alt='Template' title='%s'>";   
745     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
747     // Defines Arrays to save User and Templates
748     $tpls = array();
749     $users= array();
751     /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
752      * Read Sip Table for specified account (for each user with phoneAccount).
753      * Check the attributes ip port and regseconds.
754      * If regseconds is set and >0 , the phone is logged in.
755      * Else the phone is currently not logged.
756      * If we can't read any Data from the DB or there is no goFon DB specified
757      * show old style without status icons.
758      */
759     $r_db   =false;
760     $r_con  =false;
761     if (isset($_SESSION['config']->data['SERVERS']['FON'])){
762       $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
763       // Connect to DB server
764   
765       /* 
766         If you want to disable the status pictures, just comment out the next line
767       */
768       $r_con= @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
769       // Check if we are  connected correctly
770       if($r_con){
771         $r_db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
772       }
773     }
775     // Test Every Entry and generate divlist Array  
776     foreach($this->list as $key => $val){
777       $connected  = ""; // This string represents timestamp or offline status 
778       $ip_port    = ""; // String that will represent ip : port of the connected phone
779       if((in_array("goFonAccount"    ,$val['objectClass']))){
780   
781         /* Set defaults */
782         $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
783         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
784         $fonac = preg_replace("/%title%/", "", $fonac);
786         /* Database connection is ok ?*/
787         if($r_db){
788           $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
789           $mysql_entry = @mysql_fetch_row($res);
790           if(is_array($mysql_entry)){
791             if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
792               $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
793               $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
794               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
795               $fonac = preg_replace("/%title%/", $connected, $fonac);
796               $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
797             }
798             if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
799               $connected = " | "._("Offline");
800               $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
801               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
802               $fonac = preg_replace("/%title%/", $connected, $fonac);
803             }
804           }
805         }
806       }else{
807         $fonac=$empty;
808       }
810     
812       // Specify Pics for Extensions  
813       if(in_array("posixAccount"    ,$val['objectClass'])){ 
814         $posix = preg_replace("/%KEY%/", "$key", $posiximg);
815       }else{ 
816         $posix=$empty;
817       }
818       
819       if(in_array("gotoEnvironment"    ,$val['objectClass'])){ 
820         $enviro = preg_replace("/%KEY%/", "$key", $eviroimg);
821       }else{ 
822         $enviro =$empty;
823       }
824    
825       if(in_array("gosaMailAccount" ,$val['objectClass'])){ 
826         $maila = preg_replace("/%KEY%/", "$key", $mailimg);   
827       }else{ 
828         $maila=$empty;
829       } 
830   
831       if(in_array("goFaxAccount"    ,$val['objectClass'])){ 
832         $faxac = preg_replace("/%KEY%/", "$key", $faximg);    
833       }else{ 
834         $faxac=$empty;
835       } 
837       if(in_array("sambaSamAccount" ,$val['objectClass'])){ 
838         $samba = preg_replace("/%KEY%/", "$key", $sambaimg);  
839       }else{ 
840         $samba=$empty;
841       } 
843       if(in_array("gosaUserTemplate",$val['objectClass'])){ 
844         $tpl                          = preg_replace("/%KEY%/", "$key", $tplimg);   
845         $s_img_create_from_template   = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
846       }else{ 
847         $s_img_create_from_template   = "";
848         $tpl=$userimg;
849       }
851       $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
853       // Generate caption for rows
854       if (isset($val["sn"]) && isset($val["givenName"])){
855         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
856       } else {
857         $display= "[".$val["uid"][0]."]";
858       }
860       /* Create each field */
861       $field1 = array("string" => sprintf($tpl,$val['dn']),"attach"=>"style='width:20px;align:middle;'");
862       $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port,"attach"=>"title='".$val['dn']."'");
863       $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;'");
864       $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='border:none; text-align:right;width:48px'");
866       $add = array($field1,$field2,$field3,$field4);
868       // Template or User
869       if(in_array("gosaUserTemplate",$val['objectClass'])){
870         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
871       }else{
872         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
873       }
874     }
876     // Sort Entries 
877     ksort($users);
878     ksort($tpls);
880     // Append Templates
881     foreach($tpls as $key => $val){
882       $divlist->AddEntry( $val, array(""));
883     }
884     // Append Users 
885     foreach($users as $key => $val){
886       $divlist->AddEntry( $val, array(""));
887     }
888     /* Show main page */
889     //$smarty->assign("userlist",   nl2br(htmlentities($divlist->DrawList())));
890     $smarty->assign("userlist",   $divlist->DrawList());
891     $smarty->assign("userlisthead", $listhead);
893     /* END NEW LIST MANAGMENT
894      */  
895     $smarty->assign("search_image", get_template_path('images/search.png'));
896     $smarty->assign("tree_image", get_template_path('images/tree.png'));
897     $smarty->assign("infoimage", get_template_path('images/info.png'));
898     $smarty->assign("launchimage", get_template_path('images/launch.png'));
899     $smarty->assign("deplist", $this->config->idepartments);
900     foreach( array("depselect",  "functionalusers", "unixusers",
901           "mailusers", "sambausers", "proxyusers", 
902           "faxusers", "templates", "subsearch") as $type){
904       $smarty->assign("$type", $userfilter[$type]);
905     }
907     $smarty->assign("regex", $userfilter["regex"]);
908     /* Extend if we are not using javascript */
909     $smarty->assign("apply", apply_filter());
910     $smarty->assign("alphabet", generate_alphabet());
911     $smarty->assign("hint", print_sizelimit_warning());
913     @mysql_close($r_con);
914     return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
915   }
918   function reload()
919   {
920     /* Get config */
921     $userfilter= get_global('userfilter');
923     /* Set base for all searches */
924     $base= $userfilter['depselect'];
926     /* Regex filter? */
927     if ($userfilter['regex'] != ""){
928       $regex= $userfilter['regex'];
929     } else {
930       $regex= "*";
931     }
933     /* Set filter depending on selection */
934     if ($this->config->current['SAMBAVERSION'] == 3){
935       $samba= "sambaSamAccount";
936     } else {
937       $samba= "sambaAccount";
938     }
940     $filter="";
941     if ($userfilter['functionalusers'] == "checked"){
942       $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)(objectClass=goFaxAccount)(objectClass=gosaProxyAccount))))";
943     }
944     if ($userfilter['unixusers'] == "checked"){
945       $filter.= "(objectClass=posixAccount)";
946     }
947     if ($userfilter['mailusers'] == "checked"){
948       $filter.= "(objectClass=gosaMailAccount)";
949     }
950     if ($userfilter['sambausers'] == "checked"){
951       $filter.= "(objectClass=$samba)";
952     }
953     if ($userfilter['proxyusers'] == "checked"){
954       $filter.= "(objectClass=gosaProxyAccount)";
955     }
956     if ($userfilter['faxusers'] == "checked"){
957       $filter.= "(objectClass=goFaxAccount)";
958     }
960     if ($userfilter['templates'] == "checked"){
961       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
962     } else {
963       $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
964     }
965     $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
967     /* Generate userlist */
968     $ldap= $this->config->get_ldap_link(TRUE);
969     if ($userfilter['subsearch'] == "checked"){
970       $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
971     } else {
972       $base= get_people_ou().$base;
973       $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
974     }
978     /* NEW LIST MANAGMENT
979      * We also need to search for the departments
980      * So we are able to navigate like in konquerer 
981      */
982     $base2 = preg_replace("/ou=people,/i","",$base);
984     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
985         TRUE, $base2, array("ou", "description"), TRUE);
987     $this->departments= array();
989     $tmp = array();
990     foreach ($res3 as $value){
991       $tmp[strtolower($value['dn']).$value['dn']]=$value;
992     }
993     ksort($tmp);
994     foreach($tmp as $value){
995       if($value["description"][0]!=".."){
996         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
997       }else{
998         $this->departments[$value['dn']]=$value["description"][0];
999       }
1000     }
1001     /* END NEW LIST MANAGMENT 
1002      */
1005     $this->userlist= array();
1007     foreach ($this->list as $value){
1008       if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
1009         if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
1010           $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
1011           continue;
1012         }
1013         if (isset($value["givenName"][0]) && isset($value["sn"][0])){
1014           $this->userlist[$value["dn"]]= $value["sn"][0].", ".
1015             $value["givenName"][0].
1016             " [".$value["uid"][0]."]";
1017         } else {
1018           $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
1019         }
1020       }
1021     }
1023     natcasesort ($this->userlist);
1024     reset ($this->userlist);
1025   }
1027   function remove_from_parent()
1028   {
1029   }
1032   /* Check values */
1033   function check()
1034   {
1035   }
1038   /* Save to LDAP */
1039   function save()
1040   {
1041   }
1043   function adapt_from_template($dn)
1044   {
1045   }
1047   function password_change_needed()
1048   {
1049   }
1051   function show_header($button_text, $text, $disabled= FALSE)
1052   {
1053   }
1055   function remove_lock()
1056   {
1057     if (isset($this->usertab->dn)){
1058       del_lock ($this->usertab->dn);
1059     }
1060   }
1064 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1065 ?>