owls

view Owls.php @ 0:3021ce32ee14

begin of using hg for owls
author "Meillo r e t u r n s <meillo@marmaro.de>"
date Sun, 03 Dec 2006 22:32:13 +0100
parents
children ab74e95a8040
line source
1 <?php
2 require_once 'Includes/Header.inc.php';
5 if ($_GET['action'] == 'show') { // show
6 show($lsys);
8 } else if ($_GET['action'] == 'new' && $lsys->loggedIn()) { // new
9 create($lsys);
11 } else if ($_GET['action'] == 'edit' && $lsys->loggedIn()) { // edit
12 edit($lsys);
14 } else if ($_GET['action'] == 'delete' && $lsys->loggedIn()) { // delete
15 delete($lsys);
17 } else if ($_GET['action'] == 'login') { // login
18 $lsys->login($_POST['login_loginname'], md5($_POST['login_password']));
19 show($lsys);
21 } else if ($_GET['action'] == 'logout') { // logout
22 $lsys->logout();
23 show($lsys);
25 } else { // startpage
26 $_GET['id'] = 1;
27 show($lsys);
29 }
32 require_once 'Includes/Footer.inc.php';
44 /*
45 displays content of the node
46 performs action 'edit'
47 shows admincontrols if logged in
48 */
49 function show($lsys) {
51 // perform action: write edited node to db
52 if (isset($_POST['editDoc']) && $lsys->loggedIn()) {
53 $_POST['editDoc_title'] = addslashes($_POST['editDoc_title']);
54 $_POST['editDoc_text'] = addslashes($_POST['editDoc_text']);
55 mysql_query("update ". DB_PREFIX ."Owls set
56 name='$_POST[editDoc_title]',
57 text='$_POST[editDoc_text]',
58 idParent='$_POST[editDoc_idCategory]',
59 date=". time() ."
60 where id='$_GET[id]'") or die(mysql_error());
61 }
63 // print nav
64 include 'Includes/Nav.inc.php';
67 // query data of the node
68 $result = mysql_query("select * from ". DB_PREFIX ."Owls where id=$_GET[id]");
70 // catch nodes that not exist
71 if (!mysql_num_rows($result)) {
73 $fnord = array('',
74 'Fnord is the space between the pixels on your screen.',
75 'Fnord is the echo of silence.',
76 'Fnord is evaporated herbal tea without the herbs.',
77 'Fnord is what you see when you close your eyes.',
78 'Fnord is the empty pages at the end of the book.',
79 'Fnord is why ducks eat trees.',
80 'Fnord is the bucket where they keep the unused serifs for H*lvetica.',
81 'Fnord is the source of all the zero bits in your computer.'
82 );
84 ?>
85 <div id="content">
86 <h2>Error 23 - fnord found</h2>
87 <p>
88 <?php echo $fnord[rand(0, sizeof($fnord)-1)]; ?>
89 </p>
90 <?php
92 } else {
94 $row = mysql_fetch_array($result);
95 echo ' <div id="content">'."\n";
97 // display admin controls if logged in
98 if ($lsys->loggedIn()) {
99 ?>
100 <div class="ctrl" style="font-size: 0.8em;">
101 <a href="<?php echo $row['id'] .'n'; ?>">new</a>
102 <a href="<?php echo $row['id'] .'e'; ?>">edit</a>
103 <?php
104 if ($row['id'] != 1) {
105 echo '<a href="javascript:sureToDelete('. $row['id'] .')">delete</a>';
106 }
107 ?>
108 </div>
109 <?php
110 }
112 // print content of the node
113 echo ' <h2>'.stripslashes($row['name']).'</h2>'."\n";
114 if (!empty($row['text'])) {
115 echo ' <p>'.bbcode(stripslashes($row['text']), 1, 1).'</p>';
116 }
117 }
118 echo "\n\n";
120 }
126 /*
127 displays edit form
128 */
129 function edit($lsys) {
131 include 'Includes/Nav.inc.php';
133 $sql = "select * from ". DB_PREFIX ."Owls where id=$_GET[id]";
134 $result = mysql_query($sql) or die(mysql_error());
135 $row = mysql_fetch_array($result);
136 echo '<div id="content">';
137 ?>
138 <div id="edit">
139 <form action="<?php echo $row['id']; ?>" method="post" enctype="multipart/form-data">
140 <?php
141 if ($_GET['id'] != 1) {
142 ?>
143 <select name="editDoc_idCategory" style="width: 99%;">
144 <?php
145 $result = mysql_query("select * from ". DB_PREFIX ."Owls order by name asc") or die(mysql_error());
146 while($rowCats = mysql_fetch_array($result)) {
147 echo ' <option value="'.$rowCats['id'].'"'. (($row['idParent'] == $rowCats['id']) ? ' selected="selected"' : '') .'>'.stripslashes($rowCats['name']).'</option>';
148 }
149 ?>
150 </select><br /><br />
151 <?php
152 }
153 ?>
154 <input name="editDoc_title" type="text" value="<?php echo stripslashes($row['name']); ?>" style="width: 99%;" /><br />
155 <textarea name="editDoc_text" cols="60" rows="15" style="width: 99%; height: 30em;"><?php
156 echo stripslashes($row['text']);
157 ?></textarea><br /><br />
158 <input name="editDoc" type="submit" value="edit" class="button" style="width: 99%;" />
159 </form>
160 </div>
161 <?php
162 unset($row);
163 unset($result);
164 }
171 /*
172 performs action 'new'
173 */
174 function create($lsys) {
176 // perform action: new node
177 mysql_query("
178 insert into ". DB_PREFIX ."Owls
179 (idParent, date)
180 values('$_GET[id]',". time() .")
181 ") or die(mysql_error());
183 // set node to jump to (new created node)
184 $_GET['id'] = mysql_insert_id();
185 edit($lsys);
186 }
192 /*
193 performs action 'delete'
194 */
195 function delete($lsys) {
196 // not allowed to delete the root
197 if ($_GET['id'] != 1) {
198 // TODO: get the parent of the one which is to delete
200 // delete
201 mysql_query("delete from ". DB_PREFIX ."Owls where id='$_GET[id]'") or die(mysql_error());
202 }
203 // set node to jump to (TODO: parent from above)
204 $_GET['id'] = 1;
205 show($lsys);
206 }
211 ?>