Code

Added diffrent pictures if department is empty .. or contains another dep..
[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             $this->reload();
74     }
76     /* Test Posts */  
77     foreach($_POST as $key => $val){
78       // Post for delete
79       if(preg_match("/user_del.*/",$key)){
80         $s_action = "del";
81         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
82         // Post for edit
83       }elseif(preg_match("/user_edit_.*/",$key)){
84         $s_action="edit";
85         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
86         // Post for new
87       }elseif(preg_match("/dep_back.*/i",$key)){
88         $s_action="back";
89       }elseif(preg_match("/user_new.*/",$key)){
90         $s_action="new";
91       }elseif(preg_match("/dep_home.*/i",$key)){
92         $s_action="home";
93       }elseif(preg_match("/user_tplnew.*/i",$key)){
94         $s_action="new_tpl";
95       }elseif(preg_match("/user_chgpw.*/i",$key)){
96         $s_action="change_pw";
97         $s_entry  = preg_replace("/user_chgpw_/i","",$key);
98       }elseif(preg_match("/dep_root.*/i",$key)){
99         $s_action="root";
100       }
101     }
102     
103     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
104       $s_action ="edit";
105       $s_entry  = $_GET['id'];
106     }
108     $s_entry  = preg_replace("/_.$/","",$s_entry);
110     /* Department changed? */
111     if(isset($_POST['depselect']) && $_POST['depselect']){
112       $userfilter['depselect']= $_POST['depselect'];
113       $this->reload();
114     }
116     /* Homebutton is posted */
117     if($s_action=="home"){
118       $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
119       $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$userfilter['depselect']));
120       $this->reload();
121     }
123     if($s_action=="root"){
124       $userfilter['depselect']=($this->config->current['BASE']);
125       $this->reload();
126     }
129     /* If Backbutton is Posted */
130     if($s_action=="back"){
131       $base_back          = preg_replace("/^[^,]+,/","",$userfilter['depselect']);
132       $base_back          = convert_department_dn($base_back);
134       if(isset($this->config->departments[trim($base_back)])){
135         $userfilter['depselect']= $this->config->departments[trim($base_back)];
136       }else{
137         $userfilter['depselect']= $this->config->departments["/"];
138       }
139       $this->reload();
140     }
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         $this->usertab->set_acl($acl);
197         $_SESSION['objectinfo']= $this->dn;
198       }
199     }
201     /* Reset requested? */
202     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
203       if (isset($this->usertab)){
204         del_lock ($this->usertab->dn);
205         unset ($this->usertab);
206       }
207       $this->usertab= NULL;
208       $this->lognames= array();;
209       $this->sn= "";
210       $this->givenName= "";
211       $this->uid= "";
212       unset ($_SESSION['objectinfo']);
213     }
215     /* Password change requested */
216     if ($s_action=="change_pw"){
218       /* Get 'dn' from posted 'uid' */
219       $this->dn= $this->list[trim($s_entry)]['dn'];
221       /* Load permissions for selected 'dn' and check if
222          we're allowed to remove this 'dn' */
223       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
224       $acl= get_module_permission($acl, "user", $this->dn);
225       if (chkacl($acl, "password") == ""){
227         /* User is allowed to change passwords, save 'dn' and 'acl' for next
228            dialog. */
229         $this->acl= $acl;
230         $_SESSION['objectinfo']= $this->dn;
231         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
233       } else {
234         /* User is not allowed. Show message and cancel. */
235         print_red (_("You are not allowed to set this users password!"));
236       }
237     }
239     /* Perform password change */
240     if (isset($_POST['password_finish'])){
242       /* For security reasons, check if user is allowed to set password again */
243       if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
245         /* Check input and feed errors into 'message' */
246         $message= array();
248         /* Sanity checks... */
249         if ($_POST['new_password'] != $_POST['repeated_password']){
251           /* Matching passwords in new and repeated? */
252           $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
253         } else {
255           /* Empty password is not permitted by default. */
256           if ($_POST['new_password'] == ""){
257             $message[]= _("The password you've entered as 'New password' is empty.");
258           }
259         }
261         /* Errors, or change password? */
262         if (count($message) != 0){
264           /* Show error message and continue editing */
265           show_errors ($message);
266           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
267         }
269         /* Set password, perform required steps */
270         if ($this->usertab){
271           if ($this->usertab->password_change_needed()){
272             $obj= $this->usertab->by_object['user'];
273             change_password ($this->usertab->dn, $_POST['new_password'],
274                 0, $obj->pw_storage);
275             gosa_log ("Password for '".$this->usertab->dn."' has been changed");
276             unset($this->usertab);
277             $this->usertab= NULL;
278           }
279         } else {
280           change_password ($this->dn, $_POST['new_password']);
281           gosa_log ("Password for '".$this->dn."' has been changed");
282         }
283       } else {
285         /* Missing permissions, show message */
286         print_red (_("You are not allowed to set this users password!"));
287       }
289       /* Clean session, delete lock */
290       del_lock ($this->dn);
291       $this->reload();
292       unset ($this->usertab);
293       $this->usertab= NULL;
294       $this->lognames= array();;
295       $this->sn= "";
296       $this->givenName= "";
297       $this->uid= "";
298       unset ($_SESSION['objectinfo']);
299     }
302     /* Remove user was requested */
303     if ($s_action=="del"){
305       /* Get 'dn' from posted 'uid' */
306       $this->dn= $this->list[trim($s_entry)]['dn'];
308       /* Load permissions for selected 'dn' and check if
309          we're allowed to remove this 'dn' */
310       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
311       $this->acl= get_module_permission($acl, "user", $this->dn);
312       if (chkacl($this->acl, "delete") == ""){
314         /* Check locking, save current plugin in 'back_plugin', so
315            the dialog knows where to return. */
316         if (($user= get_lock($this->dn)) != ""){
317           return(gen_locked_message ($user, $this->dn));
318         }
320         /* Lock the current entry, so nobody will edit it during deletion */
321         add_lock ($this->dn, $this->ui->dn);
322         $smarty->assign("info", sprintf(_("You're about to delete the user %s."), $this->dn));
323         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
324       } else {
326         /* Obviously the user isn't allowed to delete. Show message and
327            clean session. */
328         print_red (_("You are not allowed to delete this user!"));
329       }
330     }
334     /* Confirmation for deletion has been passed. User should be deleted. */
335     if (isset($_POST['delete_user_confirm'])){
337       /* Some nice guy may send this as POST, so we've to check
338          for the permissions again. */
339       if (chkacl($this->acl, "delete") == ""){
341         /* Delete request is permitted, perform LDAP action */
342         $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
343             $this->dn);
344         $this->usertab->set_acl(array($this->acl));
345         $this->usertab->delete ();
346         gosa_log ("User object '".$this->dn."' has been removed");
347         unset ($this->usertab);
348         $this->usertab= NULL;
350         /* User list has changed, reload it. */
351         $this->reload ();
352       } else {
354         /* Normally this shouldn't be reached, send some extra
355            logs to notify the administrator */
356         print_red (_("You are not allowed to delete this user!"));
358         if(isset($this->ui->uid)){
359           gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
360         }
361       }
363       /* Remove lock file after successfull deletion */
364       del_lock ($this->dn);
365     }
368     /* Delete user canceled? */
369     if (isset($_POST['delete_cancel'])){
370       del_lock ($this->dn);
371     }
374     /* Finish user edit is triggered by the tabulator dialog, so
375        the user wants to save edited data. Check and save at this
376        point. */
377     if (isset($_POST['edit_finish'])){
379       /* Check tabs, will feed message array */
380       $this->usertab->last= $this->usertab->current;
381       $this->usertab->save_object();
382       $message= $this->usertab->check();
384       /* Save, or display error message? */
385       if (count($message) == 0){
387         /* No errors. Go ahead and prepare to ask for a password
388            in case we're creating a new user. 'dn' will be 'new'
389            in this case. It is set to the correct value later. */
390         if ($this->dn == "new"){
391           $set_pass= 1;
392         } else {
393           $set_pass= 0;
394         }
396         /* Save user data to ldap */
397         if($this->usertab->save() == 1){
398           gosa_log ("User object '".$this->dn."' saving failed.");
399           return;
400         }
401         gosa_log ("User object '".$this->dn."' has been saved");
403         /* User has been saved successfully, remove lock from
404            LDAP. */
405         if ($this->dn != "new"){
406           del_lock ($this->dn);
407         }
409         /* In case of new users, ask for a password */
410         if (($set_pass || $this->usertab->password_change_needed()) &&
411             !$this->is_template){
413           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
414         }
416         /* There's no page reload so we have to read new users at
417            this point. */
418         $this->reload ();
419         unset ($this->usertab);
420         $this->usertab= NULL;
421         unset ($_SESSION['objectinfo']);
423       } else {
424         /* Ok. There seem to be errors regarding to the tab data,
425            show message and continue as usual. */
426         show_errors($message);
427       }
428     }
430     /* Generate template list */
431     if ($s_action=="new"){
432       $this->templates= array();
433       $ldap= $this->config->get_ldap_link();
434       foreach ($this->config->departments as $key => $value){
435         $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
436         $acl= get_module_permission($acl, "user", get_people_ou().$value);
437         if (chkacl($acl, "create") == ""){
438           $ldap->cd (get_people_ou().$value);
439           $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
441           if ($ldap->count() != 0){
442             while ($attrs= $ldap->fetch()){
443               $this->templates[$ldap->getDN()]=
444                 $attrs['uid'][0]." - $key";
445             }
446             $this->templates['none']= _("none");
447           }
448         }
449       }
450       natcasesort ($this->templates);
451       reset ($this->templates);
452     }
454     /* New user/template request */
455     if (($s_action=="new") || ($s_action=="new_tpl")){
456       /* By default we set 'dn' to 'new', all relevant plugins will
457          react on this. */
458       $this->dn= "new";
459       if (isset($this->config->current['IDGEN'])){
460         $this->got_uid= false;
461       } else {
462         $this->got_uid= true;
463       }
465       /* Create new usertab object */
466       $this->usertab= new usertabs($this->config,
467         $this->config->data['TABS']['USERTABS'], $this->dn);
468       $this->usertab->set_acl(array(':all'));
470       /* Take care about templates */
471       if ($s_action=="new_tpl"){
472         $this->is_template= TRUE;
473         $this->usertab->set_template_mode ();
474       } else {
475         $this->is_template= FALSE;
476       }
477     
478       /* Use template if there are any of them */
479       if (count($this->templates) && !isset($_POST['new_template'])){
480         foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
481           $smarty->assign("$attr", $this->$attr);
482         }
483         if (isset($_POST['template'])){
484           $smarty->assign("template", $_POST['template']);
485         } else {
486           $smarty->assign("template", "");
487         }
488         $smarty->assign("edit_uid", "");
489         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
490       }
491     }
493     /* Continue template editing */
494     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid'])){
495       $this->sn= $_POST['sn'];
496       $this->givenName= $_POST['givenName'];
498       /* Check for requred values */
499       $message= array();
500       if ($this->sn == "") {
501         $message[]= _("The required field 'Name' is not set.");
502       }
503       if ($this->givenName == "") {
504         $message[]= _("The required field 'Given name' is not set.");
505       }
507       /* Check if dn is used */
508       $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
509       $ldap= $this->config->get_ldap_link();
510       $ldap->cd ($dn);
511       $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
512       if ($ldap->count () != 0){
513         $message[]= _("A person with the choosen name is already used in this tree.");
514       }
516       /* Show error message / continue editing */
517       if (count($message) > 0){
518         show_errors ($message);
519       } else {
520         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
521         if (isset($this->config->current['IDGEN']) &&
522             $this->config->current['IDGEN'] != ""){
523           $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
524           if (count($uids)){
525             $smarty->assign("edit_uid", "false");
526             $smarty->assign("uids", $uids);
527             $this->uid= current($uids);
528           }
529         } else {
530             $smarty->assign("edit_uid", "");
531           $this->uid= "";
532         }
533         $this->got_uid= true;
534       }
536       foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
537         $smarty->assign("$attr", $this->$attr);
538       }
539       if (isset($_POST['template'])){
540         $smarty->assign("template", $_POST['template']);
541       }
542       return($smarty->fetch(get_template_path('template.tpl', TRUE)));
543     }
545     /* No template. Ok. Lets fill data into the normal user dialog */
546     if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
547       foreach(array("sn", "givenName", "uid") as $attr){
548         if (isset($_POST[$attr])){
549           $this->usertab->by_object['user']->$attr= $_POST[$attr];
550         }
551       }
552     }
554     /* Finish template preamble */
555     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
557       /* Might not be filled if IDGEN is unset */
558       $this->sn= $_POST['sn'];
559       $this->givenName= $_POST['givenName'];
561       /* Move user supplied data to sub plugins */
562       $this->uid= $_POST['uid'];
563       $this->usertab->uid= $this->uid;
564       $this->usertab->sn= $this->sn;
565       $this->usertab->givenName= $this->givenName;
566       $template_dn= $_POST['template'];
567       $this->usertab->adapt_from_template($template_dn);
568       $template_base= $userfilter['depselect'];//preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
569       $this->usertab->by_object['user']->base= $template_base;
571       /* Set up the users ACL's for this 'dn' */
572       $acl= get_permissions ($template_base, $this->ui->subtreeACL);
573       $this->usertab->set_acl($acl);
574     }
576     /* Show tab dialog if object is present */
577     if ($this->usertab){
578       $display= $this->usertab->execute();
580       /* Don't show buttons if tab dialog requests this */
581       if (!$this->usertab->by_object[$this->usertab->current]->dialog){
582         $display.= "<p style=\"text-align:right\">\n";
583         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
584         $display.= "&nbsp;\n";
585         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
586         $display.= "</p>";
587       }
588       return ($display);
589     }
591     $smarty= get_smarty();
593     /* Check sorting variable */
594     if (!isset($this->usertab) &&
595         !isset($_POST['new_user']) &&
596         !isset($_POST['new_template']) &&
597         !isset($_POST['delete_user']) &&
598         !isset($_POST['setpass_user']) &&
599         !isset($_POST['select_user'])){
600       $this->reload();
601     }
603     /* Check for exeeded sizelimit */
604     if (($message= check_sizelimit()) != ""){
605       return($message);
606     }
608     /* Prepare departments */
609     $options= "";
610     foreach ($this->config->idepartments as $key => $value){
611             if ($userfilter['depselect'] == $key){
612                     $options.= "<option selected value='$key'>$value</option>";
613             } else {
614                     $options.= "<option value='$key'>$value</option>";
615             }
616     }
617  
618     /* NEW LIST MANAGMENT */
619     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
620             " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
621             " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
622             " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
623             " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
624             " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'>&nbsp;".
625             " <input type='image' align='middle' src='images/list_new.png' title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'>&nbsp;".
626             " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
627             _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
628             " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
629             "</div>";
631     $action= "<input type='image' src='images/edit.png' alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit user")."'>";
632     $action.= "<input type='image' src='images/list_password.png' alt='"._("password")."' name='user_chgpw_%KEY%' title='"._("Change password")."'>";
633     $action.= "<input type='image' src='images/editdelete.png' alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete user")."'>";
637     $divlist = new divlist("userstab");
638     $divlist->SetHeader(array(
639                               array("string" => "&nbsp;"),
640                               array("string" => _("Username")." / "._("Department")),
641                               array("string" => _("Properties")),
642                               array("string" => _("Actions"), "attach" => "style='border:none'" )));
643                                     
645     $divlist->SetSummary(_("This table displays all users, in the selected tree."));
646     $divlist->SetEntriesPerPage(20);
648     // Defining Links 
649     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
651     foreach($this->departments as $key=> $val){
652       
653       if(!isset($this->config->departments[trim($key)])){
654         $this->config->departments[trim($key)]="";
655       }
657       $non_empty="";
658       $keys= str_replace("/","\/",$key);
659       foreach($this->config->departments as $keyd=>$vald ){
660         if(preg_match("/".$keys."\/.*/",$keyd)){
661           $non_empty="full";
662         }
663       }
668       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>");
669       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
670       $field3 = array("string" => "&nbsp;");
671       $field4 = array("string" => "&nbsp;", "attach" => "style='border:none'");
674       $divlist->AddEntry(array($field1,$field2,$field3,$field4));
675     }
677     // Pictures for Extensions 
678     $usrimg  = "<img src='images/penguin.png'             alt='U' title='"._("GOsa")  ."'>";
679     $posiximg = "<img src='images/select_user.png'        alt='P' title='"._("Posix") ."'>";
680     $mailimg  = "<img src='images/mailto.png'             alt='M' title='"._("Mail")  ."'>";
681     $fonimg   = "<img src='images/select_phone.png'       alt='T' title='"._("Phone") ."'>";
682     $faximg   = "<img src='images/fax_small.png'          alt='F' title='"._("Fax")   ."'>";
683     $sambaimg = "<img src='images/select_winstation.png'  alt='S' title='"._("Samba") ."'>";
684  
685     // Space 
686     $empty    = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>"; 
687     
688     // User and Template  Images  
689     $userimg  = "<img src='images/select_user.png' alt='User' title='%s'>";   
690     $tplimg   = "<img src='images/select_template.png' alt='Template' title='%s'>";   
691    
692     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
693  
694     // Defines Arrays to save User and Templates
695     $tpls = array();
696     $users= array();
698     // Test Every Entry and generate divlist Array  
699     foreach($this->list as $key => $val){
701       // Specify Pics for Extensions  
702       if(in_array("posixAccount"    ,$val['objectClass'])) $posix = $posiximg;  else $posix=$empty; 
703       if(in_array("gosaMailAccount" ,$val['objectClass'])) $maila = $mailimg;   else $maila=$empty; 
704       if(in_array("goFonAccount"    ,$val['objectClass'])) $fonac = $fonimg;    else $fonac=$empty; 
705       if(in_array("goFaxAccount"    ,$val['objectClass'])) $faxac = $faximg;    else $faxac=$empty; 
706       if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = $sambaimg;  else $samba=$empty; 
707       if(in_array("gosaUserTemplate",$val['objectClass'])) $tpl   = $tplimg;    else $tpl=$userimg;
708         
709       // Generate Array to Add 
710       if (isset($val["sn"]) && isset($val["givenName"])){
711         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
712       } else {
713         $display= "[".$val["uid"][0]."]";
714       }
716       $field1 = array("string" => sprintf($tpl,$val['dn']),"attach"=>"style='width:20px;align:middle;'");
717       $field2 = array("string" => sprintf($editlink,$key,$display),"attach"=>"title='".$val['dn']."'");
718       $field3 = array("string" => $usrimg."&nbsp;".$posix."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba,"attach" => "style='width:118px;'");
719       $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='border:none; text-align:right;width:48px'");
720     
721       $add = array($field1,$field2,$field3,$field4);
722       
723       // Template or User
724       if(in_array("gosaUserTemplate",$val['objectClass'])){
725         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
726       }else{
727         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
728       }
729     }
730     
731     // Sort Entries 
732     ksort($users);
733     ksort($tpls);
735     // Append Templates
736     foreach($tpls as $key => $val){
737       $divlist->AddEntry( $val, array(""));
738     }
739     // Append Users 
740     foreach($users as $key => $val){
741       $divlist->AddEntry( $val, array(""));
742     }
743     /* Show main page */
744     //$smarty->assign("userlist",   nl2br(htmlentities($divlist->DrawList())));
745     $smarty->assign("userlist",   $divlist->DrawList());
746     $smarty->assign("userlisthead", $listhead);
748     /* END NEW LIST MANAGMENT
749      */  
750     $smarty->assign("search_image", get_template_path('images/search.png'));
751     $smarty->assign("tree_image", get_template_path('images/tree.png'));
752     $smarty->assign("infoimage", get_template_path('images/info.png'));
753     $smarty->assign("launchimage", get_template_path('images/launch.png'));
754     $smarty->assign("deplist", $this->config->idepartments);
755     foreach( array("depselect",  "functionalusers", "unixusers",
756           "mailusers", "sambausers", "proxyusers", 
757           "faxusers", "templates", "subsearch") as $type){
759       $smarty->assign("$type", $userfilter[$type]);
760     }
762     $smarty->assign("regex", $userfilter["regex"]);
763     /* Extend if we are not using javascript */
764     $smarty->assign("apply", apply_filter());
765     $smarty->assign("alphabet", generate_alphabet());
766     $smarty->assign("hint", print_sizelimit_warning());
768     return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
769   }
772   function reload()
773   {
774     /* Get config */
775     $userfilter= get_global('userfilter');
777     /* Set base for all searches */
778     $base= $userfilter['depselect'];
780     /* Regex filter? */
781     if ($userfilter['regex'] != ""){
782       $regex= $userfilter['regex'];
783     } else {
784       $regex= "*";
785     }
787     /* Set filter depending on selection */
788     if ($this->config->current['SAMBAVERSION'] == 3){
789       $samba= "sambaSamAccount";
790     } else {
791       $samba= "sambaAccount";
792     }
794     $filter="";
795     if ($userfilter['functionalusers'] == "checked"){
796       $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)(objectClass=goFaxAccount)(objectClass=gosaProxyAccount))))";
797     }
798     if ($userfilter['unixusers'] == "checked"){
799       $filter.= "(objectClass=posixAccount)";
800     }
801     if ($userfilter['mailusers'] == "checked"){
802       $filter.= "(objectClass=gosaMailAccount)";
803     }
804     if ($userfilter['sambausers'] == "checked"){
805       $filter.= "(objectClass=$samba)";
806     }
807     if ($userfilter['proxyusers'] == "checked"){
808       $filter.= "(objectClass=gosaProxyAccount)";
809     }
810     if ($userfilter['faxusers'] == "checked"){
811       $filter.= "(objectClass=goFaxAccount)";
812     }
814     if ($userfilter['templates'] == "checked"){
815       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
816     } else {
817       $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
818     }
819     $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
821     /* Generate userlist */
822     $ldap= $this->config->get_ldap_link(TRUE);
823     if ($userfilter['subsearch'] == "checked"){
824       $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
825     } else {
826       $base= get_people_ou().$base;
827       $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
828     }
832     /* NEW LIST MANAGMENT
833      * We also need to search for the departments
834      * So we are able to navigate like in konquerer 
835      */
836     $base2 = preg_replace("/ou=people,/i","",$base);
838     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
839                               TRUE, $base2, array("ou", "description"), TRUE);
841     $this->departments= array();
843     $tmp = array();
844     foreach ($res3 as $value){
845       $tmp[strtolower($value['dn']).$value['dn']]=$value;
846     }
847     ksort($tmp);
848     foreach($tmp as $value){
849       if($value["description"][0]!=".."){
850         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
851       }else{
852         $this->departments[$value['dn']]=$value["description"][0];
853       }
854     }
855     /* END NEW LIST MANAGMENT 
856      */
857   
858     
859     $this->userlist= array();
861     foreach ($this->list as $value){
862       if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
863         if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
864           $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
865           continue;
866         }
867         if (isset($value["givenName"][0]) && isset($value["sn"][0])){
868           $this->userlist[$value["dn"]]= $value["sn"][0].", ".
869             $value["givenName"][0].
870             " [".$value["uid"][0]."]";
871         } else {
872           $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
873         }
874       }
875     }
877     natcasesort ($this->userlist);
878     reset ($this->userlist);
879   }
881   function remove_from_parent()
882   {
883   }
886   /* Check values */
887   function check()
888   {
889   }
892   /* Save to LDAP */
893   function save()
894   {
895   }
897   function adapt_from_template($dn)
898   {
899   }
901   function password_change_needed()
902   {
903   }
905   function show_header($button_text, $text, $disabled= FALSE)
906   {
907   }
909   function remove_lock()
910   {
911     if (isset($this->usertab->dn)){
912       del_lock ($this->usertab->dn);
913     }
914   }
918 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
919 ?>