Code

Fixed problem with phone accounts
[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       }
100     }
101     
102     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
103       $s_action ="edit";
104       $s_entry  = $_GET['id'];
105     }
107     $s_entry  = preg_replace("/_.$/","",$s_entry);
108     if(preg_match("/.*-.*/",$s_entry)){
109       $s_tab   = preg_replace("/^.*-/i","",$s_entry);
110       $s_entry = preg_replace("/-.*$/i","",$s_entry);
111     }else{
112       $s_tab   = "user";
113     };
115     /* Department changed? */
116     if(isset($_POST['depselect']) && $_POST['depselect']){
117       $userfilter['depselect']= $_POST['depselect'];
118     }
120     /* Homebutton is posted */
121     if($s_action=="home"){
122       $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
123       $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$userfilter['depselect']));
124     }
126     if($s_action=="root"){
127       $userfilter['depselect']=($this->config->current['BASE']);
128     }
131     /* If Backbutton is Posted */
132     if($s_action=="back"){
133       $base_back          = preg_replace("/^[^,]+,/","",$userfilter['depselect']);
134       $base_back          = convert_department_dn($base_back);
136       if(isset($this->config->departments[trim($base_back)])){
137         $userfilter['depselect']= $this->config->departments[trim($base_back)];
138       }else{
139         $userfilter['depselect']= $this->config->departments["/"];
140       }
141     }
142     /* End for new List Managment */
144     /* Save filter data if we are in the headpage */
145     if (!isset($this->usertab)){
146       if (isset($_POST['regexit'])){
147         $userfilter["regex"]= $_POST['regexit'];
148       }
149     }
150     if(isset($_POST['regexit'])){
151       foreach( array("functionalusers", "unixusers", "mailusers","sambausers", "proxyusers", "faxusers", "templates", "subsearch") as $type){
152         if (isset($_POST[$type])) {
153           $userfilter[$type]= "checked";
154         } else {
155           $userfilter[$type]= "";
156         }
157       }
158     }
159     if (isset($_GET['search'])){
160       $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
161       if ($s == "**"){
162         $s= "*";
163       }
164       $userfilter['regex']= $s;
165     }
166     register_global("userfilter", $userfilter);
167     
169     /* React on user interaction here */
170     if (($_SERVER["REQUEST_METHOD"] == "POST")||($_SERVER["REQUEST_METHOD"]== "GET")){
172       /* User wants to edit data? */
173       if ($s_action=="edit"){
175         /* Get 'dn' from posted 'uid', must be unique */
176         
177         $this->dn= $this->list[trim($s_entry)]['dn'];
179         /* Check locking, save current plugin in 'back_plugin', so
180            the dialog knows where to return. */
181         if (($user= get_lock($this->dn)) != ""){
182           return(gen_locked_message ($user, $this->dn));
183         }
185         /* Lock the current entry, so everyone will get the
186            above dialog */
187         add_lock ($this->dn, $this->ui->dn);
189         /* Set up the users ACL's for this 'dn' */
190         $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
192         /* Register usertab to trigger edit dialog */
193         $this->usertab= new usertabs($this->config, 
194             $this->config->data['TABS']['USERTABS'], $this->dn);
195 //        $_POST[$s_tab]=$s_tab;
197 // This would be better
198         $this->usertab->current = $s_tab;
199         $this->usertab->set_acl($acl);
201         $_SESSION['objectinfo']= $this->dn;
202       }
203     }
205     /* Reset requested? */
206     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
207       if (isset($this->usertab)){
208         del_lock ($this->usertab->dn);
209         unset ($this->usertab);
210       }
211       $this->usertab= NULL;
212       $this->lognames= array();;
213       $this->sn= "";
214       $this->givenName= "";
215       $this->uid= "";
216       unset ($_SESSION['objectinfo']);
217     }
219     /* Password change requested */
220     if ($s_action=="change_pw"){
222       /* Get 'dn' from posted 'uid' */
223       $this->dn= $this->list[trim($s_entry)]['dn'];
225       /* Load permissions for selected 'dn' and check if
226          we're allowed to remove this 'dn' */
227       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
228       $acl= get_module_permission($acl, "user", $this->dn);
229       if (chkacl($acl, "password") == ""){
231         /* User is allowed to change passwords, save 'dn' and 'acl' for next
232            dialog. */
233         $this->acl= $acl;
234         $_SESSION['objectinfo']= $this->dn;
235         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
237       } else {
238         /* User is not allowed. Show message and cancel. */
239         print_red (_("You are not allowed to set this users password!"));
240       }
241     }
243     /* Perform password change */
244     if (isset($_POST['password_finish'])){
246       /* For security reasons, check if user is allowed to set password again */
247       if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
249         /* Check input and feed errors into 'message' */
250         $message= array();
252         /* Sanity checks... */
253         if ($_POST['new_password'] != $_POST['repeated_password']){
255           /* Matching passwords in new and repeated? */
256           $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
257         } else {
259           /* Empty password is not permitted by default. */
260           if ($_POST['new_password'] == ""){
261             $message[]= _("The password you've entered as 'New password' is empty.");
262           }
263         }
265         /* Errors, or change password? */
266         if (count($message) != 0){
268           /* Show error message and continue editing */
269           show_errors ($message);
270           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
271         }
273         /* Set password, perform required steps */
274         if ($this->usertab){
275           if ($this->usertab->password_change_needed()){
276             $obj= $this->usertab->by_object['user'];
277             change_password ($this->usertab->dn, $_POST['new_password'],
278                 0, $obj->pw_storage);
279             gosa_log ("Password for '".$this->usertab->dn."' has been changed");
280             unset($this->usertab);
281             $this->usertab= NULL;
282           }
283         } else {
284           change_password ($this->dn, $_POST['new_password']);
285           gosa_log ("Password for '".$this->dn."' has been changed");
286         }
287       } else {
289         /* Missing permissions, show message */
290         print_red (_("You are not allowed to set this users password!"));
291       }
293       /* Clean session, delete lock */
294       del_lock ($this->dn);
295       $this->reload();
296       unset ($this->usertab);
297       $this->usertab= NULL;
298       $this->lognames= array();;
299       $this->sn= "";
300       $this->givenName= "";
301       $this->uid= "";
302       unset ($_SESSION['objectinfo']);
303     }
306     /* Remove user was requested */
307     if ($s_action=="del"){
309       /* Get 'dn' from posted 'uid' */
310       $this->dn= $this->list[trim($s_entry)]['dn'];
312       /* Load permissions for selected 'dn' and check if
313          we're allowed to remove this 'dn' */
314       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
315       $this->acl= get_module_permission($acl, "user", $this->dn);
316       if (chkacl($this->acl, "delete") == ""){
318         /* Check locking, save current plugin in 'back_plugin', so
319            the dialog knows where to return. */
320         if (($user= get_lock($this->dn)) != ""){
321           return(gen_locked_message ($user, $this->dn));
322         }
324         /* Lock the current entry, so nobody will edit it during deletion */
325         add_lock ($this->dn, $this->ui->dn);
326         $smarty->assign("info", sprintf(_("You're about to delete the user %s."), $this->dn));
327         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
328       } else {
330         /* Obviously the user isn't allowed to delete. Show message and
331            clean session. */
332         print_red (_("You are not allowed to delete this user!"));
333       }
334     }
338     /* Confirmation for deletion has been passed. User should be deleted. */
339     if (isset($_POST['delete_user_confirm'])){
341       /* Some nice guy may send this as POST, so we've to check
342          for the permissions again. */
343       if (chkacl($this->acl, "delete") == ""){
345         /* Delete request is permitted, perform LDAP action */
346         $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
347             $this->dn);
348         $this->usertab->set_acl(array($this->acl));
349         $this->usertab->delete ();
350         gosa_log ("User object '".$this->dn."' has been removed");
351         unset ($this->usertab);
352         $this->usertab= NULL;
354         /* User list has changed, reload it. */
355         $this->reload ();
356       } else {
358         /* Normally this shouldn't be reached, send some extra
359            logs to notify the administrator */
360         print_red (_("You are not allowed to delete this user!"));
362         if(isset($this->ui->uid)){
363           gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
364         }
365       }
367       /* Remove lock file after successfull deletion */
368       del_lock ($this->dn);
369     }
372     /* Delete user canceled? */
373     if (isset($_POST['delete_cancel'])){
374       del_lock ($this->dn);
375     }
378     /* Finish user edit is triggered by the tabulator dialog, so
379        the user wants to save edited data. Check and save at this
380        point. */
381     if (isset($_POST['edit_finish'])){
383       /* Check tabs, will feed message array */
384       $this->usertab->last= $this->usertab->current;
385       $this->usertab->save_object();
386       $message= $this->usertab->check();
388       /* Save, or display error message? */
389       if (count($message) == 0){
391         /* No errors. Go ahead and prepare to ask for a password
392            in case we're creating a new user. 'dn' will be 'new'
393            in this case. It is set to the correct value later. */
394         if ($this->dn == "new"){
395           $set_pass= 1;
396         } else {
397           $set_pass= 0;
398         }
400         /* Save user data to ldap */
401         if($this->usertab->save() == 1){
402           gosa_log ("User object '".$this->dn."' saving failed.");
403           return;
404         }
405         gosa_log ("User object '".$this->dn."' has been saved");
407         /* User has been saved successfully, remove lock from
408            LDAP. */
409         if ($this->dn != "new"){
410           del_lock ($this->dn);
411         }
413         /* In case of new users, ask for a password */
414         if (($set_pass || $this->usertab->password_change_needed()) &&
415             !$this->is_template){
417           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
418         }
420         /* There's no page reload so we have to read new users at
421            this point. */
422         $this->reload ();
423         unset ($this->usertab);
424         $this->usertab= NULL;
425         unset ($_SESSION['objectinfo']);
427       } else {
428         /* Ok. There seem to be errors regarding to the tab data,
429            show message and continue as usual. */
430         show_errors($message);
431       }
432     }
434     /* Generate template list */
435     if ($s_action=="new"){
436       $this->templates= array();
437       $ldap= $this->config->get_ldap_link();
438       foreach ($this->config->departments as $key => $value){
439         $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
440         $acl= get_module_permission($acl, "user", get_people_ou().$value);
441         if (chkacl($acl, "create") == ""){
442           $ldap->cd (get_people_ou().$value);
443           $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
445           if ($ldap->count() != 0){
446             while ($attrs= $ldap->fetch()){
447               $this->templates[$ldap->getDN()]=
448                 $attrs['uid'][0]." - $key";
449             }
450             $this->templates['none']= _("none");
451           }
452         }
453       }
454       natcasesort ($this->templates);
455       reset ($this->templates);
456     }
458     /* New user/template request */
459     if (($s_action=="new") || ($s_action=="new_tpl")){
460       /* By default we set 'dn' to 'new', all relevant plugins will
461          react on this. */
462       $this->dn= "new";
463       if (isset($this->config->current['IDGEN'])){
464         $this->got_uid= false;
465       } else {
466         $this->got_uid= true;
467       }
469       /* Create new usertab object */
470       $this->usertab= new usertabs($this->config,
471         $this->config->data['TABS']['USERTABS'], $this->dn);
472       $this->usertab->set_acl(array(':all'));
474       /* Take care about templates */
475       if ($s_action=="new_tpl"){
476         $this->is_template= TRUE;
477         $this->usertab->set_template_mode ();
478       } else {
479         $this->is_template= FALSE;
480       }
481     
482       /* Use template if there are any of them */
483       if (count($this->templates) && !isset($_POST['new_template'])){
484         foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
485           $smarty->assign("$attr", $this->$attr);
486         }
487         if (isset($_POST['template'])){
488           $smarty->assign("template", $_POST['template']);
489         } else {
490           $smarty->assign("template", "");
491         }
492         $smarty->assign("edit_uid", "");
493         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
494       }
495     }
497     /* Continue template editing */
498     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid'])){
499       $this->sn= $_POST['sn'];
500       $this->givenName= $_POST['givenName'];
502       /* Check for requred values */
503       $message= array();
504       if ($this->sn == "") {
505         $message[]= _("The required field 'Name' is not set.");
506       }
507       if ($this->givenName == "") {
508         $message[]= _("The required field 'Given name' is not set.");
509       }
511       /* Check if dn is used */
512       $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
513       $ldap= $this->config->get_ldap_link();
514       $ldap->cd ($dn);
515       $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
516       if ($ldap->count () != 0){
517         $message[]= _("A person with the choosen name is already used in this tree.");
518       }
520       /* Show error message / continue editing */
521       if (count($message) > 0){
522         show_errors ($message);
523       } else {
524         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
525         if (isset($this->config->current['IDGEN']) &&
526             $this->config->current['IDGEN'] != ""){
527           $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
528           if (count($uids)){
529             $smarty->assign("edit_uid", "false");
530             $smarty->assign("uids", $uids);
531             $this->uid= current($uids);
532           }
533         } else {
534             $smarty->assign("edit_uid", "");
535           $this->uid= "";
536         }
537         $this->got_uid= true;
538       }
540       foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
541         $smarty->assign("$attr", $this->$attr);
542       }
543       if (isset($_POST['template'])){
544         $smarty->assign("template", $_POST['template']);
545       }
546       return($smarty->fetch(get_template_path('template.tpl', TRUE)));
547     }
549     /* No template. Ok. Lets fill data into the normal user dialog */
550     if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
551       foreach(array("sn", "givenName", "uid") as $attr){
552         if (isset($_POST[$attr])){
553           $this->usertab->by_object['user']->$attr= $_POST[$attr];
554         }
555       }
556     }
558     /* Finish template preamble */
559     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
561       /* Might not be filled if IDGEN is unset */
562       $this->sn= $_POST['sn'];
563       $this->givenName= $_POST['givenName'];
565       /* Move user supplied data to sub plugins */
566       $this->uid= $_POST['uid'];
567       $this->usertab->uid= $this->uid;
568       $this->usertab->sn= $this->sn;
569       $this->usertab->givenName= $this->givenName;
570       $template_dn= $_POST['template'];
571       $this->usertab->adapt_from_template($template_dn);
572       $template_base= $userfilter['depselect'];//preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
573       $this->usertab->by_object['user']->base= $template_base;
575       /* Set up the users ACL's for this 'dn' */
576       $acl= get_permissions ($template_base, $this->ui->subtreeACL);
577       $this->usertab->set_acl($acl);
578     }
580     /* Show tab dialog if object is present */
581     if ($this->usertab){
582       $display= $this->usertab->execute();
584       /* Don't show buttons if tab dialog requests this */
585       if (!$this->usertab->by_object[$this->usertab->current]->dialog){
586         $display.= "<p style=\"text-align:right\">\n";
587         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
588         $display.= "&nbsp;\n";
589         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
590         $display.= "</p>";
591       }
592       return ($display);
593     }
595     $smarty= get_smarty();
597     /* Check sorting variable */
598     if (!isset($this->usertab) &&
599         !isset($_POST['new_user']) &&
600         !isset($_POST['new_template']) &&
601         !isset($_POST['delete_user']) &&
602         !isset($_POST['setpass_user']) &&
603         !isset($_POST['select_user'])){
604       $this->reload();
605     }
607     /* Check for exeeded sizelimit */
608     if (($message= check_sizelimit()) != ""){
609       return($message);
610     }
612     /* Prepare departments */
613     $options= "";
614     foreach ($this->config->idepartments as $key => $value){
615             if ($userfilter['depselect'] == $key){
616                     $options.= "<option selected value='$key'>$value</option>";
617             } else {
618                     $options.= "<option value='$key'>$value</option>";
619             }
620     }
621  
622     /* NEW LIST MANAGMENT */
623     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
624             " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
625             " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
626             " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
627             " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
628             " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'>&nbsp;".
629             " <input type='image' align='middle' src='images/list_new.png' title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'>&nbsp;".
630             " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
631             _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
632             " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
633             "</div>";
635     $action= "<input type='image' src='images/edit.png' alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit user")."'>";
636     $action.= "<input type='image' src='images/list_password.png' alt='"._("password")."' name='user_chgpw_%KEY%' title='"._("Change password")."'>";
637     $action.= "<input type='image' src='images/editdelete.png' alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete user")."'>";
641     $divlist = new divlist("userstab");
642     $divlist->SetHeader(array(
643                               array("string" => "&nbsp;"),
644                               array("string" => _("Username")." / "._("Department")),
645                               array("string" => _("Properties")),
646                               array("string" => _("Actions"), "attach" => "style='border:none'" )));
647                                     
649     $divlist->SetSummary(_("This table displays all users, in the selected tree."));
650     $divlist->SetEntriesPerPage(20);
652     // Defining Links 
653     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
655     foreach($this->departments as $key=> $val){
656       
657       if(!isset($this->config->departments[trim($key)])){
658         $this->config->departments[trim($key)]="";
659       }
661       $non_empty="";
662       $keys= str_replace("/","\/",$key);
663       foreach($this->config->departments as $keyd=>$vald ){
664         if(preg_match("/".$keys."\/.*/",$keyd)){
665           $non_empty="full";
666         }
667       }
672       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>");
673       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
674       $field3 = array("string" => "&nbsp;");
675       $field4 = array("string" => "&nbsp;", "attach" => "style='border:none'");
678       $divlist->AddEntry(array($field1,$field2,$field3,$field4));
679     }
681     // Pictures for Extensions 
682     $usrimg   ="<input type='image' src='images/penguin.png' alt='"._("GOsa")."'     name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
683     $posiximg = "<input type='image' src='images/select_user.png' alt='"._("Posix")."'     name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
684     $mailimg  = "<input type='image' src='images/mailto.png' alt='"._("Mail")."'     name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
685     $fonimg   = "<input type='image' src='images/%image%' alt='"._("Phone")."'     name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
686     $faximg   = "<input type='image' src='images/fax_small.png' alt='"._("Fax")."'     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
687     $sambaimg = "<input type='image' src='images/select_winstation.png' alt='"._("Samba")."'     name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>"; 
688     $empty    = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>"; 
689     
690     // User and Template  Images  
691     $userimg  = "<img src='images/select_user.png' alt='User' title='%s'>";   
692     $tplimg   = "<img src='images/select_template.png' alt='Template' title='%s'>";   
693    
694     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
695  
696     // Defines Arrays to save User and Templates
697     $tpls = array();
698     $users= array();
699     
700     // Get Configuration
701     $r_db=false;
702     if (isset($_SESSION['config']->data['SERVERS']['FON'])){
703       $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
704       // Connect to DB server
705       $r_con= @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
706       // Check if we are  connected correctly
707       if($r_con){
708         $r_db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
709       }
710     }
712     // Test Every Entry and generate divlist Array  
713     foreach($this->list as $key => $val){
714       $connected = "";
715       $ip_port= ""; 
716       if((in_array("goFonAccount"    ,$val['objectClass']))){
717         $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
718         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
719         $fonac = preg_replace("/%title%/", "", $fonac);
721         if($r_db){
722           $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
723           $mysql_entry = @mysql_fetch_row($res);
724           if(is_array($mysql_entry)){
725             if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
726               $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
727               $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
728               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
729               $fonac = preg_replace("/%title%/", $connected, $fonac);
730               $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
731             }
732             if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
733               $connected = " | "._("Offline");
734               $fonac = preg_replace("/%image%/", "select_phone_notconnected.png", $fonimg);
735               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
736               $fonac = preg_replace("/%title%/", $connected, $fonac);
737             }
738           }
739         }
740       }else{
741         $fonac=$empty;
742       }
743     
744       // Specify Pics for Extensions  
745       if(in_array("posixAccount"    ,$val['objectClass'])) $posix = preg_replace("/%KEY%/", "$key", $posiximg);  else $posix=$empty; 
746       if(in_array("gosaMailAccount" ,$val['objectClass'])) $maila = preg_replace("/%KEY%/", "$key", $mailimg);   else $maila=$empty; 
747       if(in_array("goFaxAccount"    ,$val['objectClass'])) $faxac = preg_replace("/%KEY%/", "$key", $faximg);    else $faxac=$empty; 
748       if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = preg_replace("/%KEY%/", "$key", $sambaimg);  else $samba=$empty; 
749       if(in_array("gosaUserTemplate",$val['objectClass'])) $tpl   = preg_replace("/%KEY%/", "$key", $tplimg);    else $tpl=$userimg;
750        
751       $usrimg = preg_replace("/%KEY%/", "$key", $usrimg);
752  
753       // Generate Array to Add 
754       if (isset($val["sn"]) && isset($val["givenName"])){
755         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
756       } else {
757         $display= "[".$val["uid"][0]."]";
758       }
760       $field1 = array("string" => sprintf($tpl,$val['dn']),"attach"=>"style='width:20px;align:middle;'");
761       $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port,"attach"=>"title='".$val['dn']."'");
762       $field3 = array("string" => $usrimg."&nbsp;".$posix."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba,"attach" => "style='width:118px;'");
763       $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='border:none; text-align:right;width:48px'");
764     
765       $add = array($field1,$field2,$field3,$field4);
766       
767       // Template or User
768       if(in_array("gosaUserTemplate",$val['objectClass'])){
769         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
770       }else{
771         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
772       }
773     }
774     
775     // Sort Entries 
776     ksort($users);
777     ksort($tpls);
779     // Append Templates
780     foreach($tpls as $key => $val){
781       $divlist->AddEntry( $val, array(""));
782     }
783     // Append Users 
784     foreach($users as $key => $val){
785       $divlist->AddEntry( $val, array(""));
786     }
787     /* Show main page */
788     //$smarty->assign("userlist",   nl2br(htmlentities($divlist->DrawList())));
789     $smarty->assign("userlist",   $divlist->DrawList());
790     $smarty->assign("userlisthead", $listhead);
792     /* END NEW LIST MANAGMENT
793      */  
794     $smarty->assign("search_image", get_template_path('images/search.png'));
795     $smarty->assign("tree_image", get_template_path('images/tree.png'));
796     $smarty->assign("infoimage", get_template_path('images/info.png'));
797     $smarty->assign("launchimage", get_template_path('images/launch.png'));
798     $smarty->assign("deplist", $this->config->idepartments);
799     foreach( array("depselect",  "functionalusers", "unixusers",
800           "mailusers", "sambausers", "proxyusers", 
801           "faxusers", "templates", "subsearch") as $type){
803       $smarty->assign("$type", $userfilter[$type]);
804     }
806     $smarty->assign("regex", $userfilter["regex"]);
807     /* Extend if we are not using javascript */
808     $smarty->assign("apply", apply_filter());
809     $smarty->assign("alphabet", generate_alphabet());
810     $smarty->assign("hint", print_sizelimit_warning());
812     return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
813   }
816   function reload()
817   {
818     /* Get config */
819     $userfilter= get_global('userfilter');
821     /* Set base for all searches */
822     $base= $userfilter['depselect'];
824     /* Regex filter? */
825     if ($userfilter['regex'] != ""){
826       $regex= $userfilter['regex'];
827     } else {
828       $regex= "*";
829     }
831     /* Set filter depending on selection */
832     if ($this->config->current['SAMBAVERSION'] == 3){
833       $samba= "sambaSamAccount";
834     } else {
835       $samba= "sambaAccount";
836     }
838     $filter="";
839     if ($userfilter['functionalusers'] == "checked"){
840       $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)(objectClass=goFaxAccount)(objectClass=gosaProxyAccount))))";
841     }
842     if ($userfilter['unixusers'] == "checked"){
843       $filter.= "(objectClass=posixAccount)";
844     }
845     if ($userfilter['mailusers'] == "checked"){
846       $filter.= "(objectClass=gosaMailAccount)";
847     }
848     if ($userfilter['sambausers'] == "checked"){
849       $filter.= "(objectClass=$samba)";
850     }
851     if ($userfilter['proxyusers'] == "checked"){
852       $filter.= "(objectClass=gosaProxyAccount)";
853     }
854     if ($userfilter['faxusers'] == "checked"){
855       $filter.= "(objectClass=goFaxAccount)";
856     }
858     if ($userfilter['templates'] == "checked"){
859       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
860     } else {
861       $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
862     }
863     $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
865     /* Generate userlist */
866     $ldap= $this->config->get_ldap_link(TRUE);
867     if ($userfilter['subsearch'] == "checked"){
868       $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
869     } else {
870       $base= get_people_ou().$base;
871       $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
872     }
876     /* NEW LIST MANAGMENT
877      * We also need to search for the departments
878      * So we are able to navigate like in konquerer 
879      */
880     $base2 = preg_replace("/ou=people,/i","",$base);
882     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
883                               TRUE, $base2, array("ou", "description"), TRUE);
885     $this->departments= array();
887     $tmp = array();
888     foreach ($res3 as $value){
889       $tmp[strtolower($value['dn']).$value['dn']]=$value;
890     }
891     ksort($tmp);
892     foreach($tmp as $value){
893       if($value["description"][0]!=".."){
894         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
895       }else{
896         $this->departments[$value['dn']]=$value["description"][0];
897       }
898     }
899     /* END NEW LIST MANAGMENT 
900      */
901   
902     
903     $this->userlist= array();
905     foreach ($this->list as $value){
906       if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
907         if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
908           $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
909           continue;
910         }
911         if (isset($value["givenName"][0]) && isset($value["sn"][0])){
912           $this->userlist[$value["dn"]]= $value["sn"][0].", ".
913             $value["givenName"][0].
914             " [".$value["uid"][0]."]";
915         } else {
916           $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
917         }
918       }
919     }
921     natcasesort ($this->userlist);
922     reset ($this->userlist);
923   }
925   function remove_from_parent()
926   {
927   }
930   /* Check values */
931   function check()
932   {
933   }
936   /* Save to LDAP */
937   function save()
938   {
939   }
941   function adapt_from_template($dn)
942   {
943   }
945   function password_change_needed()
946   {
947   }
949   function show_header($button_text, $text, $disabled= FALSE)
950   {
951   }
953   function remove_lock()
954   {
955     if (isset($this->usertab->dn)){
956       del_lock ($this->usertab->dn);
957     }
958   }
962 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
963 ?>