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