Location: PHPKode > projects > JaxBlog > JaxBlog/app/common/configurator.php
<?php

// Rewrites config.php in the base directory.
// Requires filesystem.php to work.

function determineConfigValue($defaultValue, $currentValue, $requestVariableName) {
	
	$requestValue = null;
	if (isset($_POST[$requestVariableName])) $requestValue = $_POST[$requestVariableName];

	if ($currentValue == null && $requestValue == null) {
//		echo "<h1>defaultValue: $defaultValue</h1>";
		return $defaultValue;
	}
	
	if ($requestValue == null) {
//		echo "<h1>currentValue: $currentValue</h1>";
		return $currentValue;
	}
	
//	echo "<h1>requestValue: $requestValue</h1>";
	return $requestValue;
}

function writeConfigurationChangeToDisk($installed = null) {
	
	$database_vendor         = determineConfigValue("postgres", VENDOR, "database_vendor");
	$database_server         = determineConfigValue("localhost", SERVER, "database_server");
	$database_name           = determineConfigValue("jaxblog", DATABASE, "database_name");
	$database_username       = determineConfigValue("ENTER A USERNAME", USERNAME, "database_username");
	$database_password       = determineConfigValue("ENTER A PASSWORD", PASSWORD, "database_password");
	
	$admin_username          = determineConfigValue("ENTER A USERNAME", ADMINISTRATIVE_USERNAME, "admin_username");
	$admin_password          = determineConfigValue("ENTER A PASSWORD", ADMINISTRATIVE_PASSWORD, "admin_password");
	
	$folder_relative_base    = determineConfigValue("../../../", FOLDER_RELATIVE_BASE, "folder_relative_base");
	$folder_relative_common  = determineConfigValue(FOLDER_RELATIVE_COMMON . "", FOLDER_RELATIVE_COMMON, "folder_relative_common");
	$folder_adodb            = determineConfigValue("resource/adodb/", FOLDER_ADODB, "FOLDER_ADODB");
	$folder_upload           = determineConfigValue("upload/", FOLDER_UPLOAD, "folder_upload");
	$folder_template         = determineConfigValue("resource/template/", FOLDER_TEMPLATE, "folder_template");
	$folder_css              = determineConfigValue("resource/css/", FOLDER_CSS, "folder_css");
	$folder_javascript       = determineConfigValue("resource/javascript/", FOLDER_JAVASCRIPT, "folder_javascript");
	
	$file_template_main      = determineConfigValue("main.html", FILE_TEMPLATE_MAIN, "file_template_main");
	$file_template_page      = determineConfigValue("page.html", FILE_TEMPLATE_PAGE, "file_template_page");
	$file_template_admin     = determineConfigValue("admin.html", FILE_TEMPLATE_ADMIN, "file_template_admin");
	$file_template_install   = determineConfigValue("install.html", FILE_TEMPLATE_INSTALL, "file_template_install");
	$file_template_error     = determineConfigValue("error.html", FILE_TEMPLATE_ERROR, "file_template_error");
	
	$file_sqlite = '';
	if ($database_vendor == "sqlite") {
		$working_dir = str_replace('\\', '/', getcwd());
		if (substr($working_dir, -1) != "/") $working_dir .= "/";
		$file_sqlite = $working_dir . FOLDER_RELATIVE_BASE . FOLDER_UPLOAD . SERVER;
	}
	
	$misc_organization       = determineConfigValue("PLEASE ENTER AN ORGANIZATION", ORGANIZATION, "misc_organization");
	$misc_title_homepage     = determineConfigValue("YOUR HOMEPAGE", TITLE_HOMEPAGE, "misc_title_homepage");
	$misc_title_error        = determineConfigValue("YOUR HOMEPAGE Currently Unavailable", TITLE_ERROR, "misc_title_error");
	
	$flag_debug              = determineConfigValue("N", FLAG_DEBUG, "misc_flag_debug");
	if ($installed == null || $installed != 'Y') {
		$flag_installed = FLAG_INSTALLED;
	} else {
		$flag_installed = 'Y';
	}
//	return;
	
	$config = '';
	$config .= '<?php' . "\n";
	
	$config .= "\n" . '// Variables that run the show.' . "\n";
	$config .= 'set_include_path(ini_get("include_path") . ":" . dirname($_SERVER["SCRIPT_FILENAME"]) . ":" . dirname($_SERVER["SCRIPT_FILENAME"]) . "/app/common");' . "\n";
	$config .= 'require_once("app/common/errorhandler.php");' . "\n";
	
	$config .= "\n" . '// Database params.' . "\n";
	$config .= 'define("VENDOR", "' . $database_vendor . '");' . "\n";
	$config .= 'define("SERVER", "' . $database_server . '");' . "\n";
	$config .= 'define("DATABASE", "' . $database_name . '");' . "\n";
	$config .= 'define("USERNAME", "' . $database_username . '");' . "\n";
	$config .= 'define("PASSWORD", "' . $database_password . '");' . "\n";
	
	$config .= "\n" . '// Admin login.' . "\n";
	$config .= 'define("ADMINISTRATIVE_USERNAME", "' . $admin_username . '");' . "\n";
	$config .= 'define("ADMINISTRATIVE_PASSWORD", "' . $admin_password . '");' . "\n";
	
	$config .= "\n" . '// Directory params.' . "\n";
	$config .= 'define("FOLDER_RELATIVE_BASE", "' . $folder_relative_base . '");' . "\n";
	$config .= 'define("FOLDER_RELATIVE_COMMON", "' . $folder_relative_common . '");' . "\n";
	$config .= 'define("FOLDER_ADODB", "' . $folder_adodb . '");' . "\n";
	$config .= 'define("FOLDER_UPLOAD", "' . $folder_upload . '");' . "\n";
	$config .= 'define("FOLDER_TEMPLATE", "' . $folder_template . '");' . "\n";
	$config .= 'define("FOLDER_CSS", "' . $folder_css . '");' . "\n";
	$config .= 'define("FOLDER_JAVASCRIPT", "' . $folder_javascript . '");' . "\n";
	$config .= 'define("FILE_TEMPLATE_MAIN", "' . $file_template_main . '");' . "\n";
	$config .= 'define("FILE_TEMPLATE_PAGE", "' . $file_template_page . '");' . "\n";
	$config .= 'define("FILE_TEMPLATE_ADMIN", "' . $file_template_admin . '");' . "\n";
	$config .= 'define("FILE_TEMPLATE_INSTALL", "' . $file_template_install . '");' . "\n";
	$config .= 'define("FILE_TEMPLATE_ERROR", "' . $file_template_error . '");' . "\n";
	$config .= 'define("FILE_SQLITE", "' . $file_sqlite . '");' . "\n";
	
	$config .= "\n" . '// Misc' . "\n";
	$config .= 'define("ORGANIZATION", "' . $misc_organization . '");' . "\n";
	$config .= 'define("TITLE_HOMEPAGE", "' . $misc_title_homepage . '");' . "\n";
	$config .= 'define("TITLE_ERROR", "' . $misc_title_error . '");' . "\n";
	
	$config .= "\n" . '// Flags' . "\n";
	$config .= 'define("FLAG_DEBUG", "' . $flag_debug . '");' . "\n";
	$config .= 'define("FLAG_INSTALLED", "' . $flag_installed . '");' . "\n";
	$config .= 'define("FLAG_TIMESTAMP", "Y");' . "\n";
	$config .= 'define("FLAG_BREADCRUMB", "Y");' . "\n";
	
	$config .= "\n" . '?>';

	fileWrite(FOLDER_RELATIVE_BASE . 'config.php', $config);
}

?>
Return current item: JaxBlog