owls

view Owls.php @ 16:22243e7c7dc5

Name of banner pic is now configurable
author meillo@marmaro.de
date Sun, 27 May 2007 14:06:42 +0200
parents cebc198276eb
children
line source
1 <?php
3 require_once 'Config/Config.inc.php';
5 define('DB_PREFIX', $db_prefix);
6 define('TITLE', $title);
8 require_once $db_connect;
9 require_once 'Loginsys.class.php';
10 include_once 'Bbcodeparser.inc.php';
12 $lsys = &new Loginsys();
14 ?>
15 <!--
17 `Owls' - some kind of wiki system
20 (c) Copyright 2006 &> by Meillo r e t u r n s
22 This program is free software; you can redistribute it and/or
23 modify it under the terms of the GNU General Public License
24 as published by the Free Software Foundation; either version 2
25 of the License, or (at your option) any later version.
27 This program is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
33 http://prog.marmaro.de/owls/
35 -->
37 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
39 <html xml:lang="de" xmlns="http://www.w3.org/1999/xhtml">
40 <head>
41 <title><?php echo htmlentities(TITLE); ?></title>
42 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
43 <link rel="shortcut icon" href="favicon.ico" />
44 <link rel="stylesheet" type="text/css" href="Config/Owls.css.php" />
45 <script type="text/javascript">
46 <!--
47 function sureToDelete(id) {
48 if (window.prompt("Type 'delete' to delete","") == "delete") {
49 location.href = id +"d";
50 }
51 }
53 /* I want to use this function later ... perhaps
54 function toggleVisibility(boxId) {
55 if (document.getElementById('node'+ boxId).style.display == 'none') {
56 document.getElementById('node'+ boxId).style.display = "";
57 document.getElementById('ctrl'+ boxId).firstChild.nodeValue = "-";
58 } else{
59 document.getElementById('node'+ boxId).style.display = "none";
60 document.getElementById('ctrl'+ boxId).firstChild.nodeValue = "+";
61 }
62 }
63 */
64 //-->
65 </script>
66 </head>
68 <body>
69 <div id="websiteContainer">
71 <!-- Banner -->
72 <img src="<?php echo $banner; ?>" id="banner" alt="<?php echo htmlentities(TITLE); ?>" />
74 <?php
77 if ($_GET['action'] == 'show') { // show
78 show($lsys);
80 } else if ($_GET['action'] == 'new' && $lsys->loggedIn()) { // new
81 create($lsys);
83 } else if ($_GET['action'] == 'edit' && $lsys->loggedIn()) { // edit
84 edit($lsys);
86 } else if ($_GET['action'] == 'delete' && $lsys->loggedIn()) { // delete
87 delete($lsys);
89 } else if ($_GET['action'] == 'login') { // login
90 $lsys->login($_POST['login_loginname'], md5($_POST['login_password']));
91 show($lsys);
93 } else if ($_GET['action'] == 'logout') { // logout
94 $lsys->logout();
95 show($lsys);
97 } else { // startpage
98 $_GET['id'] = 1;
99 show($lsys);
101 }
107 ?>
109 </div>
112 </div>
114 </body>
115 </html>
116 <?php
125 /*
126 displays content of the node
127 performs action 'edit'
128 shows admincontrols if logged in
129 */
130 function show($lsys) {
133 // perform action: write edited node to db
134 if (isset($_POST['editDoc']) && $lsys->loggedIn()) {
135 $_POST['editDoc_title'] = addslashes($_POST['editDoc_title']);
136 $_POST['editDoc_text'] = addslashes($_POST['editDoc_text']);
137 mysql_query("update ". DB_PREFIX ."Owls set
138 name='$_POST[editDoc_title]',
139 text='$_POST[editDoc_text]',
140 idParent='$_POST[editDoc_idCategory]',
141 date=". time() ."
142 where id='$_GET[id]'") or die(mysql_error());
143 }
145 // print nav
146 include 'Nav.inc.php';
151 // query data of the node
152 $result = mysql_query("select * from ". DB_PREFIX ."Owls where id=$_GET[id]");
154 // catch nodes that not exist
155 if (!mysql_num_rows($result)) {
157 $fnord = array('',
158 'Fnord is the space between the pixels on your screen.',
159 'Fnord is the echo of silence.',
160 'Fnord is evaporated herbal tea without the herbs.',
161 'Fnord is what you see when you close your eyes.',
162 'Fnord is the empty pages at the end of the book.',
163 'Fnord is why ducks eat trees.',
164 'Fnord is the bucket where they keep the unused serifs for H*lvetica.',
165 'Fnord is the source of all the zero bits in your computer.'
166 );
168 ?>
169 <div id="content">
170 <h2>Error 23 - fnord found</h2>
171 <p>
172 <?php echo $fnord[rand(0, sizeof($fnord)-1)]; ?>
173 </p>
174 <?php
176 } else {
178 $row = mysql_fetch_array($result);
179 echo ' <div id="content">'."\n";
181 // display admin controls or login form
182 ?>
183 <div class="ctrl">
184 <?php
185 // display last update
186 if ($_GET['id'] == 1) {
187 // root node displays date of last modification of any node
188 $sql = sprintf("
189 select
190 max(date)
191 from %sOwls
192 ",
193 DB_PREFIX
194 );
195 } else {
196 $sql = sprintf("
197 select
198 date
199 from %sOwls
200 where
201 id = ". $_GET['id'] ."
202 ",
203 DB_PREFIX
204 );
205 }
206 $result = mysql_query($sql) or die(mysql_error());
207 unset($sql);
209 $rowUpdate = mysql_fetch_row($result);
210 $lastUpdate = $rowUpdate[0];
211 ?>
212 <span style="font-size: 0.8em;">
213 last update: <?php echo date('d.m.Y H:i', $lastUpdate); ?>
214 </span>
216 <?php
217 if ($lsys->loggedIn()) {
218 ?>
219 <a href="<?php echo $row['id'] .'n'; ?>">new</a>
220 <a href="<?php echo $row['id'] .'e'; ?>">edit</a>
221 <?php
222 if ($row['id'] != 1) {
223 echo '<a href="javascript:sureToDelete('. $row['id'] .')">delete</a>';
224 }
225 echo ' <a href="'. $_GET['id'] .'logout" style="color: #c00;">logout</a>';
226 } else {
227 ?>
228 <form name="loginform" id="loginform" action="<?php echo $_GET['id']; ?>login" method="post" enctype="multipart/form-data" style="display: inline;">
229 <input name="login_loginname" type="text" />
230 <input name="login_password" type="password" />
231 <input name="login" type="submit" value="login" style="padding: 0; cursor: pointer; width: 5em;" />
232 </form>
233 <?php
234 }
235 ?>
236 </div>
237 <?php
239 // print content of the node
240 echo ' <h2>'.stripslashes($row['name']).'</h2>'."\n";
241 if (!empty($row['text'])) {
242 echo ' <p>'.bbcode(stripslashes($row['text']), 1, 1).'</p>';
243 }
244 }
245 echo "\n\n";
247 }
253 /*
254 displays edit form
255 */
256 function edit($lsys) {
258 include 'Nav.inc.php';
260 $sql = "select * from ". DB_PREFIX ."Owls where id=$_GET[id]";
261 $result = mysql_query($sql) or die(mysql_error());
262 $row = mysql_fetch_array($result);
263 echo '<div id="content">';
264 ?>
265 <div id="edit" style="position: relative; width: 99%">
266 <form action="<?php echo $row['id']; ?>" method="post" enctype="multipart/form-data">
267 <?php
268 if ($_GET['id'] != 1) {
269 ?>
270 <select name="editDoc_idCategory" style="width: 99%;">
271 <?php
272 $sql = sprintf("
273 select
274 *
275 from %sOwls
276 where
277 id != %d
278 and idParent != %d
279 -- not in (
280 -- select idParent from %sOwls
281 -- )
282 order by name asc
283 ",
284 DB_PREFIX,
285 $row['id'],
286 $row['id'],
287 DB_PREFIX
288 );
289 $result = mysql_query($sql) or die(mysql_error());
290 unset($sql);
291 while($rowCats = mysql_fetch_array($result)) {
292 echo ' <option value="'.$rowCats['id'].'"'. (($row['idParent'] == $rowCats['id']) ? ' selected="selected" style="font-weight: bold;"' : '') .'>'.stripslashes($rowCats['name']).'</option>';
293 }
294 ?>
295 </select><br /><br />
296 <?php
297 }
298 ?>
299 <input name="editDoc_title" type="text" value="<?php echo stripslashes($row['name']); ?>" style="width: 99%; font-weight: bold;" /><br />
300 <textarea name="editDoc_text" cols="60" rows="15" style="width: 99%; height: 30em;"><?php
301 echo stripslashes($row['text']);
302 ?></textarea><br /><br />
303 <input name="editDoc" type="submit" value="edit" class="button" style="width: 99%;" />
304 </form>
305 </div>
306 <?php
307 unset($row);
308 unset($result);
309 }
316 /*
317 performs action 'new'
318 */
319 function create($lsys) {
321 // perform action: new node
322 mysql_query("
323 insert into ". DB_PREFIX ."Owls
324 (idParent, date)
325 values('$_GET[id]',". time() .")
326 ") or die(mysql_error());
328 // set node to jump to (new created node)
329 $_GET['id'] = mysql_insert_id();
330 edit($lsys);
331 }
337 /*
338 performs action 'delete'
339 */
340 function delete($lsys) {
341 // not allowed to delete the root
342 if ($_GET['id'] != 1) {
343 // TODO: get the parent of the one which is to delete
345 // delete
346 mysql_query("delete from ". DB_PREFIX ."Owls where id='$_GET[id]'") or die(mysql_error());
347 }
348 // set node to jump to (TODO: parent from above)
349 $_GET['id'] = 1;
350 show($lsys);
351 }
356 ?>