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",
59 "opsi"));
61 $this->parent = $parent;
62 $this->ui = get_userinfo();
64 /* Set list strings */
65 $this->SetTitle(_("List of systems"));
66 $this->SetSummary(_("List of systems"));
68 /* Result page will look like a headpage */
69 $this->SetHeadpageMode();
71 $this->EnableAplhabet (true);
73 /* Disable buttonsm */
74 $this->EnableCloseButton(false);
75 $this->EnableSaveButton (false);
77 /* Dynamic action col, depending on snapshot icons */
78 $action_col_size = 120;
79 if($this->parent->snapshotEnabled()){
80 $action_col_size += 38;
81 }
83 /* Toggle all selected / deselected */
84 $chk = "<input type='checkbox' id='select_all' name='select_all' title='"._("Select all")."'
85 onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
87 /* set Page header */
88 $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'"));
89 $this->AddHeader(array("string"=>" ","attach"=>"style='width:20px;'"));
90 $this->AddHeader(array("string"=>_("Systems")." / "._("Department")));
92 /* Add header for selected FAI release, if fai is active */
93 if($this->parent->fai_activated){
94 $this->AddHeader(array("string"=>_("Release"),"attach"=>"style='width:100px;'"));
95 }
97 $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
99 /* Text ,Value ,Name ,Is selected */
101 if(class_available("servtabs")){
102 $this->AddCheckBox("ShowServers",
103 msgPool::selectToView( _("servers")),
104 sprintf(_("Show %s"), _("servers")),true);
105 }
106 if(class_available("termtabs")){
107 $this->AddCheckBox("ShowTerminals",
108 msgPool::selectToView( _("Linux terminals")),
109 sprintf(_("Show %s"), _("terminals")),true);
110 }
111 if(class_available("worktabs")){
112 $this->AddCheckBox("ShowWorkstations",
113 msgPool::selectToView( _("Linux workstations")),
114 sprintf(_("Show %s"), _("workstations")),true);
115 }
116 if(class_available("wintabs")){
117 $this->AddCheckBox("ShowWinWorkstations",
118 msgPool::selectToView( _("MicroSoft Windows based workstations")),
119 sprintf(_("Show %s"), _("windows based workstations")),true);
120 }
121 /* Add opsi checkboxes if opsi is enabled */
122 if($this->parent->opsi instanceof opsi && $this->parent->opsi->enabled()){
123 $this->AddCheckBox("ShowOpsiHosts" , sprintf(_("Display objects of type '%s'."),
124 _("OPSI installed client")),_("Show OPSI based clients") ,true);
125 }
127 if(class_available("printtabs")){
128 $this->AddCheckBox("ShowPrinters",
129 msgPool::selectToView( _("network printers")),
130 sprintf(_("Show %s"), _("network printers")) ,true);
131 }
132 if(class_available("phonetabs")){
133 $this->AddCheckBox("ShowPhones",
134 msgPool::selectToView( _("VoIP phones")),
135 sprintf(_("Show %s"), _("phones")) ,true);
136 }
137 if(class_available("componenttabs")){
138 $this->AddCheckBox("ShowDevices",
139 msgPool::selectToView( _("network devices")),
140 sprintf(_("Show %s"), _("network devices")), true);
141 }
143 /* Add SubSearch checkbox */
144 $this->AddCheckBox(SEPERATOR);
145 $this->AddCheckBox("SubSearch", msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
147 /* Name ,Text ,Default , Connect with alphabet */
148 $this->AddRegex ("Regex", _("Display systems matching"),"*" , true);
149 $this->AddRegex ("UserRegex", _("Display systems of user"), "*" , false, "images/lists/search-user.png");
150 }
152 function GenHeader()
153 {
154 /* Prepare departments,
155 which are shown in the listbox on top of the listbox
156 */
157 $options= "";
159 /* Get all departments within this subtree */
160 $base = $this->config->current['BASE'];
161 $options = $this->create_department_list($this->module);
163 /* If there is at least one c (Create) and one w (Write) acl in this combination
164 display the snapshot paste icon. BUT check the correct acls in the management plugin */
165 $all_module_acls = "";
166 $ui = get_userinfo();
167 foreach($this->module as $module){
168 $all_module_acls .= $ui->has_complete_category_acls($this->selectedBase,$module);
169 }
171 /* Must we add an additional seperator */
172 $add_sep = false;
174 /* Add default header */
175 $listhead = MultiSelectWindow::get_default_header();
177 /* Add base selection */
178 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
179 " <input class='center' type='image' src='images/lists/submit.png' align='middle'
180 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
182 /* Handle create icons */
183 $s = ".|"._("Actions")."|\n";
184 $s.= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
185 " "._("Create")."|\n";
187 if(class_available("termtabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"terminal/termgeneric"))){
188 $s.= "...|<img src='plugins/systems/images/select_terminal.png' alt='' border='0' class='center'>".
189 " "._("Terminal")."|"."newsystem_terminal|\n";
190 }
191 if(class_available("worktabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"workstation/workgeneric"))){
192 $s.= "...|<img src='plugins/systems/images/select_workstation.png' alt='' border='0' class='center'>".
193 " "._("Workstation")."|"."newsystem_workstation|\n";
194 }
195 if(class_available("servtabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"server/servgeneric"))){
196 $s.= "...|<img src='plugins/systems/images/select_server.png' alt='' border='0' class='center'>".
197 " "._("Server")."|"."newsystem_server|\n";
198 }
199 if(class_available("phonetabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"phone/phoneGeneric"))){
200 $s.= "...|<img src='plugins/systems/images/select_phone.png' alt='' border='0' class='center'>".
201 " "._("Phone")."|"."newsystem_phone|\n";
202 }
203 if(class_available("printtabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"printer/printgeneric"))){
204 $s.= "...|<img src='plugins/systems/images/select_printer.png' alt='' border='0' class='center'>".
205 " "._("Printer")."|"."newsystem_printer|\n";
206 }
207 if(class_available("componenttabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"component/componentGeneric"))){
208 $s.= "...|<img src='plugins/systems/images/select_component.png' alt='' border='0' class='center'>".
209 " "._("Component")."|"."newsystem_component|\n";
210 }
212 if($this->parent->opsi instanceof opsi &&
213 $this->parent->opsi->enabled() &&
214 preg_match("/c/",$ui->get_permissions($this->selectedBase,"opsi/opsiGeneric"))){
215 $s.= "...|<img src='plugins/systems/images/select_winstation.png' alt='' border='0' class='center'>".
216 " "._("Opsi client")."|"."newsystem_opsi_client|\n";
217 }
219 if($this->parent->si_active){
220 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
222 $s.= "..|<img src='images/rocket.png' alt='' border='0' class='center'>".
223 " "._("Trigger action")."|\n";
224 foreach($events['TRIGGERED'] as $name => $event){
225 $s.= "...|".$event['MenuImage']." ".$event['s_Menu_Name']."|trigger_event_".$name."\n";
226 }
228 $s.= "..|<img src='plugins/systems/images/clock.png' alt='' border='0' class='center'>".
229 " "._("Schedule action")."|\n";
230 foreach($events['SCHEDULED'] as $name => $event){
231 $s.= "...|".$event['MenuImage']." ".$event['s_Menu_Name']."|schedule_event_".$name."\n";
232 }
233 }
235 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
236 " "._("Remove")."|"."remove_multiple|\n";
238 $s.= "..|<img src='images/lists/unlocked.png' alt='' border='0' class='center'>".
239 " "._("Activate systems")."|activate_multiple|\n";
241 /* Add Copy & Paste header */
242 $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
244 /* Add snapshot icons */
245 $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
247 $this->SetDropDownHeaderMenu($s);
248 $this->SetListHeader($listhead);
249 }
251 function execute()
252 {
253 $this->ClearElementsList();
254 $this->GenHeader();
255 }
257 function setEntries($terminals)
258 {
259 $empty ="<img src='images/empty.png' style='width:16px ; height: 16px;' class='center' alt=''>";
261 /* Dynamic action col, depending on snapshot icons */
262 $action_col_size = 120;
263 if($this->parent->snapshotEnabled()){
264 $action_col_size += 38;
265 }
267 // User and Template Images
268 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
270 /* ACL mapping */
271 $ui = get_userinfo();
272 $tabs = $this->parent->get_tab_defs();
274 $cnts = array("component" => 0 , "terminal" => 0 , "workstation" => 0 ,
275 "printer" => 0 , "phone" => 0 , "server" => 0,"opsi_client" => 0,
276 "NewDevice" => 0, "winstation"=> 0);
278 /* Get list of all objectGroups and their member and release configuration
279 */
280 $ogroups = array();
281 if($this->parent->fai_activated){
282 $ogroups = get_sub_list("(&(objectClass=gosaGroupOfNames)(FAIclass=*)(member=*))",array("ogroups"),
283 get_ou("ogroupRDN"),$this->config->current['BASE'],array("FAIclass","member","cn"),GL_NO_ACL_CHECK | GL_SUBSEARCH);
284 foreach($ogroups as $ogroup){
285 for($i = 0 ; $i < $ogroup['member']['count'] ; $i++){
286 if(preg_match("/:/",$ogroup['FAIclass'][0])) {
287 if(!isset($og_list[$ogroup['member'][$i]])){
288 $ogs_release[$ogroup['member'][$i]]['STR'] = "";
289 $ogs_release[$ogroup['member'][$i]]['CN'] = "";
290 }
291 $ogs_release[$ogroup['member'][$i]]['STR'] .= preg_replace("/^.*:/","",$ogroup['FAIclass'][0]).", ";
292 $ogs_release[$ogroup['member'][$i]]['CN'] .= $ogroup['cn'][0].", ";
293 }
294 }
295 }
296 }
298 // Test Every Entry and generate divlist Array
299 foreach($terminals as $key => $val){
301 /* Get system type, it is used to fetch the acls for the current object.
302 "winstation" acls are stored as 2winworkstation", so we have to map this here */
304 /* Map NewDevice acls to workstation acls */
305 $type = $this->parent->get_system_type($val);
306 if($type == "NewDevice" || $type == "ArpNewDevice"){
307 $type = "incoming";
308 }
309 $acl_type = $tabs[$type]['ACLC'];
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) ;
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 /* Add create FAI CD icon
358 */
359 $acl_cd = preg_match("/w/",$ui->get_permissions($val['dn'],"workstation/workgeneric","createFAICD"));
360 if(in_array("gotoWorkstation",$val['objectClass']) && $acl_cd){
361 $action2= "<input class='center' type='image' src='plugins/systems/images/cdrom.png' alt='"._("Create CD")."'
362 name='gen_cd_%KEY%' title='"._("Create FAI CD")."'> ".$action2;
363 }else{
364 $action2= $empty.$action2;
365 }
367 if(isset($val['message'])){
368 $display.= " (".$val['message'].")";
369 }
371 $img = $this->parent->convert_list($val);
373 /* Cutted objects should be displayed in light grey */
374 if($this->parent->CopyPasteHandler){
375 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
376 if($queue_data['dn'] == $val['dn']) {
377 $display = "<font color='#999999'>".$display."</font>";
378 break;
379 }
380 }
381 }
383 $type = $this->parent->get_system_type($val);
384 if($type == "ArpNewDevice"){
385 $type = "NewDevice";
386 }
387 $cnts[$type] ++;
389 /* Create each field */
390 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
391 "attach" => "style='width:20px;'");
392 $field1 = array("string" => sprintf($img['img'],$val['dn']),
393 "attach" => "style='text-align:center;width:20px;'");
394 $field2 = array("string" => sprintf($editlink,$key,$display),
395 "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
396 $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action),
397 "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
399 if($this->parent->fai_activated){
401 $release ="";
402 $release_attach = "";
403 if(isset($val['FAIclass'][0]) && preg_match("/:/",$val['FAIclass'][0])){
404 $release = preg_replace("/^.*:/","",$val['FAIclass'][0]);
405 $release_attach = "";
406 }elseif(isset($ogs_release[$val['dn']])){
407 $release = trim($ogs_release[$val['dn']]['STR'],", ").
408 " <img src='plugins/ogroups/images/select_ogroup.png' class='center' alt=''
409 title='".sprintf(_("Inherited from %s"),trim($ogs_release[$val['dn']]['CN'],", "))."'>";
410 $release_attach = "title='".sprintf(_("Inherited from %s"),trim($ogs_release[$val['dn']]['CN'],", "))."'";
411 }
412 $field2a = array("string" => $release." ","attach"=>$release_attach." style='width:100px;'");
413 $this->AddElement( array($field0,$field1,$field2,$field2a,$field3));
414 }else{
415 $this->AddElement( array($field0,$field1,$field2,$field3));
416 }
417 }
419 /* Create summary string for list footer */
420 $num_deps=0;
421 if(!$this->SubSearch){
422 $num_deps = count($this->Added_Departments);
423 }
425 $num_ser_str = sprintf(_("Number of listed '%s'"),_("servers"));
426 $num_ws_str = sprintf(_("Number of listed '%s'"),_("workstations"));
427 $num_ter_str = sprintf(_("Number of listed '%s'"),_("terminals"));
428 $num_pho_str = sprintf(_("Number of listed '%s'"),_("phones"));
429 $num_prt_str = sprintf(_("Number of listed '%s'"),_("printers"));
430 $num_com_str = sprintf(_("Number of listed '%s'"),_("network components"));
431 $num_new_str = sprintf(_("Number of listed '%s'"),_("new devices"));
432 $num_wws_str = sprintf(_("Number of listed '%s'"),_("windows workstations"));
433 $num_dep_str = sprintf(_("Number of listed '%s'"),_("departments"));
435 $str = "<img class='center' src='plugins/systems/images/select_server.png'
436 title='".$num_ser_str."' alt='".$num_ser_str."'> ".$cnts['server']." ";
437 $str.= "<img class='center' src='plugins/systems/images/select_workstation.png'
438 title='".$num_ws_str."' alt='".$num_ws_str."'> ".$cnts['workstation']." ";
439 $str.= "<img class='center' src='plugins/systems/images/select_terminal.png'
440 title='".$num_ter_str."' alt='".$num_ter_str."'> ".$cnts['terminal']." ";
441 $str.= "<img class='center' src='plugins/systems/images/select_phone.png'
442 title='".$num_pho_str."' alt='".$num_pho_str."'> ".$cnts['phone']." ";
443 $str.= "<img class='center' src='plugins/systems/images/select_printer.png'
444 title='".$num_prt_str."' alt='".$num_prt_str."'> ".$cnts['printer']." ";
445 $str.= "<img class='center' src='plugins/systems/images/select_component.png'
446 title='".$num_com_str."' alt='".$num_com_str."'> ".$cnts['component']." ";
447 $str.= "<img class='center' src='plugins/systems/images/select_newsystem.png'
448 title='".$num_new_str."' alt='".$num_new_str."'> ".$cnts['NewDevice']." ";
449 $str.= "<img class='center' src='plugins/systems/images/select_winstation.png'
450 title='".$num_wws_str."' alt='".$num_wws_str."'> ".$cnts['winstation']." ";
451 $str.= "<img class='center' src='images/lists/folder.png'
452 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
454 $this->set_List_Bottom_Info($str);
455 }
458 function Save()
459 {
460 MultiSelectWindow :: Save();
461 }
464 function save_object()
465 {
466 /* Save automatic created POSTs like regex, checkboxes */
467 MultiSelectWindow :: save_object();
470 }
471 }
472 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
473 ?>