owls
view Owls.php @ 11:46617062bef5
put config into own file
author | meillo@marmaro.de |
---|---|
date | Sun, 27 May 2007 02:15:39 +0200 |
parents | 144bc36a6c27 |
children | 682b4a24469c |
line source
1 <?php
3 require_once 'Config.inc.php';
5 define('DB_PREFIX', $db_prefix);
6 define('TITLE', $title);
8 require_once $db_connect;
9 require_once 'Includes/Loginsys.class.php';
10 include_once 'Includes/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="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="Owls.png" 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 'Includes/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">
185 <?php
186 // display last update
187 if ($_GET['id'] == 1) {
188 // root node displays date of last modification of any node
189 $sql = sprintf("
190 select
191 max(date)
192 from %sOwls
193 ",
194 DB_PREFIX
195 );
196 } else {
197 $sql = sprintf("
198 select
199 date
200 from %sOwls
201 where
202 id = ". $_GET['id'] ."
203 ",
204 DB_PREFIX
205 );
206 }
207 $result = mysql_query($sql) or die(mysql_error());
208 unset($sql);
210 $rowUpdate = mysql_fetch_row($result);
211 $lastUpdate = $rowUpdate[0];
212 ?>
213 <span style="font-size: 0.8em;">
214 last update: <?php echo date('d.m.Y H:i', $lastUpdate); ?>
215 </span>
217 <?php
218 if ($lsys->loggedIn()) {
219 ?>
220 <a href="<?php echo $row['id'] .'n'; ?>">new</a>
221 <a href="<?php echo $row['id'] .'e'; ?>">edit</a>
222 <?php
223 if ($row['id'] != 1) {
224 echo '<a href="javascript:sureToDelete('. $row['id'] .')">delete</a>';
225 }
226 echo ' <a href="'. $_GET['id'] .'logout" style="color: #c00;">logout</a>';
227 } else {
228 ?>
229 <form name="loginform" id="loginform" action="<?php echo $_GET['id']; ?>login" method="post" enctype="multipart/form-data" style="display: inline;">
230 <input name="login_loginname" type="text" />
231 <input name="login_password" type="password" />
232 <input name="login" type="submit" value="login" style="padding: 0; cursor: pointer; width: 5em;" />
233 </form>
234 <?php
235 }
236 ?>
237 </div>
238 <?php
240 // print content of the node
241 echo ' <h2>'.stripslashes($row['name']).'</h2>'."\n";
242 if (!empty($row['text'])) {
243 echo ' <p>'.bbcode(stripslashes($row['text']), 1, 1).'</p>';
244 }
245 }
246 echo "\n\n";
248 }
254 /*
255 displays edit form
256 */
257 function edit($lsys) {
259 include 'Includes/Nav.inc.php';
261 $sql = "select * from ". DB_PREFIX ."Owls where id=$_GET[id]";
262 $result = mysql_query($sql) or die(mysql_error());
263 $row = mysql_fetch_array($result);
264 echo '<div id="content">';
265 ?>
266 <div id="edit" style="position: relative; width: 99%">
267 <form action="<?php echo $row['id']; ?>" method="post" enctype="multipart/form-data">
268 <?php
269 if ($_GET['id'] != 1) {
270 ?>
271 <select name="editDoc_idCategory" style="width: 99%;">
272 <?php
273 $sql = sprintf("
274 select
275 *
276 from %sOwls
277 where
278 id != %d
279 and idParent != %d
280 -- not in (
281 -- select idParent from %sOwls
282 -- )
283 order by name asc
284 ",
285 DB_PREFIX,
286 $row['id'],
287 $row['id'],
288 DB_PREFIX
289 );
290 $result = mysql_query($sql) or die(mysql_error());
291 unset($sql);
292 while($rowCats = mysql_fetch_array($result)) {
293 echo ' <option value="'.$rowCats['id'].'"'. (($row['idParent'] == $rowCats['id']) ? ' selected="selected" style="font-weight: bold;"' : '') .'>'.stripslashes($rowCats['name']).'</option>';
294 }
295 ?>
296 </select><br /><br />
297 <?php
298 }
299 ?>
300 <input name="editDoc_title" type="text" value="<?php echo stripslashes($row['name']); ?>" style="width: 99%; font-weight: bold;" /><br />
301 <textarea name="editDoc_text" cols="60" rows="15" style="width: 99%; height: 30em;"><?php
302 echo stripslashes($row['text']);
303 ?></textarea><br /><br />
304 <input name="editDoc" type="submit" value="edit" class="button" style="width: 99%;" />
305 </form>
306 </div>
307 <?php
308 unset($row);
309 unset($result);
310 }
317 /*
318 performs action 'new'
319 */
320 function create($lsys) {
322 // perform action: new node
323 mysql_query("
324 insert into ". DB_PREFIX ."Owls
325 (idParent, date)
326 values('$_GET[id]',". time() .")
327 ") or die(mysql_error());
329 // set node to jump to (new created node)
330 $_GET['id'] = mysql_insert_id();
331 edit($lsys);
332 }
338 /*
339 performs action 'delete'
340 */
341 function delete($lsys) {
342 // not allowed to delete the root
343 if ($_GET['id'] != 1) {
344 // TODO: get the parent of the one which is to delete
346 // delete
347 mysql_query("delete from ". DB_PREFIX ."Owls where id='$_GET[id]'") or die(mysql_error());
348 }
349 // set node to jump to (TODO: parent from above)
350 $_GET['id'] = 1;
351 show($lsys);
352 }
357 ?>