<?php
ini_set("max_execution_time", "1200");

$siteurl = 'http://'.$_SERVER['SERVER_NAME'].str_replace('//','/',preg_replace('/\/(.*)install\/(.*)/is','/\\1', $_SERVER['SCRIPT_NAME']));
$newroot='';

if (isset($_GET['step'])){
    $step=$_GET['step'];
}else{
    $step=1;
}

if (isset($_GET['act']) and $_GET['act']=='phpinfo'){
    phpinfo();exit;
}
$stepname=array("YES风淘宝客系统","软件介绍","软件许可协议","运行环境检测","文件权限检测","填写网站基本信息","管理员设置","安装完成");
switch($step){
    case 1;
    include "step1.inc.php";
	break;
    case 2;
    include "step2.inc.php";
    break;
    case 3;
    include "step3.inc.php";
    break;
    case 4;
	$files = file("chmod.txt");
	$files = array_filter($files);
	$writablefile = $no_writablefile = null;
	foreach($files as $file)
	{
		$file = str_replace('*','',$file);
		$file = trim($file);
		if(!is_writable('../'.$file)){
			$no_writablefile .= $file.' '."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&times;<br>";
		}else{
			$writablefile .= $file.' '.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&radic;<br>';
		}
	}
    include "step4.inc.php";
    break;
    case 5;
    include "step5.inc.php";
    break;
    case 6;
    include "step6.inc.php";
    break;
    case 7;
    //写入数据
    $dbserver = $_POST['dbserver'];
$dbuser =$_POST['dbuser'];
$dbpass = $_POST['dbpass'];
$dbname = $_POST['dbname'];
$dbstr="<?php \$dbserver=\"".$dbserver."\";\$dbuser=\"".$dbuser."\";\$dbpass=\"".$dbpass."\";\$dbname=\"".$dbname."\";?>";
//echo $dbstr;

$filename   =   '../comm/conn.php';   
$somecontent   =   $dbstr;

if   (is_writable($filename))   {   
	if   (!$handle   =   fopen($filename,   'w'))   {   
		echo "<META http-equiv=Content-Type content=\"text/html; charset=gbk\">安装失败！无法打开文件  $filename ，请检查该文件是否存在！<a href=install.php>重新安装</a>";                         exit;   
       }   
     
     if   (!fwrite($handle,   $somecontent))   {   
        echo "<META http-equiv=Content-Type content=\"text/html; charset=gbk\">安装失败！无法写入  $filename ，请检查该文件是否可写！<a href=install.php>重新安装</a>";
        exit;  
          }   
    
     //print   "开始安装...";   
    
      fclose($handle);   
    
  }   else   {   
  echo "<META http-equiv=Content-Type content=\"text/html; charset=gbk\">安装失败！无法写入文件  $filename ，该文件不可写！<a href=install.php>重新安装</a>";   
  exit; 
  }
$sql01="DROP TABLE IF EXISTS `duoduo2010`;";
$sql1="CREATE TABLE `duoduo2010` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `adminname` varchar(255) DEFAULT NULL,
  `adminpass` varchar(255) DEFAULT NULL,
  `lastlogintime` datetime DEFAULT NULL,
  `lastloginip` varchar(255) DEFAULT NULL,
  `loginnum` int(11) DEFAULT '0',
  `logintime` datetime DEFAULT NULL,
  `loginip` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=gbk;";

$sql02="DROP TABLE IF EXISTS `msg`;";
$sql2="CREATE TABLE `msg` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(500) DEFAULT NULL,
  `content` varchar(6000) DEFAULT NULL,
  `addtime` datetime DEFAULT NULL,
  `see` int(11) DEFAULT '0',
  `ddusername` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=gbk;";


$sql04="DROP TABLE IF EXISTS `tbjy`;";
$sql4="CREATE TABLE `tbjy` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `tbcode` varchar(255) DEFAULT NULL,
  `tbname` varchar(255) DEFAULT NULL,
  `paytime` varchar(255) DEFAULT NULL,
  `addtime` datetime DEFAULT NULL,
  `jystate` varchar(255) DEFAULT '0',
  `tbusername` varchar(255) DEFAULT NULL,
  `ddusername` varchar(255) DEFAULT NULL,
  `payje` double DEFAULT '0',
  `fxje` double DEFAULT '0',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=44 DEFAULT CHARSET=gbk;";

$sql05="DROP TABLE IF EXISTS `tixian`;";
$sql5="CREATE TABLE `tixian` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `ddusername` varchar(255) DEFAULT NULL,
  `txje` double DEFAULT NULL,
  `zfb` varchar(255) DEFAULT NULL,
  `addtime` datetime DEFAULT NULL,
  `addip` varchar(255) DEFAULT NULL,
  `txstate` int(11) DEFAULT '0',
  `memo` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=gbk;";

$sql06="DROP TABLE IF EXISTS `user`;";
$sql6="CREATE TABLE `user` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `ddusername` varchar(255) DEFAULT NULL,
  `ddpassword` varchar(255) DEFAULT NULL,
  `tbusername` varchar(255) DEFAULT NULL,
  `regtime` datetime DEFAULT NULL,
  `loginnum` int(11) DEFAULT '0',
  `lastlogintime` datetime DEFAULT NULL,
  `lasttixian` datetime DEFAULT NULL,
  `zfb` varchar(255) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `uquestion` varchar(255) DEFAULT NULL,
  `uanswer` varchar(255) DEFAULT NULL,
  `wjs` double DEFAULT '0',
  `yjs` double DEFAULT '0',
  `txstate` int(11) DEFAULT '0',
  `dengji` int(11) DEFAULT '0',
  `tjr` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=57 DEFAULT CHARSET=gbk;";

$sql006="DROP TABLE IF EXISTS `adsen`;";
$sql116="CREATE TABLE `adsen` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `adsname` varchar(6000) DEFAULT NULL,
  `adsold` varchar(6000) DEFAULT NULL,
  `adsense` varchar(6000) DEFAULT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=gbk;";

$sql0006="DROP TABLE IF EXISTS `yf_article`;";
$sql1116="CREATE TABLE `yf_article` (
  `yf_ID` int(11) NOT NULL auto_increment,
  `yf_Name` varchar(255) NOT NULL,
  `yf_Keywords` varchar(255) default NULL,
  `yf_Color` varchar(8) default NULL,
  `yf_Pic` varchar(255) default NULL,
  `yf_ClassID` int(11) NOT NULL default '0',
  `yf_Topic` int(11) NOT NULL default '0',
  `yf_Author` varchar(255) default NULL,
  `yf_Source` varchar(255) NOT NULL,
  `yf_Remark` varchar(255) default NULL,
  `yf_Content` text NOT NULL,
  `yf_PageNum` int(11) NOT NULL default '1',
  `yf_Hits` int(11) default '1',
  `yf_Reco` int(11) NOT NULL default '0',
  `yf_IsHide` int(11) NOT NULL default '0',
  `yf_AddTime` datetime default NULL,
  `yf_Apex` int(11) NOT NULL default '0',
  `yf_Tread` int(11) NOT NULL default '0',
  `yf_PurView` varchar(100) default NULL,
  `yf_GotoUrl` varchar(255) default NULL,
  PRIMARY KEY  (`yf_ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=gbk;";

$sql07="DROP TABLE IF EXISTS `websetting`;";
$sql7="CREATE TABLE `websetting` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `appKey` varchar(255) DEFAULT NULL,
  `appSecret` varchar(255) DEFAULT NULL,
  `userpid` varchar(255) DEFAULT NULL,
  `usernick` varchar(255) DEFAULT NULL,
  `txyf` double DEFAULT NULL,
  `zzfl` double DEFAULT NULL,
  `fxbl` double DEFAULT NULL,
  `tgbl` double DEFAULT NULL,
  `webtitle` varchar(500) DEFAULT NULL,
  `keyword` varchar(6000) DEFAULT NULL,
  `description` varchar(6000) DEFAULT NULL,
  `descr1ptlon` varchar(6000) DEFAULT NULL,
  `url` varchar(255) DEFAULT NULL,
  `surl` varchar(255) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `icp` varchar(255) DEFAULT NULL,
  `tongji` varchar(6000) DEFAULT NULL,
  `qq` varchar(255) DEFAULT NULL,
  `usercenter` varchar(255) DEFAULT NULL,
  `emsg` varchar(1500) DEFAULT NULL,
  `seckey` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=gbk;";

$sql009="DROP TABLE IF EXISTS `yflink`;";
$sql119="CREATE TABLE `yflink` (
  `linkid` int(11) NOT NULL AUTO_INCREMENT,
  `linkname` varchar(6000) DEFAULT NULL,
  `linkurl` varchar(6000) DEFAULT NULL,
  `linkpic` varchar(6000) DEFAULT NULL,
  PRIMARY KEY (`linkid`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=gbk;";

$aname = $_POST['username'];
$apasswd = md5($_POST['adminpass']);
$wtitle=$_POST["webtitle"];
$aurl = $_POST['url'];
$unick = $_POST['usernick'];
$apey = $_POST['appKey'];
$apecret = $_POST['appSecret'];
$upid = $_POST['userpid'];
$fbl = $_POST['fxbl'];
$tbl = $_POST['tgbl'];
$aicp = $_POST['icp'];
$aemail = $_POST['email'];
$aqq = $_POST['qq'];

$sql8="INSERT INTO `duoduo2010` (`Id`,`adminname`,`adminpass`,`lastlogintime`,`lastloginip`,`loginnum`,`logintime`,`loginip`) VALUES  (1,'$aname','$apasswd','2010-01-21 15:42:05','127.0.0.1',0,'2010-01-22 11:46:29','127.0.0.1');";

$wbst="<p>您好，我们检测到你的 APPKEY 未经我们授权或已被恶意更改，请检查您的 APPKEY 是否填写错误。请马上登陆后台 <font color=#FF0000>网站基本信息设置</font> 检查 appkey 及pid！</p><p><font color=#ff0000><b>请注意：自行修改的 APPKEY 即使完成交易，您也无法获得推广佣金。</b></font></p><p><a href=http://www.yesfeng.com>立刻购买授权</a>&nbsp;&nbsp;&nbsp;<a href=user/buy.htm>我已经购买</a></p>";

$sql9="INSERT INTO `websetting`
(`Id`,`appKey`,`appSecret`,`userpid`,`usernick`,`txyf`,`zzfl`,`fxbl`,`tgbl`,`webtitle`,`keyword`,`description`,`descr1ptlon`,`url`,`surl`,`email`,`icp`,`tongji`,`qq`,`usercenter`,`emsg`,`seckey`) VALUES (1,'TVM0ME5EYzFNVEl4TnpFNE56WkZLekUw','VFhwRk1WcHFVVFJPVjFVMVRrUktiVmt5VVRSYVZFRXdXVzFaTVUxRVJteE5lbGt4V1hwbmVscEVVVDA9','TVM0NU1qY3hPREl5TlRVeU5UUkZLekUw','WkRJeGNHTnFUVDA9',20,10,'$fbl','$tbl',
'$wtitle','$wtitle',
'$wtitle是一个关于淘宝网商品搜索入口为主题的站，并且为我们的会员每次购物返现1-20%。我们倡导诚信网购，致力于搭建淘宝网诚信卖家与诚信买家之间的桥梁，提供淘宝网热卖商品的展示空间，致力于打造淘宝网购物的口碑站点。','','$aurl','$aurl','$aemail','$aicp','这里填写统计代码','$aqq','我的中心','$wbst','deb3cee990f2ccc531b167d84a2f5e3d');";

$link = mysql_connect($dbserver, $dbuser, $dbpass);
if (!$link) {
	die('数据库链接出错: ' . mysql_error());
	exit;
}
else
{
	mysql_query("set names gbk");	
	mysql_select_db($dbname);
	
	mysql_query($sql01);
	mysql_query($sql1);
	mysql_query($sql02);
	mysql_query($sql2);
	mysql_query($sql04);
	mysql_query($sql4);
	mysql_query($sql05);
	mysql_query($sql5);
	mysql_query($sql06);
	mysql_query($sql6);
	mysql_query($sql006);
	mysql_query($sql116);
	mysql_query($sql009);
	mysql_query($sql119);
	mysql_query($sql0006);
	mysql_query($sql1116);
	mysql_query($sql07);
	mysql_query($sql7);
	mysql_query($sql8);
	mysql_query($sql9);
	mysql_query("set names utf8");	
	$datasql=file_get_contents("yesfeng.sql");
	$dataarr=explode("-yesfeng-",$datasql);
		for($i=0;$i<count($dataarr);$i++){
		//$db->query($dataarr[$i]);
		mysql_query($dataarr[$i]);
		}	
	//echo $sql9;
}

$query="show tables like 'websetting';";
$res=mysql_query($query);	
if(mysql_num_rows($res)!=0)
{
	$query="select * from websetting;";
	$res=mysql_query($query);	
	if(mysql_num_rows($res)!=0)
	{
		rename('install.php','install.php.lock'); 
	}else
	{echo "<META http-equiv=Content-Type content=\"text/html; charset=gbk\">安装失败！<a href=install.php>重新安装</a>";
}
}
else
{echo "<META http-equiv=Content-Type content=\"text/html; charset=gbk\">安装失败！<a href=install.php>重新安装</a>";
}
mysql_close($link);

	include "step7.inc.php";
    
    break;
    
}


?>