Code

Added multi actions
[gosa.git] / gosa-plugins / systems / admin / systems / class_divListSystemService.inc
1 <?php
3 class divListSystemService extends MultiSelectWindow
4 {
5   /* CheckBoxes, to change default values modify $this->AddCheckBox */
6   var $parent             ;
7   var $ui                 ;
9   function divListSystemService ($config,$parent)
10   {
11     MultiSelectWindow::MultiSelectWindow($config,"SystemService", "server");
12     
13     $this->parent       = $parent;
14     $this->ui           = get_userinfo();
15     $this->EnableJSLeaveMsg(TRUE);
17     /* Set list strings */
18     $this->SetTitle(_("Installed services"));
19     $this->SetSummary(_("Installed services"));
21     /* Result page will look like a headpage */
22     $this->SetInformation(_("This menu allows you to add, remove and configure the properties of a specific service."));
24     /* Disable buttonsm */
25     $this->EnableCloseButton(false);
26     $this->EnableSaveButton (false);
28     /* set Page header */
29     $this->AddHeader(array("string"=>"&nbsp;","attach"=>"style='width:20px;'"));
30     $this->AddHeader(array("string"=>_("Service name")));
31     $this->AddHeader(array("string"=>_("Actions"),"attach"=>"style='width:100px;border-right:0px;'"));
32     $this->HideFilterPart();
33   }
35   function GenHeader()
36   {
37     /* Prepare departments,
38        which are shown in the listbox on top of the listbox
39      */
40     $listhead = "<div style='background:#F0F0F9;height:16px;padding:0px;'>".
41     " <input type='image' align='middle' src='images/select_new_server.png' class='center' 
42         name='addNewService' alt='"._("Add service")."' title='"._("Add new service")."'>&nbsp;".
43     " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
44     " <input type='image' align='middle' src='images/status_start_all.png' class='center'
45         name='startServices' alt='"._("Start all")."' title='"._("Start all services")."'>&nbsp;".
46     " <input type='image' align='middle' src='images/status_stop_all.png'  class='center'   
47         name='stopServices' alt='"._("Stop service")."' title='"._("Stop all services")."'>&nbsp;".
48     " <input type='image' align='middle' src='images/status_restart_all.png'    class='center'
49         name='restartServices' alt='"._("Restart service")."' title='"._("Restart all services")."'>&nbsp;".
50     "</div>";
51     $this->SetListHeader($listhead);
52   }
54   function execute()
55   {
56     $this->ClearElementsList();
57     $this->GenHeader();
58   }
60   function setEntries($list)
61   {
62     $tmp = array();
63     foreach($list as $name => $entry){
64       $tmp[$name] = $entry['Message']; 
65     }
67     natcasesort($tmp);
68     $tmp2 = array();
69     foreach($tmp as $name => $value){
70       $tmp2[$name] = $list[$name];
71     }
73     $ui = get_userinfo();
75     foreach($tmp2 as $name => $entry){
76  
77       switch($entry['Status']){
78         case ''      : $str ="&nbsp;";break;
79         case SERVICE_STOPPED  : $str ="<img src='images/status_stopped.png' title='"._("Stopped")."'>"; break;
80         case SERVICE_STARTED  : $str ="<img src='images/status_running.png' title='"._("Started")."'>"; break;
81         case SERVICE_RESTARTED : $str ="<img src='images/status_restarting.png' title='"._("Restarting")."' alt='R'>"; break;
82         default: $str= "<img src='images/select_user.png' alt='".$entry['Status']."' title='"._("User status")." : ".$entry['Status']."'>";
83       }
85       /* Get acls */
86       $acl = $ui->get_permissions($this->parent->dn,"server/".$name);
87       if(preg_match("/w/i",$acl) && !preg_match("/r/i",$acl)){
88         continue;
89       }
90   
91       $WasAccount = $this->parent->plugins[$name] -> initially_was_account;    
92   
93       $plug = $_GET['plug'];
94       $link = "<a href='?plug=".$plug."&amp;act=open&amp;id=".$name."'>".$entry['Message']."</a>";
96       $field1 = array("string" => $str ,"attach" => "style='width:20px;'");
97       $field2 = array("string" => $link);
99       $actions ="";
100       if($entry['AllowStart'] && $WasAccount){
101         $actions .= "&nbsp;<input type='image' name='StartSingleService_".$name."' src='images/status_start.png'
102                             title='"._("Start service")."'>";
103       }else{
104         $actions .= "&nbsp;<img src='images/empty.png' width='16' alt=''>";
105       }
106       if($entry['AllowStart'] && $WasAccount){
107         $actions .= "&nbsp;<input type='image' name='StopSingleService_".$name."' src='images/status_stop.png'
108                             title='"._("Stop service")."'>";
109       }else{
110         $actions .= "&nbsp;<img src='images/empty.png' width='16' alt=''>";
111       }
112       if($entry['AllowStart'] && $WasAccount){
113         $actions .= "&nbsp;<input type='image' name='RestartSingleService_".$name."' src='images/status_restart.png'
114                             title='"._("Restart service")."'>";
115       }else{
116         $actions .= "&nbsp;<img src='images/empty.png' width='16' alt=''>";
117       }
119       /* Check if edit is enabled and allowed for current service */
120       if($entry['AllowEdit'] && preg_match("/(r|w)/i",$acl)){
121         $actions .= "&nbsp;<input type='image' name='EditSingleService_".$name."' src='images/edit.png'
122                             title='"._("Edit service")."'>";
123       }else{
124         $actions .= "&nbsp;<img src='images/empty.png' width='16' alt=''>";
125       }
127       /* Check if remove is enabled and allowed for current service */
128       if($entry['AllowRemove'] && preg_match("/d/i",$acl)){
129         $actions .= "&nbsp;<input type='image' name='RemoveSingleService_".$name."' src='images/edittrash.png'
130                             title='"._("Remove service")."'>";
131       }else{
132         $actions .= "&nbsp;<img src='images/empty.png' width='16' alt=''>";
133       }
135       $field3 = array("string" => $actions ,"attach" => "style='width:100px;border-right:0px;'");
136       $this->AddElement(array($field1,$field2,$field3));
137     }
138   }
140   function Save()
141   {
142     MultiSelectWindow :: Save();  
143   }
145   function save_object()
146   {
147     /* Save automatic created POSTs like regex, checkboxes */
148     MultiSelectWindow :: save_object();   
149   }
151 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
152 ?>