<?PHP
//配置部分： 
//注意，如果您没有在后面的注释的地方加上管理员身份验证程序，
//请不要配置正确的数据库用户名和密码！
//采用默认配置运行，程序会给出表单你填写的。

$db_host="localhost";    //数据库服务器
$db_username="dns_f";     //数据库用户名
$db_password="cool88it";         //数据库密码
$db_dbname="dns";          //选择的数据库


//版本
$version=3.4;

error_reporting(1);

set_time_limit(30);

// LOGO 
function logocode(){
return base64_decode(
'R0lGODlhLAFHAOYAAAAAAO/v71OF8SxBrd4IGRswm8iJpRglSGc3iZmZmUtsxaQsWxEZMd7e3sG826OmtlhYWE5y3jpfrC9Cgshe'.
'ef///8CwznaDxGJwu4KP1OAhMJ6n1H19fUpasr29vXKH8y9DptRFWys6cEFSrlRktXuHxXOH79bW1icnJ2B14FBq1qNvnC47gAcH'.
'B2eD7jZHlXVsrk1izo6XzedGUvf39yQvXKquwiQ5pe+Lk0peyto3SObm5kBetmhYqcwULlZ76DxQvMzMzJNPhCI2nUlcxm17y+14'.
'gczR6FtqtjpLrThRpWZmZsMfPT09Paurq9h4i0Jaxmx5vuDk9IghX1mM+OtocltGnJ+Ku2OK99JRaN8SIsXFxX6P5pyn57O74o+a'.
'2OMyP3CC21tx3YKOx9PW5ueapTlSmmN0y2V75zJHjU9hws6jvc11jrGyurG30rMyVxERETZKtlpqwcrR89Swx0BUvr7E55uerpFw'.
'rd8pOsaWtZmZzKy04NFIX1qE8IBcoSH5BAQUAP8ALAAAAAAsAUcAAAf/gBWCg4SFhoeIiYqLjI2Oj5CRkpOUlZaXmJmam5ydnp+g'.
'oaKjiTRSdhsyUUgdSSBDBbGxQyBJHUhRMht2UjSkv8DBwsO/NEcbJR03sLLNzs/NQ0MdJRtHvsTZ2tvcwWQbGK/Q4+TktBgbZNjd'.
'7O3u74XGMh0g5fb34yAdMtfw/v8AQ0nZoKwciBEdSCDBECXKhYcPG0bBgAEJiQ4jRoAQV+5Ghw1SAoocSZKRsTFJoN0YgavEmJcw'.
'x5SYCVFiQ4oUkVgkcbEVR2hJ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AW8A8uL'.
'wEGgwAuMvxu8BzLA7k8SPMHOSqj89BJ30MMZvMEczMAfDMIh7L2h+78m7KsoPMDIe7Tom77Nm8AwvMAMDMRA7MNYnMU+bMUP4AQd'.
'PMREzL79S8IUm8RKvMQprMJOrLxQHMUvPMUj2sEdzMV0LMdfDMbbW8RjfMQlbMaVisYQQsBrzMZt7MZSnMdbAMaKrMiIvL3sK8Z7'.
'zMd9bLHiC8hVIsiDTMgt/JAu/MiPzMk6t7xkPMnWWrSW/C/la74r7LgGLMqu/MrLy8qyXMZdm8qnrDmpDLBdu8u83Mu+zMu5rIi3'.
'PEDBXMzGfMzZOszKPG7IbMvL/MzQHM2YEAgAOw=='.
'');
}
if($HTTP_GET_VARS["action"]=="getlogo"){
    header("Content-type: image/gif");
    header("Content-length: 4753");
    echo logocode();
exit;
}

//Button
function buttoncode(){
return base64_decode(
'R0lGODlhyAARAPcAAP/9f//9fv/9ff/8fP/8e//5ff7w2P7x1P/4e//4fP7w1P7v0P/3e//3ev/sv//xcP3qvv/vb/vnvP/uav/t'.
'bv/pZf/pa//oavnisf/hYv/gXv/fXv/ZmP/fXf/Zlv/YmP/Yl//eXf/cW//dXP/XmP/Xl//VlP/bWf/bWv/aWf/aWP/UjOrVrf/Y'.
'Vv/XUenSq+nSrPDRlOjRp+jPpP/RT//OTP/Ldf/Ke//OS//NS//NSv/MSv/MSf/MSP/LR//LRv/Gef/JRv/KRP/KRv/KRf/JQ//J'.
'Qf/JQv/DcuzHg//EZP/Da//DZf/HPerEfv6/av/DRP/AX/+9Vf+8Xue/dv++Nf+4Sf+4Rf+3Rf+2Uf+2SP+4L/+4Lv+2Ov+3Lf+1'.
'NfqzWdy3dv+1Kv+xQP+zMf+xL/6xNP+rSuKwW/+sLP+pOv+sI/+mK/+hKP6aONijSP6YJP6SG9yaNf6NJP6OGOqRJNmWLfCNEv6H'.
'HfSJGv6GE/OKFNSPJvGJEfWDE96KGsyLIeKGE/CDDtOJGt6FFOqCD9OHF/N+EPN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
'WGbJQw9cdsmlD2CG+cOYZJI5xJlooknEmmwK4eabcMYp55tF1GnnnXjmaecRfPbp55+A8mnEoIQWauihiBL6J5JbxOFfH2z44MKk'.
'LmhgaQeYZqpppiF06umnoIYwwqiklmrqCCKkquqqrKLg6quwxv+Kwgm01kprCrjmquuuKvTq66/ABivssMQWu2uutiarbKyUQgGH'.
'ZpHsYUallmpwwbXYZqvtttx26+234IYr7rjkliuuBeimq+667LbrbrU0sAHtHl9oMMG9EzSgLwL89utvvwkELPDABBcscAEIJ6zw'.
'wgw37PDDEEcs8cQUV2zxwxRk3IK8m/nRBg0VZEwBAQQMYPLJKKMswMost+zyyywHIPPMNNds880zA6Dzzjz37PPPQAetM85EF00z'.
'zEgnnfLSA0QQQQVBwIHdIILo0UYXUGSt5NZcd+3112CHLfbYZJdt9tlom93k2my37fbbTWb9BRx6KGJIEnYUkoggffRqfcffgAcu'.
'+OCEF2744YgnrvjijDfu+OOMCyJIIoG84YQDTshBCCWKdE7J55Q8IvropIsOyemop646JI607nrrjcQue+yM1G777bgvovvuvPfu'.
'++/A74778MQXb/zxyCevfO2ENP8HSQ4EBAA7'.
'');
}
if($HTTP_GET_VARS["action"]=="getbutton"){
    header("Content-type: image/gif");
    header("Content-length: 1677");
    echo buttoncode();
exit;
}

