<?php
// Somery, a weblogging script by Robin de Graaf, copyright 2001-2006
// Somery is distributed under the Artistic License (see LICENSE.txt)
//
// ADMIN/NOTES.PHP > 08-03-2006
$start = TRUE;
include("system/include.php");
if ($checkauth) {
if (!$action) {
echo "<strong>Notes</strong><br /><br /><table>";
$result = mysql_query("SELECT * FROM ".$prefix."notes ORDER BY nid");
$total = mysql_num_rows($result);
if ($total == 0) { echo "No notes."; }
while($row=mysql_fetch_object($result)) {
$note_count++;
echo "<tr><td width=175>$note_count - $row->title</td><td>";
echo "<a href='notes.php?action=edit&nid=$row->nid'>edit</a>";
echo "</td></tr>";
}
echo "</table><br>";
echo "<form method='post' action='notes.php'><input type='hidden' name='action' value='new'><table><tr><td></td></tr></table>";
echo "<b>Add a note</b><br><table>";
echo "<tr><td width=100>Note title</td><td><input size=50 name='notetitle' type='text'></td></tr>";
echo "<tr><td width=100 valign=\"top\">Note text</td><td><textarea name='notebody' rows=7 cols=50></textarea></td></tr>";
echo "<tr><td width=100> </td><td><input type='submit' value='save'></a></td></tr>";
echo "</table></form>";
} elseif ($action == "new") {
if (!$notetitle && !$err) { echo $error[11]; $err = 1; }
if (!$notebody && !$err) { echo $error[12]; $err = 1; }
if (!$err) {
$notetitle = debbcode($notetitle);
$notetitle = cleanstring($notetitle);
$notebody = cleanstring($notebody);
$notebody = addslashes($notebody);
$result = mysql_query("INSERT INTO ".$prefix."notes (title,body) VALUES ('$notetitle', '$notebody')");
echo "Note created, redirecting...<meta http-equiv=Refresh content=1;URL='notes.php'>";
}
} elseif ($action == "edit") {
echo "<table><tr><td><form method='post' action='notes.php'><input type='hidden' name='action' value='update'><input type='hidden' name='nid' value='$nid'></td></tr></table>";
echo "<b>Edit Note</b><br><table>";
$result = mysql_query("SELECT * FROM ".$prefix."notes WHERE nid='$nid'");
while($row=mysql_fetch_object($result)) {
echo "<tr><td width=100>Note title</td><td><input size=50 name='notetitle' type='text' value='$row->title'></td></tr>";
echo "<tr><td width=100 valign=\"top\">Note text</td><td><textarea name='notebody' rows=7 cols=50>$row->body</textarea></td></tr>";
}
echo "
<tr><td width=175><br>Delete this note</td><td><br><input type='checkbox' name='delete'></td></tr>
<tr><td width=175> </td><td><input type='submit' value='edit'></td></tr>
</table>";
} elseif ($action == "update") {
if ($delete) {
$result = mysql_query("DELETE FROM ".$prefix."notes WHERE nid = '$nid'");
echo "Note deleted, redirecting...<meta http-equiv=Refresh content=1;URL='notes.php'>";
} else {
if (!$notetitle && !$err) { echo $error[11]; $err = 1; }
if (!$err) {
$notetitle = debbcode($notetitle);
$notetitle = cleanstring($notetitle);
$notebody = cleanstring($notebody);
$notebody = addslashes($notebody);
$result = mysql_query("UPDATE ".$prefix."notes SET
title='$notetitle',
body='$notebody'
WHERE nid = '$nid'");
echo "Note updated, redirecting...<meta http-equiv=Refresh content=1;URL='notes.php'>";
}
}
}
?>
<?php }; $start = FALSE; include("system/include.php"); ?>