function drpap_run()
{
    global $session;
    $c = get_module_pref("count");
    // if ($c){
    // if (is_module_active("medals")){
    // require_once "modules/medals.php";
    // medals_award_medal("sexchange","Gender Reassignment","This player switched their gender at Doc Paprika's office!","medal_museumquest.png");
    // }
    // }
    $t = get_module_setting("times");
    $gold = get_module_setting("gold");
    $gems = get_module_setting("gems");
    $op = httpget('op');
    $dec = httpget('dec');
    $gen = translate_inline($session['user']['sex'] == 0 ? "sir" : "madam");
    $ngen = translate_inline($session['user']['sex'] == 1 ? "sir" : "madam");
    $g = translate_inline($gems == 1 ? "Gem" : "Gems");
    page_header("Dr Paprika's Office");
    switch ($op) {
        case "enter":
            if ($c < $t) {
                output("`3Subtle tunes play in the background; classic rock.");
                output("In the Center of the waiting room, is a large table - covered with out-of-date magazines.");
                output("A beautiful receptionist looks at you, across a pane of glass.");
                output("She glances at you, and waves, \"`%Hello there %s.", $gen);
                output("Are you here to see `QDr Paprika`%?");
                output("He is the only doctor in %s, excelling in the field of `\$Gender Changes`%.`3\"", get_module_setting("paploc"));
                addnav("Where to?");
                addnav("Dr Paprika's Room", "runmodule.php?module=drpap&op=office");
                addnav("Waiting Room", "runmodule.php?module=drpap&op=waitroom");
            } else {
                output("`3\"`%I am sorry %s, but you have already had %s `\$Gender Changes`%.", $gen, $c);
                output("Since the limit is %s, we are able to deny you service now.", $t);
                output("Please take care.`3\"");
                if (get_module_setting("reset") == 1) {
                    output("`3The receptionist adds, \"`%If you come back with some `@dragon's blood`%, we might be able to work something out.`3\"");
                }
            }
            break;
        case "office":
            if ($dec != "yes") {
                if ($session['user']['gold'] >= $gold && $session['user']['gems'] >= $gems) {
                    output("`3You walk in a white room, very white.");
                    output("A long operating table, is accompanied by a small swivel chair.");
                    output("Strutting out from the shadows, `QDr Paprika `3appears, and shakes your hand.");
                    output("\"`\$So, you wish to have a `%Gender Change `\$operation?`3\"");
                    addnav("Choices");
                    addnav("Yes", "runmodule.php?module=drpap&op=office&dec=yes");
                    addnav("Return to the Waiting Room", "runmodule.php?module=drpap&op=waitroom");
                } else {
                    output("`QDr Paprika `3stares at your blankly.");
                    output("\"`\$I am sorry %s, but you do not have the proper funds for this operation.`3\"", $gen);
                    output("`QDr Paprika `3points to a sign, stating \"`%Gender Operations cost `^%s `%Gold and `5%s `%%s.`3\"", $gold, $gems, $g);
                }
            } else {
                output("`QDr Paprika `3nods and begins to prep himself.");
                output("\"`\$Please lay down on the operating table... I will be with your shortly...`3\"");
                output("`QDr Paprika `3hovers over you and then pulls out a tiny bottle of ether.");
                output("He presses it to your nose and instructs, \"`\$Please count to One Hundred...`3\"");
                output("You begin to count...`n`n");
                for ($i = 1; $i <= $session['user']['level']; $i++) {
                    output("%s...`n", $i);
                }
                if ($session['user']['sex'] == 0) {
                    $session['user']['sex'] = 1;
                } else {
                    $session['user']['sex'] = 0;
                }
                $c++;
                set_module_pref("count", $c);
                $session['user']['gold'] -= $gold;
                $session['user']['gems'] -= $gems;
                require_once "lib/titles.php";
                $newtitle = get_dk_title($session['user']['dragonkills'], $session['user']['sex']);
                require_once "lib/names.php";
                $newname = change_player_title($newtitle);
                $session['user']['title'] = $newtitle;
                $session['user']['name'] = $newname;
                output("`nYou awaken hours later, your muscles shuddering.");
                output("You grasp the mirror to your side, and then look at yourself.");
                output("Surprisingly, you are now a healthy looking %s.", $ngen);
                output("You stand quickly, and shake `QDr Paprika's `3hand, thanking him profusely.");
                output("Taking up your clothes, you strut out from the office, smiling happily.");
            }
            break;
        case "waitroom":
            output("`3All around you, people are sitting.");
            output("Some are thumbing through magazines, whilst others are tapping their feet in anticipation.`n`n");
            require_once "lib/commentary.php";
            addcommentary();
            viewcommentary("drpap", "Nervous People are Around", 15, "says");
            addnav("Return to Lobby", "runmodule.php?module=drpap&op=enter");
            break;
    }
    addnav("Leave");
    villagenav();
    page_footer();
}
 $session['user']['gold'] = $restartgold;
 $session['user']['gems'] += $restartgems;
 if ($flawless) {
     $session['user']['gold'] += 3 * getsetting("newplayerstartgold", 50);
     $session['user']['gems'] += 1;
 }
 $session['user']['maxhitpoints'] = 10 + $hpgain['dkpoints'] + $hpgain['extra'];
 $session['user']['hitpoints'] = $session['user']['maxhitpoints'];
 // Sanity check
 if ($session['user']['maxhitpoints'] < 1) {
     // Yes, this is a freaking hack.
     die("ACK!! Somehow this user would end up perma-dead.. Not allowing DK to proceed!  Notify admin and figure out why this would happen so that it can be fixed before DK can continue.");
     exit;
 }
 // Set the new title.
 $newname = change_player_title($newtitle);
 $session['user']['title'] = $newtitle;
 $session['user']['name'] = $newname;
 reset($session['user']['dragonpoints']);
 while (list($key, $val) = each($session['user']['dragonpoints'])) {
     if ($val == "at") {
         $session['user']['attack']++;
     }
     if ($val == "de") {
         $session['user']['defense']++;
     }
 }
 $session['user']['laston'] = date("Y-m-d H:i:s", strtotime("-1 day"));
 $session['user']['slaydragon'] = 1;
 $companions = array();
 $session['user']['companions'] = array();
     $oldvalues['name'] = $newname;
     if ($session['user']['acctid'] == $userid) {
         $session['user']['name'] = $newname;
     }
 } elseif ($key == "title" && stripslashes($val) != $oldvalues[$key]) {
     $updates++;
     $tmp = sanitize_colorname(true, stripslashes($val), true);
     $tmp = preg_replace("/[`][cHw]/", "", $tmp);
     $tmp = sanitize_html($tmp);
     if ($tmp != stripslashes($val)) {
         output("`\$Illegal characters removed from player title!`0`n");
     }
     if (soap($tmp) != $tmp) {
         output("`^The new title doesn't pass the bad word filter!`0");
     }
     $newname = change_player_title($tmp, $oldvalues);
     $sql .= "{$key} = \"{$val}\",";
     output("Changed player title from %s`0 to %s`0`n", $oldvalues['title'], $tmp);
     $oldvalues[$key] = $tmp;
     if ($newname != $oldvalues['name']) {
         $sql .= "name = \"" . addslashes($newname) . "\",";
         output("Changed player name to %s`0 due to changed dragonkill title`n", $newname);
         debuglog($session['user']['name'] . "`0 changed player name to {$newname}`0 due to changed dragonkill title", $userid);
         $oldvalues['name'] = $newname;
         if ($session['user']['acctid'] == $userid) {
             $session['user']['name'] = $newname;
         }
     }
     if ($session['user']['acctid'] == $userid) {
         $session['user']['title'] = $tmp;
     }
 require_once "lib/titles.php";
 require_once "lib/names.php";
 output("`^Rebuilding all titles.`0`n`n");
 $sql = "SELECT name,title,dragonkills,acctid,sex,ctitle FROM " . db_prefix("accounts");
 $result = db_query($sql);
 $number = db_num_rows($result);
 for ($i = 0; $i < $number; $i++) {
     $row = db_fetch_assoc($result);
     $oname = $row['name'];
     $dk = $row['dragonkills'];
     $otitle = $row['title'];
     $dk = (int) $row['dragonkills'];
     if (!valid_dk_title($otitle, $dk, $row['sex'])) {
         $sex = translate_inline($row['sex'] ? "female" : "male");
         $newtitle = get_dk_title($dk, (int) $row['sex']);
         $newname = change_player_title($newtitle, $row);
         $id = $row['acctid'];
         if ($oname != $newname) {
             output("`@Changing `^%s`@ to `^%s `@(%s`@ [%s,%s])`n", $oname, $newname, $newtitle, $dk, $sex);
             if ($session['user']['acctid'] == $row['acctid']) {
                 $session['user']['title'] = $newtitle;
                 $session['user']['name'] = $newname;
             } else {
                 $sql = "UPDATE " . db_prefix("accounts") . " SET name='" . addslashes($newname) . "', title='" . addslashes($newtitle) . "' WHERE acctid='{$id}'";
                 db_query($sql);
             }
         } elseif ($otitle != $newtitle) {
             output("`@Changing only the title (not the name) of `^%s`@ `@(%s`@ [%s,%s])`n", $oname, $newtitle, $dk, $sex);
             if ($session['user']['acctid'] == $row['acctid']) {
                 $session['user']['title'] = $newtitle;
             } else {