view Owls.php @ 0:3021ce32ee14 owls-0.5

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 wrap: on
line source

<?php
  require_once 'Includes/Header.inc.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);

  }


  require_once 'Includes/Footer.inc.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 if logged in
      if ($lsys->loggedIn()) {
?>
        <div class="ctrl" style="font-size: 0.8em;">
          <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>';
          }
?>
        </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">
  <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
      $result = mysql_query("select * from ". DB_PREFIX ."Owls order by name asc") or die(mysql_error());
      while($rowCats = mysql_fetch_array($result)) {
        echo '  <option value="'.$rowCats['id'].'"'. (($row['idParent'] == $rowCats['id']) ? ' selected="selected"' : '') .'>'.stripslashes($rowCats['name']).'</option>';
      }
?>
      </select><br /><br />
<?php
    }
?>
    <input name="editDoc_title" type="text" value="<?php echo stripslashes($row['name']); ?>" style="width: 99%;" /><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);
}




?>