}
             } else {
                 output("Before you can get started, you realise someone has already depleted the materials store!`n`n");
                 improbablehousing_bottomnavs($house, $rid);
                 page_footer();
                 $interrupt = true;
             }
         } else {
             //determine iitems to use, and use them - assume we're using iitems from the Main inventory
             use_item($iitem);
             if ($iitem != "toolbox_carpentry" && $iitem != "toolbox_masonry") {
                 $qleft = has_item_quantity($iitem);
                 if ($qleft == 1) {
                     $iname = get_item_setting("verbosename", $iitem);
                 } else {
                     $iname = get_item_setting("plural", $iitem);
                 }
                 if (!$qleft) {
                     $qleft = "no";
                 }
                 output("You have %s %s left.`n`n", $qleft, $iname);
             }
         }
     }
 }
 if ($interrupt) {
     break;
 }
 foreach ($actions as $action => $reps) {
     output_notl("%s`n`n", $house['data']['buildjobs'][$job]['jobs'][$subjob]['desc']);
     for ($i = 0; $i < $reps; $i++) {
function eboy_run()
{
    global $session, $inventory;
    if (!isset($inventory)) {
        load_inventory();
    }
    page_header("eBoy's Trading Station");
    addnav("Buy Items");
    addnav("Sell Items");
    require_once "modules/cityprefs/lib.php";
    $cid = get_cityprefs_cityid("location", $session['user']['location']);
    $item = httpget('item');
    if ($item) {
        $curstock = get_item_setting("eboy_stock_" . $cid, $item);
        $curprice = get_item_setting("eboy_price_" . $cid, $item);
    }
    eboy_updateprices();
    $eboy_info = get_items_with_settings("eboy");
    if (httpget('op') == "start") {
        output("Already fearing the worst, you head into eBoy's Trading Station.`n`nYour fears are well-founded.  The place is packed with the heaving, sweaty bodies of the hardcore capitalist, shouting \"`iBuy, buy!`i\" and \"`iSell, sell!`i\" and \"`iPut down the chainsaw and let's talk about this!`i\"`n`neBoy himself - although you suspect that this place, like Mike's Chop Shop, is a franchise of which you'll find one in every outpost, so is his name really eBoy?  Whoever he is, he stands on an elevated section of floor behind a tall mahogany counter, grabbing money with one hand and tossing grenades and ration packs over his shoulder with the other.  His arms are a blur.  His speech is the unintelligible, rapid-fire gabble of a professional auctioneer.  His eyes bulge and swivel.  You know he's loving this.`n`n");
    }
    if (httpget('op') == "buy") {
        $pprice = httpget('price');
        if ($pprice == $curprice) {
            if ($curstock > 0) {
                give_item($item);
                $session['user']['gold'] -= $curprice;
                increment_item_setting("eboy_stock_" . $cid, -1, $item);
                output("You fight your way to the front of the crowd and shout your order up to eBoy, slapping your Requisition tokens down on the counter.  Before you can blink, your money is gone and the item you desired sits in its place.  You grab it hastily and stuff it into your backpack as eBoy turns to deal with the next customer.`n`n");
            } else {
                output("eBoy turns to you and gibbers.`n`n\"Sorrymatejustsoldthelastoneyougottabefasteritsthequickandthedeadaroundherepal.\"  He turns to the next customer in line, leaving you trying to piece together whatever it is that he just said.`n`n");
            }
        } else {
            output("You fight your way to the front of the crowd and shout your order up to eBoy, slapping your Requisition tokens down on the counter.  eBoy turns to you and gibbers.`n`n\"Idontmeantobefunnymatebutlookattheboardthepricehasjustbloodychangedagainyousureyoustillwannabuy?\"  After giving you exactly one microsecond to consider what the hell he just asked, he rolls his eyes and turns to the next customer in line.`n`n");
        }
    }
    if (httpget('op') == "sell") {
        $pprice = httpget('price');
        $requiredprefs = array("inventorylocation" => "main");
        $itemid = has_item($item, $requiredprefs);
        if ($pprice == $curprice) {
            delete_item($itemid);
            if ($curstock < 3) {
                $buy = round($curprice * 0.5);
            } else {
                $buy = round($curprice * 0.7);
            }
            $session['user']['gold'] += $buy;
            increment_item_setting("eboy_stock_" . $cid, 1, $item);
            output("You barge your way through the crowd like a battleship through an ice floe, and toss your item up to eBoy.  eBoy snatches the item out of the air with his left hand while tossing your Requisition tokens back at you with his right, and goes on to serve the next customer.`n`n");
        } else {
            output("You fight your way to the front of the crowd and shout your order up to eBoy, slapping your Requisition tokens down on the counter.  eBoy turns to you and gibbers.`n`n\"Idontmeatobefunnymatebutlookattheboardthepricehasjustbloodychangedagainyousureyoustillwannasell?\"  After giving you exactly one microsecond to consider what the hell he just asked, he rolls his eyes and turns to the next customer in line.`n`n");
        }
    }
    output("You look up above eBoy's head at the trading board, the values of each commodity displayed on a mechanical readout which clatters and changes constantly.`n`n");
    $sellable_inventory = array();
    foreach ($inventory as $itemid => $prefs) {
        if (!$prefs['carrieritem'] && $prefs['eboy'] && $prefs['inventorylocation'] == "main") {
            $sellable_inventory[$prefs['item']]['quantity'] += 1;
            $sellable_inventory[$prefs['item']]['itemids'][] = $itemid;
        }
    }
    eboy_updateprices();
    $eboy_info = get_items_with_settings("eboy");
    //inventory-type display routine
    rawoutput("<table width=100% style='border: dotted 1px #000000;'>");
    $classcount = 1;
    foreach ($eboy_info as $item => $settings) {
        if ($settings['eboy_stock_' . $cid] > 0) {
            $stock = number_format($settings['eboy_stock_' . $cid]) . " available";
        } else {
            $stock = "`4Sold Out`0";
        }
        $classcount++;
        $class = $classcount % 2 ? "trdark" : "trlight";
        rawoutput("<tr class='{$class}'><td>");
        if ($settings['image']) {
            rawoutput("<table width=100% cellpadding=0 cellspacing=0><tr><td width=100px align=center><img src=\"images/items/" . $settings['image'] . "\"></td><td>");
        }
        output("`b%s`b`n", stripslashes($settings['verbosename']));
        output("%s`n", stripslashes($settings['description']));
        if ($settings['weight']) {
            output("Weight: %s kg`n", $settings['weight']);
        }
        rawoutput("<table width=100%><tr><td width=50%>");
        output("`bStock:`b %s", $stock);
        if ($settings['eboy_stock_' . $cid] < 3) {
            $buy = round($settings['eboy_price_' . $cid] * 0.5);
        } else {
            $buy = round($settings['eboy_price_' . $cid] * 0.7);
        }
        if ($settings['eboy_price_' . $cid] > 0) {
            output("`n`7Buying at: %s Requisition", number_format($buy));
        } else {
            output("`nNot Buying");
        }
        if ($settings['eboy_stock_' . $cid] > 0) {
            output("`n`2Selling at: %s Requisition`n`n", number_format($settings['eboy_price_' . $cid]));
        } else {
            output("`n`n");
        }
        rawoutput("</td><td width=50%>");
        $requiredprefs = array("inventorylocation" => "main");
        if ($sellable_inventory[$item]) {
            addnav("Sell Items");
            if ($settings['eboy_stock_' . $cid] < 3) {
                $buy = round($settings['eboy_price_' . $cid] * 0.5);
            } else {
                $buy = round($settings['eboy_price_' . $cid] * 0.7);
            }
            if ($sellable_inventory[$item]['quantity'] > 0 && $settings['eboy_price_' . $cid] > 0) {
                addnav(array("%s (%s available)", $settings['verbosename'], $sellable_inventory[$item]['quantity']), "runmodule.php?module=eboy&op=sell&item=" . $item . "&price=" . $settings['eboy_price_' . $cid], true);
                addnav("", "runmodule.php?module=eboy&op=sell&item=" . $item . "&price=" . $settings['eboy_price_' . $cid]);
                rawoutput("<a href=\"runmodule.php?module=eboy&op=sell&item=" . $item . "&price=" . $settings['eboy_price_' . $cid] . "\">Sell for <strong>" . number_format($buy) . " </strong> Requisition (" . $sellable_inventory[$item]['quantity'] . " available to sell)</a><br />");
            }
        } else {
            output("`&You don't have any of this item to sell.`0`n");
        }
        if ($session['user']['gold'] >= $settings['eboy_price_' . $cid] && $settings['eboy_stock_' . $cid]) {
            addnav("Buy Items");
            addnav(array("%s (%s Req)", $settings['verbosename'], $settings['eboy_price_' . $cid]), "runmodule.php?module=eboy&op=buy&item=" . $item . "&price=" . $settings['eboy_price_' . $cid], true);
            addnav("", "runmodule.php?module=eboy&op=buy&item=" . $item . "&price=" . $settings['eboy_price_' . $cid]);
            rawoutput("<a href=\"runmodule.php?module=eboy&op=buy&item=" . $item . "&price=" . $settings['eboy_price_' . $cid] . "\">Buy for <strong>" . number_format($settings['eboy_price_' . $cid]) . "</strong> Requisition</a><br />");
        } else {
            if (!$settings['eboy_stock_' . $cid]) {
                output("`&There are no items of this type available.`0`n");
            } else {
                $difference = $settings['eboy_price_' . $cid] - $session['user']['gold'];
                output("`&You need another %s Requisition to buy this item.`0`n", number_format($difference));
            }
        }
        rawoutput("</td></tr></table>");
        if ($settings['image']) {
            rawoutput("</td></tr></table>");
        }
        rawoutput("</td></tr>");
    }
    rawoutput("</td></tr></table>");
    addnav("Leave");
    addnav("Return to the Outpost", "village.php");
    addnav("Inventory");
    addnav("View your Inventory", "inventory.php?items_context=eboy");
    //set_module_objpref("city",$cid,"eboytrades-intelligent",serialize($info));
    page_footer();
    return true;
}
function luggagehut_run()
{
    global $session;
    page_header("The Luggage Hut");
    $backpackprefs = array("carrieritem" => "main");
    $backpack = get_items_with_prefs($backpackprefs, true);
    // debug($backpack);
    foreach ($backpack as $key => $prefs) {
        $currentbackpack = $prefs;
        $currentbackpackid = $key;
    }
    $bandolierprefs = array("carrieritem" => "fight");
    $bandolier = get_items_with_prefs($bandolierprefs, true);
    // debug($bandolier);
    foreach ($bandolier as $key => $prefs) {
        $currentbandolier = $prefs;
        $currentbandolierid = $key;
    }
    global $inventory;
    // debug($inventory);
    $tradein_main = round($currentbackpack['invshop_price'] * 0.6);
    $tradein_fight = round($currentbandolier['invshop_price'] * 0.6);
    switch (httpget('op')) {
        case "start":
            output("`0You head into the Luggage Hut.  A tall woman in her mid-twenties greets you.  From the dimensions of her mullet, you suspect she may be related to Sheila.`n`n\"`2Well, hey there!  Name's Sharon, nice to meet you.  Here for some new luggage?  We've got three different types of Backpacks and Bandoliers available.  Here, take a look around.  I can give you a trade-in value of %s cigarettes on your old backpack, and %s on your old bandolier.`0\"`n`nYou look around the shop a little, finding three different types of Bandoliers and Backpacks on sale:`n`n`bStandard Backpack`b`nA bog-standard backpack made from reasonably good materials.  Comfortably holds up to twenty kilos, and costs ten cigarettes.`n`n`bImproved Backpack`b`nA more well-designed backpack with extra pockets and good balance.  Holds up to forty kilos, and costs fifty cigarettes.`n`n`bAdvanced Backpack`b`nA superior-quality backpack designed by the famous B. P. BackPack, who changed his name by deed poll after working in the backpack design business for sixty years.  The man's completely bonkers, but he knows how to design a damned good backpack.  Comfortably holds up to eighty kilos, and costs one hundred cigarettes.`n`n`n`bStandard Bandolier`b`nA slightly more advanced version of the Basic bandolier given to new recruits.  Holds up to five kilos and costs ten cigarettes.`n`n`bImproved Bandolier`b`nThis leather bandolier looks cool, and has more pockets to store more things to use in fights.  Holds up to seven kilos and costs fifty cigarettes.`n`n`bAdvanced Bandolier`b`nThe Rolls-Royce of bandoliers, these things only tend to get purchased by the serious combat nut.  Holds up to ten kilos, and costs one hundred cigarettes.", $tradein_main, $tradein_fight);
            break;
        case "buy":
            $item = httpget('buy');
            if ($item == "backpack2" || $item == "backpack3" || $item == "backpack4") {
                $invloc = "main";
                $tradein = $tradein_main;
            } else {
                $invloc = "fight";
                $tradein = $tradein_fight;
            }
            $price = get_item_setting("invshop_price", $item);
            //debug($price);
            if ($price > $session['user']['gems'] + $tradein) {
                //todo
                output("Sharon shakes her head, her mullet swaying back and forth.  \"`2Sorry love - even with the trade-in, that's just not going to be enough.`0\"`n`nYou don't actually `ihave`i that many cigarettes.  Shame.");
            } else {
                $has = has_item($item);
                if ($has) {
                    output("Sharon smiles as she takes your cigarettes.  She pauses when she sees your old equipment.`n`n\"`2Uh, mate...  That's `iexactly`i the same as the one you're buying.  I'm not gonna take your cigs and then give you something that's no different to what you've already got - I'm not Sheila, you know?`0\"`n`nEmbarrassed, you nod, and take back your cigarettes.");
                } else {
                    output("Sharon smiles as you hand over your cigarettes and your old equipment.  \"`2Great stuff.  Here you go, one lovely new shiny piece of luggage!  Treat it well, now!`0\"");
                    $session['user']['gems'] += $tradein;
                    $session['user']['gems'] -= $price;
                    $price = $price - $tradein;
                    if ($invloc == "main") {
                        delete_item($currentbackpackid);
                    } else {
                        if ($invloc == "fight") {
                            delete_item($currentbandolierid);
                        }
                    }
                    give_item($item);
                    debuglog("spent " . $price . " cigarettes on " . $item . " at the Luggage Hut.");
                }
            }
            break;
    }
    addnav("Backpacks");
    addnav("Buy Standard Backpack", "runmodule.php?module=luggagehut&op=buy&buy=backpack2");
    addnav("Buy Improved Backpack", "runmodule.php?module=luggagehut&op=buy&buy=backpack3");
    addnav("Buy Advanced Backpack", "runmodule.php?module=luggagehut&op=buy&buy=backpack4");
    addnav("Bandoliers");
    addnav("Buy Standard bandolier", "runmodule.php?module=luggagehut&op=buy&buy=bandolier2");
    addnav("Buy Improved bandolier", "runmodule.php?module=luggagehut&op=buy&buy=bandolier3");
    addnav("Buy Advanced bandolier", "runmodule.php?module=luggagehut&op=buy&buy=bandolier4");
    addnav("Other");
    addnav("Back to the Outpost", "village.php");
    page_footer();
    return true;
}
output("You can drop materials directly into this Dwelling, if you like.  However, once materials have been dropped in a Dwelling, they can only be used for construction within this Dwelling.  Only the Dwelling owner (or someone with an equivalent key) can remove them from the Dwelling.  This can help prevent materials from going missing unexpectedly (or, if you prefer, being pinched by Thieving Midget Bastards or Other Unsavoury Types), and it can be a nice surprise for the Dwelling owner.`n`n");
output("Currently, this Materials Store holds:`n");
addnav("Give Materials");
foreach ($house['data']['store'] as $storeitem => $number) {
    $qty = has_item_quantity($storeitem);
    if ($qty > 0) {
        $hasitems = 1;
        addnav(array("Give a %s (you have %s)", get_item_setting("verbosename", $storeitem), $qty), "runmodule.php?module=improbablehousing&op=store&giveiitem={$storeitem}&hid={$hid}&rid={$rid}");
    }
    if ($qty > 1) {
        addnav(array("Give all your %s", get_item_setting("plural", $storeitem)), "runmodule.php?module=improbablehousing&op=store&giveiitem={$storeitem}&giveall=true&hid={$hid}&rid={$rid}");
    }
    if ($keytype >= 100) {
        if ($number > 0) {
            addnav(array("Take a %s", get_item_setting("verbosename", $storeitem)), "runmodule.php?module=improbablehousing&op=store&takeiitem={$storeitem}&hid={$hid}&rid={$rid}");
        }
        if ($number > 1) {
            addnav(array("Take all %s", get_item_setting("plural", $storeitem)), "runmodule.php?module=improbablehousing&op=store&takeiitem={$storeitem}&takeall=true&hid={$hid}&rid={$rid}");
        }
    }
    if ($number == 1) {
        output("1 %s`0`n", get_item_setting("verbosename", $storeitem));
    } else {
        output("%s %s`0`n", $number, get_item_setting("plural", $storeitem));
    }
}
if (!$hasitems) {
    addnav("You have nothing to give right now.");
}
improbablehousing_bottomnavs($house, $rid);
page_footer();
function improbablehousing_furnitureshop_run()
{
    global $session;
    page_header("Cadfael's Furniture");
    //have the beds and such allowed to be carried in backpack (insert suitable hundred-kilo-bed-in-backpack-lols) or carried by a secondary character in a new Inventory space (we'll call it Delivery Boy - will need a suitably silly photo).
    switch (httpget('op')) {
        case "start":
            output("Cadfael greets you with a preposterously strong Welsh accent.  \"`3Well hey there!  Take a look around, all one 'undred per cent natural and me own work!`0\"`n`n");
            //find items that are furniture!
            $furniture = get_items_with_settings("furniture");
            //debug($furniture);
            usort($furniture, 'sortbyprice');
            rawoutput("<table width=100% style='border: dotted 1px #000000;'>");
            foreach ($furniture as $sort => $vals) {
                $key = $vals['item'];
                $classcount += 1;
                $class = $classcount % 2 ? "trdark" : "trlight";
                rawoutput("<tr class='{$class}'><td>");
                if ($vals['image']) {
                    rawoutput("<table width=100% cellpadding=0 cellspacing=0><tr><td width=100px align=center><img src=\"images/items/" . $vals['image'] . "\"></td><td>");
                }
                output("`b%s`b`n", stripslashes($vals['verbosename']));
                output("%s`0`n", stripslashes($vals['description']));
                if ($vals['weight']) {
                    output("Weight: %s kg`n`0", $vals['weight']);
                }
                rawoutput("<table width=100%><tr><td width=50%>");
                if ($vals['goldcost'] && $vals['gemcost']) {
                    $disp = "`b" . number_format($vals['goldcost']) . "`b Requisition and `b" . number_format($vals['gemcost']) . "`b Cigarettes";
                    $sdisp = $vals['goldcost'] . " Req, " . $vals['gemcost'] . " Cigs";
                } else {
                    if ($vals['goldcost']) {
                        $disp = "`b" . number_format($vals['goldcost']) . "`b Requisition";
                        $sdisp = $vals['goldcost'] . " Req";
                    } else {
                        $disp = "`b" . number_format($vals['goldcost']) . "`b Cigarettes";
                        $sdisp = $vals['goldcost'] . " Cigs";
                    }
                }
                if ($session['user']['gold'] >= $vals['goldcost'] && $session['user']['gems'] >= $vals['gemcost']) {
                    addnav("Buy Items");
                    addnav(array("%s (%s)", $vals['verbosename'], $sdisp), "runmodule.php?module=improbablehousing_furnitureshop&op=buy&item=" . $key, true);
                    addnav("", "runmodule.php?module=improbablehousing_furnitureshop&op=buy&item=" . $key);
                    rawoutput("<a href=\"runmodule.php?module=improbablehousing_furnitureshop&op=buy&item=" . $key . "\">Buy for " . appoencode($disp) . "</a><br />");
                } else {
                    output("Price: %s`n", $disp);
                    output("`&You can't afford this item right now.`0`n");
                }
                rawoutput("</td></tr></table>");
                if ($vals['image']) {
                    rawoutput("</td></tr></table>");
                }
                rawoutput("</td></tr>");
            }
            rawoutput("</td></tr></table>");
            break;
        case "buy":
            $item = httpget("item");
            $goldcost = get_item_setting("goldcost", $item);
            $gemcost = get_item_setting("gemcost", $item);
            $name = get_item_setting("verbosename", $item);
            if ($goldcost && $gemcost) {
                $disp = "`b" . number_format($goldcost) . "`b Requisition and `b" . number_format($gemcost) . "`b Cigarettes";
            } else {
                if ($goldcost) {
                    $disp = "`b" . number_format($goldcost) . "`b Requisition";
                } else {
                    $disp = "`b" . number_format($goldcost) . "`b Cigarettes";
                }
            }
            output("Cadfael nods.  \"`3So, you're after a %s then, are ye?  That'll be %s, please.`0\"`n`n", $name, $disp);
            addnav("Confirmation");
            addnav("Confirm sale", "runmodule.php?module=improbablehousing_furnitureshop&op=confirmbuy&item=" . $item);
            addnav("Wait, I've changed my mind!", "runmodule.php?module=improbablehousing_furnitureshop&op=start");
            break;
        case "confirmbuy":
            $item = httpget("item");
            $goldcost = get_item_setting("goldcost", $item);
            $gemcost = get_item_setting("gemcost", $item);
            $name = get_item_setting("verbosename", $item);
            $session['user']['gold'] -= $goldcost;
            $session['user']['gems'] -= $gemcost;
            give_item($item);
            output("You hand over your hard-won currency to Cadfael, who grins and says \"`3Ah, much obliged!  Pleasure doin' business... with...`0\" he stops, bemused.  \"`3Are... are you trying to fit that into a `ibackpack?`i`0\"`n`nAfter several minutes of grunting and sweating, your backpack now resembles a... well, a barely-held-together layer of canvas stretched drum-tight into the shape of a %s.  With a very small %s bent double underneath.  Cadfael shakes his head and mutters something about it taking all sorts.`n`n", $name, $session['user']['race']);
            break;
        case "drop":
            page_header("");
            $itemid = httpget('item');
            debug($itemid);
            $hid = httpget('hid');
            require_once "modules/improbablehousing/lib/lib.php";
            $house = improbablehousing_gethousedata($hid);
            $rid = httpget('rid');
            $slot = httpget('slot');
            $house['data']['rooms'][$rid]['sleepslots'][$slot]['stamina'] = get_item_pref("sleepslot_stamina", $itemid);
            $house['data']['rooms'][$rid]['sleepslots'][$slot]['name'] = get_item_pref("sleepslot_name", $itemid);
            $house['data']['rooms'][$rid]['sleepslots'][$slot]['desc'] = get_item_pref("sleepslot_desc", $itemid);
            use_item($itemid);
            improbablehousing_sethousedata($house);
            addnav("Continue");
            addnav(array("Return to %s", $house['data']['rooms'][$rid]['name']), "runmodule.php?module=improbablehousing&op=interior&hid=" . $hid . "&rid=" . $rid);
            break;
    }
    if (httpget('op') != "drop") {
        addnav("Exit");
        addnav("Back to the Outpost", "village.php");
    }
    page_footer();
    return true;
}
function give_item($item, $prefs = false, $acctid = false, $skipreload = false)
{
    //To maximise performance when giving items inside a loop, set $skipreload to true and then call load_inventory() immediately afterwards.  Unless of course you don't need to set prefs for the items, in which case just use give_multiple_items instead.
    global $session, $inventory, $itemsettings;
    if (!$acctid) {
        $acctid = $session['user']['acctid'];
    }
    if (get_item_setting("unique", $item)) {
        //check for duplicate items
        $sql = "SELECT * FROM " . db_prefix("items_player") . " WHERE item = '{$item}' AND owner = '{$acctid}'";
        $result = db_query($sql);
        if (db_num_rows($result)) {
            output("`c`b`4HORRIBLE HORRIBLE ITEM SYSTEM ERROR`nSomething has gone wrong, and the item system has tried to give you an item of which you should have only one.  Like a backpack or something.  Please report this, and tell us exactly what you did!`0`b`c`n`n");
            return false;
        }
    }
    $sql = "INSERT INTO " . db_prefix("items_player") . " (item, owner) VALUES ('{$item}','{$acctid}')";
    db_query($sql);
    //get the id of the last item entered
    $key = mysql_insert_id();
    if (is_array($prefs)) {
        foreach ($prefs as $setting => $value) {
            set_item_pref($setting, $value, $key);
        }
    }
    if ($acctid == $session['user']['acctid']) {
        //saves a query over loading the inventory every time
        if (!isset($inventory) || !is_array($inventory)) {
            load_inventory();
        } else {
            if (!isset($itemsettings) || !is_array($itemsettings)) {
                load_item_settings();
            }
            $inventory[$key] = $itemsettings[$item];
        }
    }
    return $key;
}
function iitems_hunterslodge_run()
{
    global $session;
    page_header("Hunter's Lodge");
    $op = httpget('op');
    $pointsleft = $session['user']['donation'] - $session['user']['donationspent'];
    $pointstotal = $session['user']['donation'];
    $pointsspent = $session['user']['donationspent'];
    switch ($op) {
        case "superuser":
            $sql = "SELECT * FROM " . db_prefix("purchaselog");
            $result = db_query($sql);
            $peritem = array();
            $now = time();
            while ($row = db_fetch_assoc($result)) {
                $item = $row['purchased'];
                $peritem[$item]['sold'] += 1;
                $peritem[$item]['income'] += $row['amount'];
                $time = strtotime($row['timestamp']);
                if (isset($peritem[$item]['firstpurchase']) && $peritem[$item]['firstpurchase'] > $time) {
                    $peritem[$item]['firstpurchase'] = $time;
                } else {
                    if (!isset($peritem[$item]['firstpurchase'])) {
                        $peritem[$item]['firstpurchase'] = $time;
                    }
                }
            }
            foreach ($peritem as $item => $data) {
                $timesincefirst = $now - $data['firstpurchase'];
                $incomeperday = round($data['income'] / ($timesincefirst / 86400) / 100, 2);
                $peritem[$item]['incomeperday'] = $incomeperday;
                $peritem[$item]['item'] = $item;
            }
            function sortbysold($a, $b)
            {
                if ($b['sold'] > $a['sold']) {
                    return true;
                } else {
                    return false;
                }
            }
            function sortbyincome($a, $b)
            {
                if ($b['income'] > $a['income']) {
                    return true;
                } else {
                    return false;
                }
            }
            function sortbydailyincome($a, $b)
            {
                if ($b['incomeperday'] > $a['incomeperday']) {
                    return true;
                } else {
                    return false;
                }
            }
            rawoutput("<table width=100% border=0 cellpadding=0 cellspacing=0><tr class='trhead'><td>Item</td><td>Item Verbose Name</td><td><a href='runmodule.php?module=iitems_hunterslodge&op=superuser&sort=sortbysold'>Units sold</a></td><td><a href='runmodule.php?module=iitems_hunterslodge&op=superuser&sort=sortbyincome'>Profit total</a></td><td><a href='runmodule.php?module=iitems_hunterslodge&op=superuser&sort=sortbydailyincome'>Profit per day</a></td></tr>");
            $classcount = 1;
            addnav("", "runmodule.php?module=iitems_hunterslodge&op=superuser&sort=sortbysold");
            addnav("", "runmodule.php?module=iitems_hunterslodge&op=superuser&sort=sortbyincome");
            addnav("", "runmodule.php?module=iitems_hunterslodge&op=superuser&sort=sortbydailyincome");
            if (httpget('sort')) {
                usort($peritem, httpget('sort'));
            }
            foreach ($peritem as $item => $data) {
                $classcount++;
                $class = $classcount % 2 ? "trdark" : "trlight";
                $vname = get_item_setting("verbosename", $data['item']);
                if (!$vname) {
                    $vname = $data['item'];
                }
                rawoutput("<tr class='{$class}'><td>" . $data['item'] . "</td><td>" . $vname . "</td><td>" . number_format($data['sold']) . "</td><td>\$" . number_format($data['income'] / 100, 2) . "</td><td>\$" . number_format($data['incomeperday'], 2) . "</td></tr>");
            }
            rawoutput("</table>");
            addnav("Return");
            addnav("Back to the Grotto", "superuser.php");
            break;
        case "explain":
            output("You give a friendly nod to the proprietor, and open your mouth to ask him a question.`n`nHe grins back at you.`n`nThere's a small `ipop`iping sensation in the centre of your skull, like a muscle abruptly shifting - and you suddenly realise what this place is all about.`n`n`bAbout Supporter Points`b`nImprobable Island is entirely funded by donations from its players.  When you donate, you get Supporter Points, which you can use on items in the Hunter's Lodge.  You get one hundred Supporter Points per US Dollar, and donations are accepted through PayPal.  To donate, click the coin slot to the lower right of your screen.  Always use the \"Site Admin\" PayPal button when donating if you wish to receive Supporter Points (donations made through the \"Author\" button go to Eric Stevens, the author of the game engine on which Improbable Island was originally based - you don't get any Supporter Points for donating through this button).  You can also get Supporter Points by referring new players to the site (click the Referrals link to the left) or sometimes in `4Other Ways`0 which will be announced from time to time.`n`n`bTo give presents`b`nAll Hunter's Lodge items (and most other in-game items) can be given as gifts to other players.  Visit the Gifting Station in Common Ground to do so.  Some items can be gifted for free - others cost one Supporter Point each to gift.  Hunter's Lodge items that bestow permanent benefits (IE unlimited title change documents) can only be gifted if they're unused.  In all cases, you'll get to choose your gift-wrap and whether to give anonymously or not.`n`n`bHey, it's my birthday soon.  Can I ask my non-Island-playing mates to buy me points on the Island?`b`nYes!  Just send them to this link:`nhttp://www.improbableisland.com/runmodule.php?module=giftpoints&acctid=%s`n`n", $session['user']['acctid']);
            addnav("Okay");
            addnav("Back to the Hunter's Lodge", "runmodule.php?module=iitems_hunterslodge&op=start");
            addnav("Referrals", "runmodule.php?module=iitems_hunterslodge&op=referrals");
            break;
        case "referrals":
            output("If you help bring new players to Improbable Island, you'll earn one Supporter Point every time those players hit a new Game Day.  To refer players, use this address:`n`n");
            $url = getsetting("serverurl", "http://" . $_SERVER['SERVER_NAME'] . ($_SERVER['SERVER_PORT'] == 80 ? "" : ":" . $_SERVER['SERVER_PORT']) . dirname($_SERVER['REQUEST_URI']));
            if (!preg_match("/\\/\$/", $url)) {
                $url = $url . "/";
                savesetting("serverurl", $url);
            }
            output_notl("%shome.php?r=%s`n`n", $url, rawurlencode($session['user']['login']));
            $sql = "SELECT name FROM " . db_prefix("accounts") . " WHERE referer={$session['user']['acctid']} ORDER BY dragonkills,level";
            $result = db_query($sql);
            $number = db_num_rows($result);
            if ($number) {
                output("Accounts you've referred:`n");
                for ($i = 0; $i < $number; $i++) {
                    $row = db_fetch_assoc($result);
                    output_notl("%s`0`n", $row['name']);
                }
            }
            addnav("Okay");
            addnav("Back to the Hunter's Lodge", "runmodule.php?module=iitems_hunterslodge&op=start");
            break;
        case "start":
            output("You head into the Hunter's Lodge.  It's a bright, shiny place, with many expensive-looking items arranged inside glass cabinets.  The proprietor, a snappily-dressed male Joker, grins at you from behind the counter.`n`n");
            if (!has_item("lodgebag")) {
                output("The joker silently hands you a small bag, with a look that suggests you put your purchases inside.`n`n");
                give_item("lodgebag");
            }
            output("`0You have `b`5%s`0`b Supporter Points left, out of `5%s`0 accumulated in total.`n`n", number_format($pointsleft), number_format($pointstotal));
            addnav("What's all this about, then?");
            addnav("How do I get supporter points, or give presents to people?", "runmodule.php?module=iitems_hunterslodge&op=explain");
            $lodgeitems = get_items_with_settings("lodge");
            //debug($lodgeitems);
            rawoutput("<table width=100% style='border: dotted 1px #000000;'>");
            $boughtitems = array();
            $sql = "SELECT * FROM " . db_prefix("purchaselog") . " WHERE acctid = '" . $session['user']['acctid'] . "'";
            $result = db_query($sql);
            while ($row = db_fetch_assoc($result)) {
                $boughtitems[$row['purchased']] = 1;
            }
            foreach ($lodgeitems as $key => $vals) {
                if (!$vals['lodge']) {
                    continue;
                }
                $classcount += 1;
                $class = $classcount % 2 ? "trdark" : "trlight";
                rawoutput("<tr class='{$class}'><td>");
                if ($vals['image']) {
                    rawoutput("<table width=100% cellpadding=0 cellspacing=0><tr><td width=100px align=center><img src=\"images/items/" . $vals['image'] . "\"></td><td>");
                }
                output("`b%s`b`n", stripslashes($vals['verbosename']));
                output("%s`0`n", stripslashes($vals['description']));
                if ($vals['weight']) {
                    output("Weight: %s kg`n`0", $vals['weight']);
                }
                rawoutput("<table width=100%><tr><td width=50%>");
                if ($vals['tradable']) {
                    output("`5Giftable Item`0`n");
                }
                if ($vals['lodge_cost']) {
                    $disp = "`b`5" . number_format($vals['lodge_cost']) . "`0`b Supporter Points";
                    $sdisp = $vals['lodge_cost'] . " Points";
                    output("Price: %s`n", $disp);
                    if ($vals['lodge_limited']) {
                        output("`4Limited Item`0: %s available`n", $vals['lodge_stock']);
                    }
                }
                if ($vals['lodge_limited'] && $vals['lodge_stock'] > 0 || !$vals['lodge_limited']) {
                    if ($vals['lodge_singlebuy'] && $boughtitems[$key]) {
                        output("`7You've already obtained and used this item.  No need to get it again!`n");
                    } else {
                        if ($pointstotal >= $vals['lodge_freebie_threshold'] && $vals['lodge_freebie_threshold']) {
                            output("`2This item is now `bfree`b!`0`n");
                            addnav("", "runmodule.php?module=iitems_hunterslodge&op=buy&item=" . $key . "&freebie=true");
                            rawoutput("<a href=\"runmodule.php?module=iitems_hunterslodge&op=buy&item=" . $key . "&freebie=true\">Get it!</a><br />");
                        } else {
                            if ($vals['lodge_freebie_threshold']) {
                                output("`2This item becomes free once you have accumulated more than %s Supporter Points, spent or unspent.`0`n", $vals['lodge_freebie_threshold']);
                            }
                            if ($pointsleft >= $vals['lodge_cost']) {
                                addnav("Buy Items");
                                addnav(array("%s (%s)", stripslashes($vals['verbosename']), $sdisp), "runmodule.php?module=iitems_hunterslodge&op=buy&item=" . $key, true);
                                addnav("", "runmodule.php?module=iitems_hunterslodge&op=buy&item=" . $key);
                                rawoutput("<a href=\"runmodule.php?module=iitems_hunterslodge&op=buy&item=" . $key . "\">More Details / Buy for " . appoencode($disp) . "</a><br />");
                            } else {
                                output("`&You need another %s Supporter Points for this item.`0`n", number_format($vals['lodge_cost'] - $pointsleft));
                                addnav("", "runmodule.php?module=iitems_hunterslodge&op=buy&item=" . $key . "&cannotafford=1");
                                rawoutput("<a href=\"runmodule.php?module=iitems_hunterslodge&op=buy&item=" . $key . "&cannotafford=1\">More Details</a><br />");
                            }
                        }
                    }
                } else {
                    output("`&Sold out!`0`n");
                }
                rawoutput("</td></tr></table>");
                if ($vals['image']) {
                    rawoutput("</td></tr></table>");
                }
                rawoutput("</td></tr>");
            }
            rawoutput("</td></tr></table>");
            modulehook("hunterslodge");
            break;
        case "buy":
            $itemid = httpget("item");
            $item = get_item_settings($itemid);
            $free = httpget("freebie");
            $cannotafford = httpget("cannotafford");
            //debug($item);
            if ($item['lodge_longdesc']) {
                output_notl("`0%s`0`n`n", stripslashes($item['lodge_longdesc']));
            }
            if (!$cannotafford) {
                if (!$free) {
                    output("You're about to buy a %s for %s Supporter Points, leaving you with %s points available to spend afterwards.`n`n", $item['verbosename'], number_format($item['lodge_cost']), number_format($pointsleft - $item['lodge_cost']));
                    addnav("Confirm");
                    addnav(array("Buy %s for %s Points", stripslashes($item['verbosename']), $item['lodge_cost']), "runmodule.php?module=iitems_hunterslodge&op=buyconfirm&item={$itemid}");
                    addnav("No, I don't want to do that!");
                    addnav("Back to the Lodge", "runmodule.php?module=iitems_hunterslodge&op=start");
                } else {
                    redirect("runmodule.php?module=iitems_hunterslodge&op=buyconfirm&item={$itemid}&freebie=true");
                }
            } else {
                output("`0You need another %s Supporter Points to get this item.`0`n`n", number_format($item['lodge_cost'] - $pointsleft));
                addnav("Okay");
                addnav("Back to the Lodge", "runmodule.php?module=iitems_hunterslodge&op=start");
                addnav("How do I get supporter points?", "runmodule.php?module=iitems_hunterslodge&op=explain");
            }
            break;
        case "buyconfirm":
            $itemid = httpget("item");
            $iteminside = httpget("item_inside");
            $item = get_item_settings($itemid);
            $free = httpget("freebie");
            if (!$free) {
                $cost = $item['lodge_cost'];
                output("You have purchased a %s for %s Supporter Points.  You can find the item in your Inventory.  Thank you for your support!`n`n", $item['verbosename'], $item['lodge_cost']);
                give_item($itemid);
                $session['user']['donationspent'] += $item['lodge_cost'];
            } else {
                //handle freebie items
                give_item($itemid);
                output("`0You now have a %s`0!  Thank you for your support!`n`n", $item['verbosename']);
                $cost = 0;
            }
            if ($item['lodge_limited']) {
                increment_item_setting("lodge_stock", -1, $itemid);
            }
            //log purchase
            $sql = "INSERT INTO " . db_prefix("purchaselog") . " (acctid,purchased,amount,data,giftwrap,timestamp) VALUES ('" . $session['user']['acctid'] . "','" . $itemid . "','" . $cost . "','" . addslashes(serialize($item)) . "','" . $wrap . "','" . date("Y-m-d H:i:s") . "')";
            //debug($sql);
            db_query($sql);
            addnav("Yay!");
            addnav("Back to the Hunter's Lodge", "runmodule.php?module=iitems_hunterslodge&op=start");
            break;
    }
    addnav("Leave");
    addnav("Return to the Outpost", "village.php");
    addnav("Inventory");
    addnav("View your Inventory", "inventory.php?items_context=lodge");
    page_footer();
    return true;
}
function improbablehousing_furnitureshop_run()
{
    global $session;
    page_header("Cadfael's Furniture");
    //have the beds and such allowed to be carried in backpack (insert suitable hundred-kilo-bed-in-backpack-lols) or carried by a secondary character in a new Inventory space (we'll call it Delivery Boy - will need a suitably silly photo).
    switch (httpget('op')) {
        case "start":
            output("Cadfael greets you with a preposterously strong Welsh accent.  \"`3Well hey there!  Take a look around, all one 'undred per cent natural and me own work!`0\"`n`n");
            //find items that are furniture!
            $furniture = get_items_with_settings("furniture");
            //debug($furniture);
            usort($furniture, 'sortbyprice');
            rawoutput("<table width=100% style='border: dotted 1px #000000;'>");
            foreach ($furniture as $sort => $vals) {
                $key = $vals['item'];
                $classcount += 1;
                $class = $classcount % 2 ? "trdark" : "trlight";
                rawoutput("<tr class='{$class}'><td>");
                if ($vals['image']) {
                    rawoutput("<table width=100% cellpadding=0 cellspacing=0><tr><td width=100px align=center><img src=\"images/items/" . $vals['image'] . "\"></td><td>");
                }
                output("`b%s`b`n", stripslashes($vals['verbosename']));
                output("%s`0`n", stripslashes($vals['description']));
                if ($vals['weight']) {
                    output("Weight: %s kg`n`0", $vals['weight']);
                }
                rawoutput("<table width=100%><tr><td width=50%>");
                if ($vals['goldcost'] && $vals['gemcost']) {
                    $disp = "`b" . number_format($vals['goldcost']) . "`b Requisition and `b" . number_format($vals['gemcost']) . "`b Cigarettes";
                    $sdisp = $vals['goldcost'] . " Req, " . $vals['gemcost'] . " Cigs";
                } else {
                    if ($vals['goldcost']) {
                        $disp = "`b" . number_format($vals['goldcost']) . "`b Requisition";
                        $sdisp = $vals['goldcost'] . " Req";
                    } else {
                        $disp = "`b" . number_format($vals['goldcost']) . "`b Cigarettes";
                        $sdisp = $vals['goldcost'] . " Cigs";
                    }
                }
                if ($session['user']['gold'] >= $vals['goldcost'] && $session['user']['gems'] >= $vals['gemcost']) {
                    addnav("Buy Items");
                    addnav(array("%s (%s)", $vals['verbosename'], $sdisp), "runmodule.php?module=improbablehousing_furnitureshop&op=buy&item=" . $key, true);
                    addnav("", "runmodule.php?module=improbablehousing_furnitureshop&op=buy&item=" . $key);
                    rawoutput("<a href=\"runmodule.php?module=improbablehousing_furnitureshop&op=buy&item=" . $key . "\">Buy for " . appoencode($disp) . "</a><br />");
                } else {
                    output("Price: %s`n", $disp);
                    output("`&You can't afford this item right now.`0`n");
                }
                rawoutput("</td></tr></table>");
                if ($vals['image']) {
                    rawoutput("</td></tr></table>");
                }
                rawoutput("</td></tr>");
            }
            rawoutput("</td></tr></table>");
            addnav("Custom Furniture");
            addnav("Enquire about Custom Furniture", "runmodule.php?module=improbablehousing_furnitureshop&op=custom&sub=start");
            break;
        case "buy":
            $item = httpget("item");
            $goldcost = get_item_setting("goldcost", $item);
            $gemcost = get_item_setting("gemcost", $item);
            $name = get_item_setting("verbosename", $item);
            if ($goldcost && $gemcost) {
                $disp = "`b" . number_format($goldcost) . "`b Requisition and `b" . number_format($gemcost) . "`b Cigarettes";
            } else {
                if ($goldcost) {
                    $disp = "`b" . number_format($goldcost) . "`b Requisition";
                } else {
                    $disp = "`b" . number_format($goldcost) . "`b Cigarettes";
                }
            }
            output("Cadfael nods.  \"`3So, you're after a %s then, are ye?  That'll be %s, please.`0\"`n`n", $name, $disp);
            addnav("Confirmation");
            addnav("Confirm sale", "runmodule.php?module=improbablehousing_furnitureshop&op=confirmbuy&item=" . $item);
            addnav("Wait, I've changed my mind!", "runmodule.php?module=improbablehousing_furnitureshop&op=start");
            break;
        case "confirmbuy":
            $item = httpget("item");
            $goldcost = get_item_setting("goldcost", $item);
            $gemcost = get_item_setting("gemcost", $item);
            $name = get_item_setting("verbosename", $item);
            $session['user']['gold'] -= $goldcost;
            $session['user']['gems'] -= $gemcost;
            give_item($item);
            output("You hand over your hard-won currency to Cadfael, who grins and says \"`3Ah, much obliged!  Pleasure doin' business... with...`0\" he stops, bemused.  \"`3Are... are you trying to fit that into a `ibackpack?`i`0\"`n`nAfter several minutes of grunting and sweating, your backpack now resembles a... well, a barely-held-together layer of canvas stretched drum-tight into the shape of a %s.  With a very small %s bent double underneath.  Cadfael shakes his head and mutters something about it taking all sorts.`n`n", $name, $session['user']['race']);
            break;
        case "drop":
            page_header("");
            $itemid = httpget('item');
            debug($itemid);
            $hid = httpget('hid');
            require_once "modules/improbablehousing/lib/lib.php";
            $house = improbablehousing_gethousedata($hid);
            $rid = httpget('rid');
            $slot = httpget('slot');
            $house['data']['rooms'][$rid]['sleepslots'][$slot]['stamina'] = get_item_pref("sleepslot_stamina", $itemid);
            $house['data']['rooms'][$rid]['sleepslots'][$slot]['name'] = get_item_pref("sleepslot_name", $itemid);
            $house['data']['rooms'][$rid]['sleepslots'][$slot]['desc'] = get_item_pref("sleepslot_desc", $itemid);
            $house['data']['rooms'][$rid]['sleepslots'][$slot]['multicapacity'] = get_item_pref("sleepslot_multicapacity", $itemid);
            use_item($itemid);
            improbablehousing_sethousedata($house);
            addnav("Continue");
            addnav(array("Return to %s", $house['data']['rooms'][$rid]['name']), "runmodule.php?module=improbablehousing&op=interior&hid=" . $hid . "&rid=" . $rid);
            break;
        case "custom":
            $sub = httpget('sub');
            switch ($sub) {
                case "start":
                    output("\"`3Oh yeah, I get lots of custom orders,`0\" says Cadfael, grinning.  \"`3Mostly for Mutants and Robots.  Interestin' stuff, really, tryin' to figure out where all the extra arms and legs would go.  I can make any of my furniture pieces look like just about anythin'.  Custom work'll set ye back five ciggies as a startin' price, an' goes up from there according to complexity.  You got somethin' in mind?`0\"`n`n`JCadfael can take any piece of furniture intended for sleeping on and assign a new name and description to the sleeping slot that it'll take up.  If you want your houseguests to be able to sleep on top of a bookcase, or inside a cleverly-concealed secret foldaway bed, or in a zero-gravity chamber (yes, Cadfael's carpentry skills are `ijust that good`i), then bring one of his furniture pieces here.`0`n`n");
                    $furniture = get_items_with_prefs("furniture");
                    if (is_array($furniture)) {
                        addnav("Customize Furniture");
                        foreach ($furniture as $key => $vals) {
                            addnav(array("Customize %s", $vals['verbosename']), "runmodule.php?module=improbablehousing_furnitureshop&op=custom&sub=desc&item=" . $key);
                        }
                    }
                    addnav("Return");
                    addnav("Back to the Furniture List", "runmodule.php?module=improbablehousing_furnitureshop&op=start");
                    break;
                case "desc":
                    //get the descriptions from the player
                    $item = httpget('item');
                    output("\"`3Right, then - what'll this be called?`0\"`n`n`0Enter a title for the furniture piece here.  This is what's displayed in the nav links in your Dwelling - it'll read something like \"(your title) Available\" or \"(your title) Occupied by Admin CavemanJoe\" - you've got 25 characters to play about with, and no colour or formatting codes are allowed here.`n`n");
                    $oldtitle = get_item_pref("sleepslot_name", $item);
                    $olddesc = get_item_pref("sleepslot_desc", $item);
                    rawoutput("<form action='runmodule.php?module=improbablehousing_furnitureshop&op=custom&sub=confirm&item=" . $item . "' method='POST'>");
                    rawoutput("<input id='newtitle' name='newtitle' width='25' maxlength='25' value='" . $oldtitle . "'>");
                    output("`n`nNow enter a description for the new furniture piece.  This is what's displayed to players when they settle down for a good night's kip.  The longer the description, the more it'll cost.  You can use colour and formatting codes here - remember to use ``n for new lines.`n`n");
                    rawoutput("<textarea name='newdesc' id='newdesc' rows='6' cols='60'>" . $olddesc . "</textarea><input type=submit></form>");
                    addnav("Return");
                    addnav("Back to the Furniture List", "runmodule.php?module=improbablehousing_furnitureshop&op=start");
                    addnav("", "runmodule.php?module=improbablehousing_furnitureshop&op=custom&sub=confirm&item=" . $item);
                    break;
                case "confirm":
                    $newtitle = httppost('newtitle');
                    $newdesc = httppost('newdesc');
                    $item = httpget('item');
                    $newdesc = str_replace("\n", "`n", $newdesc);
                    $newtitle = str_replace("`", "", $newtitle);
                    $newtitle = substr($newtitle, 0, 25);
                    $newtitle = stripslashes($newtitle);
                    $newdesc = stripslashes($newdesc);
                    //show the descriptions
                    output("Your new title is:`n%s`0`n`nYour new description is:`n%s`0`n`n", $newtitle, $newdesc);
                    $cigcost = 5 + floor(strlen($newdesc) / 50);
                    output("This much work will cost %s cigarettes.`n`n", $cigcost);
                    set_item_pref("proposed_sleepslot_name", $newtitle, $item);
                    set_item_pref("proposed_sleepslot_desc", $newdesc, $item);
                    if ($session['user']['gems'] >= $cigcost) {
                        addnav("Continue");
                        addnav("Pay the man!", "runmodule.php?module=improbablehousing_furnitureshop&op=custom&sub=confirmfinal&item=" . $item . "&cost=" . $cigcost);
                    } else {
                        output("You don't have enough cigarettes for that!`n`n");
                    }
                    addnav("Return");
                    addnav("Back to the Furniture List", "runmodule.php?module=improbablehousing_furnitureshop&op=start");
                    break;
                case "confirmfinal":
                    //take the cigaretes, change the prefs
                    $item = httpget('item');
                    $cost = httpget('cost');
                    $session['user']['gems'] -= $cost;
                    output("Cadfael takes your cigarettes and furniture with a smile, and disappears into the back of the shop.  You hear muffled sounds of sawing, hammering, swearing and so forth, and after half an hour or so he returns.  \"`3Here you go - might not look much different `inow,`i but wait 'til you get it in yer house.`0\"`n`nYour furniture is now customized!");
                    $newtitle = get_item_pref("proposed_sleepslot_name", $item);
                    $newdesc = get_item_pref("proposed_sleepslot_desc", $item);
                    set_item_pref("verbosename", "Customized Furniture (" . $newtitle . ")", $item);
                    set_item_pref("sleepslot_name", $newtitle, $item);
                    set_item_pref("sleepslot_desc", $newdesc, $item);
                    set_item_pref("description", "This furniture was modified at Cadfael's shop in Improbable Central.", $item);
                    addnav("Return");
                    addnav("Back to the Furniture List", "runmodule.php?module=improbablehousing_furnitureshop&op=start");
                    break;
            }
            break;
    }
    if (httpget('op') != "drop") {
        addnav("Exit");
        addnav("Back to the Outpost", "village.php");
    }
    page_footer();
    return true;
}