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