Code

Updated filter list
[gosa.git] / gosa-core / plugins / admin / users / class_divListUsers.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class divListUsers extends MultiSelectWindow
24 {
26   /* Current base */
27   var $selectedBase       = "";
28   var $departments        = array();
30   /* Regex */
31   var $Regex              = "*";
33   /* CheckBoxes */
34   var $ShowTemplates ;
35   var $ShowFunctionalUsers;
36   var $ShowUnixUsers;
37   var $ShowMailUsers;
38   var $ShowSambaUsers;
39   var $ShowProxyUsers;
41   /* Subsearch checkbox */
42   var $SubSearch              = false;
44   var $parent             ;
45   var $ui                 ;
47   function divListUsers (&$config,$parent)
48   {
49     MultiSelectWindow::MultiSelectWindow($config, "Users", "users");
50     
51     $this->parent       = $parent;
52     $this->ui           = get_userinfo();
54     /* Set list strings */
55     $this->SetTitle(_("List of users"));
56     $this->SetSummary(_("List of users"));
58     /* Result page will look like a headpage */
59     $this->SetHeadpageMode();
61     $this->EnableAplhabet   (true);
62   
63     /* Disable buttonsm */
64     $this->EnableCloseButton(false);
65     $this->EnableSaveButton (false);
67     /* Dynamic action col, depending on snapshot icons */
68     $action_col_size = 122;
69     if($this->parent->snapshotEnabled()){
70       $action_col_size += 38;
71     }
73     /* Toggle all selected / deselected */
74     $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."' 
75                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
77     /* set Page header */
78     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
79     $this->AddHeader(array("string"=> "&nbsp;",          "attach"=>"style='width:20px;'"));
80     $this->AddHeader(array("string"=>_("Username")." / "._("Department")));
81     $this->AddHeader(array("string"=>_("Properties"),   "attach" => "style='width:166px;'"));
82     $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
83     
84     $this->AddCheckBox("ShowTemplates"      ,msgPool::selectToView(_("Template"))             ,sprintf(_("Show %s"),_("templates")), false);
85     $this->AddCheckBox("ShowFunctionalUsers",msgPool::selectToView(_("GOsa object"),"enabled"),sprintf(_("Show %s"),_("functional users")), true);
86     $this->AddCheckBox("ShowUnixUsers"      ,msgPool::selectToView(_("Posix"),"enabled")      ,sprintf(_("Show %s"),_("POSIX users")), true);
87     $this->AddCheckBox("ShowMailUsers"      ,msgPool::selectToView(_("Mail"),"enabled")       ,sprintf(_("Show %s"),_("mail users")), true);
88     $this->AddCheckBox("ShowSambaUsers"     ,msgPool::selectToView(_("Samba"),"enabled")      ,sprintf(_("Show %s"),_("samba users")), true);
89     $this->AddCheckBox("ShowProxyUsers"     ,msgPool::selectToView(_("Proxy"),"enabled")      ,sprintf(_("Show %s"),_("proxy users")), true);
91     /* Add SubSearch checkbox */
92     $this->AddCheckBox(SEPERATOR);
93     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
95     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
96     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
97   }
100   function GenHeader()
101   {
102     /* Get all departments within this subtree */ 
103     $base = $this->config->current['BASE'];
104     $options  = $this->create_department_list($this->module);
106     /* Get copy & paste icon */
107     $ui = get_userinfo();
108     $acl      = $ui->get_permissions($this->selectedBase,"users/user");
110     /* Add default header */
111     $listhead = MultiSelectWindow::get_default_header();
112     $listhead .=
113       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
114       " <input class='center' type='image' src='images/lists/submit.png' align='middle' 
115       title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;";
118     /* Create Layers menu */
119     $s  = ".|"._("Actions")."|\n";
121     /* Append create options */
122     if(preg_match("/c/",$acl)) {
123       $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
124         "&nbsp;"._("Create")."|\n";
125       $s.= "...|<input class='center' type='image' src='plugins/users/images/list_new_user.png' alt=''>".
126         "&nbsp;"._("User")."|user_new|\n";
127       $s.= "...|<input class='center' type='image' src='images/lists/new.png' alt=''>".
128         "&nbsp;"._("Template")."|user_tplnew|\n";
129     }
131     /* Multiple options */ 
132     $s.= "..|---|\n";
133     $s.= "..|<img src='images/lists/edit.png' alt='' border='0' class='center'>".
134       "&nbsp;"._("Edit")."|"."multiple_edit|\n";
135     $s.= "..|<img src='plugins/users/images/list_password.png' alt='' border='0' class='center'>".
136       "&nbsp;"._("Change password")."|"."multiple_password_change|\n";
137     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
138       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
139     $s.= "..|<img src='plugins/users/images/wizard.png' alt='' border='0' class='center'>".
140       "&nbsp;"._("Apply template")."|"."templatize_multiple|\n";
142     /* Add event tag */
143     if(class_available("DaemonEvent")){
144       $events  = DaemonEvent::get_event_types(USER_EVENT);
145       if(count($events['BY_CLASS'])){
146         $s.= "..|---|\n";
147         foreach($events['BY_CLASS'] as $name => $event){
148           $s.= "..|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|event_".$name."\n";
149         }
150       }
151     }
153     $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
154     $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
156     $this->SetDropDownHeaderMenu($s);
157     $this->SetListHeader($listhead);
158   }
160   /* so some basic settings */
161   function execute()
162   {
163     $this->ClearElementsList();
164     $this->GenHeader();
165   }
167   function setEntries($list)
168   {
169     /********************
170       Variable init
171      ********************/
172     
173     $num_users      = 0;
174     $num_templates  = 0;
176     /* Variable initialation */
177     $enviro     = $posix = $maila = $faxac = $samba = $netatalk = "";
178     $empty      = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
179     $userimg    = "<img class='center' src='plugins/users/images/select_user.png' alt='User' title='%s'>";
180     $tplimg     = "<img class='center' src='plugins/users/images/select_template.png' alt='Template' title='%s'>";
181     $editlink   = "<a href='?plug=".validate($_GET['plug'])."&amp;id=%s&amp;act=edit_entry'>%s</a>";
183     /* Dynamic action col, depending on snapshot icons */
184     $action_col_size = 122;
185     if($this->parent->snapshotEnabled()){
186       $action_col_size += 38;
187     }
189     /* Possilbe objectClass image combinations */  
190     $possibleAccounts = array(
191             "posixAccount"    => array("VAR"=>"posix"     ,"IMG"=>"posiximg"),
192             "gotoEnvironment" => array("VAR"=>"enviro"    ,"IMG"=>"eviroimg"),
193             "gosaMailAccount" => array("VAR"=>"maila"     ,"IMG"=>"mailimg"),
194             "goFaxAccount"    => array("VAR"=>"faxac"     ,"IMG"=>"faximg"),
195             "sambaSamAccount" => array("VAR"=>"samba"     ,"IMG"=>"sambaimg"),
196             "apple-user"      => array("VAR"=>"netatalk"  ,"IMG"=>"netatalkimg"));
198      /* Pictures for Extensions */
199     $usrimg   ="<input class='center' type='image' src='plugins/users/images/select_user.png' alt='"._("GOsa")."'
200                     name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
201     $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
202                     name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
203     $eviroimg = "<input class='center' type='image' src='plugins/users/images/small_environment.png' alt='"._("Environment")."'
204                     name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
205     $mailimg  = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
206                     name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
207     $fonimg   = "<input class='center' type='image' src='%image%' alt='"._("Phone")."'
208                     name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
209     $faximg   = "<input class='center' type='image' src='plugins/users/images/fax_small.png' alt='"._("Fax")."'
210                     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
211     $sambaimg = "<input class='center' type='image' src='plugins/systems/images/select_winstation.png' alt='"._("Samba")."'
212                     name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
213     $netatalkimg = "<input class='center' type='image' src='plugins/netatalk/images/select_netatalk.png' alt='"._("Netatalk")."'
214                     name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
215     $tplcreateuserimg  = "<input type='image' class='center' src='images/lists/new.png' alt='"._("Create user from template")."'
216                     name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
218     /********************
219       END :: Variable init
220      ********************/
222  
223     /********************
224       Append entries to divlist 
225      ********************/
226  
227     $ui = get_userinfo(); 
228   
229     // Test Every Entry and generate divlist Array
230     foreach($list as $key => $val){
231   
232       /* Create action icons */
233       $action= "";
235       /* Add copy & cut icons */     
236       $acl      = $ui->get_permissions($val['dn'],"users/user");
237      
238       /* Add copy & cut functionality */
239       $action.= $this->parent->get_copypaste_action($val['dn'],"users","user");
241       /* Add deactivate status */
242       $lock_status = "";
244       if(isset($val['userPassword'][0]) && preg_match("/^\{[^\}]/",$val['userPassword'][0])){
245         if(preg_match("/^[^\}]*+\}!/",$val['userPassword'][0])){
246           $lock_status = "<input class='center' type='image' src='images/lists/locked.png'
247             alt='"._("inactive")."' name='toggle_lock_status_%KEY%'>";
248         }else{
249           $lock_status = "<input class='center' type='image' src='images/lists/unlocked.png'
250             alt='"._("active")."' name='toggle_lock_status_%KEY%'>";
251         }
252       }else{
253         $lock_status = "<img src='images/empty.png' alt=' ' class='center'>";
254       }
256       /* Generate edit icon */
257       $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."'
258         name='user_edit_%KEY%' title='".msgPool::editButton(_("user"))."'>";
260       /* Add deactivate status if we are allowed to */
261       if (preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))){
262         $action.= $lock_status;
263       }else{
264         $action.="<img src='images/empty.png' alt=' ' class='center'>";
265       }
267       /* Add Password change icon, if we are able to write users/password */
268       if(!in_array_ics("gosaUserTemplate",$val['objectClass']) && preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
269         $action.= "<input class='center' type='image' src='plugins/users/images/list_password.png' alt='"._("password")."'
270           name='user_chgpw_%KEY%' title='"._("Change password")."'>";
271       }else{
272         $action.= "<img class='center' src='images/empty.png' alt='&nbsp;' 
273           title='"._("Not allowed")."'>";
274       }
276       /* Add snapshot functionality */
277       $action.= $this->parent->get_snapshot_action($val['dn'],$this->module);
279       /* Add remove icon, if we are allowed to remove the current user */
280       if(preg_match("/d/",$acl)) {
281         $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("delete")."'
282           name='user_del_%KEY%' title='"._("Delete user")."'>";
283       }else{
284         $action.= "<img class='center' src='images/empty.png' alt='&nbsp;'  
285           title='"._("Not allowed")."'>";
286       }
288       /* Create phonaccopunt informationm, if conencted && is phoneAccount */ 
289       if(class_available("phoneAccount") && (in_array("goFonAccount"    ,$val['objectClass']))){
291         /* Set defaults */
292         $fonac = preg_replace("/%image%/", "plugins/gofon/images/select_phone.png", $fonimg);
293         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
294         $fonac = preg_replace("/%title%/", "", $fonac);
296       }else{
297         $fonac=$empty;
298       }
300       /* Set images for different types of objectClasses */
301       foreach($possibleAccounts as $objectClass => $Settigns){ 
302         if(in_array($objectClass ,$val['objectClass'])){
303           $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
304         }else{
305           $$Settigns['VAR'] = $empty;
306         }
307       }
309       /* Create userimg */
310       if(in_array("gosaUserTemplate",$val['objectClass'])){
311         $tpl                          = preg_replace("/%KEY%/", "$key", $tplimg);
312         $s_img_create_from_template   = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
313         $num_templates ++;
314       }else{
315         $s_img_create_from_template   = "";
316         $tpl                          = $userimg;
317         $num_users ++;
318       }
320       /* Insert key into userimg */
321       $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
323       // Generate caption for rows
324       if (isset($val["sn"]) && isset($val["givenName"])){
325         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
326       } else {
327         $display= "[".$val["uid"][0]."]";
328       }
330       /* Connect all images */
331       $UseImg = $usrimg2."&nbsp;".$posix."&nbsp;".$enviro."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba."&nbsp;".$netatalk;
333       /* Cutted objects should be displayed in light grey */ 
334       if($this->parent->CopyPasteHandler){
335         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
336           if($queue_data['dn'] == $val['dn']) {
337             $display = "<font color='#999999'>".$display."</font>";
338             break;
339           }
340         }
341       }
343       /* Create each field */
344       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
345                       "attach" => "style='width:20px;'");
346       $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
347       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', LDAP::fix($val['dn']))."'");
348       $field3 = array("string" => $UseImg, "attach" => "style='width:166px;'");
349       $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
350                       "attach" => "style='width:".$action_col_size."px;border-right:0px;    text-align:right;'");
351       /* Add to list */
352       $add = array($field0,$field1,$field2,$field3,$field4);
353       $this->AddElement($add);
355       // Template or User
356       if(in_array("gosaUserTemplate",$val['objectClass'])){
357         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
358       }else{
359         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
360       }
361     }
364     /* Create summary string for list footer */
365     $num_deps=0;
366     if(!$this->SubSearch){
367       $num_deps = count($this->Added_Departments);
368     }
369     $num_users = count($list);
371     $num_user_str = _("Number of listed users");
372     $num_dep_str = _("Number of listed departments");
374     $str = "<img class='center' src='plugins/users/images/select_user.png'
375               title='".$num_user_str."' alt='".$num_user_str."'>&nbsp;".$num_users."&nbsp;&nbsp;&nbsp;&nbsp;";
376     $str.= "<img class='center' src='images/lists/folder.png'
377               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
379     $this->set_List_Bottom_Info($str);
380   }
382   function Save()
383   {
384     MultiSelectWindow :: Save();  
385   }
387   function save_object()
388   {
389     /* Save automatic created POSTs like regex, checkboxes */
390     MultiSelectWindow::save_object();   
391   }
393 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
394 ?>