Location: PHPKode > projects > simpleMVC > myGifts/setup.php
<?php

if (!empty($_POST["language"]))
	define("LANG", $_POST["language"]);
	
@include("config/config.inc.php");
require("includes/includes.inc.php");

if (!defined("LANG") || LANG == "default") {
	$template = "setup.tpl";
} else if (!defined("DBSERVER") || !empty($_POST["dbserver"])) {
	$template = "setupdatabase.tpl";
	
	if (!empty($_POST["dbserver"])) {
		define("DBSERVER", $_POST["dbserver"]);
		define("DBUSER", $_POST["dbuser"]);
		define("DBPASSWORD", $_POST["dbpassword"]);
		define("DBDATABASE", $_POST["dbdatabase"]);
		$database = new Database(DBSERVER, DBUSER, DBPASSWORD, DBDATABASE);
		if ($database->connect()) {
			$fp = fopen("config/config.inc.php", "w");
			if ($fp) {
				fwrite($fp, "<?php\n");
				fwrite($fp, "define(\"LANG\", \"".LANG."\");\n");
				fwrite($fp, "define(\"SKIN\", \"default\");\n");
				fwrite($fp, "define(\"DBSERVER\", \"".DBSERVER."\");\n");
				fwrite($fp, "define(\"DBUSER\", \"".DBUSER."\");\n");
				fwrite($fp, "define(\"DBPASSWORD\", \"".DBPASSWORD."\");\n");
				fwrite($fp, "define(\"DBDATABASE\", \"".DBDATABASE."\");\n");
				fwrite($fp, "?>\n");
				fclose($fp);
				
				header("Location: ".$_SERVER["SCRIPT_NAME"]);
			} else {
				$text = $strings["ERROR_SETUP_CANTWRITE"];
			}
		} else {
			$text = $strings["ERROR_DATABASE"];
		}
	}
} else {
	$user = $database->fetch("select 1 from gft_user where accessLevel=2");
	if ($user == "ERROR_DATABASE") {
		$filename = "setup/myGifts.sql";	
		$fp = fopen($filename, "r");
		$dbStruct = fread($fp, filesize ($filename));
		fclose($fp);
		foreach (explode(";", $dbStruct) as $sqlQuery) {
			if (!empty($sqlQuery) && !$database->query($sqlQuery)) {
				$template = "setupdatabase.tpl";
				$text = $strings["ERROR_DATABASE"];
			}
		}
		if (empty($text))
			$user = null;
	}
		
	if ($user == null) {
		if (!empty($_POST["name"]) && !empty($_POST["password"])) {
			$user = new User();
			$user->saveUser($_POST["name"], $_POST["email"], $_POST["password"], 2);
			
			header("Location: ".$_SERVER["SCRIPT_NAME"]);
		}
		$template = "setupadmin.tpl";
	} else if ($user != "ERROR_DATABASE") {
		$template = "message.tpl";
		$title = $strings["LANG_SETUP"];
		$text = $strings["LANG_SETUP_FINISHED"];
	}
}
	
$smarty = new Smarty;
$smarty->template_dir = "./skins/".SKIN."/";
$smarty->compile_dir = "./cache/skins/";
$smarty->use_sub_dirs = false;

$smarty->assign('app', $app);
$smarty->assign('strings', $strings);
$smarty->assign('title', $title);
$smarty->assign('text', $text);
foreach (array_keys($_POST) as $variable) {
	$smarty->assign("$variable", $_POST[$variable]);
}
$smarty->display("$template"); 

?>
Return current item: simpleMVC