owls

view Owls.php @ 10:144bc36a6c27

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