function install_module($module, $force = true)
{
    global $mostrecentmodule, $session;
    $name = $session['user']['name'];
    if (!$name) {
        $name = '`@System`0';
    }
    require_once "lib/sanitize.php";
    if (modulename_sanitize($module) != $module) {
        output("Error, module file names can only contain alpha numeric characters and underscores before the trailing .php`n`nGood module names include 'testmodule.php', 'joesmodule2.php', while bad module names include, 'test.module.php' or 'joes module.php'`n");
        return false;
    } else {
        // If we are forcing an install, then whack the old version.
        if ($force) {
            $sql = "DELETE FROM " . db_prefix("modules") . " WHERE modulename='{$module}'";
            db_query($sql);
        }
        // We want to do the inject so that it auto-upgrades any installed
        // version correctly.
        if (injectmodule($module, true)) {
            // If we're not forcing and this is already installed, we are done
            if (!$force && is_module_installed($module)) {
                return true;
            }
            $info = get_module_info($module);
            //check installation requirements
            if (!module_check_requirements($info['requires'])) {
                output("`\$Module could not installed -- it did not meet its prerequisites.`n");
                return false;
            } else {
                $keys = "|" . join(array_keys($info), "|") . "|";
                $sql = "INSERT INTO " . db_prefix("modules") . " (modulename,formalname,moduleauthor,active,filename,installdate,installedby,category,infokeys,version,download,description) VALUES ('{$mostrecentmodule}','" . addslashes($info['name']) . "','" . addslashes($info['author']) . "',0,'{$mostrecentmodule}.php','" . date("Y-m-d H:i:s") . "','" . addslashes($name) . "','" . addslashes($info['category']) . "','{$keys}','" . addslashes($info['version']) . "','" . addslashes($info['download']) . "', '" . addslashes($info['description']) . "')";
                db_query($sql);
                $fname = $mostrecentmodule . "_install";
                if (isset($info['settings']) && count($info['settings']) > 0) {
                    foreach ($info['settings'] as $key => $val) {
                        if (is_array($val)) {
                            $x = explode("|", $val[0]);
                        } else {
                            $x = explode("|", $val);
                        }
                        if (isset($x[1])) {
                            $x[1] = trim($x[1]);
                            set_module_setting($key, $x[1]);
                            debug("Setting {$key} to default {$x[1]}");
                        }
                    }
                }
                if ($fname() === false) {
                    return false;
                }
                output("`^Module installed.  It is not yet active.`n");
                invalidatedatacache("inject-{$mostrecentmodule}");
                massinvalidate("moduleprepare");
                return true;
            }
        } else {
            output("`\$Module could not be injected.");
            output("Module not installed.");
            output("This is probably due to the module file having a parse error or not existing in the filesystem.`n");
            return false;
        }
    }
}
        httpset('op', "");
    } elseif ($op == "activate") {
        activate_module($module);
        $op = "";
        httpset('op', "");
        invalidatedatacache("injections/inject_{$module}");
    } elseif ($op == "deactivate") {
        deactivate_module($module);
        $op = "";
        httpset('op', "");
        invalidatedatacache("injections/inject_{$module}");
    } elseif ($op == "reinstall") {
        $sql = "UPDATE " . db_prefix("modules") . " SET filemoddate='0000-00-00 00:00:00' WHERE modulename='{$module}'";
        db_query($sql);
        // We don't care about the return value here at all.
        injectmodule($module, true);
        $op = "";
        httpset('op', "");
        invalidatedatacache("injections/inject_{$module}");
    }
}
$install_status = get_module_install_status();
$uninstmodules = $install_status['uninstalledmodules'];
$seencats = $install_status['installedcategories'];
$ucount = $install_status['uninstcount'];
ksort($seencats);
addnav(array(" ?Uninstalled - (%s modules)", $ucount), "modules.php");
reset($seencats);
foreach ($seencats as $cat => $count) {
    addnav(array(" ?%s - (%s modules)", $cat, $count), "modules.php?cat={$cat}");
}
<?php

// translator ready
// addnews ready
// mail ready
define("ALLOW_ANONYMOUS", true);
define("OVERRIDE_FORCED_NAV", true);
require_once "lib/http.php";
require_once "common.php";
require_once "lib/dump_item.php";
require_once "lib/modules.php";
require_once "lib/villagenav.php";
if (injectmodule(httpget('module'), httpget('admin') ? true : false)) {
    $info = get_module_info(httpget('module'));
    if (!isset($info['allowanonymous'])) {
        $allowanonymous = false;
    } else {
        $allowanonymous = $info['allowanonymous'];
    }
    if (!isset($info['override_forced_nav'])) {
        $override_forced_nav = false;
    } else {
        $override_forced_nav = $info['override_forced_nav'];
    }
    do_forced_nav($allowanonymous, $override_forced_nav);
    $starttime = getmicrotime();
    $fname = $mostrecentmodule . "_run";
    tlschema("module-{$mostrecentmodule}");
    $fname();
    $endtime = getmicrotime();
    if ($endtime - $starttime >= 1.0 && $session['user']['superuser'] & SU_DEBUG_OUTPUT) {
            if (!isset($old[$key])) {
                $old[$key] = "";
            }
            savesetting($key, stripslashes($val));
            output("Setting %s to %s`n", $key, stripslashes($val));
            gamelog("`@changed core setting `^{$key}`@ from `3{$old[$key]}`@ to `#{$val}`0", "settings");
            // Notify every module
            modulehook("changesetting", array("module" => "core", "setting" => $key, "old" => $old[$key], "new" => $val), true);
        }
    }
    output("`^Settings saved.`0");
    $op = "";
    httpset($op, "");
} elseif ($op == "modulesettings") {
    include_once "lib/gamelog.php";
    if (injectmodule($module, true)) {
        $save = httpget('save');
        if ($save != "") {
            load_module_settings($module);
            $old = $module_settings[$module];
            $post = httpallpost();
            $post = modulehook("validatesettings", $post, true, $module);
            if (isset($post['validation_error'])) {
                $post['validation_error'] = translate_inline($post['validation_error']);
                output("Unable to change settings:`\$%s`0", $post['validation_error']);
            } else {
                reset($post);
                while (list($key, $val) = each($post)) {
                    $key = stripslashes($key);
                    $val = stripslashes($val);
                    set_module_setting($key, $val);