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