<?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);
include_once("sound.php");
include_once("ftbbs_nav.php");
$url=$ftbbsmb[10];
$upfiletype=$ftbbsmb[12];
$upfilesize=$ftbbsmb[13];
$lxft=$ftbbsmb[18];
$getcodeoff=$ftbbsmb[30];
$shoff=$ftbbsmb[38];
$postbegintime=$ftbbsmb[42];
$postendtime=$ftbbsmb[43];
$postget=$ftbbsmb[48];
$repostget=$ftbbsmb[49];
$topostget=$ftbbsmb[50];
$tjget=$ftbbsmb[51];
$jhget=$ftbbsmb[52];
$logintili=$ftbbsmb[53];

$postvalue=$ftbbsmb[54];
$pollvalue=$ftbbsmb[55];
$topvalue=$ftbbsmb[56];
$tjvalue=$ftbbsmb[57];
$jhvalue=$ftbbsmb[58];
$downvalue=$ftbbsmb[59];
$uploadvalue=$ftbbsmb[60];

$ip=GetUserIP();
//$fd = $_GET["fd"];
$BoardID_1 = ftbbs_request($_POST["BoardID_1"]);
$BoardID_2 = ftbbs_request($_POST["BoardID_2"]);
$codestr=trim($_POST["codestr"]);
$addblog=$_POST["addblog"];
$filename=ftbbs_request($_POST["FileName"]);
$now=date("Y-m-d H:i:s");
$username=get_cookie('username');
$clubuser_id=intval(get_cookie('clubuser_id'));
$fd = $_POST["fd"];
$bbs_img_display=$_POST["bbs_img_display"];
$bbs_img=$_POST["bbs_img"];

$returnurl="main.php?layer_1=".$BoardID_1."&layer_2=".$BoardID_2;
$refbhturl="fbht.php?layer_1=".$BoardID_1."&layer_2=".$BoardID_2;

if ($ftbbsmb[7]=="M"){
 $inFolder=date("Ym",time());
 }
else{
 $inFolder=date("Ymd",time());
}

If (get_cookie('payuser')==3){
   ftbbs_msg("你的用户名被管理员封锁,请联系管理员！",$returnurl);
   exit;
}
if ($_SESSION["LastPostTime"]==""){
   $_SESSION["LastPostTime"]=$now;
   }
else{
   if (dateDiff("MINUTE",$_SESSION["LastPostTime"],$now)<=$lxft && $lxft!=0){
	  ftbbs_msg("连续发帖间隔时间不能少于".$lxft."秒!",$refbhturl);
	  exit;
	  }
   else{
      $_SESSION["LastPostTime"]=$now;
   }
}
session_destroy();
if (clearnulllen($_POST["menu"])<=0){
   ftbbs_msg("内容不能为空",$refbhturl);
   exit;
}
If ($getcodeoff==1&&$_SESSION["code"]!=$codestr){
   ftbbs_msg("验证码错误!",$refbhturl);
   exit;
}

$title = ftbbs_request(trim($_POST["title"]));
$title = nohtml($title);
$title = nojs($title);
$titlecolor = trim($_POST["titlecolor"]);
$zhiye = trim($_POST["zhiye"]);
$menu = ftbbs_request(trim($_POST["menu"]));
$ticon = trim($_POST["ticon"]);
$bbs_img_text = trim($_POST["bbs_img_text"]);
$img_url = trim($_POST["img_url"]);
$img_url_text = trim($_POST["img_url_text"]);

$tptype=$_POST["tptype"];
$daynum = trim($_POST["daynum"]);
//新
foreach($_POST as $key => $val){
   if (strpos($key,"pn")==1){
      $tpnl=$tpnl.$val."|";
   }
}

$tpnl=substr($tpnl,0,strlen($tpnl)-1);

