owls
view Owls.php @ 6:f79096d1d0ed
another color adjustment
author | Meillo r e t u r n s <meillo@marmaro.de> |
---|---|
date | Wed, 13 Dec 2006 20:02:56 +0100 |
parents | ab74e95a8040 |
children | 144bc36a6c27 |
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
78 if ($_GET['action'] == 'show') { // show
79 show($lsys);
81 } else if ($_GET['action'] == 'new' && $lsys->loggedIn()) { // new
82 create($lsys);
84 } else if ($_GET['action'] == 'edit' && $lsys->loggedIn()) { // edit
85 edit($lsys);
87 } else if ($_GET['action'] == 'delete' && $lsys->loggedIn()) { // delete
88 delete($lsys);
90 } else if ($_GET['action'] == 'login') { // login
91 $lsys->login($_POST['login_loginname'], md5($_POST['login_password']));
92 show($lsys);
94 } else if ($_GET['action'] == 'logout') { // logout
95 $lsys->logout();
96 show($lsys);
98 } else { // startpage
99 $_GET['id'] = 1;
100 show($lsys);
102 }
108 ?>
110 </div>
113 </div>
115 </body>
116 </html>
117 <?php
129 /*
130 displays content of the node
131 performs action 'edit'
132 shows admincontrols if logged in
133 */
134 function show($lsys) {
136 // perform action: write edited node to db
137 if (isset($_POST['editDoc']) && $lsys->loggedIn()) {
138 $_POST['editDoc_title'] = addslashes($_POST['editDoc_title']);
139 $_POST['editDoc_text'] = addslashes($_POST['editDoc_text']);
140 mysql_query("update ". DB_PREFIX ."Owls set
141 name='$_POST[editDoc_title]',
142 text='$_POST[editDoc_text]',
143 idParent='$_POST[editDoc_idCategory]',
144 date=". time() ."
145 where id='$_GET[id]'") or die(mysql_error());
146 }
148 // print nav
149 include 'Includes/Nav.inc.php';
152 // query data of the node
153 $result = mysql_query("select * from ". DB_PREFIX ."Owls where id=$_GET[id]");
155 // catch nodes that not exist
156 if (!mysql_num_rows($result)) {
158 $fnord = array('',
159 'Fnord is the space between the pixels on your screen.',
160 'Fnord is the echo of silence.',
161 'Fnord is evaporated herbal tea without the herbs.',
162 'Fnord is what you see when you close your eyes.',
163 'Fnord is the empty pages at the end of the book.',
164 'Fnord is why ducks eat trees.',
165 'Fnord is the bucket where they keep the unused serifs for H*lvetica.',
166 'Fnord is the source of all the zero bits in your computer.'
167 );
169 ?>
170 <div id="content">
171 <h2>Error 23 - fnord found</h2>
172 <p>
173 <?php echo $fnord[rand(0, sizeof($fnord)-1)]; ?>
174 </p>
175 <?php
177 } else {
179 $row = mysql_fetch_array($result);
180 echo ' <div id="content">'."\n";
182 // display admin controls if logged in
183 if ($lsys->loggedIn()) {
184 ?>
185 <div class="ctrl">
186 <a href="<?php echo $row['id'] .'n'; ?>">new</a>
187 <a href="<?php echo $row['id'] .'e'; ?>">edit</a>
188 <?php
189 if ($row['id'] != 1) {
190 echo '<a href="javascript:sureToDelete('. $row['id'] .')">delete</a>';
191 }
192 ?>
193 </div>
194 <?php
195 }
197 // print content of the node
198 echo ' <h2>'.stripslashes($row['name']).'</h2>'."\n";
199 if (!empty($row['text'])) {
200 echo ' <p>'.bbcode(stripslashes($row['text']), 1, 1).'</p>';
201 }
202 }
203 echo "\n\n";
205 }
211 /*
212 displays edit form
213 */
214 function edit($lsys) {
216 include 'Includes/Nav.inc.php';
218 $sql = "select * from ". DB_PREFIX ."Owls where id=$_GET[id]";
219 $result = mysql_query($sql) or die(mysql_error());
220 $row = mysql_fetch_array($result);
221 echo '<div id="content">';
222 ?>
223 <div id="edit" style="position: relative; width: 99%">
224 <form action="<?php echo $row['id']; ?>" method="post" enctype="multipart/form-data">
225 <?php
226 if ($_GET['id'] != 1) {
227 ?>
228 <select name="editDoc_idCategory" style="width: 99%;">
229 <?php
230 $sql = sprintf("
231 select
232 *
233 from %sOwls
234 where
235 id != %d
236 and idParent != %d
237 -- not in (
238 -- select idParent from %sOwls
239 -- )
240 order by name asc
241 ",
242 DB_PREFIX,
243 $row['id'],
244 $row['id'],
245 DB_PREFIX
246 );
247 $result = mysql_query($sql) or die(mysql_error());
248 unset($sql);
249 while($rowCats = mysql_fetch_array($result)) {
250 echo ' <option value="'.$rowCats['id'].'"'. (($row['idParent'] == $rowCats['id']) ? ' selected="selected" style="font-weight: bold;"' : '') .'>'.stripslashes($rowCats['name']).'</option>';
251 }
252 ?>
253 </select><br /><br />
254 <?php
255 }
256 ?>
257 <input name="editDoc_title" type="text" value="<?php echo stripslashes($row['name']); ?>" style="width: 99%; font-weight: bold;" /><br />
258 <textarea name="editDoc_text" cols="60" rows="15" style="width: 99%; height: 30em;"><?php
259 echo stripslashes($row['text']);
260 ?></textarea><br /><br />
261 <input name="editDoc" type="submit" value="edit" class="button" style="width: 99%;" />
262 </form>
263 </div>
264 <?php
265 unset($row);
266 unset($result);
267 }
274 /*
275 performs action 'new'
276 */
277 function create($lsys) {
279 // perform action: new node
280 mysql_query("
281 insert into ". DB_PREFIX ."Owls
282 (idParent, date)
283 values('$_GET[id]',". time() .")
284 ") or die(mysql_error());
286 // set node to jump to (new created node)
287 $_GET['id'] = mysql_insert_id();
288 edit($lsys);
289 }
295 /*
296 performs action 'delete'
297 */
298 function delete($lsys) {
299 // not allowed to delete the root
300 if ($_GET['id'] != 1) {
301 // TODO: get the parent of the one which is to delete
303 // delete
304 mysql_query("delete from ". DB_PREFIX ."Owls where id='$_GET[id]'") or die(mysql_error());
305 }
306 // set node to jump to (TODO: parent from above)
307 $_GET['id'] = 1;
308 show($lsys);
309 }
314 ?>