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"=>" ","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;
172 /* Add default header */
173 $listhead = MultiSelectWindow::get_default_header();
175 /* Add base selection */
176 $listhead .= _("Base")." <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")."'> ";
180 /* Handle create icons */
181 $s = ".|"._("Actions")."|\n";
182 $s.= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
183 " "._("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 " "._("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 " "._("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 " "._("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 " "._("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 " "._("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 " "._("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 " "._("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 " "._("Trigger action")."|\n";
222 foreach($events['TRIGGERED'] as $name => $event){
223 $s.= "...|".$event['MenuImage']." ".$event['s_Menu_Name']."|trigger_event_".$name."\n";
224 }
226 $s.= "..|<img src='plugins/systems/images/clock.png' alt='' border='0' class='center'>".
227 " "._("Schedule action")."|\n";
228 foreach($events['SCHEDULED'] as $name => $event){
229 $s.= "...|".$event['MenuImage']." ".$event['s_Menu_Name']."|schedule_event_".$name."\n";
230 }
231 }
233 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
234 " "._("Remove")."|"."remove_multiple|\n";
236 $s.= "..|<img src='images/lists/unlocked.png' alt='' border='0' class='center'>".
237 " "._("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']."&id=%s&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) ;
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")."'> ".$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 $field2 = array("string" => sprintf($editlink,$key,$display),
393 "attach" => "style='' title='".preg_replace('/ /', ' ', LDAP::fix($val['dn']))."'");
394 $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action),
395 "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
397 if($this->parent->fai_activated){
399 $release ="";
400 $release_attach = "";
401 if(isset($val['FAIclass'][0]) && preg_match("/:/",$val['FAIclass'][0])){
402 $release = preg_replace("/^.*:/","",$val['FAIclass'][0]);
403 $release_attach = "";
404 }elseif(isset($ogs_release[$val['dn']])){
405 $release = trim($ogs_release[$val['dn']]['STR'],", ").
406 " <img src='plugins/ogroups/images/select_ogroup.png' class='center' alt=''
407 title='".sprintf(_("Inherited from %s"),trim($ogs_release[$val['dn']]['CN'],", "))."'>";
408 $release_attach = "title='".sprintf(_("Inherited from %s"),trim($ogs_release[$val['dn']]['CN'],", "))."'";
409 }
410 $field2a = array("string" => $release." ","attach"=>$release_attach." style='width:100px;'");
411 $this->AddElement( array($field0,$field1,$field2,$field2a,$field3));
412 }else{
413 $this->AddElement( array($field0,$field1,$field2,$field3));
414 }
415 }
417 /* Create summary string for list footer */
418 $num_deps=0;
419 if(!$this->SubSearch){
420 $num_deps = count($this->Added_Departments);
421 }
423 $num_ser_str = sprintf(_("Number of listed '%s'"),_("servers"));
424 $num_ws_str = sprintf(_("Number of listed '%s'"),_("workstations"));
425 $num_ter_str = sprintf(_("Number of listed '%s'"),_("terminals"));
426 $num_pho_str = sprintf(_("Number of listed '%s'"),_("phones"));
427 $num_prt_str = sprintf(_("Number of listed '%s'"),_("printers"));
428 $num_com_str = sprintf(_("Number of listed '%s'"),_("network components"));
429 $num_new_str = sprintf(_("Number of listed '%s'"),_("new devices"));
430 $num_wws_str = sprintf(_("Number of listed '%s'"),_("windows workstations"));
431 $num_dep_str = sprintf(_("Number of listed '%s'"),_("departments"));
433 $str = "<img class='center' src='plugins/systems/images/select_server.png'
434 title='".$num_ser_str."' alt='".$num_ser_str."'> ".$cnts['server']." ";
435 $str.= "<img class='center' src='plugins/systems/images/select_workstation.png'
436 title='".$num_ws_str."' alt='".$num_ws_str."'> ".$cnts['workstation']." ";
437 $str.= "<img class='center' src='plugins/systems/images/select_terminal.png'
438 title='".$num_ter_str."' alt='".$num_ter_str."'> ".$cnts['terminal']." ";
439 $str.= "<img class='center' src='plugins/systems/images/select_phone.png'
440 title='".$num_pho_str."' alt='".$num_pho_str."'> ".$cnts['phone']." ";
441 $str.= "<img class='center' src='plugins/systems/images/select_printer.png'
442 title='".$num_prt_str."' alt='".$num_prt_str."'> ".$cnts['printer']." ";
443 $str.= "<img class='center' src='plugins/systems/images/select_component.png'
444 title='".$num_com_str."' alt='".$num_com_str."'> ".$cnts['component']." ";
445 $str.= "<img class='center' src='plugins/systems/images/select_newsystem.png'
446 title='".$num_new_str."' alt='".$num_new_str."'> ".$cnts['NewDevice']." ";
447 $str.= "<img class='center' src='plugins/systems/images/select_winstation.png'
448 title='".$num_wws_str."' alt='".$num_wws_str."'> ".($cnts['winstation'] + $cnts['opsi_client'])." ";
449 $str.= "<img class='center' src='images/lists/folder.png'
450 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
452 $this->set_List_Bottom_Info($str);
453 }
456 function Save()
457 {
458 MultiSelectWindow :: Save();
459 }
462 function save_object()
463 {
464 /* Save automatic created POSTs like regex, checkboxes */
465 MultiSelectWindow :: save_object();
468 }
469 }
470 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
471 ?>