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