if (get_cookie('username')==""){
   header("Location:fbht.php?layer_1=".$BoardID_1."&BoardID_2=".$BoardID_2);
}
//阻止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("对不起，你无权发表话题!",$returnurl); 
	   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);
	$menu = str_replace($content,'*****',$menu);		
  }
   while ($qsrow = mysql_fetch_array($qsrs)); 
}
$menu=ubb($menu);
$menu=nojs($menu);
$htmfilename=$inFolder."/".$filename;

$sh=sh($postbegintime,$postendtime);
if ($shoff==0 && $sh=1 && $postbegintime!="0" && $postendtime!="0"){
$deletedvalue=1;
}else{
$deletedvalue=$shoff;
//$shoff=0;
}
$strsql="insert into {$tablepre}bbstitle (BoardID_1,BoardID_2,name,user_id,title,zhiye,menu,ip,dateh,deleted,hit,rep,redate,P_display,img_url_display,picture,htmfilename,titlecolor,flag,bbs_img_display,bbs_img) values('$BoardID_1','$BoardID_2','$username','$username','$title','$zhiye','$menu','$ip','$now','$deletedvalue',0,0,'$now',1,0,'$ticon','$filename','$titlecolor','$fd','$bbs_img_display','$bbs_img')";
mysql_query($strsql);
$TitleID=mysql_insert_id();
$sql="update {$tablepre}clubuser set jingyuan=jingyuan+'".$postget."',postnum=postnum+1 where clubuser_name='".get_cookie('username')."'";
mysql_query($sql);
mysql_query("update {$tablepre}bbs_cate set BBS_Cate_Topic=BBS_Cate_Topic+1 where BBS_Cate_ID='".$BoardID_1."'");
if ($BoardID_2!=""){
   mysql_query("update {$tablepre}bbs_cate set BBS_Cate_Topic=BBS_Cate_Topic+1 where BBS_Cate_ID='".$BoardID_2."'");
}
//
//if ($fd==1 && $tptype!="" && $tpnl1!="" && $tpnl2!=""){
if ($fd==1 && $tptype!="" && $tpnl!=""){
   $lastdate=dateAdd("DAY",$daynum,$getnow,$return_format="Y-m-d H:i:s");
   $strsql="insert into {$tablepre}bbs_poll (pid,tptype,tpnl,pttime,bgtime,edtime) values('$TitleID','$tptype','$title','$getnow','$getnow','$lastdate')";
   mysql_query($strsql);
   
   $strarr = explode("|",$tpnl);
   for($i=0; $i<count($strarr); $i++){
   $strsql="insert into {$tablepre}bbs_poll (pid,tpnl) values('$TitleID','$strarr[$i]')";
   mysql_query($strsql);
   }
}
//内容写入个人博客中
if ($addblog=="Y"){
   $sql="select * from {$tablepre}ftblog_type where blogtype='默认分类' and userid=".$clubuser_id." and blogphoto=0 order by id desc";
   $rs=mysql_query($sql);
   $qsrow = mysql_fetch_array($rs);
   $numrows = mysql_num_rows($rs);
   if ($numrows!=0){
   $blogtypeid=$qsrow["id"];
   }
   else{
   $strsql="insert into {$tablepre}ftblog_type (userid,blogtype,blogphoto,qs,userip) values('$clubuser_id','默认分类',0,0,'$ip')";
   mysql_query($strsql);
   $blogtypeid=mysql_insert_id();
   }
   mysql_query("insert into {$tablepre}ftblog(blogtitle,blogcontent,blogtypeid,blogqs,writedate,xinqin,userip,userid,plqs) values('".$title."','".$menu."','".$blogtypeid."',0,'".$now."','一般','".$ip."',".$clubuser_id.",0)");
   mysql_query("update {$tablepre}ftblog_type set totalnum=totalnum+1 where id=".$blogtypeid." and userid=".$clubuser_id."");
}
mysql_free_result($qsrs);
mysql_free_result($rs);
$db->close(); 
include_once("delcache.php");
if ($returnurl!=""){
  header("Location:".$returnurl);
}
else{
  header("Location:main.php");
}
?>