27cd03c1f781d7b2f8b002b8fb8b5a6b629cb5d7
[gnucomo.git] / src / web / objects.php
1 <?php 
2
3 /**************************************************************************
4 ** This is free software; you can redistribute it and/or modify it under the
5 ** terms of the GNU General Public License, see the file COPYING.
6 ***************************************************************************/
7
8 /*
9  *
10  * Objects Administration page.
11  * Input parameters: action (POST) : empty, 'Create'
12  *                   objname (POST) : name of the object to create or remove
13  */
14
15 session_start();
16 require_once('classes/gnucomo_config.php');
17 ?>
18
19 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
20 <html>
21 <head>
22 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
23 <link rel='stylesheet' href='gnucomo.css' type='text/css'>
24 <title>GNUCoMo login</title>
25
26 <script language='JavaScript'>
27 function CheckCreate(f)
28 {
29    if (f.objectname.value == "")
30    {
31       alert("You must supply a name");
32       return false;
33    }
34    return true;
35 }
36
37 function CheckRemove(f)
38 {
39    var message = "Are you sure you want to remove object ";
40    message += f.objectname.value;
41    message += " ?";
42
43    return confirm(message);
44 }
45
46 </script>
47
48 </head>
49 <body>
50 <?php
51 if (empty($_SESSION['username']))
52 {
53    echo "Please log in first.";
54 }
55 else
56 {
57    echo "<h1>Objects Administration</h1><hr>";
58
59    $config = new gnucomo_config;
60
61    $config->read("gnucomo");
62
63    //  Connect to the database
64    $conn = pg_connect($config->Database($_SESSION['username'], $_SESSION['password']));
65
66
67    if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['objectname']))
68    {
69       pg_exec($conn, "INSERT INTO object (objectname) VALUES ('"
70                      . $_POST['objectname'] . "')");
71    }
72
73    if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['objectname']))
74    {
75       pg_exec($conn, "DELETE FROM object WHERE objectname='" . $_POST['objectname'] . "'");
76    }
77
78    $res = pg_exec($conn, "SELECT objectid,objectname FROM object");
79
80    echo "<table>";
81    $obj = 0;
82    while ($obj < pg_numrows($res))
83    {
84       $u = pg_fetch_object($res, $obj);
85       $r = pg_exec($conn, "SELECT count(logid) FROM log WHERE objectid='"
86                            . $u->objectid . "'");
87       $r = pg_fetch_object($r, 0);
88
89       $nr_logs = $r->count;
90
91       $r = pg_exec ($conn, "SELECT count(paramid) FROM parameter WHERE objectid='"
92                            . $u->objectid . "'");
93       $r = pg_fetch_object($r, 0);
94
95       $nr_params = $r->count;
96       ?>
97       <tr><td align='center'><img src='server.png'><br>
98              <b><?php echo $u->objectname ?></b>
99       </td><td>
100           <?php echo $nr_logs?> <a href='log.php?oid=<?php echo $u->objectid?>'>Log entries</a>
101       </td><td>
102           <?php echo $nr_params?> <a href='parameter.php?oid=<?php echo $u->objectid?>'>Parameters</a>
103       </td><td>
104           <form action='objects.php' method='post' onSubmit='return CheckRemove(this)'>
105               <input type='hidden' name='objectname' value='<?php echo $u->objectname ?>'>
106               <input type='submit' name='action' value='Remove'>
107           </form>
108       </td></tr>
109       <?php
110       $obj++;
111    }
112    echo "</table>";
113
114 }
115 ?>
116
117 <h2>Create new object:</h2>
118 <p>
119
120 <form action='objects.php' method='post' onSubmit='return CheckCreate(this)'>
121 Objects name (FQDN): <input name='objectname' type='text'>
122 <br>
123 <input type='submit' name='action' value='Create'>
124 </form>
125 </p>
126 </body>
127 </html>