Code

Goto to selected usertab when clicking on the specific picture in userlist
[gosa.git] / plugins / admin / users / class_userManagement.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2003  Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 require "tabs_user.inc";
22 class userManagement extends plugin
23 {
24   /* Definitions */
25   var $plHeadline= "Users";
26   var $plDescription= "This does something";
28   /* Dialog attributes */
29   var $usertab= NULL;
30   var $userlist= array();
31   var $ui= NULL;
32   var $acl= "";
33   var $templates= array();
34   var $got_uid= false;
35   var $departments=array();
37   function userManagement ($config, $ui)
38   {
39     /* Save configuration for internal use */
40     $this->config= $config;
41     $this->ui= $ui;
43     /* Get global filter config */
44     if (!isset($_SESSION["userfilter"])){
45       $base= get_base_from_people($ui->dn);
46       $userfilter= array( "mailusers"       => "checked",
47           "unixusers"       => "checked",
48           "templates"       => "",
49           "subsearch"       => "",
50           "proxyusers"      => "checked",
51           "sambausers"      => "checked",
52           "faxusers"        => "checked",
53           "functionalusers" => "checked",
54           "depselect"       => $base,
55           "regex"           => "*");
56       $_SESSION["userfilter"] = $userfilter;
57     }
58   }
60   function execute()
61   {
62     $smarty       = get_smarty();             // Smarty instance
63     $userfilter   = get_global("userfilter"); // contains Filter Settings
64     $s_action     = "";                       // Contains the action to proceed
65     $s_entry      = "";                       // The value for s_action
66     $base_back    = "";                       // The Link for Backbutton
68     /* Start for New List Managment */
69     if(isset($_GET['act'])&&($_GET['act']=="dep_open")){
70             $s_action="open";
71             $s_entry = base64_decode($_GET['dep_id']);
72             $userfilter['depselect']= "".$this->config->departments[trim($s_entry)];
73     }
75     /* Test Posts */  
76     foreach($_POST as $key => $val){
77       // Post for delete
78       if(preg_match("/user_del.*/",$key)){
79         $s_action = "del";
80         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
81         // Post for edit
82       }elseif(preg_match("/user_edit_.*/",$key)){
83         $s_action="edit";
84         $s_entry  = preg_replace("/user_".$s_action."_/i","",$key);
85         // Post for new
86       }elseif(preg_match("/dep_back.*/i",$key)){
87         $s_action="back";
88       }elseif(preg_match("/user_new.*/",$key)){
89         $s_action="new";
90       }elseif(preg_match("/dep_home.*/i",$key)){
91         $s_action="home";
92       }elseif(preg_match("/user_tplnew.*/i",$key)){
93         $s_action="new_tpl";
94       }elseif(preg_match("/user_chgpw.*/i",$key)){
95         $s_action="change_pw";
96         $s_entry  = preg_replace("/user_chgpw_/i","",$key);
97       }elseif(preg_match("/dep_root.*/i",$key)){
98         $s_action="root";
99       }
100     }
101     
102     if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
103       $s_action ="edit";
104       $s_entry  = $_GET['id'];
105     }
107     $s_entry  = preg_replace("/_.$/","",$s_entry);
108     if(preg_match("/.*-.*/",$s_entry)){
109       $s_tab   = preg_replace("/^.*-/i","",$s_entry);
110       $s_entry = preg_replace("/-.*$/i","",$s_entry);
111     }else{
112       $s_tab   = "user";
113     };
115     /* Department changed? */
116     if(isset($_POST['depselect']) && $_POST['depselect']){
117       $userfilter['depselect']= $_POST['depselect'];
118     }
120     /* Homebutton is posted */
121     if($s_action=="home"){
122       $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$this->ui->dn));
123       $userfilter['depselect']=(preg_replace("/^[^,]+,/","",$userfilter['depselect']));
124     }
126     if($s_action=="root"){
127       $userfilter['depselect']=($this->config->current['BASE']);
128     }
131     /* If Backbutton is Posted */
132     if($s_action=="back"){
133       $base_back          = preg_replace("/^[^,]+,/","",$userfilter['depselect']);
134       $base_back          = convert_department_dn($base_back);
136       if(isset($this->config->departments[trim($base_back)])){
137         $userfilter['depselect']= $this->config->departments[trim($base_back)];
138       }else{
139         $userfilter['depselect']= $this->config->departments["/"];
140       }
141     }
142     /* End for new List Managment */
144     /* Save filter data if we are in the headpage */
145     if (!isset($this->usertab)){
146       if (isset($_POST['regexit'])){
147         $userfilter["regex"]= $_POST['regexit'];
148       }
149     }
150     if(isset($_POST['regexit'])){
151       foreach( array("functionalusers", "unixusers", "mailusers","sambausers", "proxyusers", "faxusers", "templates", "subsearch") as $type){
152         if (isset($_POST[$type])) {
153           $userfilter[$type]= "checked";
154         } else {
155           $userfilter[$type]= "";
156         }
157       }
158     }
159     if (isset($_GET['search'])){
160       $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
161       if ($s == "**"){
162         $s= "*";
163       }
164       $userfilter['regex']= $s;
165     }
166     register_global("userfilter", $userfilter);
167     
169     /* React on user interaction here */
170     if (($_SERVER["REQUEST_METHOD"] == "POST")||($_SERVER["REQUEST_METHOD"]== "GET")){
172       /* User wants to edit data? */
173       if ($s_action=="edit"){
175         /* Get 'dn' from posted 'uid', must be unique */
176         
177         $this->dn= $this->list[trim($s_entry)]['dn'];
179         /* Check locking, save current plugin in 'back_plugin', so
180            the dialog knows where to return. */
181         if (($user= get_lock($this->dn)) != ""){
182           return(gen_locked_message ($user, $this->dn));
183         }
185         /* Lock the current entry, so everyone will get the
186            above dialog */
187         add_lock ($this->dn, $this->ui->dn);
189         /* Set up the users ACL's for this 'dn' */
190         $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
192         /* Register usertab to trigger edit dialog */
193         $_POST[$s_tab]=$s_tab;
194         $this->usertab= new usertabs($this->config, 
195             $this->config->data['TABS']['USERTABS'], $this->dn);
196         $this->usertab->set_acl($acl);
198         $_SESSION['objectinfo']= $this->dn;
199       }
200     }
202     /* Reset requested? */
203     if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel'])){
204       if (isset($this->usertab)){
205         del_lock ($this->usertab->dn);
206         unset ($this->usertab);
207       }
208       $this->usertab= NULL;
209       $this->lognames= array();;
210       $this->sn= "";
211       $this->givenName= "";
212       $this->uid= "";
213       unset ($_SESSION['objectinfo']);
214     }
216     /* Password change requested */
217     if ($s_action=="change_pw"){
219       /* Get 'dn' from posted 'uid' */
220       $this->dn= $this->list[trim($s_entry)]['dn'];
222       /* Load permissions for selected 'dn' and check if
223          we're allowed to remove this 'dn' */
224       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
225       $acl= get_module_permission($acl, "user", $this->dn);
226       if (chkacl($acl, "password") == ""){
228         /* User is allowed to change passwords, save 'dn' and 'acl' for next
229            dialog. */
230         $this->acl= $acl;
231         $_SESSION['objectinfo']= $this->dn;
232         return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
234       } else {
235         /* User is not allowed. Show message and cancel. */
236         print_red (_("You are not allowed to set this users password!"));
237       }
238     }
240     /* Perform password change */
241     if (isset($_POST['password_finish'])){
243       /* For security reasons, check if user is allowed to set password again */
244       if (chkacl($this->acl, "password") == "" || chkacl($this->acl, "create")){
246         /* Check input and feed errors into 'message' */
247         $message= array();
249         /* Sanity checks... */
250         if ($_POST['new_password'] != $_POST['repeated_password']){
252           /* Matching passwords in new and repeated? */
253           $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
254         } else {
256           /* Empty password is not permitted by default. */
257           if ($_POST['new_password'] == ""){
258             $message[]= _("The password you've entered as 'New password' is empty.");
259           }
260         }
262         /* Errors, or change password? */
263         if (count($message) != 0){
265           /* Show error message and continue editing */
266           show_errors ($message);
267           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
268         }
270         /* Set password, perform required steps */
271         if ($this->usertab){
272           if ($this->usertab->password_change_needed()){
273             $obj= $this->usertab->by_object['user'];
274             change_password ($this->usertab->dn, $_POST['new_password'],
275                 0, $obj->pw_storage);
276             gosa_log ("Password for '".$this->usertab->dn."' has been changed");
277             unset($this->usertab);
278             $this->usertab= NULL;
279           }
280         } else {
281           change_password ($this->dn, $_POST['new_password']);
282           gosa_log ("Password for '".$this->dn."' has been changed");
283         }
284       } else {
286         /* Missing permissions, show message */
287         print_red (_("You are not allowed to set this users password!"));
288       }
290       /* Clean session, delete lock */
291       del_lock ($this->dn);
292       $this->reload();
293       unset ($this->usertab);
294       $this->usertab= NULL;
295       $this->lognames= array();;
296       $this->sn= "";
297       $this->givenName= "";
298       $this->uid= "";
299       unset ($_SESSION['objectinfo']);
300     }
303     /* Remove user was requested */
304     if ($s_action=="del"){
306       /* Get 'dn' from posted 'uid' */
307       $this->dn= $this->list[trim($s_entry)]['dn'];
309       /* Load permissions for selected 'dn' and check if
310          we're allowed to remove this 'dn' */
311       $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
312       $this->acl= get_module_permission($acl, "user", $this->dn);
313       if (chkacl($this->acl, "delete") == ""){
315         /* Check locking, save current plugin in 'back_plugin', so
316            the dialog knows where to return. */
317         if (($user= get_lock($this->dn)) != ""){
318           return(gen_locked_message ($user, $this->dn));
319         }
321         /* Lock the current entry, so nobody will edit it during deletion */
322         add_lock ($this->dn, $this->ui->dn);
323         $smarty->assign("info", sprintf(_("You're about to delete the user %s."), $this->dn));
324         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
325       } else {
327         /* Obviously the user isn't allowed to delete. Show message and
328            clean session. */
329         print_red (_("You are not allowed to delete this user!"));
330       }
331     }
335     /* Confirmation for deletion has been passed. User should be deleted. */
336     if (isset($_POST['delete_user_confirm'])){
338       /* Some nice guy may send this as POST, so we've to check
339          for the permissions again. */
340       if (chkacl($this->acl, "delete") == ""){
342         /* Delete request is permitted, perform LDAP action */
343         $this->usertab= new usertabs($this->config, $this->config->data['TABS']['USERTABS'],
344             $this->dn);
345         $this->usertab->set_acl(array($this->acl));
346         $this->usertab->delete ();
347         gosa_log ("User object '".$this->dn."' has been removed");
348         unset ($this->usertab);
349         $this->usertab= NULL;
351         /* User list has changed, reload it. */
352         $this->reload ();
353       } else {
355         /* Normally this shouldn't be reached, send some extra
356            logs to notify the administrator */
357         print_red (_("You are not allowed to delete this user!"));
359         if(isset($this->ui->uid)){
360           gosa_log ("Warning: '".$this->ui->uid."' tried to trick user deletion.");
361         }
362       }
364       /* Remove lock file after successfull deletion */
365       del_lock ($this->dn);
366     }
369     /* Delete user canceled? */
370     if (isset($_POST['delete_cancel'])){
371       del_lock ($this->dn);
372     }
375     /* Finish user edit is triggered by the tabulator dialog, so
376        the user wants to save edited data. Check and save at this
377        point. */
378     if (isset($_POST['edit_finish'])){
380       /* Check tabs, will feed message array */
381       $this->usertab->last= $this->usertab->current;
382       $this->usertab->save_object();
383       $message= $this->usertab->check();
385       /* Save, or display error message? */
386       if (count($message) == 0){
388         /* No errors. Go ahead and prepare to ask for a password
389            in case we're creating a new user. 'dn' will be 'new'
390            in this case. It is set to the correct value later. */
391         if ($this->dn == "new"){
392           $set_pass= 1;
393         } else {
394           $set_pass= 0;
395         }
397         /* Save user data to ldap */
398         if($this->usertab->save() == 1){
399           gosa_log ("User object '".$this->dn."' saving failed.");
400           return;
401         }
402         gosa_log ("User object '".$this->dn."' has been saved");
404         /* User has been saved successfully, remove lock from
405            LDAP. */
406         if ($this->dn != "new"){
407           del_lock ($this->dn);
408         }
410         /* In case of new users, ask for a password */
411         if (($set_pass || $this->usertab->password_change_needed()) &&
412             !$this->is_template){
414           return($smarty->fetch(get_template_path('password.tpl', TRUE)));
415         }
417         /* There's no page reload so we have to read new users at
418            this point. */
419         $this->reload ();
420         unset ($this->usertab);
421         $this->usertab= NULL;
422         unset ($_SESSION['objectinfo']);
424       } else {
425         /* Ok. There seem to be errors regarding to the tab data,
426            show message and continue as usual. */
427         show_errors($message);
428       }
429     }
431     /* Generate template list */
432     if ($s_action=="new"){
433       $this->templates= array();
434       $ldap= $this->config->get_ldap_link();
435       foreach ($this->config->departments as $key => $value){
436         $acl= get_permissions (get_people_ou().$value, $this->ui->subtreeACL);
437         $acl= get_module_permission($acl, "user", get_people_ou().$value);
438         if (chkacl($acl, "create") == ""){
439           $ldap->cd (get_people_ou().$value);
440           $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
442           if ($ldap->count() != 0){
443             while ($attrs= $ldap->fetch()){
444               $this->templates[$ldap->getDN()]=
445                 $attrs['uid'][0]." - $key";
446             }
447             $this->templates['none']= _("none");
448           }
449         }
450       }
451       natcasesort ($this->templates);
452       reset ($this->templates);
453     }
455     /* New user/template request */
456     if (($s_action=="new") || ($s_action=="new_tpl")){
457       /* By default we set 'dn' to 'new', all relevant plugins will
458          react on this. */
459       $this->dn= "new";
460       if (isset($this->config->current['IDGEN'])){
461         $this->got_uid= false;
462       } else {
463         $this->got_uid= true;
464       }
466       /* Create new usertab object */
467       $this->usertab= new usertabs($this->config,
468         $this->config->data['TABS']['USERTABS'], $this->dn);
469       $this->usertab->set_acl(array(':all'));
471       /* Take care about templates */
472       if ($s_action=="new_tpl"){
473         $this->is_template= TRUE;
474         $this->usertab->set_template_mode ();
475       } else {
476         $this->is_template= FALSE;
477       }
478     
479       /* Use template if there are any of them */
480       if (count($this->templates) && !isset($_POST['new_template'])){
481         foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
482           $smarty->assign("$attr", $this->$attr);
483         }
484         if (isset($_POST['template'])){
485           $smarty->assign("template", $_POST['template']);
486         } else {
487           $smarty->assign("template", "");
488         }
489         $smarty->assign("edit_uid", "");
490         return($smarty->fetch(get_template_path('template.tpl', TRUE)));
491       }
492     }
494     /* Continue template editing */
495     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && !isset($_POST['uid'])){
496       $this->sn= $_POST['sn'];
497       $this->givenName= $_POST['givenName'];
499       /* Check for requred values */
500       $message= array();
501       if ($this->sn == "") {
502         $message[]= _("The required field 'Name' is not set.");
503       }
504       if ($this->givenName == "") {
505         $message[]= _("The required field 'Given name' is not set.");
506       }
508       /* Check if dn is used */
509       $dn= preg_replace("/^[^,]+,/i", "", $_POST['template']);
510       $ldap= $this->config->get_ldap_link();
511       $ldap->cd ($dn);
512       $ldap->search ("(&(sn=".$this->sn.")(givenName=".$this->givenName."))", array("givenName"));
513       if ($ldap->count () != 0){
514         $message[]= _("A person with the choosen name is already used in this tree.");
515       }
517       /* Show error message / continue editing */
518       if (count($message) > 0){
519         show_errors ($message);
520       } else {
521         $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
522         if (isset($this->config->current['IDGEN']) &&
523             $this->config->current['IDGEN'] != ""){
524           $uids= gen_uids ($this->config->current['IDGEN'], $attributes);
525           if (count($uids)){
526             $smarty->assign("edit_uid", "false");
527             $smarty->assign("uids", $uids);
528             $this->uid= current($uids);
529           }
530         } else {
531             $smarty->assign("edit_uid", "");
532           $this->uid= "";
533         }
534         $this->got_uid= true;
535       }
537       foreach(array("sn", "givenName", "uid", "got_uid", "templates") as $attr){
538         $smarty->assign("$attr", $this->$attr);
539       }
540       if (isset($_POST['template'])){
541         $smarty->assign("template", $_POST['template']);
542       }
543       return($smarty->fetch(get_template_path('template.tpl', TRUE)));
544     }
546     /* No template. Ok. Lets fill data into the normal user dialog */
547     if (isset($_POST['template_continue']) && $_POST['template'] == 'none'){
548       foreach(array("sn", "givenName", "uid") as $attr){
549         if (isset($_POST[$attr])){
550           $this->usertab->by_object['user']->$attr= $_POST[$attr];
551         }
552       }
553     }
555     /* Finish template preamble */
556     if (isset($_POST['template_continue']) && $_POST['template'] != 'none' && (isset($_POST['uid']))){
558       /* Might not be filled if IDGEN is unset */
559       $this->sn= $_POST['sn'];
560       $this->givenName= $_POST['givenName'];
562       /* Move user supplied data to sub plugins */
563       $this->uid= $_POST['uid'];
564       $this->usertab->uid= $this->uid;
565       $this->usertab->sn= $this->sn;
566       $this->usertab->givenName= $this->givenName;
567       $template_dn= $_POST['template'];
568       $this->usertab->adapt_from_template($template_dn);
569       $template_base= $userfilter['depselect'];//preg_replace("/^[^,]+,".get_people_ou()."/", '', $template_dn);
570       $this->usertab->by_object['user']->base= $template_base;
572       /* Set up the users ACL's for this 'dn' */
573       $acl= get_permissions ($template_base, $this->ui->subtreeACL);
574       $this->usertab->set_acl($acl);
575     }
577     /* Show tab dialog if object is present */
578     if ($this->usertab){
579       $display= $this->usertab->execute();
581       /* Don't show buttons if tab dialog requests this */
582       if (!$this->usertab->by_object[$this->usertab->current]->dialog){
583         $display.= "<p style=\"text-align:right\">\n";
584         $display.= "<input type=submit name=\"edit_finish\" value=\""._("Finish")."\">\n";
585         $display.= "&nbsp;\n";
586         $display.= "<input type=submit name=\"edit_cancel\" value=\""._("Cancel")."\">\n";
587         $display.= "</p>";
588       }
589       return ($display);
590     }
592     $smarty= get_smarty();
594     /* Check sorting variable */
595     if (!isset($this->usertab) &&
596         !isset($_POST['new_user']) &&
597         !isset($_POST['new_template']) &&
598         !isset($_POST['delete_user']) &&
599         !isset($_POST['setpass_user']) &&
600         !isset($_POST['select_user'])){
601       $this->reload();
602     }
604     /* Check for exeeded sizelimit */
605     if (($message= check_sizelimit()) != ""){
606       return($message);
607     }
609     /* Prepare departments */
610     $options= "";
611     foreach ($this->config->idepartments as $key => $value){
612             if ($userfilter['depselect'] == $key){
613                     $options.= "<option selected value='$key'>$value</option>";
614             } else {
615                     $options.= "<option value='$key'>$value</option>";
616             }
617     }
618  
619     /* NEW LIST MANAGMENT */
620     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
621             " <input type='image' align='middle' src='images/list_back.png' title='"._("Go up one department")."' alt='"._("Up")."' name='dep_back'>&nbsp;".
622             " <input type='image' src='images/list_root.png' align='middle' title='"._("Go to root department")."' name='dep_root' alt='"._("Root")."'>&nbsp;".
623             " <input type='image' align='middle' src='images/list_home.png' title='"._("Go to users department")."' alt='"._("Home")."' name='dep_home'>&nbsp;".
624             " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
625             " <input type='image' align='middle' src='images/list_new_user.png' title='"._("Create new user")."' alt='"._("New user")."' name='user_new'>&nbsp;".
626             " <input type='image' align='middle' src='images/list_new.png' title='"._("Create new template")."' alt='"._("New template")."' name='user_tplnew'>&nbsp;".
627             " <img src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
628             _("Current base")."&nbsp;<select name='depselect' onChange='mainform.submit()'>$options</select>".
629             " <input type='image' src='images/list_submit.png' align='middle' title='"._("Submit department")."' name='submit_department' alt='"._("Submit")."'>&nbsp;".
630             "</div>";
632     $action= "<input type='image' src='images/edit.png' alt='"._("edit")."'     name='user_edit_%KEY%' title='"._("Edit user")."'>";
633     $action.= "<input type='image' src='images/list_password.png' alt='"._("password")."' name='user_chgpw_%KEY%' title='"._("Change password")."'>";
634     $action.= "<input type='image' src='images/editdelete.png' alt='"._("delete")."'   name='user_del_%KEY%' title='"._("Delete user")."'>";
638     $divlist = new divlist("userstab");
639     $divlist->SetHeader(array(
640                               array("string" => "&nbsp;"),
641                               array("string" => _("Username")." / "._("Department")),
642                               array("string" => _("Properties")),
643                               array("string" => _("Actions"), "attach" => "style='border:none'" )));
644                                     
646     $divlist->SetSummary(_("This table displays all users, in the selected tree."));
647     $divlist->SetEntriesPerPage(20);
649     // Defining Links 
650     $linkopen = "<a href='?plug=".$_GET['plug']."&amp;act=dep_open&amp;dep_id=%s'>%s</a>";
652     foreach($this->departments as $key=> $val){
653       
654       if(!isset($this->config->departments[trim($key)])){
655         $this->config->departments[trim($key)]="";
656       }
658       $non_empty="";
659       $keys= str_replace("/","\/",$key);
660       foreach($this->config->departments as $keyd=>$vald ){
661         if(preg_match("/".$keys."\/.*/",$keyd)){
662           $non_empty="full";
663         }
664       }
669       $field1 = array("string" => "<img src='images/".$non_empty."folder.png' alt='department'>");
670       $field2 = array("string" => sprintf($linkopen,base64_encode($key),$val));
671       $field3 = array("string" => "&nbsp;");
672       $field4 = array("string" => "&nbsp;", "attach" => "style='border:none'");
675       $divlist->AddEntry(array($field1,$field2,$field3,$field4));
676     }
678     // Pictures for Extensions 
679 //$usrimg  = "<img src='images/penguin.png'             alt='U' title='"._("GOsa")  ."'>";
680     $usrimg   ="<input type='image' src='images/penguin.png' alt='"._("Generic Tab")."'     name='user_edit_%KEY%-user' title='"._("Edit users Generic Tab")."'>";
681 //$posiximg = "<img src='images/select_user.png'        alt='P' title='"._("Posix") ."'>";
682     $posiximg = "<input type='image' src='images/select_user.png' alt='"._("Posix Tab")."'     name='user_edit_%KEY%-posixAccount' title='"._("Edit users Posix Tab")."'>";
683 //$mailimg  = "<img src='images/mailto.png'             alt='M' title='"._("Mail")  ."'>";
684     $mailimg  = "<input type='image' src='images/mailto.png' alt='"._("Mail Tab")."'     name='user_edit_%KEY%-mailAccount' title='"._("Edit users Mail Tab")."'>";
685 //$fonimg   = "<img src='images/select_phone.png'       alt='T' title='"._("Phone") ."'>";
686     $fonimg   = "<input type='image' src='images/select_phone.png' alt='"._("Phone Tab")."'     name='user_edit_%KEY%-phoneAccount' title='"._("Edit users Phone Tab")."'>";
687 //$faximg   = "<img src='images/fax_small.png'          alt='F' title='"._("Fax")   ."'>";
688     $faximg   = "<input type='image' src='images/fax_small.png' alt='"._("goFox Tab")."'     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit users Fax Tab")."'>";
689 //$sambaimg = "<img src='images/select_winstation.png'  alt='S' title='"._("Samba") ."'>";
690     $sambaimg = "<input type='image' src='images/select_winstation.png' alt='"._("Samba Tab")."'     name='user_edit_%KEY%-sambaAccount' title='"._("Edit users Samba Tab")."'>"; 
691     // Space 
692     $empty    = "<img src='images/empty.png' style='width:16px;height:16px;' alt=''>"; 
693     
694     // User and Template  Images  
695     $userimg  = "<img src='images/select_user.png' alt='User' title='%s'>";   
696     $tplimg   = "<img src='images/select_template.png' alt='Template' title='%s'>";   
697    
698     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
699  
700     // Defines Arrays to save User and Templates
701     $tpls = array();
702     $users= array();
704     // Test Every Entry and generate divlist Array  
705     foreach($this->list as $key => $val){
707       // Specify Pics for Extensions  
708       if(in_array("posixAccount"    ,$val['objectClass'])) $posix = preg_replace("/%KEY%/", "$key", $posiximg);  else $posix=$empty; 
709       if(in_array("gosaMailAccount" ,$val['objectClass'])) $maila = preg_replace("/%KEY%/", "$key", $mailimg);   else $maila=$empty; 
710       if(in_array("goFonAccount"    ,$val['objectClass'])) $fonac = preg_replace("/%KEY%/", "$key", $fonimg);    else $fonac=$empty; 
711       if(in_array("goFaxAccount"    ,$val['objectClass'])) $faxac = preg_replace("/%KEY%/", "$key", $faximg);    else $faxac=$empty; 
712       if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = preg_replace("/%KEY%/", "$key", $sambaimg);  else $samba=$empty; 
713       if(in_array("gosaUserTemplate",$val['objectClass'])) $tpl   = preg_replace("/%KEY%/", "$key", $tplimg);    else $tpl=$userimg;
714        
715       $usrimg = preg_replace("/%KEY%/", "$key", $usrimg);
716  
717       // Generate Array to Add 
718       if (isset($val["sn"]) && isset($val["givenName"])){
719         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
720       } else {
721         $display= "[".$val["uid"][0]."]";
722       }
724       $field1 = array("string" => sprintf($tpl,$val['dn']),"attach"=>"style='width:20px;align:middle;'");
725       $field2 = array("string" => sprintf($editlink,$key,$display),"attach"=>"title='".$val['dn']."'");
726       $field3 = array("string" => $usrimg."&nbsp;".$posix."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba,"attach" => "style='width:118px;'");
727       $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action),"attach" => "style='border:none; text-align:right;width:48px'");
728     
729       $add = array($field1,$field2,$field3,$field4);
730       
731       // Template or User
732       if(in_array("gosaUserTemplate",$val['objectClass'])){
733         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
734       }else{
735         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
736       }
737     }
738     
739     // Sort Entries 
740     ksort($users);
741     ksort($tpls);
743     // Append Templates
744     foreach($tpls as $key => $val){
745       $divlist->AddEntry( $val, array(""));
746     }
747     // Append Users 
748     foreach($users as $key => $val){
749       $divlist->AddEntry( $val, array(""));
750     }
751     /* Show main page */
752     //$smarty->assign("userlist",   nl2br(htmlentities($divlist->DrawList())));
753     $smarty->assign("userlist",   $divlist->DrawList());
754     $smarty->assign("userlisthead", $listhead);
756     /* END NEW LIST MANAGMENT
757      */  
758     $smarty->assign("search_image", get_template_path('images/search.png'));
759     $smarty->assign("tree_image", get_template_path('images/tree.png'));
760     $smarty->assign("infoimage", get_template_path('images/info.png'));
761     $smarty->assign("launchimage", get_template_path('images/launch.png'));
762     $smarty->assign("deplist", $this->config->idepartments);
763     foreach( array("depselect",  "functionalusers", "unixusers",
764           "mailusers", "sambausers", "proxyusers", 
765           "faxusers", "templates", "subsearch") as $type){
767       $smarty->assign("$type", $userfilter[$type]);
768     }
770     $smarty->assign("regex", $userfilter["regex"]);
771     /* Extend if we are not using javascript */
772     $smarty->assign("apply", apply_filter());
773     $smarty->assign("alphabet", generate_alphabet());
774     $smarty->assign("hint", print_sizelimit_warning());
776     return ($smarty->fetch(get_template_path('headpage.tpl', TRUE)));
777   }
780   function reload()
781   {
782     /* Get config */
783     $userfilter= get_global('userfilter');
785     /* Set base for all searches */
786     $base= $userfilter['depselect'];
788     /* Regex filter? */
789     if ($userfilter['regex'] != ""){
790       $regex= $userfilter['regex'];
791     } else {
792       $regex= "*";
793     }
795     /* Set filter depending on selection */
796     if ($this->config->current['SAMBAVERSION'] == 3){
797       $samba= "sambaSamAccount";
798     } else {
799       $samba= "sambaAccount";
800     }
802     $filter="";
803     if ($userfilter['functionalusers'] == "checked"){
804       $filter.= "(&(objectClass=gosaAccount)(!(|(objectClass=posixAccount)(objectClass=gosaMailAccount)(objectClass=$samba)(objectClass=goFaxAccount)(objectClass=gosaProxyAccount))))";
805     }
806     if ($userfilter['unixusers'] == "checked"){
807       $filter.= "(objectClass=posixAccount)";
808     }
809     if ($userfilter['mailusers'] == "checked"){
810       $filter.= "(objectClass=gosaMailAccount)";
811     }
812     if ($userfilter['sambausers'] == "checked"){
813       $filter.= "(objectClass=$samba)";
814     }
815     if ($userfilter['proxyusers'] == "checked"){
816       $filter.= "(objectClass=gosaProxyAccount)";
817     }
818     if ($userfilter['faxusers'] == "checked"){
819       $filter.= "(objectClass=goFaxAccount)";
820     }
822     if ($userfilter['templates'] == "checked"){
823       $filter= "(|(objectClass=gosaUserTemplate)(&(objectClass=gosaAccount)(|$filter)))";
824     } else {
825       $filter= "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|$filter))";
826     }
827     $filter= "(&(|(uid=$regex)(sn=$regex)(givenName=$regex))$filter)";
829     /* Generate userlist */
830     $ldap= $this->config->get_ldap_link(TRUE);
831     if ($userfilter['subsearch'] == "checked"){
832       $this->list= get_list($this->ui->subtreeACL, "$filter", TRUE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
833     } else {
834       $base= get_people_ou().$base;
835       $this->list= get_list($this->ui->subtreeACL, "$filter", FALSE, $base, array("uid", "givenName", "sn", "objectClass"), TRUE);
836     }
840     /* NEW LIST MANAGMENT
841      * We also need to search for the departments
842      * So we are able to navigate like in konquerer 
843      */
844     $base2 = preg_replace("/ou=people,/i","",$base);
846     $res3 =  get_list2($this->ui->subtreeACL, "(&(|(ou=$regex)(description=$regex))(objectClass=gosaDepartment))",
847                               TRUE, $base2, array("ou", "description"), TRUE);
849     $this->departments= array();
851     $tmp = array();
852     foreach ($res3 as $value){
853       $tmp[strtolower($value['dn']).$value['dn']]=$value;
854     }
855     ksort($tmp);
856     foreach($tmp as $value){
857       if($value["description"][0]!=".."){
858         $this->departments[$value['dn']]=convert_department_dn2($value['dn'])." - [".$value["description"][0]."]";
859       }else{
860         $this->departments[$value['dn']]=$value["description"][0];
861       }
862     }
863     /* END NEW LIST MANAGMENT 
864      */
865   
866     
867     $this->userlist= array();
869     foreach ($this->list as $value){
870       if (isset($value["uid"][0]) && !preg_match('/\$$/', $value["uid"][0])){
871         if (in_array_ics('gosaUserTemplate', $value['objectClass'])){
872           $this->userlist[$value["dn"]]= "* ".$value["uid"][0]." ("._("Template").")";
873           continue;
874         }
875         if (isset($value["givenName"][0]) && isset($value["sn"][0])){
876           $this->userlist[$value["dn"]]= $value["sn"][0].", ".
877             $value["givenName"][0].
878             " [".$value["uid"][0]."]";
879         } else {
880           $this->userlist[$value["dn"]]= "[".$value["uid"][0]."]";
881         }
882       }
883     }
885     natcasesort ($this->userlist);
886     reset ($this->userlist);
887   }
889   function remove_from_parent()
890   {
891   }
894   /* Check values */
895   function check()
896   {
897   }
900   /* Save to LDAP */
901   function save()
902   {
903   }
905   function adapt_from_template($dn)
906   {
907   }
909   function password_change_needed()
910   {
911   }
913   function show_header($button_text, $text, $disabled= FALSE)
914   {
915   }
917   function remove_lock()
918   {
919     if (isset($this->usertab->dn)){
920       del_lock ($this->usertab->dn);
921     }
922   }
926 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
927 ?>