<?php
/*
   The Index software may be freely distributed.
   See license.txt for details.
*/
define('ROOT', './');
include(ROOT . 'text.inc');
include(ROOT . 'counts/count.inc');
include(ROOT . 'layout.inc');
include(ROOT . 'list/list.inc');
include(ROOT . 'notes/notes.inc');

start_page();

ReadList();
ReadNotes();

$label = $key;

if ($key)
{
    $value = $combilist[$key];
    $name = $value['name'];
    if (!isset($value))
    {
        $value = $deletedlist[$key];
        $name = "Deleted item: " . $value['name'];
    }
}
else
{
    $key = "General";
    $name = "General notes";
}
?>
    <h2><?php print $name ?></h2>
<?php
print "<p><a href=\"index.php#$label\">Back to the full list</a></p>";

start_itemlist();
start_item();
if ($key != "General")
{
    item($key, $value, 0, 0);
}
if ($note != "")
{
    if (
               strpos($note, '<') !== false 
            or strpos($note, '>') !== false
            or strpos($note, 'http:') !== false
            or (trim($note) == '')
       )
        $spam = true;
    $note = submit2text($note);
    $email = submit2text($email);

    $noterec = MakeNote($email, $note);
    if ($preview != "Preview") 
    {
        if (!$spam)
            StoreNote($key, $noterec, "");
        $email = $note = "";
    }
}
if (NrNotes($key))
{
    start_notelist("Visitor-supplied notes");
    for ($i = 0; $i < count($notes[$key]); $i++)
    {
        note($notes[$key][$i]);
    }
    end_notelist();
}
if ($preview == "Preview")
{
    start_notelist("Preview of your note");
    note($noterec);
    end_notelist();

}
else 
{
    ?>
    <h3>Submit your own notes</h3>
    <?php
    if ($key)
    {
        ?><p>Just fill in the form below and a note will
        be added to this item. These notes will be read and incorporated
        in the text at a certain time.</p>
        <?php
    } 
    else
    {
        ?><p>Just fill in the form below if you want to add a general comment
            about the NetHack Index. If you want to comment on a specific item,
            follow the link "Add comment" below that item.
            </p>
        <?php
    }
}
note_form($key, $email, $note, "");

end_item();
end_itemlist();

end_page();
?>