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