<?php
/*
 ########################################################################
#                                                                        #
#           Version 4       /                        /   /               #
#          -----------__---/__---__------__----__---/---/-               #
#           | /| /  /___) /   ) (_ `   /   ) /___) /   /                 #
#          _|/_|/__(___ _(___/_(__)___/___/_(___ _/___/___               #
#                       Free Content / Management System                 #
#                                   /                                    #
#                                                                        #
#                                                                        #
#   Copyright 2005-2006 by webspell.org                                  #
#                                                                        #
#   visit webSPELL.org, webspell.info to get webSPELL for free           #
#   - Script runs under the GNU GENERAL PUBLIC LICENSE                   #
#   - It's NOT allowed to remove this copyright-tag                      #
#   -- http://www.fsf.org/licensing/licenses/gpl.html                    #
#                                                                        #
#   Code based on WebSPELL Clanpackage (Michael Gruber - webspell.at),   #
#   Far Development by Development Team - webspell.org                   #
#                                                                        #
#   visit webspell.org                                                   #
#                                                                        #
 ########################################################################
*/

include('functions.php');

if($_POST['installtype'] == "update") {

 include('../_mysql.php');
 mysql_connect($host, $user, $pwd) or die ('ERROR: no connection to mysql');
 mysql_select_db($db) or die ('ERROR: cannot connect to database "'.$db.'"');

 update31_4beta4();
 update4beta4_4beta5();
 update4beta5_4beta6();


} elseif($_POST['installtype'] == "full") {

$host = $_POST['host'];
$user = $_POST['user'];
$pwd = $_POST['pwd'];
$db = $_POST['db'];
$prefix = $_POST['prefix'];
$adminname = $_POST['adminname'];
$adminpwd = $_POST['adminpwd'];
$adminmail = $_POST['adminmail'];
$url = $_POST['url'];

    if(!(strlen(trim($host)))) {
	    $error="please verify your data!";
		die('<b>ERROR: '.$error.'</b><br><br><a href="javascript:history.back()">back</a>');
	}
	if(!(strlen(trim($db)))) {
	    $error="please verify your data!";
		die('<b>ERROR: '.$error.'</b><br><br><a href="javascript:history.back()">back</a>');
	} 
	if(!(strlen(trim($adminname)))) {
	    $error="please verify your data!";
		die('<b>ERROR: '.$error.'</b><br><br><a href="javascript:history.back()">back</a>');
	} 
	if(!(strlen(trim($adminpwd)))) {
	    $error="please verify your data!";
		die('<b>ERROR: '.$error.'</b><br><br><a href="javascript:history.back()">back</a>');
	} 
	if(!(strlen(trim($adminmail)))) {
	    $error="please verify your data!";
		die('<b>ERROR: '.$error.'</b><br><br><a href="javascript:history.back()">back</a>');
	} 
	if(!(strlen(trim($url)))) {
	    $error="please verify your data!";
		die('<b>ERROR: '.$error.'</b><br><br><a href="javascript:history.back()">back</a>');
	} 
	
	$adminpassword=md5($adminpwd);          			

//write _mysql.php

$file = ("../_mysql.php");
if($fp = fopen ($file, "wb")) {

$string='<?php
 $host = "'.$host.'";
 $user = "'.$user.'";
 $pwd = "'.$pwd.'";
 $db = "'.$db.'";
 define(PREFIX, \''.$prefix.'\');
?>
';

fwrite ($fp, $string);
fclose($fp);
} else echo 'Writing to file failed. Please write your MySQL-Data to the _mysql.php manually.';

//write sql-tables

mysql_connect($host, $user, $pwd) or die ('ERROR: no connection to mysql');
mysql_select_db($db) or die ('ERROR: cannot connect to databe "'.$db.'"');
	
define(PREFIX, $prefix);

fullinstall();
update4beta4_4beta5();
update4beta5_4beta6();
update4beta6_4final();
update40000_40100();
update40100_40101();
}
elseif($_POST['installtype'] == "update_beta") {

 include('../_mysql.php');
 mysql_connect($host, $user, $pwd) or die ('ERROR: no connection to mysql');
 mysql_select_db($db) or die ('ERROR: cannot connect to "'.$db.'"');

 update4beta4_4beta5();
 update4beta5_4beta6();
 update4beta6_4final();
 update40000_40100();
 update40100_40101();
}
elseif($_POST['installtype'] == "update_beta5") {

 include('../_mysql.php');
 mysql_connect($host, $user, $pwd) or die ('ERROR: no connection to mysql');
 mysql_select_db($db) or die ('ERROR: cannot connect to"'.$db.'"');

 update4beta5_4beta6();
 update4beta6_4final();
 update40000_40100();
 update40100_40101(); 
}

elseif($_POST['installtype'] == "update_beta6") {

 include('../_mysql.php');
 mysql_connect($host, $user, $pwd) or die ('ERROR: no connection to mysql');
 mysql_select_db($db) or die ('ERROR: cannot connect to"'.$db.'"');

 update4beta6_4final();
 update40000_40100(); 
 update40100_40101(); 
}

elseif($_POST['installtype'] == "update_final") {
	
 include('../_mysql.php');
 mysql_connect($host, $user, $pwd) or die ('ERROR: no connection to mysql');
 mysql_select_db($db) or die ('ERROR: cannot connect to"'.$db.'"');

 update40000_40100();
 update40100_40101(); 
}

elseif($_POST['installtype'] == "update_40100") {
	
 include('../_mysql.php');
 mysql_connect($host, $user, $pwd) or die ('ERROR: no connection to mysql');
 mysql_select_db($db) or die ('ERROR: cannot connect to"'.$db.'"');

 update40100_40101();
 
}

?>

<p align="center">Installation complete!<br>
          Please delete <strong>/install</strong> dir for your own security.<br>
          Please reset CHMOD of <strong>_mysql.php</strong> to 644.<br>
          <br>
          <a href="../index.php">View Site</a><br>
</p>
