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 : parameter.php
11 ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
12 ** VERSION NUMBER : $Revision: 1.10 $
14 ** DESCRIPTION : Parameter administration for a specific object.
15 ** Input - GET[oid] : Object id
20 ***************************************************************************
21 ** ADMINISTRATIVE INFORMATION *
22 ********************************
23 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
24 ** CREATION DATE : Dec 04, 2002
25 ** LAST UPDATE : Aug 04, 2003
27 **************************************************************************/
29 /*****************************
30 $Log: parameter.php,v $
31 Revision 1.10 2007-11-28 17:02:23 arjen
32 Added fields to edit the range of a DYNAMIC property.
34 Revision 1.9 2007/11/21 14:38:06 arjen
35 The buttonbar at the top of each page is now a fixed 'div' element
36 instead of a framed page.
37 Contributed by Edwin Nadorp.
39 Revision 1.8 2007/01/11 13:44:29 arjen
40 Manually edit parameters.
41 View logs from abusing IP addresses.
43 Revision 1.7 2003/12/03 08:03:28 arjen
44 Optionally show or hide removed parameters from the parameter
47 Revision 1.6 2003/08/14 10:33:01 arjen
48 Added performance measurement.
50 Revision 1.5 2003/07/15 11:06:45 arjen
51 Removed parameters are displayed in a shaded style.
53 Revision 1.4 2003/02/21 08:50:12 arjen
54 Database optimizations.
56 Revision 1.3 2003/02/13 09:01:29 arjen
57 All web interface pages use the page class.
59 Revision 1.2 2003/02/05 09:47:39 arjen
60 Display the difference of all package class parameters for two objects
62 ******************************/
64 // RCSID = "$Id: parameter.php,v 1.10 2007-11-28 17:02:23 arjen Exp $";
67 ini_set('include_path', '.:./classes:../phpclasses');
69 require_once('page.class.php');
74 function getmicrotime()
76 list ($usec, $sec) = explode(" ", microtime());
77 return (float)$sec + (float)$usec;
80 function object_selection($db, $skip_oid)
82 /* Create and print an HTML option list of objects */
84 $res = pg_exec("SELECT objectid, objectname FROM object WHERE objectid != "
85 . $skip_oid . "ORDER BY objectname");
86 for ($row = 0; $row < pg_numrows($res); $row++)
88 $obj = pg_fetch_object($res, $row);
89 echo "<option value='" . $obj->objectid . "'>";
90 echo $obj->objectname;
95 class param_page extends page
101 if (!empty($_GET['oid']))
103 $ObjId = $_GET['oid'];
105 $res = pg_exec($this->database, "SELECT objectname FROM object WHERE objectid=CAST('" . $ObjId ."' AS BIGINT)");
106 $obj = pg_fetch_object($res, 0);
107 echo "<script type='text/ecmascript'>document.getElementById('menu_title').innerHTML = '<h1>Parameters for " . $obj->objectname . "<\/h1>'</script><br>";
109 if( isset($_POST['action']) ) {
110 echo "Action = " . $_POST['action'] . "<br>";
112 // See if we have an update for the database
113 if (isset($_POST['action']) && $_POST['action'] == 'Create Parameter')
115 $name = $_POST['paramname'];
116 $class = $_POST['paramclass'];
117 $description = $_POST['paramdescr'];
119 echo "<h2>Creating parameter $name of class $class.</h2>";
121 echo "<form action='parameter.php?oid=$ObjId' method='post'>";
122 echo "<input type='hidden' name='paramclass' value='$class'>";
123 echo "<input type='hidden' name='paramname' value='$name'>";
124 echo "Description : <input type='text' name='paramdescr' value='$description'>";
127 echo "<tr><th>Property</th><th>Description</th><th>Value</th></tr>";
129 $class_res = pg_exec($this->database, "SELECT * FROM parameter_class WHERE name='$class'");
130 for ($row = 0; $row < pg_numrows($class_res); $row++)
132 $prop = pg_fetch_object($class_res, $row);
134 echo "<td>", $prop->property_name, "</td><td>", $prop->description, "</td>";
135 echo "<td><input type='text' name='" . $prop->property_name . "'></td>";
139 echo "<input type='submit' name='action' value='Save New Parameter'>";
143 if (isset($_POST['action']) && $_POST['action'] == 'Save New Parameter')
145 $name = $_POST['paramname'];
146 $class = $_POST['paramclass'];
147 $description = $_POST['paramdescr'];
149 echo "<h2>Saving new parameter $name of class $class.</h2>";
151 echo "Description : $description";
154 $insertion = "insert into parameter (objectid, name, class, description) values ";
155 $insertion .= "('$ObjId', '$name', '$class', '$description')";
156 pg_exec($this->database, $insertion);
157 $par = pg_fetch_object(pg_exec($this->database, "select currval('paramid_seq')"), 0);
160 echo "<tr><th>Property</th><th>Description</th><th>Value</th></tr>";
162 $class_res = pg_exec($this->database, "SELECT * FROM parameter_class WHERE name='$class'");
163 for ($row = 0; $row < pg_numrows($class_res); $row++)
165 $prop = pg_fetch_object($class_res, $row);
166 $insertion = "insert into property (paramid, name, value, type, min, max) values ('";
167 $insertion .= $par->currval . "', '" . $prop->property_name . "', '";
168 $insertion .= $_POST[$prop->property_name] . "', '" . $prop->property_type . "', '";
169 $insertion .= $prop->min . "', '" . $prop->max . "')";
171 pg_exec($this->database, $insertion);
173 $insertion = "insert into history (paramid, modified, change_nature, changed_property, new_value)";
174 $insertion .= " values ('" . $par->currval . "', '";
175 $insertion .= date('Y-m-d H:i:s') . "', 'CREATED', '";
176 $insertion .= $prop->property_name . "', '" . $_POST[$prop->property_name] . "')";
178 pg_exec($this->database, $insertion);
181 echo "<td>", $prop->property_name, "</td><td>", $prop->description, "</td>";
182 echo "<td>" . $_POST[$prop->property_name] . "</td>";
190 <form action='parameter_compare.php' method='post'>
191 <input type='hidden' name='oid' value='<?php echo $ObjId ?>'>
193 <select name='compare_to'>
194 <?php object_selection($this->database, $ObjId ); ?>
196 <input type='hidden' name='class' value='package'>
197 <input type='checkbox' name='show_removed' value='on'>Show removed parameters
198 <input type='submit' value=' Show Difference'>
204 $start_time = getmicrotime();
205 $res = pg_exec($this->database, "SELECT paramid, class, name, description FROM parameter "
206 ."WHERE objectid= CAST('" . $ObjId . "' AS BIGINT) order by class, name");
207 while ($row < pg_numrows($res))
209 $par = pg_fetch_object($res, $row);
210 $qry ="select change_nature from history where paramid= CAST('";
211 $qry .= $par->paramid . "' AS BIGINT) order by modified desc";
212 $rhist = pg_exec($this->database, $qry);
213 $hist = pg_fetch_object($rhist, 0);
214 if ($hist->change_nature != "REMOVED")
217 <tr><td align='center'>
218 <?php echo $par->class?>
220 <?php echo "<a href=\"parameter.php?paramid=" . $par->paramid . "\">" . $par->name . "</a>"?>
222 <?php echo $par->description?>
225 $r = pg_exec($this->database, "SELECT name, value FROM property
226 WHERE paramid=CAST('" . $par->paramid . "' AS BIGINT)");
227 for ($p = 0; $p < pg_numrows($r); $p++)
229 $prop = pg_fetch_object($r, $p);
230 echo $prop->name . "=" . $prop->value . " ";
239 $duration = getmicrotime() - $start_time;
241 echo "$row parameters in " . round($duration, 3) . " seconds (";
242 echo round($duration / $row * 1000, 3) . " milliseconds per parameter).<br>";
244 <h2>Create new parameter:</h2>
245 <form action='parameter.php?oid=<?php echo $ObjId ?>' method='post'>
246 Class : <input type='text' name='paramclass'>
247 Name : <input type='text' name='paramname'>
248 Description : <input type='text' name='paramdescr'>
250 <input type='submit' name='action' value='Create Parameter'>
254 if (!empty($_GET['paramid']))
256 // Edit a specific parameter
258 $paramid = $_GET['paramid'];
259 $par = pg_fetch_object(pg_exec($this->database, "SELECT * FROM parameter WHERE paramid='$paramid'"), 0);
261 if (isset($_POST['action']) && $_POST['action'] == 'Update Parameter')
263 // Update each property if its value has changed
265 $class_res = pg_exec($this->database, "SELECT * FROM parameter_class WHERE name='" . $par->class . "'");
266 for ($row = 0; $row < pg_numrows($class_res); $row++)
268 $prop = pg_fetch_object($class_res, $row);
269 $pname = $prop->property_name;
270 $property = pg_fetch_object(pg_exec($this->database,
271 "SELECT value, type, min, max FROM property WHERE paramid='$paramid' AND name='$pname'"), 0);
272 $pvalue = $property->value;
273 if ($pvalue != $_POST[$pname])
275 $pvalue = $_POST[$pname];
277 pg_exec($this->database, "UPDATE property SET value='$pvalue' WHERE paramid='$paramid' AND name='$pname'");
279 $insertion = "insert into history (paramid, modified, change_nature, changed_property, new_value)";
280 $insertion .= " values ('" . $paramid . "', '";
281 $insertion .= date('Y-m-d H:i:s') . "', 'MODIFIED', '";
282 $insertion .= $pname . "', '" . $pvalue . "')";
284 pg_exec($this->database, $insertion);
287 if ($property->type == 'DYNAMIC')
289 // Update the range if necessary.
291 if ($_POST[$pname . "_min"] != $property->min)
293 pg_exec($this->database, "UPDATE property SET min='" . $_POST[$pname . "_min"]
294 . "' WHERE paramid='$paramid' AND name='$pname'");
296 if ($_POST[$pname . "_max"] != $property->max)
298 pg_exec($this->database, "UPDATE property SET max='" . $_POST[$pname . "_max"]
299 . "' WHERE paramid='$paramid' AND name='$pname'");
305 echo "<h1>Parameter " . $par->name . " of class " . $par->class . "</h1>\n";
307 echo "<form action='parameter.php?paramid=$paramid' method='post'>\n";
308 echo "Description : <input type='text' name='paramdescr' value='" . $par->description . "'>\n";
311 echo "<tr><th>Property</th><th>Description</th><th>Value</th><th>Minimum</th><th>Maximum</th></tr>\n";
313 $class_res = pg_exec($this->database, "SELECT * FROM parameter_class WHERE name='" . $par->class . "'");
314 for ($row = 0; $row < pg_numrows($class_res); $row++)
316 $prop = pg_fetch_object($class_res, $row);
317 $pname = $prop->property_name;
318 $property = pg_fetch_object(pg_exec($this->database,
319 "SELECT value, type, min, max FROM property WHERE paramid='$paramid' AND name='$pname'"), 0);
320 $pvalue = $property->value;
321 $ptype = $property->type;
322 $pmin = $property->min;
323 $pmax = $property->max;
325 echo "<td>", $pname, "</td><td>", $prop->description, "</td>";
326 echo "<td><input type='text' name='$pname' value='$pvalue'></td>";
327 if ($ptype == 'DYNAMIC')
329 echo "<td><input type='text' name='" . $pname . "_min' value='$pmin'></td>";
330 echo "<td><input type='text' name='" . $pname . "_max' value='$pmax'></td>";
334 echo "<td> </td><td> </td>";
339 echo "<input type='submit' name='action' value='Update Parameter'>\n";
342 echo "<h2>Change history for " . $par->class . " parameter " . $par->name . "</h2>";
344 $histres = pg_exec($this->database, "SELECT * FROM history WHERE paramid='$paramid' ORDER BY modified");
346 for ($row = 0; $row < pg_numrows($histres); $row++)
348 $hist = pg_fetch_object($histres, $row);
350 echo "<td>" . $hist->changed_property . "</td>";
351 echo "<td>" . $hist->modified . "</td>";
352 echo "<td>" . $hist->change_nature . "</td>";
353 echo "<td>" . $hist->new_value . "</td>";
361 $page = new param_page("Gnucomo Parameters");