<?php
/*******************************************************************************
* Ourphp - CMS建站系统
* Copyright (C) 2023 www.ourphp.net
* 开发者：哈尔滨伟成科技有限公司
*******************************************************************************/
include '../../config/ourphp_code.php';
include '../../config/ourphp_config.php';

function compress_html1($string) {  
	$string = str_replace("\r\n", '', $string); //清除换行符  
	$string = str_replace("\n", '', $string); //清除换行符  
	$string = str_replace("\t", '', $string); //清除制表符  
	$pattern = array (  
		"/> *([^ ]*) *</", //去掉注释标记  
		"/[\s]+/",  
		"/<!--[^!]*-->/",  
		"/\" /",  
		"/ \"/",  
		"'/\*[^*]*\*/'"  
	);  
	$replace = array (  
		">\\1<",  
		" ",  
		"",  
		"\"",  
		"\"",  
		""  
	);  
	return preg_replace($pattern, $replace, $string);  
}

$md = $_POST['md'];
if($md != $ourphp['safecode'])
{
	$ourphpmsg = array("error" => 0);
	echo json_encode($ourphpmsg);
	exit;
}
$i = intval($_POST['installdata']);

//导入数据
$sql = compress_html1(file_get_contents("install_".$i.".sql"));
$sql = rtrim($sql, ";");
$a = explode(";",$sql);
foreach($a as $b){
	$c = $b.";";
	$db -> create($c,2);
}
$db -> close();

$error = 2;
if($i >= intval($_POST['demodata']))
{
	$error = 1;
}
$ourphpmsg = array("error" => $error,"list" => "<p>install_".$i.".sql 导入成功</p>","i" => $i+1);
echo json_encode($ourphpmsg);
exit;
	
?>