Location: PHPKode > projects > phpBannerEx > admin/setup.php
<?
#################################################################################################
#
#  project           	: phpBannerEx
#  filename          	: ./admin/setup.php
#  last modified by  	: 
#  e-mail            	: hide@address.com
#  purpose           	: File to install the Tables for phpBannerEx
#  version           	: 2.0.0
#  last modified     	: 04/30/2001
#
#################################################################################################


#  Include Configs & Variables
#################################################################################################
require ("config.php");

#  or use the variables below and comment out the above line ...
#$server  	= "localhost";
#$db_user   	= "mysql_user";
#$db_pass   	= "mysql_pass";
#$database   	= "phpBannerEx";

$title		= "phpBannerEx Install/Update-Tool V1.10";
$sql_file	= "phpBannerEx.sql";


#  Function-Declaration
#################################################################################################

function split_sql($sql) {
    $sql = trim($sql);
    $sql = ereg_replace("#[^\n]*\n", "", $sql);
    $buffer = array();
    $ret = array();
    $in_string = false;

    for($i=0; $i<strlen($sql)-1; $i++) {
	if($sql[$i] == ";" && !$in_string) {
            $ret[] = substr($sql, 0, $i);
            $sql = substr($sql, $i + 1);
            $i = 0;
        }
        if($in_string && ($sql[$i] == $in_string) && $buffer[0] != "\\") {
             $in_string = false;
        } elseif(!$in_string && ($sql[$i] == "\"" || $sql[$i] == "'") && (!isset($buffer[0]) || $buffer[0] != "\\")) {
             $in_string = $sql[$i];
        }
        if(isset($buffer[1])) {
            $buffer[0] = $buffer[1];
        }
        $buffer[1] = $sql[$i];
     }
    if(!empty($sql)) {
        $ret[] = $sql;
    }
    return($ret);
}

function installdb() {
    global $database,$sql_file;

    mysql_create_db($database) or die ("ERROR: ".mysql_error());
    mysql_select_db($database) or die ("ERROR: ".mysql_error());

    $sql_query = addslashes(fread(fopen($sql_file, "r"), filesize($sql_file)));
    $pieces  = split_sql($sql_query);

    if (count($pieces) == 1 && !empty($pieces[0])) {
	echo "Error !!!";
    }

    for ($i=0; $i<count($pieces); $i++) {
	$pieces[$i] = stripslashes(trim($pieces[$i]));
        if(!empty($pieces[$i]) && $pieces[$i] != "#") {
	    $result = mysql_query ($pieces[$i]);
	    if (!$result) {
		echo "Database: [$database] - MYSQL-ERROR: ".mysql_error()."<br>Command: ".stripslashes($pieces[$i])."<br>";
    	    } else {
		echo "Database: [$database] - mySQL-command: <b>OK!</b><br>";
	    }
        }
    }
    echo "<br><b>phpBannerEx Tables installed, Ready ...</b>";
}

function altertables($v_table,$v_command,$v_field,$v_type) {
    global $database;
    $result = mysql_query("ALTER TABLE $v_table $v_command $v_field $v_type");
    if (!$result) {
	echo "Database: [$database] - Alteration of Table: $v_table failed! <b>Error</b>: " .mysql_errno(). ": ".mysql_error(). "<br>";
    } else {
        echo "Database: [$database] - Alteration of Table: $v_table -> Field: $v_field <b>OK!</b><br>";
    }
}

function updatetables($v_table,$v_field,$v_type) {
    global $database;
    $result = mysql_query("UPDATE $v_table SET $v_field $v_type");
    if (!$result) {
	echo "Database: [$database] - Update of Table: $v_table failed! <b>Error</b>: " .mysql_errno(). ": ".mysql_error(). "<br>";
    } else {
        echo "Database: [$database] - Update of Table: $v_table -> Fields: $v_field <b>OK!</b><br>";
    }
}

