Code

Order fix
[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;
40   var $ShowPhoneUsers;
42   /* Subsearch checkbox */
43   var $SubSearch              = false;
45   var $parent             ;
46   var $ui                 ;
48   function divListUsers (&$config,$parent)
49   {
50     MultiSelectWindow::MultiSelectWindow($config, "Users", "users");
51     
52     $this->parent       = $parent;
53     $this->ui           = get_userinfo();
55     /* Set list strings */
56     $this->SetTitle(_("List of users"));
57     $this->SetSummary(_("List of users"));
59     /* Result page will look like a headpage */
60     $this->SetHeadpageMode();
62     $this->EnableAplhabet   (true);
63   
64     /* Disable buttonsm */
65     $this->EnableCloseButton(false);
66     $this->EnableSaveButton (false);
68     /* Dynamic action col, depending on snapshot icons */
69     $action_col_size = 122;
70     if($this->parent->snapshotEnabled()){
71       $action_col_size += 38;
72     }
74     /* Toggle all selected / deselected */
75     $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."' 
76                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
78     /* set Page header */
79     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
80     $this->AddHeader(array("string"=> "&nbsp;",          "attach"=>"style='width:20px;'"));
81     $this->AddHeader(array("string"=>_("Username")." / "._("Department")));
82     $this->AddHeader(array("string"=>_("Properties"),   "attach" => "style='width:166px;'"));
83     $this->AddHeader(array("string"=>_("Actions"),      "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"));
84     
85     $this->AddCheckBox("ShowTemplates"      ,msgPool::selectToView(_("Template"))             ,sprintf(_("Show %s"),_("templates")), false);
86     $this->AddCheckBox("ShowFunctionalUsers",msgPool::selectToView(_("GOsa object"),"enabled"),sprintf(_("Show %s"),_("functional users")), true);
87     $this->AddCheckBox("ShowUnixUsers"      ,msgPool::selectToView(_("Posix"),"enabled")      ,sprintf(_("Show %s"),_("POSIX users")), true);
88     $this->AddCheckBox("ShowMailUsers"      ,msgPool::selectToView(_("Mail"),"enabled")       ,sprintf(_("Show %s"),_("mail users")), true);
89     $this->AddCheckBox("ShowSambaUsers"     ,msgPool::selectToView(_("Samba"),"enabled")      ,sprintf(_("Show %s"),_("samba users")), true);
90     $this->AddCheckBox("ShowProxyUsers"     ,msgPool::selectToView(_("Proxy"),"enabled")      ,sprintf(_("Show %s"),_("proxy users")), true);
92     if(class_available("phoneAccount")){
93       $this->AddCheckBox("ShowPhoneUsers"     ,msgPool::selectToView(_("Phone"),"enabled")      ,sprintf(_("Show %s"),_("phone users")), true);
94     }
96     /* Add SubSearch checkbox */
97     $this->AddCheckBox(SEPERATOR);
98     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
100     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
101     $this->AddRegex   ("Regex",     _("Display users matching"),"*" , true);
102   }
105   function GenHeader()
106   {
107     /* Get all departments within this subtree */ 
108     $base = $this->config->current['BASE'];
109     $options  = $this->create_department_list($this->module);
111     /* Get copy & paste icon */
112     $ui = get_userinfo();
113     $acl      = $ui->get_permissions($this->selectedBase,"users/user");
115     /* Add default header */
116     $listhead = MultiSelectWindow::get_default_header();
117     $listhead .=
118       _("Base")."&nbsp;<select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
119       " <input class='center' type='image' src='images/lists/submit.png' align='middle' 
120       title='"._("Submit department")."' name='submit_department' alt='".  _("Submit")."'>&nbsp;";
123     /* Create Layers menu */
124     $s  = ".|"._("Actions")."|\n";
126     /* Append create options */
127     if(preg_match("/c/",$acl)) {
128       $s .= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
129         "&nbsp;"._("Create")."|\n";
130       $s.= "...|<input class='center' type='image' src='plugins/users/images/list_new_user.png' alt=''>".
131         "&nbsp;"._("User")."|user_new|\n";
132       $s.= "...|<input class='center' type='image' src='images/lists/new.png' alt=''>".
133         "&nbsp;"._("Template")."|user_tplnew|\n";
134     }
136     /* Multiple options */ 
137     $s.= "..|---|\n";
138     $s.= "..|<img src='images/lists/edit.png' alt='' border='0' class='center'>".
139       "&nbsp;"._("Edit")."|"."multiple_edit|\n";
140     $s.= "..|<img src='plugins/users/images/list_password.png' alt='' border='0' class='center'>".
141       "&nbsp;"._("Change password")."|"."multiple_password_change|\n";
142     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
143       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
144     $s.= "..|<img src='plugins/users/images/wizard.png' alt='' border='0' class='center'>".
145       "&nbsp;"._("Apply template")."|"."templatize_multiple|\n";
147     /* Add event tag */
148     if(class_available("DaemonEvent")){
149       $events  = DaemonEvent::get_event_types(USER_EVENT);
150       if(count($events['BY_CLASS'])){
151         $s.= "..|---|\n";
152         foreach($events['BY_CLASS'] as $name => $event){
153           $s.= "..|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|event_".$name."\n";
154         }
155       }
156     }
158     $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
159     $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
161     $this->SetDropDownHeaderMenu($s);
162     $this->SetListHeader($listhead);
163   }
165   /* so some basic settings */
166   function execute()
167   {
168     $this->ClearElementsList();
169     $this->GenHeader();
170   }
172   function setEntries($list)
173   {
174     /********************
175       Variable init
176      ********************/
177     
178     $num_users      = 0;
179     $num_templates  = 0;
181     /* Variable initialation */
182     $enviro     = $posix = $maila = $faxac = $samba = $netatalk = "";
183     $empty      = "<img class='center' src='images/empty.png' style='width:16px;height:16px;' alt='-'>";
184     $userimg    = "<img class='center' src='plugins/users/images/select_user.png' alt='User' title='%s'>";
185     $tplimg     = "<img class='center' src='plugins/users/images/select_template.png' alt='Template' title='%s'>";
186     $editlink   = "<a href='?plug=".validate($_GET['plug'])."&amp;id=%s&amp;act=edit_entry'>%s</a>";
188     /* Dynamic action col, depending on snapshot icons */
189     $action_col_size = 122;
190     if($this->parent->snapshotEnabled()){
191       $action_col_size += 38;
192     }
194     /* Possilbe objectClass image combinations */  
195     $possibleAccounts = array(
196             "posixAccount"    => array("VAR"=>"posix"     ,"IMG"=>"posiximg"),
197             "gotoEnvironment" => array("VAR"=>"enviro"    ,"IMG"=>"eviroimg"),
198             "gosaMailAccount" => array("VAR"=>"maila"     ,"IMG"=>"mailimg"),
199             "goFaxAccount"    => array("VAR"=>"faxac"     ,"IMG"=>"faximg"),
200             "sambaSamAccount" => array("VAR"=>"samba"     ,"IMG"=>"sambaimg"),
201             "apple-user"      => array("VAR"=>"netatalk"  ,"IMG"=>"netatalkimg"));
203      /* Pictures for Extensions */
204     $usrimg   ="<input class='center' type='image' src='plugins/users/images/select_user.png' alt='"._("GOsa")."'
205                     name='user_edit_%KEY%-user' title='"._("Edit generic properties")."'>";
206     $posiximg = "<input class='center' type='image' src='images/penguin.png' alt='"._("Posix")."'
207                     name='user_edit_%KEY%-posixAccount' title='"._("Edit UNIX properties")."'>";
208     $eviroimg = "<input class='center' type='image' src='plugins/users/images/small_environment.png' alt='"._("Environment")."'
209                     name='user_edit_%KEY%-environment' title='"._("Edit environment properties")."'>";
210     $mailimg  = "<input class='center' type='image' src='images/mailto.png' alt='"._("Mail")."'
211                     name='user_edit_%KEY%-mailAccount' title='"._("Edit mail properties")."'>";
212     $fonimg   = "<input class='center' type='image' src='%image%' alt='"._("Phone")."'
213                     name='user_edit_%KEY%-phoneAccount' title='"._("Edit phone properties")."%title%'>";
214     $faximg   = "<input class='center' type='image' src='plugins/users/images/fax_small.png' alt='"._("Fax")."'
215                     name='user_edit_%KEY%-gofaxAccount' title='"._("Edit fax properies")."'>";
216     $sambaimg = "<input class='center' type='image' src='plugins/systems/images/select_winstation.png' alt='"._("Samba")."'
217                     name='user_edit_%KEY%-sambaAccount' title='"._("Edit samba properties")."'>";
218     $netatalkimg = "<input class='center' type='image' src='plugins/netatalk/images/select_netatalk.png' alt='"._("Netatalk")."'
219                     name='user_edit_%KEY%-netatalk' title='"._("Edit netatalk properties")."'>";
220     $tplcreateuserimg  = "<input type='image' class='center' src='images/lists/new.png' alt='"._("Create user from template")."'
221                     name='userfrom_tpl_%KEY%' title='"._("Create user with this template")."'>";
223     /********************
224       END :: Variable init
225      ********************/
227  
228     /********************
229       Append entries to divlist 
230      ********************/
231  
232     $ui = get_userinfo(); 
233   
234     // Test Every Entry and generate divlist Array
235     foreach($list as $key => $val){
236   
237       /* Create action icons */
238       $action= "";
240       /* Add copy & cut icons */     
241       $acl      = $ui->get_permissions($val['dn'],"users/user");
242      
243       /* Add copy & cut functionality */
244       $action.= $this->parent->get_copypaste_action($val['dn'],"users","user");
246       /* Add deactivate status */
247       $lock_status = "";
249       if(isset($val['userPassword'][0]) && preg_match("/^\{[^\}]/",$val['userPassword'][0])){
250         if(preg_match("/^[^\}]*+\}!/",$val['userPassword'][0])){
251           $lock_status = "<input class='center' type='image' src='images/lists/locked.png'
252             alt='"._("inactive")."' name='toggle_lock_status_%KEY%'>";
253         }else{
254           $lock_status = "<input class='center' type='image' src='images/lists/unlocked.png'
255             alt='"._("active")."' name='toggle_lock_status_%KEY%'>";
256         }
257       }else{
258         $lock_status = "<img src='images/empty.png' alt=' ' class='center'>";
259       }
261       /* Generate edit icon */
262       $action.= "<input class='center' type='image' src='images/lists/edit.png' alt='"._("edit")."'
263         name='user_edit_%KEY%' title='".msgPool::editButton(_("user"))."'>";
265       /* Add deactivate status if we are allowed to */
266       if (preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))){
267         $action.= $lock_status;
268       }else{
269         $action.="<img src='images/empty.png' alt=' ' class='center'>";
270       }
272       /* Add Password change icon, if we are able to write users/password */
273       if(!in_array_ics("gosaUserTemplate",$val['objectClass']) && preg_match("/w/",$ui->get_permissions($val['dn'],"users/password"))) {
274         $action.= "<input class='center' type='image' src='plugins/users/images/list_password.png' alt='"._("password")."'
275           name='user_chgpw_%KEY%' title='"._("Change password")."'>";
276       }else{
277         $action.= "<img class='center' src='images/empty.png' alt='&nbsp;' 
278           title='"._("Not allowed")."'>";
279       }
281       /* Add snapshot functionality */
282       $action.= $this->parent->get_snapshot_action($val['dn'],$this->module);
284       /* Add remove icon, if we are allowed to remove the current user */
285       if(preg_match("/d/",$acl)) {
286         $action.= "<input class='center' type='image' src='images/lists/trash.png' alt='"._("delete")."'
287           name='user_del_%KEY%' title='"._("Delete user")."'>";
288       }else{
289         $action.= "<img class='center' src='images/empty.png' alt='&nbsp;'  
290           title='"._("Not allowed")."'>";
291       }
293       /* Create phonaccopunt informationm, if conencted && is phoneAccount */ 
294       if(class_available("phoneAccount") && (in_array("goFonAccount"    ,$val['objectClass']))){
296         /* Set defaults */
297         $fonac = preg_replace("/%image%/", "plugins/gofon/images/select_phone.png", $fonimg);
298         $fonac = preg_replace("/%KEY%/", "$key", $fonac);
299         $fonac = preg_replace("/%title%/", "", $fonac);
301       }else{
302         $fonac=$empty;
303       }
305       /* Set images for different types of objectClasses */
306       foreach($possibleAccounts as $objectClass => $Settigns){ 
307         if(in_array($objectClass ,$val['objectClass'])){
308           $$Settigns['VAR'] = preg_replace("/%KEY%/", "$key", $$Settigns['IMG']);
309         }else{
310           $$Settigns['VAR'] = $empty;
311         }
312       }
314       /* Create userimg */
315       if(in_array("gosaUserTemplate",$val['objectClass'])){
316         $tpl                          = preg_replace("/%KEY%/", "$key", $tplimg);
317         $s_img_create_from_template   = preg_replace("/%KEY%/", "$key", $tplcreateuserimg);
318         $num_templates ++;
319       }else{
320         $s_img_create_from_template   = "";
321         $tpl                          = $userimg;
322         $num_users ++;
323       }
325       /* Insert key into userimg */
326       $usrimg2 = preg_replace("/%KEY%/", "$key", $usrimg);
328       // Generate caption for rows
329       if (isset($val["sn"]) && isset($val["givenName"])){
330         $display= $val["sn"][0].", ".$val["givenName"][0]." [".$val["uid"][0]."]";
331       } else {
332         $display= "[".$val["uid"][0]."]";
333       }
335       /* Connect all images */
336       $UseImg = $usrimg2."&nbsp;".$posix."&nbsp;".$enviro."&nbsp;".$maila."&nbsp;".$fonac."&nbsp;".$faxac."&nbsp;".$samba."&nbsp;".$netatalk;
338       /* Cutted objects should be displayed in light grey */ 
339       if($this->parent->CopyPasteHandler){
340         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
341           if($queue_data['dn'] == $val['dn']) {
342             $display = "<font color='#999999'>".$display."</font>";
343             break;
344           }
345         }
346       }
348       /* Create each field */
349       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
350                       "attach" => "style='width:20px;'");
351       $field1 = array("string" => sprintf($tpl,$val['dn']), "attach" => "style='text-align:center;width:20px;'");
352       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', LDAP::fix($val['dn']))."'");
353       $field3 = array("string" => $UseImg, "attach" => "style='width:166px;'");
354       $field4 = array("string" => $s_img_create_from_template.preg_replace("/%KEY%/", "$key", $action),
355                       "attach" => "style='width:".$action_col_size."px;border-right:0px;    text-align:right;'");
356       /* Add to list */
357       $add = array($field0,$field1,$field2,$field3,$field4);
358       $this->AddElement($add);
360       // Template or User
361       if(in_array("gosaUserTemplate",$val['objectClass'])){
362         $tpls[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
363       }else{
364         $users[strtolower( $val['sn']['0'].$val['uid']['0'])]=$add;
365       }
366     }
369     /* Create summary string for list footer */
370     $num_deps=0;
371     if(!$this->SubSearch){
372       $num_deps = count($this->Added_Departments);
373     }
374     $num_users = count($list);
376     $num_user_str = _("Number of listed users");
377     $num_dep_str = _("Number of listed departments");
379     $str = "<img class='center' src='plugins/users/images/select_user.png'
380               title='".$num_user_str."' alt='".$num_user_str."'>&nbsp;".$num_users."&nbsp;&nbsp;&nbsp;&nbsp;";
381     $str.= "<img class='center' src='images/lists/folder.png'
382               title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
384     $this->set_List_Bottom_Info($str);
385   }
387   function Save()
388   {
389     MultiSelectWindow :: Save();  
390   }
392   function save_object()
393   {
394     /* Save automatic created POSTs like regex, checkboxes */
395     MultiSelectWindow::save_object();   
396   }
398 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
399 ?>