Location: PHPKode > projects > FiForms Framework > FiForms/scripts/importdb_final.php
<?php
/*  This file is part of the FiForms Framework
    Copyright (C) 2003-2008 by Daniel McFeeters,
    Licensed under the GNU GPL. 
    See LICENSE.txt for details. 
*/
    $checkpass = TRUE; $noclose= TRUE; require_once('authenticate.php');
?>
<html>
<head>
<title>FiForms Database Import</title>
</head>
<body>

<?php 


if(isset($_FILES['sql']['tmp_name'])) // && file_exists($FIFORMS_CONFIG['APP_BASE'].$FIFORMS_CONFIG['APP_NAME']."/sql/".$_POST['selection']))
{ 
   $sql = file_get_contents($_FILES['sql']['tmp_name']);
   if(trim($sql))
   {
       echo "<p>Using Uploaded SQL File</p>";
   }
}
if(!trim($sql) && $_POST['selection'] != "***Select a file***" && file_exists($FIFORMS_CONFIG['APP_BASE'].$FIFORMS_CONFIG['APP_NAME']."/sql/".$_POST['selection']))
{
   $sql = file_get_contents($FIFORMS_CONFIG['APP_BASE'].$FIFORMS_CONFIG['APP_NAME']."/sql/".$_POST['selection']);
   echo "<p>Using ".$_POST['selection']." on the server.</p>";
}
if(!trim($sql))
{
  ?>
   No File Available.<br />
<a href="javascript:history.go(-2);">Return</a>
</body>
</html>
      <?php
      die();
}

if(isset($FIFORMS_CONFIG['AVAILABLE_APP_INFO'][$FIFORMS_CONFIG['APP_NAME']]['appdatabase']))
{
    mysql_select_db($FIFORMS_CONFIG['AVAILABLE_APP_INFO'][$FIFORMS_CONFIG['APP_NAME']]['appdatabase']);
    if($_POST['wipealltables'])
    {
        $tbrslt = mysql_query('SHOW TABLES;');
        mysql_query("SET FOREIGN_KEY_CHECKS = 0");
        while($tablename = mysql_fetch_row($tbrslt))
        {
            echo "Dropping table $tablename[0]";
            mysql_query("DROP TABLE $tablename[0]") or die(mysql_error());
            echo " Done<br />";
        }
        mysql_query("SET FOREIGN_KEY_CHECKS = 1");
    }
}
$qarray = explode(";",$sql);
//print_r($sql);
$lastbuffer = "";
foreach($qarray as $line)
{
    $lstat = count_chars($lastbuffer.$line);
    //print_r($lstat); die();
    if($lstat[39] % 2 == 1)  //34
    {
        $lastbuffer .= $line.";";
    }
    else if(trim($line) != '')
    {
        mysql_query($lastbuffer.$line) or die(mysql_error()."<br /><a href=\"javascript:history.go(-1);\">Return</a>");
        $lastbuffer = "";
    }
}
echo "<br />Database Import Successful.";
//mysql_close();
?>
<br />
<a href="javascript:history.go(-2);">Return</a>
</body>
</html>
Return current item: FiForms Framework