function num_chunk($num){
$num=strrev(chunk_split(strrev($num),3,","));
$num=substr("$num",1);
return $num;
}

function fheader(){
global $_SERVER,$HTTP_POST_VARS;
$logosrc="$_SERVER[PHP_SELF]?action=getlogo";
if($HTTP_POST_VARS["logosrc"]){
	$logosrc=$HTTP_POST_VARS["logosrc"];
	if(!is_file($logosrc)) die("该目录无法写入文件，请检查目录权限！");
}
echo "<html>
<head> 
<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<title>faisunSQL自导入数据库备份程序 — Powerd By faisun</title>
<style type='text/css'>
<!--
body,td {
	font-family: '宋体';
	font-size: 9pt;
}
-->
</style>
</head><body link='#0000FF' vlink='#0000FF' alink='#0000FF'>
 <center>
 <a href='http://faisun.1816.net' target='_blank'><img src='$logosrc' border=0 width=300 height=71></a>
<form name='myform' method='post' action=''>
";
while(list($key,$val)=each($HTTP_POST_VARS)){
	$HTTP_POST_VARS[$key]=$val;
	$$key=$val;
	if(is_array($HTTP_POST_VARS[$key])){
		while(list($key2,$val2)=each($HTTP_POST_VARS[$key])){
			echo "<input name='{$key}[$key2]' value='$val2' type='hidden'>\n";
		}
	}
	else echo "<input name='$key' value='$val' type='hidden'>\n";
}reset($HTTP_POST_VARS);
}
while(list($key,$val)=each($HTTP_POST_VARS)){
	$HTTP_POST_VARS[$key]=$val;
	$$key=$val;
}reset($HTTP_POST_VARS);

if($totalsize){
$totalsize_chunk=num_chunk($totalsize);
}


function ffooter(){
global $version;
echo "
</form>
<font color=red><B>请阅读《<a href='$_SERVER[PHP_SELF]?action=readme' target='_blank'><font color=red>说明文档</font></a>》</B></font><br>
<br>
<B>faisunSQL自导入数据库备份程序 V{$version}</B><br>
使用问题或BUG报告请到<a href='http://faisun.1816.net/bbs/' target='_blank'>天窗社区</a>讨论<br>
本程序&copy;由 <a href='mailto:faisun@sina.com'>faisun</a> 设计 <a href='http://faisun.1816.net' target='_blank'>天窗</a> 提供<br>
免费程序 欢迎宣传、发布
<Br>
E动网PHP+mysql空间100M 75元，速度快，稳定性好。联系QQ：293199 、9015868
</center>
</body></html>
";
}

function fbutton($type="submit",$name="Submit",$value="确定",$script=""){
$imagebg="$_SERVER[PHP_SELF]?action=getbutton";
$height=17;
$margin=5;
$forecolor="#A15309";
$alphacolor=($forecolor=="#123456"?"#654321":"#123456");
echo "<label style='background:url($imagebg) 0 0;'><label style='width:$margin'></label>";
echo "<input type='$type' name='$name' value='$value' style='background:$alphacolor;filter:chroma(color=$alphacolor);color:$forecolor;border:0;height:$height' onfocus='this.blur()' $script></label>";
echo "<label style='background:url($imagebg) 100% 0;height:$height;width:$margin'></label>\n";
}

