33a90e0435346d6dd69e0c1fbddaa008c5b4bcef
[gnucomo.git] / src / web / objects.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      : objects.php
11 **      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
12 **      VERSION NUMBER : $Revision: 1.2 $
13 **
14 **  DESCRIPTION      : Objects Administration page.
15 **                     Input parameters: action (POST) : empty, 'Create'
16 **                                      objname (POST) : name of the object 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   : Dec 04, 2002
26 **      LAST UPDATE     : Feb 03, 2003
27 **      MODIFICATIONS   : 
28 **************************************************************************/
29
30 /*****************************
31    $Log: objects.php,v $
32    Revision 1.2  2003-02-05 09:48:14  arjen
33    Added display and handling of notifications
34
35 ******************************/
36
37 // RCSID = "$Id: objects.php,v 1.2 2003-02-05 09:48:14 arjen Exp $";
38
39 session_start();
40 require_once('classes/gnucomo_config.php');
41 ?>
42
43 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
44 <html>
45 <head>
46 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
47 <link rel='stylesheet' href='gnucomo.css' type='text/css'>
48 <title>GNUCoMo login</title>
49
50 <script language='JavaScript'>
51 function CheckCreate(f)
52 {
53    if (f.objectname.value == "")
54    {
55       alert("You must supply a name");
56       return false;
57    }
58    return true;
59 }
60
61 function CheckRemove(f)
62 {
63    var message = "Are you sure you want to remove object ";
64    message += f.objectname.value;
65    message += " ?";
66
67    return confirm(message);
68 }
69
70 </script>
71
72 </head>
73 <body>
74 <?php
75 if (empty($_SESSION['username']))
76 {
77    echo "Please log in first.";
78 }
79 else
80 {
81    echo "<h1>Objects Administration</h1><hr>";
82
83    $config = new gnucomo_config;
84
85    $config->read("gnucomo");
86
87    //  Connect to the database
88    $conn = pg_connect($config->Database($_SESSION['username'], $_SESSION['password']));
89
90
91    if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['objectname']))
92    {
93       pg_exec($conn, "INSERT INTO object (objectname) VALUES ('"
94                      . $_POST['objectname'] . "')");
95    }
96
97    if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['objectname']))
98    {
99       pg_exec($conn, "DELETE FROM object WHERE objectname='" . $_POST['objectname'] . "'");
100    }
101
102    $res = pg_exec($conn, "SELECT objectid,objectname FROM object");
103
104    echo "<table>";
105    $obj = 0;
106    while ($obj < pg_numrows($res))
107    {
108       $u = pg_fetch_object($res, $obj);
109       $r = pg_exec($conn, "SELECT count(logid) FROM log WHERE objectid='"
110                            . $u->objectid . "'");
111       $r = pg_fetch_object($r, 0);
112
113       $nr_logs = $r->count;
114
115       $r = pg_exec ($conn, "SELECT count(paramid) FROM parameter WHERE objectid='"
116                            . $u->objectid . "'");
117       $r = pg_fetch_object($r, 0);
118
119       $nr_params = $r->count;
120
121       $r = pg_exec ($conn, "SELECT count(notificationid) FROM notification WHERE objectid='"
122                            . $u->objectid . "'");
123       $r = pg_fetch_object($r, 0);
124
125       $nr_notifications = $r->count;
126       ?>
127       <tr><td align='center'><img src='server.png'><br>
128              <b><?php echo $u->objectname ?></b>
129       </td><td>
130           <?php echo $nr_logs?> <a href='log.php?oid=<?php echo $u->objectid?>'>Log entries</a>
131       </td><td>
132           <?php echo $nr_params?> <a href='parameter.php?oid=<?php echo $u->objectid?>'>Parameters</a>
133       </td><td>
134           <?php echo $nr_notifications?> <a href='notification.php?oid=<?php echo $u->objectid?>'>Notifications</a>
135       </td><td>
136           <form action='objects.php' method='post' onSubmit='return CheckRemove(this)'>
137               <input type='hidden' name='objectname' value='<?php echo $u->objectname ?>'>
138               <input type='submit' name='action' value='Remove'>
139           </form>
140       </td></tr>
141       <?php
142       $obj++;
143    }
144    echo "</table>";
145
146 }
147 ?>
148
149 <h2>Create new object:</h2>
150 <p>
151
152 <form action='objects.php' method='post' onSubmit='return CheckCreate(this)'>
153 Objects name (FQDN): <input name='objectname' type='text'>
154 <br>
155 <input type='submit' name='action' value='Create'>
156 </form>
157 </p>
158 </body>
159 </html>