function suppr($file) {
    $delete = @unlink($file);
    if (@file_exists($file)) {
	$filesys = eregi_replace("/","\\",$file);
	$delete = @system("del $filesys");
	if (@file_exists($file)) {
	    $delete = @chmod ($file, 0775);
	    $delete = @unlink($file);
	    $delete = @system("del $filesys");
	}
    }
}

#  Start
#################################################################################################
@set_time_limit(1000);
$timestamp=time();

header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    			// Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");  	// always modified
header ("Cache-Control: no-cache, must-revalidate");  			// HTTP/1.1
header ("Pragma: no-cache");                          			// HTTP/1.0

echo "<html>\n";
echo "<head>\n";
echo "<title>$title</title>\n";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">\n";
echo "</head>\n";

echo "<body bgcolor=\"#E2E2E2\"><font face=\"verdana\" size=\"2\">\n";
echo "<h3>$title</h3>";

@mysql_connect($server, $db_user, $db_pass);

if (mysql_select_db($database)) {

    @mysql_close();
    mysql_connect($server, $db_user, $db_pass) or die ("Database connect Error");
    mysql_select_db($database);

    if ($action=="up1") {

	$result=mysql_query("CREATE TABLE banner ( ba_id int(12) NOT NULL auto_increment,ba_banner blob NOT NULL, PRIMARY KEY (ba_id));");
        if (!$result) {
            echo "Database: [$database] - Table banner: failed! <b>Error</b>: " .mysql_errno(). ": ".mysql_error(). "<br>";
        } else {
            echo "Database: [$database] - Table banner: <b>OK!</b><br>";
	    $count=0;
	    $query=mysql_query("SELECT st_id,st_banner FROM site");
	    while ($db=mysql_fetch_array($query)) {
		$bin=addslashes($db[st_banner]);
		mysql_query("INSERT INTO banner VALUES ('$db[st_id]','$bin')") or die(mysql_error());
		$count++;
	    }
	    echo "$count Banners moved<br>";
    	    $v_table        ="site";
	    $v_command      ="DROP";
	    $v_field        ="st_banner";
	    altertables($v_table,$v_command,$v_field,$v_type);

        }


	$result=mysql_query("INSERT INTO var VALUES ( '49', 'banner_path', 'Scalar', './uploads')");
        if (!$result) {
            echo "Database: [$database] - Insert: failed! <b>Error</b>: " .mysql_errno(). ": ".mysql_error(). "<br>";
        } else {
            echo "Database: [$database] - Insert: <b>OK!</b><br>";
        }

	$result=mysql_query("INSERT INTO var VALUES ( '50', 'banner_store_db', 'Scalar', '0')");
        if (!$result) {
            echo "Database: [$database] - Insert: failed! <b>Error</b>: " .mysql_errno(). ": ".mysql_error(). "<br>";
        } else {
            echo "Database: [$database] - Insert: <b>OK!</b><br>";
        }

	$result=mysql_query("INSERT INTO var VALUES ( '51', 'logging', 'Scalar', '0')");
        if (!$result) {
            echo "Database: [$database] - Insert: failed! <b>Error</b>: " .mysql_errno(). ": ".mysql_error(). "<br>";
        } else {
            echo "Database: [$database] - Insert: <b>OK!</b><br>";
        }

	$result=mysql_query("INSERT INTO msg VALUES ( '1049', 'var_banner_path', '0', 'Path to Banners (if NOT stored in DB)')");
        if (!$result) {
            echo "Database: [$database] - Insert: failed! <b>Error</b>: " .mysql_errno(). ": ".mysql_error(). "<br>";
        } else {
            echo "Database: [$database] - Insert: <b>OK!</b><br>";
        }

	$result=mysql_query("INSERT INTO msg VALUES ( '1050', 'var_banner_store_db', '0', 'Store Banners in DB (!!! SLOW !!!)')");
        if (!$result) {
            echo "Database: [$database] - Insert: failed! <b>Error</b>: " .mysql_errno(). ": ".mysql_error(). "<br>";
        } else {
            echo "Database: [$database] - Insert: <b>OK!</b><br>";
        }

	$result=mysql_query("INSERT INTO msg VALUES ( '1051', 'var_logging', 'Scalar', 'Enable Logging')");
        if (!$result) {
            echo "Database: [$database] - Insert: failed! <b>Error</b>: " .mysql_errno(). ": ".mysql_error(). "<br>";
        } else {
            echo "Database: [$database] - Insert: <b>OK!</b><br>";
        }

        echo "<br><b>phpBazar Tables Updated, Ready ...</b>";

    } elseif ($action=="del") {

	mysql_drop_db($database);
        echo "Database: [$database] - deleted !!!<br>";
	installdb();

    } else {

	echo "Database [$database] does exist !!!<p>";
	echo "<table width=\"400\" border=\"1\"><tr><td><center><br>";
        echo "<form method=\"POST\" action=\"$PHP_SELF\"><input type=\"hidden\" name=\"action\" value=\"up1\"><input type=\"submit\" value=\"UPDATE DB from Version 1.xx to 1.10\"></form>";
	echo "<form method=\"POST\" action=\"$PHP_SELF\"><input type=\"hidden\" name=\"action\" value=\"del\"><input type=\"submit\" value=\"DELETE DB install NEW Version 1.10\"></form>";
	echo "</td></tr></table></center>\n";
    }
    echo "<br><br><input type=\"submit\" value=\"HOME\" onclick=\"javascript:window.location.href='$PHP_SELF'\">&nbsp;<input type=\"submit\" value=\"ADMIN\" onclick=\"javascript:window.location.href='../adm.php'\">&nbsp;<input type=\"submit\" value=\"MEMBERAREA\" onclick=\"javascript:window.location.href='http://www.smartisoft.com/bannerexmember'\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"submit\" value=\"EXIT\" onclick=\"javascript:window.close()\">";
    mysql_close();

} else {

    @mysql_close();

    if ($action=="inst") {

        mysql_connect($server, $db_user, $db_pass) or die ("Database connect Error");
        echo "<b>phpBannerEx Database/Table install</b><p>";
	installdb();
        mysql_close();

    } else {

	echo "Database [$database] does NOT exist !!!<p>";
        echo "<form method=\"POST\" action=\"$PHP_SELF\">\n";

	echo "<table width=\"400\">\n";
	echo "<tr><td colspan=2><font face=\"verdana\" size=\"2\"><br>Check your mySQL Data (edit config.php)<br><br></font></td></tr>\n";
	echo "<tr><td><font face=\"verdana\" size=\"2\">mySQL-Server: </font></td><td><input type=\"text\" name=\"mysqlserver\" value=\"$server\" size=\"20\" readonly><br></td></tr>\n";
	echo "<tr><td><font face=\"verdana\" size=\"2\">mySQL-User: </font></td><td><input type=\"text\" name=\"mysqluser\" value=\"$db_user\" size=\"20\" readonly><br></td></tr>\n";
	echo "<tr><td><font face=\"verdana\" size=\"2\">mySQL-Pass: </font></td><td><input type=\"text\" name=\"mysqlpass\" value=\"$db_pass\" size=\"20\" readonly><br></td></tr>\n";
	echo "<tr><td><font face=\"verdana\" size=\"2\">mySQL-DB: </font></td><td><input type=\"text\" name=\"mysqldb\" value=\"$database\" size=\"20\" readonly><br></td></tr>\n";

        echo "<tr><td colspan=2><hr><center><input type=\"hidden\" name=\"action\" value=\"inst\"><input type=\"submit\" value=\"INSTALL DB V1.10 new\"></form>";
	echo "</center></td></tr></table>\n";
    }
    echo "<br><br><input type=\"submit\" value=\"HOME\" onclick=\"javascript:window.location.href='$PHP_SELF'\">&nbsp;<input type=\"submit\" value=\"EXIT\" onclick=\"javascript:window.close()\">";

}


#  End
#################################################################################################

echo "</body></html>\n";

?>
Return current item: phpBannerEx