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 $
14 ** DESCRIPTION : Service Administration page.
15 ** Input parameters: action (POST) : empty, 'Create'
16 ** servcode (POST) : short name of the service to create or remove
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
28 **************************************************************************/
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.
35 ******************************/
37 // RCSID = "$Id: services.php,v 1.1 2003-09-01 06:53:22 arjen Exp $";
39 ini_set('include_path', '.:./classes:../phpclasses');
41 require_once('page.class.php');
43 function clientscripts()
48 <script language='JavaScript'>
50 function CheckCreate(f)
52 if (f.servcode.value == "")
54 alert("You must supply a service code");
60 function CheckRemove(f)
62 var message = "Are you sure you want to remove service ";
63 message += f.servcode.value;
66 return confirm(message);
74 class service_page extends page
82 if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['servcode']))
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'] . "')");
90 if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['servcode']))
92 pg_exec($this->database, "DELETE FROM service WHERE servicecode='"
93 . $_POST['servcode'] . "'");
96 if (isset($_GET['servcode']))
98 echo "<h1>Detailed information for service " . $_GET['servcode'] . "</h1><br>\n";
100 if (isset($_POST['action']) && $_POST['action'] == 'Save Changes')
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'] . "'";
107 pg_exec($this->database, $qry);
110 $res = pg_exec($this->database, "SELECT * FROM service
111 WHERE servicecode='" . $_GET['servcode'] . "'");
112 $srv = pg_fetch_object($res, 0);
114 echo "<form action='services.php?servcode=" . $srv->servicecode . "' method='POST'>";
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++)
122 echo "<option value='$prior'";
123 if ($prior == $srv->default_priority)
125 echo " selected='true'";
127 echo ">$prior</option>\n";
130 echo "<tr><td>Maximum priority</td><td><select name='maxprior'>";
131 for ($prior = 1; $prior < 6; $prior++)
133 echo "<option value='$prior'";
134 if ($prior == $srv->max_priority)
136 echo " selected='true'";
138 echo ">$prior</option>\n";
142 echo "<input type='submit' name='action' value='Save Changes'>";
147 echo "<h1>Service Administration</h1><hr>";
149 $res = pg_exec($this->database, "SELECT * FROM service ORDER BY servicecode");
152 echo "<tr><th>Service code</th><th>Name</th><th>Priority</th><th>Max priority</th><tr>";
154 while ($srv < pg_numrows($res))
156 $u = pg_fetch_object($res, $srv);
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>
161 <?php echo $u->servicename ?>
163 <?php echo $u->default_priority ?>
165 <?php echo $u->max_priority ?>
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'>
179 <h2>Create new service:</h2>
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>
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>
200 <input type='submit' name='action' value='Create'>
209 $page = new service_page("Gnucomo User Administration");