e53e686ad70e57d7c625e6f763593308a8b58e8d
[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.6 $
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 14, 2003
27 **      MODIFICATIONS   : 
28 **************************************************************************/
29
30 /*****************************
31    $Log: objects.php,v $
32    Revision 1.6  2003-02-21 08:46:58  arjen
33    Improved the table layout.
34
35    Revision 1.5  2003/02/13 09:01:29  arjen
36    All web interface pages use the page class.
37
38    Revision 1.4  2003/02/13 08:48:23  arjen
39    Added log, notification and parameter counters to the 'object' table.
40    Counting these things at the time a user interface needs them is
41    too slow. Other programs, like gcm_daemon en gcm_input should prepare
42    these counters for quick retrieval.
43
44    Revision 1.3  2003/02/10 15:42:24  arjen
45    Show the total number of Log entries, parameters and notifications
46
47    Revision 1.2  2003/02/05 09:48:14  arjen
48    Added display and handling of notifications
49
50 ******************************/
51
52 // RCSID = "$Id: objects.php,v 1.6 2003-02-21 08:46:58 arjen Exp $";
53
54 ini_set('include_path', '.:./classes:../phpclasses');
55
56 require_once('page.class.php');
57
58 function clientscripts()
59 {
60 ?>
61
62 <script language='JavaScript'>
63
64 function CheckCreate(f)
65 {
66    if (f.objectname.value == "")
67    {
68       alert("You must supply a name");
69       return false;
70    }
71    return true;
72 }
73
74 function CheckRemove(f)
75 {
76    var message = "Are you sure you want to remove object ";
77    message += f.objectname.value;
78    message += " ?";
79
80    return confirm(message);
81 }
82
83 </script>
84
85 <?php
86 }
87
88 class object_page extends page
89 {
90
91    function Body()
92    {
93       clientscripts();
94
95    echo "<h1>Objects Administration</h1><hr>";
96
97    if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['objectname']))
98    {
99       pg_exec($this->database, "INSERT INTO object (objectname, log_count, parameter_count, notification_count)
100                                VALUES ('" . $_POST['objectname'] . "', '0', '0', '0')");
101    }
102
103    if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['objectname']))
104    {
105       pg_exec($this->database, "DELETE FROM object WHERE objectname='" . $_POST['objectname'] . "'");
106    }
107
108    $res = pg_exec($this->database, "SELECT objectid,objectname, log_count, notification_count
109                                     FROM object ORDER BY objectname");
110 ?>
111
112    <table>
113    <tr><th>Object</th><th>Log entries</th>
114        <th>Parameters</th><th>Notifications</th>
115    </tr>
116
117 <?php
118    $obj = 0;
119
120    //The counters are set to zero
121    $count_logs = 0;
122    $count_notifications = 0;
123    $count_parameters = 0;
124
125    while ($obj < pg_numrows($res))
126    {
127       $u = pg_fetch_object($res, $obj);
128       $nr_logs = $u->log_count;
129       $count_logs = $count_logs + $nr_logs;
130
131       $r = pg_exec ($this->database, "SELECT count(paramid) FROM parameter WHERE objectid=CAST('"
132                            . $u->objectid . "' AS BIGINT)");
133       $r = pg_fetch_object($r, 0);
134
135       $nr_params = $r->count;
136       $count_parameters = $count_parameters + $nr_params;
137
138       $nr_notifications = $u->notification_count;
139       $count_notifications = $count_notifications + $nr_notifications;
140       ?>
141       <tr><td><center><img src='server.png'><br>
142              <b><?php echo $u->objectname ?></b></center>
143       </td><td class='number'>
144           <?php echo "<a href='log.php?oid=$u->objectid'> $nr_logs </a>" ?>
145       </td><td class='number'>
146           <?php echo "<a href='parameter.php?oid=$u->objectid'> $nr_params </a>" ?>
147       </td><td class='number'>
148           <?php echo "<a href='notification.php?oid=$u->objectid'> $nr_notifications </a>" ?>
149       </td><td>
150           <form action='objects.php' method='post' onSubmit='return CheckRemove(this)'>
151               <input type='hidden' name='objectname' value='<?php echo $u->objectname ?>'>
152               <input type='submit' name='action' value='Remove'>
153           </form>
154       </td></tr>
155       <?php
156       $obj++;
157    }
158
159    //Show the totals
160    echo "<tr><td><strong><B><br><br>TOTALS</B></strong></td>";
161    echo "<td class='number'>$count_logs</td>";
162    echo "<td class='number'>$count_parameters</td>";
163    echo "<td class='number'>$count_notifications</td></tr>";
164    echo "</table>";
165
166 ?>
167
168 <h2>Create new object:</h2>
169 <p>
170
171 <form action='objects.php' method='post' onSubmit='return CheckCreate(this)'>
172 Objects name (FQDN): <input name='objectname' type='text'>
173 <br>
174 <input type='submit' name='action' value='Create'>
175 </form>
176 </p>
177 <?php
178
179    }
180 }
181
182 $obj_page = new object_page("Gnucomo Objects Administration");
183
184 $obj_page->Showpage();
185
186 ?>
187