
<?php

$v=$_GET["v"];
$u1=$_POST["u1"];
$u2=$_POST["u2"];
$u3=$_POST["u3"];
$u4=$_POST["u4"];
if($v==""){
 require_once(dirname(__FILE__)."/configs/config.php");
}


if ($v=="1"){
$op=fopen(dirname(__FILE__)."/configs/config.php",'w');
$value="<?php".chr(13).chr(10)."//数据库连接配置文件.".chr(13).chr(10);
$value=$value."$"."host=".""."\"".$u1."\"".";   //数据库连接地址".chr(13).chr(10);
$value=$value."$"."sqluser="."\"".$u2."\"".";   //数据库用户名".chr(13).chr(10);
$value=$value."$"."sqlpass="."\"".$u3."\"".";   //数据库密码".chr(13).chr(10);
$value=$value."$"."sqldb="."\"".$u4."\"".";   //数据库文件名".chr(13).chr(10);
$value=$value."?>";
fwrite($op,$value);
fclose($op);

require_once(dirname(__FILE__)."/configs/config.php");
$conn=mysql_connect($host,$sqluser,$sqlpass);
if(!$conn)
{
   echo "<script>alert('数据库连接失败，请检查连接参数从新填写，或联系空间供应商！');window.location.href='setup.php?u1=".$u1."&u2=".$u2."&u3=".$u3."&u4=".$u4."';</script>";
   exit;
}
$selectdb=mysql_select_db($sqldb,$conn);
if(!$selectdb)
{
   echo "<script>alert('数据库名错误，请检查连接参数从新填写，或联系空间供应商！');window.location.href='setup.php?u1=".$u1."&u2=".$u2."&u3=".$u3."&u4=".$u4."';</script>";
   exit;
}else{
mysql_close();
      echo "<script>;window.location.href='setup.php?v=2';</script>";
   exit;
}

}
if($v=="2"){


require_once(dirname(__FILE__)."/configs/config.php");

$conn=mysql_connect($host,$sqluser,$sqlpass);
mysql_select_db($sqldb,$conn);
mysql_query("set names 'gbk'"); 
if(mysql_query("show tables like 'cbody'")){
mysql_query("drop table cbody,cid,comm,config,ad,user"); 
}

$sql = "CREATE TABLE `cbody` (
  `id` int(11) NOT NULL auto_increment,
  `cid` int(11) NOT NULL default '0',
  `c` text NOT NULL,
  `sj` datetime NOT NULL default '0000-00-00 00:00:00',
  `sh` tinyint(1) NOT NULL default '0',
  `h` int(11) NOT NULL default '0',
  `t` varchar(255) NOT NULL,
  `pid` int(11) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE utf8_general_ci;
";
mysql_query($sql) or die(mysql_error());
$sql=NULL;

$sql="CREATE TABLE `cid` (
  `id` int(11) NOT NULL auto_increment,
   `cid` varchar(255) NOT NULL default '',
  `sh` tinyint(1) NOT NULL default '0',
   `pid` int(11) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE utf8_general_ci;
";

mysql_query($sql) or die(mysql_error());
$sql=NULL;

mysql_query("INSERT INTO cid(cid) VALUES ('广告信息');") or die(mysql_error());
mysql_query("INSERT INTO cid(cid) VALUES ('招聘信息');") or die(mysql_error());
mysql_query("INSERT INTO cid(cid) VALUES ('加盟商家');") or die(mysql_error());
mysql_query("INSERT INTO cid(cid) VALUES ('房产信息');") or die(mysql_error());

$sql="CREATE TABLE `comm` (
  `id` int(11) NOT NULL auto_increment,
  `cid` int(11) NOT NULL default '0',
  `c` text NOT NULL,
  `u` varchar(255) NOT NULL default '',
  `sj` datetime NOT NULL default '0000-00-00 00:00:00',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE utf8_general_ci;
";
mysql_query($sql) or die(mysql_error());
$sql=NULL;
$sql="CREATE TABLE `ad` (
  `id` int(11) NOT NULL auto_increment,
  `cid` int(11) NOT NULL default '0',
  `s` int(11) NOT NULL default '0',
  `u` varchar(255) NOT NULL default '',
   `h` varchar(255) NOT NULL default '',
  `img` varchar(255) NOT NULL default '',
  `sj` datetime NOT NULL default '0000-00-00 00:00:00',
  `esj` datetime NOT NULL default '0000-00-00 00:00:00',
  
  PRIMARY KEY  (`id`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE utf8_general_ci;
";

mysql_query($sql) or die(mysql_error());
$sql=NULL;

$sql="CREATE TABLE `user` (
  `id` int(11) NOT NULL auto_increment,
   `user` varchar(255) NOT NULL default '',
   `pass` varchar(255) NOT NULL default '',
   `email` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE utf8_general_ci;
";

mysql_query($sql) or die(mysql_error());
$sql=NULL;
$sql="CREATE TABLE `config` (
  `id` int(11) NOT NULL default '0',
  `s_name` varchar(255) NOT NULL default '',
  `s_url` varchar(255) NOT NULL default '',
  `s_user` varchar(255) NOT NULL default '',
  `s_pass` varchar(255) NOT NULL default '',
  `s_seo` varchar(255) NOT NULL default '',
  `s_ss` varchar(255) NOT NULL default '',
 
  `add_c` tinyint(1) NOT NULL default '0',
  `add_i` tinyint(1) NOT NULL default '0',
   `s_tj` varchar(255) NOT NULL default '',
  `s_end` varchar(255) NOT NULL default '',
  `s_r` tinyint(1) NOT NULL default '0',
  `ca_che` tinyint(1) NOT NULL default '0',
 `s_logo` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM DEFAULT CHARSET=utf8 COLLATE utf8_general_ci;
";
mysql_query($sql) or die(mysql_error());


mysql_query("INSERT INTO config( `s_name` , `s_url` , `s_user` , `s_pass` , `s_seo` , `s_ss` , `add_c` , `add_i` ,`s_end`,`s_logo`) VALUES ('随风PHP分类信息', '', 'admin', '123456', '随风分类信息,地方分类信息,分类信息门户', '随风分类信息程序是终身免费升级、使用，操作简单、使用、方便、简洁，适合做各类分类信息网、地方分类信息，地方信息港等.', 0,0,'声明：本站信息均来自于网络或网友自行发布，仅供参考，请网友慎重选择，出现任何法律及连带责任于本站无关！
','logo.gif')") or die(mysql_error());

mysql_query("insert into cbody(cid,c,sj,sh,h,t) values(0,'恭喜，当您看到这条信息的时候，说明您的站已经安装成功！ 随风PHP分类信息系统','".date("Y-n-j G:i:s")."',0,'0','恭喜，当您看到这条信息的时候，说明您的站已经安装成功！ 随风PHP分类信息系统')") or die(mysql_error());

mysql_close();
 echo "<script>;window.location.href='setup.php?v=3';</script>";
exit;
}
?> 
<!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=gb2312" />
<title>随风分类信息安装页面</title>
<meta http-equiv="x-ua-compatible" content="ie=7" />
<link type="text/css" rel="stylesheet" href="templates/a/comm2.css" />
<style type="text/css">
<!--
.STYLE1 {font-size: 14px}
.STYLE3 {font-size: 12px}
.STYLE4 {PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 10px; MARGIN: 0px auto; WIDTH: 98%; PADDING-TOP: 0px; clear: both;}
.STYLE5 {BORDER-TOP: #bad1de 1px solid; BORDER-LEFT: #bad1de 1px solid; LINE-HEIGHT: 18px; BORDER-BOTTOM: #bad1de 1px solid; HEIGHT: 18px; border-right: #bad1de 1px solid;}
.STYLE6 {color: #06C; font-weight: bold; }
.STYLE7 {
	font-size: 16px
}
.STYLE8 {color: #FF0000}
-->
</style>
</head>

<body>


<!-- Copyright ?2005. Spidersoft Ltd -->
<style>
A.applink:hover {border: 2px dotted #DCE6F4;padding:2px;background-color:#ffff00;color:green;text-decoration:none}
A.applink       {border: 2px dotted #DCE6F4;padding:2px;color:#2F5BFF;background:transparent;text-decoration:none}
A.info          {color:#2F5BFF;background:transparent;text-decoration:none}
A.info:hover    {color:green;background:transparent;text-decoration:underline}
</style>
<DIV id="pageMain">
  <div class="status"><a href="/" target="_blank">随风PHP分类信息</a>&gt; 安装程序</div>
<Div id="main">

<div class="tit STYLE1">随风分类信息<?=$lwan?>安装页面</div>
<div class="conBody">
<div class="h" style="height:28px"></div>
<div align="center" style="padding:20px;color:#F00;font-size:14px"><?
if ($host!="") echo "您已经安装过此程序，如继续安装，将删除以前全部数据，慎重！"; 
?></div>

<script language="javascript">
function checkform()
{


	if (document.f1.u1.value == "")
	{
		alert("数据库连接地址不可以为空...    ");
		document.f1.u1.focus();
		return false;
	}else 	if (document.f1.u2.value == "")
	{
		alert("数据库用户名不可以为空...    ");
		document.f1.u2.focus();
		return false;
	}else 	if (document.f1.u3.value == "")
	{
		alert("数据库密码不可以为空...    ");
		document.f1.u3.focus();
		return false;
	}else 	if (document.f1.u4.value == "")
	{
		alert("数据库名不可以为空...    ");
		document.f1.u4.focus();
		return false;
	}

}

</script>
<?
if($v!="3"){
$a = $a=="" ? 1 : 2; 
$u1=$_GET["u1"]=="" ? $host : $_GET["u1"];
$u2=$_GET["u2"]=="" ? $sqluser : $_GET["u2"];
$u3=$_GET["u3"]=="" ? $sqlpass : $_GET["u3"];
$u4=$_GET["u4"]=="" ? $sqldb : $_GET["u4"];
?><table width="600" height="254" border="0" align="center" cellpadding="8" cellspacing="1" bordercolor="#EEEEEE" bgcolor="#EEEEEE" class="aset24">
<form name="f1" method="post" action="setup.php?v=1" >
<tr>
  <td colspan="2" bgcolor="#FFFFFF"><div align="center" class="STYLE6">MYSQL 数据库参数配置</div></td>
  </tr>
<tr> 
<td width="378" height="56" bgcolor="#FFFFFF"><div align="center" class="STYLE6">数据库地址<span class="STYLE3">*</span></div></td>
<td width="374" bgcolor="#FFFFFF"><div align="center" class="STYLE6"><span class="STYLE4">
  <input name="u1" class="STYLE5" id="u1" value="<?=$u1?>" size="30" />
  例：</span>127.0.0.1</div></td>
</tr>

<tr>
  <td valign="top" bgcolor="#FFFFFF" style="padding-top:5px"><span class="STYLE6">&nbsp;&nbsp;
    </span>
    <div align="center" class="STYLE6">数据库用户<span class="STYLE3">*</span></div></td>
  <td valign="top" bgcolor="#FFFFFF"><div align="center" class="STYLE6"><span class="STYLE4">
    <input name="u2" class="STYLE5" id="u2" size="30" value="<?=$u2?>"/>
  例：</span>root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div></td>
</tr>
<tr>
  <td valign="top" bgcolor="#FFFFFF" style="padding-top:5px"><span class="STYLE6">&nbsp;&nbsp; </span>
      <div align="center" class="STYLE6">数据库密码<span class="STYLE3">*</span></div></td>
  <td valign="top" bgcolor="#FFFFFF"><div align="center" class="STYLE6"><span class="STYLE4">
    <input name="u3" class="STYLE5" id="u3" size="30"value="<?=$u3?>" />
  </span><span class="STYLE4">例：</span>123456&nbsp;&nbsp;&nbsp;</div></td>
</tr>
<tr> 
<td valign="top" bgcolor="#FFFFFF" style="padding-top:5px"><span class="STYLE6">&nbsp;&nbsp;
  </span>
  <div align="center" class="STYLE6">数据库名<span class="STYLE3">*</span></div></td>
<td valign="top" bgcolor="#FFFFFF"><div align="center" class="STYLE6"><span class="STYLE4">
  <input name="u4" class="STYLE5" id="u4" size="30" value="<?=$u4?>"/>
例：</span>gw413&nbsp;&nbsp;&nbsp;&nbsp;</div></td>
</tr>


<tr align="center"> 
<td colspan="2" bgcolor="#FFFFFF"><input type="submit" name="Submit" onclick="return checkform()"  value="开始安装"  class="btn"></td>
</tr>
</form>
</table>
<?
}
else
{
?>
<table width="600" height="254" border="0" align="center" cellpadding="8" cellspacing="1" bordercolor="#EEEEEE" bgcolor="#EEEEEE" class="aset24">

    <tr>
      <td bgcolor="#FFFFFF"><div align="center" class="STYLE6 STYLE7">恭喜安装成功！可正常使用本程序，为安全考虑请删除本安装文件！</div></td>
    </tr>
    <tr>
      <td valign="top" bgcolor="#FFFFFF" style="padding-top:5px"><div align="center"><span class="STYLE6"><br />
        默认管理员：<span class="STYLE8">admin</span> 密码：<span class="STYLE8">123456</span> (登录后台修改)<br />
        <br />
        <br />
      </span> 后台路径：/admin/index.php </div>        
      <div align="center"></div></td>
      </tr>
    <tr align="center">
      <td bgcolor="#FFFFFF"><input type="button" onclick="window.open('index.php');" name="Submit2"   value="访问首页"  class="btn" />
        <input type="button" onclick="window.open('admin/index.php');" name="Submit3"   value="登录后台"  class="btn" /></td>
    </tr>
</table>
<?
}
?>
<div class="h" style="height:18px"></div>
</div>
<div class="bfoot"></div>

</Div>
 <div id="footer">Copyright <span class="fontArial">&copy;</span>  &nbsp;<a href="http://www.gw413.com" target="_blank">随风分类信息<?=$lwan?></a>&nbsp;  All Rights Reserved.　<a href="http://<?=$w_url?>" target="_blank"><?=$w_name?></a>　版权所有　
  <a href="http://sighttp.qq.com/authd?IDKEY=4c2e9b8deeae69dc43438840196da35dcf260c08b9fc093c" style="color:#FF0066" target="_blank">QQ:250523691</a></div>

</DIV></body>
</html>