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