function dwellings_run()
{
    checkday();
    page_header("Dwellings");
    global $session;
    $op = httpget("op");
    $dwid = httpget('dwid');
    $type = httpget('type');
    debug(get_module_pref("location_saver"));
    if ($type == "" && $dwid > 0) {
        $sql = "SELECT type FROM " . db_prefix("dwellings") . " WHERE dwid={$dwid}";
        $result = db_query($sql);
        $row = db_fetch_assoc($result);
        $type = $row['type'];
    }
    $cityid = httpget('cityid');
    require_once "modules/dwellings/run/case_{$op}.php";
    if ($op != "list" && $op != "") {
        addnav("Leave");
        addnav("Return to Hamlet", "runmodule.php?module=dwellings");
    } else {
        addnav("Navigation");
        villagenav();
    }
    page_footer();
}
function darkhorse_checkday()
{
    // Reset special-in just in case checkday kicks in.
    $session['user']['specialinc'] = "";
    checkday();
    // And now set it back.
    $session['user']['specialinc'] = "module:darkhorse";
}
<?php

require_once "common.php";
checkday();
$result = db_query("SELECT login,name,level,sex,title,specialty,hashorse,acctid,resurrections,bio,dragonkills,race FROM accounts WHERE login='******'char']}'");
$row = db_fetch_assoc($result);
$row[login] = rawurlencode($row['login']);
page_header("Character Biography: " . preg_replace("'[`].'", "", $row['name']));
$specialty = array(0 => "Unspecified", "Dark Arts", "Mystical Powers", "Thieving Skills");
//$horses=array(0=>"None","Pony","Gelding","Stallion");
output("`^Biography for " . $row['name'] . "");
if ($session['user']['loggedin']) {
    output("<a href=\"mail.php?op=write&to={$row['login']}\" target=\"_blank\" onClick=\"" . popup("mail.php?op=write&to={$row['login']}") . ";return false;\"><img src='images/newscroll.png' width='16' height='16' alt='Write Mail' border='0'></a>", true);
}
output("`n`n");
output("`^Title: `@" . $row['title'] . "`n");
output("`^Level: `@" . $row['level'] . "`n");
output("`^Resurrections: `@" . $row['resurrections'] . "`n");
output("`^Race: `@" . $races[$row['race']] . "`n");
output("`^Gender: `@" . ($row['sex'] ? "Female" : "Male") . "`n");
output("`^Specialty: `@" . $specialty[$row['specialty']] . "`n");
$sql = "SELECT mountname FROM mounts WHERE mountid='{$row['hashorse']}'";
$result = db_query($sql);
$mount = db_fetch_assoc($result);
if ($mount['mountname'] == "") {
    $mount['mountname'] = "`iNone`i";
}
output("`^Creature: `@" . $mount['mountname'] . "`n");
if ($row['dragonkills'] > 0) {
    output("`^Dragon Kills: `@" . $row['dragonkills'] . "`n");
}
function worldmapen_run_real()
{
    global $session, $badguy, $pvptimeout, $options, $outdoors, $shady;
    $outdoors = true;
    $op = httpget("op");
    $battle = false;
    if ($op == 'move' && rawurldecode(httpget('oloc')) != get_module_pref('worldXYZ')) {
        debug(get_module_pref('worldXYZ'));
        $op = 'continue';
        httpset('op', $op);
    }
    //	debug("Worldmap running op={$op} ...");
    // handle the admin editor first
    if ($op == "edit") {
        if (!get_module_pref("canedit")) {
            check_su_access(SU_EDIT_USERS);
        }
        if (get_module_setting("worldmapenInstalled") != 1) {
            set_module_setting('worldmapenInstalled', "1");
            worldmapen_defaultcityloc();
        }
        worldmapen_editor();
    }
    if ($op == "destination") {
        $cname = httpget("cname");
        $session['user']['location'] = $cname;
        addnav(array("Enter %s", $cname), "village.php");
        output("`c`4`bYou've Arrived in %s.`b`0`c`n", $cname);
        output("`cYou have reached the outer gates of the city.`c");
    }
    if (!get_module_setting("worldmapenInstalled")) {
        page_header("A rip in the fabric of space and time");
        require_once "lib/villagenav.php";
        villagenav();
        output("`^The admins of this game haven't yet finished installing the worldmapen module.");
        output("You should send them a petition and tell them that they forgot to generate the initial locations of the cities.");
        output("Until then, you are kind of stuck here, so I hope you like where you are.`n`n");
        output("After all, remember:`nWherever you go, there you are.`0");
        page_footer();
    }
    $subop = httpget("subop");
    $act = httpget("act");
    $type = httpget("type");
    $name = httpget("name");
    $direction = httpget("dir");
    $su = httpget("su");
    $buymap = httpget("buymap");
    $worldmapCostGold = get_module_setting("worldmapCostGold");
    $pvp = httpget('pvp');
    require_once "lib/events.php";
    if ($session['user']['specialinc'] != "" || httpget("eventhandler")) {
        $in_event = handle_event(get_module_setting("randevent"), "runmodule.php?module=worldmapen&op=continue&", "Travel");
        if ($in_event) {
            addnav("Continue", "runmodule.php?module=worldmapen&op=continue");
            module_display_events(get_module_setting("randevent"), "runmodule.php?module=worldmapen&op=continue");
            page_footer();
        }
    }
    page_header("Journey");
    //is the player looking at chat?
    if (httpget('comscroll') || httpget('comscroll') === 0 || httpget('comment') || httpget('refresh')) {
        $chatoverride = 1;
        require_once "lib/commentary.php";
        addcommentary();
        $loc = get_module_pref("worldXYZ", "worldmapen");
        viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
    }
    if ($op == "beginjourney") {
        $loc = $session['user']['location'];
        $x = get_module_setting($loc . "X");
        $y = get_module_setting($loc . "Y");
        $z = get_module_setting($loc . "Z");
        $xyz = $x . "," . $y . "," . $z;
        set_module_pref("worldXYZ", $xyz);
        output("`b`&The gates of %s`& stand closed behind you.`0`b`n`n", $session['user']['location']);
        $num = e_rand(1, 5);
        $msg = get_module_setting("leaveGates{$num}");
        output("`c`n`^%s`0`n`c`n", $msg);
        worldmapen_determinenav();
        if (get_module_setting("smallmap")) {
            worldmapen_viewsmallmap();
        }
        if (!$chatoverride) {
            require_once "lib/commentary.php";
            addcommentary();
            $loc = get_module_pref("worldXYZ", "worldmapen");
            viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
        }
        worldmapen_viewmapkey(true, false);
        module_display_events(get_module_setting("randevent"), "runmodule.php?module=worldmapen&op=continue");
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        $t = worldmapen_getTerrain($x, $y, $z);
        //debug($t);
        if ($t['type'] == "Forest") {
            $shady = true;
        }
    } elseif ($op == "continue") {
        checkday();
        worldmapen_determinenav();
        if (get_module_setting("smallmap")) {
            worldmapen_viewsmallmap();
        }
        if (!$chatoverride) {
            require_once "lib/commentary.php";
            addcommentary();
            $loc = get_module_pref("worldXYZ", "worldmapen");
            viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
        }
        worldmapen_viewmapkey(true, false);
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        $t = worldmapen_getTerrain($x, $y, $z);
        //debug($t);
        if ($t['type'] == "Forest") {
            $shady = true;
        }
        //Turns Trading bit, added by CavemanJoe
    } elseif ($op == "tradeturn") {
        checkday();
        $pointstrade = get_module_setting("turntravel");
        output("You can trade one Turn for %s Travel Points.  Do you want to do this now?", $pointstrade);
        addnav("Yes, use a turn", "runmodule.php?module=worldmapen&op=tradeturnconfirm");
        addnav("No, cancel and return to the map", "runmodule.php?module=worldmapen&op=continue");
    } elseif ($op == "tradeturnconfirm") {
        $pointstrade = get_module_setting("turntravel");
        output("By conserving energy that you would have otherwise used for fighting creatures, you have gained %s Travel Points.", $pointstrade);
        $session['user']['turns']--;
        $ttoday = get_module_pref("traveltoday", "cities");
        set_module_pref("traveltoday", $ttoday - $pointstrade, "cities");
        addnav("Continue", "runmodule.php?module=worldmapen&op=continue");
    } elseif ($op == "move" && !$chatoverride) {
        checkday();
        if ($session['user']['location'] != 'World') {
            set_module_pref("lastCity", $session['user']['location']);
            $session['user']['location'] = "World";
        }
        $session['user']['restorepage'] = "runmodule.php?module=worldmapen&op=continue";
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        if ($direction == "north") {
            $y += 1;
        }
        if (get_module_setting("compasspoints") == "1" and $direction == "northeast") {
            $y += 1;
            $x += 1;
        }
        if (get_module_setting("compasspoints") == "1" and $direction == "northwest") {
            $y += 1;
            $x -= 1;
        }
        if ($direction == "east") {
            $x += 1;
        }
        if ($direction == "south") {
            $y -= 1;
        }
        if (get_module_setting("compasspoints") == "1" and $direction == "southeast") {
            $y -= 1;
            $x += 1;
        }
        if (get_module_setting("compasspoints") == "1" and $direction == "southwest") {
            $y -= 1;
            $x -= 1;
        }
        if ($direction == "west") {
            $x -= 1;
        }
        $terraincost = worldmapen_terrain_cost($x, $y, $z);
        $encounterbase = worldmapen_encounter($x, $y, $z);
        $encounterchance = get_module_pref("encounterchance");
        $encounter = $encounterbase * $encounterchance / 100;
        debug($encounterbase . " * " . $encounterchance . " / 100 = " . $encounter);
        $ttoday = get_module_pref("traveltoday", "cities");
        set_module_pref("traveltoday", $ttoday + $terraincost, "cities");
        worldmapen_terrain_takestamina($x, $y, $z);
        $xyz = $x . "," . $y . "," . $z;
        set_module_pref("worldXYZ", $xyz);
        // $randchance = get_module_setting("randchance");
        // if (e_rand(0,100) < $randchance){
        // $eventravel = "travel";
        // set_module_setting("randevent", $eventravel);
        // }else{
        // $eventravel = "forest";
        // set_module_setting("randevent", $eventravel);
        // }
        //Extra Gubbins pertaining to trading Turns for Travel, added by Caveman Joe
        $useturns = get_module_setting("useturns");
        $allowzeroturns = get_module_setting("allowzeroturns");
        $playerturns = $session['user']['turns'];
        $proceed = 1;
        //the Proceed value is used when the player has hit a monster, to make sure it's okay to actually run the event/monster.
        if ($playerturns == 0 && $allowzeroturns == 0) {
            $proceed = 0;
        }
        if (e_rand(0, 100) < $encounter && $su != '1' && $proceed == 1 && !$chatoverride) {
            // They've hit a monster!
            if (module_events(get_module_setting("randevent"), get_module_setting("wmspecialchance"), "runmodule.php?module=worldmapen&op=continue&") != 0) {
                page_header("Something Special!");
                if (checknavs()) {
                    page_footer();
                } else {
                    // Reset the special for good.
                    $session['user']['specialinc'] = "";
                    $session['user']['specialmisc'] = "";
                    $skipvillagedesc = true;
                    $op = "";
                    httpset("op", "");
                    addnav("Continue", "runmodule.php?module=worldmapen&op=continue&");
                    module_display_events(get_module_setting("randevent"), "runmodule.php?module=worldmapen&op=continue");
                    page_footer();
                }
            }
            //Check if we're removing a turn when the player encounters a monster, and if so, do it
            if ($useturns == 1) {
                $session['user']['turns']--;
            }
            //Fix to only search for Forest type creatures, added by CavemanJoe
            $sql = "SELECT * FROM " . db_prefix("creatures") . " WHERE creaturelevel = '{$session['user']['level']}' AND forest = 1 ORDER BY rand(" . e_rand() . ") LIMIT 1";
            $result = db_query($sql);
            restore_buff_fields();
            if (db_num_rows($result) == 0) {
                // There is nothing in the database to challenge you,
                // let's give you a doppleganger.
                $badguy = array();
                $badguy['creaturename'] = "An evil doppleganger of " . $session['user']['name'];
                $badguy['creatureweapon'] = $session['user']['weapon'];
                $badguy['creaturelevel'] = $session['user']['level'];
                $badguy['creaturegold'] = rand($session['user']['level'] * 15, $session['user']['level'] * 30);
                $badguy['creatureexp'] = round($session['user']['experience'] / 10, 0);
                $badguy['creaturehealth'] = $session['user']['maxhitpoints'];
                $badguy['creatureattack'] = $session['user']['attack'];
                $badguy['creaturedefense'] = $session['user']['defense'];
            } else {
                $badguy = db_fetch_assoc($result);
                require_once "lib/forestoutcomes.php";
                $badguy = buffbadguy($badguy);
            }
            calculate_buff_fields();
            $badguy['playerstarthp'] = $session['user']['hitpoints'];
            $badguy['diddamage'] = 0;
            $badguy['type'] = 'world';
            //debug("Worldmap run.php is debugging badguy");
            //debug($badguy);
            $session['user']['badguy'] = createstring($badguy);
            $battle = true;
        } else {
            // $args = modulehook("count-travels", array('available'=>0, 'used'=>0));
            // $free = max(0, $args['available'] - $args['used']);
            // if (get_module_setting("usestamina")==1){
            // output("`c`nYou think to yourself what a nice day it is.`c`n");
            // } else {
            // output("`c`nYou think to yourself what a nice day it is.`nYou have %s Travel Points remaining.%s`c`n",$free);
            // }
            $free = 100;
            worldmapen_determinenav();
            if (get_module_setting("smallmap")) {
                worldmapen_viewsmallmap();
            }
            if (!$chatoverride) {
                require_once "lib/commentary.php";
                addcommentary();
                $loc = get_module_pref("worldXYZ", "worldmapen");
                viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
            }
            worldmapen_viewmapkey(true, false);
            module_display_events(get_module_setting("randevent"), "runmodule.php?module=worldmapen&op=continue");
        }
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        $t = worldmapen_getTerrain($x, $y, $z);
        //debug($t);
        if ($t['type'] == "Forest") {
            $shady = true;
        }
    } elseif ($op == "gypsy") {
        $outdoors = false;
        if ($buymap == '') {
            output("`5\"`!Ah, yes.  An adventurer.  I could tell by looking into your eyes,`5\" the gypsy says.`n");
            output("\"`!Many people have lost their way while journeying without a guide such as this.");
            output("It will let you see all the world.`5\"`n");
            output("\"`!Yes, yes.  Let's see...  What sort of price should we put on this?");
            output("Hmm.  How about `^%s`! gold?`5\"", $worldmapCostGold);
            addnav(array("Buy World Map `0(`^%s gold`0)", $worldmapCostGold), "runmodule.php?module=worldmapen&op=gypsy&buymap=yes");
            addnav("Forget it", "village.php");
        } elseif ($buymap == 'yes') {
            if ($session['user']['gold'] < $worldmapCostGold) {
                output("`5\"`!What do you take me for?  A blind hag?  Come back when you have the money`5\"");
                addnav("Leave quickly", "village.php");
            } else {
                output("`5\"`!Enjoy your newfound sight,`5\"  the gypsy says as she walks away to greet some patrons that have just strolled in.");
                $session['user']['gold'] -= $worldmapCostGold;
                set_module_pref("worldmapbuy", 1);
                require_once "lib/villagenav.php";
                villagenav();
            }
        }
    } elseif ($op == "viewmap") {
        worldmapen_determinenav();
        worldmapen_viewmap(true);
        if (is_module_active("medals")) {
            require_once "modules/medals.php";
            medals_award_medal("boughtmap", "Bearer of the Map", "This player purchased the World Map from the Comms Tent!", "medal_islandmap.png");
        }
    } elseif ($op == "camp") {
        if ($session['user']['loggedin']) {
            $session['user']['loggedin'] = 0;
            $session['user']['restorepage'] = "runmodule.php?module=worldmapen&op=wake";
            saveuser();
            invalidatedatacache("charlisthomepage");
            invalidatedatacache("list.php-warsonline");
        }
        $session = array();
        redirect("index.php", "Redirected to Index from World Map");
    } elseif ($op == "wake") {
        if ($session['user']['hitpoints'] > 0) {
            // runmodule.php calls do_forced_nav,
            $session['user']['alive'] = true;
            // and that resets ['alive'], so
        } else {
            // this is from common.php to make sure
            $session['user']['alive'] = false;
            // the player is not half-dead after log-in.
        }
        output("You yawn and stretch and look around your campsite.`n`n");
        output("Ah, how wonderful it is to sleep in the open air!`n");
        output("The world seems full of possibilities today.`n`n");
        checkday();
        worldmapen_determinenav();
        if (get_module_setting("smallmap")) {
            worldmapen_viewsmallmap();
        }
        if (!$chatoverride) {
            require_once "lib/commentary.php";
            addcommentary();
            $loc = get_module_pref("worldXYZ", "worldmapen");
            viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
        }
        worldmapen_viewmapkey(true, false);
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        $t = worldmapen_getTerrain($x, $y, $z);
        //debug($t);
        if ($t['type'] == "Forest") {
            $shady = true;
        }
    } elseif ($op == "combat") {
        // Okay, we've picked a person to fight.
        require_once "lib/pvpsupport.php";
        $name = httpget("name");
        $badguy = setup_target($name);
        $failedattack = false;
        if ($badguy === false) {
            output("`0`n`nYou survey the area again.`n");
            worldmapen_determinenav();
        } else {
            $battle = true;
            $badguy['type'] = 'pvp';
            //$options['type'] = 'pvp';
            $session['user']['badguy'] = createstring($badguy);
            $session['user']['playerfights']--;
        }
    } elseif ($op == "fight" || $op == "run") {
        if (!$chatoverride && !httpget("frombio")) {
            $battle = true;
        } else {
            worldmapen_determinenav();
            if (get_module_setting("smallmap")) {
                worldmapen_viewsmallmap();
            }
            worldmapen_viewmapkey(true, false);
        }
        // $args = modulehook("count-travels", array('available'=>0,'used'=>0));
        // $free = max(0, $args['available'] - $args['used']);
        // if (get_module_setting("usestamina")==1){
        $free = 100;
        // }
        if ($op == "run" && !$pvp) {
            if (!$chatoverride) {
                if (e_rand(1, 5) < 3 && $free) {
                    // They managed to get away.
                    output("You set off running at a breakneck pace!`n`n");
                    output("A short time later, you have managed to avoid your opponent, so you stop to catch your breath.");
                    $ttoday = get_module_pref("traveltoday", "cities");
                    set_module_pref("traveltoday", $ttoday + 1, "cities");
                    output("As you look around, you realize that all you really managed was to run in circles.");
                    $battle = false;
                    worldmapen_determinenav();
                    if (get_module_setting("smallmap")) {
                        worldmapen_viewsmallmap();
                    }
                    require_once "lib/commentary.php";
                    addcommentary();
                    $loc = get_module_pref("worldXYZ", "worldmapen");
                    viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
                    worldmapen_viewmapkey(true, false);
                } else {
                    output("You try to run, but you don't manage to get away!`n");
                    $op = "fight";
                    httpset('op', $op);
                }
            } else {
                if (get_module_setting("smallmap")) {
                    worldmapen_viewsmallmap();
                }
                require_once "lib/commentary.php";
                addcommentary();
                $loc = get_module_pref("worldXYZ", "worldmapen");
                viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
                worldmapen_determinenav();
                worldmapen_viewmapkey(true, false);
            }
        } elseif ($op == "run" && $pvp) {
            output("Your pride prevents you from running");
            $op = "fight";
            httpset('op', $op);
        }
        $loc = get_module_pref('worldXYZ');
        list($x, $y, $z) = explode(",", $loc);
        $t = worldmapen_getTerrain($x, $y, $z);
        //debug($t);
        if ($t['type'] == "Forest") {
            $shady = true;
        }
    }
    if ($battle) {
        include_once "battle.php";
        if (isset($enemies) && !$pvp) {
            $badguy =& $enemies;
        }
        if ($victory) {
            if ($pvp) {
                require_once "lib/pvpsupport.php";
                $aliveloc = $badguy['location'];
                pvpvictory($badguy, $aliveloc, $options);
                addnews("`4%s`3 defeated `4%s`3 while they were camped in the wilderness.`0", $session['user']['name'], $badguy['creaturename']);
                $badguy = array();
            } else {
                if (!$chatoverride && !httpget('frombio')) {
                    //is talking
                    require_once "lib/forestoutcomes.php";
                    forestvictory($badguy, false);
                }
            }
            //has just beaten a badguy
            worldmapen_determinenav();
            if (get_module_setting("smallmap")) {
                worldmapen_viewsmallmap();
            }
            if (!$chatoverride) {
                require_once "lib/commentary.php";
                addcommentary();
                $loc = get_module_pref("worldXYZ", "worldmapen");
                viewcommentary("mapchat-" . $loc, "Chat with others who walk this path...", 25);
            }
            worldmapen_viewmapkey(true, false);
        } elseif ($defeat) {
            // Reset the players body to the last city they were in
            $session['user']['location'] = get_module_pref('lastCity');
            if ($pvp) {
                require_once "lib/pvpsupport.php";
                require_once "lib/taunt.php";
                $killedloc = $badguy['location'];
                $taunt = select_taunt();
                pvpdefeat($badguy, $killedloc, $taunt, $options);
                addnews("`4%s`3 was defeated while attacking `4%s`3 as they were camped in the wilderness.`0`n%s", $session['user']['name'], $badguy['creaturename'], $taunt);
            } else {
                require_once "lib/forestoutcomes.php";
                forestdefeat($badguy, "in the wild");
            }
            output("`n`n`&You are sure that someone, sooner or later, will stumble over your corpse and return it to %s`& for you.`0", $session['user']['location']);
        } else {
            require_once "lib/fightnav.php";
            $allow = true;
            $extra = "";
            if ($pvp) {
                $allow = false;
                $extra = "pvp=1&";
            }
            fightnav($allow, $allow, "runmodule.php?module=worldmapen&{$extra}");
        }
    }
    page_footer();
}
function peerpressure_runevent($type)
{
    global $session;
    $session['user']['specialinc'] = "module:peerpressure";
    // For translation reasons, you cannot really substitute in his/her
    // since the gender can change other things
    if ($session['user']['sex']) {
        addnews("`&%s`7 heroically decided to seek out `@The Green Dragon`7 with cheers of encouragement from her peers ringing in her ears.", $session['user']['name']);
    } else {
        addnews("`&%s`7 heroically decided to seek out `@The Green Dragon`7 with cheers of encouragement from his peers ringing in his ears.", $session['user']['name']);
    }
    output("`2Wandering the village, going about your business, you are suddenly surrounded by a group of villagers.");
    output("They wonder why such an experienced adventurer as yourself hasn't slain a dragon yet.");
    output("You mutter some embarrassed excuses but they aren't listening.");
    output("They crowd around you closer, and lift you up on their shoulders.");
    $isforest = 0;
    $vloc = modulehook('validforestloc', array());
    foreach ($vloc as $i => $l) {
        if ($session['user']['location'] == $l) {
            $isforest = 1;
            break;
        }
    }
    if ($isforest || count($vloc) == 0) {
        output("`n`nCheering your name the whole way, they carry you into the forest, and right to the mouth of a cave outside the town!`n`n");
    } else {
        $key = array_rand($vloc);
        output("`n`nCheering your name the whole way, they carry you far into the forest, and right to the mouth of a cave outside the town of %s!`n`n", $key);
        $session['user']['location'] = $key;
    }
    output("Still cheering your name, they put you down and eagerly wait for you to enter and slay that dragon.`n`n");
    output("You know that you'd never live it down if you tried to back out now.");
    output("Swallowing your fear as best you can, you enter the cave.");
    if (is_module_active("dragonplace")) {
        addnav("Enter the cave", "runmodule.php?module=dragonplace&op=cave");
    } else {
        addnav("Enter the cave", "dragon.php?nointro=1");
    }
    $session['user']['specialinc'] = "";
    checkday();
    //increment buffs, newday buffs, and heal... and probably throw people off in general
    $session['user']['specialinc'] = "module:peerpressure";
    apply_buff('peerpressure', array("name" => "`2Heroic Valor", "rounds" => 20, "atkmod" => 1 + get_module_pref("dayspast") / 100, "defmod" => 1 + get_module_pref("dayspast") / 100, "startmsg" => "`2You fight bravely, considering the pressure you're under.", "wearoff" => "`@The Green Dragon`2 has beaten and burnt the bravery out of you.", "schema" => "module-peerpressure"));
}
               <input type="checkbox" id="inlineCheckbox4" <?php 
        checkday('Jueves', $dias);
        ?>
 name="diasC[]" value="Jueves">
               <span class='checkbox-material'><span class='check'></span></span> Jue
            </label>
            <label class="checkday">
               <input type="checkbox" id="inlineCheckbox5" <?php 
        checkday('Viernes', $dias);
        ?>
 name="diasC[]" value="Viernes">
               <span class='checkbox-material'><span class='check'></span></span> Vie
            </label>
            <label class="checkday">
               <input type="checkbox" id="inlineCheckbox6" <?php 
        checkday('Sabado', $dias);
        ?>
 name="diasC[]" value="Sabado" name="diasC">
               <span class='checkbox-material'><span class='check'></span></span> Sab
            </label>
         </div>
      </div>
   </div>
   <div class="clearfix"></div>
