<?php
include_once("inc/config.php");
include_once("inc/ftbbsdbclass.php");
include_once("inc/publicfun.php");
include_once("conn.php");
include_once("touxianfun.php");
include_once("inc/ftcode.php");
include_once("checkuser.php");
include_once("bbsuser.php");
$query = "SELECT * FROM {$tablepre}ftbbsmb";
$ftbbsmb=makecache('ftbbsmb.html',$query,$expire);

$pagenum=$ftbbsmb[6];
$url=$ftbbsmb[10];
$upfiletype=$ftbbsmb[12];
$upfilesize=$ftbbsmb[13];
$lxft=$ftbbsmb[18];
$getcodeoff=$ftbbsmb[30];
$htmlsign=$ftbbsmb[37];
$shoff=$ftbbsmb[38];
$repostbegintime=$ftbbsmb[44];
$repostendtime=$ftbbsmb[45];
$repostget=$ftbbsmb[49];
$topostget=$ftbbsmb[50];
$ip=GetUserIP();
$pid=intval($_POST["id"]);
$remenu=$_POST["remenu"];
$BoardID_1=$_POST["BoardID_1"];
$BoardID_2=$_POST["BoardID_2"];
$username=get_cookie('username');
$bbs_img_display=$_POST["bbs_img_display"];
$bbs_img=$_POST["bbs_img"];
$codestr=trim($_POST["codestr"]);
if (clearnulllen($_POST["remenu"])<=0){
   ftbbs_msg("内容不能为空","ftbbs.php?id=".$pid);
   exit;
}
if ($username==""){
   ftbbs_msg("用户名不能为空！","ftbbs.php?id=".$pid);
   exit;
}
$now=date("Y-m-d H:i:s");
$_SESSION["id"]=$pid;

if ($ftbbsmb[7]=="M"){
 $inFolder=date("Ym",time());
 }
else{
 $inFolder=date("Ymd",time());
}
/*
if(!file_exists ($inFolder)){
  mkdir($inFolder,0777);   
}
*/
If (get_cookie('payuser')==3){
   ftbbs_msg("你的用户名被管理员封锁,请联系管理员！","ftbbs.php?id=".$pid);
   exit;
}
if ($_SESSION["LastPostTime"]==""){
   $_SESSION["LastPostTime"]=$now;
   }
else{
   if (datediff("MINUTE",$_SESSION["LastPostTime"],$now)<=$lxft && $lxft!=0){
	  ftbbs_msg("连续回帖间隔时间不能少于".$lxft."秒!","ftbbs.php?id=".$pid);
	  exit;
	  }
   else{
      $_SESSION["LastPostTime"]=$now;
   }
}

If ($getcodeoff==1&&$_SESSION["code"]!=$codestr){
   ftbbs_msg("验证码错误!","ftbbs.php?id=".$pid);
   exit;
}
 
//阻止ip
$sql_arrest="select * from {$tablepre}bbs_arrest where Kind='IP' order by id asc";
$qsrs=mysql_query($sql_arrest);
$qsrow = mysql_fetch_array($qsrs);
$numrows = mysql_num_rows($qsrs);

