Code

98f434fce14a6cd30426c90673c12a859904e655
[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);
109     /* Department changed? */
110     if(isset($_POST['depselect']) && $_POST['depselect']){
111       $userfilter['depselect']= $_POST['depselect'];
112     }
114     /* Homebutton is posted */
115     if($s_action=="home"){
116       $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
117       $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$userfilter['depselect']));
118     }
120     if($s_action=="root"){
121       $userfilter['depselect']=($this->config->current['BASE']);
122     }
125     /* If Backbutton is Posted */
126     if($s_action=="back"){
127       $base_back          = preg_replace("/^[^,]+,/","",$userfilter['depselect']);
128       $base_back          = convert_department_dn($base_back);
130       if(isset($this->config->departments[trim($base_back)])){
131         $userfilter['depselect']= $this->config->departments[trim($base_back)];
132       }else{
133         $userfilter['depselect']= $this->config->departments["/"];
134       }
135     }
136     /* End for new List Managment */
138     /* Save filter data if we are in the headpage */
139     if (!isset($this->usertab)){
140       if (isset($_POST['regexit'])){
141         $userfilter["regex"]= $_POST['regexit'];
142       }
143     }
144     if(isset($_POST['regexit'])){
145       foreach( array("functionalusers", "unixusers", "mailusers","sambausers", "proxyusers", "faxusers", "templates", "subsearch") as $type){
146         if (isset($_POST[$type])) {
147           $userfilter[$type]= "checked";
148         } else {
149           $userfilter[$type]= "";
150         }
151       }
152     }
153     if (isset($_GET['search'])){
154       $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
155       if ($s == "**"){
156         $s= "*";
157       }
158       $userfilter['regex']= $s;
159     }
160     register_global("userfilter", $userfilter);
161     
163     /* React on user interaction here */
164     if (($_SERVER["REQUEST_METHOD"] == "POST")||($_SERVER["REQUEST_METHOD"]== "GET")){
166       /* User wants to edit data? */
167       if ($s_action=="edit"){
169         /* Get 'dn' from posted 'uid', must be unique */
170         
171         $this->dn= $this->list[trim($s_entry)]['dn'];
173         /* Check locking, save current plugin in 'back_plugin', so
174            the dialog knows where to return. */
175         if (($user= get_lock($this->dn)) != ""){
176           return(gen_locked_message ($user, $this->dn));
177         }
179         /* Lock the current entry, so everyone will get the
180            above dialog */
181         add_lock ($this->dn, $this->ui->dn);
183         /* Set up the users ACL's for this 'dn' */
184         $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
186         /* Register usertab to trigger edit dialog */
187         $this->usertab= new usertabs($this->config, 
188             $this->config->data['TABS']['USERTABS'], $this->dn);
189         $this->usertab->set_acl($acl);
191         $_SESSION['objectinfo']= $this->dn;
192       }
193     }
195     /* Reset requested? */
196     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
197       if (isset($this->usertab)){
198         del_lock ($this->usertab->dn);
199         unset ($this->usertab);
200       }
201       $this->usertab= NULL;
202       $this->lognames= array();;
203       $this->sn= "";
204       $this->givenName= "";
205       $this->uid= "";
206       unset ($_SESSION['objectinfo']);
207     }
209     /* Password change requested */
210     if ($s_action=="change_pw"){
212       /* Get 'dn' from posted 'uid' */
213       $this->dn= $this->list[trim($s_entry)]['dn'];
215       /* Load permissions for selected 'dn' and check if
216          we're allowed to remove this 'dn' */
217       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
218       $acl= get_module_permission($acl, "user", $this->dn);
219       if (chkacl($acl, "password") == ""){
221         /* User is allowed to change passwords, save 'dn' and 'acl' for next
222            dialog. */
223         $this->acl= $acl;
224         $_SESSION['objectinfo']= $this->dn;
225         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
227       } else {
228         /* User is not allowed. Show message and cancel. */
229         print_red (_("You are not allowed to set this users password!"));
230       }
231     }
233     /* Perform password change */
234     if (isset($_POST['password_finish'])){
236       /* For security reasons, check if user is allowed to set password again */
237       if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
239         /* Check input and feed errors into 'message' */
240         $message= array();
242         /* Sanity checks... */
243         if ($_POST['new_password'] != $_POST['repeated_password']){
245           /* Matching passwords in new and repeated? */
246           $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
247         } else {
249           /* Empty password is not permitted by default. */
250           if ($_POST['new_password'] == ""){
251             $message[]= _("The password you've entered as 'New password' is empty.");
252           }
253         }
255         /* Errors, or change password? */
256         if (count($message) != 0){
258           /* Show error message and continue editing */
259           show_errors ($message);
260           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
261         }
263         /* Set password, perform required steps */
264         if ($this->usertab){
265           if ($this->usertab->password_change_needed()){
266             $obj= $this->usertab->by_object['user'];
267             change_password ($this->usertab->dn, $_POST['new_password'],
268                 0, $obj->pw_storage);
269             gosa_log ("Password for '".$this->usertab->dn."' has been changed");
270             unset($this->usertab);
271             $this->usertab= NULL;
272           }
273         } else {
274           change_password ($this->dn, $_POST['new_password']);
275           gosa_log ("Password for '".$this->dn."' has been changed");
276         }
277       } else {
279         /* Missing permissions, show message */
280         print_red (_("You are not allowed to set this users password!"));
281       }
283       /* Clean session, delete lock */
284       del_lock ($this->dn);
285       $this->reload();
286       unset ($this->usertab);
287       $this->usertab= NULL;
288       $this->lognames= array();;
289       $this->sn= "";
290       $this->givenName= "";
291       $this->uid= "";
292       unset ($_SESSION['objectinfo']);
293     }
296     /* Remove user was requested */
297     if ($s_action=="del"){
299       /* Get 'dn' from posted 'uid' */
300       $this->dn= $this->list[trim($s_entry)]['dn'];
302       /* Load permissions for selected 'dn' and check if
303          we're allowed to remove this 'dn' */
304       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
305       $this->acl= get_module_permission($acl, "user", $this->dn);
306       if (chkacl($this->acl, "delete") == ""){
308         /* Check locking, save current plugin in 'back_plugin', so
309            the dialog knows where to return. */
310         if (($user= get_lock($this->dn)) != ""){
311           return(gen_locked_message ($user, $this->dn));
312         }
314         /* Lock the current entry, so nobody will edit it during deletion */
315         add_lock ($this->dn, $this->ui->dn);
316         $smarty->assign("info", sprintf(_("You're about to delete the user %s."), $this->dn));
317         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
318       } else {
320         /* Obviously the user isn't allowed to delete. Show message and
321            clean session. */
322         print_red (_("You are not allowed to delete this user!"));
323       }
324     }
328     /* Confirmation for deletion has been passed. User should be deleted. */
329     if (isset($_POST['delete_user_confirm'])){
331       /* Some nice guy may send this as POST, so we've to check
332          for the permissions again. */
333       if (chkacl($this->acl, "delete") == ""){
335         /* Delete request is permitted, perform LDAP action */
336         $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
337             $this->dn);
338         $this->usertab->set_acl(array($this->acl));
339         $this->usertab->delete ();
340         gosa_log ("User object '".$this->dn."' has been removed");
341         unset ($this->usertab);
342         $this->usertab= NULL;
344         /* User list has changed, reload it. */
345         $this->reload ();
346       } else {
348         /* Normally this shouldn't be reached, send some extra
349            logs to notify the administrator */
350         print_red (_("You are not allowed to delete this user!"));
352         if(isset($this->ui->uid)){
353           gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
354         }
355       }
357       /* Remove lock file after successfull deletion */
358       del_lock ($this->dn);
359     }
362     /* Delete user canceled? */
363     if (isset($_POST['delete_cancel'])){
364       del_lock ($this->dn);
365     }
368     /* Finish user edit is triggered by the tabulator dialog, so
369        the user wants to save edited data. Check and save at this
370        point. */
371     if (isset($_POST['edit_finish'])){
373       /* Check tabs, will feed message array */
374       $this->usertab->last= $this->usertab->current;
375       $this->usertab->save_object();
376       $message= $this->usertab->check();
378       /* Save, or display error message? */
379       if (count($message) == 0){
381         /* No errors. Go ahead and prepare to ask for a password
382            in case we're creating a new user. 'dn' will be 'new'
383            in this case. It is set to the correct value later. */
384         if ($this->dn == "new"){
385           $set_pass= 1;
386         } else {
387           $set_pass= 0;
388         }
390         /* Save user data to ldap */
391         if($this->usertab->save() == 1){
392           gosa_log ("User object '".$this->dn."' saving failed.");
393           return;
394         }
395         gosa_log ("User object '".$this->dn."' has been saved");
397         /* User has been saved successfully, remove lock from
398            LDAP. */
399         if ($this->dn != "new"){
400           del_lock ($this->dn);
401         }
403         /* In case of new users, ask for a password */
404         if (($set_pass || $this->usertab->password_change_needed()) &&
405             !$this->is_template){
407           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
408         }
410         /* There's no page reload so we have to read new users at
411            this point. */
412         $this->reload ();
413         unset ($this->usertab);
414         $this->usertab= NULL;
415         unset ($_SESSION['objectinfo']);
417       } else {
418         /* Ok. There seem to be errors regarding to the tab data,
419            show message and continue as usual. */
420         show_errors($message);
421       }
422     }
424     /* Generate template list */
425     if ($s_action=="new"){
426       $this->templates= array();
427       $ldap= $this->config->get_ldap_link();
428       foreach ($this->config->departments as $key => $value){
429         $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
430         $acl= get_module_permission($acl, "user", get_people_ou().$value);
431         if (chkacl($acl, "create") == ""){
432           $ldap->cd (get_people_ou().$value);
433           $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
435           if ($ldap->count() != 0){
436             while ($attrs= $ldap->fetch()){
437               $this->templates[$ldap->getDN()]=
438                 $attrs['uid'][0]." - $key";
439             }
440             $this->templates['none']= _("none");
441           }
442         }
443       }
444       natcasesort ($this->templates);
445       reset ($this->templates);
446     }
448     /* New user/template request */
449     if (($s_action=="new") || ($s_action=="new_tpl")){
450       /* By default we set 'dn' to 'new', all relevant plugins will
451          react on this. */
452       $this->dn= "new";
453       if (isset($this->config->current['IDGEN'])){
454         $this->got_uid= false;
455       } else {
456         $this->got_uid= true;
457       }
459       /* Create new usertab object */
460       $this->usertab= new usertabs($this->config,
461         $this->config->data['TABS']['USERTABS'], $this->dn);
462       $this->usertab->set_acl(array(':all'));
464       /* Take care about templates */
465       if ($s_action=="new_tpl"){
466         $this->is_template= TRUE;
467         $this->usertab->set_template_mode ();
468       } else {
469         $this->is_template= FALSE;
470       }
471     
472       /* Use template if there are any of them */
473       if (count($this->templates) && !isset($_POST['new_template'])){
474         foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
475           $smarty->assign("$attr", $this->$attr);
476         }
477         if (isset($_POST['template'])){
478           $smarty->assign("template", $_POST['template']);
479         } else {
480           $smarty->assign("template", "");
481         }
482         $smarty->assign("edit_uid", "");
483         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
484       }
485     }
487     /* Continue template editing */
488     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid'])){
489       $this->sn= $_POST['sn'];
490       $this->givenName= $_POST['givenName'];
492       /* Check for requred values */
493       $message= array();
494       if ($this->sn == "") {
495         $message[]= _("The required field 'Name' is not set.");
496       }
497       if ($this->givenName == "") {
498         $message[]= _("The required field 'Given name' is not set.");
499       }
501       /* Check if dn is used */
502       $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
503       $ldap= $this->config->get_ldap_link();
504       $ldap->cd ($dn);
505       $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
506       if ($ldap->count () != 0){
507         $message[]= _("A person with the choosen name is already used in this tree.");
508       }
510       /* Show error message / continue editing */
511       if (count($message) > 0){
512         show_errors ($message);
513       } else {
514         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
515         if (isset($this->config->current['IDGEN']) &&
516             $this->config->current['IDGEN'] != ""){
517           $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
518           if (count($uids)){
519             $smarty->assign("edit_uid", "false");
520             $smarty->assign("uids", $uids);
521             $this->uid= current($uids);
522           }
523         } else {
524             $smarty->assign("edit_uid", "");
525           $this->uid= "";
526         }
527         $this->got_uid= true;
528       }
530       foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
531         $smarty->assign("$attr", $this->$attr);
532       }
533       if (isset($_POST['template'])){
534         $smarty->assign("template", $_POST['template']);
535       }
536       return($smarty->fetch(get_template_path('template.tpl', TRUE)));
537     }
539     /* No template. Ok. Lets fill data into the normal user dialog */
540     if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
541       foreach(array("sn", "givenName", "uid") as $attr){
542         if (isset($_POST[$attr])){
543           $this->usertab->by_object['user']->$attr= $_POST[$attr];
544         }
545       }
546     }
548     /* Finish template preamble */
549     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
551       /* Might not be filled if IDGEN is unset */
552       $this->sn= $_POST['sn'];
553       $this->givenName= $_POST['givenName'];
555       /* Move user supplied data to sub plugins */
556       $this->uid= $_POST['uid'];
557       $this->usertab->uid= $this->uid;
558       $this->usertab->sn= $this->sn;
559       $this->usertab->givenName= $this->givenName;
560       $template_dn= $_POST['template'];
561       $this->usertab->adapt_from_template($template_dn);
562       $template_base= $userfilter['depselect'];//preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
563       $this->usertab->by_object['user']->base= $template_base;
565       /* Set up the users ACL's for this 'dn' */
566       $acl= get_permissions ($template_base, $this->ui->subtreeACL);
567       $this->usertab->set_acl($acl);
568     }
570     /* Show tab dialog if object is present */
571     if ($this->usertab){
572       $display= $this->usertab->execute();
574       /* Don't show buttons if tab dialog requests this */
575       if (!$this->usertab->by_object[$this->usertab->current]->dialog){
576         $display.= "<p style=\"text-align:right\">\n";
577         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
578         $display.= "&nbsp;\n";
579         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
580         $display.= "</p>";
581       }
582       return ($display);
583     }
585     $smarty= get_smarty();
587     /* Check sorting variable */
588     if (!isset($this->usertab) &&
589         !isset($_POST['new_user']) &&
590         !isset($_POST['new_template']) &&
591         !isset($_POST['delete_user']) &&
592         !isset($_POST['setpass_user']) &&
593         !isset($_POST['select_user'])){
594       $this->reload();
595     }
597     /* Check for exeeded sizelimit */
598     if (($message= check_sizelimit()) != ""){
599       return($message);
600     }
602     /* Prepare departments */
603     $options= "";
604     foreach ($this->config->idepartments as $key => $value){
605             if ($userfilter['depselect'] == $key){
606                     $options.= "<option selected value='$key'>$value</option>";
607             } else {
608                     $options.= "<option value='$key'>$value</option>";
609             }
610     }
611  
612     /* NEW LIST MANAGMENT */
613     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
614             " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
615             " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
616             " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
617             " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
618             " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'>&nbsp;".
619             " <input type='image' align='middle' src='images/list_new.png' title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'>&nbsp;".
620             " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
621             _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
622             " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
623             "</div>";
625     $action= "<input type='image' src='images/edit.png' alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit user")."'>";
626     $action.= "<input type='image' src='images/list_password.png' alt='"._("password")."' name='user_chgpw_%KEY%' title='"._("Change password")."'>";
627     $action.= "<input type='image' src='images/editdelete.png' alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete user")."'>";
631     $divlist = new divlist("userstab");
632     $divlist->SetHeader(array(
633                               array("string" => "&nbsp;"),
634                               array("string" => _("Username")." / "._("Department")),
635                               array("string" => _("Properties")),
636                               array("string" => _("Actions"), "attach" => "style='border:none'" )));
637                                     
639     $divlist->SetSummary(_("This table displays all users, in the selected tree."));
640     $divlist->SetEntriesPerPage(20);
642     // Defining Links 
643     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
645     foreach($this->departments as $key=> $val){
646       
647       if(!isset($this->config->departments[trim($key)])){
648         $this->config->departments[trim($key)]="";
649       }
651       $non_empty="";
652       $keys= str_replace("/","\/",$key);
653       foreach($this->config->departments as $keyd=>$vald ){
654         if(preg_match("/".$keys."\/.*/",$keyd)){
655           $non_empty="full";
656         }
657       }
662       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>");
663       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
664       $field3 = array("string" => "&nbsp;");
665       $field4 = array("string" => "&nbsp;", "attach" => "style='border:none'");
668       $divlist->AddEntry(array($field1,$field2,$field3,$field4));
669     }
671     // Pictures for Extensions 
672     $usrimg  = "<img src='images/penguin.png'             alt='U' title='"._("GOsa")  ."'>";
673     $posiximg = "<img src='images/select_user.png'        alt='P' title='"._("Posix") ."'>";
674     $mailimg  = "<img src='images/mailto.png'             alt='M' title='"._("Mail")  ."'>";
675     $fonimg   = "<img src='images/select_phone.png'       alt='T' title='"._("Phone") ."'>";
676     $faximg   = "<img src='images/fax_small.png'          alt='F' title='"._("Fax")   ."'>";
677     $sambaimg = "<img src='images/select_winstation.png'  alt='S' title='"._("Samba") ."'>";
678  
679     // Space 
680     $empty    = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>"; 
681     
682     // User and Template  Images  
683     $userimg  = "<img src='images/select_user.png' alt='User' title='%s'>";   
684     $tplimg   = "<img src='images/select_template.png' alt='Template' title='%s'>";   
685    
686     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
687  
688     // Defines Arrays to save User and Templates
689     $tpls = array();
690     $users= array();
692     // Test Every Entry and generate divlist Array  
693     foreach($this->list as $key => $val){
695       // Specify Pics for Extensions  
696       if(in_array("posixAccount"    ,$val['objectClass'])) $posix = $posiximg;  else $posix=$empty; 
697       if(in_array("gosaMailAccount" ,$val['objectClass'])) $maila = $mailimg;   else $maila=$empty; 
698       if(in_array("goFonAccount"    ,$val['objectClass'])) $fonac = $fonimg;    else $fonac=$empty; 
699       if(in_array("goFaxAccount"    ,$val['objectClass'])) $faxac = $faximg;    else $faxac=$empty; 
700       if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = $sambaimg;  else $samba=$empty; 
701       if(in_array("gosaUserTemplate",$val['objectClass'])) $tpl   = $tplimg;    else $tpl=$userimg;
702         
703       // Generate Array to Add 
704       if (isset($val["sn"]) && isset($val["givenName"])){
705         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
706       } else {
707         $display= "[".$val["uid"][0]."]";
708       }
710       $field1 = array("string" => sprintf($tpl,$val['dn']),"attach"=>"style='width:20px;align:middle;'");
711       $field2 = array("string" => sprintf($editlink,$key,$display),"attach"=>"title='".$val['dn']."'");
712       $field3 = array("string" => $usrimg."&nbsp;".$posix."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba,"attach" => "style='width:118px;'");
713       $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='border:none; text-align:right;width:48px'");
714     
715       $add = array($field1,$field2,$field3,$field4);
716       
717       // Template or User
718       if(in_array("gosaUserTemplate",$val['objectClass'])){
719         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
720       }else{
721         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
722       }
723     }
724     
725     // Sort Entries 
726     ksort($users);
727     ksort($tpls);
729     // Append Templates
730     foreach($tpls as $key => $val){
731       $divlist->AddEntry( $val, array(""));
732     }
733     // Append Users 
734     foreach($users as $key => $val){
735       $divlist->AddEntry( $val, array(""));
736     }
737     /* Show main page */
738     //$smarty->assign("userlist",   nl2br(htmlentities($divlist->DrawList())));
739     $smarty->assign("userlist",   $divlist->DrawList());
740     $smarty->assign("userlisthead", $listhead);
742     /* END NEW LIST MANAGMENT
743      */  
744     $smarty->assign("search_image", get_template_path('images/search.png'));
745     $smarty->assign("tree_image", get_template_path('images/tree.png'));
746     $smarty->assign("infoimage", get_template_path('images/info.png'));
747     $smarty->assign("launchimage", get_template_path('images/launch.png'));
748     $smarty->assign("deplist", $this->config->idepartments);
749     foreach( array("depselect",  "functionalusers", "unixusers",
750           "mailusers", "sambausers", "proxyusers", 
751           "faxusers", "templates", "subsearch") as $type){
753       $smarty->assign("$type", $userfilter[$type]);
754     }
756     $smarty->assign("regex", $userfilter["regex"]);
757     /* Extend if we are not using javascript */
758     $smarty->assign("apply", apply_filter());
759     $smarty->assign("alphabet", generate_alphabet());
760     $smarty->assign("hint", print_sizelimit_warning());
762     return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
763   }
766   function reload()
767   {
768     /* Get config */
769     $userfilter= get_global('userfilter');
771     /* Set base for all searches */
772     $base= $userfilter['depselect'];
774     /* Regex filter? */
775     if ($userfilter['regex'] != ""){
776       $regex= $userfilter['regex'];
777     } else {
778       $regex= "*";
779     }
781     /* Set filter depending on selection */
782     if ($this->config->current['SAMBAVERSION'] == 3){
783       $samba= "sambaSamAccount";
784     } else {
785       $samba= "sambaAccount";
786     }
788     $filter="";
789     if ($userfilter['functionalusers'] == "checked"){
790       $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)(objectClass=goFaxAccount)(objectClass=gosaProxyAccount))))";
791     }
792     if ($userfilter['unixusers'] == "checked"){
793       $filter.= "(objectClass=posixAccount)";
794     }
795     if ($userfilter['mailusers'] == "checked"){
796       $filter.= "(objectClass=gosaMailAccount)";
797     }
798     if ($userfilter['sambausers'] == "checked"){
799       $filter.= "(objectClass=$samba)";
800     }
801     if ($userfilter['proxyusers'] == "checked"){
802       $filter.= "(objectClass=gosaProxyAccount)";
803     }
804     if ($userfilter['faxusers'] == "checked"){
805       $filter.= "(objectClass=goFaxAccount)";
806     }
808     if ($userfilter['templates'] == "checked"){
809       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
810     } else {
811       $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
812     }
813     $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
815     /* Generate userlist */
816     $ldap= $this->config->get_ldap_link(TRUE);
817     if ($userfilter['subsearch'] == "checked"){
818       $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
819     } else {
820       $base= get_people_ou().$base;
821       $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
822     }
826     /* NEW LIST MANAGMENT
827      * We also need to search for the departments
828      * So we are able to navigate like in konquerer 
829      */
830     $base2 = preg_replace("/ou=people,/i","",$base);
832     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
833                               TRUE, $base2, array("ou", "description"), TRUE);
835     $this->departments= array();
837     $tmp = array();
838     foreach ($res3 as $value){
839       $tmp[strtolower($value['dn']).$value['dn']]=$value;
840     }
841     ksort($tmp);
842     foreach($tmp as $value){
843       if($value["description"][0]!=".."){
844         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
845       }else{
846         $this->departments[$value['dn']]=$value["description"][0];
847       }
848     }
849     /* END NEW LIST MANAGMENT 
850      */
851   
852     
853     $this->userlist= array();
855     foreach ($this->list as $value){
856       if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
857         if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
858           $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
859           continue;
860         }
861         if (isset($value["givenName"][0]) && isset($value["sn"][0])){
862           $this->userlist[$value["dn"]]= $value["sn"][0].", ".
863             $value["givenName"][0].
864             " [".$value["uid"][0]."]";
865         } else {
866           $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
867         }
868       }
869     }
871     natcasesort ($this->userlist);
872     reset ($this->userlist);
873   }
875   function remove_from_parent()
876   {
877   }
880   /* Check values */
881   function check()
882   {
883   }
886   /* Save to LDAP */
887   function save()
888   {
889   }
891   function adapt_from_template($dn)
892   {
893   }
895   function password_change_needed()
896   {
897   }
899   function show_header($button_text, $text, $disabled= FALSE)
900   {
901   }
903   function remove_lock()
904   {
905     if (isset($this->usertab->dn)){
906       del_lock ($this->usertab->dn);
907     }
908   }
912 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
913 ?>