***********************
** FILE NAME : objects.php
** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
-** VERSION NUMBER : $Revision: 1.8 $
+** VERSION NUMBER : $Revision: 1.9 $
**
** DESCRIPTION : Objects Administration page.
** Input parameters: action (POST) : empty, 'Create'
/*****************************
$Log: objects.php,v $
- Revision 1.8 2003-08-14 10:35:07 arjen
+ Revision 1.9 2003-09-01 06:55:00 arjen
+ Provides an interface to edit the list of
+ services and users for an object.
+
+ Revision 1.8 2003/08/14 10:35:07 arjen
Added editing of detailed object information.
Revision 1.7 2003/07/15 11:02:25 arjen
******************************/
-// RCSID = "$Id: objects.php,v 1.8 2003-08-14 10:35:07 arjen Exp $";
+// RCSID = "$Id: objects.php,v 1.9 2003-09-01 06:55:00 arjen Exp $";
ini_set('include_path', '.:./classes:../phpclasses');
pg_exec($this->database, $qry);
}
+ else if (isset($_POST['action']) && $_POST['action'] == 'Modify Service')
+ {
+ $obj_srv_res = pg_exec($this->database, "SELECT * from object_service WHERE objectid='" . $_GET['oid']
+ . "' AND servicecode='" . $_POST['servcode'] . "'");
+
+ if (pg_numrows($obj_srv_res) == 0)
+ {
+ // Add a new service for this object
+ if (isset($_POST['servused']))
+ {
+ $qry = "INSERT INTO object_service (objectid, servicecode, expected_interval) ";
+ $qry .= "VALUES ('" . $_GET['oid'] . "', '" . $_POST['servcode'] . "', '";
+ $qry .= $_POST['expinterval'] . "')";
+
+ pg_exec($this->database, $qry);
+ }
+ }
+ else
+ {
+ // Modify or remove the service for this object
+ if (isset($_POST['servused']))
+ {
+ // Service is still used; update some values.
+ $qry = "UPDATE object_service SET expected_interval='" . $_POST['expinterval'];
+ $qry .= "' WHERE objectid='" . $_GET['oid'];
+ $qry .= "' AND servicecode='" . $_POST['servcode'] . "'";
+ pg_exec($this->database, $qry);
+ }
+ else
+ {
+ // Checkbox was turned off, remove the service
+
+ $qry = "DELETE FROM object_service WHERE objectid='" . $_GET['oid'];
+ $qry .= "' AND servicecode='" . $_POST['servcode'] . "'";
+ pg_exec($this->database, $qry);
+ }
+ }
+ }
+ else if (isset($_POST['action']) && $_POST['action'] == 'Modify User')
+ {
+ $obj_srv_res = pg_exec($this->database, "SELECT * from object_user WHERE objectid='" . $_GET['oid']
+ . "' AND username='" . $_POST['username'] . "'");
+
+ if (pg_numrows($obj_srv_res) == 0)
+ {
+ // Add a new user for this object
+ if (isset($_POST['userused']))
+ {
+ $qry = "INSERT INTO object_user (objectid, username, security_level) ";
+ $qry .= "VALUES ('" . $_GET['oid'] . "', '" . $_POST['username'] . "', '";
+ $qry .= $_POST['seclevel'] . "')";
+
+ pg_exec($this->database, $qry);
+ }
+ }
+ else
+ {
+ // Modify or remove the user for this object
+ if (isset($_POST['userused']))
+ {
+ // Service is still used; update some values.
+ $qry = "UPDATE object_user SET security_level='" . $_POST['seclevel'];
+ $qry .= "' WHERE objectid='" . $_GET['oid'];
+ $qry .= "' AND username='" . $_POST['username'] . "'";
+ pg_exec($this->database, $qry);
+ }
+ else
+ {
+ // Checkbox was turned off, remove the user
+
+ $qry = "DELETE FROM object_user WHERE objectid='" . $_GET['oid'];
+ $qry .= "' AND username='" . $_POST['username'] . "'";
+ pg_exec($this->database, $qry);
+ }
+ }
+ }
$res = pg_exec($this->database, "SELECT * FROM object
WHERE objectid='" . $_GET['oid'] . "'");
echo "</table>";
echo "<input type='submit' name='action' value='Save Changes'>";
echo "</form>";
+
+ echo "<h1>Services on " . $obj->objectname . "</h1><hr>\n";
+
+ echo "<table>";
+ echo "<tr><th>Service name</th><th>Last entry</th><th>Expected interval</th></tr>";
+ $srv_res = pg_exec($this->database, "SELECT servicecode, servicename FROM service
+ ORDER BY servicecode");
+ for ($srv_row = 0; $srv_row < pg_numrows($srv_res); $srv_row++)
+ {
+ $srv = pg_fetch_object($srv_res, $srv_row);
+ $srv_obj_res = pg_exec($this->database, "SELECT * FROM object_service WHERE objectid='"
+ . $obj->objectid . "' AND servicecode='" . $srv->servicecode . "'");
+
+ echo "<tr><form action='objects.php?oid=" . $obj->objectid . "' method='POST'>";
+ echo "<input type='hidden' name='servcode' value='" . $srv->servicecode . "'>";
+
+ if (pg_numrows($srv_obj_res) == 0)
+ {
+ echo "<td><input name='servused' type='checkbox'> " . $srv->servicename . "</td>";
+ echo "<td> </td>";
+ echo "<td><input name='expinterval' type='text' value='0'></td>";
+ echo "<td><input type='submit' name='action' value='Modify Service'></td>";
+ }
+ else
+ {
+ $obj_srv = pg_fetch_object($srv_obj_res, 0);
+ echo "<td><input name='servused' type='checkbox' checked='true'> " . $srv->servicename . "</td>";
+ echo "<td>" . $obj_srv->last_entry . "</td>";
+ echo "<td><input name='expinterval' type='text' value='" . $obj_srv->expected_interval . "'></td>";
+ echo "<td><input type='submit' name='action' value='Modify Service'></td>";
+ }
+ echo "</form></tr>";
+ }
+ echo "</table>";
+
+ echo "<h1>Users of " . $obj->objectname . "</h1><hr>\n";
+
+ echo "<table>";
+ echo "<tr><th>User name</th><th>Security level</th><th> </th></tr>";
+
+ $usr_res = pg_exec($this->database, "SELECT username, security_level FROM usr ORDER BY username");
+ for ($usr_row = 0; $usr_row < pg_numrows($usr_res); $usr_row++)
+ {
+ $usr = pg_fetch_object($usr_res, $usr_row);
+ $usr_obj_res = pg_exec($this->database, "SELECT * FROM object_user WHERE objectid='"
+ . $obj->objectid . "' AND username='" . $usr->username . "'");
+
+ echo "<tr><form action='objects.php?oid=" . $obj->objectid . "' method='POST'>";
+ echo "<input type='hidden' name='username' value='" . $usr->username . "'>";
+
+ if (pg_numrows($usr_obj_res) == 0)
+ {
+ echo "<td><input name='userused' type='checkbox'> " . $usr->username . "</td>";
+ echo "<td><input name='seclevel' type='text' value='" . $usr->security_level . "'></td>";
+ echo "<td><input type='submit' name='action' value='Modify User'></td>";
+ }
+ else
+ {
+ $usr_obj = pg_fetch_object($usr_obj_res, 0);
+ echo "<td><input name='userused' type='checkbox' checked='on'> " . $usr->username . "</td>";
+ echo "<td><input name='seclevel' type='text' value='" . $usr_obj->security_level . "'></td>";
+ echo "<td><input type='submit' name='action' value='Modify User'></td>";
+ }
+ echo "</form></tr>";
+ }
+ echo "</table>";
}
else
{
$count_notifications += $this->nr_notifications;
$closed_notifications += $this->closed_notifications;
?>
- <tr><td><center><a href='objects.php?oid=<?php echo $u->objectid?>'<img src='server.png'></a><br>
+ <tr><td><center><a href='objects.php?oid=<?php echo $u->objectid?>'><img src='server.png'></a><br>
<b><?php echo $u->objectname ?></b></center>
</td><td>
<?php echo nl2br($u->object_description) ?>