Rev 1 | Rev 3 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | tom | 1 | <?php |
2 | |||
3 | class Taios_Page |
||
4 | { |
||
5 | function __construct($title, $url = "") |
||
6 | { |
||
7 | $this->title = $title; |
||
8 | $this->url = $url; |
||
9 | |||
10 | $this->drawnHeader = false; |
||
11 | $this->drawnMiddle = false; |
||
12 | $this->drawnFooter = false; |
||
13 | |||
14 | $this->db = mysql_connect('localhost', 'root', 'puppylinux'); |
||
15 | if (!$this->db) |
||
16 | { |
||
17 | $this->drawError('Failed to connect to database: ' . mysql_error()); |
||
18 | } |
||
19 | |||
20 | if (!mysql_select_db('Tim32')) |
||
21 | { |
||
22 | $this->drawError('Failed to select database: ' . mysql_error()); |
||
23 | } |
||
24 | } |
||
25 | |||
26 | function drawHeader() |
||
27 | { |
||
28 | if (!$this->drawnHeader) |
||
29 | { |
||
30 | write('<!DOCTYPE html>'); |
||
31 | write('<html>'); |
||
32 | write('<head>'); |
||
33 | write('<meta http-equiv="Content-Type" content="text/html;charset=utf-8">'); |
||
34 | write('<title>Tim32 · ' . $this->title . '</title>'); |
||
35 | write('<link href="' . $this->url . 'styles.css" rel="stylesheet" type="text/css" media="screen">'); |
||
36 | write('</head>'); |
||
37 | write('<body>'); |
||
38 | write('<div class="sidebar">'); |
||
39 | write('<div class="sidebar-header">'); |
||
40 | write('<h1>Tim32</h1>'); |
||
41 | write('</div>'); |
||
42 | write('<div class="sidebar-menu">'); |
||
43 | $this->drawMenuItem('Home', 'index.php'); |
||
44 | $this->drawMenuItem('Blog', 'blog/'); |
||
45 | $this->drawMenuItem('Projects', 'projects/'); |
||
46 | $this->drawMenuItem('Forums', 'forums/'); |
||
47 | $this->drawMenuItem('Wiki', 'wiki/'); |
||
48 | $this->drawMenuItem('Photos', 'photos/'); |
||
49 | write('<br />'); |
||
50 | if ($this->isLoggedIn()) |
||
51 | { |
||
52 | $this->drawMenuItem('Manage Account', 'admim/?id=' . $this->getLoggedInUser()->ID); |
||
53 | $this->drawMenuItem('Logout', 'logout-do.php'); |
||
54 | } |
||
55 | else |
||
56 | { |
||
57 | $this->drawMenuItem('Login', 'login.php'); |
||
58 | $this->drawMenuItem('Register', 'register.php'); |
||
59 | } |
||
60 | write('<br />'); |
||
61 | |||
62 | $this->drawnHeader = true; |
||
63 | } |
||
64 | } |
||
65 | |||
66 | function drawMenuItem($t, $u) |
||
67 | { |
||
68 | write('<p><a href="' . $this->url . $u . '"</a>' . $t . '</a></p>'); |
||
69 | } |
||
70 | |||
71 | function drawMiddle() |
||
72 | { |
||
73 | if (!$this->drawnMiddle) |
||
74 | { |
||
75 | write('<br />'); |
||
76 | write('</div>'); |
||
77 | write('</div>'); |
||
78 | write('<div class="content">'); |
||
79 | write('<h2>' . $this->title . '</h2>'); |
||
80 | |||
81 | $this->drawnMiddle = true; |
||
82 | } |
||
83 | } |
||
84 | |||
85 | function drawFooter() |
||
86 | { |
||
87 | if (!$this->drawnFooter) |
||
88 | { |
||
89 | write('</div>'); |
||
90 | write('</body>'); |
||
91 | write('</html>'); |
||
92 | |||
93 | $this->drawnFooter = true; |
||
94 | } |
||
95 | |||
2 | tom | 96 | // die(); |
1 | tom | 97 | } |
98 | |||
99 | function drawError($text, $die = true) |
||
100 | { |
||
101 | $this->drawHeader(); |
||
102 | $this->drawMiddle(); |
||
103 | |||
104 | write('<h4 style="color: red;">Error: ' . $text . '</h4>'); |
||
105 | |||
106 | if ($die) |
||
107 | { |
||
108 | $this->drawFooter(); |
||
109 | die(); |
||
110 | } |
||
111 | } |
||
112 | |||
113 | function redirect($url) |
||
114 | { |
||
115 | header('Location: ' . $url); |
||
116 | die(); |
||
117 | } |
||
118 | |||
119 | function isLoggedIn() |
||
120 | { |
||
121 | $cookie = $_COOKIE['Tim32_Login']; |
||
122 | if (!empty($cookie)) |
||
123 | { |
||
124 | $clist = explode('|~|', $cookie); |
||
125 | $user = $this->getUserByUsername($clist[0]); |
||
126 | if ($user) |
||
127 | { |
||
128 | if ($user->password == $clist[1]) |
||
129 | { |
||
130 | return true; |
||
131 | } |
||
132 | } |
||
133 | } |
||
134 | |||
135 | return false; |
||
136 | } |
||
137 | |||
138 | function isUserAdmin() |
||
139 | { |
||
140 | if ($this->isLoggedIn()) |
||
141 | { |
||
142 | if ($this->getLoggedInUser()->accessID <= 0) |
||
143 | { |
||
144 | return true; |
||
145 | } |
||
146 | } |
||
147 | |||
148 | return false; |
||
149 | } |
||
150 | |||
151 | function isUserGM() |
||
152 | { |
||
153 | if ($this->isLoggedIn()) |
||
154 | { |
||
155 | if ($this->getLoggedInUser()->accessID <= 1) |
||
156 | { |
||
157 | return true; |
||
158 | } |
||
159 | } |
||
160 | |||
161 | return false; |
||
162 | } |
||
163 | |||
164 | function isUserNormal() |
||
165 | { |
||
166 | if ($this->isLoggedIn()) |
||
167 | { |
||
168 | if ($this->getLoggedInUser()->accessID <= 2) |
||
169 | { |
||
170 | return true; |
||
171 | } |
||
172 | } |
||
173 | |||
174 | return false; |
||
175 | } |
||
176 | |||
177 | function query($query) |
||
178 | { |
||
179 | $result = mysql_query($query); |
||
180 | if (!$result) |
||
181 | { |
||
182 | $this->drawError('MySQL Error: ' . mysql_error()); |
||
183 | } |
||
184 | |||
185 | return $result; |
||
186 | } |
||
187 | |||
188 | function findIDs($table, $query = '') |
||
189 | { |
||
190 | $array = array(); |
||
191 | |||
192 | $result = $this->query('SELECT ID FROM ' . $table . ' ' . $query); |
||
193 | while ($row = mysql_fetch_array($result)) |
||
194 | { |
||
195 | array_push($array, $row['ID']); |
||
196 | } |
||
197 | |||
198 | return $array; |
||
199 | } |
||
200 | |||
201 | function getUserByID($id) |
||
202 | { |
||
203 | $result = $this->query('SELECT * FROM Users WHERE ID = ' . $id); |
||
204 | while ($row = mysql_fetch_array($result)) |
||
205 | { |
||
206 | $user = new User; |
||
207 | $user->ID = $row['ID']; |
||
208 | $user->accessID = $row['AccessID']; |
||
209 | $user->username = $row['Username']; |
||
210 | $user->password = $row['Password']; |
||
211 | $user->emailAddress = $row['EmailAddress']; |
||
212 | $user->name = $row['Name']; |
||
213 | $user->challengeID = $row['ChallengeID']; |
||
214 | |||
215 | return $user; |
||
216 | } |
||
217 | |||
218 | return false; |
||
219 | } |
||
220 | |||
221 | function getUserByUsername($username) |
||
222 | { |
||
223 | $result = $this->query('SELECT * FROM Users WHERE Username = "' . $username . '"'); |
||
224 | while ($row = mysql_fetch_array($result)) |
||
225 | { |
||
226 | return $this->getUserByID($row['ID']); |
||
227 | } |
||
228 | |||
229 | return false; |
||
230 | } |
||
231 | |||
232 | function getLoggedInUser() |
||
233 | { |
||
234 | if ($this->isLoggedIn()) |
||
235 | { |
||
236 | $clist = explode('|~|', $_COOKIE['Tim32_Login']); |
||
237 | return $this->getUserByUsername($clist[0]); |
||
238 | } |
||
239 | |||
240 | return false; |
||
241 | } |
||
242 | |||
243 | function getBlogPost($id) |
||
244 | { |
||
245 | $result = $this->query('SELECT * FROM BlogPosts WHERE ID = ' . $id); |
||
246 | while ($row = mysql_fetch_array($result)) |
||
247 | { |
||
248 | $post = new BlogPost; |
||
249 | $post->ID = $row['ID']; |
||
250 | $post->user = $this->getUserByID($row['AuthorID']); |
||
251 | $post->title = $row['Title']; |
||
252 | $post->content = $row['Content']; |
||
253 | $post->datePosted = strtotime($row['DatePosted']); |
||
254 | $post->category = $row['Category']; |
||
255 | |||
256 | return $post; |
||
257 | } |
||
258 | |||
259 | $this->drawError('Cannot find blog post, #' . $id); |
||
260 | } |
||
261 | } |
||
262 | |||
263 | class User |
||
264 | { |
||
265 | public $ID; |
||
266 | public $accessID; |
||
267 | public $username; |
||
268 | public $password; |
||
269 | public $emailAddress; |
||
270 | public $name; |
||
271 | public $challengeID; |
||
272 | } |
||
273 | |||
274 | class BlogPost |
||
275 | { |
||
276 | public $ID; |
||
277 | public $author; |
||
278 | public $title; |
||
279 | public $content; |
||
280 | public $datePosted; |
||
281 | public $category; |
||
282 | } |
||
283 | |||
284 | function write($str) |
||
285 | { |
||
286 | echo $str; |
||
287 | echo "\n"; |
||
288 | } |
||
289 | |||
290 | ?> |