Code

Added Button to create user directly from template
[gosa.git] / plugins / admin / users / class_userManagement.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003  Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 require "tabs_user.inc";
22 class userManagement extends plugin
23 {
24   /* Definitions */
25   var $plHeadline= "Users";
26   var $plDescription= "This does something";
28   /* Dialog attributes */
29   var $usertab= NULL;
30   var $userlist= array();
31   var $ui= NULL;
32   var $acl= "";
33   var $templates= array();
34   var $got_uid= false;
35   var $departments=array();
37   function userManagement ($config, $ui)
38   {
39     /* Save configuration for internal use */
40     $this->config= $config;
41     $this->ui= $ui;
43     /* Get global filter config */
44     if (!isset($_SESSION["userfilter"])){
45       $base= get_base_from_people($ui->dn);
46       $userfilter= array( "mailusers"       => "checked",
47           "unixusers"       => "checked",
48           "templates"       => "",
49           "subsearch"       => "",
50           "proxyusers"      => "checked",
51           "sambausers"      => "checked",
52           "faxusers"        => "checked",
53           "functionalusers" => "checked",
54           "depselect"       => $base,
55           "regex"           => "*");
56       $_SESSION["userfilter"] = $userfilter;
57     }
58   }
60   function execute()
61   {
62     $smarty       = get_smarty();             // Smarty instance
63     $userfilter   = get_global("userfilter"); // contains Filter Settings
64     $s_action     = "";                       // Contains the action to proceed
65     $s_entry      = "";                       // The value for s_action
66     $base_back    = "";                       // The Link for Backbutton
68     /* Start for New List Managment */
69     if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
70       $s_action="open";
71       $s_entry = base64_decode($_GET['dep_id']);
72       $userfilter['depselect']= "".$this->config->departments[trim($s_entry)];
73     }
75     /* Test Posts */  
76     foreach($_POST as $key => $val){
77       // Post for delete
78       if(preg_match("/user_del.*/",$key)){
79         $s_action = "del";
80         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
81         // Post for edit
82       }elseif(preg_match("/user_edit_.*/",$key)){
83         $s_action="edit";
84         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
85         // Post for new
86       }elseif(preg_match("/dep_back.*/i",$key)){
87         $s_action="back";
88       }elseif(preg_match("/user_new.*/",$key)){
89         $s_action="new";
90       }elseif(preg_match("/dep_home.*/i",$key)){
91         $s_action="home";
92       }elseif(preg_match("/user_tplnew.*/i",$key)){
93         $s_action="new_tpl";
94       }elseif(preg_match("/user_chgpw.*/i",$key)){
95         $s_action="change_pw";
96         $s_entry  = preg_replace("/user_chgpw_/i","",$key);
97       }elseif(preg_match("/dep_root.*/i",$key)){
98         $s_action="root";
99       }elseif(preg_match("/userfrom_tpl.*/i",$key)){
100         $s_action="create_user_from_tpl";
101         $s_entry  = preg_replace("/userfrom_tpl_/i","",$key);
102       }
103     }
105     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
106       $s_action = "edit";
107       $s_entry  = $_GET['id'];
108     }
110     $s_entry  = preg_replace("/_.$/","",$s_entry);
111     if(preg_match("/.*-.*/",$s_entry)){
112       $s_tab   = preg_replace("/^.*-/i","",$s_entry);
113       $s_entry = preg_replace("/-.*$/i","",$s_entry);
114     }else{
115       $s_tab   = "user";
116     };
118     /* Department changed? */
119     if(isset($_POST['depselect']) && $_POST['depselect']){
120       $userfilter['depselect']= $_POST['depselect'];
121     }
123     /* Homebutton is posted */
124     if($s_action=="home"){
125       $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
126       $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$userfilter['depselect']));
127     }
129     if($s_action=="root"){
130       $userfilter['depselect']=($this->config->current['BASE']);
131     }
134     /* If Backbutton is Posted */
135     if($s_action=="back"){
136       $base_back          = preg_replace("/^[^,]+,/","",$userfilter['depselect']);
137       $base_back          = convert_department_dn($base_back);
139       if(isset($this->config->departments[trim($base_back)])){
140         $userfilter['depselect']= $this->config->departments[trim($base_back)];
141       }else{
142         $userfilter['depselect']= $this->config->departments["/"];
143       }
144     }
146     /* End for new List Managment */
148     /* Save filter data if we are in the headpage */
149     if (!isset($this->usertab)){
150       if (isset($_POST['regexit'])){
151         $userfilter["regex"]= $_POST['regexit'];
152       }
153     }
154     if(isset($_POST['regexit'])){
155       foreach( array("functionalusers", "unixusers", "mailusers","sambausers", "proxyusers", "faxusers", "templates", "subsearch") as $type){
156         if (isset($_POST[$type])) {
157           $userfilter[$type]= "checked";
158         } else {
159           $userfilter[$type]= "";
160         }
161       }
162     }
163     if (isset($_GET['search'])){
164       $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
165       if ($s == "**"){
166         $s= "*";
167       }
168       $userfilter['regex']= $s;
169     }
170     register_global("userfilter", $userfilter);
173     /* React on user interaction here */
174     if (($_SERVER["REQUEST_METHOD"] == "POST")||($_SERVER["REQUEST_METHOD"]== "GET")){
176       /* User wants to edit data? */
177       if ($s_action=="edit"){
179         /* Get 'dn' from posted 'uid', must be unique */
181         $this->dn= $this->list[trim($s_entry)]['dn'];
183         /* Check locking, save current plugin in 'back_plugin', so
184            the dialog knows where to return. */
185         if (($user= get_lock($this->dn)) != ""){
186           return(gen_locked_message ($user, $this->dn));
187         }
189         /* Lock the current entry, so everyone will get the
190            above dialog */
191         add_lock ($this->dn, $this->ui->dn);
193         /* Set up the users ACL's for this 'dn' */
194         $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
196         /* Register usertab to trigger edit dialog */
197         $this->usertab= new usertabs($this->config, 
198             $this->config->data['TABS']['USERTABS'], $this->dn);
199         //        $_POST[$s_tab]=$s_tab;
201         // This would be better
202         $this->usertab->current = $s_tab;
203         $this->usertab->set_acl($acl);
205         $_SESSION['objectinfo']= $this->dn;
206       }
207     }
209     /* Reset requested? */
210     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
211       if (isset($this->usertab)){
212         del_lock ($this->usertab->dn);
213         unset ($this->usertab);
214       }
215       $this->usertab= NULL;
216       $this->lognames= array();;
217       $this->sn= "";
218       $this->givenName= "";
219       $this->uid= "";
220       unset ($_SESSION['objectinfo']);
221     }
223     /* Password change requested */
224     if ($s_action=="change_pw"){
226       /* Get 'dn' from posted 'uid' */
227       $this->dn= $this->list[trim($s_entry)]['dn'];
229       /* Load permissions for selected 'dn' and check if
230          we're allowed to remove this 'dn' */
231       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
232       $acl= get_module_permission($acl, "user", $this->dn);
233       if (chkacl($acl, "password") == ""){
235         /* User is allowed to change passwords, save 'dn' and 'acl' for next
236            dialog. */
237         $this->acl= $acl;
238         $_SESSION['objectinfo']= $this->dn;
239         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
241       } else {
242         /* User is not allowed. Show message and cancel. */
243         print_red (_("You are not allowed to set this users password!"));
244       }
245     }
247     /* Perform password change */
248     if (isset($_POST['password_finish'])){
250       /* For security reasons, check if user is allowed to set password again */
251       if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
253         /* Check input and feed errors into 'message' */
254         $message= array();
256         /* Sanity checks... */
257         if ($_POST['new_password'] != $_POST['repeated_password']){
259           /* Matching passwords in new and repeated? */
260           $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
261         } else {
263           /* Empty password is not permitted by default. */
264           if ($_POST['new_password'] == ""){
265             $message[]= _("The password you've entered as 'New password' is empty.");
266           }
267         }
269         /* Errors, or change password? */
270         if (count($message) != 0){
272           /* Show error message and continue editing */
273           show_errors ($message);
274           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
275         }
277         $config= $this->config;
278         $ldap_ui= $this->config->get_ldap_link();
279         if(isset($this->usertab->dn)){
280           $user = ($ldap_ui->fetch($ldap_ui->cat($this->usertab->dn)));
281         }else{
282           $user = ($ldap_ui->fetch($ldap_ui->cat($this->dn)));
283         }
284         if((is_array($user))&&(isset($user['uid']))){
285           $username= $user['uid'][0];
286         }
288         /* Set password, perform required steps */
289         if ($this->usertab){
290           if ($this->usertab->password_change_needed()){
291             $obj= $this->usertab->by_object['user'];
292             change_password ($this->usertab->dn, $_POST['new_password'],
293                 0, $obj->pw_storage);
294             if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
295               exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
296             }
298             gosa_log ("Password for '".$this->usertab->dn."' has been changed");
299             unset($this->usertab);
300             $this->usertab= NULL;
301           }
302         } else {
303           change_password ($this->dn, $_POST['new_password']);
304           if (isset($config->data['MAIN']['EXTERNALPWDHOOK'])){
305             exec($config->data['MAIN']['EXTERNALPWDHOOK']." ".$username." ".$_POST['new_password'], $resarr);
306           }
308           gosa_log ("Password for '".$this->dn."' has been changed");
309         }
310       } else {
312         /* Missing permissions, show message */
313         print_red (_("You are not allowed to set this users password!"));
314       }
316       /* Clean session, delete lock */
317       del_lock ($this->dn);
318       $this->reload();
319       unset ($this->usertab);
320       $this->usertab= NULL;
321       $this->lognames= array();;
322       $this->sn= "";
323       $this->givenName= "";
324       $this->uid= "";
325       unset ($_SESSION['objectinfo']);
326     }
329     /* Remove user was requested */
330     if ($s_action=="del"){
332       /* Get 'dn' from posted 'uid' */
333       $this->dn= $this->list[trim($s_entry)]['dn'];
335       /* Load permissions for selected 'dn' and check if
336          we're allowed to remove this 'dn' */
337       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
338       $this->acl= get_module_permission($acl, "user", $this->dn);
339       if (chkacl($this->acl, "delete") == ""){
341         /* Check locking, save current plugin in 'back_plugin', so
342            the dialog knows where to return. */
343         if (($user= get_lock($this->dn)) != ""){
344           return(gen_locked_message ($user, $this->dn));
345         }
347         /* Lock the current entry, so nobody will edit it during deletion */
348         add_lock ($this->dn, $this->ui->dn);
349         $smarty->assign("info", sprintf(_("You're about to delete the user %s."), $this->dn));
350         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
351       } else {
353         /* Obviously the user isn't allowed to delete. Show message and
354            clean session. */
355         print_red (_("You are not allowed to delete this user!"));
356       }
357     }
361     /* Confirmation for deletion has been passed. User should be deleted. */
362     if (isset($_POST['delete_user_confirm'])){
364       /* Some nice guy may send this as POST, so we've to check
365          for the permissions again. */
366       if (chkacl($this->acl, "delete") == ""){
368         /* Delete request is permitted, perform LDAP action */
369         $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
370             $this->dn);
371         $this->usertab->set_acl(array($this->acl));
372         $this->usertab->delete ();
373         gosa_log ("User object '".$this->dn."' has been removed");
374         unset ($this->usertab);
375         $this->usertab= NULL;
377         /* User list has changed, reload it. */
378         $this->reload ();
379       } else {
381         /* Normally this shouldn't be reached, send some extra
382            logs to notify the administrator */
383         print_red (_("You are not allowed to delete this user!"));
385         if(isset($this->ui->uid)){
386           gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
387         }
388       }
390       /* Remove lock file after successfull deletion */
391       del_lock ($this->dn);
392     }
395     /* Delete user canceled? */
396     if (isset($_POST['delete_cancel'])){
397       del_lock ($this->dn);
398     }
401     /* Finish user edit is triggered by the tabulator dialog, so
402        the user wants to save edited data. Check and save at this
403        point. */
404     if (isset($_POST['edit_finish'])){
406       /* Check tabs, will feed message array */
407       $this->usertab->last= $this->usertab->current;
408       $this->usertab->save_object();
409       $message= $this->usertab->check();
411       /* Save, or display error message? */
412       if (count($message) == 0){
414         /* No errors. Go ahead and prepare to ask for a password
415            in case we're creating a new user. 'dn' will be 'new'
416            in this case. It is set to the correct value later. */
417         if ($this->dn == "new"){
418           $set_pass= 1;
419         } else {
420           $set_pass= 0;
421         }
423         /* Save user data to ldap */
424         if($this->usertab->save() == 1){
425           gosa_log ("User object '".$this->dn."' saving failed.");
426           return;
427         }
428         gosa_log ("User object '".$this->dn."' has been saved");
430         /* User has been saved successfully, remove lock from
431            LDAP. */
432         if ($this->dn != "new"){
433           del_lock ($this->dn);
434         }
436         /* In case of new users, ask for a password */
437         if (($set_pass || $this->usertab->password_change_needed()) &&
438             !$this->is_template){
440           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
441         }
443         /* There's no page reload so we have to read new users at
444            this point. */
445         $this->reload ();
446         unset ($this->usertab);
447         $this->usertab= NULL;
448         unset ($_SESSION['objectinfo']);
450       } else {
451         /* Ok. There seem to be errors regarding to the tab data,
452            show message and continue as usual. */
453         show_errors($message);
454       }
455     }
457     /* Generate template list */
458     if ($s_action=="new"){
459       $this->templates= array();
460       $ldap= $this->config->get_ldap_link();
461       foreach ($this->config->departments as $key => $value){
462         $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
463         $acl= get_module_permission($acl, "user", get_people_ou().$value);
464         if (chkacl($acl, "create") == ""){
465           $ldap->cd (get_people_ou().$value);
466           $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
468           if ($ldap->count() != 0){
469             while ($attrs= $ldap->fetch()){
470               $this->templates[$ldap->getDN()]=
471                 $attrs['uid'][0]." - $key";
472             }
473             $this->templates['none']= _("none");
474           }
475         }
476       }
477       natcasesort ($this->templates);
478       reset ($this->templates);
479     }
481     /* New user/template request */
482     if (($s_action=="create_user_from_tpl")||($s_action=="new") || ($s_action=="new_tpl")){
483       /* By default we set 'dn' to 'new', all relevant plugins will
484          react on this. */
485       $this->dn= "new";
486       if (isset($this->config->current['IDGEN'])){
487         $this->got_uid= false;
488       } else {
489         $this->got_uid= true;
490       }
492       /* Create new usertab object */
493       $this->usertab= new usertabs($this->config,
494           $this->config->data['TABS']['USERTABS'], $this->dn);
495       $this->usertab->set_acl(array(':all'));
497       /* Take care about templates */
498       if ($s_action=="new_tpl"){
499         $this->is_template= TRUE;
500         $this->usertab->set_template_mode ();
501       } else {
502         $this->is_template= FALSE;
503       }
505       /* Use template if there are any of them */
506       if (count($this->templates) && !isset($_POST['new_template'])){
507         foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
508           $smarty->assign("$attr", $this->$attr);
509         }
510         if ($s_action=="create_user_from_tpl"){
511           $smarty->assign("template", $this->dn= $this->list[trim($s_entry)]['dn']);
512         } else {
513           $smarty->assign("template", "");
514         }
515         $smarty->assign("edit_uid", "");
516         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
517       }
518     }
520     /* Continue template editing */
521     if ((isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid']))){
522       $this->sn= $_POST['sn'];
523       $this->givenName= $_POST['givenName'];
525       /* Check for requred values */
526       $message= array();
527       if ($this->sn == "") {
528         $message[]= _("The required field 'Name' is not set.");
529       }
530       if ($this->givenName == "") {
531         $message[]= _("The required field 'Given name' is not set.");
532       }
534       /* Check if dn is used */
535       $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
536       $ldap= $this->config->get_ldap_link();
537       $ldap->cd ($dn);
538       $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
539       if ($ldap->count () != 0){
540         $message[]= _("A person with the choosen name is already used in this tree.");
541       }
543       /* Show error message / continue editing */
544       if (count($message) > 0){
545         show_errors ($message);
546       } else {
547         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
548         if (isset($this->config->current['IDGEN']) &&
549             $this->config->current['IDGEN'] != ""){
550           $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
551           if (count($uids)){
552             $smarty->assign("edit_uid", "false");
553             $smarty->assign("uids", $uids);
554             $this->uid= current($uids);
555           }
556         } else {
557           $smarty->assign("edit_uid", "");
558           $this->uid= "";
559         }
560         $this->got_uid= true;
561       }
563       foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
564         $smarty->assign("$attr", $this->$attr);
565       }
566       if (isset($_POST['template'])){
567         $smarty->assign("template", $_POST['template']);
568       }
569       return($smarty->fetch(get_template_path('template.tpl', TRUE)));
570     }
572     /* No template. Ok. Lets fill data into the normal user dialog */
573     if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
574       foreach(array("sn", "givenName", "uid") as $attr){
575         if (isset($_POST[$attr])){
576           $this->usertab->by_object['user']->$attr= $_POST[$attr];
577         }
578       }
579     }
581     /* Finish template preamble */
582     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
584       /* Might not be filled if IDGEN is unset */
585       $this->sn                 = $_POST['sn'];
586       $this->givenName          = $_POST['givenName'];
588       /* Move user supplied data to sub plugins */
589       $this->uid                = $_POST['uid'];
590       $this->usertab->uid       = $this->uid;
591       $this->usertab->sn        = $this->sn;
592       $this->usertab->givenName = $this->givenName;
593       $template_dn              = $_POST['template'];
594       $this->usertab->adapt_from_template($template_dn);
595       $template_base            = $userfilter['depselect'];//preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
596       $this->usertab->by_object['user']->base= $template_base;
598       /* Set up the users ACL's for this 'dn' */
599       $acl= get_permissions ($template_base, $this->ui->subtreeACL);
600       $this->usertab->set_acl($acl);
601     }
603     /* Show tab dialog if object is present */
604     if ($this->usertab){
605       $display= $this->usertab->execute();
607       /* Don't show buttons if tab dialog requests this */
608       if (!$this->usertab->by_object[$this->usertab->current]->dialog){
609         $display.= "<p style=\"text-align:right\">\n";
610         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
611         $display.= "&nbsp;\n";
612         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
613         $display.= "</p>";
614       }
615       return ($display);
616     }
618     $smarty= get_smarty();
620     /* Check sorting variable */
621     if (!isset($this->usertab) &&
622         !isset($_POST['new_user']) &&
623         !isset($_POST['new_template']) &&
624         !isset($_POST['delete_user']) &&
625         !isset($_POST['setpass_user']) &&
626         !isset($_POST['select_user'])){
627       $this->reload();
628     }
630     /* Check for exeeded sizelimit */
631     if (($message= check_sizelimit()) != ""){
632       return($message);
633     }
635     /* Prepare departments */
636     $options= "";
637     foreach ($this->config->idepartments as $key => $value){
638       if ($userfilter['depselect'] == $key){
639         $options.= "<option selected value='$key'>$value</option>";
640       } else {
641         $options.= "<option value='$key'>$value</option>";
642       }
643     }
645     /* NEW LIST MANAGMENT */
646     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
647       " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
648       " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
649       " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
650       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
651       " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'>&nbsp;".
652       " <input type='image' align='middle' src='images/list_new.png' title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'>&nbsp;".
653       " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
654       _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
655       " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
656       "</div>";
658     $action= "<input type='image' src='images/edit.png' alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit user")."'>";
659     $action.= "<input type='image' src='images/list_password.png' alt='"._("password")."' name='user_chgpw_%KEY%' title='"._("Change password")."'>";
660     $action.= "<input type='image' src='images/editdelete.png' alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete user")."'>";
664     $divlist = new divlist("userstab");
665     $divlist->SetHeader(array(
666           array("string" => "&nbsp;"),
667           array("string" => _("Username")." / "._("Department")),
668           array("string" => _("Properties")),
669           array("string" => _("Actions"), "attach" => "style='border:none'" )));
672     $divlist->SetSummary(_("This table displays all users, in the selected tree."));
673     $divlist->SetEntriesPerPage(20);
675     // Defining Links 
676     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
678     /* Insert departments in divlist*/
679     foreach($this->departments as $key=> $val){
681       if(!isset($this->config->departments[trim($key)])){
682         $this->config->departments[trim($key)]="";
683       }
685       $non_empty="";
686       $keys= str_replace("/","\/",$key);
687       foreach($this->config->departments as $keyd=>$vald ){
688         if(preg_match("/".$keys."\/.*/",$keyd)){
689           $non_empty="full";
690         }
691       }
693       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>");
694       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
695       $field3 = array("string" => "&nbsp;");
696       $field4 = array("string" => "&nbsp;", "attach" => "style='border:none'");
699       $divlist->AddEntry(array($field1,$field2,$field3,$field4));
700     }
702     /* Pictures for Extensions */
703     $usrimg   ="<input type='image' src='images/penguin.png' alt='"._("GOsa")."'   
704                     name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
705     $posiximg = "<input type='image' src='images/select_user.png' alt='"._("Posix")."'  
706                     name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
707     $mailimg  = "<input type='image' src='images/mailto.png' alt='"._("Mail")."'     
708                     name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
709     $fonimg   = "<input type='image' src='images/%image%' alt='"._("Phone")."'     
710                     name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
711     $faximg   = "<input type='image' src='images/fax_small.png' alt='"._("Fax")."'     
712                     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
713     $sambaimg = "<input type='image' src='images/select_winstation.png' alt='"._("Samba")."'     
714                     name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>"; 
715     $tplcreateuserimg  = "<input type='image' src='images/list_new.png' alt='"._("Create user from template")."'
716                     name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";   
717     
719     $empty    = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>"; 
721     // User and Template  Images  
722     $userimg  = "<img src='images/select_user.png' alt='User' title='%s'>";   
723     $tplimg   = "<img src='images/select_template.png' alt='Template' title='%s'>";   
724     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
726     // Defines Arrays to save User and Templates
727     $tpls = array();
728     $users= array();
730     /* Get Configuration for goFon DB (if it is set), to connect to the asterisk tables.
731      * Read Sip Table for specified account (for each user with phoneAccount).
732      * Check the attributes ip port and regseconds.
733      * If regseconds is set and >0 , the phone is logged in.
734      * Else the phone is currently not logged.
735      * If we can't read any Data from the DB or there is no goFon DB specified
736      * show old style without status icons.
737      */
738     $r_db   =false;
739     $r_con  =false;
740     if (isset($_SESSION['config']->data['SERVERS']['FON'])){
741       $a_SETUP= $_SESSION['config']->data['SERVERS']['FON'];
742       // Connect to DB server
743   
744       /* 
745         If you want to disable the status pictures, just comment out the next line
746       */
747       $r_con= @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
748       // Check if we are  connected correctly
749       if($r_con){
750         $r_db  =  @mysql_select_db($a_SETUP['DB'],$r_con);
751       }
752     }
754     // Test Every Entry and generate divlist Array  
755     foreach($this->list as $key => $val){
756       $connected  = ""; // This string represents timestamp or offline status 
757       $ip_port    = ""; // String that will represent ip : port of the connected phone
758       if((in_array("goFonAccount"    ,$val['objectClass']))){
759   
760         /* Set defaults */
761         $fonac = preg_replace("/%image%/", "select_phone.png", $fonimg);
762         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
763         $fonac = preg_replace("/%title%/", "", $fonac);
765         /* Database connection is ok ?*/
766         if($r_db){
767           $res= @mysql_query("SELECT regseconds,name,port,ipaddr FROM ".$a_SETUP['SIP_TABLE']." WHERE (name='".$val['uid'][0]."')");
768           $mysql_entry = @mysql_fetch_row($res);
769           if(is_array($mysql_entry)){
770             if((isset($mysql_entry[0]))&&($mysql_entry[0]>1)){
771               $connected = " | "._("Online")." : ".gmdate("d.m.Y H:i:s",($mysql_entry[0]+(60*60)));
772               $fonac = preg_replace("/%image%/", "select_phone_connected.png", $fonimg);
773               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
774               $fonac = preg_replace("/%title%/", $connected, $fonac);
775               $ip_port= " - ".$mysql_entry[3].":".$mysql_entry[2];
776             }
777             if((isset($mysql_entry[0]))&&($mysql_entry[0]==0)){
778               $connected = " | "._("Offline");
779               $fonac = preg_replace("/%image%/", "select_phone_notconnected.png", $fonimg);
780               $fonac = preg_replace("/%KEY%/", "$key", $fonac);
781               $fonac = preg_replace("/%title%/", $connected, $fonac);
782             }
783           }
784         }
785       }else{
786         $fonac=$empty;
787       }
789       // Specify Pics for Extensions  
790       if(in_array("posixAccount"    ,$val['objectClass'])){ 
791         $posix = preg_replace("/%KEY%/", "$key", $posiximg);
792       }else{ 
793         $posix=$empty;
794       }
795    
796       if(in_array("gosaMailAccount" ,$val['objectClass'])){ 
797         $maila = preg_replace("/%KEY%/", "$key", $mailimg);   
798       }else{ 
799         $maila=$empty;
800       } 
801   
802       if(in_array("goFaxAccount"    ,$val['objectClass'])){ 
803         $faxac = preg_replace("/%KEY%/", "$key", $faximg);    
804       }else{ 
805         $faxac=$empty;
806       } 
808       if(in_array("sambaSamAccount" ,$val['objectClass'])){ 
809         $samba = preg_replace("/%KEY%/", "$key", $sambaimg);  
810       }else{ 
811         $samba=$empty;
812       } 
814       if(in_array("gosaUserTemplate",$val['objectClass'])){ 
815         $tpl                          = preg_replace("/%KEY%/", "$key", $tplimg);   
816         $s_img_create_from_template   = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
817       }else{ 
818         $s_img_create_from_template   = "";
819         $tpl=$userimg;
820       }
822       $usrimg = preg_replace("/%KEY%/", "$key", $usrimg);
824       // Generate caption for rows
825       if (isset($val["sn"]) && isset($val["givenName"])){
826         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
827       } else {
828         $display= "[".$val["uid"][0]."]";
829       }
831       /* Create each field */
832       $field1 = array("string" => sprintf($tpl,$val['dn']),"attach"=>"style='width:20px;align:middle;'");
833       $field2 = array("string" => sprintf($editlink,$key,$display).$ip_port,"attach"=>"title='".$val['dn']."'");
834       $field3 = array("string" => $usrimg."&nbsp;".$posix."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba."&nbsp;".$s_img_create_from_template, "attach" => "style='width:138px;'");
835       $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='border:none; text-align:right;width:48px'");
837       $add = array($field1,$field2,$field3,$field4);
839       // Template or User
840       if(in_array("gosaUserTemplate",$val['objectClass'])){
841         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
842       }else{
843         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
844       }
845     }
847     // Sort Entries 
848     ksort($users);
849     ksort($tpls);
851     // Append Templates
852     foreach($tpls as $key => $val){
853       $divlist->AddEntry( $val, array(""));
854     }
855     // Append Users 
856     foreach($users as $key => $val){
857       $divlist->AddEntry( $val, array(""));
858     }
859     /* Show main page */
860     //$smarty->assign("userlist",   nl2br(htmlentities($divlist->DrawList())));
861     $smarty->assign("userlist",   $divlist->DrawList());
862     $smarty->assign("userlisthead", $listhead);
864     /* END NEW LIST MANAGMENT
865      */  
866     $smarty->assign("search_image", get_template_path('images/search.png'));
867     $smarty->assign("tree_image", get_template_path('images/tree.png'));
868     $smarty->assign("infoimage", get_template_path('images/info.png'));
869     $smarty->assign("launchimage", get_template_path('images/launch.png'));
870     $smarty->assign("deplist", $this->config->idepartments);
871     foreach( array("depselect",  "functionalusers", "unixusers",
872           "mailusers", "sambausers", "proxyusers", 
873           "faxusers", "templates", "subsearch") as $type){
875       $smarty->assign("$type", $userfilter[$type]);
876     }
878     $smarty->assign("regex", $userfilter["regex"]);
879     /* Extend if we are not using javascript */
880     $smarty->assign("apply", apply_filter());
881     $smarty->assign("alphabet", generate_alphabet());
882     $smarty->assign("hint", print_sizelimit_warning());
884     return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
885   }
888   function reload()
889   {
890     /* Get config */
891     $userfilter= get_global('userfilter');
893     /* Set base for all searches */
894     $base= $userfilter['depselect'];
896     /* Regex filter? */
897     if ($userfilter['regex'] != ""){
898       $regex= $userfilter['regex'];
899     } else {
900       $regex= "*";
901     }
903     /* Set filter depending on selection */
904     if ($this->config->current['SAMBAVERSION'] == 3){
905       $samba= "sambaSamAccount";
906     } else {
907       $samba= "sambaAccount";
908     }
910     $filter="";
911     if ($userfilter['functionalusers'] == "checked"){
912       $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)(objectClass=goFaxAccount)(objectClass=gosaProxyAccount))))";
913     }
914     if ($userfilter['unixusers'] == "checked"){
915       $filter.= "(objectClass=posixAccount)";
916     }
917     if ($userfilter['mailusers'] == "checked"){
918       $filter.= "(objectClass=gosaMailAccount)";
919     }
920     if ($userfilter['sambausers'] == "checked"){
921       $filter.= "(objectClass=$samba)";
922     }
923     if ($userfilter['proxyusers'] == "checked"){
924       $filter.= "(objectClass=gosaProxyAccount)";
925     }
926     if ($userfilter['faxusers'] == "checked"){
927       $filter.= "(objectClass=goFaxAccount)";
928     }
930     if ($userfilter['templates'] == "checked"){
931       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
932     } else {
933       $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
934     }
935     $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
937     /* Generate userlist */
938     $ldap= $this->config->get_ldap_link(TRUE);
939     if ($userfilter['subsearch'] == "checked"){
940       $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
941     } else {
942       $base= get_people_ou().$base;
943       $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
944     }
948     /* NEW LIST MANAGMENT
949      * We also need to search for the departments
950      * So we are able to navigate like in konquerer 
951      */
952     $base2 = preg_replace("/ou=people,/i","",$base);
954     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
955         TRUE, $base2, array("ou", "description"), TRUE);
957     $this->departments= array();
959     $tmp = array();
960     foreach ($res3 as $value){
961       $tmp[strtolower($value['dn']).$value['dn']]=$value;
962     }
963     ksort($tmp);
964     foreach($tmp as $value){
965       if($value["description"][0]!=".."){
966         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
967       }else{
968         $this->departments[$value['dn']]=$value["description"][0];
969       }
970     }
971     /* END NEW LIST MANAGMENT 
972      */
975     $this->userlist= array();
977     foreach ($this->list as $value){
978       if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
979         if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
980           $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
981           continue;
982         }
983         if (isset($value["givenName"][0]) && isset($value["sn"][0])){
984           $this->userlist[$value["dn"]]= $value["sn"][0].", ".
985             $value["givenName"][0].
986             " [".$value["uid"][0]."]";
987         } else {
988           $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
989         }
990       }
991     }
993     natcasesort ($this->userlist);
994     reset ($this->userlist);
995   }
997   function remove_from_parent()
998   {
999   }
1002   /* Check values */
1003   function check()
1004   {
1005   }
1008   /* Save to LDAP */
1009   function save()
1010   {
1011   }
1013   function adapt_from_template($dn)
1014   {
1015   }
1017   function password_change_needed()
1018   {
1019   }
1021   function show_header($button_text, $text, $disabled= FALSE)
1022   {
1023   }
1025   function remove_lock()
1026   {
1027     if (isset($this->usertab->dn)){
1028       del_lock ($this->usertab->dn);
1029     }
1030   }
1034 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1035 ?>