function darkhorse_runevent($type, $link)
{
    global $session;
    $from = $link;
    $gameret = substr($link, 0, -1);
    $session['user']['specialinc'] = "module:darkhorse";
    require_once "lib/sanitize.php";
    $iname = get_module_setting("tavernname");
    rawoutput("<span style='color: #787878'>");
    output_notl("`c`b%s`b`c", $iname);
    $op = httpget('op');
    switch ($op) {
        case "":
        case "search":
            darkhorse_checkday();
            output("A cluster of trees nearby looks familiar...");
            output("You're sure you've seen this place before.");
            output("As you approach the grove, a strange mist creeps in around you; your mind begins to buzz, and you're no longer sure exactly how you got here.");
            if (darkhorse_tavernmount()) {
                require_once "lib/mountname.php";
                list($name, $lcname) = getmountname();
                output("%s`0 seems to have known the way, however.", $name);
            }
            output("`n`nThe mist clears, and before you is a log building with smoke trailing from its chimney.");
            output("A sign over the door says `7\"%s.\"`0", $iname);
            addnav("Enter the tavern", $from . "op=tavern");
            addnav("Leave this place", $from . "op=leaveleave");
            break;
        case "tavern":
            darkhorse_checkday();
            output("You stand near the entrance of the tavern and survey the scene before you.");
            output("Whereas most taverns are noisy and raucous, this one is quiet and nearly empty.");
            output("In the corner, an old man plays with some dice.");
            output("You notice that the tables have been etched on by previous adventurers who have found this place before, and behind the bar, a stick of an old man hobbles around, polishing glasses, as though there were anyone here to use them.");
            addnav("Talk to the old man", $from . "op=oldman");
            addnav("Talk to the bartender", $from . "op=bartender");
            // Special case here.  go and see if the comment area is blocked and
            // if so, don't put the link in.
            $args = modulehook("blockcommentarea", array("section" => "darkhorse"));
            if (!isset($args['block']) || $args['block'] != 'yes') {
                addnav("Examine the tables", $from . "op=tables");
            }
            addnav("Exit the tavern", $from . "op=leave");
            break;
        case "tables":
            require_once "lib/commentary.php";
            addcommentary();
            commentdisplay("You examine the etchings in the table:`n`n", "darkhorse", "Add your own etching:");
            addnav("Return to the Main Room", $from . "op=tavern");
            break;
        case "bartender":
            darkhorse_bartender($from);
            break;
        case "oldman":
            darkhorse_checkday();
            addnav("Old Man");
            modulehook("darkhorsegame", array("return" => $gameret));
            output("The old man looks up at you, his eyes sunken and hollow.");
            output("His red eyes make it seem that he may have been crying recently so you ask him what is bothering him.");
            if ($session['user']['sex'] == SEX_MALE) {
                output("\"`7Aah, I met an adventurer in the woods, and figured I'd play a little game with her, but she won and took almost all of my money.`0\"`n`n");
            } else {
                output("\"`7Aah, I met an adventurer in the woods, and figured I'd play a little game with him, but he won and took almost all of my money.`0\"`n`n");
            }
            $c = navcount();
            if ($c != 0) {
                output("`0\"`7Say... why not do an old man a favor and let me try to win some of it back from you?");
                if ($c > 1) {
                    output(" I can play several games!`0\"");
                } else {
                    output(" Shall we play a game?`0\"");
                }
            }
            $session['user']['specialmisc'] = "";
            addnav("Return to the Main Room", $from . "op=tavern");
            break;
        case "leave":
            output("You duck out of the tavern, and wander into the thick foliage around you.");
            output("That strange mist revisits you, making your mind buzz.");
            output("The mist clears, and you find yourself again where you were before the mist first covered you.");
            if (!darkhorse_tavernmount()) {
                output(" How exactly you got to the tavern is not exactly clear.");
            }
            $session['user']['specialinc'] = "";
            break;
        case "leaveleave":
            output("You decide that the tavern holds no appeal for you today.");
            $session['user']['specialinc'] = "";
            break;
    }
    rawoutput("</span>");
}
// translator ready
// addnews ready
// mail ready
require_once "common.php";
require_once "lib/commentary.php";
tlschema("shades");
page_header("The FailBoat");
addcommentary();
checkday();
if ($session['user']['alive']) {
    redirect("village.php", "Player is not dead!");
}
output("`0The FailBoat bobs a couple of miles offshore.  In the distance, Improbable Island stares back at you.  It seems to mock you, as much as an island can.`n`nYou wander around the upper deck, wearing a simple set of grey overalls marked with reddish-brown stains, your regular armour confiscated along with your weapon, backpack, bandolier and just about everything else, pride included.`n`nA pair of heavy steel doors lead to the lower decks, which contain the Retraining Pits and... `\$Her.`0  A few contestants are clustered together around the doors, talking in the fast-and-slow-and-fast-again tones of people running entirely on adrenaline.  They're bandaged, and traumatized, and uncertain.  Like you.`n`nThey cast occasional worried glances at the doors to the Retraining Pits, knowing that their best chances at rejoining their friends lie inside - but they're unsure of themselves.  After all, they've already been beaten up once today.`n`n");
output("`0Once every minute, a loudspeaker blares into life.  A certain `\$familiar`0 recorded voice says \"`&The time is now %s.  One more minute has passed since you arrived here; one more minute in which someone else is claiming your glory.  You will be returned to the Island at midnight, or after you have undergone Retraining to my satisfaction, whichever occurs first.  This message will repeat until you bloody well get off my Retraining Vessel.`0\"`n`n", getgametime());
modulehook("shades", array());
commentdisplay("`n`0Nearby, some fellow failies grumble to themselves and, occasionally, each other:`n", "shade", "Chat with other Failed contestants", 25, "mutters");
addnav("Log out", "login.php?op=logout");
addnav("Places");
addnav("Head Below Decks", "graveyard.php");
addnav("Info");
addnav("Return to the news", "news.php");
addnav("Preferences", "prefs.php");
tlschema("nav");
// the mute module blocks players from speaking until they
// read the FAQs, and if they first try to speak when dead
// there is no way for them to unmute themselves without this link.
// addnav("Other");
// addnav("??F.A.Q. (Frequently Asked Questions)", "petition.php?op=faq",false,true);
if ($session['user']['superuser'] & SU_EDIT_COMMENTS) {
    addnav("Superuser");
    addnav(",?Comment Moderation", "moderate.php");
addnav("Describe Points", "lodge.php?op=points");
villagenav();
if ($op == "") {
    output("`b`c`!The Hunter's Lodge`0`c`b");
    output("`7You follow a narrow path away from the stables and come across a rustic Hunter's Lodge.");
    output("A guard stops you at the door and asks to see your membership card.`n`n");
    if ($entry) {
        output("Upon showing it to him, he says, `3\"Very good %s, welcome to the J. C. Petersen Hunting Lodge.", translate_inline($session['user']['sex'] ? "ma'am" : "sir"));
        output("You have earned `^%s`3 points and have `^%s`3 points available to spend,\"`7 and admits you in.`n`n", $session['user']['donation'], $pointsavailable);
        output("You enter a room dominated by a large fireplace at the far end.");
        output("The wood-panelled walls are covered with weapons, shields, and mounted hunting trophies, including the heads of several dragons that seem to move in the flickering light.`n`n");
        output("Many high-backed leather chairs fill the room.");
        output("In the chair closest to the fire sits J. C. Petersen, reading a heavy tome entitled \"Alchemy Today.\"`n`n");
        output("As you approach, a large hunting dog at his feet raises her head and looks at you.");
        output("Sensing that you belong, she lays down and goes back to sleep.`n`n");
        commentdisplay("Nearby some other rugged hunters talk:`n", "hunterlodge", "Talk quietly", 25);
        addnav("Use Points");
        modulehook("lodge");
    } else {
        $iname = getsetting("innname", LOCATION_INN);
        output("You pull out your Frequent Boozer Card from %s, with 9 out of the 10 slots punched out with a small profile of %s`0's Head.`n`n", $iname, getsetting('barkeep', '`tCedrik'));
        output("The guard glances at it, advises you not to drink so much, and directs you down the path.");
    }
} else {
    if ($op == "points") {
        output("`b`3Points:`b`n`n");
        $points_messages = modulehook("donator_point_messages", array('messages' => array('default' => tl("`7For each \$1 donated, the account which makes the donation will receive 100 contributor points in the game."))));
        foreach ($points_messages['messages'] as $id => $message) {
            output_notl($message, true);
        }
        output("\"`&But what are points,`7\" you ask?");
$sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid={$claninfo['motdauthor']}";
$result = db_query($sql);
$row = db_fetch_assoc($result);
$motdauthname = $row['name'];
$sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid={$claninfo['descauthor']}";
$result = db_query($sql);
$row = db_fetch_assoc($result);
$descauthname = $row['name'];
if ($claninfo['clanmotd'] != '') {
    rawoutput("<div style='margin-left: 15px; padding-left: 15px;'>");
    output("`&`bCurrent MoTD:`b `3by %s`2`n", $motdauthname);
    output_notl(nltoappon($claninfo['clanmotd']) . "`n");
    rawoutput("</div>");
    output_notl("`n");
}
commentdisplay("", "clan-{$claninfo['clanid']}", "Speak", 25, $claninfo['customsay'] > '' ? $claninfo['customsay'] : "says");
modulehook("clanhall");
if ($claninfo['clandesc'] != '') {
    modulehook("collapse{", array("name" => "collapsedesc"));
    output("`n`n`&`bCurrent Description:`b `3by %s`2`n", $descauthname);
    output_notl(nltoappon($claninfo['clandesc']));
    modulehook("}collapse");
}
$sql = "SELECT count(*) AS c, clanrank FROM " . db_prefix("accounts") . " WHERE clanid={$claninfo['clanid']} GROUP BY clanrank DESC";
$result = db_query($sql);
// begin collapse
modulehook("collapse{", array("name" => "clanmemberdet"));
output("`n`n`bMembership Details:`b`n");
$leaders = 0;
while ($row = db_fetch_assoc($result)) {
    output_notl($ranks[$row['clanrank']] . ": `0" . $row['c'] . "`n");
$cost = $session['user']['level'] * 20;
$op = httpget('op');
if ($op == "pay") {
    if ($session['user']['gold'] >= $cost) {
        // Gunnar Kreitz
        $session['user']['gold'] -= $cost;
        debuglog("spent {$cost} gold to speak to the dead");
        redirect("gypsy.php?op=talk", "Gypsy Redirect");
    } else {
        page_header("Gypsy Seer's tent");
        villagenav();
        output("`5You offer the old gypsy woman your `^%s`5 gold for your gen-u-wine say-ance, however she informs you that the dead may be dead, but they ain't cheap.", $session['user']['gold']);
    }
} elseif ($op == "talk") {
    page_header("In a deep trance, you talk with the shades");
    commentdisplay("`5While in a deep trance, you are able to talk with the dead:`n", "shade", "Project", 25, "projects");
    addnav("Snap out of your trance", "gypsy.php");
} else {
    checkday();
    page_header("Gypsy Seer's tent");
    output("`5You duck into a gypsy tent like many you have seen throughout the realm.");
    output("All of them promise to let you talk with the deceased, and most of them surprisingly seem to work.");
    output("There are also rumors that the gypsy have the power to speak over distances other than just those of the afterlife.");
    output("In typical gypsy style, the old woman sitting behind a somewhat smudgy crystal ball informs you that the dead only speak with the paying.");
    output("\"`!For you, %s, the price is a trifling `^%s`! gold.`5\", she rasps.", translate_inline($session['user']['sex'] ? "my pretty" : "my handsome"), $cost);
    addnav("Seance");
    addnav(array("Pay to talk to the dead (%s gold)", $cost), "gypsy.php?op=pay");
    if ($session['user']['superuser'] & SU_EDIT_COMMENTS) {
        addnav("Superuser Entry", "gypsy.php?op=talk");
    }
    addnav("Other");
    modulehook("village-desc-{$session['user']['location']}", $texts);
    if ($texts['newestplayer'] > "" && $texts['newest']) {
        modulehook("collapse{", array("name" => "villagenewest-" . $session['user']['location']));
        tlschema($schemas['newest']);
        output($texts['newest'], $texts['newestplayer']);
        tlschema();
        $id = $texts['newestid'];
        if ($session['user']['superuser'] & SU_EDIT_USERS && $id) {
            $edit = translate_inline("Edit");
            rawoutput(" [<a href='user.php?op=edit&userid={$id}'>{$edit}</a>]");
            addnav("", "user.php?op=edit&userid={$id}");
        }
        output_notl("`n");
        modulehook("}collapse");
    }
}
modulehook("village", $texts);
//special hook for all villages... saves queries...
modulehook("village-{$session['user']['location']}", $texts);
if ($skipvillagedesc) {
    output("`n");
}
$args = modulehook("blockcommentarea", array("section" => $texts['section']));
if (!isset($args['block']) || $args['block'] != 'yes') {
    tlschema($schemas['talk']);
    output($texts['talk']);
    tlschema();
    commentdisplay("", $texts['section'], "Speak", 25, $texts['sayline'], $schemas['sayline']);
}
module_display_events("village", "village.php");
page_footer();
        } else {
            pollitem($row['motditem'], $row['motdtitle'], $row['motdbody'], $row['motdauthorname'], $row['motddate'], $row['motditem']);
        }
    }
    /*
    motditem("Beta!","For those who might be unaware, this website is still in beta mode.  I'm working on it when I have time, which generally means a couple of changes a week.  Feel free to drop suggestions, I'm open to anything :-)","","", "");
    */
    $result = db_query("SELECT mid(motddate,1,7) AS d, count(*) AS c FROM " . db_prefix("motd") . " GROUP BY d ORDER BY d DESC");
    $row = db_fetch_assoc($result);
    rawoutput("<form action='motd.php' method='GET'>");
    output("MoTD Archives:");
    rawoutput("<select name='month' onChange='this.form.submit();' >");
    rawoutput("<option value=''>--Current--</option>");
    while ($row = db_fetch_assoc($result)) {
        $time = strtotime("{$row['d']}-01");
        $m = translate_inline(date("M", $time));
        rawoutput("<option value='{$row['d']}'" . (httpget("month") == $row['d'] ? " selected" : "") . ">{$m}" . date(", Y", $time) . " ({$row['c']})</option>");
    }
    rawoutput("</select>" . tlbutton_clear());
    rawoutput("<input type='hidden' name='newcount' value='" . ($count + $newcount) . "'>");
    rawoutput("<input type='submit' value='&gt;' name='proceed'  class='button'>");
    rawoutput(" <input type='submit' value='" . translate_inline("Submit") . "' class='button'>");
    rawoutput("</form>");
    commentdisplay("`n`@Commentary:`0`n", "motd");
}
$session['needtoviewmotd'] = false;
$sql = "SELECT motddate FROM " . db_prefix("motd") . " ORDER BY motditem DESC LIMIT 1";
$result = db_query_cached($sql, "motddate");
$row = db_fetch_assoc($result);
$session['user']['lastmotd'] = $row['motddate'];
popup_footer();
<?php

addnav("Module Prefs");
module_editor_navs("prefs-dwellings", "runmodule.php?module=dwellingseditor&op=dweditmodule&dwid={$dwid}&mdule=");
$sql = "SELECT * FROM " . db_prefix("dwellings") . " WHERE dwid={$dwid}";
$result = db_query($sql);
$row = db_fetch_assoc($result);
output("`c`b%s`b`n`n%s`c`n`n", $row['name'], $row['description']);
require_once "lib/commentary.php";
addcommentary();
commentdisplay("", "dwellings-{$dwid}", "Speak into this dwelling", 25, "echoes through the walls");
require_once "common.php";
require_once "lib/commentary.php";
tlschema("shades");
page_header("Land of the Shades");
addcommentary();
checkday();
if ($session['user']['alive']) {
    redirect("village.php");
}
output("`\$You walk among the dead now, you are a shade. ");
output("Everywhere around you are the souls of those who have fallen in battle, in old age, and in grievous accidents. ");
output("Each bears telltale signs of the means by which they met their end.`n`n");
output("Their souls whisper their torments, haunting your mind with their despair:`n");
output("`nA sepulchral voice intones, \"`QIt is now %s in the world above.`\$\"`n`n", getgametime());
modulehook("shades", array());
commentdisplay("`n`QNearby, some lost souls lament:`n", "shade", "Despair", 25, "despairs");
addnav("Log out", "login.php?op=logout");
addnav("Places");
addnav("The Graveyard", "graveyard.php");
addnav("Return to the news", "news.php");
tlschema("nav");
// the mute module blocks players from speaking until they
// read the FAQs, and if they first try to speak when dead
// there is no way for them to unmute themselves without this link.
addnav("Other");
addnav("??F.A.Q. (Frequently Asked Questions)", "petition.php?op=faq", false, true);
if ($session['user']['superuser'] & SU_EDIT_COMMENTS) {
    addnav("Superuser");
    addnav(",?Comment Moderation", "moderate.php");
}
if ($session['user']['superuser'] & ~SU_DOESNT_GIVE_GROTTO) {
function claneditor_run()
{
    global $session;
    tlschema("claneditor");
    $dt = httpget("dt");
    $op = httpget('op');
    if ($dt != "") {
        $sql = "SELECT * FROM " . db_prefix("clans") . " WHERE clanid='{$dt}'";
        $result = db_query($sql);
        $claninfo = db_fetch_assoc($result);
        if (db_num_rows($result) == 0) {
            $op = "";
        }
    }
    addcommentary();
    $ranks = array(CLAN_APPLICANT => "`!Applicant`0", CLAN_MEMBER => "`#Member`0", CLAN_OFFICER => "`^Officer`0", CLAN_LEADER => "`&Leader`0", CLAN_FOUNDER => "`\$Founder");
    $args = modulehook("clanranks", array("ranks" => $ranks, "clanid" => $dt));
    $ranks = translate_inline($args['ranks'], "clan");
    superusernav();
    addnav("Clans");
    addnav("List Clans", "runmodule.php?module=claneditor&op=list");
    addnav("Create a New Clan", "runmodule.php?module=claneditor&op=new");
    if ($op == "" || $op == "list") {
        page_header("Clan Listing");
        rawoutput("<table border='0' padding='0'><tr><td>");
        $sql = "SELECT MAX(" . db_prefix("clans") . ".clanid) AS clanid, MAX(clanname) AS clanname,count(" . db_prefix("accounts") . ".acctid) AS c FROM " . db_prefix("clans") . " LEFT JOIN " . db_prefix("accounts") . " ON " . db_prefix("clans") . ".clanid=" . db_prefix("accounts") . ".clanid AND clanrank>" . CLAN_APPLICANT . " GROUP BY " . db_prefix("clans") . ".clanid ORDER BY c DESC";
        $result = db_query($sql);
        if (db_num_rows($result) > 0) {
            output("`%Karissa`7 steps in as if by magic, listing the clans for you.`n");
            output("`@`bList of Clans:`b`0`n`n");
            $v = 0;
            $memb_n = translate_inline("(%s members)");
            $memb_1 = translate_inline("(%s member)");
            rawoutput('<table cellspacing="0" cellpadding="2" align="left">');
            output_notl("<tr class='trhead'><td>%s</td><td>%s</td></tr>", translate_inline("`b`&Name of Clan`b"), translate_inline("`&`iNumber of Members`i"), true);
            for ($i = 0; $i < db_num_rows($result); $i++) {
                $row = db_fetch_assoc($result);
                if ($row['c'] == 0) {
                    $sql = "DELETE FROM " . db_prefix("clans") . " WHERE clanid={$row['clanid']}";
                    db_query($sql);
                } else {
                    rawoutput('<tr class="' . ($v % 2 ? "trlight" : "trdark") . '"><td>', true);
                    if ($row['c'] == 1) {
                        $memb = sprintf($memb_1, $row['c']);
                    } else {
                        $memb = sprintf($memb_n, $row['c']);
                    }
                    output_notl("&#149; <a href='runmodule.php?module=claneditor&op=mview&dt=%s'>%s</a></td><td>%s`n", $row['clanid'], full_sanitize(htmlentities($row['clanname']), ENT_COMPAT, getsetting("charset", "ISO-8859-1")), $memb, true);
                    rawoutput('</td></tr>');
                    addnav("", "runmodule.php?module=claneditor&op=mview&dt={$row['clanid']}");
                    $v++;
                }
            }
            rawoutput("</table>", true);
        } else {
            output("`7There are no clans in the database.`n`c");
        }
        rawoutput("</td></tr><tr><td>");
        output_notl("<br>[<a href='runmodule.php?module=claneditor&op=new'>%s</a>]", translate_inline("Create a New Clan"), true);
        addnav("", "runmodule.php?module=claneditor&op=new");
        rawoutput("</td></tr></table>");
        page_footer();
    } elseif ($op == "new") {
        page_header("Clan Creation");
        $apply = httpget('apply');
        if ($apply == 1) {
            $id = httpget("id");
            $ocn = httppost('clanname');
            $ocs = httppost('clanshort');
            $clanname = stripslashes($ocn);
            $clanname = full_sanitize($clanname);
            $clanname = preg_replace("'[^[:alpha:] \\'-]'", "", $clanname);
            $clanname = addslashes($clanname);
            httppostset('clanname', $clanname);
            $clanshort = full_sanitize($ocs);
            $clanshort = preg_replace("'[^[:alpha:]]'", "", $clanshort);
            httppostset('clanshort', $clanshort);
            $sql = "SELECT * FROM " . db_prefix("clans") . " WHERE clanname='{$clanname}'";
            $result = db_query($sql);
            $e = translate_inline("`%Karissa`7 hands you a form to start a clan.");
            $e1 = translate_inline("`%Karissa`7 looks over your form but informs you that your clan name must consist only of letters, spaces, apostrophes, or dashes.  Also, your short name can consist only of letters. She hands you a blank form.");
            $e2 = translate_inline("`%Karissa`7 looks over your form but informs you that you must have at least 5 and no more than 50 characters in your clan's name (and they must consist only of letters, spaces, apostrophes, or dashes), then hands you a blank form.");
            $e3 = translate_inline("`%Karissa`7 looks over your form but informs you that you must have at least 2 and no more than 5 characters in your clan's short name (and they must all be letters), then hands you a blank form.");
            $e4 = translate_inline("`%Karissa`7 looks over your form but informs you that the clan name %s is already taken, and hands you a blank form.");
            $e5 = translate_inline("`%Karissa`7 looks over your form but informs you that the short name %s is already taken, and hands you a blank form.");
            if ($ocs == "" && $ocn == "" && !httppostisset('clanname') && !httppostisset('clanshort')) {
                output_notl($e);
                clanform();
            } elseif ($clanname != $ocn || $clanshort != $ocs) {
                output_notl($e1);
                clanform();
            } elseif (strlen($clanname) < 5 || strlen($clanname) > 50) {
                output_notl($e2);
                clanform();
            } elseif (strlen($clanshort) < 2 || strlen($clanshort) > 5) {
                output_notl($e3);
                clanform();
            } elseif (db_num_rows($result) > 0) {
                output_notl($e4, stripslashes($clanname));
                clanform();
            } else {
                $sql = "SELECT * FROM " . db_prefix("clans") . " WHERE clanshort='{$clanshort}'";
                $result = db_query($sql);
                if (db_num_rows($result) > 0) {
                    output_notl($e5, stripslashes($clanshort));
                    clanform();
                } else {
                    $sql = "INSERT INTO " . db_prefix("clans") . " (clanname,clanshort) VALUES ('{$clanname}','{$clanshort}')";
                    db_query($sql);
                    $clid = db_insert_id();
                    $sql = "UPDATE " . db_prefix("accounts") . " SET clanid='{$clid}',clanrank='" . CLAN_LEADER . "' WHERE acctid='{$id}'";
                    db_query($sql);
                    $subj = "New Clan!";
                    $msg = array("%s`0`^ has made you a new clan!", $session['user']['name']);
                    systemmail($id, $subj, $msg);
                    output("`%Karissa`7 looks over your form, and finding that everything seems to be in order, she takes your fees, stamps the form \"`\$APPROVED`7\" and files it in a drawer.`n`n");
                    output("Congratulations, you've created a new clan named %s!", stripslashes($clanname));
                }
            }
        } elseif ($apply == 0) {
            clanuserform();
        } else {
            output("`7You teleport to the Clan Hall...");
            output("`7You approach `%Karissa`7 and mention that you would like to start a new clan.");
            output("She tells you that there are three requirements to starting a clan.");
            output("First, you have to decide on a full name for your clan.");
            output("Second, you have to decide on an abbreviation for your clan.");
            output("Third you have to decide on the person that should run the clan.");
            $e = translate_inline("`n`n\"`5If you're ok with these three requirements, please fill out the following form,`7\" she says, handing you a sheet of paper.");
            output_notl($e);
            clanuserform();
        }
    } else {
        if ($op != "deleteclan") {
            page_header("The Clan of %s", full_sanitize($claninfo['clanname']));
            output("`n`c`^`bThe Clan of %s`b`c`n`n", full_sanitize($claninfo['clanname']));
        } else {
            page_header("Clan Deletion");
        }
        if ($op == "mview") {
            $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid={$claninfo['motdauthor']}";
            $result = db_query($sql);
            $row = db_fetch_assoc($result);
            $motdauthname = $row['name'];
            $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid={$claninfo['descauthor']}";
            $result = db_query($sql);
            $row = db_fetch_assoc($result);
            $descauthname = $row['name'];
            output("`&`bCurrent MoTD:`b `#by %s`2`n", $motdauthname);
            output_notl(nltoappon($claninfo['clanmotd']) . "`n`n");
            commentdisplay("", "clan-{$claninfo['clanid']}", "Speak into their Clan", 25, "projects");
            output_notl("`n`n");
            modulehook("collapse{", array("name" => "collapsedesc"));
            output("`&`bCurrent Description:`b `#by %s`2`n", $descauthname);
            output_notl(nltoappon($claninfo['clandesc']) . "`n");
            modulehook("}collapse");
            $sql = "SELECT count(*) AS c, clanrank FROM " . db_prefix("accounts") . " WHERE clanid={$claninfo['clanid']} GROUP BY clanrank DESC";
            $result = db_query($sql);
            // begin collapse
            modulehook("collapse{", array("name" => "clanmemberdet"));
            output("`n`bMembership Details:`b`n");
            $leaders = 0;
            while ($row = db_fetch_assoc($result)) {
                output_notl($ranks[$row['clanrank']] . ": " . $row['c'] . "`n");
                if ($row['clanrank'] >= CLAN_OFFICER) {
                    $leaders += $row['c'];
                }
            }
            output("`n");
            $noleader = translate_inline("`^There is currently no leader!  Promoting %s`^ to leader as they are the highest ranking member (or oldest member in the event of a tie).`n`n");
            if ($leaders == 0) {
                //There's no leader here, probably because the leader's account
                //expired.
                $sql = "SELECT name,acctid,clanrank FROM " . db_prefix("accounts") . " WHERE clanid={$dt} ORDER BY clanrank DESC, clanjoindate";
                $result = db_query($sql);
                $row = db_fetch_assoc($result);
                $sql = "UPDATE " . db_prefix("accounts") . " SET clanrank=" . CLAN_LEADER . " WHERE acctid='" . $row['acctid'] . "'";
                db_query($sql);
                output_notl($noleader, $row['name']);
            }
            // end collapse
            modulehook("}collapse");
        } elseif ($op == "deleteclan") {
            if (httpget("sop") == "yes") {
                //notify users of the deletion of the clan
                $sql = "SELECT acctid FROM " . db_prefix("accounts") . " WHERE clanid={$dt}";
                $result = db_query($sql);
                $subj = array("Deletion of %s", $claninfo['clanname']);
                $msg = array("The clan you were in, %s, has closed its doors.\nSorry for any inconvenience.", $claninfo['clanname']);
                while ($row = db_fetch_assoc($result)) {
                    systemmail($row['acctid'], $subj, $msg);
                }
                //change the clan if a user is in this clan
                $sql = "UPDATE " . db_prefix("accounts") . " SET clanid=0,clanrank=" . CLAN_APPLICANT . ",clanjoindate='0000-00-00 00:00:00' WHERE clanid={$dt}";
                db_query($sql);
                //change the current users clan if this user was in that clan
                if ($session['user']['clanid'] == $dt) {
                    $session['user']['clanid'] = 0;
                    $session['user']['clanrank'] = CLAN_APPLICANT;
                    $session['user']['clanjoindate'] = '0000-00-00 00:00:00';
                }
                //drop the clan.
                $sql = "DELETE FROM " . db_prefix("clans") . " WHERE clanid={$dt}";
                db_query($sql);
                module_delete_objprefs('clans', $dt);
                $op = "";
                httpset("op", "");
                unset($claninfo);
                $dt = "";
                output("That clan has been wiped.`n");
                output("`@Users within the clan have been notified.");
            } else {
                output("`%`c`bAre you SURE you want to delete this clan?`b`c`n");
                $dc = translate_inline("Delete this clan? Are you sure!");
                rawoutput("[<a href='runmodule.php?module=claneditor&op=deleteclan&sop=yes&dt={$dt}' onClick='return confirm(\"{$dc}\");'>{$dc}</a>]");
                addnav("", "runmodule.php?module=claneditor&op=deleteclan&sop=yes&dt={$dt}");
            }
        } elseif ($op == "editmodule" || $op == "editmodulesave") {
            $mdule = httpget("mdule");
            if ($op == "editmodulesave") {
                // Save module prefs
                $post = httpallpost();
                reset($post);
                while (list($key, $val) = each($post)) {
                    set_module_objpref("clans", $dt, $key, $val, $mdule);
                }
                output("`^Saved!`0`n");
            }
            rawoutput("<form action='runmodule.php?module=claneditor&op=editmodulesave&dt={$dt}&mdule={$mdule}' method='POST'>");
            module_objpref_edit("clans", $mdule, $dt);
            rawoutput("</form>");
            addnav("", "runmodule.php?module=claneditor&op=editmodulesave&dt={$dt}&mdule={$mdule}");
        } elseif ($op == "updinfo") {
            page_header("Update Clan Information");
            $clanmotd = substr(httppost('clanmotd'), 0, 4096);
            if (httppostisset('clanmotd') && $clanmotd != $claninfo['clanmotd']) {
                if ($clanmotd == "") {
                    $mauthor = 0;
                } else {
                    $mauthor = $session['user']['acctid'];
                }
                $sql = "UPDATE " . db_prefix("clans") . " SET clanmotd='{$clanmotd}',motdauthor={$mauthor} WHERE clanid={$claninfo['clanid']}";
                db_query($sql);
                invalidatedatacache("clandata-{$claninfo['clanid']}");
                $claninfo['clanmotd'] = stripslashes($clanmotd);
                output("Updating MoTD`n");
                $claninfo['motdauthor'] = $mauthor;
            }
            $clandesc = httppost('clandesc');
            if (httppostisset('clandesc') && $clandesc != $claninfo['clandesc']) {
                if ($clandesc == "") {
                    $claninfo['descauthor'] = 0;
                    $dauthor = 0;
                } else {
                    $dauthor = $session['user']['acctid'];
                }
                $sql = "UPDATE " . db_prefix("clans") . " SET clandesc='" . addslashes(substr(stripslashes($clandesc), 0, 4096)) . "',descauthor={$dauthor} WHERE clanid={$claninfo['clanid']}";
                db_query($sql);
                invalidatedatacache("clandata-{$claninfo['clanid']}");
                output("Updating description`n");
                $claninfo['clandesc'] = stripslashes($clandesc);
                $claninfo['descauthor'] = $session['user']['acctid'];
            }
            $customsay = httppost('customsay');
            if (httppostisset('customsay') && $customsay != $claninfo['customsay']) {
                $sql = "UPDATE " . db_prefix("clans") . " SET customsay='{$customsay}' WHERE clanid={$claninfo['clanid']}";
                db_query($sql);
                invalidatedatacache("clandata-{$claninfo['clanid']}");
                output("Updating custom say line`n");
                $claninfo['customsay'] = stripslashes($customsay);
            }
            $clanname = httppost('clanname');
            if ($clanname) {
                $clanname = full_sanitize($clanname);
            }
            $clanshort = httppost('clanshort');
            if ($clanshort) {
                $clanshort = full_sanitize($clanshort);
            }
            if (httppostisset('clanname') && $clanname != $claninfo['clanname']) {
                $sql = "UPDATE " . db_prefix("clans") . " SET clanname='{$clanname}' WHERE clanid={$claninfo['clanid']}";
                output("Updating the clan name`n");
                db_query($sql);
                invalidatedatacache("clandata-{$detail}");
                $claninfo['clanname'] = $clanname;
            }
            if (httppostisset('clanshort') && $clanshort != $claninfo['clanshort']) {
                $sql = "UPDATE " . db_prefix("clans") . " SET clanshort='{$clanshort}' WHERE clanid={$claninfo['clanid']}";
                output("Updating the short clan name`n");
                db_query($sql);
                invalidatedatacache("clandata-{$detail}");
                $claninfo['clanshort'] = $clanshort;
            }
            $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid={$claninfo['motdauthor']}";
            $result = db_query($sql);
            $row = db_fetch_assoc($result);
            $motdauthname = $row['name'];
            $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE acctid={$claninfo['descauthor']}";
            $result = db_query($sql);
            $row = db_fetch_assoc($result);
            $descauthname = $row['name'];
            output("`&`bCurrent MoTD:`b `#by %s`2`n", $motdauthname);
            output_notl(nltoappon($claninfo['clanmotd']) . "`n");
            output("`&`bCurrent Description:`b `#by %s`2`n", $descauthname);
            output_notl(nltoappon($claninfo['clandesc']) . "`n");
            rawoutput("<form action='runmodule.php?module=claneditor&op=updinfo&dt={$dt}' method='POST'>");
            addnav("", "runmodule.php?module=claneditor&op=updinfo&dt={$dt}");
            output("`&`bMoTD:`b `7(4096 chars)`n");
            rawoutput("<textarea name='clanmotd' cols='50' rows='10'>" . htmlentities($claninfo['clanmotd'], ENT_COMPAT, getsetting("charset", "ISO-8859-1")) . "</textarea><br>");
            output("`bRenaming:`b`n");
            output("`iLong Name:`i ");
            rawoutput("<input name='clanname' value=\"" . htmlentities($claninfo['clanname'], ENT_COMPAT, getsetting("charset", "ISO-8859-1")) . "\" maxlength=50 size=50>");
            output("`n`iShort Name:`i ");
            rawoutput("<input name='clanshort' value=\"" . htmlentities($claninfo['clanshort'], ENT_COMPAT, getsetting("charset", "ISO-8859-1")) . "\" maxlength=5 size=5>");
            output_notl("`n");
            output("`n`&`bDescription:`b `7(4096 chars)`n");
            if (httppost('block') > "") {
                $blockdesc = translate_inline("Description blocked for inappropriate usage.");
                $sql = "UPDATE " . db_prefix("clans") . " SET descauthor=4294967295, clandesc='{$blockdesc}' where clanid='" . $claninfo['clanid'] . "'";
                output("Blocking public description`n");
                db_query($sql);
                invalidatedatacache("clandata-" . $claninfo['clanid'] . "");
                $claninfo['blockdesc'] = "";
                $claninfo['descauthor'] = 4294967295.0;
            } elseif (httppost('unblock') > "") {
                $sql = "UPDATE " . db_prefix("clans") . " SET descauthor=0, clandesc='' where clanid='" . $claninfo['clanid'] . "'";
                output("Unblocking public description`n");
                db_query($sql);
                invalidatedatacache("clandata-" . $claninfo['clanid'] . "");
                $claninfo['clandesc'] = "";
                $claninfo['descauthor'] = 0;
            }
            $blocked = translate_inline("The clan has been blocked from posting a description.`n");
            if ($claninfo['descauthor'] == 4294967295.0) {
                output_notl("`b`%" . $blocked . "`b");
            }
            rawoutput("<textarea name='clandesc' cols='50' rows='10'>" . htmlentities($claninfo['clandesc'], ENT_COMPAT, getsetting("charset", "ISO-8859-1")) . "</textarea><br>");
            output("`n`&`bCustom Talk Line`b `7(blank means \"says\" -- 15 chars max)`n");
            rawoutput("<input name='customsay' value=\"" . htmlentities($claninfo['customsay'], ENT_COMPAT, getsetting("charset", "ISO-8859-1")) . "\" maxlength=\"15\"><br/>");
            $save = translate_inline("Save");
            rawoutput("<input type='submit' class='button' value=\"{$save}\">");
            $snu = htmlentities(translate_inline("Save & Unblock public description"), ENT_COMPAT, getsetting("charset", "ISO-8859-1"));
            $snb = htmlentities(translate_inline("Save & Block public description"), ENT_COMPAT, getsetting("charset", "ISO-8859-1"));
            if ($claninfo['descauthor'] == "4294967295") {
                rawoutput("<input type='submit' name='unblock' value=\"{$snu}\" class='button'>");
            } else {
                rawoutput("<input type='submit' name='block' value=\"{$snb}\" class='button'>");
            }
            rawoutput("</form>");
        } elseif ($op == "membership") {
            output("This is the clans current membership:`n");
            $setrank = httpget('setrank');
            $who = httpget('who');
            if ($setrank > "") {
                $sql = "UPDATE " . db_prefix("accounts") . " SET clanrank={$setrank} WHERE login='******'";
                db_query($sql);
            }
            $remove = httpget('remove');
            if ($remove > "") {
                $sql = "UPDATE " . db_prefix("accounts") . " SET clanrank=" . CLAN_APPLICANT . ",clanid=0,clanjoindate='0000-00-00 00:00:00' WHERE login='******' AND clanrank<={$session['user']['clanrank']}";
                db_query($sql);
                //delete unread application emails from this user.
                //breaks if the applicant has had their name changed via
                //dragon kill, superuser edit, or lodge color change
                $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE login='******'";
                $row = db_fetch_assoc(db_query($sql));
                $subj = serialize(array($apply_short, $row['name']));
                $sql = "DELETE FROM " . db_prefix("mail") . " WHERE msgfrom=0 AND seen=0 AND subject='{$subj}'";
                db_query($sql);
            }
            $sql = "SELECT acctid,name,login,clanrank,laston,clanjoindate,dragonkills,level FROM " . db_prefix("accounts") . " WHERE clanid={$claninfo['clanid']} ORDER BY clanrank DESC,clanjoindate";
            $result = db_query($sql);
            rawoutput("<table border='0' cellpadding='2' cellspacing='0'>");
            $rank = translate_inline("Rank");
            $name = translate_inline("Name");
            $lev = translate_inline("Level");
            $dk = translate_inline("Dragon Kills");
            $jd = translate_inline("Join Date");
            $lo = translate_inline("Last On");
            $ops = translate_inline("Operations");
            $promote = translate_inline("Promote");
            $demote = translate_inline("Demote");
            $remove = translate_inline("Remove From The Clan");
            $confirm = translate_inline("Are you sure you wish to remove this member from the clan?");
            rawoutput("<tr class='trhead'><td>{$rank}</td><td>{$name}</td><td>{$lev}</td><td>{$dk}</td><td>{$jd}</td><td>{$lo}</td>" . ($session['user']['clanrank'] > CLAN_MEMBER ? "<td>{$ops}</td>" : "") . "</tr>", true);
            $i = 0;
            $tot = 0;
            while ($row = db_fetch_assoc($result)) {
                $i++;
                $tot += $row['dragonkills'];
                rawoutput("<tr class='" . ($i % 2 ? "trlight" : "trdark") . "'>");
                rawoutput("<td>");
                output_notl($ranks[$row['clanrank']]);
                rawoutput("</td><td>");
                $link = "bio.php?char=" . $row['acctid'] . "&ret=" . urlencode($_SERVER['REQUEST_URI']);
                rawoutput("<a href='{$link}'>", true);
                addnav("", $link);
                output_notl("`&%s`0", $row['name']);
                rawoutput("</a>");
                rawoutput("</td><td align='center'>");
                output_notl("`^%s`0", $row['level']);
                rawoutput("</td><td align='center'>");
                output_notl("`\$%s`0", $row['dragonkills']);
                rawoutput("</td><td>");
                output_notl("`3%s`0", $row['clanjoindate']);
                rawoutput("</td><td>");
                output_notl("`#%s`0", reltime(strtotime($row['laston'])));
                rawoutput("</td>");
                rawoutput("<td>");
                rawoutput("[ <a href='runmodule.php?module=claneditor&op=membership&dt={$dt}&setrank=" . ($row['clanrank'] + 1) . "&who=" . rawurlencode($row['login']) . "'>{$promote}</a> | ");
                addnav("", "runmodule.php?module=claneditor&op=membership&dt={$dt}&setrank=" . ($row['clanrank'] + 1) . "&who=" . rawurlencode($row['login']));
                rawoutput("<a href='runmodule.php?module=claneditor&op=membership&dt={$dt}&setrank=" . ($row['clanrank'] - 1) . "&who=" . rawurlencode($row['login']) . "'>{$demote}</a> | ");
                addnav("", "runmodule.php?module=claneditor&op=membership&dt={$dt}&setrank=" . ($row['clanrank'] - 1) . "&who=" . rawurlencode($row['login']));
                rawoutput("<a href='runmodule.php?module=claneditor&op=membership&dt={$dt}&remove=" . rawurlencode($row['login']) . "' onClick=\"return confirm('{$confirm}');\">{$remove}</a> ]");
                addnav("", "runmodule.php?module=claneditor&op=membership&dt={$dt}&remove=" . rawurlencode($row['login']));
                rawoutput("</td>");
                rawoutput("</tr>");
            }
            rawoutput("</table>");
            output("`n`n`^This clan has a total of `\$%s`^ dragon kills.", $tot);
        }
        if ($dt != "" && isset($claninfo)) {
            addnav("Clan Options");
            addnav("Main View", "runmodule.php?module=claneditor&op=mview&dt={$dt}");
            addnav("Update Clan Information", "runmodule.php?module=claneditor&op=updinfo&dt={$dt}");
            addnav("Delete this Clan", "runmodule.php?module=claneditor&op=deleteclan&dt={$dt}");
            addnav("Update Members", "runmodule.php?module=claneditor&op=membership&dt={$dt}");
            addnav("Module Prefs");
            module_editor_navs("prefs-clans", "runmodule.php?module=claneditor&op=editmodule&dt=" . $claninfo['clanid'] . "&mdule=");
        }
    }
    page_footer();
}
function grassyfield_runevent($type)
{
    require_once "lib/buffs.php";
    require_once "lib/commentary.php";
    addcommentary();
    global $session, $playermount;
    // We assume this event only shows up in the forest currently.
    $from = "forest.php?";
    $session['user']['specialinc'] = "module:grassyfield";
    $op = httpget('op');
    if ($op == "return") {
        $session['user']['specialmisc'] = "";
        $session['user']['specialinc'] = "";
        redirect($from, "Redirected to " . $from . " from Grassy Field module");
    }
    checkday();
    output("`n`c`#You Stumble Upon a Grassy Field`c`n`n");
    addnav("Return to the forest", $from . "op=return");
    require_once "lib/mountname.php";
    list($name, $lcname) = getmountname();
    if ($session['user']['specialmisc'] != "Nothing to see here, move along.") {
        if ($session['user']['hashorse'] > 0) {
            list($max, $cur) = grassyfield_getrounds();
            if ($cur > $max * 0.5) {
                // XXX: this message really should be a module objpref
                if ($playermount['partrecharge']) {
                    tlschema("mounts");
                    output($playermount['partrecharge']);
                    tlschema();
                } else {
                    output("`&You allow %s`& to frolic and gambol in the field.", $lcname);
                }
            } else {
                // XXX: this message really should be a module objpref
                if ($playermount['recharge']) {
                    tlschema("mounts");
                    output($playermount['recharge']);
                    tlschema();
                } else {
                    output("`&You allow %s`& to hunt and rest in the field.", $lcname);
                }
            }
            $buff = unserialize($playermount['mountbuff']);
            if (!isset($buff['schema']) || $buff['schema'] == "") {
                $buff['schema'] = "mounts";
            }
            apply_buff('mount', $buff);
            if ($session['user']['hitpoints'] < $session['user']['maxhitpoints']) {
                output("`n`^Your nap leaves you completely healed!");
                $session['user']['hitpoints'] = $session['user']['maxhitpoints'];
            }
            $args = array('soberval' => 0.8, 'sobermsg' => "`n`&Naps are quite a sobering experience!`n", 'schema' => "module-grassyfield");
            modulehook("soberup", $args);
            $session['user']['turns']--;
            output("`n`n`^You spend some time - and Stamina - lying around.");
        } else {
            output("`&Deciding to take a moment and a load off your poor weary feet you take a quick break from your ventures to take in the beautiful surroundings.");
            output("`n`n`^Your break leaves you completely healed!");
            if ($session['user']['hitpoints'] < $session['user']['maxhitpoints']) {
                $session['user']['hitpoints'] = $session['user']['maxhitpoints'];
            }
        }
        $session['user']['specialmisc'] = "Nothing to see here, move along.";
    } else {
        output("`&You relax a while in the fields enjoying the sun and the shade.");
    }
    commentdisplay("`n`n`@Talk with the others lounging here.`n", "grassyfield", "Speak lazily", 10);
}
    $session['user']['recentcomments'] = $seen;
}
page_header("Comment Moderation");
if ($op == "") {
    $area = httpget('area');
    $link = "moderate.php" . ($area ? "?area={$area}" : "");
    $refresh = translate_inline("Refresh");
    rawoutput("<form action='{$link}' method='POST'>");
    rawoutput("<input type='submit' class='button' value='{$refresh}'>");
    rawoutput("</form>");
    addnav("", "{$link}");
    if ($area == "") {
        talkform("X", "says");
        commentdisplay("", "' or '1'='1", "X", 100);
    } else {
        commentdisplay("", $area, "X", 100);
        talkform($area, "says");
    }
} elseif ($op == "audit") {
    $subop = httpget("subop");
    if ($subop == "undelete") {
        $unkeys = httppost("mod");
        if ($unkeys && is_array($unkeys)) {
            $sql = "SELECT * FROM " . db_prefix("moderatedcomments") . " WHERE modid IN ('" . join("','", array_keys($unkeys)) . "')";
            $result = db_query($sql);
            while ($row = db_fetch_assoc($result)) {
                $comment = unserialize($row['comment']);
                $id = addslashes($comment['commentid']);
                $postdate = addslashes($comment['postdate']);
                $section = addslashes($comment['section']);
                $author = addslashes($comment['author']);
    output_notl("`b`c");
}
$subop = httpget('subop');
$com = httpget('comscroll');
$comment = httppost('insertcommentary');
require_once "lib/partner.php";
$partner = get_partner();
addnav("Other");
villagenav();
addnav("I?Return to the Inn", "inn.php");
switch ($op) {
    case "":
    case "strolldown":
    case "fleedragon":
        require "lib/inn/inn_default.php";
        blocknav("inn.php");
        break;
    case "converse":
        commentdisplay("You stroll over to a table, place your foot up on the bench and listen in on the conversation:`n", "inn", "Add to the conversation?", 20);
        break;
    case "bartender":
        require "lib/inn/inn_bartender.php";
        break;
    case "room":
        require "lib/inn/inn_room.php";
        break;
}
if (!$skipinndesc) {
    rawoutput("</span>");
}
page_footer();
<?php

page_header("Clan Halls");
addnav("Clan Options");
output("`b`c`&Clan Halls`c`b");
output("You stroll off to the side where there are some plush leather chairs, and take a seat.");
output("There are several other warriors sitting here talking amongst themselves.");
output("Some Ye Olde Muzak is coming from a fake rock sitting at the base of a potted bush.`n`n");
commentdisplay("", "waiting", "Speak", 25);
if ($session['user']['clanrank'] == CLAN_APPLICANT) {
    addnav("Return to the Lobby", "clan.php");
} else {
    addnav("Return to your Clan Rooms", "clan.php");
}
function scry_run()
{
    global $session;
    addcommentary();
    $area = httpget("area");
    $village = httpget("village");
    $op = httpget("op");
    $cost = $session['user']['level'] * get_module_setting("cost");
    if ($op == "pay") {
        if ($session['user']['gold'] >= $cost) {
            $session['user']['gold'] -= $cost;
            set_module_pref("talks", 0);
            set_module_pref("speaking", 1);
            debuglog("spent {$cost} gold to scry a remote village");
            redirect("runmodule.php?module=scry&op=talk&area=" . htmlentities($area, ENT_COMPAT, getsetting("charset", "ISO-8859-1")) . "&village=" . htmlentities($village, ENT_COMPAT, getsetting("charset", "ISO-8859-1")));
            page_footer();
        } else {
            page_header("Gypsy Seer's tent");
            villagenav();
            addnav("Continue looking around", "gypsy.php");
            output("`5You offer the old gypsy woman your `^%s`5 gold for her scrying services, but she informs you that such a pittance is far too little.", $session['user']['gold']);
            page_footer();
        }
    } elseif ($op == "talk") {
        $times = get_module_setting("uses");
        if ($times && get_module_pref("talks") >= $times) {
            page_header("Gypsy Seer's tent");
            output("`5Looking around dazedly, it takes you a moment to realize that you are no longer viewing the village of %s and that the gypsy woman is staring at you with her hand out.", $village);
            output("`5\"`!I'll need more gold if you want to keep taking up space for my other paying customers!`5\", she demands.`n`n");
            output("You start to demand, \"`&What other customers?`5\" but decide that it's best not to annoy someone who has such power.");
            addnav(array("Scrying (%s gold)", $cost));
            addnav(array("Scry %s", $village), "runmodule.php?module=scry&op=pay&area=" . htmlentities($area, ENT_COMPAT, getsetting("charset", "ISO-8859-1")) . "&village=" . htmlentities($village, ENT_COMPAT, getsetting("charset", "ISO-8859-1")));
            addnav("Other");
            addnav("Return to the tent", "gypsy.php");
            villagenav();
            page_footer();
        } else {
            page_header("Peering in the bowl, you view %s", $village);
            output("`5While staring into the inky water, you are able to make out the people of %s:`n", $village);
            commentdisplay("", $area, "Project", 25, "projects");
            addnav("Look up from the bowl", "gypsy.php");
            page_footer();
        }
    }
}
            addnav("Random Validate Avatars", "runmodule.php?module=avatar&op=validate&mode=validate");
            $sql = "SELECT a.login as login, u.userid as acctid ,a.name as name,a.emailaddress as email FROM " . db_prefix("module_userprefs") . " AS u INNER JOIN " . db_prefix("module_userprefs") . " AS t RIGHT JOIN " . db_prefix("accounts") . " AS a ON u.userid=t.userid AND a.acctid=u.userid WHERE u.modulename='avatar' AND u.setting='avatar' AND u.value!='' AND t.modulename='avatar' AND t.setting='validated' AND t.value!='1' ORDER BY a.login LIMIT 20;";
            $result = db_query($sql);
            output("Click on the name to YOM a user and on a picture to view it in original size.`n`n");
            rawoutput("<table border='0' cellpadding='2' cellspacing='0' width='100%'>");
            rawoutput("<tr class='trhead'><td>" . translate_inline("Picture") . "</td><td>" . translate_inline("Name") . "</td><td>" . translate_inline("Ops") . "</td></tr>");
            $i = 0;
            $details = translate_inline("Details");
            $validate = translate_inline("Validate directly");
            $deny = translate_inline("Deny+Set Default Picture");
            while ($row = db_fetch_assoc($result)) {
                $i = !$i;
                $url = get_module_pref("avatar", "avatar", $row['acctid']);
                rawoutput("<tr class='" . ($i ? "trlight" : "trdark") . "'><td><a href='{$url}' target='_blank'><img src='{$url}' align='center' width='150' height='150'></a></td><td>");
                rawoutput("<a href='mail.php?op=write&to={$row['login']}' class='colLtGreen' target='_blank' onClick=\"" . popup("mail.php?op=write&to={$row['login']}") . ";return false;\">" . sanitize($row['name']) . "</a></td><td>");
                rawoutput("<a href='runmodule.php?module=avatar&op=validate&mode=validate&who={$row['acctid']}'>{$details}</a><br><br>");
                addnav("", "runmodule.php?module=avatar&op=validate&mode=validate&who={$row['acctid']}");
                rawoutput("<a href='runmodule.php?module=avatar&op=validate&mode=&giveok=1&user={$row['acctid']}'>{$validate}</a><br><br>");
                rawoutput("<a href='runmodule.php?module=avatar&op=validate&mode=&deny=1&user={$row['acctid']}'>{$deny}</a><br><br></td></tr>");
                addnav("", "runmodule.php?module=avatar&op=validate&mode=&deny=1&user={$row['acctid']}");
                addnav("", "runmodule.php?module=avatar&op=validate&mode=&giveok=1&user={$row['acctid']}");
            }
            rawoutput("</table>");
        }
        addnav("Invalidate Avatars", "runmodule.php?module=avatar&op=validate&mode=invalidate");
        break;
}
require_once "lib/commentary.php";
addcommentary();
commentdisplay("`n`n`@Validation Discussions`n", "AvatarVal", "Talk", 30, "says");
$refresh = httpget("refresh");
$commenting = httpget("commenting");
$comment = httppost('insertcommentary');
// Don't give people a chance at a special event if they are just browsing
// the commentary (or talking) or dealing with any of the hooks in the village.
if (!$op && $com == "" && !$comment && !$refresh && !$commenting) {
    if (module_events("gardens", getsetting("gardenchance", 0)) != 0) {
        if (checknavs()) {
            page_footer();
        } else {
            // Reset the special for good.
            $session['user']['specialinc'] = "";
            $session['user']['specialmisc'] = "";
            $skipgardendesc = true;
            $op = "";
            httpset("op", "");
        }
    }
}
if (!$skipgardendesc) {
    checkday();
    output("`b`c`2The Gardens`0`c`b");
    output("`n`nYou walk through a gate and on to one of the many winding paths that makes its way through the well-tended gardens.");
    output("From the flowerbeds that bloom even in darkest winter, to the hedges whose shadows promise forbidden secrets, these gardens provide a refuge for those seeking out the Green Dragon; a place where they can forget their troubles for a while and just relax.`n`n");
    output("One of the fairies buzzing about the garden flies up to remind you that the garden is a place for roleplaying and peaceful conversation, and to confine out-of-character comments to the other areas of the game.`n`n");
}
villagenav();
modulehook("gardens", array());
commentdisplay("", "gardens", "Whisper here", 30, "whispers");
module_display_events("gardens", "gardens.php");
page_footer();
    output("`@From: ");
    if ($row['login'] > "") {
        rawoutput("<a href=\"mail.php?op=write&to=" . rawurlencode($row['login']) . "&body=" . rawurlencode("\n\n----- {$yourpeti} -----\n{$reppet}") . "&subject=RE:+{$peti}\" target=\"_blank\" onClick=\"" . popup("mail.php?op=write&to=" . rawurlencode($row['login']) . "&body=" . rawurlencode("\n\n----- {$yourpeti} -----\n{$reppet}") . "&subject=RE:+{$peti}") . ";return false;\"><img src='images/newscroll.GIF' width='16' height='16' alt='{$write}' border='0'></a>");
    }
    output_notl("`^`b%s`b`n", $row['name']);
    output("`@Date: `^`b%s`b (%s)`n", $row['date'], relativedate($row['date']));
    output("`@Status: %s`n", $statuses[$row['status']]);
    if ($row['closedate'] != '0000-00-00 00:00:00') {
        output("`@Last Update: `^%s`@ on `^%s (%s)`n", $row['closer'], $row['closedate'], dhms(strtotime('now') - strtotime($row['closedate']), true));
    }
    output("`@Body:`^`n");
    $body = htmlentities(stripslashes($row['body']), ENT_COMPAT, getsetting("charset", "ISO-8859-1"));
    $body = preg_replace("'([[:alnum:]_.-]+[@][[:alnum:]_.-]{2,}([.][[:alnum:]_.-]{2,})+)'i", "<a href='mailto:\\1?subject=RE: {$peti}&body=" . str_replace("+", " ", URLEncode("\n\n----- {$yourpeti} -----\n" . $row['body'])) . "'>\\1</a>", $body);
    $body = preg_replace("'([\\[][[:alnum:]_.-]+[\\]])'i", "<span class='colLtRed'>\\1</span>", $body);
    rawoutput("<span style='font-family: fixed-width'>" . nl2br($body) . "</span>");
    commentdisplay("`n`@Commentary:`0`n", "pet-{$id}", "Add information", 200);
    if ($viewpageinfo) {
        output("`n`n`@Page Info:`&`n");
        $row['pageinfo'] = stripslashes($row['pageinfo']);
        $body = HTMLEntities($row['pageinfo'], ENT_COMPAT, getsetting("charset", "ISO-8859-1"));
        $body = preg_replace("'([[:alnum:]_.-]+[@][[:alnum:]_.-]{2,}([.][[:alnum:]_.-]{2,})+)'i", "<a href='mailto:\\1?subject=RE: {$peti}&body=" . str_replace("+", " ", URLEncode("\n\n----- {$yourpeti} -----\n" . $row['body'])) . "'>\\1</a>", $body);
        $body = preg_replace("'([\\[][[:alnum:]_.-]+[\\]])'i", "<span class='colLtRed'>\\1</span>", $body);
        rawoutput("<pre>" . nl2br($body) . "</pre>");
    }
}
if ($id && $op != "") {
    $prevsql = "SELECT p1.petitionid, p1.status FROM " . db_prefix("petitions") . " AS p1, " . db_prefix("petitions") . " AS p2\n            WHERE p1.petitionid<'{$id}' AND p2.petitionid='{$id}' AND p1.status=p2.status ORDER BY p1.petitionid DESC LIMIT 1";
    $prevresult = db_query($prevsql);
    $prevrow = db_fetch_assoc($prevresult);
    if ($prevrow) {
        $previd = $prevrow['petitionid'];
} elseif ($op == "newsdelete") {
    $sql = "DELETE FROM " . db_prefix("news") . " WHERE newsid='" . httpget('newsid') . "'";
    db_query($sql);
    $return = httpget('return');
    $return = cmd_sanitize($return);
    $return = substr($return, strrpos($return, "/") + 1);
    redirect($return);
}
page_header("Superuser Grotto");
output("`^You duck into a secret cave that few know about. ");
if ($session['user']['sex']) {
    output("Inside you are greeted by the sight of numerous muscular bare-chested men who wave palm fronds at you and offer to feed you grapes as you lounge on Greco-Roman couches draped with silk.`n`n");
} else {
    output("Inside you are greeted by the sight of numerous scantily clad buxom women who wave palm fronds at you and offer to feed you grapes as you lounge on Greco-Roman couches draped with silk.`n`n");
}
commentdisplay("", "superuser", "Engage in idle conversation with other gods:", 25);
addnav("Actions");
if ($session['user']['superuser'] & SU_EDIT_PETITIONS) {
    addnav("Petition Viewer", "viewpetition.php");
}
if ($session['user']['superuser'] & SU_EDIT_COMMENTS) {
    addnav("C?Recent Commentary", "moderate.php");
}
if ($session['user']['superuser'] & SU_EDIT_COMMENTS) {
    addnav("B?Player Bios", "bios.php");
}
if ($session['user']['superuser'] & SU_EDIT_DONATIONS) {
    addnav("Donator Page", "donators.php");
}
if (file_exists("paylog.php") && $session['user']['superuser'] & SU_EDIT_PAYLOG) {
    addnav("Payment Log", "paylog.php");
$commenting = httpget("commenting");
$comment = httppost('insertcommentary');
// Don't give people a chance at a special event if they are just browsing
// the commentary (or talking) or dealing with any of the hooks in the village.
if (!$op && $com == "" && !$comment && !$refresh && !$commenting) {
    if (module_events("gardens", getsetting("gardenchance", 0)) != 0) {
        if (checknavs()) {
            page_footer();
        } else {
            // Reset the special for good.
            $session['user']['specialinc'] = "";
            $session['user']['specialmisc'] = "";
            $skipgardendesc = true;
            $op = "";
            httpset("op", "");
        }
    }
}
if (!$skipgardendesc) {
    checkday();
    $gardentext = array("text" => "`n`nYou walk through a gate and on to one of the many winding paths that makes its way through the well-tended gardens.`n`nFrom the flowerbeds that bloom even in darkest winter, to the hedges whose shadows promise forbidden secrets, these gardens provide a refuge for those seeking out the Green Dragon; a place where they can forget their troubles for a while and just relax.`n`nOne of the fairies buzzing about the garden flies up to remind you that the garden is a place for roleplaying and peaceful conversation, and to confine out-of-character comments to the other areas of the game.`n`n");
    $gardentext = modulehook("gardentext", $gardentext);
    output_notl("%s", $gardentext['text']);
}
addnav("Places");
modulehook("gardens", array());
commentdisplay("", "gardens", "Chat with other players", 30, "says");
module_display_events("gardens", "gardens.php");
addnav("Leave");
villagenav();
page_footer();
// translator ready
// addnews ready
// mail ready
require_once "common.php";
require_once "lib/villagenav.php";
require_once "lib/commentary.php";
tlschema("rock");
// This idea is Imusade's from lotgd.net
if ($session['user']['dragonkills'] > 0 || $session['user']['superuser'] & SU_EDIT_COMMENTS) {
    addcommentary();
}
checkday();
if ($session['user']['dragonkills'] > 0 || $session['user']['superuser'] & SU_EDIT_COMMENTS) {
    page_header("The Veteran's Club");
    output("`b`c`2The Veteran's Club`0`c`b");
    output("`n`n`4Something in you compels you to examine the curious rock.  Some dark magic, locked up in age old horrors.`n`n");
    output("When you arrive at the rock, an old scar on your arm begins to throb in succession with a mysterious light that now seems to come from the rock.  ");
    output("As you stare at it, the rock shimmers, shaking off an illusion.  You realize that this is more than a rock.  ");
    output("It is, in fact, a doorway, and over the threshold you see others bearing an identical scar to yours.  ");
    output("It somehow reminds you of the head of one of the great serpents from legend.`n`n");
    output("You have discovered The Veteran's Club.`n`n");
    modulehook("rock");
    commentdisplay("", "veterans", "Boast here", 30, "boasts");
} else {
    page_header("Curious looking rock");
    output("You approach the curious looking rock.  ");
    output("After staring and looking at it for a little while, it continues to look just like a curious looking rock.`n`n");
    output("Bored, you decide to leave the rock alone.");
}
villagenav();
page_footer();