<!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>《GV32-CMS开源企业建站系统》许可协议</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" scr="" ></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('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());
 								
								$resultCount = mysql_result($numquery, 0) ;
								
								if($resultCount >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 `gv32_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."user` VALUES (1, 'e', '".$user_email."', '".$user_name."', '".$user_pwdval."','', '', 0, 1, 0, $use_regtime, 0, 0, '', 0, 0, 0, 0, 0, 0, 0, 0, '0', '0', 0)";
									$sqlgv32[] = "INSERT INTO `".$mysql_prefix."userdetail` VALUES (1, 0, '', '', 0, 0, 0, 0, '0', 0, '', '', '', '', '', NULL, 0, 0, 0, NULL, NULL)";

									
									foreach($sqlgv32 as $gvkey => $gvval)
									{
											
										if(mysql_query($gvval))
										{
											//echo ".";
										}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.gv32.com")  ,$file_name = ROOT_PATH . '/system/config/gv32.com.install.lock');
									
									echo '<li>GV32-CMS企业建站系统安装完成</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>信息不完整，请重新填写！</li>';
			}

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