function hunterslodge_customtitle_run()
{
    require_once "lib/sanitize.php";
    require_once "lib/names.php";
    global $session;
    $op = httpget("op");
    $free = httpget("free");
    page_header("Choose your Custom Title");
    switch ($op) {
        case "change":
            output("Ready to change your Title?  No problem.  Enter your desired Title in the box below.  You've got 25 characters to play with, including colour codes.`n`n");
            titlechange_form();
            addnav("Cancel");
            addnav("Don't change colours, just go back to the Lodge", "runmodule.php?module=iitems_hunterslodge&op=start");
            break;
        case "confirm":
            $ntitle = rawurldecode(httppost('newname'));
            $ntitle = newline_sanitize($ntitle);
            if ($ntitle == "") {
                $ntitle = "`0";
            }
            $ntitle = preg_replace("/[`][cHw]/", "", $ntitle);
            $ntitle = sanitize_html($ntitle);
            $nname = get_player_basename();
            output("`0Your new title will look like this: %s`0`n", $ntitle);
            output("`0Your entire name will look like: %s %s`0`n`n", $ntitle, $nname);
            output("Do you want to set the new title now?`n`n");
            output("`0Try a different title below, if you like.`n`n");
            titlechange_form();
            addnav("Confirm");
            addnav("Set the new Title", "runmodule.php?module=hunterslodge_customtitle&op=set&free={$free}&newname=" . rawurlencode($ntitle));
            addnav("Cancel");
            addnav("Don't change your Title, just go back to the Lodge", "runmodule.php?module=iitems_hunterslodge&op=start");
            break;
        case "set":
            $ntitle = rawurldecode(httpget('newname'));
            $fromname = $session['user']['name'];
            $newname = change_player_ctitle($ntitle);
            $session['user']['ctitle'] = $ntitle;
            $session['user']['name'] = $newname;
            output("You are now known as %s!`0`n`n", $session['user']['name']);
            if (!$free) {
                $id = has_item("hunterslodge_customtitle");
                delete_item($id);
            }
            addnav("Return");
            addnav("Return to the Lodge", "runmodule.php?module=iitems_hunterslodge&op=start");
            break;
    }
    page_footer();
}
function titlechange_run()
{
    require_once "lib/sanitize.php";
    require_once "lib/names.php";
    global $session;
    $op = httpget("op");
    page_header("Hunter's Lodge");
    $pointsavailable = $session['user']['donation'] - $session['user']['donationspent'];
    $permcost = get_module_setting("permanent");
    if ($op == "permanent") {
        page_header("Unlimited Title Changes");
        output("For %s Donator Points, you can change your Title as often as you like without paying again.`n`n", $permcost);
        addnav("Unlimited Changes");
        if ($pointsavailable >= $permcost) {
            addnav(array("Get permanent free Title changes (%s Points)", $permcost), "runmodule.php?module=titlechange&op=permanentconfirm");
        } else {
            addnav(array("Sorry, but you need %s more Donator Points for this option.", $permcost - $pointsavailable), "");
        }
        addnav("Cancel", "lodge.php");
        page_footer();
    }
    if ($op == "permanentconfirm") {
        page_header("Unlimited Title Changes");
        output("You've got unlimited Title Changes!");
        addnav("Back to the Lodge", "lodge.php");
        set_module_pref("permanent", 1);
        $session['user']['donationspent'] += $permcost;
        page_footer();
    }
    if ($op == "titlechange") {
        if (get_module_pref("timespurchased")) {
            $cost = get_module_setting("extrapoints");
        } else {
            $cost = get_module_setting("initialpoints");
        }
        if (get_module_pref("permanent")) {
            $cost = 0;
        }
        if ($cost <= $session['user']['donation'] - $session['user']['donationspent']) {
            output("`3`bCustomize Title`b`0`n`n");
            output("`7Because you have earned sufficient points, you have been granted the ability to set a custom title of your choosing.");
            output("The title must be appropriate, and the admin of the game can reset if it isn't (as well as penalize you for abusing the game).");
            output("The title may not be more than 25 characters long including any characters used for colorization!.`n`n");
            $otitle = get_player_title();
            if ($otitle == "`0") {
                $otitle = "";
            }
            output("`7Your title is currently`^ ");
            rawoutput($otitle);
            output_notl("`0`n");
            output("`7which looks like %s`n`n", $otitle);
            if (httpget("err") == 1) {
                output("`\$Please enter a title.`n");
            }
            output("`7How would you like your title to look?`n");
            rawoutput("<form action='runmodule.php?module=titlechange&op=titlepreview' method='POST'>");
            rawoutput("<input id='input' name='newname' width='25' maxlength='25' value='" . htmlentities($otitle, ENT_COMPAT, getsetting("charset", "ISO-8859-1")) . "'>");
            rawoutput("<input type='submit' class='button' value='Preview'>");
            rawoutput("</form>");
            addnav("", "runmodule.php?module=titlechange&op=titlepreview");
        } else {
            output("Sorry, but you don't have enough points to do that!`n`n");
        }
    } elseif ($op == "titlepreview") {
        $ntitle = rawurldecode(httppost('newname'));
        $ntitle = newline_sanitize($ntitle);
        if ($ntitle == "") {
            if (get_module_setting("blank")) {
                $ntitle = "`0";
            } else {
                redirect("runmodule.php?module=titlechange&op=titlechange&err=1");
            }
        }
        if (!get_module_setting("bold")) {
            $ntitle = str_replace("`b", "", $ntitle);
        }
        if (!get_module_setting("italics")) {
            $ntitle = str_replace("`i", "", $ntitle);
        }
        $ntitle = sanitize_colorname(get_module_setting("spaceinname"), $ntitle);
        $ntitle = preg_replace("/[`][cHw]/", "", $ntitle);
        $ntitle = sanitize_html($ntitle);
        $nname = get_player_basename();
        output("`7Your new title will look like this: %s`0`n", $ntitle);
        output("`7Your entire name will look like: %s %s`0`n`n", $ntitle, $nname);
        output("`7Is this how you wish it to look?");
        addnav("`bConfirm Custom Title`b");
        addnav("Yes", "runmodule.php?module=titlechange&op=changetitle&newname=" . rawurlencode($ntitle));
        addnav("No", "runmodule.php?module=titlechange&op=titlechange");
    } elseif ($op == "changetitle") {
        $ntitle = rawurldecode(httpget('newname'));
        $fromname = $session['user']['name'];
        $newname = change_player_ctitle($ntitle);
        $session['user']['ctitle'] = $ntitle;
        $session['user']['name'] = $newname;
        addnews("%s`^ has become known as %s.", $fromname, $session['user']['name']);
        // modifications by sixf00t4
        if (!get_module_pref("permanent")) {
            if (get_module_setting("take")) {
                $cost = 0;
                if (get_module_pref("timespurchased")) {
                    $cost = get_module_setting("extrapoints");
                    debuglog("bought another custom title for {$cost} points");
                } else {
                    $cost = get_module_setting("initialpoints");
                    debuglog("bought first custom title for {$cost} points");
                }
                $session['user']['donationspent'] += $cost;
            }
        }
        set_module_pref("timespurchased", get_module_pref("timespurchased") + 1);
        output("Your custom title has been set.");
        modulehook("namechange", array());
    }
    addnav("L?Return to the Lodge", "lodge.php");
    page_footer();
}