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"=>" ","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;
165 /* Add default header */
166 $listhead = MultiSelectWindow::get_default_header();
168 /* Add base selection */
169 $listhead .= _("Base")." <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")."'> ";
173 /* Handle create icons */
174 $s = ".|"._("Actions")."|\n";
175 $s.= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
176 " "._("Create")."|\n";
178 if(class_available("termtabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"terminal/termgeneric"))){
179 $s.= "...|<img src='plugins/systems/images/select_terminal.png' alt='' border='0' class='center'>".
180 " "._("Terminal")."|"."newsystem_terminal|\n";
181 }
182 if(class_available("worktabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"workstation/workgeneric"))){
183 $s.= "...|<img src='plugins/systems/images/select_workstation.png' alt='' border='0' class='center'>".
184 " "._("Workstation")."|"."newsystem_workstation|\n";
185 }
186 if(class_available("servtabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"workstation/servgeneric"))){
187 $s.= "...|<img src='plugins/systems/images/select_server.png' alt='' border='0' class='center'>".
188 " "._("Server")."|"."newsystem_server|\n";
189 }
190 if(class_available("phonetabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"phone/phoneGeneric"))){
191 $s.= "...|<img src='plugins/systems/images/select_phone.png' alt='' border='0' class='center'>".
192 " "._("Phone")."|"."newsystem_phone|\n";
193 }
194 if(class_available("printtabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"printer/printgeneric"))){
195 $s.= "...|<img src='plugins/systems/images/select_printer.png' alt='' border='0' class='center'>".
196 " "._("Printer")."|"."newsystem_printer|\n";
197 }
198 if(class_available("componenttabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"component/componentGeneric"))){
199 $s.= "...|<img src='plugins/systems/images/select_component.png' alt='' border='0' class='center'>".
200 " "._("Component")."|"."newsystem_component|\n";
201 }
202 if(class_available("opsigeneric") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"opsi/opsigeneric"))){
203 $s.= "...|<img src='plugins/systems/images/select_component.png' alt='' border='0' class='center'>".
204 " "._("Opsi")."|"."newsystem_opsi_client|\n";
205 }
207 if($this->parent->si_active){
208 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
210 $s.= "..|<img src='images/rocket.png' alt='' border='0' class='center'>".
211 " "._("Trigger action")."|\n";
212 foreach($events['TRIGGERED'] as $name => $event){
213 $s.= "...|".$event['MenuImage']." ".$event['s_Menu_Name']."|trigger_event_".$name."\n";
214 }
216 $s.= "..|<img src='plugins/systems/images/clock.png' alt='' border='0' class='center'>".
217 " "._("Schedule action")."|\n";
218 foreach($events['SCHEDULED'] as $name => $event){
219 $s.= "...|".$event['MenuImage']." ".$event['s_Menu_Name']."|schedule_event_".$name."\n";
220 }
221 }
223 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
224 " "._("Remove")."|"."remove_multiple|\n";
226 $s.= "..|<img src='images/lists/unlocked.png' alt='' border='0' class='center'>".
227 " "._("Activate systems")."|activate_multiple|\n";
229 /* Add Copy & Paste header */
230 $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
232 /* Add snapshot icons */
233 $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
235 $this->SetDropDownHeaderMenu($s);
236 $this->SetListHeader($listhead);
237 }
239 function execute()
240 {
241 $this->ClearElementsList();
242 $this->GenHeader();
243 }
245 function setEntries($terminals)
246 {
247 $empty ="<img src='images/empty.png' style='width:16px ; height: 16px;' class='center' alt=''>";
249 /* Dynamic action col, depending on snapshot icons */
250 $action_col_size = 120;
251 if($this->parent->snapshotEnabled()){
252 $action_col_size += 38;
253 }
255 // User and Template Images
256 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
258 /* ACL mapping */
259 $ui = get_userinfo();
260 $tabs = $this->parent->get_tab_defs();
262 $cnts = array("component" => 0 , "terminal" => 0 , "workstation" => 0 ,
263 "printer" => 0 , "phone" => 0 , "server" => 0,"opsi_client" => 0,
264 "NewDevice" => 0, "winstation"=> 0);
266 /* Get list of all objectGroups and their member and release configuration
267 */
268 $ogroups = array();
269 if($this->parent->fai_activated){
270 $ogroups = get_sub_list("(&(objectClass=gosaGroupOfNames)(FAIclass=*)(member=*))",array("ogroups"),
271 get_ou("ogroupou"),$this->config->current['BASE'],array("FAIclass","member","cn"),GL_NO_ACL_CHECK | GL_SUBSEARCH);
272 foreach($ogroups as $ogroup){
273 for($i = 0 ; $i < $ogroup['member']['count'] ; $i++){
274 if(preg_match("/:/",$ogroup['FAIclass'][0])) {
275 if(!isset($og_list[$ogroup['member'][$i]])){
276 $ogs_release[$ogroup['member'][$i]]['STR'] = "";
277 $ogs_release[$ogroup['member'][$i]]['CN'] = "";
278 }
279 $ogs_release[$ogroup['member'][$i]]['STR'] .= preg_replace("/^.*:/","",$ogroup['FAIclass'][0]).", ";
280 $ogs_release[$ogroup['member'][$i]]['CN'] .= $ogroup['cn'][0].", ";
281 }
282 }
283 }
284 }
286 // Test Every Entry and generate divlist Array
287 foreach($terminals as $key => $val){
289 /* Get system type, it is used to fetch the acls for the current object.
290 "winstation" acls are stored as 2winworkstation", so we have to map this here */
292 /* Map NewDevice acls to workstation acls */
293 $type = $this->parent->get_system_type($val);
294 if($type == "NewDevice" || $type == "ArpNewDevice"){
295 $type = "incoming";
296 }
297 $acl_type = $tabs[$type]['ACLC'];
298 $s_acl = $tabs[$type]['ACL'];
299 $category = preg_replace("/\/.*$/","",$s_acl);
300 $class = preg_replace("/^.*\//","",$s_acl);
302 /* Get complete category acls */
303 $acl_all = $ui->has_complete_category_acls($val['dn'],$acl_type) ;
305 /* Get specific generic acls */
306 $acl = $ui->get_permissions($val['dn'],$tabs[$type]['ACL']);
308 /* Add copy & cut functionality */
309 $action= $this->parent->get_copypaste_action($val['dn'],$category,$class);
311 $action.= "<input class='center' type='image' src='images/lists/edit.png'
312 alt='"._("edit")."' name='system_edit_%KEY%' title='"._("Edit system")."'>";
314 $action.= $this->parent->get_snapshot_action($val['dn'],$acl_type);
316 if(preg_match("/d/",$acl)){
317 $action.= "<input class='center' type='image' src='images/lists/trash.png'
318 alt='"._("delete")."' name='system_del_%KEY%' title='"._("Delete system")."'>";
319 }else{
320 $action.= $empty;
321 }
323 $val['cn'][0]= preg_replace('/\$$/', '', $val['cn'][0]);
325 // Generate Array to Add
326 $dsc= "";
327 if (isset($val['description'][0])){
328 $dsc= " [".$val['description'][0]."]";
329 }
330 if((isset($val['is_new']))&&(!empty($val['is_new']))){
331 $display= $val["cn"][0]." ".$val['is_new'].$dsc;
332 }else{
333 $display= $val["cn"][0].$dsc;
334 }
336 /* Check if this is a terminal/workstation && if we are allowed to change the gotoRootPasswd */
337 $display_key_for = array("terminal","workstation","server","component");
338 $pwd_acl = $ui->get_permissions($val['dn'],$tabs[$type]['ACL'],"userPassword");
339 if(preg_match("/w/",$pwd_acl) && in_array($type,$display_key_for)){
340 $action2 = "<input class='center' type='image' src='images/lists/key.png' alt='"._("Password")."' name='system_setpwd_%KEY%' title='"._("Set password")."'>";
341 }else{
342 $action2 = $empty;
343 }
345 if(in_array("gotoWorkstation",$val['objectClass'])){
346 $action2= "<input class='center' type='image' src='plugins/systems/images/cdrom.png' alt='"._("Create CD")."'
347 name='gen_cd_%KEY%' title='"._("Create FAI CD")."'> ".$action2;
348 }else{
349 $action2= $empty.$action2;
350 }
352 if(isset($val['message'])){
353 $display.= " (".$val['message'].")";
354 }
356 $img = $this->parent->convert_list($val);
358 /* Cutted objects should be displayed in light grey */
359 if($this->parent->CopyPasteHandler){
360 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
361 if($queue_data['dn'] == $val['dn']) {
362 $display = "<font color='#999999'>".$display."</font>";
363 break;
364 }
365 }
366 }
368 $type = $this->parent->get_system_type($val);
369 if($type == "ArpNewDevice"){
370 $type = "NewDevice";
371 }
372 $cnts[$type] ++;
374 /* Create each field */
375 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
376 "attach" => "style='width:20px;'");
377 $field1 = array("string" => sprintf($img['img'],$val['dn']),
378 "attach" => "style='text-align:center;width:20px;'");
379 $field2 = array("string" => sprintf($editlink,$key,$display),
380 "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
381 $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action),
382 "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
384 if($this->parent->fai_activated){
386 $release =" ";
387 $release_attach = "";
388 if(isset($val['FAIclass'][0]) && preg_match("/:/",$val['FAIclass'][0])){
389 $release = preg_replace("/^.*:/","",$val['FAIclass'][0]);
390 $release_attach = "";
391 }elseif(isset($ogs_release[$val['dn']])){
392 $release = trim($ogs_release[$val['dn']]['STR'],", ").
393 " <img src='plugins/ogroups/images/select_ogroup.png' class='center' alt=''
394 title='".sprintf(_("Inherited from %s"),trim($ogs_release[$val['dn']]['CN'],", "))."'>";
395 $release_attach = "title='".sprintf(_("Inherited from %s"),trim($ogs_release[$val['dn']]['CN'],", "))."'";
396 }
397 $field2a = array("string" => $release,"attach"=>$release_attach." style='width:100px;'");
398 $this->AddElement( array($field0,$field1,$field2,$field2a,$field3));
399 }else{
400 $this->AddElement( array($field0,$field1,$field2,$field3));
401 }
402 }
404 /* Create summary string for list footer */
405 $num_deps=0;
406 if(!$this->SubSearch){
407 $num_deps = count($this->Added_Departments);
408 }
410 $num_ser_str = sprintf(_("Number of listed '%s'"),_("servers"));
411 $num_ws_str = sprintf(_("Number of listed '%s'"),_("workstations"));
412 $num_ter_str = sprintf(_("Number of listed '%s'"),_("terminals"));
413 $num_pho_str = sprintf(_("Number of listed '%s'"),_("phones"));
414 $num_prt_str = sprintf(_("Number of listed '%s'"),_("printers"));
415 $num_com_str = sprintf(_("Number of listed '%s'"),_("network components"));
416 $num_new_str = sprintf(_("Number of listed '%s'"),_("new devices"));
417 $num_wws_str = sprintf(_("Number of listed '%s'"),_("windows workstations"));
418 $num_dep_str = sprintf(_("Number of listed '%s'"),_("departments"));
420 $str = "<img class='center' src='plugins/systems/images/select_server.png'
421 title='".$num_ser_str."' alt='".$num_ser_str."'> ".$cnts['server']." ";
422 $str.= "<img class='center' src='plugins/systems/images/select_workstation.png'
423 title='".$num_ws_str."' alt='".$num_ws_str."'> ".$cnts['workstation']." ";
424 $str.= "<img class='center' src='plugins/systems/images/select_terminal.png'
425 title='".$num_ter_str."' alt='".$num_ter_str."'> ".$cnts['terminal']." ";
426 $str.= "<img class='center' src='plugins/systems/images/select_phone.png'
427 title='".$num_pho_str."' alt='".$num_pho_str."'> ".$cnts['phone']." ";
428 $str.= "<img class='center' src='plugins/systems/images/select_printer.png'
429 title='".$num_prt_str."' alt='".$num_prt_str."'> ".$cnts['printer']." ";
430 $str.= "<img class='center' src='plugins/systems/images/select_component.png'
431 title='".$num_com_str."' alt='".$num_com_str."'> ".$cnts['component']." ";
432 $str.= "<img class='center' src='plugins/systems/images/select_newsystem.png'
433 title='".$num_new_str."' alt='".$num_new_str."'> ".$cnts['NewDevice']." ";
434 $str.= "<img class='center' src='plugins/systems/images/select_winstation.png'
435 title='".$num_wws_str."' alt='".$num_wws_str."'> ".$cnts['winstation']." ";
436 $str.= "<img class='center' src='images/lists/folder.png'
437 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
439 $this->set_List_Bottom_Info($str);
440 }
443 function Save()
444 {
445 MultiSelectWindow :: Save();
446 }
449 function save_object()
450 {
451 /* Save automatic created POSTs like regex, checkboxes */
452 MultiSelectWindow :: save_object();
455 }
456 }
457 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
458 ?>