if ($numrows!=0){
  do {
    $content=$qsrow["Content"];
	if ($content==$ip){
	   ftbbs_msg("对不起，你无权发表话题!","ftbbs.php?id=".$pid); 
	   exit;
	}
  }
  while ($qsrow = mysql_fetch_array($qsrs));
}
//阻止关键字
$sql_arrest="select * from {$tablepre}bbs_arrest where Kind='Keyword' order by id asc";
$qsrs=mysql_query($sql_arrest);
$qsrow = mysql_fetch_array($qsrs);
$numrows = mysql_num_rows($qsrs);
if ($numrows!=0){
   do {
    $content=$qsrow["Content"];
	$title = str_replace($content,'*****',$title);
	$remenu = str_replace($content,'*****',$remenu);		
  }
   while ($qsrow = mysql_fetch_array($qsrs)); 
}
//引用部份
if (strrpos($remenu,"[/ftquote]")){
   $k1=strstr($remenu,"[ftquote]");
   $k2=strlen($k1);
   $k3=strrchr($k1,"[/ftquote]");
   $k4=strlen($k3);
   $yyid=substr($k1,9,$k2-$k4-9);//引用ID
   $replace1="[ftquote]".$yyid."[/ftquote]";
   $sql="select * from {$tablepre}bbstitle where id='".$yyid."'";
   $rs=mysql_query($sql);
   $row = mysql_fetch_array($rs);
   $keyxx="<font color=#568AC2>引用回复: ".$row["user_id"]."</font>";
   $replace2="<table width=99% border=0 align=center cellpadding=4 cellspacing=1 bgcolor=#999999><tr><td bgcolor=#ffffee>". $keyxx ."<br>".$row["menu"]."</td></tr></table>";
   $remenu=str_replace($replace1,$replace2,$remenu);
}
if (strrpos($remenu,"[/quote]")){
   $k1=strstr($remenu,"[quote]");
   $k2=strlen($k1);
   $k3=strrchr($k1,"[/quote]");
   $k4=strlen($k3);
   $yyid=substr($k1,7,$k2-$k4-7);//引用ID
   $replace1="[quote]".$yyid."[/quote]";
   $sql="select * from {$tablepre}bbsmenu where id='".$yyid."'";
   $rs=mysql_query($sql);
   $row = mysql_fetch_array($rs);
   $keyxx="<font color=#568AC2>引用回复: ".$row["user_id"]."</font>";
   $replace2="<table width=99% border=0 align=center cellpadding=4 cellspacing=1 bgcolor=#999999><tr><td bgcolor=#ffffee>". $keyxx ."<br>".$row["remenu"]."</td></tr></table>";
   $remenu=str_replace($replace1,$replace2,$remenu);
}

$sql="select * from {$tablepre}bbstitle where id=".$pid;
$rs=mysql_query($sql);
$row = mysql_fetch_array($rs);
$P_display=$row["P_display"];
$reinfo=$row["reinfo"];
$totalrep=$row["rep"];
$postuser=$row["name"];
$k=$totalrep/$pagenum;
$p=$totalrep%$pagenum;
if (is_int($k) && $p!=0){
   $page=intval($k);
}else{
   $page=intval($k)+1;
}
if ($P_display==0){
   ftbbs_msg("该主题贴被禁止回贴!","ftbbs.php?id=".$pid);
   exit;
}

$remenu = ubb($remenu);
$remenu=eregi_replace("<script>","< script >",$remenu);
$remenu=eregi_replace("<iframe","< iframe",$remenu);

//加入跟贴
$sh=sh($repostbegintime,$repostendtime);
if ($shoff==0 && $sh=1 && $repostbegintime!="0" && $repostendtime!="0"){
$deletedvalue=1;
}else{
$deletedvalue=$shoff;
}

$strsql="insert into {$tablepre}bbsmenu (BoardID_1,BoardID_2,pid,user_id,re_name,remenu,reip,dateh,kind,img_url_display,deleted) values('$BoardID_1','$BoardID_2','$pid','$username','$username','$remenu','$ip','$now',0,0,'$deletedvalue')";
mysql_query($strsql);
$reinfo=$reinfo."|".$now.",".$username."|";
$strsql="update {$tablepre}bbstitle set bbs_img_display='$bbs_img_display',bbs_img='$bbs_img',rep=rep+1,postnum=postnum+1,redate='$now',reinfo='$reinfo' where id='$pid'";
mysql_query($strsql);
mysql_query("update {$tablepre}bbs_cate set BBS_Cate_Reply=BBS_Cate_Reply+1 where BBS_Cate_ID='".$BoardID_1."'");
if ($BoardID_2!=""){
   mysql_query("update {$tablepre}bbs_cate set BBS_Cate_Reply=BBS_Cate_Reply+1 where BBS_Cate_ID='".$BoardID_2."'");
}
mysql_query("update {$tablepre}clubuser set jingyuan=jingyuan+'".$repostget."' where clubuser_name='".$username."'");
mysql_query("update {$tablepre}clubuser set jingyuan=jingyuan+'".$topostget."' where clubuser_name='".$postuser."' and clubuser_name<>'".$username."'");
mysql_free_result($qsrs);
mysql_free_result($rs);
$db->close(); 
include_once("delcache.php");
if ($htmlsign==1){
$urla="ftbbs-".$pid.".html";
$urlb="ftbbs-".$pid."-".$page.".html";
}
else{
$urla="ftbbs.php?id=".$pid;
$urlb="ftbbs.php?id=".$pid."&page=".$page;
}
if ($page>1){
//header("Location:ftbbs.php?id=".$pid."&page=".$page);
header("Location:".$urlb);
}
else{
//header("Location:ftbbs.php?id=".$pid);
header("Location:".$urla);
}
?>