Code

Updated system management.
[gosa.git] / gosa-plugins / systems / admin / systems / class_divListSystem.inc
1 <?php
3 class divListSystem extends MultiSelectWindow
4 {
6   /* Current base */
7   var $selectedBase       = "";
8   var $departments        = array();
10   /* Regex */
11   var $Regex              = "*";
12   var $UserRegex          = "*";
14   /* CheckBoxes, to change default values modify $this->AddCheckBox */
15   var $ShowServers;
16   var $ShowTerminals;
17   var $ShowWorkstations;
18   var $ShowWinWorkstations;
19   var $ShowPrinters;
20   var $ShowDevices;
21   var $ShowPhones;
23   /* Subsearch checkbox */
24   var $SubSearch;
26   var $parent             ;
27   var $ui                 ;
29   function divListSystem (&$config,$parent)
30   {
31     MultiSelectWindow::MultiSelectWindow($config, "System", array("server",
32                                                                   "workstation",
33                                                                   "terminal",
34                                                                   "phone",
35                                                                   "incoming",
36                                                                   "printer"));
38     $this->parent       = $parent;
39     $this->ui           = get_userinfo();
41     /* Set list strings */
42     $this->SetTitle(_("List of systems"));
43     $this->SetSummary(_("List of systems"));
45     /* Result page will look like a headpage */
46     $this->SetHeadpageMode();
47     $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."));
49     $this->EnableAplhabet   (true);
51     /* Disable buttonsm */
52     $this->EnableCloseButton(false);
53     $this->EnableSaveButton (false);
55     /* Dynamic action col, depending on snapshot icons */
56     $action_col_size = 110;
57     if($this->parent->snapshotEnabled()){
58       $action_col_size += 38;
59     }
61     /* Toggle all selected / deselected */
62     $chk = "<input type='checkbox' id='select_all' name='select_all'
63                onClick='toggle_all_(\"^item_selected_[0-9]*$\",\"select_all\");' >";
65     /* set Page header */
66     $this->AddHeader(array("string"=> $chk,          "attach"=>"style='width:20px;'"));
67     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
68     $this->AddHeader(array("string"=>_("System / Department")));
69     $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:".$action_col_size."px;border-right:0px;'"));
71     /*                  Text        ,Value    ,Name         ,Is selected */
72     $this->AddCheckBox("ShowServers",         _("Select to see servers"),            _("Show servers"),          true);
73     $this->AddCheckBox("ShowTerminals",       _("Select to see Linux terminals"),    _("Show terminals") ,       true);
74     $this->AddCheckBox("ShowWorkstations",    _("Select to see Linux workstations"), _("Show workstations"),     true);
75     $this->AddCheckBox("ShowWinWorkstations", _("Select to see MicroSoft Windows based workstations"), _("Show windows based workstations"),true);
76     $this->AddCheckBox("ShowPrinters",        _("Select to see network printers"),    _("Show network printers") ,true);
77     $this->AddCheckBox("ShowPhones",          _("Select to see VOIP phones"),         _("Show phones") ,          true);
78     $this->AddCheckBox("ShowDevices",         _("Select to see network devices"),     _("Show network devices"),  true);
80     /* Add SubSearch checkbox */
81     $this->AddCheckBox(SEPERATOR);
82     $this->AddCheckBox("SubSearch",  _("Select to search within subtrees"), _("Search in subtrees"), false);
84     /*                  Name                 ,Text                              ,Default  , Connect with alphabet  */
85     $this->AddRegex   ("Regex",     _("Display systems matching"),"*" , true);
86     $this->AddRegex   ("UserRegex", _("Display systems of user"), "*" , false, "images/search_user.png");
87   }
89   function GenHeader()
90   {
91    /* Prepare departments,
92        which are shown in the listbox on top of the listbox
93      */
94     $options= "";
96     /* Get all departments within this subtree */
97     $base = $this->config->current['BASE'];
99     /* Add base */
100     $tmp = array();
101     $tmp[] = array("dn"=>$this->config->current['BASE']);
102     $tmp=  array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base,
103                     array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH));
105     $deps = array();
106     foreach($tmp as $tm){
107       $deps[$tm['dn']] = $tm['dn'];
108     }
110     /* Load possible departments */
111     $ui= get_userinfo();
112     $first = "";
113     $found = FALSE;
114     $department = $departments = array();
115     foreach($this->module as $module){
116       $d = $ui->get_module_departments($module);      
117       foreach($d as $department){
118         $departments[$department] = $department;
119       }
120     }
122     /* Load possible departments */
123     $ui= get_userinfo();
124     $ids = $this->config->idepartments;
125     $first = "";
126     $found = FALSE;
127     foreach($ids as $dep => $name){
128       if(isset($deps[$dep]) && in_array_ics($dep, $departments)){
130         /* Keep first base dn in mind, we could need this
131          *  info if no valid base was found
132          */
133         if(empty($first)) {
134           $first = $dep['dn'];
135         }
137         $value = $ids[$dep];
138         if ($this->selectedBase == $dep){
139           $found = TRUE;
140           $options.= "<option selected='selected' value='".$dep."'>$value</option>";
141         } else {
142           $options.= "<option value='".$dep."'>$value</option>";
143         }
144       }
145     }
148     /* The currently used base is not visible with your acl setup.
149      * Set base to first useable base.
150      */
151     if(!$found){
152       $this->selectedBase = $first;
153     }
155     /* If there is at least one c (Create) and one w (Write) acl in this combination
156         display the snapshot paste icon. BUT check the correct acls in the management plugin */
157     $all_module_acls = "";
158     foreach($this->module as $module){
159       $all_module_acls .= $ui->has_complete_category_acls($this->selectedBase,$module);
160     }
162     /* Must we add an additional seperator */
163     $add_sep = false;
164    
165     /* Add default header */
166     $listhead = MultiSelectWindow::get_default_header();
168     /* Add base selection */
169     $listhead .= _("Base")."&nbsp; <select name='CurrentMainBase' onChange='mainform.submit()' class='center'>$options</select>".
170       " <input class='center' type='image' src='images/list_submit.png' align='middle'
171       title='"._("Submit department")."' name='submit_department' alt='".           _("Submit")."'>&nbsp;";
173     /* Handle create icons */ 
174     $s = ".|"._("Actions")."|\n";
175     $s.= "..|<img src='images/list_new.png' alt='' border='0' class='center'>".
176       "&nbsp;"._("Create")."|\n";
177     if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"terminal/termgeneric"))){
178       $s.= "...|<img src='images/select_terminal.png' alt='' border='0' class='center'>".
179         "&nbsp;"._("Terminal")."|"."newsystem_terminal|\n";
180     }
181     if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"workstation/workgeneric"))){
182       $s.= "...|<img src='images/select_workstation.png' alt='' border='0' class='center'>".
183         "&nbsp;"._("Workstation")."|"."newsystem_workstation|\n";
184     }
185     if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"workstation/servgeneric"))){
186       $s.= "...|<img src='images/select_server.png' alt='' border='0' class='center'>".
187         "&nbsp;"._("Server")."|"."newsystem_server|\n";
188     }
189     if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"phone/phoneGeneric"))){
190       $s.= "...|<img src='images/select_phone.png' alt='' border='0' class='center'>".
191         "&nbsp;"._("Phone")."|"."newsystem_phone|\n";
192     }
193     if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"printer/printgeneric"))){
194       $s.= "...|<img src='images/select_printer.png' alt='' border='0' class='center'>".
195         "&nbsp;"._("Printer")."|"."newsystem_printer|\n";
196     }
197     if(preg_match("/c/",$ui->get_permissions($this->selectedBase,"component/componentGeneric"))){
198       $s.= "...|<img src='images/select_component.png' alt='' border='0' class='center'>".
199         "&nbsp;"._("Component")."|"."newsystem_component|\n";
200     }
202     $events  = DaemonEvent::get_event_types();
203     $s.= "..|<img src='images/rocket.png' alt='' border='0' class='center'>".
204       "&nbsp;"._("Trigger action")."|\n";
205     foreach($events['BY_CLASS'] as $name =>  $event){
206       $s.= "...|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|trigger_event_".$name."\n";
207     }
209     $s.= "..|<img src='images/clock.png' alt='' border='0' class='center'>".
210       "&nbsp;"._("Schedule action")."|\n";
211     foreach($events['BY_CLASS'] as $name =>  $event){
212       $s.= "...|".$event['MenuImage']."&nbsp;".$event['s_Menu_Name']."|schedule_event_".$name."\n";
213     }
215     $s.= "..|<img src='images/edittrash.png' alt='' border='0' class='center'>".
216       "&nbsp;"._("Remove")."|"."remove_multiple|\n";
218     /* Add multiple copy & cut icons */
219     if(is_object($this->parent->CopyPasteHandler)){
220       $s.= "..|---|\n";
221       $s.= "..|<img src='images/editcopy.png' alt='' border='0' class='center'>".
222         "&nbsp;"._("Copy")."|"."multiple_copy_systems|\n";
223       $s.= "..|<img src='images/editcut.png' alt='' border='0' class='center'>".
224         "&nbsp;"._("Cut")."|"."multiple_cut_systems|\n";
225     }
227     /* Get copy & paste icon */
228     $Copy_Paste ="";
229     if(preg_match("/(c.*w|w.*c)/",$all_module_acls) &&  $this->parent->CopyPasteHandler){
230       $s .= "..|---|\n";
231       if($this->parent->CopyPasteHandler->entries_queued()){
232         $img = "<img border='0' class='center' src='images/editpaste.png' alt=''>";
233         $s.="..|".$img."&nbsp;"._("Paste")."|editPaste|\n";
234       }else{
235         $img = "<img border='0' class='center' src='images/cant_editpaste.png' alt=''>";
236         $s.="..|".$img."&nbsp;"._("Paste")."\n";
237       }
238     }
240     /* Add snapshot icons */
241     if(preg_match("/(c.*w|w.*c)/",$all_module_acls)){
242       $s .= "..|---|\n";
243       $s .= $this->get_snapshot_header(TRUE);
244     }
246     $this->SetDropDownHeaderMenu($s);
247     $this->SetListHeader($listhead);
248   }
250   function execute()
251   {
252     $this->ClearElementsList();
253     $this->GenHeader();
254   }
256   function setEntries($terminals)
257   {
258     $img1  = "<img class='center' src='images/printer.png'            alt='C' title='"._("Cups Server")  ."'>";
259     $img2  = "<img class='center' src='images/scanner.png'            alt='L' title='"._("Log Db") ."'>";
260     $img3  = "<img class='center' src='images/select_terminal.png'    alt='L' title='"._("Syslog Server") ."'>";
261     $img4  = "<img class='center' src='images/mailto.png'             alt='M' title='"._("Mail Server")  ."'>";
262     $img5  = "<img class='center' src='images/select_phone.png'       alt='I' title='"._("Imap Server") ."'>";
263     $img6  = "<img class='center' src='images/fax_small.png'          alt='F' title='"._("Nfs Server")   ."'>";
264     $img7  = "<img class='center' src='images/select_winstation.png'  alt='K' title='"._("Kerberos Server") ."'>";
265     $img8  = "<img class='center' src='images/select_phone.png'       alt='A' title='"._("Asterisk Server") ."'>";
266     $img9  = "<img class='center' src='images/fax_small.png'          alt='F' title='"._("Fax Server") ."'>";
267     $img10 = "<img class='center' src='images/save.png'               alt='L' title='"._("Ldap Server") ."'>";
269     $empty    ="<img src='images/empty.png' style='width:16px ; height: 16px;' class='center' alt=''>";
271     /* Dynamic action col, depending on snapshot icons */
272     $action_col_size = 110;
273     if($this->parent->snapshotEnabled()){
274       $action_col_size += 38;
275     }
277     // User and Template  Images
278     $editlink = "<a href='?plug=".$_GET['plug']."&amp;id=%s&amp;act=edit_entry'>%s</a>";
280     /* ACL mapping */
281     $ui = get_userinfo();
282     $tabs = array(
283           "terminal"    => array("CLASS"=>"TERMTABS",     "TABCLASS" =>"termtabs",      "ACL"=> "terminal/termgeneric"),
284           "workstation" => array("CLASS"=>"WORKTABS",     "TABCLASS" =>"worktabs",      "ACL"=> "workstation/workgeneric"),
285           "server"      => array("CLASS"=>"SERVTABS",     "TABCLASS" =>"servtabs",      "ACL"=> "server/servgeneric"),
286           "printer"     => array("CLASS"=>"PRINTTABS",    "TABCLASS" =>"printtabs",     "ACL"=> "printer/printgeneric"),
287           "phone"       => array("CLASS"=>"PHONETABS",    "TABCLASS" =>"phonetabs",     "ACL"=> "phone/phoneGeneric"),
288           "winstation"  => array("CLASS"=>"WINTABS",      "TABCLASS" =>"wintabs",       "ACL"=> "winworkstation/wingeneric"),
289           "incoming"    => array("CLASS"=>"",             "TABCLASS" =>"",              "ACL"=> "incoming/systems"),
290           "component"   => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
293     $cnts = array("component" => 0 , "terminal" => 0 , "workstation" => 0 , 
294                   "printer" => 0 , "phone" => 0 , "server" => 0,
295                   "NewDevice" => 0, "winstation"=> 0);
297     // Test Every Entry and generate divlist Array
298     foreach($terminals as $key => $val){
300       /* Get system type, it is used to fetch the acls for the current object.
301           "winstation" acls are stored as 2winworkstation", so we have to map this here */
302       $type     = $this->parent->get_system_type($val);
303       if($type == "winstation") {
304         $acl_type = "winworkstation";
305       }else{
306         $acl_type = $type;
307       }
309       /* Map NewDevice acls to workstation acls */
310       if($type == "NewDevice" || $type == "ArpNewDevice"){
311         $type     = "incoming";
312         $acl_type = "incoming";
313       }
315       /* Get complete category acls */
316       $acl_all  = $ui->has_complete_category_acls($val['dn'],$acl_type) ;
317   
318       /* Get specific generic acls */
319       $acl      = $ui->get_permissions($val['dn'],$tabs[$type]['ACL']);
321       $action ="";
322       if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){
323         $action.= "<input class='center' type='image'
324           src='images/editcut.png' alt='"._("cut")."' name='cut_%KEY%' title='"._("Cut this entry")."'>&nbsp;";
325         $action.= "<input class='center' type='image'
326           src='images/editcopy.png' alt='"._("copy")."' name='copy_%KEY%' title='"._("Copy this entry")."'>&nbsp;";
327       }
328       $action.= "<input class='center' type='image' src='images/edit.png' 
329                     alt='"._("edit")."'     name='system_edit_%KEY%' title='"._("Edit system")."'>";
330       if(preg_match("/(c.*w|w.*c)/",$acl_all)){
331         $action.= $this->GetSnapShotActions($val['dn']);
332       }else{
333         $action.= $empty."&nbsp;".$empty."&nbsp;";
334       }
337       if(preg_match("/d/",$acl)){
338         $action.= "<input class='center' type='image' src='images/edittrash.png' 
339           alt='"._("delete")."'   name='system_del_%KEY%' title='"._("Delete system")."'>";
340       }else{
341         $action.= $empty;    
342       }
344       /* Generate picture list, which is currently disabled */
345       if(in_array("goCupsServer"    ,$val['objectClass'])) $cups    = $img1;   else $cups  =$empty;
346       if(in_array("goLogDBServer"   ,$val['objectClass'])) $logdb   = $img2;   else $logdb =$empty;
347       if(in_array("goSyslogServer"  ,$val['objectClass'])) $syslog  = $img3;   else $syslog=$empty;
348       if(in_array("goImapServer"    ,$val['objectClass'])) $imap    = $img4;   else $imap  =$empty;
349       if(in_array("sambaSamAccount" ,$val['objectClass'])) $samba   = $img5;   else $samba =$empty;
350       if(in_array("goShareServer"   ,$val['objectClass'])) $nfs     = $img6;   else $nfs   =$empty;
351       if(in_array("goKrbServer"     ,$val['objectClass'])) $krb     = $img7;   else $krb   =$empty;
352       if(in_array("goFonServer"     ,$val['objectClass'])) $fon     = $img8;   else $fon   =$empty;
353       if(in_array("goFaxServer"     ,$val['objectClass'])) $fax     = $img9;   else $fax   =$empty;
354       if(in_array("goLdapServer"    ,$val['objectClass'])) $ldap     = $img10;   else $ldap   =$empty;
356       $pics = $cups.$logdb.$syslog.$imap.$samba.$nfs.$krb.$fon.$fax.$ldap;
357       $pics = ""; // Pictures currently hidden
359       $val['cn'][0]= preg_replace('/\$$/', '', $val['cn'][0]);
361       // Generate Array to Add
362       $dsc= "";
363       if (isset($val['description'][0])){
364         $dsc= " [".$val['description'][0]."]";
365       }
366       if((isset($val['is_new']))&&(!empty($val['is_new']))){
367         $display= $val["cn"][0]." ".$val['is_new'].$dsc;
368       }else{
369         $display= $val["cn"][0].$dsc;
370       }
372      
373       /* Check if this is a terminal/workstation && if we are allowed to change the gotoRootPasswd */
374       $pwd_acl =""; 
375       if(in_array("gotoWorkstation",$val['objectClass'])){
376         $pwd_acl = $ui->get_permissions($val['dn'],"workstation/workgeneric","gotoRootPasswd");
377       }    
378       if(in_array("gotoTerminal",$val['objectClass'])){
379         $pwd_acl = $ui->get_permissions($val['dn'],"terminal/termgeneric","gotoRootPasswd");
380       }    
381       if(preg_match("/w/",$pwd_acl)){
382         $action2 = "<input class='center' type='image' src='images/certs.png' alt='"._("Password")."'   name='system_setpwd_%KEY%' title='"._("Set root password")."'>";
383       }else{
384         $action2 = $empty;
385       }
388       if(in_array("gotoWorkstation",$val['objectClass'])){
389         $action2= "<input class='center' type='image' src='images/cdrom.png' alt='"._("Create CD")."'   
390                       name='gen_cd_%KEY%' title='"._("Create FAI CD")."'>&nbsp;".$action2;
391       }else{
392         $action2= $empty.$action2;
393       }
395       if(isset($val['message'])){
396         $display.= "  (".$val['message'].")";
397       }
399       $img    = $this->parent->convert_list($val);
401       /* Cutted objects should be displayed in light grey */
402       if($this->parent->CopyPasteHandler){
403         foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){
404           if($queue_data['dn'] == $val['dn']) {
405             $display = "<font color='#999999'>".$display."</font>";
406             break;
407           }
408         }
409       }
411       $type = $this->parent->get_system_type($val);
412       if($type == "ArpNewDevice"){
413         $type = "NewDevice";
414       }
415       $cnts[$type] ++;
418       /* Create each field */
419       $field0 = array("string" => "<input type='checkbox' id='item_selected_".$key."' name='item_selected_".$key."'>" ,
420                       "attach" => "style='width:20px;'");
422       $field1 = array("string" => sprintf($img['img'],$val['dn']), "attach" => "style='text-align:center;width:20px;'");
423       $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', '&nbsp;', @LDAP::fix($val['dn']))."'");
424       $field3 = array("string" => preg_replace("/%KEY%/", "$key", $action2.$action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'");
425       $this->AddElement( array($field0,$field1,$field2,$field3));
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 = _("Number of listed servers");
435     $num_ws_str  = _("Number of listed workstations");
436     $num_ter_str = _("Number of listed terminals");
437     $num_pho_str = _("Number of listed phones");
438     $num_prt_str = _("Number of listed printers");
439     $num_com_str = _("Number of listed network components");
440     $num_new_str = _("Number of listed new devices");
441     $num_wws_str = _("Number of listed windows workstations");
442     $num_dep_str = _("Number of listed departments");
444     $str = "<img class='center' src='images/select_server.png'
445       title='".$num_ser_str."' alt='".$num_ser_str."'>&nbsp;".$cnts['server']."&nbsp;&nbsp;&nbsp;&nbsp;";
446     $str.= "<img class='center' src='images/select_workstation.png'
447       title='".$num_ws_str."' alt='".$num_ws_str."'>&nbsp;".$cnts['workstation']."&nbsp;&nbsp;&nbsp;&nbsp;";
448     $str.= "<img class='center' src='images/select_terminal.png'
449       title='".$num_ter_str."' alt='".$num_ter_str."'>&nbsp;".$cnts['terminal']."&nbsp;&nbsp;&nbsp;&nbsp;";
450     $str.= "<img class='center' src='images/select_phone.png'
451       title='".$num_pho_str."' alt='".$num_pho_str."'>&nbsp;".$cnts['phone']."&nbsp;&nbsp;&nbsp;&nbsp;";
452     $str.= "<img class='center' src='images/select_printer.png'
453       title='".$num_prt_str."' alt='".$num_prt_str."'>&nbsp;".$cnts['printer']."&nbsp;&nbsp;&nbsp;&nbsp;";
454     $str.= "<img class='center' src='images/select_component.png'
455       title='".$num_com_str."' alt='".$num_com_str."'>&nbsp;".$cnts['component']."&nbsp;&nbsp;&nbsp;&nbsp;";
456     $str.= "<img class='center' src='images/select_newsystem.png'
457       title='".$num_new_str."' alt='".$num_new_str."'>&nbsp;".$cnts['NewDevice']."&nbsp;&nbsp;&nbsp;&nbsp;";
458     $str.= "<img class='center' src='images/select_winstation.png'
459       title='".$num_wws_str."' alt='".$num_wws_str."'>&nbsp;".$cnts['winstation']."&nbsp;&nbsp;&nbsp;&nbsp;";
460     $str.= "<img class='center' src='images/folder.png'
461       title='".$num_dep_str."' alt='".$num_dep_str."'>&nbsp;".$num_deps."&nbsp;&nbsp;&nbsp;&nbsp;";
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   }
481 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
482 ?>