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