// Initialize the language
if (isset($_POST['lang'])) {
    define('LANG', $_POST['lang']);
}
define('SCRIPT_EXP_RELATIVE', 'install/');
define('SCRIPT_FILENAME', 'index.php');
include_once '../exponent.php';
// Load i18n values
$i18n = exponent_lang_loadFile('install/index.php');
// Initialize the language
if (isset($_POST['lang'])) {
    //prepare value array for exponent_config_saveConfiguration
    $values = array("c");
    $values["c"]["LANG"] = LANG;
    include_once BASE . "/subsystems/config.php";
    exponent_config_saveConfiguration($values);
}
if (!isset($_REQUEST['page'])) {
    $_REQUEST['page'] = 'setlang';
}
$page = $_REQUEST['page'];
$page_image = '';
$page_text = '';
switch ($page) {
    case 'setlang':
        $page_image = 'setlang';
        $page_text = $i18n['setlang'];
        break;
    case 'sanity':
        $page_image = 'sanity';
        $page_text = $i18n['sanity'];
         $continue = false;
         $errors .= $i18n['cant_connect'];
     }
     if ($continue) {
         $status = $newdb->testPrivileges();
         foreach ($status as $type => $flag) {
             if (!$flag) {
                 $continue = false;
                 $errors .= sprintf($i18n['perm_denied'], $type);
             }
         }
     }
 }
 $template = new template('AdministrationModule', '_config_results');
 if ($continue) {
     exponent_config_saveConfiguration($_POST);
     $ob = "";
     if ($user->is_admin == 1) {
         $i18n = exponent_lang_loadFile('db_recover.php');
         $db = $newdb;
         ob_start();
         include_once BASE . 'modules/AdministrationModule/actions/installtables.php';
         $ob = ob_get_contents();
         ob_end_clean();
         if ($db->tableIsEmpty('user')) {
             $user = null;
             $user->username = '******';
             $user->password = md5('admin');
             $user->is_admin = 1;
             $user->is_acting_admin = 1;
             $db->insertObject($user, 'user');
 $used = array(CORE_EXT_MODULE => array(), CORE_EXT_SUBSYSTEM => array(), CORE_EXT_THEME => array());
 foreach (exponent_core_resolveDependencies(null, CORE_EXT_SYSTEM, $core->path) as $d) {
     if (!in_array($d['name'], $used[$d['type']])) {
         $extension->name = $d['name'];
         $extension->type = $d['type'];
         $db->insertObject($extension, "sharedcore_extension");
         $used[$d['type']][] = $d['name'];
     }
 }
 exponent_sharedcore_link($core, $site, $used);
 // Save database config.
 $values = array("c" => array("db_engine" => $_POST['db_engine'], "db_name" => $_POST['db_name'], "db_user" => $_POST['db_user'], "db_pass" => $_POST['db_pass'], "db_host" => $_POST['db_host'], "db_port" => $_POST['db_port'], "db_table_prefix" => $_POST['db_table_prefix']), "opts" => array(), "activate" => 1, "configname" => "Default");
 if (!defined("SYS_CONFIG")) {
     require_once BASE . "subsystems/config.php";
 }
 exponent_config_saveConfiguration($values, $site->path);
 // Install database for base system
 $newdb = exponent_database_connect($_POST['db_user'], $_POST['db_pass'], $_POST['db_host'] . ':' . $_POST['db_port'], $_POST['db_name'], $_POST['db_engine'], true);
 $newdb->prefix = $_POST['db_table_prefix'] . '_';
 // Following code snipped from modules/AdministrationModule/actions/installtables.php
 $dir = $site->path . "datatypes/definitions";
 if (is_readable($dir)) {
     $tables = array();
     $dh = opendir($dir);
     while (($file = readdir($dh)) !== false) {
         if (is_readable("{$dir}/{$file}") && is_file("{$dir}/{$file}") && substr($file, -4, 4) == ".php" && substr($file, -9, 9) != ".info.php") {
             $tablename = substr($file, 0, -4);
             $dd = (include "{$dir}/{$file}");
             $info = null;
             if (is_readable("{$dir}/{$tablename}.info.php")) {
                 $info = (include "{$dir}/{$tablename}.info.php");