Mercurial > owls
view Owls.php @ 12:682b4a24469c
optimized layout of ctrl bar
author | meillo@marmaro.de |
---|---|
date | Sun, 27 May 2007 02:28:20 +0200 |
parents | 46617062bef5 |
children | 3e3fa7725abb |
line wrap: on
line source
<?php require_once 'Config.inc.php'; define('DB_PREFIX', $db_prefix); define('TITLE', $title); require_once $db_connect; require_once 'Includes/Loginsys.class.php'; include_once 'Includes/Bbcodeparser.inc.php'; $lsys = &new Loginsys(); ?> <!-- `Owls' - some kind of wiki system (c) Copyright 2006 &> by Meillo r e t u r n s This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. http://prog.marmaro.de/owls/ --> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xml:lang="de" xmlns="http://www.w3.org/1999/xhtml"> <head> <title><?php echo htmlentities(TITLE); ?></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="shortcut icon" href="favicon.ico" /> <link rel="stylesheet" type="text/css" href="Owls.css.php" /> <script type="text/javascript"> <!-- function sureToDelete(id) { if (window.prompt("Type 'delete' to delete","") == "delete") { location.href = id +"d"; } } /* I want to use this function later ... perhaps function toggleVisibility(boxId) { if (document.getElementById('node'+ boxId).style.display == 'none') { document.getElementById('node'+ boxId).style.display = ""; document.getElementById('ctrl'+ boxId).firstChild.nodeValue = "-"; } else{ document.getElementById('node'+ boxId).style.display = "none"; document.getElementById('ctrl'+ boxId).firstChild.nodeValue = "+"; } } */ //--> </script> </head> <body> <div id="websiteContainer"> <!-- Banner --> <img src="Owls.png" id="banner" alt="<?php echo htmlentities(TITLE); ?>" /> <?php if ($_GET['action'] == 'show') { // show show($lsys); } else if ($_GET['action'] == 'new' && $lsys->loggedIn()) { // new create($lsys); } else if ($_GET['action'] == 'edit' && $lsys->loggedIn()) { // edit edit($lsys); } else if ($_GET['action'] == 'delete' && $lsys->loggedIn()) { // delete delete($lsys); } else if ($_GET['action'] == 'login') { // login $lsys->login($_POST['login_loginname'], md5($_POST['login_password'])); show($lsys); } else if ($_GET['action'] == 'logout') { // logout $lsys->logout(); show($lsys); } else { // startpage $_GET['id'] = 1; show($lsys); } ?> </div> </div> </body> </html> <?php /* displays content of the node performs action 'edit' shows admincontrols if logged in */ function show($lsys) { // perform action: write edited node to db if (isset($_POST['editDoc']) && $lsys->loggedIn()) { $_POST['editDoc_title'] = addslashes($_POST['editDoc_title']); $_POST['editDoc_text'] = addslashes($_POST['editDoc_text']); mysql_query("update ". DB_PREFIX ."Owls set name='$_POST[editDoc_title]', text='$_POST[editDoc_text]', idParent='$_POST[editDoc_idCategory]', date=". time() ." where id='$_GET[id]'") or die(mysql_error()); } // print nav include 'Includes/Nav.inc.php'; // query data of the node $result = mysql_query("select * from ". DB_PREFIX ."Owls where id=$_GET[id]"); // catch nodes that not exist if (!mysql_num_rows($result)) { $fnord = array('', 'Fnord is the space between the pixels on your screen.', 'Fnord is the echo of silence.', 'Fnord is evaporated herbal tea without the herbs.', 'Fnord is what you see when you close your eyes.', 'Fnord is the empty pages at the end of the book.', 'Fnord is why ducks eat trees.', 'Fnord is the bucket where they keep the unused serifs for H*lvetica.', 'Fnord is the source of all the zero bits in your computer.' ); ?> <div id="content"> <h2>Error 23 - fnord found</h2> <p> <?php echo $fnord[rand(0, sizeof($fnord)-1)]; ?> </p> <?php } else { $row = mysql_fetch_array($result); echo ' <div id="content">'."\n"; // display admin controls or login form ?> <div class="ctrl"> <?php // display last update if ($_GET['id'] == 1) { // root node displays date of last modification of any node $sql = sprintf(" select max(date) from %sOwls ", DB_PREFIX ); } else { $sql = sprintf(" select date from %sOwls where id = ". $_GET['id'] ." ", DB_PREFIX ); } $result = mysql_query($sql) or die(mysql_error()); unset($sql); $rowUpdate = mysql_fetch_row($result); $lastUpdate = $rowUpdate[0]; ?> <span style="font-size: 0.8em;"> last update: <?php echo date('d.m.Y H:i', $lastUpdate); ?> </span> <?php if ($lsys->loggedIn()) { ?> <a href="<?php echo $row['id'] .'n'; ?>">new</a> <a href="<?php echo $row['id'] .'e'; ?>">edit</a> <?php if ($row['id'] != 1) { echo '<a href="javascript:sureToDelete('. $row['id'] .')">delete</a>'; } echo ' <a href="'. $_GET['id'] .'logout" style="color: #c00;">logout</a>'; } else { ?> <form name="loginform" id="loginform" action="<?php echo $_GET['id']; ?>login" method="post" enctype="multipart/form-data" style="display: inline;"> <input name="login_loginname" type="text" /> <input name="login_password" type="password" /> <input name="login" type="submit" value="login" style="padding: 0; cursor: pointer; width: 5em;" /> </form> <?php } ?> </div> <?php // print content of the node echo ' <h2>'.stripslashes($row['name']).'</h2>'."\n"; if (!empty($row['text'])) { echo ' <p>'.bbcode(stripslashes($row['text']), 1, 1).'</p>'; } } echo "\n\n"; } /* displays edit form */ function edit($lsys) { include 'Includes/Nav.inc.php'; $sql = "select * from ". DB_PREFIX ."Owls where id=$_GET[id]"; $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_array($result); echo '<div id="content">'; ?> <div id="edit" style="position: relative; width: 99%"> <form action="<?php echo $row['id']; ?>" method="post" enctype="multipart/form-data"> <?php if ($_GET['id'] != 1) { ?> <select name="editDoc_idCategory" style="width: 99%;"> <?php $sql = sprintf(" select * from %sOwls where id != %d and idParent != %d -- not in ( -- select idParent from %sOwls -- ) order by name asc ", DB_PREFIX, $row['id'], $row['id'], DB_PREFIX ); $result = mysql_query($sql) or die(mysql_error()); unset($sql); while($rowCats = mysql_fetch_array($result)) { echo ' <option value="'.$rowCats['id'].'"'. (($row['idParent'] == $rowCats['id']) ? ' selected="selected" style="font-weight: bold;"' : '') .'>'.stripslashes($rowCats['name']).'</option>'; } ?> </select><br /><br /> <?php } ?> <input name="editDoc_title" type="text" value="<?php echo stripslashes($row['name']); ?>" style="width: 99%; font-weight: bold;" /><br /> <textarea name="editDoc_text" cols="60" rows="15" style="width: 99%; height: 30em;"><?php echo stripslashes($row['text']); ?></textarea><br /><br /> <input name="editDoc" type="submit" value="edit" class="button" style="width: 99%;" /> </form> </div> <?php unset($row); unset($result); } /* performs action 'new' */ function create($lsys) { // perform action: new node mysql_query(" insert into ". DB_PREFIX ."Owls (idParent, date) values('$_GET[id]',". time() .") ") or die(mysql_error()); // set node to jump to (new created node) $_GET['id'] = mysql_insert_id(); edit($lsys); } /* performs action 'delete' */ function delete($lsys) { // not allowed to delete the root if ($_GET['id'] != 1) { // TODO: get the parent of the one which is to delete // delete mysql_query("delete from ". DB_PREFIX ."Owls where id='$_GET[id]'") or die(mysql_error()); } // set node to jump to (TODO: parent from above) $_GET['id'] = 1; show($lsys); } ?>