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 = 110;
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'
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")));
88 $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
90 /* Text ,Value ,Name ,Is selected */
91 $this->AddCheckBox("ShowServers",
92 msgPool::selectToView( _("servers")),
93 sprintf(_("Show %s"), _("servers")),true);
94 $this->AddCheckBox("ShowTerminals",
95 msgPool::selectToView( _("Linux terminals")),
96 sprintf(_("Show %s"), _("terminals")),true);
97 $this->AddCheckBox("ShowWorkstations",
98 msgPool::selectToView( _("Linux workstations")),
99 sprintf(_("Show %s"), _("workstations")),true);
100 $this->AddCheckBox("ShowWinWorkstations",
101 msgPool::selectToView( _("MicroSoft Windows based workstations")),
102 sprintf(_("Show %s"), _("windows based workstations")),true);
103 $this->AddCheckBox("ShowPrinters",
104 msgPool::selectToView( _("network printers")),
105 sprintf(_("Show %s"), _("network printers")) ,true);
106 $this->AddCheckBox("ShowPhones",
107 msgPool::selectToView( _("VoIP phones")),
108 sprintf(_("Show %s"), _("phones")) ,true);
109 $this->AddCheckBox("ShowDevices",
110 msgPool::selectToView( _("network devices")),
111 sprintf(_("Show %s"), _("network devices")), true);
113 /* Add SubSearch checkbox */
114 $this->AddCheckBox(SEPERATOR);
115 $this->AddCheckBox("SubSearch", msgPool::selectToView("","subsearch"), msgPool::selectToView("","subsearch_small"), false);
117 /* Name ,Text ,Default , Connect with alphabet */
118 $this->AddRegex ("Regex", _("Display systems matching"),"*" , true);
119 $this->AddRegex ("UserRegex", _("Display systems of user"), "*" , false, "images/search_user.png");
120 }
122 function GenHeader()
123 {
124 /* Prepare departments,
125 which are shown in the listbox on top of the listbox
126 */
127 $options= "";
129 /* Get all departments within this subtree */
130 $base = $this->config->current['BASE'];
132 /* Add base */
133 $tmp = array();
134 $tmp[] = array("dn"=>$this->config->current['BASE']);
135 $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
136 array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
138 $deps = array();
139 foreach($tmp as $tm){
140 $deps[$tm['dn']] = $tm['dn'];
141 }
143 /* Load possible departments */
144 $ui= get_userinfo();
145 $first = "";
146 $found = FALSE;
147 $department = $departments = array();
148 foreach($this->module as $module){
149 $d = $ui->get_module_departments($module);
150 foreach($d as $department){
151 $departments[$department] = $department;
152 }
153 }
155 /* Load possible departments */
156 $ui= get_userinfo();
157 $ids = $this->config->idepartments;
158 $first = "";
159 $found = FALSE;
160 foreach($ids as $dep => $name){
161 if(isset($deps[$dep]) && in_array_ics($dep, $departments)){
163 /* Keep first base dn in mind, we could need this
164 * info if no valid base was found
165 */
166 if(empty($first)) {
167 $first = $dep['dn'];
168 }
170 $value = $ids[$dep];
171 if ($this->selectedBase == $dep){
172 $found = TRUE;
173 $options.= "<option selected='selected' value='".$dep."'>$value</option>";
174 } else {
175 $options.= "<option value='".$dep."'>$value</option>";
176 }
177 }
178 }
181 /* The currently used base is not visible with your acl setup.
182 * Set base to first useable base.
183 */
184 if(!$found){
185 $this->selectedBase = $first;
186 }
188 /* If there is at least one c (Create) and one w (Write) acl in this combination
189 display the snapshot paste icon. BUT check the correct acls in the management plugin */
190 $all_module_acls = "";
191 foreach($this->module as $module){
192 $all_module_acls .= $ui->has_complete_category_acls($this->selectedBase,$module);
193 }
195 /* Must we add an additional seperator */
196 $add_sep = false;
198 /* Add default header */
199 $listhead = MultiSelectWindow::get_default_header();
201 /* Add base selection */
202 $listhead .= _("Base")." <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
203 " <input class='center' type='image' src='images/list_submit.png' align='middle'
204 title='"._("Submit department")."' name='submit_department' alt='". _("Submit")."'> ";
206 /* Handle create icons */
207 $s = ".|"._("Actions")."|\n";
208 $s.= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
209 " "._("Create")."|\n";
210 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"terminal/termgeneric"))){
211 $s.= "...|<img src='images/select_terminal.png' alt='' border='0' class='center'>".
212 " "._("Terminal")."|"."newsystem_terminal|\n";
213 }
214 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"workstation/workgeneric"))){
215 $s.= "...|<img src='images/select_workstation.png' alt='' border='0' class='center'>".
216 " "._("Workstation")."|"."newsystem_workstation|\n";
217 }
218 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"workstation/servgeneric"))){
219 $s.= "...|<img src='images/select_server.png' alt='' border='0' class='center'>".
220 " "._("Server")."|"."newsystem_server|\n";
221 }
222 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"phone/phoneGeneric"))){
223 $s.= "...|<img src='images/select_phone.png' alt='' border='0' class='center'>".
224 " "._("Phone")."|"."newsystem_phone|\n";
225 }
226 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"printer/printgeneric"))){
227 $s.= "...|<img src='images/select_printer.png' alt='' border='0' class='center'>".
228 " "._("Printer")."|"."newsystem_printer|\n";
229 }
230 if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"component/componentGeneric"))){
231 $s.= "...|<img src='images/select_component.png' alt='' border='0' class='center'>".
232 " "._("Component")."|"."newsystem_component|\n";
233 }
235 $events = DaemonEvent::get_event_types(SYSTEM_EVENT);
237 $s.= "..|<img src='images/rocket.png' alt='' border='0' class='center'>".
238 " "._("Trigger action")."|\n";
239 foreach($events['TRIGGERED'] as $name => $event){
240 $s.= "...|".$event['MenuImage']." ".$event['s_Menu_Name']."|trigger_event_".$name."\n";
241 }
243 $s.= "..|<img src='images/clock.png' alt='' border='0' class='center'>".
244 " "._("Schedule action")."|\n";
245 foreach($events['SCHEDULED'] as $name => $event){
246 $s.= "...|".$event['MenuImage']." ".$event['s_Menu_Name']."|schedule_event_".$name."\n";
247 }
249 $s.= "..|<img src='images/lists/trash.png' alt='' border='0' class='center'>".
250 " "._("Remove")."|"."remove_multiple|\n";
252 /* Add multiple copy & cut icons */
253 if(is_object($this->parent->CopyPasteHandler)){
254 $s.= "..|---|\n";
255 $s.= "..|<img src='images/lists/copy.png' alt='' border='0' class='center'>".
256 " "._("Copy")."|"."multiple_copy_systems|\n";
257 $s.= "..|<img src='images/lists/cut.png' alt='' border='0' class='center'>".
258 " "._("Cut")."|"."multiple_cut_systems|\n";
259 }
261 /* Get copy & paste icon */
262 $Copy_Paste ="";
263 if(preg_match("/(c.*w|w.*c)/",$all_module_acls) && $this->parent->CopyPasteHandler){
264 $s .= "..|---|\n";
265 if($this->parent->CopyPasteHandler->entries_queued()){
266 $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
267 $s.="..|".$img." "._("Paste")."|editPaste|\n";
268 }else{
269 $img = "<img border='0' class='center' src='images/lists/paste.png' alt=''>";
270 $s.="..|".$img." "._("Paste")."\n";
271 }
272 }
274 /* Add snapshot icons */
275 if(preg_match("/(c.*w|w.*c)/",$all_module_acls)){
276 $s .= "..|---|\n";
277 $s .= $this->get_snapshot_header(TRUE);
278 }
280 $this->SetDropDownHeaderMenu($s);
281 $this->SetListHeader($listhead);
282 }
284 function execute()
285 {
286 $this->ClearElementsList();
287 $this->GenHeader();
288 }
290 function setEntries($terminals)
291 {
292 $img1 = "<img class='center' src='images/printer.png' alt='C' title='"._("Cups Server") ."'>";
293 $img2 = "<img class='center' src='images/scanner.png' alt='L' title='"._("Log Db") ."'>";
294 $img3 = "<img class='center' src='images/select_terminal.png' alt='L' title='"._("Syslog Server") ."'>";
295 $img4 = "<img class='center' src='images/mailto.png' alt='M' title='"._("Mail Server") ."'>";
296 $img5 = "<img class='center' src='images/select_phone.png' alt='I' title='"._("Imap Server") ."'>";
297 $img6 = "<img class='center' src='images/fax_small.png' alt='F' title='"._("Nfs Server") ."'>";
298 $img7 = "<img class='center' src='images/select_winstation.png' alt='K' title='"._("Kerberos Server") ."'>";
299 $img8 = "<img class='center' src='images/select_phone.png' alt='A' title='"._("Asterisk Server") ."'>";
300 $img9 = "<img class='center' src='images/fax_small.png' alt='F' title='"._("Fax Server") ."'>";
301 $img10 = "<img class='center' src='images/save.png' alt='L' title='"._("Ldap Server") ."'>";
303 $empty ="<img src='images/empty.png' style='width:16px ; height: 16px;' class='center' alt=''>";
305 /* Dynamic action col, depending on snapshot icons */
306 $action_col_size = 110;
307 if($this->parent->snapshotEnabled()){
308 $action_col_size += 38;
309 }
311 // User and Template Images
312 $editlink = "<a href='?plug=".$_GET['plug']."&id=%s&act=edit_entry'>%s</a>";
314 /* ACL mapping */
315 $ui = get_userinfo();
316 $tabs = array(
317 "terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
318 "workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
319 "server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
320 "printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
321 "phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
322 "winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
323 "incoming" => array("CLASS"=>"", "TABCLASS" =>"", "ACL"=> "incoming/systems"),
324 "component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
327 $cnts = array("component" => 0 , "terminal" => 0 , "workstation" => 0 ,
328 "printer" => 0 , "phone" => 0 , "server" => 0,
329 "NewDevice" => 0, "winstation"=> 0);
331 // Test Every Entry and generate divlist Array
332 foreach($terminals as $key => $val){
334 /* Get system type, it is used to fetch the acls for the current object.
335 "winstation" acls are stored as 2winworkstation", so we have to map this here */
336 $type = $this->parent->get_system_type($val);
337 if($type == "winstation") {
338 $acl_type = "winworkstation";
339 }else{
340 $acl_type = $type;
341 }
343 /* Map NewDevice acls to workstation acls */
344 if($type == "NewDevice" || $type == "ArpNewDevice"){
345 $type = "incoming";
346 $acl_type = "incoming";
347 }
349 /* Get complete category acls */
350 $acl_all = $ui->has_complete_category_acls($val['dn'],$acl_type) ;
352 /* Get specific generic acls */
353 $acl = $ui->get_permissions($val['dn'],$tabs[$type]['ACL']);
355 $action ="";
356 if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
357 $action.= "<input class='center' type='image'
358 src='images/lists/cut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'> ";
359 $action.= "<input class='center' type='image'
360 src='images/lists/copy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'> ";
361 }
362 $action.= "<input class='center' type='image' src='images/lists/edit.png'
363 alt='"._("edit")."' name='system_edit_%KEY%' title='"._("Edit system")."'>";
364 if(preg_match("/(c.*w|w.*c)/",$acl_all)){
365 $action.= $this->GetSnapShotActions($val['dn']);
366 }else{
367 $action.= $empty." ".$empty." ";
368 }
371 if(preg_match("/d/",$acl)){
372 $action.= "<input class='center' type='image' src='images/lists/trash.png'
373 alt='"._("delete")."' name='system_del_%KEY%' title='"._("Delete system")."'>";
374 }else{
375 $action.= $empty;
376 }
378 /* Generate picture list, which is currently disabled */
379 if(in_array("goCupsServer" ,$val['objectClass'])) $cups = $img1; else $cups =$empty;
380 if(in_array("goLogDBServer" ,$val['objectClass'])) $logdb = $img2; else $logdb =$empty;
381 if(in_array("goSyslogServer" ,$val['objectClass'])) $syslog = $img3; else $syslog=$empty;
382 if(in_array("goImapServer" ,$val['objectClass'])) $imap = $img4; else $imap =$empty;
383 if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba = $img5; else $samba =$empty;
384 if(in_array("goShareServer" ,$val['objectClass'])) $nfs = $img6; else $nfs =$empty;
385 if(in_array("goKrbServer" ,$val['objectClass'])) $krb = $img7; else $krb =$empty;
386 if(in_array("goFonServer" ,$val['objectClass'])) $fon = $img8; else $fon =$empty;
387 if(in_array("goFaxServer" ,$val['objectClass'])) $fax = $img9; else $fax =$empty;
388 if(in_array("goLdapServer" ,$val['objectClass'])) $ldap = $img10; else $ldap =$empty;
390 $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
391 $pics = ""; // Pictures currently hidden
393 $val['cn'][0]= preg_replace('/\$$/', '', $val['cn'][0]);
395 // Generate Array to Add
396 $dsc= "";
397 if (isset($val['description'][0])){
398 $dsc= " [".$val['description'][0]."]";
399 }
400 if((isset($val['is_new']))&&(!empty($val['is_new']))){
401 $display= $val["cn"][0]." ".$val['is_new'].$dsc;
402 }else{
403 $display= $val["cn"][0].$dsc;
404 }
406 /* Check if this is a terminal/workstation && if we are allowed to change the gotoRootPasswd */
407 $display_key_for = array("terminal","workstation","server","component");
408 $pwd_acl = $ui->get_permissions($val['dn'],$tabs[$type]['ACL'],"userPassword");
409 if(preg_match("/w/",$pwd_acl) && in_array($type,$display_key_for)){
410 $action2 = "<input class='center' type='image' src='images/lists/key.png' alt='"._("Password")."' name='system_setpwd_%KEY%' title='"._("Set password")."'>";
411 }else{
412 $action2 = $empty;
413 }
415 if(in_array("gotoWorkstation",$val['objectClass'])){
416 $action2= "<input class='center' type='image' src='images/cdrom.png' alt='"._("Create CD")."'
417 name='gen_cd_%KEY%' title='"._("Create FAI CD")."'> ".$action2;
418 }else{
419 $action2= $empty.$action2;
420 }
422 if(isset($val['message'])){
423 $display.= " (".$val['message'].")";
424 }
426 $img = $this->parent->convert_list($val);
428 /* Cutted objects should be displayed in light grey */
429 if($this->parent->CopyPasteHandler){
430 foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
431 if($queue_data['dn'] == $val['dn']) {
432 $display = "<font color='#999999'>".$display."</font>";
433 break;
434 }
435 }
436 }
438 $type = $this->parent->get_system_type($val);
439 if($type == "ArpNewDevice"){
440 $type = "NewDevice";
441 }
442 $cnts[$type] ++;
445 /* Create each field */
446 $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
447 "attach" => "style='width:20px;'");
449 $field1 = array("string" => sprintf($img['img'],$val['dn']), "attach" => "style='text-align:center;width:20px;'");
450 $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'");
451 $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
452 $this->AddElement( array($field0,$field1,$field2,$field3));
453 }
455 /* Create summary string for list footer */
456 $num_deps=0;
457 if(!$this->SubSearch){
458 $num_deps = count($this->Added_Departments);
459 }
461 $num_ser_str = sprintf(_("Number of listed '%s'"),_("servers"));
462 $num_ws_str = sprintf(_("Number of listed '%s'"),_("workstations"));
463 $num_ter_str = sprintf(_("Number of listed '%s'"),_("terminals"));
464 $num_pho_str = sprintf(_("Number of listed '%s'"),_("phones"));
465 $num_prt_str = sprintf(_("Number of listed '%s'"),_("printers"));
466 $num_com_str = sprintf(_("Number of listed '%s'"),_("network components"));
467 $num_new_str = sprintf(_("Number of listed '%s'"),_("new devices"));
468 $num_wws_str = sprintf(_("Number of listed '%s'"),_("windows workstations"));
469 $num_dep_str = sprintf(_("Number of listed '%s'"),_("departments"));
471 $str = "<img class='center' src='images/select_server.png'
472 title='".$num_ser_str."' alt='".$num_ser_str."'> ".$cnts['server']." ";
473 $str.= "<img class='center' src='images/select_workstation.png'
474 title='".$num_ws_str."' alt='".$num_ws_str."'> ".$cnts['workstation']." ";
475 $str.= "<img class='center' src='images/select_terminal.png'
476 title='".$num_ter_str."' alt='".$num_ter_str."'> ".$cnts['terminal']." ";
477 $str.= "<img class='center' src='images/select_phone.png'
478 title='".$num_pho_str."' alt='".$num_pho_str."'> ".$cnts['phone']." ";
479 $str.= "<img class='center' src='images/select_printer.png'
480 title='".$num_prt_str."' alt='".$num_prt_str."'> ".$cnts['printer']." ";
481 $str.= "<img class='center' src='images/select_component.png'
482 title='".$num_com_str."' alt='".$num_com_str."'> ".$cnts['component']." ";
483 $str.= "<img class='center' src='images/select_newsystem.png'
484 title='".$num_new_str."' alt='".$num_new_str."'> ".$cnts['NewDevice']." ";
485 $str.= "<img class='center' src='images/select_winstation.png'
486 title='".$num_wws_str."' alt='".$num_wws_str."'> ".$cnts['winstation']." ";
487 $str.= "<img class='center' src='images/lists/folder.png'
488 title='".$num_dep_str."' alt='".$num_dep_str."'> ".$num_deps." ";
490 $this->set_List_Bottom_Info($str);
491 }
494 function Save()
495 {
496 MultiSelectWindow :: Save();
497 }
500 function save_object()
501 {
502 /* Save automatic created POSTs like regex, checkboxes */
503 MultiSelectWindow :: save_object();
506 }
507 }
508 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
509 ?>