Code

removed unused code
[gosa.git] / gosa-plugins / systems / admin / systems / class_divListSystem.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 divListSystem extends MultiSelectWindow
24 {
26   /* Current base */
27   var $selectedBase       = "";
28   var $departments        = array();
30   /* Regex */
31   var $Regex              = "*";
32   var $UserRegex          = "*";
34   /* CheckBoxes, to change default values modify $this->AddCheckBox */
35   var $ShowServers;
36   var $ShowTerminals;
37   var $ShowWorkstations;
38   var $ShowWinWorkstations;
39   var $ShowPrinters;
40   var $ShowDevices;
41   var $ShowPhones;
43   /* Subsearch checkbox */
44   var $SubSearch;
46   var $parent             ;
47   var $ui                 ;
49   function divListSystem (&$config,$parent)
50   {
51     MultiSelectWindow::MultiSelectWindow($config, "System", array("server",
52                                                                   "workstation",
53                                                                   "terminal",
54                                                                   "phone",
55                                                                   "incoming",
56                                                                   "printer"));
58     $this->parent       = $parent;
59     $this->ui           = get_userinfo();
61     /* Set list strings */
62     $this->SetTitle(_("List of systems"));
63     $this->SetSummary(_("List of systems"));
65     /* Result page will look like a headpage */
66     $this->SetHeadpageMode();
68     $this->EnableAplhabet   (true);
70     /* Disable buttonsm */
71     $this->EnableCloseButton(false);
72     $this->EnableSaveButton (false);
74     /* Dynamic action col, depending on snapshot icons */
75     $action_col_size = 120;
76     if($this->parent->snapshotEnabled()){
77       $action_col_size += 38;
78     }
80     /* Toggle all selected / deselected */
81     $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
82                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
84     /* set Page header */
85     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
86     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
87     $this->AddHeader(array("string"=>_("Systems")." / "._("Department")));
89     /* Add header for selected FAI release, if fai is active */
90     if($this->parent->fai_activated){
91       $this->AddHeader(array("string"=>_("Release"),"attach"=>"style='width:100px;'"));
92     }
94     $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
96     /*                  Text        ,Value    ,Name         ,Is selected */
98     if(class_available("servtabs")){
99       $this->AddCheckBox("ShowServers",        
100           msgPool::selectToView(  _("servers")),            
101           sprintf(_("Show %s"),   _("servers")),true);
102     }
103     if(class_available("termtabs")){
104       $this->AddCheckBox("ShowTerminals",       
105           msgPool::selectToView(  _("Linux terminals")),    
106           sprintf(_("Show %s"),   _("terminals")),true);
107     }
108     if(class_available("worktabs")){
109       $this->AddCheckBox("ShowWorkstations",
110           msgPool::selectToView(  _("Linux workstations")), 
111           sprintf(_("Show %s"),   _("workstations")),true);
112     }
113     if(class_available("wintabs")){
114       $this->AddCheckBox("ShowWinWorkstations", 
115           msgPool::selectToView(  _("MicroSoft Windows based workstations")), 
116           sprintf(_("Show %s"),   _("windows based workstations")),true);
117     }
118     if(class_available("printtabs")){
119       $this->AddCheckBox("ShowPrinters",
120           msgPool::selectToView(  _("network printers")),   
121           sprintf(_("Show %s"),   _("network printers")) ,true);
122     }
123     if(class_available("phonetabs")){
124       $this->AddCheckBox("ShowPhones",
125           msgPool::selectToView(  _("VoIP phones")),        
126           sprintf(_("Show %s"),   _("phones")) ,true);
127     }
128     if(class_available("componenttabs")){
129       $this->AddCheckBox("ShowDevices",
130           msgPool::selectToView(  _("network devices")),    
131           sprintf(_("Show %s"),   _("network devices")),  true);
132     }
134     /* Add SubSearch checkbox */
135     $this->AddCheckBox(SEPERATOR);
136     $this->AddCheckBox("SubSearch",  msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
138     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
139     $this->AddRegex   ("Regex",     _("Display systems matching"),"*" , true);
140     $this->AddRegex   ("UserRegex", _("Display systems of user"), "*" , false, "images/lists/search-user.png");
141   }
143   function GenHeader()
144   {
145    /* Prepare departments,
146        which are shown in the listbox on top of the listbox
147      */
148     $options= "";
150     /* Get all departments within this subtree */
151     $base     = $this->config->current['BASE'];
152     $options  = $this->create_department_list($this->module);
154     /* If there is at least one c (Create) and one w (Write) acl in this combination
155         display the snapshot paste icon. BUT check the correct acls in the management plugin */
156     $all_module_acls = "";
157     $ui = get_userinfo();
158     foreach($this->module as $module){
159       $all_module_acls .= $ui->has_complete_category_acls($this->selectedBase,$module);
160     }
162     /* Must we add an additional seperator */
163     $add_sep = false;
164    
165     /* Add default header */
166     $listhead = MultiSelectWindow::get_default_header();
168     /* Add base selection */
169     $listhead .= _("Base")."&nbsp; <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
170       " <input class='center' type='image' src='images/lists/submit.png' align='middle'
171       title='"._("Submit department")."' name='submit_department' alt='".           _("Submit")."'>&nbsp;";
173     /* Handle create icons */ 
174     $s = ".|"._("Actions")."|\n";
175     $s.= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
176       "&nbsp;"._("Create")."|\n";
178     if(class_available("termtabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"terminal/termgeneric"))){
179       $s.= "...|<img src='images/select_terminal.png' alt='' border='0' class='center'>".
180         "&nbsp;"._("Terminal")."|"."newsystem_terminal|\n";
181     }
182     if(class_available("worktabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"workstation/workgeneric"))){
183       $s.= "...|<img src='images/select_workstation.png' alt='' border='0' class='center'>".
184         "&nbsp;"._("Workstation")."|"."newsystem_workstation|\n";
185     }
186     if(class_available("servtabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"workstation/servgeneric"))){
187       $s.= "...|<img src='images/select_server.png' alt='' border='0' class='center'>".
188         "&nbsp;"._("Server")."|"."newsystem_server|\n";
189     }
190     if(class_available("phonetabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"phone/phoneGeneric"))){
191       $s.= "...|<img src='images/select_phone.png' alt='' border='0' class='center'>".
192         "&nbsp;"._("Phone")."|"."newsystem_phone|\n";
193     }
194     if(class_available("printtabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"printer/printgeneric"))){
195       $s.= "...|<img src='images/select_printer.png' alt='' border='0' class='center'>".
196         "&nbsp;"._("Printer")."|"."newsystem_printer|\n";
197     }
198     if(class_available("componenttabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"component/componentGeneric"))){
199       $s.= "...|<img src='images/select_component.png' alt='' border='0' class='center'>".
200         "&nbsp;"._("Component")."|"."newsystem_component|\n";
201     }
203     if($this->parent->si_active){
204       $events  = DaemonEvent::get_event_types(SYSTEM_EVENT);
206       $s.= "..|<img src='images/rocket.png' alt='' border='0' class='center'>".
207         "&nbsp;"._("Trigger action")."|\n";
208       foreach($events['TRIGGERED'] as $name => $event){
209         $s.= "...|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|trigger_event_".$name."\n";
210       }
212       $s.= "..|<img src='plugins/systems/images/clock.png' alt='' border='0' class='center'>".
213         "&nbsp;"._("Schedule action")."|\n";
214       foreach($events['SCHEDULED'] as $name =>  $event){
215         $s.= "...|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|schedule_event_".$name."\n";
216       }
217     }
219     $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
220       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
222     $s.= "..|<img src='images/lists/unlocked.png' alt='' border='0' class='center'>".
223       "&nbsp;"._("Activate systems")."|activate_multiple|\n";
225     /* Add Copy & Paste header */
226     $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
228     /* Add snapshot icons */
229     $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
231     $this->SetDropDownHeaderMenu($s);
232     $this->SetListHeader($listhead);
233   }
235   function execute()
236   {
237     $this->ClearElementsList();
238     $this->GenHeader();
239   }
241   function setEntries($terminals)
242   {
243     $empty    ="<img src='images/empty.png' style='width:16px ; height: 16px;' class='center' alt=''>";
245     /* Dynamic action col, depending on snapshot icons */
246     $action_col_size = 120;
247     if($this->parent->snapshotEnabled()){
248       $action_col_size += 38;
249     }
251     // User and Template  Images
252     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
254     /* ACL mapping */
255     $ui = get_userinfo();
256     $tabs = array(
257           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
258           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
259           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
260           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
261           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
262           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
263           "incoming"    => array("CLASS"=>"",             "TABCLASS" =>"",              "ACL"=> "incoming/systems"),
264           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
267     $cnts = array("component" => 0 , "terminal" => 0 , "workstation" => 0 , 
268                   "printer" => 0 , "phone" => 0 , "server" => 0,
269                   "NewDevice" => 0, "winstation"=> 0);
272     /* Get list of all objectGroups and their member and release configuration 
273      */
274     $ogroups = array();
275     if($this->parent->fai_activated){
276       $ogroups = get_sub_list("(&(objectClass=gosaGroupOfNames)(FAIclass=*)(member=*))",array("ogroups"),
277           get_ou("ogroupou"),$this->config->current['BASE'],array("FAIclass","member","cn"),GL_NO_ACL_CHECK | GL_SUBSEARCH);
278       foreach($ogroups as $ogroup){
279         for($i = 0 ; $i < $ogroup['member']['count'] ; $i++){
280           if(preg_match("/:/",$ogroup['FAIclass'][0])) {
281             if(!isset($og_list[$ogroup['member'][$i]])){
282               $ogs_release[$ogroup['member'][$i]]['STR'] = ""; 
283               $ogs_release[$ogroup['member'][$i]]['CN'] = ""; 
284             }
285             $ogs_release[$ogroup['member'][$i]]['STR'] .= preg_replace("/^.*:/","",$ogroup['FAIclass'][0]).", ";
286             $ogs_release[$ogroup['member'][$i]]['CN']  .= $ogroup['cn'][0].", ";
287           }
288         }
289       }
290     }
292     // Test Every Entry and generate divlist Array
293     foreach($terminals as $key => $val){
295       /* Get system type, it is used to fetch the acls for the current object.
296           "winstation" acls are stored as 2winworkstation", so we have to map this here */
297       $type     = $this->parent->get_system_type($val);
298       if($type == "winstation") {
299         $acl_type = "winworkstation";
300       }else{
301         $acl_type = $type;
302       }
304       /* Map NewDevice acls to workstation acls */
305       if($type == "NewDevice" || $type == "ArpNewDevice"){
306         $type     = "incoming";
307         $acl_type = "incoming";
308       }
310       $s_acl    = $tabs[$type]['ACL'];
311       $category = preg_replace("/\/.*$/","",$s_acl);
312       $class    = preg_replace("/^.*\//","",$s_acl);
314       /* Get complete category acls */
315       $acl_all  = $ui->has_complete_category_acls($val['dn'],$acl_type) ;
316   
317       /* Get specific generic acls */
318       $acl      = $ui->get_permissions($val['dn'],$tabs[$type]['ACL']);
320       /* Add copy & cut functionality */
321       $action= $this->parent->get_copypaste_action($val['dn'],$category,$class);
323       $action.= "<input class='center' type='image' src='images/lists/edit.png' 
324                     alt='"._("edit")."'     name='system_edit_%KEY%' title='"._("Edit system")."'>";
326       $action.= $this->parent->get_snapshot_action($val['dn'],$acl_type);
328       if(preg_match("/d/",$acl)){
329         $action.= "<input class='center' type='image' src='images/lists/trash.png'
330           alt='"._("delete")."'   name='system_del_%KEY%' title='"._("Delete system")."'>";
331       }else{
332         $action.= $empty;
333       }
335       $val['cn'][0]= preg_replace('/\$$/', '', $val['cn'][0]);
337       // Generate Array to Add
338       $dsc= "";
339       if (isset($val['description'][0])){
340         $dsc= " [".$val['description'][0]."]";
341       }
342       if((isset($val['is_new']))&&(!empty($val['is_new']))){
343         $display= $val["cn"][0]." ".$val['is_new'].$dsc;
344       }else{
345         $display= $val["cn"][0].$dsc;
346       }
348       /* Check if this is a terminal/workstation && if we are allowed to change the gotoRootPasswd */
349       $display_key_for = array("terminal","workstation","server","component");
350       $pwd_acl = $ui->get_permissions($val['dn'],$tabs[$type]['ACL'],"userPassword");
351       if(preg_match("/w/",$pwd_acl) && in_array($type,$display_key_for)){
352         $action2 = "<input class='center' type='image' src='images/lists/key.png' alt='"._("Password")."'   name='system_setpwd_%KEY%' title='"._("Set password")."'>";
353       }else{
354         $action2 = $empty;
355       }
357       if(in_array("gotoWorkstation",$val['objectClass'])){
358         $action2= "<input class='center' type='image' src='plugins/systems/images/cdrom.png' alt='"._("Create CD")."'   
359                       name='gen_cd_%KEY%' title='"._("Create FAI CD")."'>&nbsp;".$action2;
360       }else{
361         $action2= $empty.$action2;
362       }
364       if(isset($val['message'])){
365         $display.= "  (".$val['message'].")";
366       }
368       $img    = $this->parent->convert_list($val);
370       /* Cutted objects should be displayed in light grey */
371       if($this->parent->CopyPasteHandler){
372         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
373           if($queue_data['dn'] == $val['dn']) {
374             $display = "<font color='#999999'>".$display."</font>";
375             break;
376           }
377         }
378       }
380       $type = $this->parent->get_system_type($val);
381       if($type == "ArpNewDevice"){
382         $type = "NewDevice";
383       }
384       $cnts[$type] ++;
386       /* Create each field */
387       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
388           "attach" => "style='width:20px;'");
389       $field1 = array("string" => sprintf($img['img'],$val['dn']),
390           "attach" => "style='text-align:center;width:20px;'");
391       $field2 = array("string" => sprintf($editlink,$key,$display),
392           "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
393       $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action),
394           "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
396       if($this->parent->fai_activated){
398         $release ="&nbsp;";
399         $release_attach = ""; 
400         if(isset($val['FAIclass'][0]) && preg_match("/:/",$val['FAIclass'][0])){
401           $release        = preg_replace("/^.*:/","",$val['FAIclass'][0]);
402           $release_attach = ""; 
403         }elseif(isset($ogs_release[$val['dn']])){
404           $release = trim($ogs_release[$val['dn']]['STR'],", ").
405             "&nbsp;<img src='images/select_ogroup.png' class='center' alt='' 
406             title='".sprintf(_("Inherited from %s"),trim($ogs_release[$val['dn']]['CN'],", "))."'>";
407           $release_attach = "title='".sprintf(_("Inherited from %s"),trim($ogs_release[$val['dn']]['CN'],", "))."'"; 
408         }
409         $field2a = array("string" => $release,"attach"=>$release_attach." style='width:100px;'");
410         $this->AddElement( array($field0,$field1,$field2,$field2a,$field3));
411       }else{
412         $this->AddElement( array($field0,$field1,$field2,$field3));
413       }
414     }
416     /* Create summary string for list footer */
417     $num_deps=0;
418     if(!$this->SubSearch){
419       $num_deps = count($this->Added_Departments);
420     }
422     $num_ser_str = sprintf(_("Number of listed '%s'"),_("servers"));
423     $num_ws_str  = sprintf(_("Number of listed '%s'"),_("workstations"));
424     $num_ter_str = sprintf(_("Number of listed '%s'"),_("terminals"));
425     $num_pho_str = sprintf(_("Number of listed '%s'"),_("phones"));
426     $num_prt_str = sprintf(_("Number of listed '%s'"),_("printers"));
427     $num_com_str = sprintf(_("Number of listed '%s'"),_("network components"));
428     $num_new_str = sprintf(_("Number of listed '%s'"),_("new devices"));
429     $num_wws_str = sprintf(_("Number of listed '%s'"),_("windows workstations"));
430     $num_dep_str = sprintf(_("Number of listed '%s'"),_("departments"));
432     $str = "<img class='center' src='images/select_server.png'
433       title='".$num_ser_str."' alt='".$num_ser_str."'>&nbsp;".$cnts['server']."&nbsp;&nbsp;&nbsp;&nbsp;";
434     $str.= "<img class='center' src='images/select_workstation.png'
435       title='".$num_ws_str."' alt='".$num_ws_str."'>&nbsp;".$cnts['workstation']."&nbsp;&nbsp;&nbsp;&nbsp;";
436     $str.= "<img class='center' src='images/select_terminal.png'
437       title='".$num_ter_str."' alt='".$num_ter_str."'>&nbsp;".$cnts['terminal']."&nbsp;&nbsp;&nbsp;&nbsp;";
438     $str.= "<img class='center' src='images/select_phone.png'
439       title='".$num_pho_str."' alt='".$num_pho_str."'>&nbsp;".$cnts['phone']."&nbsp;&nbsp;&nbsp;&nbsp;";
440     $str.= "<img class='center' src='images/select_printer.png'
441       title='".$num_prt_str."' alt='".$num_prt_str."'>&nbsp;".$cnts['printer']."&nbsp;&nbsp;&nbsp;&nbsp;";
442     $str.= "<img class='center' src='images/select_component.png'
443       title='".$num_com_str."' alt='".$num_com_str."'>&nbsp;".$cnts['component']."&nbsp;&nbsp;&nbsp;&nbsp;";
444     $str.= "<img class='center' src='images/select_newsystem.png'
445       title='".$num_new_str."' alt='".$num_new_str."'>&nbsp;".$cnts['NewDevice']."&nbsp;&nbsp;&nbsp;&nbsp;";
446     $str.= "<img class='center' src='images/select_winstation.png'
447       title='".$num_wws_str."' alt='".$num_wws_str."'>&nbsp;".$cnts['winstation']."&nbsp;&nbsp;&nbsp;&nbsp;";
448     $str.= "<img class='center' src='images/lists/folder.png'
449       title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
451     $this->set_List_Bottom_Info($str);
452   }
455   function Save()
456   {
457     MultiSelectWindow :: Save();  
458   }
461   function save_object()
462   {
463     /* Save automatic created POSTs like regex, checkboxes */
464     MultiSelectWindow :: save_object();  
467   }
469 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
470 ?>