Code

Some page reload fixes,
[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;
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       
187       /* Check for config to ensure that there is currently no user open */
188       if (($s_action=="edit") && (!isset($this->usertab->config))){
190         /* Get 'dn' from posted 'uid', must be unique */
192         $this->dn= $this->list[trim($s_entry)]['dn'];
194         /* Check locking, save current plugin in 'back_plugin', so
195            the dialog knows where to return. */
196         if (($user= get_lock($this->dn)) != ""){
197           return(gen_locked_message ($user, $this->dn));
198         }
200         /* Lock the current entry, so everyone will get the
201            above dialog */
202         add_lock ($this->dn, $this->ui->dn);
204         /* Set up the users ACL's for this 'dn' */
205         $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
207         /* Register usertab to trigger edit dialog */
208         $this->usertab= new usertabs($this->config, 
209             $this->config->data['TABS']['USERTABS'], $this->dn);
210         //        $_POST[$s_tab]=$s_tab;
212         // This would be better
213         $this->usertab->current = $s_tab;
214         $this->usertab->set_acl($acl);
216         $_SESSION['objectinfo']= $this->dn;
217       }
218     }
220     /* Reset requested? */
221     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
222       if (isset($this->usertab)){
223         del_lock ($this->usertab->dn);
224         unset ($this->usertab);
225       }
226       $this->usertab= NULL;
227       $this->lognames= array();;
228       $this->sn= "";
229       $this->givenName= "";
230       $this->uid= "";
231       unset ($_SESSION['objectinfo']);
232     }
234     /* Password change requested */
235     if ($s_action=="change_pw"){
237       /* Get 'dn' from posted 'uid' */
238       $this->dn= $this->list[trim($s_entry)]['dn'];
240       /* Load permissions for selected 'dn' and check if
241          we're allowed to remove this 'dn' */
242       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
243       $acl= get_module_permission($acl, "user", $this->dn);
244       if (chkacl($acl, "password") == ""){
246         /* User is allowed to change passwords, save 'dn' and 'acl' for next
247            dialog. */
248         $this->acl= $acl;
249         $_SESSION['objectinfo']= $this->dn;
250         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
252       } else {
253         /* User is not allowed. Show message and cancel. */
254         print_red (_("You are not allowed to set this users password!"));
255       }
256     }
258     /* Perform password change */
259     if (isset($_POST['password_finish'])){
261       /* For security reasons, check if user is allowed to set password again */
262       if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
264         /* Check input and feed errors into 'message' */
265         $message= array();
267         /* Sanity checks... */
268         if ($_POST['new_password'] != $_POST['repeated_password']){
270           /* Matching passwords in new and repeated? */
271           $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
272         } else {
274           /* Empty password is not permitted by default. */
275           if ($_POST['new_password'] == ""){
276             $message[]= _("The password you've entered as 'New password' is empty.");
277           }
278         }
280         /* Errors, or change password? */
281         if (count($message) != 0){
283           /* Show error message and continue editing */
284           show_errors ($message);
285           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
286         }
288         $config= $this->config;
289         $ldap_ui= $this->config->get_ldap_link();
290         if(isset($this->usertab->dn)){
291           $user = ($ldap_ui->fetch($ldap_ui->cat($this->usertab->dn)));
292         }else{
293           $user = ($ldap_ui->fetch($ldap_ui->cat($this->dn)));
294         }
295         if((is_array($user))&&(isset($user['uid']))){
296           $username= $user['uid'][0];
297         }
299         /* Set password, perform required steps */
300         if ($this->usertab){
301           if ($this->usertab->password_change_needed()){
302             $obj= $this->usertab->by_object['user'];
303             change_password ($this->usertab->dn, $_POST['new_password'],
304                 0, $obj->pw_storage);
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->usertab->dn."' has been changed");
310             unset($this->usertab);
311             $this->usertab= NULL;
312           }
313         } else {
314           change_password ($this->dn, $_POST['new_password']);
315           if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
316             exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
317           }
319           gosa_log ("Password for '".$this->dn."' has been changed");
320         }
321       } else {
323         /* Missing permissions, show message */
324         print_red (_("You are not allowed to set this users password!"));
325       }
327       /* Clean session, delete lock */
328       del_lock ($this->dn);
329       $this->reload();
330       unset ($this->usertab);
331       $this->usertab= NULL;
332       $this->lognames= array();;
333       $this->sn= "";
334       $this->givenName= "";
335       $this->uid= "";
336       unset ($_SESSION['objectinfo']);
337     }
340     /* Remove user was requested */
341     if ($s_action=="del"){
343       /* Get 'dn' from posted 'uid' */
344       $this->dn= $this->list[trim($s_entry)]['dn'];
346       /* Load permissions for selected 'dn' and check if
347          we're allowed to remove this 'dn' */
348       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
349       $this->acl= get_module_permission($acl, "user", $this->dn);
350       if (chkacl($this->acl, "delete") == ""){
352         /* Check locking, save current plugin in 'back_plugin', so
353            the dialog knows where to return. */
354         if (($user= get_lock($this->dn)) != ""){
355           return(gen_locked_message ($user, $this->dn));
356         }
358         /* Lock the current entry, so nobody will edit it during deletion */
359         add_lock ($this->dn, $this->ui->dn);
360         $smarty->assign("info", sprintf(_("You're about to delete the user %s."), LDAP::fix($this->dn)));
361         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
362       } else {
364         /* Obviously the user isn't allowed to delete. Show message and
365            clean session. */
366         print_red (_("You are not allowed to delete this user!"));
367       }
368     }
372     /* Confirmation for deletion has been passed. User should be deleted. */
373     if (isset($_POST['delete_user_confirm'])){
375       /* Some nice guy may send this as POST, so we've to check
376          for the permissions again. */
377       if (chkacl($this->acl, "delete") == ""){
379         /* Delete request is permitted, perform LDAP action */
380         $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
381             $this->dn);
382         $this->usertab->set_acl(array($this->acl));
383         $this->usertab->delete ();
384         gosa_log ("User object '".$this->dn."' has been removed");
385         unset ($this->usertab);
386         $this->usertab= NULL;
388         /* User list has changed, reload it. */
389         $this->reload ();
390       } else {
392         /* Normally this shouldn't be reached, send some extra
393            logs to notify the administrator */
394         print_red (_("You are not allowed to delete this user!"));
396         if(isset($this->ui->uid)){
397           gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
398         }
399       }
401       /* Remove lock file after successfull deletion */
402       del_lock ($this->dn);
403     }
406     /* Delete user canceled? */
407     if (isset($_POST['delete_cancel'])){
408       del_lock ($this->dn);
409     }
412     /* Finish user edit is triggered by the tabulator dialog, so
413        the user wants to save edited data. Check and save at this
414        point. */
415     if ((isset($_POST['edit_finish'])) && (isset($this->usertab->config))){
417       /* Check tabs, will feed message array */
418       $this->usertab->last= $this->usertab->current;
419       $this->usertab->save_object();
420       $message= $this->usertab->check();
422       /* Save, or display error message? */
423       if (count($message) == 0){
425         /* No errors. Go ahead and prepare to ask for a password
426            in case we're creating a new user. 'dn' will be 'new'
427            in this case. It is set to the correct value later. */
428         if ($this->dn == "new"){
429           $set_pass= 1;
430         } else {
431           $set_pass= 0;
432         }
434         /* Save user data to ldap */
435         if($this->usertab->save() == 1){
436           gosa_log ("User object '".$this->dn."' saving failed.");
437           return;
438         }
439         gosa_log ("User object '".$this->dn."' has been saved");
441         /* User has been saved successfully, remove lock from
442            LDAP. */
443         if ($this->dn != "new"){
444           del_lock ($this->dn);
445         }
447         /* In case of new users, ask for a password */
448         if (($set_pass || $this->usertab->password_change_needed()) &&
449             !$this->is_template){
451           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
452         }
454         /* There's no page reload so we have to read new users at
455            this point. */
456         $this->reload ();
457         unset ($this->usertab);
458         $this->usertab= NULL;
459         unset ($_SESSION['objectinfo']);
461       } else {
462         /* Ok. There seem to be errors regarding to the tab data,
463            show message and continue as usual. */
464         show_errors($message);
465       }
466     }
468     /* Generate template list */
469     if (($s_action=="new")||($s_action=="create_user_from_tpl")){
471       $this->templates= array();
473       $ldap= $this->config->get_ldap_link();
475       /* Create list of tempaltes */
476       foreach ($this->config->departments as $key => $value){
477     
478         /* Get acls from different ou's */
479         $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
480         $acl= get_module_permission($acl, "user", get_people_ou().$value);
481   
482         /* If creation of a new user is allowed, append this template */
483         if (chkacl($acl, "create") == ""){
484           
485           /* Search all templates from the current dn */
486           $ldap->cd (get_people_ou().$value);
487           $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
489           /* Append */
490           if ($ldap->count() != 0){
491             while ($attrs= $ldap->fetch()){
492               $this->templates[$ldap->getDN()]=
493                 $attrs['uid'][0]." - $key";
494             }
495             $this->templates['none']= _("none");
496           }
497         }
498       }
500       /* Sort templates */
501       natcasesort ($this->templates);
502       reset ($this->templates);
503     }
505     /* New user/template request */
506     if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
507       /* By default we set 'dn' to 'new', all relevant plugins will
508          react on this. */
509       $this->dn= "new";
510       if (isset($this->config->current['IDGEN'])){
511         $this->got_uid= false;
512       } else {
513         $this->got_uid= true;
514       }
516       /* Create new usertab object */
517       $this->usertab= new usertabs($this->config,
518           $this->config->data['TABS']['USERTABS'], $this->dn);
519       $this->usertab->set_acl(array(':all'));
520       $this->usertab->by_object['user']->base= $userfilter['depselect'];
522       /* Take care about templates */
523       if ($s_action=="new_tpl"){
524         $this->is_template= TRUE;
525         $this->usertab->set_template_mode ();
526       } else {
527         $this->is_template= FALSE;
528       }
530       /* Use template if there are any of them */
531   
532       if ((count($this->templates) && ($s_action!='new_tpl'))||($s_action=="create_user_from_tpl")){
533         foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
534           $smarty->assign("$attr", $this->$attr);
535         }
536         if ($s_action=="create_user_from_tpl"){
537           $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
538         } else {
539           $smarty->assign("template", "none");
540         }
541         $smarty->assign("edit_uid", "");
542         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
543       }
544     }
546     /* Continue template editing */
547     if ((isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid']))){
548       $this->sn= $_POST['sn'];
549       $this->givenName= $_POST['givenName'];
551       /* Check for requred values */
552       $message= array();
553       if ($this->sn == "") {
554         $message[]= _("The required field 'Name' is not set.");
555       }
556       if ($this->givenName == "") {
557         $message[]= _("The required field 'Given name' is not set.");
558       }
560       /* Check if dn is used */
561       $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
562       $ldap= $this->config->get_ldap_link();
563       $ldap->cd ($dn);
564       $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
565       if ($ldap->count () != 0){
566         $message[]= _("A person with the choosen name is already used in this tree.");
567       }
569       /* Show error message / continue editing */
570       if (count($message) > 0){
571         show_errors ($message);
572       } else {
573         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
574         if (isset($this->config->current['IDGEN']) &&
575             $this->config->current['IDGEN'] != ""){
576           $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
577           if (count($uids)){
578             $smarty->assign("edit_uid", "false");
579             $smarty->assign("uids", $uids);
580             $this->uid= current($uids);
581           }
582         } else {
583           $smarty->assign("edit_uid", "");
584           $this->uid= "";
585         }
586         $this->got_uid= true;
587       }
589       foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
590         $smarty->assign("$attr", $this->$attr);
591       }
592       if (isset($_POST['template'])){
593         $smarty->assign("template", $_POST['template']);
594       }
595       return($smarty->fetch(get_template_path('template.tpl', TRUE)));
596     }
598     /* No template. Ok. Lets fill data into the normal user dialog */
599     if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
600       foreach(array("sn", "givenName", "uid") as $attr){
601         if (isset($_POST[$attr])){
602           $this->usertab->by_object['user']->$attr= $_POST[$attr];
603         }
604       }
605     }
607     /* Finish template preamble */
608     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
610       /* Might not be filled if IDGEN is unset */
611       $this->sn                 = $_POST['sn'];
612       $this->givenName          = $_POST['givenName'];
614       /* Move user supplied data to sub plugins */
615       $this->uid                = $_POST['uid'];
616       $this->usertab->uid       = $this->uid;
617       $this->usertab->sn        = $this->sn;
618       $this->usertab->givenName = $this->givenName;
619       $template_dn              = $_POST['template'];
620       $this->usertab->adapt_from_template($template_dn);
621       $template_base            = preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
622       $this->usertab->by_object['user']->base= $template_base;
624       /* Set up the users ACL's for this 'dn' */
625       $acl= get_permissions ($template_base, $this->ui->subtreeACL);
626       $this->usertab->set_acl($acl);
627     }
628     
629     if (isset($_POST['template_continue']) && ($_POST['template'] == 'none')){
630       $this->usertab->by_object['user']->base= $userfilter['depselect'];
631     }
633     /* Show tab dialog if object is present */
634     if(isset($this->usertab->config)){
635       $display= $this->usertab->execute();
637       /* Don't show buttons if tab dialog requests this */
638       if (!$this->usertab->by_object[$this->usertab->current]->dialog){
639         $display.= "<p style=\"text-align:right\">\n";
640         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
641         $display.= "&nbsp;\n";
642         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
643         $display.= "</p>";
644       }
645       return ($display);
646     }
648     $smarty= get_smarty();
650     /* Check sorting variable */
651     if (!isset($this->usertab) &&
652         !isset($_POST['new_user']) &&
653         !isset($_POST['new_template']) &&
654         !isset($_POST['delete_user']) &&
655         !isset($_POST['setpass_user']) &&
656         !isset($_POST['select_user'])){
657       $this->reload();
658     }
660     /* Check for exeeded sizelimit */
661     if (($message= check_sizelimit()) != ""){
662       return($message);
663     }
665     /* Prepare departments */
666     $options= "";
667     foreach ($this->config->idepartments as $key => $value){
668       if ($userfilter['depselect'] == $key){
669         $options.= "<option selected value='$key'>$value</option>";
670       } else {
671         $options.= "<option value='$key'>$value</option>";
672       }
673     }
675     /* NEW LIST MANAGMENT */
676     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
677       " <input class='center' type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
678       " <input class='center' type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
679       " <input class='center' type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
680       " <img   class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
681       " <input class='center' type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'>&nbsp;".
682       " <input class='center' type='image' align='middle' src='images/list_new.png' title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'>&nbsp;".
683       " <img   class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
684       _("Base")."&nbsp;<select name='depselect' onChange='mainform.submit()' class='center'>$options</select>".
685       " <input class='center' type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
686       "</div>";
688     $action= "<input class='center' type='image' src='images/edit.png' alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit user")."'>";
689     $action.= "<input class='center' type='image' src='images/list_password.png' alt='"._("password")."' name='user_chgpw_%KEY%' title='"._("Change password")."'>";
690     $action.= "<input class='center' type='image' src='images/edittrash.png' alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete user")."'>";
694     $divlist = new divlist("userstab");
695     $divlist->SetHeader(array(
696           array("string" => "&nbsp;", "attach" => "style='text-align:center;width:20px;'"),
697           array("string" => _("Username")." / "._("Department"), "attach" => "style=''"),
698           array("string" => _("Properties"), "attach" => "style='width:152px;'"),
699           array("string" => _("Actions"), "attach" => "style='width:60px;border-right:0px;text-align:right;'")));
702     $divlist->SetSummary(_("This table displays all users, in the selected tree."));
703     $divlist->SetEntriesPerPage(0);
705     // Defining Links 
706     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
708     /* Insert departments in divlist*/
709     foreach($this->departments as $key=> $val){
711       if(!isset($this->config->departments[trim($key)])){
712         $this->config->departments[trim($key)]="";
713       }
715       $non_empty="";
716       $keys= str_replace("/","\/",$key);
717       foreach($this->config->departments as $keyd=>$vald ){
718         if(preg_match("/".$keys."\/.*/",$keyd)){
719           $non_empty="full";
720         }
721       }
723       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>", "attach" => "style='text-align:center;width:20px;'");
724       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val), "attach" => "style=''");
725       $field3 = array("string" => "&nbsp;", "attach" => "style='width:152px;'");
726       $field4 = array("string" => "&nbsp;", "attach" => "style='width:60px;border-right:0px;text-align:right;'");
729       $divlist->AddEntry(array($field1,$field2,$field3,$field4));
730     }
732     /* Pictures for Extensions */
733     $usrimg   ="<input class='center' type='image' src='images/penguin.png' alt='"._("GOsa")."'   
734                     name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
735     $posiximg = "<input class='center' type='image' src='images/select_user.png' alt='"._("Posix")."'  
736                     name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
737     $eviroimg = "<input class='center' type='image' src='images/smallenv.png' alt='"._("Environment")."'  
738                     name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
739     $mailimg  = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'     
740                     name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
741     $fonimg   = "<input class='center' type='image' src='images/%image%' alt='"._("Phone")."'     
742                     name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
743     $faximg   = "<input class='center' type='image' src='images/fax_small.png' alt='"._("Fax")."'     
744                     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
745     $sambaimg = "<input class='center' type='image' src='images/select_winstation.png' alt='"._("Samba")."'     
746                     name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>"; 
747     $tplcreateuserimg  = "<input type='image' class='center' src='images/list_new.png' alt='"._("Create user from template")."'
748                     name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";   
749     
751     $empty    = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt=''>"; 
753     // User and Template  Images  
754     $userimg  = "<img class='center' src='images/select_user.png' alt='User' title='%s'>";   
755     $tplimg   = "<img class='center' src='images/select_template.png' alt='Template' title='%s'>";   
756     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
758     // Defines Arrays to save User and Templates
759     $tpls = array();
760     $users= array();
762     /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
763      * Read Sip Table for specified account (for each user with phoneAccount).
764      * Check the attributes ip port and regseconds.
765      * If regseconds is set and >0 , the phone is logged in.
766      * Else the phone is currently not logged.
767      * If we can't read any Data from the DB or there is no goFon DB specified
768      * show old style without status icons.
769      */
770     $r_db   =false;
771     $r_con  =false;
772     if (isset($_SESSION['config']->data['SERVERS']['FON'])){
773       $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
774       // Connect to DB server
775   
776       /* 
777         If you want to disable the status pictures, just comment out the next line
778       */
779       $r_con = false;
780       $r_db  = false;
781       if(is_callable("mysql_pconnect")){
782         $r_con= @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
783         // Check if we are  connected correctly
784         if($r_con){
785           $r_db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
786         }
787       }
788     }
790     // Test Every Entry and generate divlist Array  
791     foreach($this->list as $key => $val){
792       $connected  = ""; // This string represents timestamp or offline status 
793       $ip_port    = ""; // String that will represent ip : port of the connected phone
794       if((in_array("goFonAccount"    ,$val['objectClass']))){
795   
796         /* Set defaults */
797         $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
798         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
799         $fonac = preg_replace("/%title%/", "", $fonac);
801         /* Database connection is ok ?*/
802         if(($r_db)&&(is_callable("mysql_query"))){
803           $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
804           $mysql_entry = @mysql_fetch_row($res);
805           if(is_array($mysql_entry)){
806             if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
807               $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
808               $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
809               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
810               $fonac = preg_replace("/%title%/", $connected, $fonac);
811               $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
812             }
813             if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
814               $connected = " | "._("Offline");
815               $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
816               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
817               $fonac = preg_replace("/%title%/", $connected, $fonac);
818             }
819           }
820         }
821       }else{
822         $fonac=$empty;
823       }
825     
827       // Specify Pics for Extensions  
828       if(in_array("posixAccount"    ,$val['objectClass'])){ 
829         $posix = preg_replace("/%KEY%/", "$key", $posiximg);
830       }else{ 
831         $posix=$empty;
832       }
833       
834       if(in_array("gotoEnvironment"    ,$val['objectClass'])){ 
835         $enviro = preg_replace("/%KEY%/", "$key", $eviroimg);
836       }else{ 
837         $enviro =$empty;
838       }
839    
840       if(in_array("gosaMailAccount" ,$val['objectClass'])){ 
841         $maila = preg_replace("/%KEY%/", "$key", $mailimg);   
842       }else{ 
843         $maila=$empty;
844       } 
845   
846       if(in_array("goFaxAccount"    ,$val['objectClass'])){ 
847         $faxac = preg_replace("/%KEY%/", "$key", $faximg);    
848       }else{ 
849         $faxac=$empty;
850       } 
852       if(in_array("sambaSamAccount" ,$val['objectClass'])){ 
853         $samba = preg_replace("/%KEY%/", "$key", $sambaimg);  
854       }else{ 
855         $samba=$empty;
856       } 
858       if(in_array("gosaUserTemplate",$val['objectClass'])){ 
859         $tpl                          = preg_replace("/%KEY%/", "$key", $tplimg);   
860         $s_img_create_from_template   = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
861       }else{ 
862         $s_img_create_from_template   = "";
863         $tpl=$userimg;
864       }
866       $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
868       // Generate caption for rows
869       if (isset($val["sn"]) && isset($val["givenName"])){
870         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
871       } else {
872         $display= "[".$val["uid"][0]."]";
873       }
875       /* Create each field */
876       $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
877       $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port, "attach" => "style='' title='".$val['dn']."'");
878       $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:152px;'");
879       $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='width:60px;border-right:0px;text-align:right;'");
881       $add = array($field1,$field2,$field3,$field4);
883       // Template or User
884       if(in_array("gosaUserTemplate",$val['objectClass'])){
885         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
886       }else{
887         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
888       }
889     }
891     // Sort Entries 
892     ksort($users);
893     ksort($tpls);
895     // Append Templates
896     foreach($tpls as $key => $val){
897       $divlist->AddEntry( $val, array(""));
898     }
899     // Append Users 
900     foreach($users as $key => $val){
901       $divlist->AddEntry( $val, array(""));
902     }
903     /* Show main page */
904     //$smarty->assign("userlist",   nl2br(htmlentities($divlist->DrawList())));
905     $smarty->assign("userlist",   $divlist->DrawList());
906     $smarty->assign("userlisthead", $listhead);
908     /* END NEW LIST MANAGMENT
909      */  
910     $smarty->assign("search_image", get_template_path('images/search.png'));
911     $smarty->assign("tree_image", get_template_path('images/tree.png'));
912     $smarty->assign("infoimage", get_template_path('images/info.png'));
913     $smarty->assign("launchimage", get_template_path('images/launch.png'));
914     $smarty->assign("deplist", $this->config->idepartments);
915     foreach( array("depselect",  "functionalusers", "unixusers",
916           "mailusers", "sambausers", "proxyusers", 
917           "faxusers", "templates", "subsearch") as $type){
919       $smarty->assign("$type", $userfilter[$type]);
920     }
922     $smarty->assign("regex", $userfilter["regex"]);
923     /* Extend if we are not using javascript */
924     $smarty->assign("apply", apply_filter());
925     $smarty->assign("alphabet", generate_alphabet());
926     $smarty->assign("hint", print_sizelimit_warning());
928     if((is_callable("mysql_close"))&&($r_con)){
929       @mysql_close($r_con);
930     }
931     return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
932   }
935   function reload()
936   {
937     /* Get config */
938     $userfilter= get_global('userfilter');
940     /* Set base for all searches */
941     $base= $userfilter['depselect'];
943     /* Regex filter? */
944     if ($userfilter['regex'] != ""){
945       $regex= $userfilter['regex'];
946     } else {
947       $regex= "*";
948     }
950     /* Set filter depending on selection */
951     if ($this->config->current['SAMBAVERSION'] == 3){
952       $samba= "sambaSamAccount";
953     } else {
954       $samba= "sambaAccount";
955     }
957     $filter="";
958     if ($userfilter['functionalusers'] == "checked"){
959       $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)(objectClass=goFaxAccount)(objectClass=gosaProxyAccount))))";
960     }
961     if ($userfilter['unixusers'] == "checked"){
962       $filter.= "(objectClass=posixAccount)";
963     }
964     if ($userfilter['mailusers'] == "checked"){
965       $filter.= "(objectClass=gosaMailAccount)";
966     }
967     if ($userfilter['sambausers'] == "checked"){
968       $filter.= "(objectClass=$samba)";
969     }
970     if ($userfilter['proxyusers'] == "checked"){
971       $filter.= "(objectClass=gosaProxyAccount)";
972     }
973     if ($userfilter['faxusers'] == "checked"){
974       $filter.= "(objectClass=goFaxAccount)";
975     }
977     if ($userfilter['templates'] == "checked"){
978       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
979     } else {
980       $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
981     }
982     $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
984     /* Generate userlist */
985     $ldap= $this->config->get_ldap_link(TRUE);
986     if ($userfilter['subsearch'] == "checked"){
987       $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
988     } else {
989       $base= get_people_ou().$base;
990       $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
991     }
995     /* NEW LIST MANAGMENT
996      * We also need to search for the departments
997      * So we are able to navigate like in konquerer 
998      */
1000     /* Create base to search in */
1002     $peopleOU = get_people_ou();
1003     if(empty($peopleOU))  {
1004       $base2 = $base;
1005     }else{
1006       $base2 = preg_replace("/".$peopleOU."/i","",$base);
1007     }
1009     /* Get all departments within this subtree */
1010     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
1011         TRUE, $base2, array("ou", "description"), TRUE);
1013     $this->departments= array();
1015     /* Create array with results */
1016     $tmp = array();
1017     foreach ($res3 as $value){
1018       $tmp[strtolower($value['dn']).$value['dn']]=$value;
1019     }
1021     /* Sort array */
1022     ksort($tmp);
1024     /* Create result array */
1025     foreach($tmp as $value){
1026       if(isset($value['description'][0])){
1027         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
1028       }else{
1029         $this->departments[$value['dn']]=convert_department_dn2($value['dn']);
1030       }
1031     }
1032     /* END NEW LIST MANAGMENT 
1033      */
1036     $this->userlist= array();
1038     foreach ($this->list as $value){
1039       if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
1040         if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
1041           $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
1042           continue;
1043         }
1044         if (isset($value["givenName"][0]) && isset($value["sn"][0])){
1045           $this->userlist[$value["dn"]]= $value["sn"][0].", ".
1046             $value["givenName"][0].
1047             " [".$value["uid"][0]."]";
1048         } else {
1049           $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
1050         }
1051       }
1052     }
1054     natcasesort ($this->userlist);
1055     reset ($this->userlist);
1056   }
1058   function remove_from_parent()
1059   {
1060   }
1063   /* Check values */
1064   function check()
1065   {
1066   }
1069   /* Save to LDAP */
1070   function save()
1071   {
1072   }
1074   function adapt_from_template($dn)
1075   {
1076   }
1078   function password_change_needed()
1079   {
1080   }
1082   function show_header($button_text, $text, $disabled= FALSE)
1083   {
1084   }
1086   function remove_lock()
1087   {
1088     if (isset($this->usertab->dn)){
1089       del_lock ($this->usertab->dn);
1090     }
1091   }
1095 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1096 ?>