New theme, fixed some minor stuff
[specialops2.git] / lib / class.page.php
blob9537a9898869f11fe10b4f80e8b9d211d710c320
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 $this->nav['Board List'] = '.';
23 function pageheader()
25 switch ( $GLOBALS['user']->theme ) {
26 case -1:
27 $css = 'default.css'; break;
28 case 0:
29 $css = 'u'.$GLOBALS['user']->userid.'.css'; break;
30 default:
31 list($css) = $GLOBALS['DB']->query('SELECT `css_file` FROM `themes`
32 WHERE `themeid` = '.$GLOBALS['user']->theme)->fetch_row();
35 header('Content-Type: application/xhtml+xml; charset=UTF-8');
36 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',"\n",
37 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-GB">',"\n",
38 "<head>\n",
39 ' <title>',$this->title,' :: ',$this->sitename,"</title>\n",
40 ' <link rel="stylesheet" type="text/css" href="css/',$css,'"/>',"\n",
41 "</head>\n\n",
42 "<body>\n",
43 '<h1>',$this->title,"</h1>\n";
45 if ( isset($_POST['logout']) && $GLOBALS['user'] instanceof anonuser )
46 echo '<p class="notice">You are now logged out.</p>',"\n";
47 elseif ( isset($_POST['login'], $_POST['u'], $_POST['p']) ) {
48 if ( $GLOBALS['user'] instanceof authuser )
49 echo '<p class="notice">You are now logged in.</p>',"\n";
50 else
51 echo '<p class="error">Username and/or password is invalid.</p>',"\n";
54 if ( $GLOBALS['user'] instanceof authuser && $GLOBALS['user']->password === null )
55 echo '<p class="notice">Your password has been reset by an admin. You need to set a new one as soon as possible.</p>';
57 if ( $this->nav ) {
58 echo '<ul id="navbar" class="nl">',"\n";
59 foreach ( $this->nav as $title => $url )
60 echo "\t",'<li><a href="',$url,'">',$title,"</a></li>\n";
61 echo "</ul>\n\n";
64 $this->headers |= self::Pageheader;
67 function footer($text = null)
69 echo $text;
70 $this->pagefooter();
73 function errorfooter($type = 'login', $var = null, $var2 = null)
75 if ( ! ($this->headers & self::Pageheader) )
76 $this->pageheader();
77 if ( ! ($this->headers & self::Userheader) )
78 $GLOBALS['user']->userheader();
79 $messages = array(
80 'level' => 'You must be at least level '.$var.' to view this page.',
81 'levelpoints' => 'You must be at least level '.$var.' and have '.$var2.' points to view this page.',
82 'login' => 'You must be logged in to view this page.',
83 'logout' => 'You must be logged out to view this page.',
84 'boardid' => 'Invalid board ID given.',
85 'topicid' => 'Invalid topic ID given.',
86 'messageid' => 'Invalid message ID given.',
87 'userid' => 'Invalid user ID given.'
89 echo '<p class="error">',$messages[$type],'</p>';
90 $this->pagefooter();
93 function pagefooter()
95 echo "\n\n",
96 '<form id="footer" action="',
97 $_SERVER['PHP_SELF'],'?',htmlspecialchars($_SERVER['QUERY_STRING']),'" method="post"><fieldset>',"\n",
98 ' <legend>Session:</legend>',"\n";
100 if ( $GLOBALS['user'] instanceof authuser )
101 echo ' <button type="submit" name="logout" value="yes" onclick="return confirm(\'o rly?\');">Log Out</button>';
102 else
103 echo
104 ' <label>Username: <input type="text" name="u"/></label>',"\n",
105 ' <label>Password: <input type="password" name="p"/></label>',"\n",
106 ' <button type="submit" name="login" value="yes">Log In</button>';
108 echo "\n</fieldset>\n";
110 if ( defined('DEVELOPER') && count($this->errors) ) {
111 echo "<h2>Errors on page:</h2>\n<dl>\n";
113 foreach ( $this->errors as $e )
114 echo "<dt>${e[2]}:${e[3]}</dt>\n\t<dd>${e[0]}:${e[1]}</dd>\n";
116 echo "</dl>\n";
119 echo
120 '<p>© 2004-2005 Ant P | ',round(microtime(1) - CLOCK, 4),'s | ',
121 ( defined('DEVELOPER') ?
122 $GLOBALS['DB']->c.' queries | '.
123 $GLOBALS['user']->gets.' $user::gets | '.
124 $GLOBALS['user']->sets.' $user::sets' :
125 count($this->errors).' errors' ),
126 ' | <a href="http://specialops.ath.cx/b/#Special_Ops_Two">',SO2VER,"</a></p>\n</form>\n",
127 '</body></html>';
129 exit;
132 function error_handler($number, $string, $file, $line)
134 $this->errors[] = array($number, $string, $file, $line);