示例#1
0
function getDbFile()
{
    if (defined('DB_CONFIG_FILE')) {
        $config_file = DB_CONFIG_FILE;
    } else {
        $config_files = configFileList();
        if (count($config_files) != 1) {
            echo "unable to auto-determine config file, please specify DB_CONFIG_FILE in install.php";
            exit(1);
        }
        $config_file = $config_files[0];
    }
    return getcwd() . '/' . $config_file;
}
function configWrite()
{
    global $configOptions;
    $config_files = configFileList();
    foreach ($config_files as $config_file) {
        $these_configs = getFileConfigs($config_file);
        $file_scratch = file_get_contents("{$config_file}.tpl");
        foreach ($these_configs as $key => $config) {
            if (strstr($key, "db_") === FALSE) {
                $value = configGetValue($key);
            } else {
                $value = configGetDBValue($key);
            }
            $new_scratch = str_replace($config['string'], $value, $file_scratch);
            $file_scratch = $new_scratch;
        }
        #TODO - error handling !
        $handle = fopen($config_file, "w");
        if ($handle === FALSE) {
            userMessage("error", "Unable to open {$config_file}");
            return FALSE;
        } else {
            $write_result = fwrite($handle, $file_scratch);
            if ($write_result === FALSE || $write_result < strlen($file_scratch)) {
                userMessage("error", "Problem writing " . getcwd() . "/{$config_file}");
                return FALSE;
            } else {
                fclose($handle);
            }
        }
    }
    return TRUE;
}