</div>
<div class="row">
   <div class="col-xs-12 col-sm-12 bg-info ">   
      <div class="form-group">
         <label class="col-xs-12 col-sm-3">Hora Entrada: </label>
         <div class="col-xs-12 col-sm-9">
            <input type="time" class="form-control" name="hora1" value="<?php 
<?
require_once "common.php";
if ((int)getsetting("expirecontent",180)>0){
	$sql = "DELETE FROM news WHERE newsdate<'".date("Y-m-d H:i:s",strtotime("-".getsetting("expirecontent",180)." days"))."'";
	//echo $sql;
	db_query($sql);
}
if ($session[user][slainby]!=""){
	page_header("You have been slain!");
		output("`\$You were slain in ".$session[user][killedin]."`\$ by `%".$session[user][slainby]."`\$.  They cost you 5% of your experience, and took any gold you had.  Don't you think it's time for some revenge?");
	addnav("Continue",$REQUEST_URI);
	$session[user][slainby]="";
	page_footer();
}else{
	
	if ($session['user']['loggedin']) checkday();
	$newsperpage=50;
	
	$offset = (int)$HTTP_GET_VARS[offset];
	$timestamp=strtotime((0-$offset)." days");
	$sql = "SELECT count(newsid) AS c FROM news WHERE newsdate='".date("Y-m-d",$timestamp)."'";
	$result = db_query($sql);
	$row = db_fetch_assoc($result);
	$totaltoday=$row['c'];
	$pageoffset = (int)$_GET['page'];
	if ($pageoffset>0) $pageoffset--;
	$pageoffset*=$newsperpage;
	$sql = "SELECT * FROM news WHERE newsdate='".date("Y-m-d",$timestamp)."' ORDER BY newsid DESC LIMIT $pageoffset,$newsperpage";
	$result = db_query($sql) or die(db_error(LINK));
	page_header("LoGD News");
	$date=date("D, M j, Y",$timestamp);
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);
}
function haberdasher_run()
{
    global $session;
    $uid = $session['user']['acctid'];
    $spendall = get_module_setting("spendall");
    $op = httpget('op');
    $page = httpget('page');
    $perpage = get_module_setting("perpage");
    page_header("Deimos' Haberdashery");
    output("`c`b`\$Deimos' Haberdashery`b`c");
    $starting = get_module_setting("lowesthat");
    if ($op == "buy") {
        output("`7\"`3I think I'd like to buy a hat,`7\" you say.`n`n");
        output("`\$Deimos`7 says, \"`\$Good plan. Everyone should have a hat, especially you.`7\"`n`n");
        output("You ask him, \"`3What would a hat do?`7\"");
        output("You expect it'd look rather charming, or maybe help you defend yourself.`n`n");
        output("`\$Deimos`7 gives you a look, then answers, \"`\$Why, it sits on your head, of course.");
        output("What else would it do?");
        output("My hats are a luxury, you see.");
        output("Well, I suppose you could compare your hat to others, and see whose is the grandest.");
        output("Hats start at `^%s `\$gold, for the basic model.`7\"`n`n", $starting);
        output("`7How much gold do you want to spend on your hat?`n");
        $buy = translate_inline("Buy Hat");
        rawoutput("<form action='runmodule.php?module=haberdasher&op=bought' method='POST'>");
        rawoutput("<input name='amount' id='amount' width='8'>");
        rawoutput("<input type='submit' class='button' value='{$buy}'>");
        rawoutput("</form>");
        addnav("", "runmodule.php?module=haberdasher&op=bought");
        if ($spendall) {
            output("`i`7Enter 0 or nothing to spend all your gold on your hat.`i");
        }
        addnav("H?Return to Haberdashery", "runmodule.php?module=haberdasher");
        addnav("L?View Deimos' Customer List", "runmodule.php?module=haberdasher&op=listing");
        villagenav();
    } elseif ($op == "bought") {
        $amount = abs((int) httppost('amount'));
        if ($spendall) {
            if ($amount == 0) {
                $amount = $session['user']['gold'];
            }
        }
        if ($session['user']['gold'] == 0) {
            output("`\$Deimos`7 stares at you blankly, as you don't have any gold, then walks off to do more important things.");
        } elseif ($amount > $session['user']['gold']) {
            output("`\$Deimos`7 stares at you blankly, as you don't have that much gold, then walks off to do more important things.");
        } elseif ($amount < $starting) {
            output("`\$Deimos`7 looks at you pointedly and says, \"`\$I thought we went over this,`7\" then walks off to do more important things.`n`n");
            output("`7You need to spend at least `^%s`7 gold on a hat.", $starting);
        } else {
            $session['user']['gold'] -= $amount;
            debuglog("spent {$amount} gold buying a hat.");
            set_module_pref("hatgold", $amount);
            $hatsize = haberdasher_sizecalc($uid);
            output("`\$Deimos`7 quickly and skillfully fashions you a hat as you try and follow what he is doing.");
            output("When he is done he hands the hat to you and watches you don it.");
            output("\"`\$Wonderful hat, if I do say so myself. Which I do.");
            output("You'll surely have some bragging rights with a hat like that,`7\" he says, mostly to himself.`n`n");
            output("You pay `\$Deimos`7 his `^%s `7gold and are now the proud owner of a size `@%s `7hat.", $amount, $hatsize);
            addnav("H?Return to Haberdashery", "runmodule.php?module=haberdasher");
            addnav("L?View Deimos' Customer List", "runmodule.php?module=haberdasher&op=listing");
        }
        villagenav();
    } elseif ($op == "upgrade") {
        output("`7You inform `\$Deimos`7 that you want a bigger hat.`n`n");
        output("`\$Deimos`7 looks at you and your hat and says, \"`\$I suppose you're right.");
        output("Your hat, grand as it is, could stand some improving.");
        output("I'll tell you what, I'll do just that, just let me know how much to improve it.");
        output("Bear in mind, I won't keep doing this bit by bit, as I'm quite busy.");
        $impmin = get_module_setting("improvemin");
        output("You'll have to spend at least %s percent of what you've already spent on your hat to make it worth my doing.`7\"`n`n", $impmin);
        $worth = get_module_pref("hatgold");
        $hatsize = haberdasher_sizecalc($uid);
        output("`7Your size `@%s `7hat is worth `^%s `7gold so far.`n`n", $hatsize, $worth);
        output("`7How much gold do you want to spend on your hat?`n");
        $upgrade = translate_inline("Upgrade Hat");
        rawoutput("<form action='runmodule.php?module=haberdasher&op=upgraded' method='POST'>");
        rawoutput("<input name='amount' id='amount' width='8'>");
        rawoutput("<input type='submit' class='button' value='{$upgrade}'>");
        rawoutput("</form>");
        addnav("", "runmodule.php?module=haberdasher&op=upgraded");
        if ($spendall) {
            output("`i`7Enter 0 or nothing to spend all your gold on your hat.`i");
        }
        addnav("H?Return to Haberdashery", "runmodule.php?module=haberdasher");
        addnav("L?View Deimos' Customer List", "runmodule.php?module=haberdasher&op=listing");
        villagenav();
    } elseif ($op == "upgraded") {
        $amount = abs((int) httppost('amount'));
        $hatgold = get_module_pref("hatgold");
        $impmin = get_module_setting("improvemin");
        $impmin = $impmin / 100;
        $needimp = $hatgold * $impmin;
        if ($spendall) {
            if ($amount == 0) {
                $amount = $session['user']['gold'];
            }
        }
        if ($session['user']['gold'] == 0) {
            output("`\$Deimos`7 stares at you blankly, as you don't have any gold, then walks off to do more important things.");
        } elseif ($amount > $session['user']['gold']) {
            output("`\$Deimos`7 stares at you blankly, as you don't have that much gold, then walks off to do more important things.");
        } elseif ($amount < $needimp) {
            output("`\$Deimos`7 looks at you pointedly and says, \"`\$I thought we went over this,`7\" then walks off to do more important things.`n`n");
            $impmin = get_module_setting("improvemin");
            output("`7You need to improve your hat by at least %s percent.", $impmin);
        } else {
            $session['user']['gold'] -= $amount;
            debuglog("spent {$amount} gold upgrading their hat.");
            set_module_pref("hatgold", $amount + get_module_pref("hatgold"));
            $hatsize = haberdasher_sizecalc($uid);
            output("`\$Deimos`7 takes your hat and sets to work quickly and skillfully improving it.");
            output("In what seems to be a lot less time than it should take, your hat is ready to be donned again.");
            output("`\$Deimos`7 hands your hat back to you, better than ever.");
            output("\"`\$I didn't think I could improve on my own work, but here I am, doing it again,`7\" he comments, mostly to himself.`n`n");
            $worth = get_module_pref("hatgold");
            output("You pay `\$Deimos`7 his `^%s `7gold. You now have a size `@%s `7hat, worth `^%s`7 gold!", $amount, $hatsize, $worth);
            addnav("H?Return to Haberdashery", "runmodule.php?module=haberdasher");
            addnav("L?View Deimos' Customer List", "runmodule.php?module=haberdasher&op=listing");
        }
        villagenav();
    } elseif ($op == "listing") {
        $page = (int) $page;
        if (!$page) {
            $page = 1;
        }
        $pageoffset = $page;
        if ($pageoffset > 0) {
            $pageoffset--;
        }
        $pageoffset *= $perpage;
        $from = $pageoffset + 1;
        $limit = " LIMIT {$pageoffset},{$perpage} ";
        output("`7You take a look at `\$Deimos`7' customer listing, which is sitting on the counter.");
        output("Apparently `\$Deimos`7 is rather proud of his biggest customers.`n`n");
        output("`c`b`\$Deimos' Customer Listing`b`c`n");
        $sql = "SELECT COUNT(*) AS c FROM " . db_prefix("module_userprefs") . " WHERE modulename='haberdasher' and value>0 and setting='hatsize'";
        $result = db_query($sql);
        $row = db_fetch_assoc($result);
        $listtotal = $row['c'];
        $sql = "SELECT prefs.userid, (prefs.value+0) AS hatsize, users.name, users.sex, users.race FROM " . db_prefix("module_userprefs") . " AS prefs, " . db_prefix("accounts") . " AS users WHERE prefs.setting='hatsize' AND prefs.value>0 AND prefs.modulename='haberdasher' AND prefs.userid=users.acctid ORDER BY (prefs.value+0) DESC, prefs.userid ASC {$limit}";
        $result = db_query($sql);
        $count = db_num_rows($result);
        $rank = translate_inline("Rank");
        $size = translate_inline("Size");
        $cust = translate_inline("Customer");
        $sex = translate_inline("Sex");
        $race = translate_inline("Race");
        rawoutput("<table border='0' cellpadding='2' cellspacing='1' align='center' bgcolor='#999999'>");
        rawoutput("<tr class='trhead'><td>{$rank}</td><td>{$size}</td><td>{$cust}</td><td>{$sex}</td><td>{$race}</td>");
        if ($from + $perpage < $listtotal) {
            $cond = $pageoffset + $perpage;
        } else {
            $cond = $listtotal;
        }
        for ($i = $pageoffset; $i < $cond && $count; $i++) {
            $row = db_fetch_assoc($result);
            if ($row['name'] == $session['user']['name']) {
                rawoutput("<tr class='trhilight'><td>");
            } else {
                rawoutput("<tr class='" . ($i % 2 ? "trdark" : "trlight") . "'><td>");
            }
            $j = $i + 1;
            output_notl("{$j}.");
            rawoutput("</td><td align=\"center\">");
            output_notl("`@%s`0", $row['hatsize']);
            rawoutput("</td><td>");
            output_notl("`&%s`0", $row['name']);
            rawoutput("</td><td>");
            output_notl("%s`0", translate_inline($row['sex'] ? "`%Female" : "`!Male"));
            rawoutput("</td><td>");
            output_notl("`#%s`0", translate_inline($row['race'], "race"));
            rawoutput("</td></tr>");
        }
        if ($count == 0) {
            rawoutput("<tr><td colspan='5'>");
            output("`i`7Nobody has yet bought one of `\$Deimos'`7 fine hats. Why not be the first?`i");
            rawoutput("</td></tr>");
        }
        rawoutput("</table>");
        addnav("H?Return to Haberdashery", "runmodule.php?module=haberdasher");
        villagenav();
        if ($listtotal > $perpage) {
            // only show multipage navs if multiple pages are used.
            addnav("Pages");
            for ($p = 0; $p < $listtotal; $p += $perpage) {
                $pnum = $p / $perpage + 1;
                if ($pnum == $page) {
                    addnav(array("`b`#Page %s`0 (%s-%s)`b", $p / $perpage + 1, $p + 1, min($p + $perpage, $listtotal)), "runmodule.php?module=haberdasher&op=listing&page={$pnum}");
                } else {
                    addnav(array("Page %s (%s-%s)", $pnum, $p + 1, min($p + $perpage, $listtotal)), "runmodule.php?module=haberdasher&op=listing&page={$pnum}");
                }
            }
        }
    } else {
        checkday();
        output("`7You step into a respectable building, and see `\$Deimos`7 hard at work on a hat, as usual.");
        $hattypes = array("rakish", "stylish", "dashing", "snazzy", "jaunty", "dapper");
        $n = array_rand($hattypes);
        $hattype = $hattypes[$n];
        output("`7He himself wears a `\$%s red hat`7, which you take to be a good sign of his skill.`n`n", $hattype);
        output("`\$Deimos`7 notices your entrance and stands and doffs his hat to you and says, \"`\$Hi, I assume you're here about a hat.");
        output("Most people who come in here are, this being a haberdashery and all.");
        output("So, what can I do for you?`7\"`n`n");
        if (get_module_pref("hatsize") < 1) {
            output("`7You currently do not have a hat.");
            addnav("Buy a Hat", "runmodule.php?module=haberdasher&op=buy");
        } else {
            output("`7You have a size `@%s `7hat.", get_module_pref("hatsize"));
            addnav("Upgrade Your Hat", "runmodule.php?module=haberdasher&op=upgrade");
        }
        addnav("L?View Deimos' Customer List", "runmodule.php?module=haberdasher&op=listing");
        villagenav();
    }
    page_footer();
}