Code

Updated workstation - Startup
[gosa.git] / plugins / 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();
16     /* Set list strings */
17     $this->SetTitle(_("Installed services"));
18     $this->SetSummary(_("Installed services"));
20     /* Result page will look like a headpage */
21 //    $this->SetHeadpageMode();
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     $this->SetHeadpageMode();
34   }
36   function GenHeader()
37   {
38     /* Prepare departments,
39        which are shown in the listbox on top of the listbox
40      */
41     $options= "";
42     foreach ($this->config->idepartments as $key => $value){
43       if ($this->selectedBase == $key){
44         $options.= "<option selected='selected' value='$key'>$value</option>";
45       } else {
46         $options.= "<option value='$key'>$value</option>";
47       }
48     }
49     $listhead = "<div style='background:#F0F0F9;padding:5px;'>".
50     " <input type='image' align='middle' src='images/select_new_server.png' class='center' 
51         name='addNewService' alt='"._("Add service")."' title='"._("Add new service")."'>&nbsp;".
52     " <img class='center' src='images/list_seperator.png' align='middle' alt='' height='16' width='1'>&nbsp;".
53     " <input type='image' align='middle' src='images/status_start_all.png' class='center'
54         name='startServices' alt='"._("Start all")."' title='"._("Start all services")."'>&nbsp;".
55     " <input type='image' align='middle' src='images/status_stop_all.png'  class='center'   
56         name='stopServices' alt='"._("Stop service")."' title='"._("Stop all services")."'>&nbsp;".
57     " <input type='image' align='middle' src='images/status_restart_all.png'    class='center'
58         name='restartServices' alt='"._("Restart service")."' title='"._("Restart all services")."'>&nbsp;".
59     "</div>";
60     $this->SetListHeader($listhead);
61   }
63   function execute()
64   {
65     $this->ClearElementsList();
66     $this->GenHeader();
67   }
69   function setEntries($list)
70   {
71     $tmp = array();
72     foreach($list as $name => $entry){
73       $tmp[$name] = $entry['Message']; 
74     }
76     natcasesort($tmp);
77     $tmp2 = array();
78     foreach($tmp as $name => $value){
79       $tmp2[$name] = $list[$name];
80     }
82     $ui = get_userinfo();
84     foreach($tmp2 as $name => $entry){
85  
86       switch($entry['Status']){
87         case ''      : $str ="&nbsp;";break;
88         case SERVICE_STOPPED  : $str ="<img src='images/status_stopped.png' title='"._("Stopped")."'>"; break;
89         case SERVICE_STARTED  : $str ="<img src='images/status_running.png' title='"._("Started")."'>"; break;
90         case SERVICE_RESTARTED : $str ="<img src='images/status_restarting.png' title='"._("Restarting")."' alt='R'>"; break;
91         default: $str= "<img src='images/select_user.png' alt='".$entry['Status']."' title='"._("User status")." : ".$entry['Status']."'>";
92       }
94       /* Get acls */
95       $acl = $ui->get_permissions($this->parent->dn,"server/".$name);
96       if(preg_match("/w/i",$acl) && !preg_match("/r/i",$acl)){
97         continue;
98       }
99   
100       $WasAccount = $this->parent->plugins[$name] -> initially_was_account;    
101   
102       $field1 = array("string" => $str ,"attach" => "style='width:20px;'");
103       $field2 = array("string" => $entry['Message'] );
105       $actions ="";
106       if($entry['AllowStart'] && $WasAccount){
107         $actions .= "&nbsp;<input type='image' name='StartSingleService_".$name."' src='images/status_start.png'
108                             title='"._("Start service")."'>";
109       }else{
110         $actions .= "&nbsp;<img src='images/empty' width='16' alt=''>";
111       }
112       if($entry['AllowStart'] && $WasAccount){
113         $actions .= "&nbsp;<input type='image' name='StopSingleService_".$name."' src='images/status_stop.png'
114                             title='"._("Stop service")."'>";
115       }else{
116         $actions .= "&nbsp;<img src='images/empty' width='16' alt=''>";
117       }
118       if($entry['AllowStart'] && $WasAccount){
119         $actions .= "&nbsp;<input type='image' name='RestartSingleService_".$name."' src='images/status_restart.png'
120                             title='"._("Restart service")."'>";
121       }else{
122         $actions .= "&nbsp;<img src='images/empty' width='16' alt=''>";
123       }
125       /* Check if edit is enabled and allowed for current service */
126       if($entry['AllowEdit'] && preg_match("/(r|w)/i",$acl)){
127         $actions .= "&nbsp;<input type='image' name='EditSingleService_".$name."' src='images/edit.png'
128                             title='"._("Edit service")."'>";
129       }else{
130         $actions .= "&nbsp;<img src='images/empty' width='16' alt=''>";
131       }
133       /* Check if remove is enabled and allowed for current service */
134       if($entry['AllowRemove'] && preg_match("/d/i",$acl)){
135         $actions .= "&nbsp;<input type='image' name='RemoveSingleService_".$name."' src='images/edittrash.png'
136                             title='"._("Remove service")."'>";
137       }else{
138         $actions .= "&nbsp;<img src='images/empty' width='16' alt=''>";
139       }
141       $field3 = array("string" => $actions ,"attach" => "style='width:100px;border-right:0px;'");
142       $this->AddElement(array($field1,$field2,$field3));
143     }
144   }
146   function Save()
147   {
148     MultiSelectWindow :: Save();  
149   }
151   function save_object()
152   {
153     /* Save automatic created POSTs like regex, checkboxes */
154     MultiSelectWindow :: save_object();   
155   }
157 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
158 ?>