<?php
/*
mysql_query ("CREATE TABLE IF NOT EXISTS `TABLE` (`ID` INT NOT NULL AUTO_INCREMENT , PRIMARY KEY ( `id` ) )");
mysql_query ("ALTER TABLE `TABLE` ADD `FIELD` varchar(255) NOT NULL");
*/

if (!file_exists("$_SERVER[DOCUMENT_ROOT]/webifycore/customheader.php")) {
	$ourFileName = "$_SERVER[DOCUMENT_ROOT]/webifycore/customheader.php"; 
	$ourFileHandle = fopen($ourFileName, 'w'); 
	fclose($ourFileHandle);
}

if (!file_exists("$_SERVER[DOCUMENT_ROOT]/webifycore/customfooter.php")) {
	$ourFileName = "$_SERVER[DOCUMENT_ROOT]/webifycore/customfooter.php"; 
	$ourFileHandle = fopen($ourFileName, 'w'); 
	fclose($ourFileHandle);
}
//..........................

$table = "$prefix" . "USERS";
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 `EMAIL` varchar(255) NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `FIRSTNAME` varchar(255) NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `LASTNAME` varchar(255) NOT NULL");

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

$table = "$prefix" . "OBJECTS";
mysql_query ("CREATE TABLE IF NOT EXISTS `$table` (`ID` INT NOT NULL AUTO_INCREMENT , PRIMARY KEY ( `id` ) )");
mysql_query ("ALTER TABLE `$table` ADD `TITLE` varchar(255) NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `MAINPHOTO` varchar(255) NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `CATEGORY` varchar(255) NOT NULL");

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

$table = "$prefix" . "LANG";
mysql_query ("CREATE TABLE IF NOT EXISTS `$table` (`ID` INT NOT NULL AUTO_INCREMENT , PRIMARY KEY ( `id` ) )");
mysql_query ("ALTER TABLE `$table` ADD `LANG` varchar(255) NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `CODE` varchar(255) NOT NULL");

$SQL = "SELECT * from $table";
$result = @mySQL_query( $SQL );
$row = @mySQL_fetch_array( $result );

IF (empty($row[ID])) {
        $sql    = "INSERT INTO $table SET LANG = 'English', CODE = 'en'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Afrikaans', CODE = 'af'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Albanian', CODE = 'sq'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Arabic', CODE = 'ar'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Belarusian', CODE = 'be'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Bulgarian', CODE = 'bg'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Catalan', CODE = 'ca'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Chinese Simplified', CODE = 'zh-CN'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Chinese Traditional', CODE = 'zh-TW'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Croatian', CODE = 'hr'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Czech', CODE = 'cs'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Danish', CODE = 'da'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Dutch', CODE = 'nl'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Estonian', CODE = 'et'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Filipino', CODE = 'tl'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Finnish', CODE = 'fi'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'French', CODE = 'fr'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Galician', CODE = 'gl'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'German', CODE = 'de'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Greek', CODE = 'el'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Hebrew', CODE = 'iw'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Hindi', CODE = 'hi'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Hungarian', CODE = 'hu'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Icelandic', CODE = 'is'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Indonesian', CODE = 'id'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Irish', CODE = 'ga'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Italian', CODE = 'it'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Japanese', CODE = 'ja'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Korean', CODE = 'ko'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Latvian', CODE = 'lv'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Lithuanian', CODE = 'lt'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Macedonian', CODE = 'mk'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Malay', CODE = 'ms'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Maltese', CODE = 'mt'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Norwegian', CODE = 'no'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Persian', CODE = 'fa'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Polish', CODE = 'pl'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Portuguese', CODE = 'pt'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Romanian', CODE = 'ro'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Russian', CODE = 'ru'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Serbian', CODE = 'sr'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Slovak', CODE = 'sk'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Slovenian', CODE = 'sl'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Spanish', CODE = 'sw'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Swahili', CODE = 'en'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Swedish', CODE = 'sv'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Thai', CODE = 'th'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Turkish', CODE = 'tr'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Ukrainian', CODE = 'uk'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Vietnamese', CODE = 'vi'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Welsh', CODE = 'cy'";
        $query  = @mysql_query($sql);
        $sql    = "INSERT INTO $table SET LANG = 'Yiddish', CODE = 'yi'";
        $query  = @mysql_query($sql);
}

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

$table = "$prefix" . "SETTINGS";
mysql_query ("CREATE TABLE IF NOT EXISTS `$table` (`ID` INT NOT NULL AUTO_INCREMENT , PRIMARY KEY ( `id` ) )");
mysql_query ("ALTER TABLE `$table` ADD `THEME` varchar(255) NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `LANG` varchar(255) NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `HTML1` TEXT NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `HTML2` TEXT NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `HTML3` TEXT NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `HTML4` TEXT NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `HTML5` TEXT NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `HTML6` TEXT NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `HTML7` TEXT NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `HTML8` TEXT NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `DEBUG` TEXT NOT NULL");

$SQL = "SELECT * from $table";
$result = @mySQL_query( $SQL );
$row = @mySQL_fetch_array( $result );

IF (empty($row[ID])) {
        $sql    = "INSERT INTO $table SET THEME = '1', LANG = 'en'";
        $query  = @mysql_query($sql);
}

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

$table = "$prefix" . "CATEGORIES";
mysql_query ("CREATE TABLE IF NOT EXISTS `$table` (`ID` INT NOT NULL AUTO_INCREMENT , PRIMARY KEY ( `id` ) )");
mysql_query ("ALTER TABLE `$table` ADD `PARENT` varchar(255) NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `GRANDPARENT` varchar(255) NOT NULL");

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

$table = "APPS";
mysql_query ("CREATE TABLE IF NOT EXISTS `$table` (`ID` INT NOT NULL AUTO_INCREMENT , PRIMARY KEY ( `id` ) )");
mysql_query ("ALTER TABLE `$table` ADD `TITLE` varchar(255) NOT NULL");
mysql_query ("ALTER TABLE `$table` ADD `URL` varchar(255) NOT NULL");

$SQL = "SELECT * from $table WHERE TITLE = '$script_title'";
$result = @mySQL_query( $SQL );
$row = @mySQL_fetch_array( $result );

$url = "http://" . $_SERVER[HTTP_HOST] . $_SERVER[PHP_SELF];

if (empty($row[TITLE])) {
        $sql    = "INSERT INTO $table SET
        TITLE   = '$script_title',
        URL           = '$url'";
        $query  = @mysql_query($sql);
}
//..........................

?>
