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 */
97 $this->AddCheckBox("ShowServers",
98 msgPool::selectToView( _("servers")),
99 sprintf(_("Show %s"), _("servers")),true);
100 $this->AddCheckBox("ShowTerminals",
101 msgPool::selectToView( _("Linux terminals")),
102 sprintf(_("Show %s"), _("terminals")),true);
103 $this->AddCheckBox("ShowWorkstations",
104 msgPool::selectToView( _("Linux workstations")),
105 sprintf(_("Show %s"), _("workstations")),true);
106 $this->AddCheckBox("ShowWinWorkstations",
107 msgPool::selectToView( _("MicroSoft Windows based workstations")),
108 sprintf(_("Show %s"), _("windows based workstations")),true);
109 $this->AddCheckBox("ShowPrinters",
110 msgPool::selectToView( _("network printers")),
111 sprintf(_("Show %s"), _("network printers")) ,true);
112 $this->AddCheckBox("ShowPhones",
113 msgPool::selectToView( _("VoIP phones")),
114 sprintf(_("Show %s"), _("phones")) ,true);
115 $this->AddCheckBox("ShowDevices",
116 msgPool::selectToView( _("network devices")),
117 sprintf(_("Show %s"), _("network devices")), true);
119 /* Add SubSearch checkbox */
120 $this->AddCheckBox(SEPERATOR);
121 $this->AddCheckBox("SubSearch", msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
123 /* Name ,Text ,Default , Connect with alphabet */
124 $this->AddRegex ("Regex", _("Display systems matching"),"*" , true);
125 $this->AddRegex ("UserRegex", _("Display systems of user"), "*" , false, "images/lists/search-user.png");
126 }
128 function GenHeader()
129 {
130 /* Prepare departments,
131 which are shown in the listbox on top of the listbox
132 */
133 $options= "";
135 /* Get all departments within this subtree */
136 $base = $this->config->current['BASE'];
137 $options = $this->create_department_list($this->module);
139 /* If there is at least one c (Create) and one w (Write) acl in this combination
140 display the snapshot paste icon. BUT check the correct acls in the management plugin */
141 $all_module_acls = "";
142 $ui = get_userinfo();
143 foreach($this->module as $module){
144 $all_module_acls .= $ui->has_complete_category_acls($this->selectedBase,$module);
145 }
147 /* Must we add an additional seperator */
148 $add_sep = false;
150 /* Add default header */
151 $listhead = MultiSelectWindow::get_default_header();
153 /* Add base selection */
154 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
155 " <input class='center' type='image' src='images/lists/submit.png' align='middle'
156 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
158 /* Handle create icons */
159 $s = ".|"._("Actions")."|\n";
160 $s.= "..|<img src='images/lists/new.png' alt='' border='0' class='center'>".
161 " "._("Create")."|\n";
163 if(class_available("termtabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"terminal/termgeneric"))){
164 $s.= "...|<img src='images/select_terminal.png' alt='' border='0' class='center'>".
165 " "._("Terminal")."|"."newsystem_terminal|\n";
166 }
167 if(class_available("worktabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"workstation/workgeneric"))){
168 $s.= "...|<img src='images/select_workstation.png' alt='' border='0' class='center'>".
169 " "._("Workstation")."|"."newsystem_workstation|\n";
170 }
171 if(class_available("servtabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"workstation/servgeneric"))){
172 $s.= "...|<img src='images/select_server.png' alt='' border='0' class='center'>".
173 " "._("Server")."|"."newsystem_server|\n";
174 }
175 if(class_available("phonetabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"phone/phoneGeneric"))){
176 $s.= "...|<img src='images/select_phone.png' alt='' border='0' class='center'>".
177 " "._("Phone")."|"."newsystem_phone|\n";
178 }
179 if(class_available("printtabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"printer/printgeneric"))){
180 $s.= "...|<img src='images/select_printer.png' alt='' border='0' class='center'>".
181 " "._("Printer")."|"."newsystem_printer|\n";
182 }
183 if(class_available("componenttabs") && preg_match("/c/",$ui->get_permissions($this->selectedBase,"component/componentGeneric"))){
184 $s.= "...|<img src='images/select_component.png' alt='' border='0' class='center'>".
185 " "._("Component")."|"."newsystem_component|\n";
186 }
188 if($this->parent->si_active){
189 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
191 $s.= "..|<img src='images/rocket.png' alt='' border='0' class='center'>".
192 " "._("Trigger action")."|\n";
193 foreach($events['TRIGGERED'] as $name => $event){
194 $s.= "...|".$event['MenuImage']." ".$event['s_Menu_Name']."|trigger_event_".$name."\n";
195 }
197 $s.= "..|<img src='images/clock.png' alt='' border='0' class='center'>".
198 " "._("Schedule action")."|\n";
199 foreach($events['SCHEDULED'] as $name => $event){
200 $s.= "...|".$event['MenuImage']." ".$event['s_Menu_Name']."|schedule_event_".$name."\n";
201 }
202 }
204 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
205 " "._("Remove")."|"."remove_multiple|\n";
207 $s.= "..|<img src='images/lists/unlocked.png' alt='' border='0' class='center'>".
208 " "._("Activate systems")."|activate_multiple|\n";
210 /* Add Copy & Paste header */
211 $s .= $this->parent->get_copypaste_header($this->selectedBase,$this->module);
213 /* Add snapshot icons */
214 $s .= $this->parent->get_snapshot_header($this->selectedBase,$this->module);
216 $this->SetDropDownHeaderMenu($s);
217 $this->SetListHeader($listhead);
218 }
220 function execute()
221 {
222 $this->ClearElementsList();
223 $this->GenHeader();
224 }
226 function setEntries($terminals)
227 {
228 $img1 = "<img class='center' src='images/printer.png' alt='C' title='"._("Cups Server") ."'>";
229 $img2 = "<img class='center' src='images/scanner.png' alt='L' title='"._("Log Db") ."'>";
230 $img3 = "<img class='center' src='images/select_terminal.png' alt='L' title='"._("Syslog Server") ."'>";
231 $img4 = "<img class='center' src='images/mailto.png' alt='M' title='"._("Mail Server") ."'>";
232 $img5 = "<img class='center' src='images/select_phone.png' alt='I' title='"._("Imap Server") ."'>";
233 $img6 = "<img class='center' src='images/fax_small.png' alt='F' title='"._("Nfs Server") ."'>";
234 $img7 = "<img class='center' src='images/select_winstation.png' alt='K' title='"._("Kerberos Server") ."'>";
235 $img8 = "<img class='center' src='images/select_phone.png' alt='A' title='"._("Asterisk Server") ."'>";
236 $img9 = "<img class='center' src='images/fax_small.png' alt='F' title='"._("Fax Server") ."'>";
237 $img10 = "<img class='center' src='images/save.png' alt='L' title='"._("Ldap Server") ."'>";
239 $empty ="<img src='images/empty.png' style='width:16px ; height: 16px;' class='center' alt=''>";
241 /* Dynamic action col, depending on snapshot icons */
242 $action_col_size = 120;
243 if($this->parent->snapshotEnabled()){
244 $action_col_size += 38;
245 }
247 // User and Template Images
248 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
250 /* ACL mapping */
251 $ui = get_userinfo();
252 $tabs = array(
253 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
254 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
255 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
256 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
257 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
258 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
259 "incoming" => array("CLASS"=>"", "TABCLASS" =>"", "ACL"=> "incoming/systems"),
260 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
263 $cnts = array("component" => 0 , "terminal" => 0 , "workstation" => 0 ,
264 "printer" => 0 , "phone" => 0 , "server" => 0,
265 "NewDevice" => 0, "winstation"=> 0);
268 /* Get list of all objectGroups and their member and release configuration
269 */
270 $ogroups = array();
271 if($this->parent->fai_activated){
272 $ogroups = get_sub_list("(&(objectClass=gosaGroupOfNames)(FAIclass=*)(member=*))",array("ogroups"),
273 get_ou("ogroupou"),$this->config->current['BASE'],array("FAIclass","member","cn"),GL_NO_ACL_CHECK | GL_SUBSEARCH);
274 foreach($ogroups as $ogroup){
275 for($i = 0 ; $i < $ogroup['member']['count'] ; $i++){
276 if(preg_match("/:/",$ogroup['FAIclass'][0])) {
277 if(!isset($og_list[$ogroup['member'][$i]])){
278 $ogs_release[$ogroup['member'][$i]]['STR'] = "";
279 $ogs_release[$ogroup['member'][$i]]['CN'] = "";
280 }
281 $ogs_release[$ogroup['member'][$i]]['STR'] .= preg_replace("/^.*:/","",$ogroup['FAIclass'][0]).", ";
282 $ogs_release[$ogroup['member'][$i]]['CN'] .= $ogroup['cn'][0].", ";
283 }
284 }
285 }
286 }
288 // Test Every Entry and generate divlist Array
289 foreach($terminals as $key => $val){
291 /* Get system type, it is used to fetch the acls for the current object.
292 "winstation" acls are stored as 2winworkstation", so we have to map this here */
293 $type = $this->parent->get_system_type($val);
294 if($type == "winstation") {
295 $acl_type = "winworkstation";
296 }else{
297 $acl_type = $type;
298 }
300 /* Map NewDevice acls to workstation acls */
301 if($type == "NewDevice" || $type == "ArpNewDevice"){
302 $type = "incoming";
303 $acl_type = "incoming";
304 }
306 $s_acl = $tabs[$type]['ACL'];
307 $category = preg_replace("/\/.*$/","",$s_acl);
308 $class = preg_replace("/^.*\//","",$s_acl);
310 /* Get complete category acls */
311 $acl_all = $ui->has_complete_category_acls($val['dn'],$acl_type) ;
313 /* Get specific generic acls */
314 $acl = $ui->get_permissions($val['dn'],$tabs[$type]['ACL']);
316 /* Add copy & cut functionality */
317 $action= $this->parent->get_copypaste_action($val['dn'],$category,$class);
319 $action.= "<input class='center' type='image' src='images/lists/edit.png'
320 alt='"._("edit")."' name='system_edit_%KEY%' title='"._("Edit system")."'>";
322 $action.= $this->parent->get_snapshot_action($val['dn'],$acl_type);
324 if(preg_match("/d/",$acl)){
325 $action.= "<input class='center' type='image' src='images/lists/trash.png'
326 alt='"._("delete")."' name='system_del_%KEY%' title='"._("Delete system")."'>";
327 }else{
328 $action.= $empty;
329 }
332 /* Generate picture list, which is currently disabled */
333 if(in_array("goCupsServer" ,$val['objectClass'])) $cups = $img1; else $cups =$empty;
334 if(in_array("goLogDBServer" ,$val['objectClass'])) $logdb = $img2; else $logdb =$empty;
335 if(in_array("goSyslogServer" ,$val['objectClass'])) $syslog = $img3; else $syslog=$empty;
336 if(in_array("goImapServer" ,$val['objectClass'])) $imap = $img4; else $imap =$empty;
337 if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = $img5; else $samba =$empty;
338 if(in_array("goShareServer" ,$val['objectClass'])) $nfs = $img6; else $nfs =$empty;
339 if(in_array("goKrbServer" ,$val['objectClass'])) $krb = $img7; else $krb =$empty;
340 if(in_array("goFonServer" ,$val['objectClass'])) $fon = $img8; else $fon =$empty;
341 if(in_array("goFaxServer" ,$val['objectClass'])) $fax = $img9; else $fax =$empty;
342 if(in_array("goLdapServer" ,$val['objectClass'])) $ldap = $img10; else $ldap =$empty;
344 $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
345 $pics = ""; // Pictures currently hidden
347 $val['cn'][0]= preg_replace('/\$$/', '', $val['cn'][0]);
349 // Generate Array to Add
350 $dsc= "";
351 if (isset($val['description'][0])){
352 $dsc= " [".$val['description'][0]."]";
353 }
354 if((isset($val['is_new']))&&(!empty($val['is_new']))){
355 $display= $val["cn"][0]." ".$val['is_new'].$dsc;
356 }else{
357 $display= $val["cn"][0].$dsc;
358 }
360 /* Check if this is a terminal/workstation && if we are allowed to change the gotoRootPasswd */
361 $display_key_for = array("terminal","workstation","server","component");
362 $pwd_acl = $ui->get_permissions($val['dn'],$tabs[$type]['ACL'],"userPassword");
363 if(preg_match("/w/",$pwd_acl) && in_array($type,$display_key_for)){
364 $action2 = "<input class='center' type='image' src='images/lists/key.png' alt='"._("Password")."' name='system_setpwd_%KEY%' title='"._("Set password")."'>";
365 }else{
366 $action2 = $empty;
367 }
369 if(in_array("gotoWorkstation",$val['objectClass'])){
370 $action2= "<input class='center' type='image' src='images/cdrom.png' alt='"._("Create CD")."'
371 name='gen_cd_%KEY%' title='"._("Create FAI CD")."'> ".$action2;
372 }else{
373 $action2= $empty.$action2;
374 }
376 if(isset($val['message'])){
377 $display.= " (".$val['message'].")";
378 }
380 $img = $this->parent->convert_list($val);
382 /* Cutted objects should be displayed in light grey */
383 if($this->parent->CopyPasteHandler){
384 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
385 if($queue_data['dn'] == $val['dn']) {
386 $display = "<font color='#999999'>".$display."</font>";
387 break;
388 }
389 }
390 }
392 $type = $this->parent->get_system_type($val);
393 if($type == "ArpNewDevice"){
394 $type = "NewDevice";
395 }
396 $cnts[$type] ++;
398 /* Create each field */
399 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
400 "attach" => "style='width:20px;'");
401 $field1 = array("string" => sprintf($img['img'],$val['dn']),
402 "attach" => "style='text-align:center;width:20px;'");
403 $field2 = array("string" => sprintf($editlink,$key,$display),
404 "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
405 $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action),
406 "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
408 if($this->parent->fai_activated){
410 $release =" ";
411 $release_attach = "";
412 if(isset($val['FAIclass'][0]) && preg_match("/:/",$val['FAIclass'][0])){
413 $release = preg_replace("/^.*:/","",$val['FAIclass'][0]);
414 $release_attach = "";
415 }elseif(isset($ogs_release[$val['dn']])){
416 $release = trim($ogs_release[$val['dn']]['STR'],", ").
417 " <img src='images/select_ogroup.png' class='center' alt=''
418 title='".sprintf(_("Inherited from %s"),trim($ogs_release[$val['dn']]['CN'],", "))."'>";
419 $release_attach = "title='".sprintf(_("Inherited from %s"),trim($ogs_release[$val['dn']]['CN'],", "))."'";
420 }
421 $field2a = array("string" => $release,"attach"=>$release_attach." style='width:100px;'");
422 $this->AddElement( array($field0,$field1,$field2,$field2a,$field3));
423 }else{
424 $this->AddElement( array($field0,$field1,$field2,$field3));
425 }
426 }
428 /* Create summary string for list footer */
429 $num_deps=0;
430 if(!$this->SubSearch){
431 $num_deps = count($this->Added_Departments);
432 }
434 $num_ser_str = sprintf(_("Number of listed '%s'"),_("servers"));
435 $num_ws_str = sprintf(_("Number of listed '%s'"),_("workstations"));
436 $num_ter_str = sprintf(_("Number of listed '%s'"),_("terminals"));
437 $num_pho_str = sprintf(_("Number of listed '%s'"),_("phones"));
438 $num_prt_str = sprintf(_("Number of listed '%s'"),_("printers"));
439 $num_com_str = sprintf(_("Number of listed '%s'"),_("network components"));
440 $num_new_str = sprintf(_("Number of listed '%s'"),_("new devices"));
441 $num_wws_str = sprintf(_("Number of listed '%s'"),_("windows workstations"));
442 $num_dep_str = sprintf(_("Number of listed '%s'"),_("departments"));
444 $str = "<img class='center' src='images/select_server.png'
445 title='".$num_ser_str."' alt='".$num_ser_str."'> ".$cnts['server']." ";
446 $str.= "<img class='center' src='images/select_workstation.png'
447 title='".$num_ws_str."' alt='".$num_ws_str."'> ".$cnts['workstation']." ";
448 $str.= "<img class='center' src='images/select_terminal.png'
449 title='".$num_ter_str."' alt='".$num_ter_str."'> ".$cnts['terminal']." ";
450 $str.= "<img class='center' src='images/select_phone.png'
451 title='".$num_pho_str."' alt='".$num_pho_str."'> ".$cnts['phone']." ";
452 $str.= "<img class='center' src='images/select_printer.png'
453 title='".$num_prt_str."' alt='".$num_prt_str."'> ".$cnts['printer']." ";
454 $str.= "<img class='center' src='images/select_component.png'
455 title='".$num_com_str."' alt='".$num_com_str."'> ".$cnts['component']." ";
456 $str.= "<img class='center' src='images/select_newsystem.png'
457 title='".$num_new_str."' alt='".$num_new_str."'> ".$cnts['NewDevice']." ";
458 $str.= "<img class='center' src='images/select_winstation.png'
459 title='".$num_wws_str."' alt='".$num_wws_str."'> ".$cnts['winstation']." ";
460 $str.= "<img class='center' src='images/lists/folder.png'
461 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
463 $this->set_List_Bottom_Info($str);
464 }
467 function Save()
468 {
469 MultiSelectWindow :: Save();
470 }
473 function save_object()
474 {
475 /* Save automatic created POSTs like regex, checkboxes */
476 MultiSelectWindow :: save_object();
479 }
480 }
481 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
482 ?>