//说明文档
if($HTTP_GET_VARS["action"]=="readme"){
fheader();
echo "
 <table width='600' border='0' cellspacing='1' cellpadding='3' bgcolor='#1B56C5' align=center>
        <tr bgcolor='#D6DFF7'> 
            <td>
			<center><font color=red><B>说明文档</B></font></center><br>
<br>
<B>导入数据时需要用到外部工具，很不方便而且速度慢、成功率低，怎么办？<br>
数据库太大根本无法导出或导入，怎么办？<br>
faisunSQL 就是为解决以上问题而诞生的。</B>
<br>
<br>
1、本程序为非商业免费程序，为方便广大网友而编写。程序员可以将其整合至系统管理后台等，但请保留开发者的版权信息。<br>
免费的本程序不得未经开发者本人同意而改写源码、整合、或直接应用到收费的系统中发布，请联系 <a href='mailto:faisun@sina.com'>faisun</a> 以获得商业使用权。<br>
<br>
2、本程序只能用于PHP+MySQL系统中备份MySQL的数据。<br>
导出时可以选择下载整个数据库备份（只在数据库比小时使用），或分为多个文件导出并保存在服务器的形式。<br>
多文件时数据文件大小可以自由定义，导出导入都是分页并自动完成，理论上无论多大的数据库，它都可以处理。<br>
<br>
3、本程序导出的文件为完整的PHP文件，导入数据时直接将导出的文件/文件夹上传到服务器，并输入其http路径运行即可，不必辅助外部工具导入。
多文件形式的只要访问您填入的“主文件名.php”（注意填入时不要“.php”扩展名，程序会自动添加）的文件路径即可。
导出的文件包含了您所选定表的结构和数据，并包含了“DROP TABLE”语句。
<br>
<br>
4、简要操作说明：<br>
　　a.如果您不是PHP程序员，本程序开头的“配置部分”请不要更改，否则可能对您的数据安全不利。<br>
如果你有本程序的整合权，为导出数据加了管理员的身份验证后，可以在本程序开头的配置部分设定好配置。<br>
如果程序试图以配置部分的设定连接数据库不成功，则要求检查配置。
提交的表单只作为该次导出数据之用，并不更新本文件的配置部分。<br>
　　b.“导入默认配置”只是设定导入文件的默认设定值，导入文件时仍可以更改这个设定。<br>
　　c.单文件导出时勾选“显示导入过程”会在导入时显示导入日志，但会使导入速度变慢和导入成功率降低。在数据量比较多时建议不要勾选。<br>
　　d.多文件导出时数据的“存放目录”指相对本程序所在的文件夹而言的目录，该目录不存在时程序会自动创建，您必须保证PHP对该目录有写入权（许可设为 777）。<br>
　　e.“主文件名”不必包含扩展名“.php”，但导入时需要输入扩展名。<br>
　　f.多文件导出时为了防止别人偷取您的数据，要求输入导入密码（不是数据库密码）。如果导入时忘记了导入密码，请编辑主文件源文件的开头部分，把 \$usedumppass 的值改为 0 。<br>
　　g.备份时您必须保证您的服务器有足够的空间放置备份文件。备份文件虽然是PHP程序文件，但它对数据进行了一定的优化，总文件大小大概与PHPMyAdmin等备份出来的文件大小相当。<br>
<br>
5、备份好的数据库自导入文件请妥善保存。<br>
<br>
6、由于开发者技术水平或您个人或服务器的原因造成的损失恕不负责。
为了防止因他人修改过本程序或程序的BUG对您数据的安全不利，请到开发者的网站 <a href='http://faisun.1816.net' target='_blank'>http://faisun.1816.net</a> 下载最新版本程序。<br>
<br>
7、版权声明：本程序为 <a href='mailto:faisun@sina.com'>faisun</a> 所开发编写，<a href='http://faisun.1816.net'>天窗</a> 拥有全部版权。
<br>
<br>
<B>谢谢您使用本程序，并欢迎代为宣传、发布。</B>
<br>
<div align=right>faisun &nbsp;&nbsp;&nbsp;&nbsp;<BR>2003年8月 于广州华南理工大学&nbsp;&nbsp;<br>(Email:<a href='mailto:faisun@sina.com'>faisun@sina.com</a> QQ:15242663)</div>

<br>
<br>

			</td>
		</tr>
</table>
";
ffooter();
exit;
}

/* 如果您在开头配置部分填写了正确的配置，您可以在这里加上管理员身份验证 */

// 配置表单
if(!@mysql_connect($db_host,$db_username,$db_password)||!@mysql_select_db($db_dbname)){
fheader();
echo "

    <table width='400' border='0' cellspacing='1' cellpadding='3' bgcolor='#1B56C5' align=center>
        <tr> 
            <td><font color='#FFFFFF' colspan='2'><strong>请检查您的配置</strong></font></td>
        </tr>   
<tr bgcolor='#D6DFF7'><td> 服务器主机：</td><td> <input name='db_host' value='$db_host' type='text'></td></tr>
<tr bgcolor='#D6DFF7'><td> 要导出的数据库：</td><td> <input name='db_dbname' value='$db_dbname' type='text'></td></tr>
<tr bgcolor='#D6DFF7'><td> 数据库用户名：</td><td> <input name='db_username' value='$db_username' type='text'></td></tr>
<tr bgcolor='#D6DFF7'><td> 数据库密码：</td><td> <input name='db_password' value='$db_password' type='password'></td></tr>
</table>
<br>
<input name='action' type='hidden' id='action' value='selecttable'>
";
fbutton('submit','dosubmit','连接');
fbutton('reset','doreset','重置');
ffooter();
exit;
}

