$stackedrooms += 1;
                        }
                    }
                }
            }
        }
        if ($stackedrooms) {
            if ($stackedrooms == 1) {
                output("`c`b`\$Careful!`0`b`nYou've already set up a build job to create a new room branching from this one!  If you add a new build job, then you and your friends will be able to perform this new room creation once the current room size creation is finished.  In other words, you can have multiple build jobs queued up per room, but you can only add materials to them sequentially.`c`n`n");
            } else {
                output("`c`b`\$Careful!`0`b`nYou've already set up a build job to create %s new rooms branching from this one!  If you add a further build job, then you and your friends will have to complete the new rooms in sequence.`c`n`n", $stackedrooms);
            }
        }
        addnav("Confirm");
        addnav("Yeah, do it!", "runmodule.php?module=improbablehousing&op=buildjobs&sub=newroom-confirm&hid={$hid}&rid={$rid}");
        break;
    case "increasesize-confirm":
        output("You've started a new build job to increase the size of this room!`n`n");
        $newjob = array("name" => "Room Size Increase (" . $house['data']['rooms'][$rid]['name'] . "`0)", "jobs" => array(0 => array("name" => "Add wood", "iitems" => array("wood" => 1, "toolbox_carpentry" => 1), "actions" => array("Carpentry" => 1), "req" => 20, "done" => 0, "desc" => "You set about hammering and sawing.  Before too long, the room expansion is one step closer to completion."), 1 => array("name" => "Add stone", "iitems" => array("stone" => 1, "toolbox_masonry" => 1), "actions" => array("Masonry" => 1), "req" => 5, "done" => 0, "desc" => "You set about chiseling and tinkering.  Before too long, the room expansion is one step closer to completion.")), "completioneffects" => array("rooms" => array($rid => array("deltas" => array("size" => 1), "newsleepslots" => array(0 => array("name" => "Floor space", "stamina" => 50000, "desc" => "You settle down for a good night's kip on the floor.")))), "msg" => "The room expansion is now complete!"));
        $house['data']['buildjobs'][] = $newjob;
        improbablehousing_sethousedata($house);
        break;
    case "newroom-confirm":
        output("You've started a new build job to create a new room.  Have at it!`n`n");
        $newjob = array("name" => "New Room Construction (extension from " . $house['data']['rooms'][$rid]['name'] . "`0)", "jobs" => array(0 => array("name" => "Add wood", "iitems" => array("wood" => 1, "toolbox_carpentry" => 1), "actions" => array("Carpentry" => 1), "req" => 70, "done" => 0, "desc" => "You set about hammering and sawing.  Before too long, the new room is one step closer to completion."), 1 => array("name" => "Add stone", "iitems" => array("stone" => 1, "toolbox_masonry" => 1), "actions" => array("Masonry" => 1), "req" => 20, "done" => 0, "desc" => "You set about chiseling and tinkering.  Before too long, the new room is one step closer to completion.")), "completioneffects" => array("newrooms" => array(0 => array("name" => "Extension", "size" => 1, "enterfrom" => $rid, "desc" => "You're standing in a small, undecorated extension room.", "sleepslots" => array())), "msg" => "The new room is now complete!"));
        $house['data']['buildjobs'][] = $newjob;
        improbablehousing_sethousedata($house);
        break;
}
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 rail_ironhorse_cleanup($hid)
{
    // code here is copied from exit.php in improbablehousing/run.
    // the train extracts the player from the station dwelling
    //   so we need to remove all traces that they were there.
    global $session;
    $house = improbablehousing_gethousedata($hid);
    // Run through the rooms and make sure the player isn't registered as
    // being in them or sleeping in them
    foreach ($house['data']['rooms'] as $rkey => $rvals) {
        if (isset($rvals['sleepslots'])) {
            foreach ($rvals['sleepslots'] as $skey => $svals) {
                if ($svals['occupier'] == $session['user']['acctid']) {
                    unset($house['data']['rooms'][$rkey]['sleepslots'][$skey]['occupier']);
                }
            }
        }
        if (isset($rvals['occupants'])) {
            foreach ($rvals['occupants'] as $okey => $ovals) {
                //				output("`0Occupant %s: %s`0`n",$okey,$house['data']['rooms'][$rkey]['occupants'][$okey]);
                //				output("okey..%s, acctid..%s`n",$okey,$session['user']['acctid']);
                if ($okey == $session['user']['acctid']) {
                    //					output("- unset`n");
                    unset($house['data']['rooms'][$rkey]['occupants'][$okey]);
                }
            }
        }
    }
    improbablehousing_sethousedata($house);
    clear_module_pref("sleepingat", "improbablehousing");
    return true;
}
function improbablehousing_secretrooms_run()
{
    global $session;
    page_header("Secret Rooms");
    require_once "modules/improbablehousing/lib/lib.php";
    $hid = httpget("hid");
    $rid = httpget("rid");
    $house = improbablehousing_gethousedata($hid);
    $cost = get_module_setting("cost");
    $roomname = $house['data']['rooms'][$rid]['name'];
    switch (httpget('op')) {
        case "start":
            output("`5Secret Rooms`0 are rooms that exist in your Dwelling and operate just like normal rooms - except that there's no nav link for players to reach them by.  Instead, a player will be instantly transported from the current room to your `5Secret Room`0 by typing a key phrase into their chat box (the phrase itself won't show up in the chat log - it'd be pretty hard to keep it secret otherwise!).`n`nYou as the secret room owner can assign as many key phrases per room as you would like.  For example, you might assign the key phrases \"`#EXAMINE BOOKCASE`0\", \"`&LOOK BEHIND BOOKCASE`0\", and perhaps a few others, to have the player discover a traditional secret passage.  Or, you could assign the phrase \"`#OPEN SESAME`0\" to reveal a cleverly-hidden door.`n`nIn all other aspects, `5Secret Rooms`0 operate exactly like normal rooms - they can be extended, decorated, and can have more rooms branch from them (including other `5Secret Rooms`0).  They can even be locked just like normal rooms - if a player tries to enter a locked `5Secret Room`0 to which he or she doesn't have access, they'll get bounced straight back as usual.`n`n`5Secret Rooms`0 are a donator-only feature, cost %s Donator Points per room, and come pre-assembled.  No construction materials are necessary; `5Secret Rooms`0 arrive ready to decorate.`n`nYou're currently building a `5Secret Room`0 that can be accessed from the room called \"`b%s`b`0\" - are you sure that this is the room you want to build from?`n`n", $cost, $roomname);
            addnav("Want a Secret Room?");
            $donationavailable = $session['user']['donation'] - $session['user']['donationspent'];
            if ($donationavailable >= $cost) {
                addnav(array("Yes, build a Secret Room branching from this one (%s Points)", $cost), "runmodule.php?module=improbablehousing_secretrooms&op=buy&hid={$hid}&rid={$rid}");
            } else {
                addnav("Ah, but you don't have enough points!", "");
            }
            addnav("Cancel and return to the last room", "runmodule.php?module=improbablehousing&op=interior&hid={$hid}&rid={$rid}");
            break;
        case "buy":
            $session['user']['donationspent'] += $cost;
            output("You've bought a `5Secret Room!`0  To enter it, just type \"`#SECRET`0\" into the chat box in the room called \"%s\" (you can delete this trigger phrase and set up some new ones once you're inside the secret room).`n`nHave fun!`n`n", $roomname);
            $newroom = array("name" => "Secret Room", "size" => 1, "enterfrom" => $rid, "desc" => "You're standing in a small, undecorated secret room.", "sleepslots" => array(), "hidden" => 1, "triggers" => array(0 => "SECRET"), "lockreject" => "You do all the right things, but you still can't get in.  Maybe the room is locked?");
            $house['data']['rooms'][] = $newroom;
            improbablehousing_sethousedata($house);
            addnav("Let's get busy!");
            addnav("Back to your Dwelling", "runmodule.php?module=improbablehousing&op=interior&hid={$hid}&rid={$rid}");
            break;
        case "manage":
            if (httpget("save")) {
                $posted = httpallpost();
                $nphrases = array();
                foreach ($posted as $phrase) {
                    $nphrase = stripslashes($phrase);
                    if ($nphrase != "") {
                        $nphrases[] = strtoupper($nphrase);
                    }
                }
                $house['data']['rooms'][$rid]['triggers'] = $nphrases;
                improbablehousing_sethousedata($house);
            }
            $phrases = $house['data']['rooms'][$rid]['triggers'];
            output("You're currently managing the secret room called \"`b%s`b.`0\"  You can set this room's trigger phrases and lock rejection notices below.`n`nRemember, the text that the player inputs must be an exact match.  There's no extra charge for adding more trigger phrases, so more is often better.`n`nTo erase a trigger phrase, just blank the box.`n`n", $roomname);
            rawoutput("<form action='runmodule.php?module=improbablehousing_secretrooms&op=manage&save=true&hid={$hid}&rid={$rid}' method='POST'>");
            rawoutput("<table border='0' cellpadding='2' cellspacing='2'>");
            $phrasecount = 0;
            foreach ($phrases as $phrase) {
                $class = $phrasecount % 2 ? "trlight" : "trdark";
                $phrasecount++;
                rawoutput("<tr class='{$class}'><td><input name=\"phrase{$phrasecount}\" value=\"{$phrase}\"></td></tr>");
            }
            rawoutput("</table>");
            output("`nNow add up to ten new phrases.  Boxes left blank will be ignored.  To add more, just save and you'll get another ten slots.");
            $extracount = $phrasecount + 10;
            rawoutput("<table border='0' cellpadding='2' cellspacing='2'>");
            for ($i = $phrasecount; $i <= $extracount; $i++) {
                $class = $phrasecount % 2 ? "trlight" : "trdark";
                $phrasecount++;
                rawoutput("<tr class='{$class}'><td><input name=\"phrase{$phrasecount}\" value=''></td></tr>");
            }
            rawoutput("</table>");
            rawoutput("<input type='submit' class='button' value='" . translate_inline("Save") . "'");
            rawoutput("</form>");
            addnav("", "runmodule.php?module=improbablehousing_secretrooms&op=manage&save=true&hid={$hid}&rid={$rid}");
            addnav("Return");
            addnav("Back to the Dwelling", "runmodule.php?module=improbablehousing&op=interior&hid={$hid}&rid={$rid}");
            break;
    }
    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;
}