<?PHP
include "../include/global.php";
//---------------------------------------------------------------------------------------------
if(!isset($_SERVER['DOCUMENT_ROOT'])){
        if(isset($_SERVER['SCRIPT_FILENAME'])){
                $_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF'])));
                };
        };

if(!isset($_SERVER['DOCUMENT_ROOT'])){ if(isset($_SERVER['PATH_TRANSLATED'])){
        $_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr(str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']), 0, 0-strlen($_SERVER['PHP_SELF'])));
        };
};

$svr_root 	= "$_SERVER[DOCUMENT_ROOT]"; 	# /home/USER/public_html
$svr_domain 	= "http://$_SERVER[HTTP_HOST]"; # www.domain.com
$svr_rootfile 	= "$_SERVER[SCRIPT_FILENAME]"; 	#/home/USER/public_html/folder/file.php
$svr_phpself 	= "$_SERVER[PHP_SELF]"; 	# /directory/file.php

$mystring 	= "$svr_domain$svr_phpself";
$findme  	= '/';
$pos 		= strrpos($mystring, $findme);
$substr 	= substr("$mystring", 0, $pos);
$svr_pthself 	= $substr;
        
$mystring 	= "$svr_rootfile";
$findme  	= '/';
$pos 		= strrpos($mystring, $findme);
$substr 	= substr("$mystring", 0, $pos);
$svr_rootself 	= $substr;

//---------------------------------------------------------------------------------------------
$mystring1      = "$svr_rootfile";
$findme1        = '/';
$pos1           = strrpos($mystring1, $findme1);
$newpos1        = $pos1 - 8;
$substr1        = substr("$mystring1", 0, $newpos1);

$mystring2      = "$svr_domain$svr_phpself";
$findme2        = '/';
$pos2           = strrpos($mystring2, $findme2);
$newpos2        = $pos2 - 8;
$substr2        = substr("$mystring2", 0, $newpos2);

@fopen("../include/mysql.php", "w");

$filename       = '../include/mysql.php';

$somecontent    = "<?php
\$host = \"$_POST[host]\";
\$user = \"$_POST[dbusername]\";
\$pass = \"$_POST[dbpassword]\";
\$database = \"$_POST[dbname]\";
\$con=@mysql_connect(\"\$host\",\"\$user\",\"\$pass\"); \$db=\"\$database\"; @mysql_select_db(\$db, \$con);
\$svr_rootscript = \"$substr1\";
\$svr_urlscript = \"$substr2\"; 
?>";

if (is_writable($filename)) {
        if (!$handle = @fopen($filename, 'a')) {
                exit;
        }

        if (@fwrite($handle, $somecontent) === FALSE) {
                exit;
        }

        @fclose($handle); 

} else {
        include 'install.php'; die();
}

//---------------------------------------------------------------------------------------------

include "../include/mysql.php";

mysql_query ("CREATE TABLE IF NOT EXISTS `USERS` (`ID` INT NOT NULL AUTO_INCREMENT ,
        `FIRSTNAME` varchar(255) NOT NULL,
        `LASTNAME` varchar(255) NOT NULL,
        `USERNAME` varchar(255) NOT NULL,
        `PASSWORD` varchar(255) NOT NULL,
        `EMAIL` varchar(255) NOT NULL,
        `STATUS` varchar(255) NOT NULL,
        PRIMARY KEY ( `id` ) )");

if ($_POST['USERNAME'] == $nil or $_POST['PASSWORD'] == $nil) {
        include 'install.php';
        die();
} else {
        $SQL = "SELECT * from USERS WHERE USERNAME = '$_POST[USERNAME]'"; $result = @mysql_query( $SQL ); $row = @mysql_fetch_array( $result );
        if ($_POST[USERNAME] == $row[USERNAME]) {
        } else {
                $sql = "INSERT INTO USERS SET
                USERNAME = '$_POST[USERNAME]' ,
                PASSWORD = '$_POST[PASSWORD]' ,
                STATUS = '1'";
                $query = mysql_query($sql) or include ('install.php');
                $query = mysql_query($sql) or die("mysql_error()");
        }
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>One moment please...</title>
<meta http-equiv="REFRESH" content="0;url=../admin/"></HEAD>
<BODY></BODY>
</HTML>