if ($HTTP_POST_VARS['action']=="selecttable"){
fheader();
echo "

    <table width='500' border='0' cellspacing='1' cellpadding='3' bgcolor='#1B56C5' align=center>
        <tr> 
            <td colspan='4'><font color='#FFFFFF'><strong>请选择要备份的数据表：</strong></font></td>
        </tr>
        <tr bgcolor='#D6DFF7'> 
            <td width='31%'><strong>表名</strong></td>
            <td width='32%'><strong>注释</strong></td>
            <td width='21%'><strong>大小</strong></td>
            <td width='16%' nowrap><strong>选择</strong><input type='checkbox' name='checkbox' value='' onclick='selrev();'>
			</td>
        </tr>
";
  $result=mysql_query("SHOW TABLE STATUS");
  while ($currow=mysql_fetch_array($result)){
echo "
        <tr bgcolor='#EBEFFC'> 
          <td>$currow[Name]</td>
          <td>$currow[Comment]</td>
            <td>".num_chunk($currow[Data_length])." B</td>
            <td align='center'>
<input name='table[$currow[Name]]' type='checkbox' value='yes' datalength='$currow[Data_length]' checked onclick='getsize()'>
            </td>
        </tr>
";
}

echo "<tr bgcolor='#EBEFFC'>
<td colspan=2><B>目前选择表的总大小：</B></td><td><B><input type=hidden name=totalsize value='0'><label id='totalsizetxt'></label>&nbsp;B</B></td>
<td align=center>反选<input type='checkbox' name='checkbox' value='' onclick='selrev()'></td>
</tr>
      </table>

<br>
<script language='JavaScript'>
<!--
function selrev() {
	with(myform) {
		for(i=0;i<elements.length;i++) {
			thiselm = elements[i];
			if(thiselm.name.match(/table\[\w+\]/))
				thiselm.checked = !thiselm.checked;
		}
	}
	getsize();
}

function getsize(){
 ts=0;
	with(document.myform) {
		for(i=0;i<elements.length;i++) {
			thiselm = elements[i];
			if(thiselm.datalength&&thiselm.checked)
				ts += parseInt(thiselm.datalength);
		}
	totalsize.value=ts=ts.toString();

	i=ts.length;
	ts2='';
	while(i>0){
	  if(ts2)ts2=','+ts2;
	  ts2=ts.substring(i-3,i)+ts2;
	  i-=3;
	}	
	document.all.totalsizetxt.innerHTML=ts2;
	
	}
}
getsize();

-->
</script>
<input name='action' type='hidden' id='action' value='selecttype'>
";
fbutton('submit','dosubmit','下一步',"onclick=getsize()");
fbutton('reset','doreset','重置',"onmouseup=setTimeout('getsize()',100)");
ffooter();
}

