Code

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