<?php 

//禁止直接访问
!defined('IN_SYSTEM') && exit('Access Denied');

//来路判断
if($AdminLogin->CheckHttpReferer(WEB_URL.'/admin/index.php?location=dbmanage') == true){
	//获取get文件名
	if(isset($_GET['filename'])){
		$filename = $_GET['filename'];	//过滤方法待写
		//过滤处理
		$filename = ToUtf8($filename);	//转换编码格式
		$filename = DeleteHtml($filename);	//删除HTML代码
		$filename = strip_tags($filename);	//第二道过滤去除标签
		$filename = trimall($filename);		//去除空格
		//安全验证
		if(preg_match("[([0-9]{14})(_)([A-Za-z0-9]{10})]", $filename) == false){
			$AdminShowMessage = AdminShowMessage('非法提交！', WEB_URL.'/admin/index.php?location=dbmanage', 0, '#F00');
		}
		//读取备份文件目录
		$backup_dir = scandir(SITE_DIR."data/backup/".$filename);
		echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
		//要导入的数据库
		$BackupDB = new DBManage ($DbHostAddress, $DbUserName, $DbPassword, $DbName, 'utf8' );
		$return = true;
		//循环导入每一个文件
		foreach($backup_dir as $v){
			if($v !== '.' && $v !== '..'){
				if(is_file(SITE_DIR."data/backup/".$filename."/".$v)){
					$full_url = SITE_DIR."data/backup/".$filename."/".$v;
					if($BackupDB->_import($full_url) == false){
						$return = false;
					}
				}
			}	
		}
		if($return == true){
			$AdminShowMessage = AdminShowMessage('数据导入成功！', WEB_URL.'/admin/index.php?location=dbmanage', 1);
		}
		else{
			$AdminShowMessage = AdminShowMessage('导入失败！请检查原因！', WEB_URL.'/admin/index.php?location=dbmanage', 0, '#F00');
		}
	}
}
else{
	$AdminShowMessage = AdminShowMessage('来路不正确！', WEB_URL.'/admin/index.php?location=dbmanage', 0, '#F00');	//来路不正确
}

?>