if($HTTP_POST_VARS['action']=="selecttype"){
fheader();
if($totalsize>1024*1024) $partsaveck="checked";
else $downloadck="checked";
echo "
<table width='500' border='0' cellspacing='1' cellpadding='3' bgcolor='#1B56C5' align=center>
   <tr> 
     <td><font color='#FFFFFF' colspan='2'><strong>请选择导出方式</strong></font></td>
</tr>
<tr bgcolor='#D6DFF7'><td> 导出方式：</td><td>
<input name='back_type' value='download' type='radio' $downloadck>生成单个文件并下载 (备份的数据量较大时不建议使用)<br>
<input name='back_type' value='partsave' type='radio' $partsaveck>分为多个文件并保存在服务器 
</td></tr>
</table>
<br>

<script language='JavaScript'>
function confirmit(){
	with(myform){
		if(back_type[0].checked && $totalsize>1024*1024 && !confirm(\"您要导出的数据量比较多（{$totalsize_chunk} B），建议选择多文件导出方式。\\n点击“确定”继续导出单文件，“取消”返回更改。\"))
			return false;
	}
	return true;
}
myform.onsubmit=new Function('return confirmit();');
</script>
<input name='action' type='hidden' id='action' value='selectoption'>
";
fbutton('submit','dosubmit','下一步');
fbutton('reset','doreset','重置');
ffooter();
}


if($HTTP_POST_VARS['action']=="selectoption"){

	if($HTTP_POST_VARS['back_type']=="partsave"){
fheader();
echo "
您选择了多文件导出方式，总数据量 $totalsize_chunk 字节。<br><br>

<table width='500' border='0' cellspacing='1' cellpadding='3' bgcolor='#1B56C5' align=center>
   <tr> 
      <td><font color='#FFFFFF' colspan='2'><strong>保存选项：</strong></font></td>
</tr>   
<tr bgcolor='#D6DFF7'><td> 存放目录：</td><td> <input name='dir' value='{$db_dbname}sql' type='text' size=10>(相对本程序所在目录，必须有写入权限)</td></tr>
<tr bgcolor='#D6DFF7'><td> 主文件名：</td><td> <input name='filename' value='sqlback' type='text' size=10>.php (不含扩展名！)</td></tr>
<tr bgcolor='#D6DFF7'><td> 每个数据文件大小：</td><td> <input name='filesize' value='100000' type='text' size=10>(单位 B，1 MB = 1048576 B)</td></tr>
<tr bgcolor='#D6DFF7'><td> 数据导入密码：</td><td> <input name='back_pass' value='' type='password' size=10>(为了安全，导入时必须输入此密码)</td></tr>
<tr bgcolor='#D6DFF7'><td> 确认导入密码：</td><td> <input name='back_pass2' value='' type='password' size=10></td></tr>
</table>
<br>
<table width='500' border='0' cellspacing='1' cellpadding='3' bgcolor='#1B56C5' align=center>
   <tr> 
      <td><font color='#FFFFFF' colspan='2'><strong>导入默认配置（导入时仍可更改）：</strong></font></td>
</tr>   
<tr bgcolor='#D6DFF7'><td> 服务器：</td><td> <input name='back_host' value='$db_host' type='text'></td></tr>
<tr bgcolor='#D6DFF7'><td> 数据库：</td><td> <input name='back_dbname' value='$db_dbname' type='text'></td></tr>
<tr bgcolor='#D6DFF7'><td> 该数据库不存在时自动创建：</td><td> <input name='back_autocreate' value=' checked ' type='checkbox' checked></td></tr>
</table><br>

<script language='JavaScript'>
function confirmit(){
	with(myform){
		if(back_pass.value==''||back_pass.value!=back_pass2.value){
			alert('导入密码不能为空且两次输入密码必须相同。');
			return false;
		}
	}
	return true;
}
myform.onsubmit=new Function('return confirmit();');
</script>
<input name='action' type='hidden' id='action' value='databackup'>
";
fbutton('submit','dosubmit','下一步');
fbutton('reset','doreset','重置');
ffooter();
	}


	if($HTTP_POST_VARS['back_type']=="download"){
fheader();
echo "
您选择了单文件导出方式，总数据量 $totalsize_chunk 字节。<br><br>
	
<table width='500' border='0' cellspacing='1' cellpadding='3' bgcolor='#1B56C5' align=center>
   <tr> 
      <td><font color='#FFFFFF' colspan='2'><strong>单文件导出-导入默认配置（导入时仍可更改）：</strong></font></td>
</tr>   
<tr bgcolor='#D6DFF7'><td> 服务器：</td><td> <input name='back_host' value='$db_host' type='text'></td></tr>
<tr bgcolor='#D6DFF7'><td> 数据库：</td><td> <input name='back_dbname' value='$db_dbname' type='text'></td></tr>
<tr bgcolor='#D6DFF7'><td> 该数据库不存在时自动创建：</td><td> <input name='back_autocreate' value=' checked ' type='checkbox' checked></td></tr>
<tr bgcolor='#D6DFF7'><td> 显示导入过程：</td><td> <input name='back_showlog' value=' checked ' type='checkbox'></td></tr>
</table>
<br>
		<input name='action' type='hidden' id='action' value='databackup'>
";
fbutton('submit','dosubmit','导出');
fbutton('reset','doreset','重置');
ffooter();
	}

}

if($HTTP_POST_VARS['action']=="databackup"){

function escape_string($str){
$str=mysql_escape_string($str);
$str=str_replace('\\\'','\'\'',$str);
$str=str_replace("\\\\","\\\\\\\\",$str);
$str=str_replace('$','\$',$str);
return $str;
}

function sqldumptable($table,$part=0) {
if($part) global $HTTP_POST_VARS,$lastcreate_temp,$tableid;

if(($tableid==0 and $HTTP_POST_VARS[page]==1) or $tableid>$lastcreate_temp or $part==0){
  $dumpstring = "create(\"$table\",\"";

  $dumpstring .= "(";

  $firstfield=1;

  $fields = mysql_query("SHOW FIELDS FROM `$table`");
  while ($field = mysql_fetch_array($fields)) {
    if (!$firstfield) {
      $dumpstring .= ",";
    } else {
      $firstfield=0;
    }
    $dumpstring .= " $field[Field] $field[Type]"; 
    if (!empty($field["Default"])) {
      $dumpstring .= " DEFAULT '$field[Default]'";
    }
		if ($field['Null'] != "YES") {
      $dumpstring .= " NOT NULL";
    }
    if ($field['Extra'] != "") {
      $dumpstring .= " $field[Extra]";
    }
  }
  mysql_free_result($fields);

  $keys = mysql_query("SHOW KEYS FROM `$table`");
  while ($key = mysql_fetch_array($keys)) {
    $kname=$key['Key_name'];
    if ($kname != "PRIMARY" and $key['Non_unique'] == 0) {
      $kname="UNIQUE|$kname";
    }
    if(!is_array($index[$kname])) {
      $index[$kname] = array();
    }
    $index[$kname][] = $key['Column_name'];
  }
  mysql_free_result($keys);

  while(list($kname, $columns) = @each($index)){
    $dumpstring .= ",";
    $colnames=implode($columns,",");

    if($kname == "PRIMARY"){
      $dumpstring .= " PRIMARY KEY ($colnames)";
    } else {
      if (substr($kname,0,6) == "UNIQUE") {
        $kname=substr($kname,7); 
      }

      $dumpstring .= " KEY $kname ($colnames)";

    }
  }

  $dumpstring .= ") ";
  
  $statuses=mysql_query("SHOW TABLE STATUS");
  while($status=mysql_fetch_array($statuses)){
    if($status[Name]==$table){
		$dumpstring .=" Type=$status[Type] COMMENT='$status[Comment]';\");\n\n";
		mysql_free_result($statuses);
		break;
		}
  	else
	   continue;
  }
  if($tableid!=0 and $HTTP_POST_VARS[page]!=1 and $part) $HTTP_POST_VARS[lastcreate]++;
  $HTTP_POST_VARS[lastinsert]=0;
  dealdata($dumpstring);
}

  $rows = mysql_query("SELECT count(*) as count FROM `$table` ");
  $row = mysql_fetch_array($rows);
  $rows = mysql_query("SELECT * FROM `$table` limit $HTTP_POST_VARS[lastinsert],$row[count] ");

  $numfields=mysql_num_fields($rows);
  while ($row = mysql_fetch_array($rows)) {
    $dumpstring = "insert(\"$table\",\"";

    $firstfield=1;

    for ($i=0;$i<$numfields;$i++) {
	
	if($part) $HTTP_POST_VARS[fin]+=strlen($row[$i]); //这个方法计算完成量不是很准确
	
      if (!$firstfield) {
        $dumpstring.=",";
      } else {
        $firstfield=0;
      }

      if (!isset($row[$i])) {
        $dumpstring .= "NULL";
      } else {
        $dumpstring .= "'".escape_string($row[$i])."'";
      }
    }

    $dumpstring .= "\");\n\n";
	
	if($part) $HTTP_POST_VARS[lastinsert]++;
	dealdata($dumpstring);
  }
  mysql_free_result($rows);
}


if($HTTP_POST_VARS[back_type]=="partsave"){////////////////////////   Save Data ////////////////////////////

$current_size=0;
function dealdata($data){
global $HTTP_POST_VARS,$current_size,$tablearr;

$current_size+=strlen($data);
writefile($data);

if($current_size>=intval($HTTP_POST_VARS["filesize"])){
$current_size=0;

writefile("\n ?>");

$HTTP_POST_VARS[page]++;

$finish=intval($HTTP_POST_VARS[fin]/$HTTP_POST_VARS[totalsize]*100);

fheader();
echo "<table width=500  cellspacing='1' cellpadding='3' align=center>
<tr><td><B>faisunSQL正在导出数据……</B></td>
<TR><td width=210 nowrap>
<select size=9>";
for($i=$HTTP_POST_VARS[lastcreate]+1;$i<9;$i++){
	echo "<option></option>\n";
}
while(list($key,$val)=each($tablearr)){
if($key<$HTTP_POST_VARS[lastcreate]){
	echo "<option style='color:#FF0000'>√ $val</option>\n";
}else if($key==$HTTP_POST_VARS[lastcreate]){
	echo "<option selected>-= 以上数据表处理完成 =-</option>
	</select><select size=9>
	<option selected>-= 以下数据表正待处理 =-</option>\n<option>→ $val</option>\n";
}else{
	echo "<option style='color:#666666'>· $val</option>\n";
}

}

echo "</select></td><td valign=top nowrap><BR><BR>正在从数据库'$HTTP_POST_VARS[db_dbname]'中导出数据……
<BR><BR>共有数据 ".num_chunk($HTTP_POST_VARS[totalsize])." 字节，每页导出≥ ".num_chunk(intval($HTTP_POST_VARS[fin]/$HTTP_POST_VARS[page]))." 字节。
<BR><BR>每页生成数据文件≥ ".num_chunk($HTTP_POST_VARS["filesize"])." B ，已生成 ".($HTTP_POST_VARS[page]-1)." 个数据文件。
<BR><BR>本页运行完成！ 正在自动进入 <a href='javascript:myform.submit();'>第 $HTTP_POST_VARS[page] 页</a>……
<BR><BR><BR>估计已完成：≥{$finish}% <table width=250 height=12  border=0 cellspacing=1 cellpadding=0 bgcolor='#1B56C5'><tr><td width='$finish%' bgcolor='#1B56C5'><div></div></td><td width='".(100-$finish)."%' bgcolor='#D6DFF7'><div></div></td></tr></table>
<BR><BR>
</td></tr>
</table>";
ffooter();
echo "
<script language='Javascript'>
	myform.submit();
</script>
";

exit();
}
}


function writefile($data,$method='a'){
global $HTTP_POST_VARS;
$file="$HTTP_POST_VARS[dir]/$HTTP_POST_VARS[filename]_pg$HTTP_POST_VARS[page].php";
$fp=fopen($file,"$method");
flock($fp,2);
fwrite($fp,$data);
}


$HTTP_POST_VARS["logosrc"]="$dir/{$filename}_faisunsqllogo.gif";
if(!$HTTP_POST_VARS[lastcreate]) $HTTP_POST_VARS[lastcreate]=0;
if(!$HTTP_POST_VARS[lastinsert]) $HTTP_POST_VARS[lastinsert]=0;
if(!$HTTP_POST_VARS[page]) $page=$HTTP_POST_VARS[page]=0;
$lastcreate_temp=$HTTP_POST_VARS[lastcreate];
$tablearr=array();

while (count($table)&&list($key,$val)=each($table)) {
  if ($val=="yes") {
	$tablearr[]=$key;
  }
}

if(!is_dir("$dir") and !@mkdir("$dir",0777)){
fheader();
echo "
<BR><BR><BR><center>目录'$dir'不存在且不能自动创建！请检查目录权限（权限为 777 方可写文件）。</center><BR><BR><BR>
";
ffooter();
exit;
}

//是否有多余的文件
$dfileNo=0;
$open=opendir($dir);
$delhtml="";
while($afilename=readdir($open) and !$HTTP_POST_VARS[filedeled]){
	$checked="";
	if(eregi("^{$filename}_pg[0-9]+\.php$",$afilename) or $afilename=="{$filename}.php" or $afilename=="{$filename}_faisunsqllogo.gif"){
		$checked="checked";
	}if(is_file("$dir/$afilename")){
			$delhtml.="
	        <tr bgcolor='#EBEFFC'> 
	          <td>$afilename</td>
 	         <td>".date("Y-m-d",filectime("$dir/$afilename"))."</td>
  	          <td>".filesize("$dir/$afilename")." B</td>
   	         <td align='center'>
				<input name='dfile[$dfileNo]' type='checkbox' value='$dir/$afilename' $checked>
     	       </td>
     	   </tr>
			";
		$dfileNo++;
	}
}


if($dfileNo){
$HTTP_POST_VARS[filedeled]=1;
fheader();
echo "
'$dir/'中以下文件已存在，它们可能被覆盖或成为额外的文件。<br>
您可以有选择地删除它们或返回上一步重新设定：<br>

<table width='500' border='0' cellspacing='1' cellpadding='3' bgcolor='#1B56C5' align=center>
        <tr> 
            <td colspan='4'><font color='#FFFFFF'><strong>选择要删除的文件：</strong></font></td>
        </tr>
        <tr bgcolor='#D6DFF7'> 
            <td width='31%'><strong>文件名</strong></td>
            <td width='32%'><strong>修改日期</strong></td>
            <td width='21%'><strong>大小</strong></td>
            <td width='16%' nowrap><strong>选择</strong><input type='checkbox' name='checkbox' value='' onclick='selrev();'>
			</td>
        </tr>
$delhtml
";

echo "
</table>
<br>

<script language='JavaScript'>
<!--
function selrev() {
	with(myform) {
		for(i=0;i<elements.length;i++) {
			thiselm = elements[i];
			if(thiselm.name.match(/dfile\[\w+\]/))
				thiselm.checked = !thiselm.checked;
		}
	}
}
</script>
";
fbutton('submit','dosubmit','删除并继续');
fbutton('reset','doreset','重置');
fbutton('button','dogoback','返回修改','onclick=\'history.back();\'');
ffooter();
exit;
}

//删除多余文件
if($HTTP_POST_VARS[filedeled]==1){
while(list($key,$val)=each($dfile)){
	if($val) unlink($val);
}
}
$HTTP_POST_VARS[filedeled]=2;

if($HTTP_POST_VARS[page]==0){
//写入图片
$fp=fopen($HTTP_POST_VARS["logosrc"],"w");
flock($fp,2);
fwrite($fp,logocode());
fclose($fp);

$HTTP_POST_VARS[page]=1;
fheader();
echo "<table width='400' border='0' cellspacing='1' cellpadding='3'  bgcolor='#1B56C5'>
<tr><td><font color='#FFFFFF'><strong>目录权限正确</strong></font></td></tr>
	<tr bgcolor='#D6DFF7'> 
		<td><br>
经测试，该目录可以写入文件，LOGO图片已成功写入。<br>
下面开始导出数据并保存在服务器中。<br><br>
导出过程中可能会出现运行超时，<br>
在那种情况下，请刷新本页并点击“重试”重新发送信息，<br>
即可继续导出。<br><br>
		</td>
	</tr>
</table><br>
";
fbutton('submit','dosubmit','继续导出');
ffooter();
exit;
}

writefile("<? \n","w");

	for($i=$HTTP_POST_VARS[lastcreate];$i<count($tablearr);$i++){
		 $tableid=$i;
		 sqldumptable($tablearr[$i],1);
	}


//结束最后文件
$data="
echo '<center><BR><BR><BR><BR>完成。所有数据都已经导入数据库中。</center></body></html>';
exit;
?>
";
writefile("$data");

//写入引导文件
$data='<?

$usedumppass=1;  //是否使用导入密码。如果您忘记了导入密码，请把值改为 0 。

set_time_limit(30);
while(list($key,$val)=each($HTTP_POST_VARS)){
	$$key=$val;
}reset($HTTP_POST_VARS);
?><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>faisunSQL 数据库自导入程序 — Powerd By faisun</title>
<style type="text/css">body,td {font-family: "宋体";font-size: 10.8pt;}</style></head>
<body link="#0000FF" vlink="#0000FF" alink="#0000FF">
<center><a href="http://faisun.1816.net" target="_blank"><img src="'.$filename.'_faisunsqllogo.gif" border=0 width=300 height=71></a><br>
<font color=red>本文件由 faisun 编写的 <a href="http://faisun.1816.net" target="_blank">faisunSQL自导入数据库备份程序</a> 生成</font><HR size=1>
</center><script language=javascript>noerrer=true;</script>
<?
if(!$HTTP_POST_VARS["action"]){
?>
<form name="configform" method="post" action="">
<table width="400" border="0" bgcolor="#1B56C5" align=center>
<tr><td><font color="#FFFFFF"><strong>导入数据库配置</strong></font></td></tr>
<tr bgcolor="#D6DFF7"><td>
　服务器：<input name="db_host" value="'.$back_host.'" type="text"><br>
　数据库：<input name="db_dbname" value="'.$back_dbname.'" type="text"><br>
　该数据库不存在时自动创建：<input name="db_autocreate" value="1" type="checkbox" '.$back_autocreate.'><br>
　用户名：<input name="db_username" value="" type="text"><br>
　密　码：<input name="db_password" value="" type="password"><br>
　导入密码：<input name="db_pass" value="" type="password">
        <br>
<tr><td align=center>
<input name="action" type="submit" value=" 导入 ">
</td></tr></table></form></body></html>
<?
exit;
}
if(md5($db_pass)!="'.md5($back_pass).'" and $usedumppass) die("导入密码不正确！如果您忘记了导入密码，请把本源文件开头的 \$usedumppass 的值改为 0 。");
@mysql_connect($db_host,$db_username,$db_password) or die("<BR><BR><center>不能连接服务器！请返回检查您的配置。</center>");
if(!@mysql_select_db($db_dbname)){
	if(!$db_autocreate){echo "<BR><BR><center>数据库[{$db_dbname}]不存在！请返回检查您的配置。</center>";exit;	}
	if(!mysql_query("CREATE DATABASE `$db_dbname`")){echo "<BR><BR><center>数据库[{$db_dbname}]不存在且自动创建失败！请返回检查您的配置。</center>";exit;}
	mysql_select_db("$db_dbname");
}
function query($sql){
  if(!mysql_query($sql)) echo "<BR><BR><font color=red>MySQL语句错误！您可能发现了程序的BUG！<a href=\"mailto:faisun@sina.com\">请报告开发者。</a>
  								<BR>语句：<XMP>$sql</XMP>错误信息： ".mysql_error()." </font><script language=javascript>noerrer=false;</script>" ;
}
function create($table,$sql){
query("DROP TABLE IF EXISTS `$table`;");
query("CREATE TABLE `$table` ".$sql);
}
function insert($table,$data){
query("INSERT INTO `$table` VALUES ($data);");
}

if(!$HTTP_POST_VARS[loadpage]){$HTTP_POST_VARS[loadpage]=1;}
$totalpage='.$HTTP_POST_VARS[page].';
include("'.$filename.'_pg$HTTP_POST_VARS[loadpage].php");
echo "<center><form name=myform  method=\'post\' action=\'\'>";
$HTTP_POST_VARS[loadpage]++;
while(list($key,$val)=each($HTTP_POST_VARS)){
echo "<input name=\'$key\' value=\'$val\' type=\'hidden\'>\n";
}
echo "<BR><BR>正在导入数据到数据库\'$HTTP_POST_VARS[db_dbname]\'……<BR><BR>本页运行完成！ 正在自动进入<a href=\'javascript:myform.submit();\'>第 $HTTP_POST_VARS[loadpage] 页</a>，共 $totalpage 页……
<script language=\'Javascript\'>
if(noerrer)myform.submit();
</script>
</form></center>
";
?>
<body></html>
';

$file="$dir/{$filename}.php";
$fp=fopen($file,"w");
flock($fp,2);
fwrite($fp,$data);
fclose($fp);

fheader();
echo "
<BR><BR><BR><BR><BR><BR><center>完成。
<BR><BR>数据库'$db_dbname'已全部保存到文件夹'$dir'中，共 $page 页，".($page+2)." 个文件。
<BR><BR>将此文件夹置于服务器可访问目录，并运行'$filename.php'即可将数据导入。</center><BR><BR><BR>
";
ffooter();
exit;

}else if($HTTP_POST_VARS[back_type]=="download"){////////////////////////   Sent Data ////////////////////////////

function dealdata($data){
echo "$data";
}
	header("Content-disposition: filename=$db_dbname(".date("Ymj",time()).")_faisunsql.php");
	header("Content-type: unknown/unknown");

echo '<?
set_time_limit(30);
function getmicrotime(){ 
    list($usec, $sec) = explode(" ",microtime()); 
    return ((float)$usec + (float)$sec); 
    } 
$time_start = getmicrotime();
while(list($key,$val)=each($HTTP_POST_VARS)){
	$$key=$val;
}reset($HTTP_POST_VARS);
?>
<html><head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>faisunSQL 数据库自导入程序 — Powerd By faisun</title><style type="text/css">body,td {font-family: "宋体";font-size: 10.8pt;}</style></head>
<body link="#0000FF" vlink="#0000FF" alink="#0000FF">
<center>
<font color=red>本文件由 faisun 编写的 <a href="http://faisun.1816.net" target="_blank">faisunSQL自导入数据库备份程序</a> 生成</font><HR size=1>
</center>
<?
if(!$HTTP_POST_VARS["action"]){
?>
<form name="configform" method="post" action=""><table width="400" border="0" bgcolor="#1B56C5" align=center>
<tr><td><font color="#FFFFFF"><strong>导入数据库配置</strong></font></td></tr>
<tr bgcolor="#D6DFF7"><td>
　服务器：<input name="db_host" value="'.$back_host.'" type="text"><br>
　数据库：<input name="db_dbname" value="'.$back_dbname.'" type="text"><br>
　该数据库不存在时自动创建：<input name="db_autocreate" value="1" type="checkbox" '.$back_autocreate.'><br>
　显示导入过程：<input name="back_showlog" value="1" type="checkbox" '.$back_showlog.'><br>
　用户名：<input name="db_username" value="" type="text"><br>
　密　码：<input name="db_password" value="" type="password"><br>
<br>
<tr><td align=center>
<input name="action" type="submit" value=" 导入 ">

</td></tr></table></form></body></html>
<?
exit;
}

@mysql_connect($db_host,$db_username,$db_password) or die("<BR><BR><center>不能连接服务器！请返回检查您的配置。</center>");
if(!@mysql_select_db($db_dbname)){
	if(!$db_autocreate){echo "<BR><BR><center>数据库[{$db_dbname}]不存在！请返回检查您的配置。</center>";exit;	}
	if(!mysql_query("CREATE DATABASE `$db_dbname`")){echo "<BR><BR><center>数据库[{$db_dbname}]不存在且自动创建失败！请返回检查您的配置。</center>";exit;}
	else if($back_showlog) echo "<BR><BR>创建数据库[{$db_dbname}]...OK.";
	mysql_select_db("$db_dbname");
}
function query($sql){
  if(!mysql_query($sql)) echo "<BR><font color=red>MySQL语句错误！您可能发现了程序的BUG！<a href=\"mailto:faisun@sina.com\">请报告开发者。</a>
  								<BR>语句：<XMP>$sql</XMP><BR>错误信息： ".mysql_error()." </font>" ;
}
function create($table,$sql){
global $back_showlog,$firstinsert;
if($back_showlog){$firstinsert=1;echo "\n<BR><BR>创建数据表[$table]...";}
query("DROP TABLE IF EXISTS `$table`;");
query("CREATE TABLE `$table` ".$sql);
}
function insert($table,$data){
global $back_showlog,$firstinsert;
if($back_showlog and $firstinsert){$firstinsert=0; echo "\n<BR>添加数据到数据表[$table]...";}
query("INSERT INTO `$table` VALUES ($data);");
}

';

////// 开头部分结束 ////////
	while (count($table)&&list($key,$val)=each($table)) {
		if ($val=="yes") {
		  sqldumptable($key,0);
		}
    }

echo "
\$time_end = getmicrotime();\$time = \$time_end - \$time_start;
echo \"<BR><BR>完成。所有数据已成功导入到 [\$db_dbname]，运行时间 \$time 秒。\";
?></body></html>";

exit;
}

}
?>