Code

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