<?php
error_reporting(0);
@set_time_limit(3600);
define('ROOT_PATH', str_replace('install/index.php', '', str_replace('\\', '/', __FILE__)));  //首页文件目录 

if(file_exists(ROOT_PATH . 'system/config/hucart.com.install.lock.php'))
{
	require './already.php';
	exit();
}else{

	$act = $_REQUEST["act"];
	switch ($act) 
	{
		case '':
			require './step1.php';
			break;
		case 'step2':
			require './step2.php';
			break;
		case 'step3':
			require './step3.php';
			break;
		case 'step4':
			require './step4.php';
			break;
		case 'step5':
			require './step5.php';
			break;
		case 'step6':
			require './step6.php';
			break;
		case 'step7':
			require './step7.php';
			break;
		case 'step8':
			require './step8.php';
			break;
		case 'step9':
			require './step9.php';
			break;
		default:
			require './step1.php';
			break;
	}
	
	exit();
}


	function sqlquery($sql)
	{
		$re = mysql_query($sql);
		if(!$re){
			$message .= $sql . " \r\n";
			$message .= "错误内容: ". mysql_error() ." \r\n";
			$message .= "时间: ".gmdate('Y-m-d H:i:s', time() + (3600 * 8)). "\r\n";
			$message .= "文件: http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
			echo '<center><font color="#FF0000"><b>数据库访问错误!</b></font><br />
			<input type="button" name="back" value=" 返&nbsp;回 " onclick="history.back();return false;" />		
			</center><BR>';
			exit();
		}else{
			echo "执行成功！<br />";
			//return true;
		}
		
	}
	
	function filebuild($typefilename = 'mysql', $arrval = array(), $contenthtml ='' ,$file_name ='')
	{
		if($typefilename =='mysql'){
			$contenthtml = str_replace("{mysql_hostname}", $arrval["mysql_hostname"], $contenthtml);
			$contenthtml = str_replace("{mysql_username}", $arrval["mysql_username"], $contenthtml);
			$contenthtml = str_replace("{mysql_password}", $arrval["mysql_password"], $contenthtml);
			$contenthtml = str_replace("{mysql_database}", $arrval["mysql_database"], $contenthtml);
			$contenthtml = str_replace("{mysql_prefix}", $arrval["mysql_prefix"], $contenthtml);
			
			$contenthtml = str_replace("{domain_name}",  $arrval["domain_name"] , $contenthtml);
			$contenthtml = str_replace("{base_weburl}",  $arrval["base_weburl"] , $contenthtml);
			
			$contenthtml = str_replace("{document_dir}",  $arrval["document_dir"] , $contenthtml);
			$contenthtml = str_replace("{url_time}",  $arrval["url_time"] , $contenthtml);
			$contenthtml = str_replace("{user_name}",  $arrval["user_name"] , $contenthtml);
		}else{
			$contenthtml = md5("HuCart.COM")." HTTP://www.HuCart.COM ".$contenthtml;
		}
		
		writeToFile($file_name,$contenthtml,$method="w+");
	}

	function writeToFile($file_name,$content,$method="w+")
	{
	
		if($filenum=fopen($file_name,$method)){
			flock($filenum,LOCK_EX);
			$file_data=fwrite($filenum,$content);
			flock($filenum,LOCK_UN);
			fclose($filenum);
			return true;
		}else{
			return false;
		}
	}
	
	?>