<?PHP
if (0 != @filesize('../db/mysql.php'))
        die(Snooper);
        
//....................................
        
$con = @mysql_connect("$_POST[HOST]","$_POST[FTPUSER]","$_POST[FTPPASS]");
if (!$con) {
        $error = "Setup failed because we could not connect to the database: " . mysql_error() . ". <br><br><font color=green>Don't worry, this is usually easy to fix: Try adjusting your FTP Username/Password, Host or Database Name and try again. If you do not know what these values should be, contact your web host for assistance. The Easy Installation method will not work on all servers, if you are sure that you are using the correct values, try the Standard Installation instead.</font>";
        include "easyinstall.php"; die();
}
                
//....................................

if (@mysql_query("CREATE DATABASE $_POST[FTPUSER]_$_POST[DBNAME]",$con)) {
                
        echo "<h2>Setup has completed successfully. Access your Control Panel below.</h2>";

        $path[] = "$_SERVER[DOCUMENT_ROOT]";

                while(count($path) != 0) {
                        $v = array_shift($path);

                        foreach(glob($v) as $item) {
                                if (is_dir($item))
                                $path[] = $item . '/*';

                                elseif (is_file($item)) {

                                        $pos = strpos($item, "inc/global.php");
                                        if (!empty($pos)) {

                                                include "$item";
                                                $url = str_replace($_SERVER[DOCUMENT_ROOT],$_SERVER[HTTP_HOST],$item);
                                                $pieces = explode ("inc", "$url");
                                                $url = $pieces[0];
                                                $url = "$url" . "admin";
                                                echo "<div class=primebox style=\"width: 100%; margin-bottom:15px;\">";
                                                echo "<a href=\"http://$url/index.php?qun=$_POST[ADMINUSER]&qpw=$_POST[ADMINPASS]&first=1\"><img src=\"http://$_SERVER[HTTP_HOST]/webifycore/images/$script_title.png\" width=\"64\" height=\"64\" style=\"float: left; margin-right:10px;\"></a>";
                                                echo "<h3>$script_title</h3>";
                                                echo "<a href=\"http://$url/index.php?qun=$_POST[ADMINUSER]&qpw=$_POST[ADMINPASS]&first=1\">$url</a><br>";
                                                echo "</div>";

                                        }
                                }
                        }
                }

//....................................

        } else {

                $error = "Setup failed because we could not create a database: " . mysql_error() . ". <br><br><font color=green>Don't worry, this just means that you cannot use the Easy installation method. You can still use the Standard Installation however. This means that you will now need to create a MySQL database in you web hosting control panel for this App to use. After you have done that, come back here and fill out the fields below.</font><br><br><font color=black>If you are attempting to re-install into an existing database (database exists error) you can still do so with the standard installation form (now loaded below).</font>";
                include "standardinstall.php"; die();

        }
                
//....................................

fopen("../db/mysql.php", "w");
$filename = "../db/mysql.php";

$somecontent = '<?php' . ' $con = mysql_connect' . "(\"$_POST[HOST]\", \"$_POST[FTPUSER]\", \"$_POST[FTPPASS]\"); " . 'mysql_select_db' . "(\"$_POST[FTPUSER]_$_POST[DBNAME]\"," . '$con);' . ' ?>';

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

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

fclose($handle);

}

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

$table = "ADMINS";
mysql_query ("CREATE TABLE IF NOT EXISTS `$table` (`ID` INT NOT NULL AUTO_INCREMENT , PRIMARY KEY ( `id` ) )");
mysql_query ("ALTER TABLE `$table` ADD `USERNAME` varchar(255) NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `PASSWORD` varchar(255) NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `PRIME` varchar(255) NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `EMAIL` varchar(255) NOT NULL");
        
$sql = "INSERT INTO $table SET
USERNAME = '$_POST[ADMINUSER]',
PRIME = '1',
PASSWORD = '$_POST[ADMINPASS]'";
$query = @mysql_query($sql);
?>
