owls

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Owls.php	Sun Dec 03 22:32:13 2006 +0100
     1.3 @@ -0,0 +1,212 @@
     1.4 +<?php
     1.5 +  require_once 'Includes/Header.inc.php';
     1.6 +
     1.7 +
     1.8 +  if ($_GET['action'] == 'show') {    // show
     1.9 +    show($lsys);
    1.10 +
    1.11 +  } else if ($_GET['action'] == 'new' && $lsys->loggedIn()) {    // new
    1.12 +    create($lsys);
    1.13 +
    1.14 +  } else if ($_GET['action'] == 'edit' && $lsys->loggedIn()) {    // edit
    1.15 +    edit($lsys);
    1.16 +
    1.17 +  } else if ($_GET['action'] == 'delete' && $lsys->loggedIn()) {    // delete
    1.18 +    delete($lsys);
    1.19 +
    1.20 +  } else if ($_GET['action'] == 'login') {    // login
    1.21 +    $lsys->login($_POST['login_loginname'], md5($_POST['login_password']));
    1.22 +    show($lsys);
    1.23 +
    1.24 +  } else if ($_GET['action'] == 'logout') {    // logout
    1.25 +    $lsys->logout();
    1.26 +    show($lsys);
    1.27 +
    1.28 +  } else {    // startpage
    1.29 +    $_GET['id'] = 1;
    1.30 +    show($lsys);
    1.31 +
    1.32 +  }
    1.33 +
    1.34 +
    1.35 +  require_once 'Includes/Footer.inc.php';
    1.36 +
    1.37 +
    1.38 +
    1.39 +
    1.40 +
    1.41 +
    1.42 +
    1.43 +
    1.44 +
    1.45 +
    1.46 +
    1.47 +/*
    1.48 +    displays content of the node
    1.49 +    performs action 'edit'
    1.50 +    shows admincontrols if logged in
    1.51 +*/
    1.52 +function show($lsys) {
    1.53 +
    1.54 +  // perform action: write edited node to db
    1.55 +  if (isset($_POST['editDoc']) && $lsys->loggedIn()) {
    1.56 +    $_POST['editDoc_title'] = addslashes($_POST['editDoc_title']);
    1.57 +    $_POST['editDoc_text'] = addslashes($_POST['editDoc_text']);
    1.58 +    mysql_query("update ". DB_PREFIX ."Owls set
    1.59 +      name='$_POST[editDoc_title]',
    1.60 +      text='$_POST[editDoc_text]',
    1.61 +      idParent='$_POST[editDoc_idCategory]',
    1.62 +      date=". time() ."
    1.63 +    where id='$_GET[id]'") or die(mysql_error());
    1.64 +  }
    1.65 +
    1.66 +  // print nav
    1.67 +  include 'Includes/Nav.inc.php';
    1.68 +
    1.69 +
    1.70 +  // query data of the node
    1.71 +  $result = mysql_query("select * from ". DB_PREFIX ."Owls where id=$_GET[id]");
    1.72 +  
    1.73 +  // catch nodes that not exist
    1.74 +  if (!mysql_num_rows($result)) {
    1.75 +
    1.76 +    $fnord = array('',
    1.77 +      'Fnord is the space between the pixels on your screen.',
    1.78 +      'Fnord is the echo of silence.',
    1.79 +      'Fnord is evaporated herbal tea without the herbs.',
    1.80 +      'Fnord is what you see when you close your eyes.',
    1.81 +      'Fnord is the empty pages at the end of the book.',
    1.82 +      'Fnord is why ducks eat trees.',
    1.83 +      'Fnord is the bucket where they keep the unused serifs for H*lvetica.',
    1.84 +      'Fnord is the source of all the zero bits in your computer.'
    1.85 +    );
    1.86 +
    1.87 +?>
    1.88 +      <div id="content">
    1.89 +        <h2>Error 23 - fnord found</h2>
    1.90 +        <p>
    1.91 +          <?php echo $fnord[rand(0, sizeof($fnord)-1)]; ?>
    1.92 +        </p>
    1.93 +<?php
    1.94 +
    1.95 +  } else {
    1.96 +
    1.97 +    $row = mysql_fetch_array($result);
    1.98 +    echo '  <div id="content">'."\n";
    1.99 +
   1.100 +      // display admin controls if logged in
   1.101 +      if ($lsys->loggedIn()) {
   1.102 +?>
   1.103 +        <div class="ctrl" style="font-size: 0.8em;">
   1.104 +          <a href="<?php echo $row['id'] .'n'; ?>">new</a>
   1.105 +          <a href="<?php echo $row['id'] .'e'; ?>">edit</a>
   1.106 +<?php
   1.107 +          if ($row['id'] != 1) {
   1.108 +            echo '<a href="javascript:sureToDelete('. $row['id'] .')">delete</a>';
   1.109 +          }
   1.110 +?>
   1.111 +        </div>
   1.112 +<?php
   1.113 +      }
   1.114 +
   1.115 +    // print content of the node
   1.116 +    echo '    <h2>'.stripslashes($row['name']).'</h2>'."\n";
   1.117 +    if (!empty($row['text'])) {
   1.118 +      echo '    <p>'.bbcode(stripslashes($row['text']), 1, 1).'</p>';
   1.119 +    }
   1.120 +  }
   1.121 +  echo "\n\n";
   1.122 +
   1.123 +}
   1.124 +
   1.125 +
   1.126 +
   1.127 +
   1.128 +
   1.129 +/*
   1.130 +    displays edit form
   1.131 +*/
   1.132 +function edit($lsys) {
   1.133 +
   1.134 +    include 'Includes/Nav.inc.php';
   1.135 +
   1.136 +    $sql = "select * from ". DB_PREFIX ."Owls where id=$_GET[id]";
   1.137 +    $result = mysql_query($sql) or die(mysql_error());
   1.138 +    $row = mysql_fetch_array($result);
   1.139 +      echo '<div id="content">';
   1.140 +?>
   1.141 +<div id="edit">
   1.142 +  <form action="<?php echo $row['id']; ?>" method="post" enctype="multipart/form-data">
   1.143 +<?php
   1.144 +    if ($_GET['id'] != 1) {
   1.145 +?>
   1.146 +      <select name="editDoc_idCategory" style="width: 99%;">
   1.147 +<?php
   1.148 +      $result = mysql_query("select * from ". DB_PREFIX ."Owls order by name asc") or die(mysql_error());
   1.149 +      while($rowCats = mysql_fetch_array($result)) {
   1.150 +        echo '  <option value="'.$rowCats['id'].'"'. (($row['idParent'] == $rowCats['id']) ? ' selected="selected"' : '') .'>'.stripslashes($rowCats['name']).'</option>';
   1.151 +      }
   1.152 +?>
   1.153 +      </select><br /><br />
   1.154 +<?php
   1.155 +    }
   1.156 +?>
   1.157 +    <input name="editDoc_title" type="text" value="<?php echo stripslashes($row['name']); ?>" style="width: 99%;" /><br />
   1.158 +    <textarea name="editDoc_text" cols="60" rows="15" style="width: 99%; height: 30em;"><?php
   1.159 +      echo stripslashes($row['text']);
   1.160 +    ?></textarea><br /><br />
   1.161 +    <input name="editDoc" type="submit" value="edit" class="button" style="width: 99%;" />
   1.162 +  </form>
   1.163 +</div>
   1.164 +<?php
   1.165 +  unset($row);
   1.166 +  unset($result);
   1.167 +}
   1.168 +
   1.169 +
   1.170 +
   1.171 +
   1.172 +
   1.173 +
   1.174 +/*
   1.175 +    performs action 'new'
   1.176 +*/
   1.177 +function create($lsys) {
   1.178 +
   1.179 +  // perform action: new node
   1.180 +  mysql_query("
   1.181 +    insert into ". DB_PREFIX ."Owls
   1.182 +    (idParent, date)
   1.183 +    values('$_GET[id]',". time() .")
   1.184 +  ") or die(mysql_error());
   1.185 +
   1.186 +  // set node to jump to (new created node)
   1.187 +  $_GET['id'] = mysql_insert_id();
   1.188 +  edit($lsys);
   1.189 +}
   1.190 +
   1.191 +
   1.192 +
   1.193 +
   1.194 +
   1.195 +/*
   1.196 +    performs action 'delete'
   1.197 +*/
   1.198 +function delete($lsys) {
   1.199 +  // not allowed to delete the root
   1.200 +  if ($_GET['id'] != 1) {
   1.201 +    // TODO: get the parent of the one which is to delete
   1.202 +
   1.203 +    // delete
   1.204 +    mysql_query("delete from ". DB_PREFIX ."Owls where id='$_GET[id]'") or die(mysql_error());
   1.205 +  }
   1.206 +  // set node to jump to (TODO: parent from above)
   1.207 +  $_GET['id'] = 1;
   1.208 +  show($lsys);
   1.209 +}
   1.210 +
   1.211 +
   1.212 +
   1.213 +
   1.214 +?>
   1.215 +