New page to enter and modify services.
authorarjen <arjen>
Mon, 1 Sep 2003 06:53:22 +0000 (06:53 +0000)
committerarjen <arjen>
Mon, 1 Sep 2003 06:53:22 +0000 (06:53 +0000)
src/web/menu.html
src/web/services.php [new file with mode: 0644]

index 8c6d9a2..6b80d44 100644 (file)
@@ -8,6 +8,7 @@
 <body>
    <a href='objects.php' target='main'><img src='server.png' alt='Objects'></a>
    <a href='users.php' target='main'><img src='user.png' alt='Users'></a>
+   <a href='services.php' target='main'><img src='service.png' alt='Services'></a>
    <a href='logout.php' target='main'><img src='exit.png' alt='Logout'></a>
    <hr>
 
diff --git a/src/web/services.php b/src/web/services.php
new file mode 100644 (file)
index 0000000..dd10654
--- /dev/null
@@ -0,0 +1,213 @@
+<?php 
+
+/**************************************************************************
+**  (c) Copyright 2003, Andromeda Technology & Automation
+** This is free software; you can redistribute it and/or modify it under the
+** terms of the GNU General Public License, see the file COPYING.
+***************************************************************************
+** MODULE INFORMATION *
+***********************
+**      FILE NAME      : services.php
+**      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
+**      VERSION NUMBER : $Revision: 1.1 $
+**
+**  DESCRIPTION      :  Service Administration page.
+**                      Input parameters: action (POST) : empty, 'Create'
+**                              servcode (POST) : short name of the service to create or remove
+**
+**  EXPORTED OBJECTS : 
+**  LOCAL    OBJECTS : 
+**  MODULES  USED    :
+***************************************************************************
+**  ADMINISTRATIVE INFORMATION *
+********************************
+**      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
+**      CREATION DATE   : Aug 04, 2003
+**      LAST UPDATE     : Aug 28, 2003
+**      MODIFICATIONS   : 
+**************************************************************************/
+
+/*****************************
+   $Log: services.php,v $
+   Revision 1.1  2003-09-01 06:53:22  arjen
+   New page to enter and modify services.
+
+******************************/
+
+// RCSID = "$Id: services.php,v 1.1 2003-09-01 06:53:22 arjen Exp $";
+
+ini_set('include_path', '.:./classes:../phpclasses');
+
+require_once('page.class.php');
+
+function clientscripts()
+{
+
+?>
+
+<script language='JavaScript'>
+
+function CheckCreate(f)
+{
+   if (f.servcode.value == "")
+   {
+      alert("You must supply a service code");
+      return false;
+   }
+   return true;
+}
+
+function CheckRemove(f)
+{
+   var message = "Are you sure you want to remove service ";
+   message += f.servcode.value;
+   message += " ?";
+
+   return confirm(message);
+}
+
+</script>
+
+<?php
+}
+
+class service_page extends page
+{
+
+   function Body()
+   {
+
+   clientscripts();
+
+   if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['servcode']))
+   {
+      pg_exec($this->database, "INSERT INTO service
+                       (servicecode, servicename, default_priority, max_priority) VALUES ('"
+                     . $_POST['servcode'] . "','" . $_POST['servname'] . "','"
+                     . $_POST['defprior'] . "','" . $_POST['maxprior'] . "')");
+   }
+
+   if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['servcode']))
+   {
+      pg_exec($this->database, "DELETE FROM service WHERE servicecode='"
+                                . $_POST['servcode'] . "'");
+   }
+
+   if (isset($_GET['servcode']))
+   {
+      echo "<h1>Detailed information for service " . $_GET['servcode'] . "</h1><br>\n";
+
+      if (isset($_POST['action']) && $_POST['action'] == 'Save Changes')
+      {
+         $qry = "UPDATE service SET servicename='" . $_POST['servname'] . "'";
+         $qry .= ", default_priority='" . $_POST['defprior'] . "'";
+         $qry .= ", max_priority='" . $_POST['maxprior'] . "'";
+         $qry .= " WHERE servicecode='" . $_GET['servcode'] . "'";
+
+         pg_exec($this->database, $qry);
+      }
+
+      $res = pg_exec($this->database, "SELECT * FROM service
+                                       WHERE servicecode='" . $_GET['servcode'] . "'");
+      $srv = pg_fetch_object($res, 0);
+
+      echo "<form action='services.php?servcode=" . $srv->servicecode . "' method='POST'>";
+      echo "<table>";
+
+      echo "<tr><td>Service name</td><td><input name='servname' type='text' value='";
+      echo $srv->servicename . "'></td></tr>";
+      echo "<tr><td>Default priority</td><td><select name='defprior'>";
+      for ($prior = 1; $prior < 6; $prior++)
+      {
+         echo "<option value='$prior'";
+         if ($prior == $srv->default_priority)
+         {
+            echo " selected='true'";
+         }
+         echo ">$prior</option>\n";
+      }
+      echo "</select>";
+      echo "<tr><td>Maximum priority</td><td><select name='maxprior'>";
+      for ($prior = 1; $prior < 6; $prior++)
+      {
+         echo "<option value='$prior'";
+         if ($prior == $srv->max_priority)
+         {
+            echo " selected='true'";
+         }
+         echo ">$prior</option>\n";
+      }
+      echo "</select>";
+      echo "</table>";
+      echo "<input type='submit' name='action' value='Save Changes'>";
+      echo "</form>";
+   }
+   else
+   {
+   echo "<h1>Service Administration</h1><hr>";
+
+   $res = pg_exec($this->database, "SELECT * FROM service ORDER BY servicecode");
+
+   echo "<table>";
+   echo "<tr><th>Service code</th><th>Name</th><th>Priority</th><th>Max priority</th><tr>";
+   $srv = 0;
+   while ($srv < pg_numrows($res))
+   {
+      $u = pg_fetch_object($res, $srv);
+      ?>
+      <tr><td align='center'><a href='services.php?servcode=<?php echo $u->servicecode?>'><img src='service.png'></a><br>
+             <b><?php echo $u->servicecode ?></b>
+      </td><td>
+         <?php echo $u->servicename ?>
+      </td><td>
+         <?php echo $u->default_priority ?>
+      </td><td>
+         <?php echo $u->max_priority ?>
+      </td><td>
+          <form action='services.php' method='post' onSubmit='return CheckRemove(this)'>
+              <input type='hidden' name='servcode' value='<?php echo $u->servicecode ?>'>
+              <input type='submit' name='action' value='Remove'>
+          </form>
+      </td></tr>
+      <?php
+      $srv++;
+   }
+   echo "</table>";
+
+?>
+
+<h2>Create new service:</h2>
+<p>
+
+<form action='services.php' method='post' onSubmit='return CheckCreate(this)'>
+Service code: <input name='servcode' type='text'>
+Service name: <input name='servname' type='text'>
+Default priority: <select name='defprior'>
+<option value='1'>1</option>
+<option value='2'>2</option>
+<option value='3'>3</option>
+<option value='4'>4</option>
+<option value='5'>5</option>
+</select>
+Maximum priority: <select name='maxprior'>
+<option value='1'>1</option>
+<option value='2'>2</option>
+<option value='3'>3</option>
+<option value='4'>4</option>
+<option value='5' selected='true'>5</option>
+</select>
+<br>
+<input type='submit' name='action' value='Create'>
+</form>
+</p>
+
+<?php
+   }
+   }
+}
+
+$page = new service_page("Gnucomo User Administration");
+
+$page->Showpage();
+
+?>