<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>《HuCart开源企业建站系统》许可协议</title>
<link rel="stylesheet" type="text/css" href="./install.css" />
</head>
<body>
<div style="height:30px;"></div>
<div class="setuplogo"><img src="./setuplogo2.png" width="465" height="62"  ></div>
<div class="setuptable">
<lu>
<?php

			//安装数据库初始化系统
			 $mysql_hostname = $_REQUEST["mysql_hostname"];
			 $mysql_database = $_REQUEST["mysql_database"];
			 $mysql_username = $_REQUEST["mysql_username"];
			 $mysql_password = $_REQUEST["mysql_password"];
			 $mysql_prefix 	= $_REQUEST["mysql_prefix"];
			
			$user_name 		= $_REQUEST["user_name"];
			$user_pwd 		= $_REQUEST["user_pwd"];
			$user_email 	= $_REQUEST["user_email"];
			
			$reuser_pwd 	= $_REQUEST["reuser_pwd"];
			
			$test_data 		= $_REQUEST["test_data"];//接收测试数据
			
			if( $mysql_hostname != '' and $mysql_database !='' and $mysql_username !='' and $mysql_password !=''  and $user_name !='' and $user_pwd !='' and $reuser_pwd !='' and  $mysql_prefix !='')
			{
				if(function_exists('mysqli_connect')){

					//$connection = new  mysqli( $mysql_hostname, $mysql_username, $mysql_password, $mysql_database  );
					if(empty($mysql_database)){

						$connection = mysqli_connect($mysql_hostname,$mysql_username,$mysql_password);
					}else{

						$connection = mysqli_connect($mysql_hostname,$mysql_username,$mysql_password,$mysql_database);
					}
					//echo '<br>';
					//var_dump($_REQUEST);
					//echo '<br>';
					//var_dump( $connection );
					// Check connection
					if (mysqli_connect_errno($connection))
					{
						echo "Failed to connect to MySQL: " . mysqli_connect_error();
					}

					if($connection){
						$sqlversion = @mysqli_get_server_info();
						if(empty($sqlversion)) $sqlversion='5.0';

						if( $sqlversion >= '4.1')
						{
							mysqli_query("set names 'utf8'");
							mysqli_query("SET COLLATION_CONNECTION='utf8_general_ci'");
							mysqli_query("ALTER DATABASE $mysql_database DEFAULT CHARACTER SET utf8 COLLATE 'utf8_general_ci'");
						}

						if($sqlversion >= '5.0')
						{
							mysqli_query("SET sql_mode=''");
						}


						if(mysqli_select_db( $connection,$mysql_database))
						{
							echo '数据库存在!<br>';

						}else{
							if(!@mysqli_query($connection,"CREATE DATABASE `".$mysql_database."`"))
							{
								echo $installerrors = '创建数据库 "' . $mysql_database . '" 失败! 您的用户名可能没有创建数据库的权限.<br />' . mysqli_error();
							}
							mysqli_select_db( $connection ,$mysql_database);
							echo '创建数据库 '.$mysql_database;
						}

						echo "<li>执行Sql语句！</li>";

						include_once("gv32cms.sql.php");

						//是否安装测试数据
						if($_REQUEST["test_data"]==1)
						{
							// include_once("gv32cms.other.sql.php");
						}

						foreach($sqlgv32cms as $kcmd => $val)
						{

							if(mysqli_query($connection,$val))
							{
								echo "<li>创建数据表".$mysql_prefix.$kcmd."执行成功！</li>";

							}else{
								echo "<li>错误内容: ". mysql_error() ."</li>";
								$errorInfo = false;
							}
						}

						include_once("sqlgv32areadict.sql.php");

						echo '正在执行插入数据.';

						$user_pwdval 	=  md5($user_pwd);
						$use_regtime 	= time();


						$sqlgv32[] = "INSERT INTO `".$mysql_prefix."admins` VALUES (1, '".$user_name."', '".$user_email."', '', '".$user_pwdval."', ".$use_regtime.", 0, 0, '127.0.0.1', '0', '0', '0', 1)";


						foreach($sqlgv32 as $gvkey => $gvval)
						{
							if(mysqli_query($connection,$gvval))
							{
								//echo $gvval."<br>";
							}else{
								echo "<li>错误内容: ".$gvval. mysqli_error() ."</li>";
								$errorInfo = false;
							}
						}

						echo '<li>插入测试数据.</li>';

						include_once("needstr.php");

						//{domain_name} {base_weburl} {document_dir}

						if(getenv('SCRIPT_NAME')!=''){
							$needUrl = getenv('SCRIPT_NAME');
						}else if($_SERVER["REQUEST_URI"]!='')
						{
							$needUrl = $_SERVER["REQUEST_URI"];
						}else if($_SERVER["SCRIPT_NAME"]!='')
						{
							$needUrl = $_SERVER["SCRIPT_NAME"];
						}else if($_SERVER["PHP_SELF"]!='')
						{
							$needUrl = $_SERVER["PHP_SELF"];
						}
						$UrlArray = explode("?",$needUrl);
						$needUrlsrt = $UrlArray[0];

						if(getenv('SERVER_NAME')!='')
						{
							$domain_name = 'http://'.getenv('SERVER_NAME');
						}else if($_SERVER["SERVER_NAME"]!='')
						{
							$domain_name = 'http://'.$_SERVER["SERVER_NAME"];
						}else if($_SERVER["REQUEST_URI"]!='')
						{
							$domain_name = 'http://'.$_SERVER["REQUEST_URI"];
						}

						$base_weburl = str_replace('/install/index.php', '', $needUrlsrt);

						$domain_name = $domain_name.$base_weburl;

						$document_dir = ROOT_PATH;

						$arrvalsql = array('mysql_hostname'=>$mysql_hostname,'mysql_username'=>$mysql_username,'mysql_password'=>$mysql_password,'mysql_database'=>$mysql_database,'mysql_prefix'=>$mysql_prefix,'user_name'=>$user_name ,'url_time' => 3 , 'domain_name' => $domain_name, 'base_weburl' => $base_weburl , 'document_dir' => $document_dir);


						filebuild($typefilename = 'mysql', $arrvalsql  , $configstr  ,$file_name = ROOT_PATH . '/system/config/config.ini.php');

						//ROOT_PATH . 'system/config/config.lock.php'
						filebuild($typefilename = '', ''  , $configstr = base64_encode("www.HuCart.COM")  ,$file_name = ROOT_PATH . '/system/config/hucart.com.install.lock.php');

						echo '<li>HuCart企业建站系统安装完成</li>';
						echo '<li>安装过程中有测试数据请你登录后自行删除!</li>';
						echo '<li><a href="'.$domain_name.'/" class="nextbutton">访问首页</a><br><br></li>';
						echo '<li><a href="'.$domain_name.'/adminsys/" class="nextbutton">访问管理员后台</a><br></li>';




					}else{
						echo '<li>无法连接MySql数据库服务器, 信息:' . mysqli_connect_errno().'</li>';
					}


				}else if(function_exists('mysql_connect'))
				{
						$connection = @mysql_connect($mysql_hostname, $mysql_username, $mysql_password);
						if($connection)
						{
							 $sqlversion = @mysql_get_server_info();
							 if(empty($sqlversion)) $sqlversion='5.0';
								
							 if($sqlversion >= '4.1')
							 {
								mysql_query("set names 'utf8'");
								mysql_query("SET COLLATION_CONNECTION='utf8_general_ci'");
								mysql_query("ALTER DATABASE $mysql_database DEFAULT CHARACTER SET utf8 COLLATE 'utf8_general_ci'");           
							 }
							 
							 if($sqlversion >= '5.0')
							 {
								mysql_query("SET sql_mode=''");
							 }
						
						
							if(mysql_select_db($mysql_database, $connection))
							{
								echo '数据库存在!<br>';
								
								//查询数据库是否存在配置性文件，得删除后再试
								/* //有问题 Table 'sqlgv51data.def_configsys' doesn't exist
								mysql_select_db($mysql_database, $connection);
								
								$sqlQuery = " SELECT COUNT(1) AS CONnum FROM `".$mysql_prefix."configsys`  WHERE cfs_type ='web' ";
							
	   							$numquery = mysql_query($sqlQuery, $connection ) or die ( mysql_error());
 								
								$result_count = mysql_result($numquery, 0) ;
								
								if($result_count >0 )
								{
									echo '数据库中系统配置数信息已经存在，请清除后再试！<a href="./index.php?act=step1" class="nextbutton">返回重新安装</a>';
									exit();
								}*/
								
								
							}else{
								if(!@mysql_query("CREATE DATABASE `".$mysql_database."`"))
								{
									echo $installerrors = '创建数据库 "' . $mysql_database . '" 失败! 您的用户名可能没有创建数据库的权限.<br />' . mysql_error();
										
								}
								
								mysql_select_db($mysql_database, $connection);
							}
									
									echo "<li>执行Sql语句！</li>";
									
									include_once("gv32cms.sql.php");
									
									//是否安装测试数据
									if($_REQUEST["test_data"]==1)
									{
										// include_once("gv32cms.other.sql.php");
									}
									
									foreach($sqlgv32cms as $kcmd => $val)
									{
											
										if(mysql_query($val))
										{
											echo "<li>创建数据表".$mysql_prefix.$kcmd."执行成功！</li>";
										
										}else{
											echo "<li>错误内容: ". mysql_error() ."</li>";
											$errorInfo = false;
										}
									}

									include_once("sqlgv32areadict.sql.php");

									//INSERT INTO `gvd_user` VALUES (2, 'e', 'dsa@16e.com', 'fdsgfd', 'e10adc3949ba59abbe56e057f20f883e', '', '', 0, 1, 0, 1346726916, 0, 0, '', 0, 0, 0, 0, 0, 0, 0, 0, '0', '0', 0);
									echo '正在执行插入数据.';

									$user_pwdval 	=  md5($user_pwd);
									$use_regtime 	= time();
									

									$sqlgv32[] = "INSERT INTO `".$mysql_prefix."admins` VALUES (1, '".$user_name."', '".$user_email."', '', '".$user_pwdval."', ".$use_regtime.", 0, 0, '127.0.0.1', '0', '0', '0', 1)";
									
									
									foreach($sqlgv32 as $gvkey => $gvval)
									{	
										if(mysql_query($gvval))
										{
											//echo $gvval."<br>";
										}else{
											echo "<li>错误内容: ".$gvval. mysql_error() ."</li>";
											$errorInfo = false;
										}
									}

									echo '<li>插入测试数据.</li>';
									
									include_once("needstr.php");
									
									//{domain_name} {base_weburl} {document_dir} 
									
									if(getenv('SCRIPT_NAME')!=''){
										$needUrl = getenv('SCRIPT_NAME');
									}else if($_SERVER["REQUEST_URI"]!='')
									{
										$needUrl = $_SERVER["REQUEST_URI"];
									}else if($_SERVER["SCRIPT_NAME"]!='')
									{
										$needUrl = $_SERVER["SCRIPT_NAME"];
									}else if($_SERVER["PHP_SELF"]!='')
									{
										$needUrl = $_SERVER["PHP_SELF"];
									}
									$UrlArray = explode("?",$needUrl);
									$needUrlsrt = $UrlArray[0];
									
									if(getenv('SERVER_NAME')!='')
									{
										$domain_name = 'http://'.getenv('SERVER_NAME');
									}else if($_SERVER["SERVER_NAME"]!='')
									{
										$domain_name = 'http://'.$_SERVER["SERVER_NAME"];	
									}else if($_SERVER["REQUEST_URI"]!='')
									{
										$domain_name = 'http://'.$_SERVER["REQUEST_URI"];
									}

									$base_weburl = str_replace('/install/index.php', '', $needUrlsrt);
									
									$domain_name = $domain_name.$base_weburl;
																		
									$document_dir = ROOT_PATH;
									
									
									$arrvalsql = array('mysql_hostname'=>$mysql_hostname,'mysql_username'=>$mysql_username,'mysql_password'=>$mysql_password,'mysql_database'=>$mysql_database,'mysql_prefix'=>$mysql_prefix,'user_name'=>$user_name ,'url_time' => 3 , 'domain_name' => $domain_name, 'base_weburl' => $base_weburl , 'document_dir' => $document_dir);


									filebuild($typefilename = 'mysql', $arrvalsql  , $configstr  ,$file_name = ROOT_PATH . '/system/config/config.ini.php');

									//ROOT_PATH . 'system/config/config.lock.php'
									filebuild($typefilename = '', ''  , $configstr = base64_encode("www.HuCart.COM")  ,$file_name = ROOT_PATH . '/system/config/hucart.com.install.lock.php');

									echo '<li>HuCart企业建站系统安装完成</li>';
									echo '<li>安装过程中有测试数据请你登录后自行删除!</li>';
									echo '<li><a href="'.$domain_name.'/" class="nextbutton">访问首页</a><br><br></li>';
									echo '<li><a href="'.$domain_name.'/adminsys/" class="nextbutton">访问管理员后台</a><br></li>';

						}else{
						
							echo '<li>无法连接MySql数据库服务器, 信息:' . mysql_error().'</li>';
						}
					
				}else{
					echo  '<li>网站服务器环境不支持MySql数据库<li>';
				}
			
				
			}else{
				
				echo '<li>信息不完整，请重新填写！<a href="./index.php?act=step4">返回</a> </li>';
			}

?>
</lu>
</div>
</body>
</html>
