The buttonbar at the top of each page is now a fixed 'div' element
[gnucomo.git] / src / web / page.class.php
1 <?php
2 /**************************************************************************
3 **  (c) Copyright 2003, Andromeda Technology & Automation
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 ** MODULE INFORMATION *
8 ***********************
9 **      FILE NAME      : page.class.php
10 **      SYSTEM NAME    : Gnucomo - Gnu Computer Monitoring
11 **      VERSION NUMBER : $Revision: 1.10 $
12 **
13 **  DESCRIPTION      : Base class for Gnucomo web interface pages.
14 **
15 **  EXPORTED OBJECTS : 
16 **  LOCAL    OBJECTS : 
17 **  MODULES  USED    :
18 ***************************************************************************
19 **  ADMINISTRATIVE INFORMATION *
20 ********************************
21 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
22 **      CREATION DATE   : Jan 22, 2003
23 **      LAST UPDATE     : Feb 19, 2003
24 **      MODIFICATIONS   : 
25 **************************************************************************/
26
27 /*****************************
28    $Log: page.class.php,v $
29    Revision 1.10  2007-11-21 14:38:06  arjen
30    The buttonbar at the top of each page is now a fixed 'div' element
31    instead of a framed page.
32    Contributed by Edwin Nadorp.
33
34    Revision 1.9  2007/10/23 14:47:42  arjen
35    Prepared for release 0.0.10
36
37    Revision 1.8  2007/01/11 13:44:29  arjen
38    Manually edit parameters.
39    View logs from abusing IP addresses.
40
41    Revision 1.7  2003/12/24 07:41:23  arjen
42    Changed version number
43
44    Revision 1.6  2003/09/04 06:53:40  arjen
45    Prepared for release 0.0.8
46
47    Revision 1.5  2003/08/14 10:37:04  arjen
48    Prepared for release 0.0.7
49
50    Revision 1.4  2003/07/15 11:05:32  arjen
51    Chnaged version number to 0.0.6 in login form.
52
53    Revision 1.3  2003/02/19 09:12:27  arjen
54    Added the 'form' class on table and td elements. This class is intended
55    for borderless tables that are used to layout HTML forms.
56
57    Revision 1.2  2003/02/13 08:59:52  arjen
58    Use our own error handler for PHP errors and warnings
59
60    Revision 1.1  2003/02/05 09:38:42  arjen
61    A base class for all web interface pages
62
63 ******************************/
64
65 // RCSID = "$Id: page.class.php,v 1.10 2007-11-21 14:38:06 arjen Exp $";
66
67
68 require_once('gnucomo_config.php');
69
70 $last_error = "&nbsp;";
71
72 function error($errno, $errstr, $errfile, $errline)
73 {
74    global $last_error;
75
76    $last_error = $errstr;
77 }
78
79 function login_form()
80 {
81    global $last_error;
82
83 ?>
84    <div class='login'>
85    <h1 align="center">GNU Computer Monitoring</h1>
86    <h4 align="center"><i>Version 0.0.10, October 19, 2007</i></h4>
87    <h2 class='error'><?php echo $last_error?></h2>
88    <center><table class='form'>
89    <tr>
90    <td width='50%' class='form'>
91       <a href='http://gnucomo.org/' target='_top'><img src='logo.png' alt='GnuCoMo logo'></a></td>
92    <td class='form'><form name="login" method="POST" action="index.php">
93        <table class='form'>
94        <tr>
95        <td class='form'>Username</td>
96        <td class='form'><input type="text" name="username"></td>
97        </tr>
98        <tr>
99        <td class='form'>Password</td>
100        <td class='form'><input type="password" name="password"></td>
101        </tr>
102        <tr>
103        <td class='form'>&nbsp;</td>
104        <td align="right" class='form'><input type="submit" value="signin"></td>
105        </tr>
106        </table>
107        </form>
108    </td>
109    </tr>
110    </table></center>
111    </div>
112 <?php
113 }
114
115 class page
116 {
117    var  $the_title;       //  The title used on the page.
118    var  $database;        //  Connection to the database server.
119    var  $path;            //  Directory path to stylesheets and images.
120    var  $config;          //  The XML configuration object.
121
122    //   Page constructor.
123
124    function page($title, $path = "")
125    {
126       $this->the_title = $title;
127       $this->database = false;
128       $this->path = $path;
129       session_start();
130       //set_error_handler("error");
131    }
132
133    function Head()
134    {
135 ?>
136       <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
137                     "http://www.w3.org/TR/html4/loose.dtd">
138       <html>
139       <head>
140       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
141       <meta name="author" content="Arjen Baart">
142       <meta name="expires" content="0">
143
144       <link rel='stylesheet' href='<?php echo $this->path ?>gnucomo.css' type='text/css'>
145       <title><?php echo $this->the_title ?></title>
146       </head>
147       <body>
148         <div id="header">
149            <a href='index.php'><img src='small-logo.png' title='Gnucomo' alt='Gnucomo'></a>
150            <a href='objects.php'><img src='server.png' title='Objects' alt='Objects'></a>
151            <a href='users.php'><img src='user.png' title='Users' alt='Users'></a>
152            <a href='services.php'><img src='service.png' title='Services' alt='Services'></a>
153            <a href='issues.php'><img src='bell.png' title='Issues' alt='Issues'></a>
154            <a href='classes.php'><img src='change.png' title='Classes' alt='Classes'></a>
155            <!-- a href='notification2.php'>N2</a -->
156            <a href='logout.php'><img src='exit.png' title='Logout' alt='Logout'></a>
157         </div>
158
159         <div id="menu_title">&nbsp;</div>
160
161         <div id="content">
162 <?php
163    }
164
165    function Body()
166    {
167       //echo "The default body.";
168       echo "<div id='content'>
169                  <img src='logo.png' alt='GnuCoMo'>
170             </div>";
171    }
172
173    function Tail()
174    {
175       if ($this->database)
176       {
177          pg_close($this->database);
178       }
179       echo "<br></div>
180             <div id='footer'>
181             &copy; <a href='http://www.gnucomo.org'>GnuCoMo</a>
182             </div>";
183       echo "</body>";
184       echo "</html>";
185    }
186
187    function Showpage()
188    {
189       $this->config = new gnucomo_config;
190
191       $this->config->read("gnucomo");
192
193       $this->Head();
194       if (empty($_SESSION['username']))
195       {
196          //  Nobody logged in yet.
197
198          if (isset($_POST['username']) && isset($_POST['password']))
199          {
200             //  Login form submitted. Try to start a new session.
201
202             $name   = $_POST['username'];   // PostgreSQL username
203             $passw  = $_POST['password'];   // PostgreSQL user password
204
205             //  Connect to the database
206             $this->database = pg_connect($this->config->Database($name, $passw));
207             if ($this->database == false)
208             {
209                login_form();
210             }
211             else
212             {
213                session_register('username');
214                $_SESSION['username'] = $name;
215                session_register('password');
216                $_SESSION['password'] = $passw;
217                $this->Body();
218             }
219
220          }
221          else
222          {
223             //  Nobody tried to login yet. Present the login form.
224             login_form();
225          }
226       }
227       else
228       {
229          $name   = $_SESSION['username'];   // PostgreSQL username
230          $passw  = $_SESSION['password'];   // PostgreSQL user password
231
232          //  Connect to the database
233          $this->database = pg_connect($this->config->Database($name, $passw));
234          $this->Body();
235       }
236       $this->Tail();
237    }
238 }