<?php
/*
   The Index software may be freely distributed.
   See license.txt for details.
*/
function getmicrotime()
{
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
}

function start_page()
{
    global $sname, $sauth, $surl, $scat, $sdesc, $sany, $snotes;
    global $sort;
    global $t0;

    $t0 = getmicrotime();

    header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
    header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
                                                          // always modified
    header ("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
    header ("Pragma: no-cache");                          // HTTP/1.0
        
    $page = basename($GLOBALS["PHP_SELF"]);
    ReadCounts();
    CountIt($page);
    $pages = array( 'index.php' => 'Main', 
                    'item.php' => 'Show/add notes', 
                    'submit.php' => 'Submit an item', 
                    'changes.php' => 'Changes',
                    'about.php' => 'About');
    ReadCategoryList();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
    <head>
        <meta name="description" content="Find all places on the web about the roguelike computer game NetHack. Links with helpful descriptions. Learn everything about NetHack, SLASH'EM, and other descendants of Hack.">
        <meta name="keywords" content="nethack, nethack spoilers, nethack online, allegrohack, nethack guides, nethack tiles, nethack walkthrough, nethack servers, nethack tips, nethack commands, slashem, nethack help, nethack stories, nethack graphics, graphical nethack, nethack falcon's eye, falcon's eye, noegnud, nethack spoiler, nethack tileset, nethack tilesets, <?php print $pages[$page] ?>, nethack <?php print $pages[$page] ?>, nethack rss, nethack news feed, nethack news, adom, angband, roguelike, zangband, utumno, hearse, yendor, crossfire, tome, rogue, moria">
        <title>The NetHack Index - Listing every webpage about your favourite computer game - <?php print $pages[$page] ?></title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <link rel="alternate" type="application/rss+xml" title="RSS"
            href="http://www.nicolaas.net/erebus/rss.php?ch=edited" />
        <link rel="alternate" type="application/rss+xml" title="RSS"
            href="http://www.nicolaas.net/erebus/rss.php?ch=deleted" />
        <link rel="alternate" type="application/rss+xml" title="RSS"
            href="http://www.nicolaas.net/erebus/rss.php?ch=visitor" />
        <link rel="alternate" type="application/rss+xml" title="RSS"
            href="http://www.nicolaas.net/erebus/rss.php?ch=comments" />
    </head>
    <body bgcolor="#cccccc">
        <table cellpadding="8" cellspacing="0" border="1" width="100%">
            <tr>
                <td valign="top" bgcolor="#cccc99">
                    <div align="right">
                        <big><b><i>erebus.nicolaas.net</i></b></big><br>
                    <img src="<?php print ROOT . "home.gif" ?>" border="0">
                    </div>
                    <form method="get" action="<?php print ROOT . "index.php" ?>">
                        <p align="right">
                        <b>Sort by</b><br>
                        <select name="sort">
                            <option value=""<?php print $sort=="" ? " selected" : ""?>>(Category)</option>
                            <option value="name"<?php print $sort=="name" ? " selected" : ""?>>Name</option>
                            <option value="author"<?php print $sort=="author" ? " selected" : ""?>>Author</option>
                            <option value="date"<?php print $sort=="date" ? " selected" : ""?>>Change date</option>
                            <option value="url"<?php print $sort=="url" ? " selected" : ""?>>URL</option>
                            <option value="count"<?php print $sort=="count" ? " selected" : ""?>>Popularity</option>
                        </select>
                        </p>
                        <p align="right">
                        <b>Search</b><br>
                        Anywhere in item<br />
                        <input name="sany" type="text" value="<?php print $sany ?>"><br /><br />
                        By name<br />
                        <input name="sname" type="text" value="<?php print $sname ?>"><br />
                        By author<br />
                        <input name="sauth" type="text" value="<?php print $sauth ?>"><br />
                        By URL<br />
                        <input name="surl" type="text" value="<?php print $surl ?>"><br />
                        By category<br />
                        <select name="scat">
                            <option value=""<?php print $scat=="" ? " selected" : ""?>>(All sites)</option>
                            <?php
                            global $categories;
                            reset($categories);
                            while (list($key, $value) = each($categories))
                            {
                                $catnum = substr($key, 0, 2);
                                print "<option value=\"$key\"";
                                print $scat==$key ? " selected" : "";
                                print ">" . $value['name'] . "</option>\n";
                            }
                            ?>
                        </select><br />
                        By text<br />
                        <input name="sdesc" type="text" value="<?php print $sdesc ?>"><br />
                        In notes<br />
                        <input name="snotes" type="text" value="<?php print $snotes ?>"><br />
                        <br>
                        <input type="submit" value="Show">
                        </p>
                    </form>
                    <br>
                    <p align="right">
                    Didn't find what you were looking for? Try
                    </p>
<!-- Search Google -->
<center>
<form method="get" action="http://www.google.com/custom" target="_top">
<table bgcolor="#cccccc">
<tr><td nowrap="nowrap" valign="top" align="left" height="32">
<a href="http://www.google.com/">
<img src="http://www.google.com/logos/Logo_25gry.gif" border="0" alt="Google" align="middle"></img></a>
<br/>
<input type="text" name="q" size="25" maxlength="255" value=""></input>
</td></tr>
<tr><td valign="top" align="left">
<input type="submit" name="sa" value="Search"></input>
<input type="hidden" name="client" value="pub-6617610812194684"></input>
<input type="hidden" name="forid" value="1"></input>
<input type="hidden" name="channel" value="6512474138"></input>
<input type="hidden" name="ie" value="ISO-8859-1"></input>
<input type="hidden" name="oe" value="ISO-8859-1"></input>
<input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;LH:80;LW:120;L:http://erebus.nicolaas.net/home.gif;S:http://erebus.nicolaas.net;LP:1;FORID:1;"></input>
<input type="hidden" name="hl" value="en"></input>
</td></tr></table>
</form>
</center>
<!-- Search Google -->
<br><br>
                    <div align="right" width="100%">                    
                    <?php
                    include(ROOT . 'list/random.inc');
                    randomsite();
                    ?>
                    </div>
<br>
<br>
<br>
<br>
<div align="right" width="100%">                    
<script type="text/javascript"><!--
google_ad_client = "pub-6617610812194684";
google_alternate_color = "cccc99";
google_ad_width = 160;
google_ad_height = 600;
google_ad_format = "160x600_as";
google_ad_channel ="7793232174";
google_color_border = "CCCC99";
google_color_bg = "CCCC99";
google_color_link = "000000";
google_color_url = "0000FF";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
                    
                </td>
                <td valign="top" width="100%" bgcolor="#ffffcc" background="<?php print ROOT . "bg.gif" ?>">
                    <div align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-6617610812194684";
google_alternate_ad_url = "http://www.nicolaas.net/erebus/dudad.htm";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_channel ="6468403903";
google_color_border = "FFFFCC";
google_color_bg = "FFFFCC";
google_color_link = "000000";
google_color_url = "0000FF";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
                        <br>
                        <br>
                        <table>
                            <tr>
                                <td>|</td>
                                <?php
                                while (list($pg,$name) = each($pages)) 
                                {
                                    if ($page == $pg)
                                        print "<td><b>$name</b></td><td>|</td>";
                                    else
                                        print "<td><a href=\"" . ROOT . "$pg\">$name</a></td><td>|</td>";
                                }
                                ?>
                            </tr>
                        </table>
                    </div>
                    <h1 align="center">The NetHack Index</h1>
<?php
}


function jump_url($key, $url, $label)
{
    print "<a href=\"" . ROOT . "counts/jump.php?url=";
    print urlencode($url);
    print "&amp;key=";
    print $key;
    print "\">";
    print $label;
    print "</a>";
}

function category($category)
{
    global $categories;

    $value = $categories[$category];
    ?><h2><?php
    print $value['name'];
    ?></h2><p><?php
    print $value['desc'];
    ?></p><?php
}

function start_itemlist()
{
    ?><table border="0" cellpadding="0" cellspacing="0" width="100%"><?php
}

function start_item()
{
    ?><tr><td><?php
}

function blockitem($key, $value)
{
    global $list;
    global $categories;

    // Item header 
    ?><table width="100%" bgcolor="#ffffcc" background="<?php print ROOT . "bg.gif" ?>">
    <tr><td align="right">
    <small><b>
    <?php
    $cats = explode(",", $value['category']);
    $first = true;
    while (list(, $cat) = each($cats))
    {
        if ($first)
            $first = false;
        else
            print ", ";
        print $categories[$cat]['name'];
    }
    // End category
    // End item header table
    // End item header, 
    // Begin item text
    ?>
    </b></small>
    </td></tr>
    <tr><td>
    <b><?php
    print "<a href=\"" . ROOT . "item.php?key=$key\">" . $value['name'] . "</a>";
    ?></b><?php
    if ($value['author']) 
    {
        ?><br><i><?php
        print $value['author'];
        ?></i><?php
    }
    // Item header right side
    ?></td></tr>
    
    </table>
    </td></tr>
    <tr><td>
    <?php
    if ($value['email'] or $value['date'])
    {
        print "<small><i>";
        if ($value['email'])
            print "Contributed by " . $value['email'] . ". ";
        if ($value['date'])
            print "Edited on " . date("F j, Y", $value['date']);
        print ".</i></small><br>";
    }
}

function item($key, $value, $justheader, $noteslink)
{
    global $list;
    global $categories;

    print "<a name=\"$key\"></a>";
    // Item header left side
    ?><table width="100%" bgcolor="#cccc99"><tr><td>
    <b><?php
    if ($justheader)
    {
        print "<a href=\"" . ROOT . "item.php?key=$key\">" . $value['name'] . "</a>";
    }
    else
    {
        if ($value['url'])
            jump_url($key, $value['url'], $value['name']);
        else
            print $value['name'];
    }
    ?></b><?php
    if ($value['author']) 
    {
        ?> -- <i><?php
        print $value['author'];
        ?></i><?php
    }
    // Item header right side
    ?></td><td align="right">
    <small><b>
    <?php
    $cats = explode(",", $value['category']);
    $first = true;
    while (list(, $cat) = each($cats))
    {
        if ($first)
            $first = false;
        else
            print ", ";
        print $categories[$cat]['name'];
    }
    // End category
    // End item header table
    // End item header, 
    // Begin item text
    ?>
    </b></small>
    </td></tr></table>
    </td></tr>
    <tr><td>
    <?php
    if ($value['email'] or $value['date'])
    {
        print "<small><i>";
        if ($value['email'])
            print "Contributed by " . $value['email'] . ". ";
        if ($value['date'])
            print "Edited on " . date("F j, Y", $value['date']);
        print ".</i></small><br>";
    }
    if (!$justheader)
    { 
        // Item text margin, begin text.
        ?>
        <table>
        <tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td><td>
        <?php
        print $value['desc'];
        ?>
        <br>
        <small>
        <?php
        if ($value['url']) 
        {
            ?><b><?php
            jump_url($key, $value['url'], $value['url']);
            ?></b><?php
            ?> <b>&middot;</b> <?php
        }
        global $counts;
        ReadCounts();
        if ($counts[$key] > 1)
            print "$counts[$key] pageviews";
        else if ($counts[$key] > 0)
            print "1 pageview";
        else
            print "no pageviews yet";
        global $notes;
        ReadNotes();
        if ($noteslink) 
        {
            ?> <b>&middot;</b> <?php
            $nr = NrNotes($key);
            if ($nr > 0)
            {
                print "<a href=\"" . ROOT . "item.php?key=$key\">Show/add notes (";
                print "$nr note";
                print $nr > 1 ? "s" : "";
                print ")</a>";
            }
            else
            {
                print "<a href=\"" . ROOT . "item.php?key=$key\">Add notes</a>";
            }
        }
        /*print " <b>&middot;</b> ";
        print "<a href=\"" . ROOT . "list/edit.php?key=$key&preview=Preview\">Edit item</a>";
        print " <b>&middot;</b> ";
        print "<a href=\"" . ROOT . "list/edit.php?key=$key&delete=Delete&preview=Preview\">Delete item</a><br><br>";
        */
        // End item text>
        ?>
        </small>
        </td></tr>
        </table>
        <?php
    }
    ?><br><?php

}

function start_notelist($title)
{
    ?>
    <blockquote>
    <h3><?php
         print $title
    ?></h3>
    <table border="1" width="100%" cellspacing="0">
    <?php
}


function note($note)
{
    ?>
        <tr><td>
        <table width="100%" cellspacing="0">
        <tr>
            <th bgcolor="#99cccc" align="left">
                <?php
                print $note['email'] 
                ?>
            </th>
            <th bgcolor="#99cccc" align="right">
                <small>
                    <?php
                    print date("F j, Y", $note['date']) 
                    ?>
                </small>
            </th>
        </tr>
        </table>
        </td></tr>
        <tr><td>
                <?php
                print $note['note'] 
                ?>
        </td></tr>
    <?php        
}


function end_notelist()
{
    ?>
        </table>
        </blockquote>
    <?php
}

function end_item()
{
    ?></td></tr><?php
}

function end_itemlist()
{
    ?></table><?php
}

function explain_tags()
{
    ?>
    <p>You cannot use HTML in your text, but some text attibutes are
    recognised:
    text between stars (like <tt>*bold*</tt>) will be set in <b>bold</b>;
    Text between underscores (<tt>_underline_</tt>) will be <u>underlined</u>;
    and text in slashes (<tt>/italic/</tt>) will become <i>italic</i>. If you
    want to include literal stars. slashes or underscores in your text,
    you can escape them with a backslash: <tt>\/slashes\/</tt> will become 
        /slashes/.
    </p>    
    <p>Furthermore, web addresses starting with <tt>http://</tt>
    (or <tt>ftp://</tt> or some
    other scheme) will be turned into links. E-mail addresses will be turned
    into <tt>mailto:</tt> links.</p>
    <p>If you enclose a word, or some words, in square brackets ('[' and ']'),
    these words will be turned into a link to that item in the NetHack Index.
    E.g. <tt>[SLASH'EM]</tt> will become
    <a href="<?php print ROOT . "item.php?key=TheSLASHEMHomepage" ?>">SLASH'EM</a>.
    Note that the item to link to is found by looking at the name of the site 
    and the name of the author. Thus you can try things like 
    "Michael K. Neylon's page" if the name of the page is not unique.
    </p>
    <p>Use the "Preview" feature to preview your text before submitting it,
    else a link phrase might point the wrong way.</p>
    <p><em>
    Note: Since spammers have discovered this site and put in lots
    of annoying ads, any text containing HTML (or even just &lt; or &gt;
    characters or 'http:') will be refused silently. Apologies for the inconvenience.
    </em></p>
    <hr>
    <?php
}

function submit_form($action, $key, $position, $name, $author, $url, $desc, $category, $email)
{
    global $categories;

    explain_tags();
    ?>
    <form action="<?php print $action ?>" method="post">
    <input type="hidden" name="key" value="<?php print $key ?>">
    <input type="hidden" name="position" value="<?php print $position ?>">
    <table border="0" cellspacing="9">
    <tr valign="bottom">
    <th align="left">Name</th>
    <td><small>Enter the title or name of this NetHack site.
    Normally this would be the &lt;title&gt; of the HTML
    page (which usually appears in the title bar of your browser);
    in some cases, some additional information is needed (such as
    the name of a e-zine a review appears in).</small></td>
    </tr>
    <tr>
    <td colspan=2>
    <input name="name" type="text" size="60" value = "<?php print $name ?>"></td>
    </tr>
    <tr valign="bottom">
    <th align="left">Author</th>
    <td><small>The author of this website. Preferably, the full
    name that the author uses him- or herself. Leave
    blank if no author is known.</small></td>
    </tr>
    <tr>
    <td colspan=2>
    <input name="author" type="text" size="60" value="<?php print $author?>"></td>
    </tr>
    <tr valign="bottom">
    <th align="left">URL</th>
    <td><small>The place on the web where this page resides. If
    the page is inside a frameset, specify the
    main page, if that is the only way to navigate.</small></td>
    </tr>
    <tr>
    <td colspan=2>
    <input name="url" type="text" size="60" value="<?php print $url ?>"></td>
    </tr>
    <tr valign="bottom">
    <th align="left">Description</th>
    <td><small>A short description or "mini-review" of the
    page.</small></td>
    </tr>
    <tr>
    <td colspan=2>
    <textarea name="desc" rows="10" cols="60"><?php print $desc ?></textarea>
    </td>
    </tr>
    <tr valign="bottom">
    <th align="left">Suggested category</th>
    <td><small>The category, or categories, in which you
    think the page belongs. If you think a new category is
    needed, describe that in the description
    above.</small></td>
    </tr>
    <tr>
    <td colspan=2>
    <?php
        // Remove unselectable categories (num >= 80)
        reset($categories);
        while (list($key, $value) = each($categories))
        {
            $catnum = substr($key, 0, 2);
            if ($catnum < 80)
            {
                $selcats[$key] = $value;
            }
        }
    ?>
    <select name="cats[]" multiple="multiple" size="<?php print count($selcats)?>">
        <?php
        reset($selcats);
        while (list($key, $value) = each($selcats))
        {
            print "<option value=\"$key\"";
            print strstr($category, $key) ? " selected" : "";
            print ">" . $value['name'] . "</option>\n";
        }
        ?>
    </select>
    </td>
    </tr>
    <tr valign="bottom">
    <th align="left" colspan="2"><br>Your name and e-mail address</th>
    </tr>
    <tr>
    <td colspan=2>
    <input name="email" type="text" size="60" value="<?php print $email ?>"></td>
    </tr>
    <tr><th align="left"><input name="preview" value="Preview" type="checkbox" checked>Preview</th></tr>
    <tr>
    <td colspan=2>
    <input type="submit" value="Add item"><input type="reset" value="Reset">
    </td>
    </tr>
    </table>
    </form>
    <?php
}

function note_form($key, $email, $note, $index)
{
    explain_tags();
    ?>
    <form method="post">
    <input type="hidden" name="key" value="<?php print $key ?>">
    <input type="hidden" name="index" value="<?php print $index ?>">
    <table cellspacing="9">
        <tr><th align="left">Name/E-mail</th><td><small>Fill in you e-mail address, or if you don't like that, a name you choose.</small></td></tr>
        <tr><td colspan="2"><input name="email" type="text" size="60" value="<?php print $email ?>"></td></tr>
    <tr><th align="left">Note</th><td><small>Your comment</small></td></tr>
    <tr><td colspan="2"><textarea name="note" cols="60" rows="4"><?php print $note ?></textarea></td></tr>
    <tr><th align="left"><input name="preview" value="Preview" type="checkbox" checked>Preview</th></tr>
    <tr><td>
      <input type="submit" value="Add note"><input type="reset" value="Reset">
    </td></tr>
    </table>

    </form>
    <?php
}

function end_page()
{
    global $t0;
?>
                    <br />
                    <hr>
                    <br />
                    <table width="100%"><tr>
                    <td>
                    <address>
                        Dion Nicolaas<br />
                        <a href="mailto:nethack@nicolaas.net">nethack@nicolaas.net</a>
                    </address>
                    </td>
                    <td align="right">
                    <small>|
                    <?php print number_format(getmicrotime() - $t0, 3) ?> (s)
                    |
                    <a href="<?php print ROOT . "source.php?file=" . basename($GLOBALS["PHP_SELF"]) ?>">View source</a>
                    |
                    <a href="<?php print ROOT . "list/editlist.php" ?>">Edit items</a>
                    |</small>
                    </td>
                    </tr></table>
                    <div align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-6617610812194684";
google_alternate_ad_url = "http://www.nicolaas.net/erebus/dudad.htm";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_channel ="6468403903";
google_color_border = "FFFFCC";
google_color_bg = "FFFFCC";
google_color_link = "000000";
google_color_url = "0000FF";
google_color_text = "000000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
                </div>
                </td>
            </tr>
        </table>
    </body>
</html>
<?php
}
?>