New page to enter and modify services.
[gnucomo.git] / src / web / services.php
1 <?php 
2
3 /**************************************************************************
4 **  (c) Copyright 2003, Andromeda Technology & Automation
5 ** This is free software; you can redistribute it and/or modify it under the
6 ** terms of the GNU General Public License, see the file COPYING.
7 ***************************************************************************
8 ** MODULE INFORMATION *
9 ***********************
10 **      FILE NAME      : services.php
11 **      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
12 **      VERSION NUMBER : $Revision: 1.1 $
13 **
14 **  DESCRIPTION      :  Service Administration page.
15 **                      Input parameters: action (POST) : empty, 'Create'
16 **                              servcode (POST) : short name of the service to create or remove
17 **
18 **  EXPORTED OBJECTS : 
19 **  LOCAL    OBJECTS : 
20 **  MODULES  USED    :
21 ***************************************************************************
22 **  ADMINISTRATIVE INFORMATION *
23 ********************************
24 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
25 **      CREATION DATE   : Aug 04, 2003
26 **      LAST UPDATE     : Aug 28, 2003
27 **      MODIFICATIONS   : 
28 **************************************************************************/
29
30 /*****************************
31    $Log: services.php,v $
32    Revision 1.1  2003-09-01 06:53:22  arjen
33    New page to enter and modify services.
34
35 ******************************/
36
37 // RCSID = "$Id: services.php,v 1.1 2003-09-01 06:53:22 arjen Exp $";
38
39 ini_set('include_path', '.:./classes:../phpclasses');
40
41 require_once('page.class.php');
42
43 function clientscripts()
44 {
45
46 ?>
47
48 <script language='JavaScript'>
49
50 function CheckCreate(f)
51 {
52    if (f.servcode.value == "")
53    {
54       alert("You must supply a service code");
55       return false;
56    }
57    return true;
58 }
59
60 function CheckRemove(f)
61 {
62    var message = "Are you sure you want to remove service ";
63    message += f.servcode.value;
64    message += " ?";
65
66    return confirm(message);
67 }
68
69 </script>
70
71 <?php
72 }
73
74 class service_page extends page
75 {
76
77    function Body()
78    {
79
80    clientscripts();
81
82    if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['servcode']))
83    {
84       pg_exec($this->database, "INSERT INTO service
85                        (servicecode, servicename, default_priority, max_priority) VALUES ('"
86                      . $_POST['servcode'] . "','" . $_POST['servname'] . "','"
87                      . $_POST['defprior'] . "','" . $_POST['maxprior'] . "')");
88    }
89
90    if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['servcode']))
91    {
92       pg_exec($this->database, "DELETE FROM service WHERE servicecode='"
93                                 . $_POST['servcode'] . "'");
94    }
95
96    if (isset($_GET['servcode']))
97    {
98       echo "<h1>Detailed information for service " . $_GET['servcode'] . "</h1><br>\n";
99
100       if (isset($_POST['action']) && $_POST['action'] == 'Save Changes')
101       {
102          $qry = "UPDATE service SET servicename='" . $_POST['servname'] . "'";
103          $qry .= ", default_priority='" . $_POST['defprior'] . "'";
104          $qry .= ", max_priority='" . $_POST['maxprior'] . "'";
105          $qry .= " WHERE servicecode='" . $_GET['servcode'] . "'";
106
107          pg_exec($this->database, $qry);
108       }
109
110       $res = pg_exec($this->database, "SELECT * FROM service
111                                        WHERE servicecode='" . $_GET['servcode'] . "'");
112       $srv = pg_fetch_object($res, 0);
113
114       echo "<form action='services.php?servcode=" . $srv->servicecode . "' method='POST'>";
115       echo "<table>";
116
117       echo "<tr><td>Service name</td><td><input name='servname' type='text' value='";
118       echo $srv->servicename . "'></td></tr>";
119       echo "<tr><td>Default priority</td><td><select name='defprior'>";
120       for ($prior = 1; $prior < 6; $prior++)
121       {
122          echo "<option value='$prior'";
123          if ($prior == $srv->default_priority)
124          {
125             echo " selected='true'";
126          }
127          echo ">$prior</option>\n";
128       }
129       echo "</select>";
130       echo "<tr><td>Maximum priority</td><td><select name='maxprior'>";
131       for ($prior = 1; $prior < 6; $prior++)
132       {
133          echo "<option value='$prior'";
134          if ($prior == $srv->max_priority)
135          {
136             echo " selected='true'";
137          }
138          echo ">$prior</option>\n";
139       }
140       echo "</select>";
141       echo "</table>";
142       echo "<input type='submit' name='action' value='Save Changes'>";
143       echo "</form>";
144    }
145    else
146    {
147    echo "<h1>Service Administration</h1><hr>";
148
149    $res = pg_exec($this->database, "SELECT * FROM service ORDER BY servicecode");
150
151    echo "<table>";
152    echo "<tr><th>Service code</th><th>Name</th><th>Priority</th><th>Max priority</th><tr>";
153    $srv = 0;
154    while ($srv < pg_numrows($res))
155    {
156       $u = pg_fetch_object($res, $srv);
157       ?>
158       <tr><td align='center'><a href='services.php?servcode=<?php echo $u->servicecode?>'><img src='service.png'></a><br>
159              <b><?php echo $u->servicecode ?></b>
160       </td><td>
161          <?php echo $u->servicename ?>
162       </td><td>
163          <?php echo $u->default_priority ?>
164       </td><td>
165          <?php echo $u->max_priority ?>
166       </td><td>
167           <form action='services.php' method='post' onSubmit='return CheckRemove(this)'>
168               <input type='hidden' name='servcode' value='<?php echo $u->servicecode ?>'>
169               <input type='submit' name='action' value='Remove'>
170           </form>
171       </td></tr>
172       <?php
173       $srv++;
174    }
175    echo "</table>";
176
177 ?>
178
179 <h2>Create new service:</h2>
180 <p>
181
182 <form action='services.php' method='post' onSubmit='return CheckCreate(this)'>
183 Service code: <input name='servcode' type='text'>
184 Service name: <input name='servname' type='text'>
185 Default priority: <select name='defprior'>
186 <option value='1'>1</option>
187 <option value='2'>2</option>
188 <option value='3'>3</option>
189 <option value='4'>4</option>
190 <option value='5'>5</option>
191 </select>
192 Maximum priority: <select name='maxprior'>
193 <option value='1'>1</option>
194 <option value='2'>2</option>
195 <option value='3'>3</option>
196 <option value='4'>4</option>
197 <option value='5' selected='true'>5</option>
198 </select>
199 <br>
200 <input type='submit' name='action' value='Create'>
201 </form>
202 </p>
203
204 <?php
205    }
206    }
207 }
208
209 $page = new service_page("Gnucomo User Administration");
210
211 $page->Showpage();
212
213 ?>