Code

Updates
[gosa.git] / gosa-plugins / systems / admin / systems / class_divListSystem.inc
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"=>"&nbsp;","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;
184    
185     /* Add default header */
186     $listhead = MultiSelectWindow::get_default_header();
188     /* Add base selection */
189     $listhead .= _("Base")."&nbsp; <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")."'>&nbsp;";
193     /* Handle create icons */ 
194     $s = ".|"._("Actions")."|\n";
195     $s.= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
196       "&nbsp;"._("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         "&nbsp;"._("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         "&nbsp;"._("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         "&nbsp;"._("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         "&nbsp;"._("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         "&nbsp;"._("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         "&nbsp;"._("Component")."|"."newsystem_component|\n";
220     }
222     $events  = DaemonEvent::get_event_types(SYSTEM_EVENT);
223     $s.= "..|<img src='images/rocket.png' alt='' border='0' class='center'>".
224       "&nbsp;"._("Trigger action")."|\n";
225     foreach($events['BY_CLASS'] as $name =>  $event){
226       $s.= "...|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|trigger_event_".$name."\n";
227     }
229     $s.= "..|<img src='images/clock.png' alt='' border='0' class='center'>".
230       "&nbsp;"._("Schedule action")."|\n";
231     foreach($events['BY_CLASS'] as $name =>  $event){
232       $s.= "...|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|schedule_event_".$name."\n";
233     }
235     $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
236       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
238     /* Add multiple copy & cut icons */
239     if(is_object($this->parent->CopyPasteHandler)){
240       $s.= "..|---|\n";
241       $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
242         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
243       $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
244         "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
245     }
247     /* Get copy & paste icon */
248     $Copy_Paste ="";
249     if(preg_match("/(c.*w|w.*c)/",$all_module_acls) &&  $this->parent->CopyPasteHandler){
250       $s .= "..|---|\n";
251       if($this->parent->CopyPasteHandler->entries_queued()){
252         $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
253         $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
254       }else{
255         $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
256         $s.="..|".$img."&nbsp;"._("Paste")."\n";
257       }
258     }
260     /* Add snapshot icons */
261     if(preg_match("/(c.*w|w.*c)/",$all_module_acls)){
262       $s .= "..|---|\n";
263       $s .= $this->get_snapshot_header(TRUE);
264     }
266     $this->SetDropDownHeaderMenu($s);
267     $this->SetListHeader($listhead);
268   }
270   function execute()
271   {
272     $this->ClearElementsList();
273     $this->GenHeader();
274   }
276   function setEntries($terminals)
277   {
278     $img1  = "<img class='center' src='images/printer.png'            alt='C' title='"._("Cups Server")  ."'>";
279     $img2  = "<img class='center' src='images/scanner.png'            alt='L' title='"._("Log Db") ."'>";
280     $img3  = "<img class='center' src='images/select_terminal.png'    alt='L' title='"._("Syslog Server") ."'>";
281     $img4  = "<img class='center' src='images/mailto.png'             alt='M' title='"._("Mail Server")  ."'>";
282     $img5  = "<img class='center' src='images/select_phone.png'       alt='I' title='"._("Imap Server") ."'>";
283     $img6  = "<img class='center' src='images/fax_small.png'          alt='F' title='"._("Nfs Server")   ."'>";
284     $img7  = "<img class='center' src='images/select_winstation.png'  alt='K' title='"._("Kerberos Server") ."'>";
285     $img8  = "<img class='center' src='images/select_phone.png'       alt='A' title='"._("Asterisk Server") ."'>";
286     $img9  = "<img class='center' src='images/fax_small.png'          alt='F' title='"._("Fax Server") ."'>";
287     $img10 = "<img class='center' src='images/save.png'               alt='L' title='"._("Ldap Server") ."'>";
289     $empty    ="<img src='images/empty.png' style='width:16px ; height: 16px;' class='center' alt=''>";
291     /* Dynamic action col, depending on snapshot icons */
292     $action_col_size = 110;
293     if($this->parent->snapshotEnabled()){
294       $action_col_size += 38;
295     }
297     // User and Template  Images
298     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
300     /* ACL mapping */
301     $ui = get_userinfo();
302     $tabs = array(
303           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
304           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
305           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
306           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
307           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
308           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
309           "incoming"    => array("CLASS"=>"",             "TABCLASS" =>"",              "ACL"=> "incoming/systems"),
310           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
313     $cnts = array("component" => 0 , "terminal" => 0 , "workstation" => 0 , 
314                   "printer" => 0 , "phone" => 0 , "server" => 0,
315                   "NewDevice" => 0, "winstation"=> 0);
317     // Test Every Entry and generate divlist Array
318     foreach($terminals as $key => $val){
320       /* Get system type, it is used to fetch the acls for the current object.
321           "winstation" acls are stored as 2winworkstation", so we have to map this here */
322       $type     = $this->parent->get_system_type($val);
323       if($type == "winstation") {
324         $acl_type = "winworkstation";
325       }else{
326         $acl_type = $type;
327       }
329       /* Map NewDevice acls to workstation acls */
330       if($type == "NewDevice" || $type == "ArpNewDevice"){
331         $type     = "incoming";
332         $acl_type = "incoming";
333       }
335       /* Get complete category acls */
336       $acl_all  = $ui->has_complete_category_acls($val['dn'],$acl_type) ;
337   
338       /* Get specific generic acls */
339       $acl      = $ui->get_permissions($val['dn'],$tabs[$type]['ACL']);
341       $action ="";
342       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
343         $action.= "<input class='center' type='image'
344           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
345         $action.= "<input class='center' type='image'
346           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
347       }
348       $action.= "<input class='center' type='image' src='images/edit.png' 
349                     alt='"._("edit")."'     name='system_edit_%KEY%' title='"._("Edit system")."'>";
350       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
351         $action.= $this->GetSnapShotActions($val['dn']);
352       }else{
353         $action.= $empty."&nbsp;".$empty."&nbsp;";
354       }
357       if(preg_match("/d/",$acl)){
358         $action.= "<input class='center' type='image' src='images/edittrash.png' 
359           alt='"._("delete")."'   name='system_del_%KEY%' title='"._("Delete system")."'>";
360       }else{
361         $action.= $empty;    
362       }
364       /* Generate picture list, which is currently disabled */
365       if(in_array("goCupsServer"    ,$val['objectClass'])) $cups    = $img1;   else $cups  =$empty;
366       if(in_array("goLogDBServer"   ,$val['objectClass'])) $logdb   = $img2;   else $logdb =$empty;
367       if(in_array("goSyslogServer"  ,$val['objectClass'])) $syslog  = $img3;   else $syslog=$empty;
368       if(in_array("goImapServer"    ,$val['objectClass'])) $imap    = $img4;   else $imap  =$empty;
369       if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba   = $img5;   else $samba =$empty;
370       if(in_array("goShareServer"   ,$val['objectClass'])) $nfs     = $img6;   else $nfs   =$empty;
371       if(in_array("goKrbServer"     ,$val['objectClass'])) $krb     = $img7;   else $krb   =$empty;
372       if(in_array("goFonServer"     ,$val['objectClass'])) $fon     = $img8;   else $fon   =$empty;
373       if(in_array("goFaxServer"     ,$val['objectClass'])) $fax     = $img9;   else $fax   =$empty;
374       if(in_array("goLdapServer"    ,$val['objectClass'])) $ldap     = $img10;   else $ldap   =$empty;
376       $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
377       $pics = ""; // Pictures currently hidden
379       $val['cn'][0]= preg_replace('/\$$/', '', $val['cn'][0]);
381       // Generate Array to Add
382       $dsc= "";
383       if (isset($val['description'][0])){
384         $dsc= " [".$val['description'][0]."]";
385       }
386       if((isset($val['is_new']))&&(!empty($val['is_new']))){
387         $display= $val["cn"][0]." ".$val['is_new'].$dsc;
388       }else{
389         $display= $val["cn"][0].$dsc;
390       }
392      
393       /* Check if this is a terminal/workstation && if we are allowed to change the gotoRootPasswd */
394       $pwd_acl =""; 
395       if(in_array("gotoWorkstation",$val['objectClass'])){
396         $pwd_acl = $ui->get_permissions($val['dn'],"workstation/workgeneric","gotoRootPasswd");
397       }    
398       if(in_array("gotoTerminal",$val['objectClass'])){
399         $pwd_acl = $ui->get_permissions($val['dn'],"terminal/termgeneric","gotoRootPasswd");
400       }    
401       if(preg_match("/w/",$pwd_acl)){
402         $action2 = "<input class='center' type='image' src='images/certs.png' alt='"._("Password")."'   name='system_setpwd_%KEY%' title='"._("Set root password")."'>";
403       }else{
404         $action2 = $empty;
405       }
408       if(in_array("gotoWorkstation",$val['objectClass'])){
409         $action2= "<input class='center' type='image' src='images/cdrom.png' alt='"._("Create CD")."'   
410                       name='gen_cd_%KEY%' title='"._("Create FAI CD")."'>&nbsp;".$action2;
411       }else{
412         $action2= $empty.$action2;
413       }
415       if(isset($val['message'])){
416         $display.= "  (".$val['message'].")";
417       }
419       $img    = $this->parent->convert_list($val);
421       /* Cutted objects should be displayed in light grey */
422       if($this->parent->CopyPasteHandler){
423         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
424           if($queue_data['dn'] == $val['dn']) {
425             $display = "<font color='#999999'>".$display."</font>";
426             break;
427           }
428         }
429       }
431       $type = $this->parent->get_system_type($val);
432       if($type == "ArpNewDevice"){
433         $type = "NewDevice";
434       }
435       $cnts[$type] ++;
438       /* Create each field */
439       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
440                       "attach" => "style='width:20px;'");
442       $field1 = array("string" => sprintf($img['img'],$val['dn']), "attach" => "style='text-align:center;width:20px;'");
443       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
444       $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
445       $this->AddElement( array($field0,$field1,$field2,$field3));
446     }
448     /* Create summary string for list footer */
449     $num_deps=0;
450     if(!$this->SubSearch){
451       $num_deps = count($this->Added_Departments);
452     }
454     $num_ser_str = _("Number of listed servers");
455     $num_ws_str  = _("Number of listed workstations");
456     $num_ter_str = _("Number of listed terminals");
457     $num_pho_str = _("Number of listed phones");
458     $num_prt_str = _("Number of listed printers");
459     $num_com_str = _("Number of listed network components");
460     $num_new_str = _("Number of listed new devices");
461     $num_wws_str = _("Number of listed windows workstations");
462     $num_dep_str = _("Number of listed departments");
464     $str = "<img class='center' src='images/select_server.png'
465       title='".$num_ser_str."' alt='".$num_ser_str."'>&nbsp;".$cnts['server']."&nbsp;&nbsp;&nbsp;&nbsp;";
466     $str.= "<img class='center' src='images/select_workstation.png'
467       title='".$num_ws_str."' alt='".$num_ws_str."'>&nbsp;".$cnts['workstation']."&nbsp;&nbsp;&nbsp;&nbsp;";
468     $str.= "<img class='center' src='images/select_terminal.png'
469       title='".$num_ter_str."' alt='".$num_ter_str."'>&nbsp;".$cnts['terminal']."&nbsp;&nbsp;&nbsp;&nbsp;";
470     $str.= "<img class='center' src='images/select_phone.png'
471       title='".$num_pho_str."' alt='".$num_pho_str."'>&nbsp;".$cnts['phone']."&nbsp;&nbsp;&nbsp;&nbsp;";
472     $str.= "<img class='center' src='images/select_printer.png'
473       title='".$num_prt_str."' alt='".$num_prt_str."'>&nbsp;".$cnts['printer']."&nbsp;&nbsp;&nbsp;&nbsp;";
474     $str.= "<img class='center' src='images/select_component.png'
475       title='".$num_com_str."' alt='".$num_com_str."'>&nbsp;".$cnts['component']."&nbsp;&nbsp;&nbsp;&nbsp;";
476     $str.= "<img class='center' src='images/select_newsystem.png'
477       title='".$num_new_str."' alt='".$num_new_str."'>&nbsp;".$cnts['NewDevice']."&nbsp;&nbsp;&nbsp;&nbsp;";
478     $str.= "<img class='center' src='images/select_winstation.png'
479       title='".$num_wws_str."' alt='".$num_wws_str."'>&nbsp;".$cnts['winstation']."&nbsp;&nbsp;&nbsp;&nbsp;";
480     $str.= "<img class='center' src='images/folder.png'
481       title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
483     $this->set_List_Bottom_Info($str);
484   }
487   function Save()
488   {
489     MultiSelectWindow :: Save();  
490   }
493   function save_object()
494   {
495     /* Save automatic created POSTs like regex, checkboxes */
496     MultiSelectWindow :: save_object();  
499   }
501 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
502 ?>