The buttonbar at the top of each page is now a fixed 'div' element
[gnucomo.git] / src / web / classes.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      : classes.php
11 **      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
12 **      VERSION NUMBER : $Revision: 1.2 $
13 **
14 **  DESCRIPTION      :  Parameter classes Administration page.
15 **                      Input parameters: action (POST) : empty, 'Create'
16 **                            classname (POST) : short name of the class 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: classes.php,v $
32    Revision 1.2  2007-11-21 14:38:06  arjen
33    The buttonbar at the top of each page is now a fixed 'div' element
34    instead of a framed page.
35    Contributed by Edwin Nadorp.
36
37    Revision 1.1  2005/06/04 07:22:40  arjen
38    New page: Parameter classes administration.
39
40
41 ******************************/
42
43 // RCSID = "$Id: classes.php,v 1.2 2007-11-21 14:38:06 arjen Exp $";
44
45 ini_set('include_path', '.:./classes:../phpclasses');
46
47 require_once('page.class.php');
48
49 function clientscripts()
50 {
51
52 ?>
53
54 <script type='text/ecmascript'>
55
56 function CheckCreate(f)
57 {
58    if (f.classname.value == "")
59    {
60       alert("You must supply a class name");
61       return false;
62    }
63
64    if (f.propname.value == "")
65    {
66       alert("You must supply a property name");
67       return false;
68    }
69    return true;
70 }
71
72 function CheckRemove(f)
73 {
74    var message = "Are you sure you want to remove property ";
75    message += f.propname.value;
76    message += " of class ";
77    message += f.classname.value;
78    message += " ?";
79
80    return confirm(message);
81 }
82
83 </script>
84
85 <?php
86 }
87
88 class class_page extends page
89 {
90
91    function Body()
92    {
93
94    clientscripts();
95
96    if (isset($_POST['action']) && $_POST['action'] == 'Create'
97        && !empty($_POST['classname']) && !empty($_POST['propname']))
98    {
99       pg_exec($this->database, "INSERT INTO parameter_class
100                        (name, property_name, property_type, notify) VALUES ('"
101                      . $_POST['classname'] . "','" . $_POST['propname'] . "','STATIC', 'true')");
102    }
103
104    if (isset($_POST['action']) && $_POST['action'] == 'Remove'
105        && !empty($_POST['classname']) && !empty($_POST['propname']))
106    {
107       pg_exec($this->database, "DELETE FROM parameter_class WHERE name='"
108                                 . $_POST['classname'] . "' AND property_name='" . $_POST['propname'] . "'");
109    }
110
111    if (isset($_GET['classname']) && isset($_GET['propname']))
112    {
113       echo "<script type='text/ecmascript'>document.getElementById('menu_title').innerHTML = '<h1>Detailed information<\/h1>'</script><br>";
114       echo "<h1>for property " . $_GET['propname']
115            . " of class " . $_GET['classname'] . "</h1><br>\n";
116
117       if (isset($_POST['action']) && $_POST['action'] == 'Save Changes')
118       {
119          $notify = 'f';
120          if (!empty($_POST['notify']) && $_POST['notify'] == 'on')
121          {
122             $notify='t';
123          }
124          $qry = "UPDATE parameter_class SET description='" . $_POST['description'] . "'";
125          $qry .= ", property_type='" . $_POST['proptype'] . "'";
126          $qry .= ", notify='" . $notify . "'";
127          if (isset($_POST['min']))
128          {
129             $qry .= ", min='" . $_POST['min'] . "'";
130          }
131          if (isset($_POST['max']))
132          {
133             $qry .= ", max='" . $_POST['max'] . "'";
134          }
135          $qry .= " WHERE name='" . $_GET['classname'] . "'";
136          $qry .= " AND property_name='" . $_GET['propname'] . "'";
137
138          echo $qry . "<br>";
139          pg_exec($this->database, $qry);
140          echo pg_errormessage($this->database) . "<br>";
141          print_r($_POST);
142       }
143
144       $res = pg_exec($this->database, "SELECT * FROM parameter_class
145                                        WHERE name='" . $_GET['classname']
146                                     . "' AND property_name='" . $_GET['propname'] . "'");
147       $cls = pg_fetch_object($res, 0);
148
149       echo "<form action='classes.php?classname=" . $cls->name . "&amp;propname=" . $cls->property_name . "' method='POST'>";
150       echo "<table>";
151
152       echo "<tr><td>Description</td><td><input name='description' type='text' value='";
153       echo $cls->description . "'></td></tr>";
154
155       echo "<tr><td>Property type</td><td><input name='proptype' type='radio' value='STATIC'";
156       if ($cls->property_type == "STATIC")
157       {
158          echo " checked='true'";
159       }
160       echo ">STATIC<br><input name='proptype' type='radio' value='DYNAMIC'";
161       if ($cls->property_type == "DYNAMIC")
162       {
163          echo " checked='true'";
164       }
165       echo ">DYNAMIC</td></tr>";
166
167       echo "<tr><td>Notify Changes</td><td><input type='checkbox' name='notify'";
168       if ($cls->notify == 't')
169       {
170          echo " checked='true'";
171       }
172       echo "></td></tr>";
173       if ($cls->property_type == "DYNAMIC")
174       {
175          echo "<tr><td>Default minimum</td><td><input type='text' name='min' value='";
176          echo $cls->min;
177          echo "'></td></tr>";
178          echo "<tr><td>Default maximum</td><td><input type='text' name='max' value='";
179          echo $cls->max;
180          echo "'></td></tr>";
181       }
182       echo "</table>";
183       echo "<input type='submit' name='action' value='Save Changes'>";
184       echo "</form>";
185    }
186    else
187    {
188    echo "<script type='text/ecmascript'>document.getElementById('menu_title').innerHTML = '<h1>Parameter Classes Administration<\/h1>'</script><br>";
189
190    $res = pg_exec($this->database, "SELECT name, property_name, description FROM parameter_class
191                                     ORDER BY name, property_name");
192
193    echo "<table>";
194    echo "<tr><th>Class</th><th>Property</th><th>Description</th></tr>";
195    $cls = 0;
196    while ($cls < pg_numrows($res))
197    {
198       $u = pg_fetch_object($res, $cls);
199       ?>
200       <tr><td align='center'><a href='classes.php?classname=<?php echo $u->name?>&amp;propname=<?php echo $u->property_name ?>'><img src='change.png'></a><br>
201              <b><?php echo $u->name ?></b>
202       </td><td>
203          <?php echo $u->property_name ?>
204       </td><td>
205          <?php echo $u->description ?>
206       </td><td>
207           <form action='classes.php' method='post' onSubmit='return CheckRemove(this)'>
208               <input type='hidden' name='classname' value='<?php echo $u->name ?>'>
209               <input type='hidden' name='propname' value='<?php echo $u->property_name ?>'>
210               <input type='submit' name='action' value='Remove'>
211           </form>
212       </td></tr>
213       <?php
214       $cls++;
215    }
216    echo "</table>";
217
218 ?>
219
220 <h2>Create new parameter class property:</h2>
221
222 <form action='classes.php' method='post' onSubmit='return CheckCreate(this)'>
223 Class name: <input name='classname' type='text'>
224 Property name: <input name='propname' type='text'>
225 <br>
226 <input type='submit' name='action' value='Create'>
227 </form>
228
229 <?php
230    }
231    }
232 }
233
234 $page = new class_page("Gnucomo Parameter Classes Administration");
235
236 $page->Showpage();
237
238 ?>