Updated footer link
[specialops2.git] / lib / class.page.php
blob8cff7afe343d4e7986668399af6e455a632b5451
1 <?php
2 // $Id$
4 class page
6 public $sitename = 'Special Ops';
7 public $title;
8 public $lang;
9 public $errors = array();
10 public $nav = array();
12 const Pageheader = 1;
13 const Userheader = 2;
14 public $headers = 0;
16 function __construct()
18 set_error_handler(array($this, 'error_handler'));
20 if ( strpos($_SERVER['PHP_SELF'], 'index') === false )
21 $this->nav['Board List'] = '.';
24 function pageheader()
26 switch ( $GLOBALS['user']->theme ) {
27 case -1:
28 $css = 'default.css'; break;
29 case 0:
30 $css = 'u'.$GLOBALS['user']->userid.'.css'; break;
31 default:
32 list($css) = $GLOBALS['DB']->query('SELECT `css_file` FROM `themes`
33 WHERE `themeid` = '.$GLOBALS['user']->theme)->fetch_row();
36 if ( defined('DEVELOPER') && isset($_GET['viewsrc']) )
37 header('Content-Type: text/plain; charset=UTF-8');
38 else
39 header('Content-Type: application/xhtml+xml; charset=UTF-8');
41 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',"\n",
42 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB">',"\n",
43 "<head>\n",
44 ' <title>',$this->title,' :: ',$this->sitename,"</title>\n",
45 ' <link rel="stylesheet" type="text/css" href="css/',$css,'"/>',"\n",
46 "</head>\n\n",
47 "<body>\n",
48 '<h1>',$this->title,"</h1>\n";
50 if ( isset($_POST['logout']) && $GLOBALS['user'] instanceof anonuser )
51 echo '<p class="notice">You are now logged out.</p>',"\n";
52 elseif ( isset($_POST['login'], $_POST['u'], $_POST['p']) ) {
53 if ( $GLOBALS['user'] instanceof authuser ) {
54 $GLOBALS['DB']->query('UPDATE `users`
55 SET `last_login_ip` = INET_ATON(\''.$_SERVER['REMOTE_ADDR'].'\')
56 WHERE `userid` = @userid');
57 echo '<p class="notice">You are now logged in.</p>',"\n";
58 } else
59 echo '<p class="error">Username and/or password is invalid.</p>',"\n";
62 if ( $GLOBALS['user'] instanceof authuser && $GLOBALS['user']->password === null )
63 echo '<p class="notice">Your password has been reset by an admin. You should set a new one.</p>';
65 if ( $this->nav ) {
66 echo '<ul id="navbar" class="nl">',"\n";
67 foreach ( $this->nav as $title => $url )
68 echo "\t",'<li><a href="',$url,'">',$title,"</a></li>\n";
69 echo "</ul>\n\n";
72 $this->headers |= self::Pageheader;
75 function footer($text = null)
77 echo $text;
78 $this->pagefooter();
81 function errorfooter($type = 'login', $var = null, $var2 = null)
83 if ( !headers_sent() )
84 switch ( $type ) {
85 case 'level':
86 case 'levelpoints':
87 header('HTTP/1.1 403 Forbidden'); break;
88 default:
89 header('HTTP/1.1 400 Bad Request');
92 if ( ! ($this->headers & self::Pageheader) )
93 $this->pageheader();
94 if ( ! ($this->headers & self::Userheader) )
95 $GLOBALS['user']->userheader();
96 $messages = array(
97 'level' => 'You must be at least level '.$var.' to view this page.',
98 'levelpoints' => 'You must be at least level '.$var.' and have '.$var2.' points to view this page.',
99 'login' => 'You must be logged in to view this page.',
100 'logout' => 'You must be logged out to view this page.',
101 'boardid' => 'Invalid board ID given.',
102 'topicid' => 'Invalid topic ID given.',
103 'messageid' => 'Invalid message ID given.',
104 'userid' => 'Invalid user ID given.'
106 echo '<p class="error">',$messages[$type],'</p>';
107 $this->pagefooter();
110 function pagefooter()
112 echo "\n\n",
113 '<form id="footer" action="',
114 $_SERVER['PHP_SELF'],'?',htmlspecialchars($_SERVER['QUERY_STRING']),'" method="post">',"\n",
115 ' <fieldset><legend>Session:</legend>',"\n";
117 if ( $GLOBALS['user'] instanceof authuser )
118 echo ' <button type="submit" name="logout" value="yes" onclick="return confirm(\'o rly?\');">Log Out</button>';
119 else
120 echo
121 ' <label>Username: <input type="text" name="u"/></label>',"\n",
122 ' <label>Password: <input type="password" name="p"/></label>',"\n",
123 ' <button type="submit" name="login" value="yes">Log In</button>';
125 echo "\n</fieldset>\n";
127 if ( defined('DEVELOPER') && count($this->errors) ) {
128 echo "<h2>Errors on page:</h2>\n<dl>\n";
130 foreach ( $this->errors as $e )
131 printf('<dt>%s:%s</dt><dd>%s:%s</dd>',
132 $e[2],
133 $e[3],
134 $e[0],
135 $e[1]
138 echo "</dl>\n";
141 echo
142 '<p>© 2004-2005 Ant P | ',round(microtime(1) - CLOCK, 4),'s | ',
143 ( defined('DEVELOPER') ?
144 sprintf('%d queries | %d $user::gets | %d $user::sets',
145 $GLOBALS['DB']->c,
146 $GLOBALS['user']->gets,
147 $GLOBALS['user']->sets) :
148 count($this->errors).' errors'
149 ),' | <a href="http://specialops.ath.cx/repos/so2/">',SO2VER,"</a></p>\n</form>\n",
150 '</body></html>';
152 exit;
155 function error_handler($number, $string, $file, $line)
157 // If errors are being returned plaintext with all the <>&s then fix them
158 if ( ! ini_get('html_errors') ) {
159 $string = new message($string);
160 $string = $string->output;
162 $this->errors[] = array($number, $string, $file, $line);