<?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);

$url=$ftbbsmb[10];
$upfiletype=$ftbbsmb[12];
$upfilesize=$ftbbsmb[13];
$getcodeoff=$ftbbsmb[30];
$htm_ext=$ftbbsmb[32];

$now=date("Y-m-d H:i:s");
$postuser = $_POST["postuser"];
$pid = intval($_POST["id"]);
$reid = intval($_POST["reid"]);
$BoardID_1 = $_POST["BoardID_1"];
$BoardID_2 = $_POST["BoardID_2"];
$codestr=trim($_POST["codestr"]);
$reurl = $_POST["reurl"];

$title = ftbbs_request(trim($_POST["title"]));
$title = nohtml($title);
$title = nojs($title);
$titlecolor = trim($_POST["titlecolor"]);
$zhiye = trim($_POST["zhiye"]);
$menu = ftbbs_request($_POST["menu"]);
$ticon = trim($_POST["ticon"]);
$bbs_img = $_POST["bbs_img"];
$bbs_img_display = $_POST["bbs_img_display"];
if (clearnulllen($_POST["menu"])<=0){
   echo "<script language='javascript'>alert('内容不能为空');history.go(-1);</script>";
   exit;
}
If ($getcodeoff==1&&$_SESSION["code"]!=$codestr){
   echo "<script language='javascript'>";
   echo "alert('验证码错误');history.go(-1);";
   echo "</script>";
   exit;
}
//阻止关键字
$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);
$menu=eregi_replace("<script>","< script >",$menu);
$menu=eregi_replace("<iframe","< iframe",$menu);

$sql="select {$tablepre}bbs_cate.BBS_Cate_Manager_Name from {$tablepre}bbs_cate,{$tablepre}bbstitle where {$tablepre}bbs_cate.BBS_Cate_ID = {$tablepre}bbstitle.BoardID_2 and {$tablepre}bbstitle.ID='".$pid."'";
$rs=mysql_query($sql);
$myrow = mysql_fetch_array($rs);
$numrows = mysql_num_rows($rs);

$myname=$myrow["BBS_Cate_Manager_Name"];
$admintobz=0;
$username=get_cookie('username');
if (strrpos($myname,"|")){
	$arr=explode("|",$myname);
    for($i=0; $i<count($arr); $i++){
	if ($arr[$i]==$username){
	   $admintobz=1;
	   }
    }
}
elseif($myname==$username){
    $admintobz=1;
}
$img_url="[此贴子已经被".$username."于".$now."编辑过]";
if (get_cookie('bz')==1 || $admintobz==1 || $postuser==$username){
   if ($reid==""){
   $sql="update {$tablepre}bbstitle set BoardID_1='".$BoardID_1."',BoardID_2='".$BoardID_2."',menu='".$menu."',title='".$title."',picture='".$ticon."',zhiye='".$zhiye."',titlecolor='".$titlecolor."',img_url='".$img_url."',img_url_display=1 where id=".$pid;
   mysql_query($sql);
   sendsms($username,$postuser,$pid,$title,1);
   }
   else{
   $sql="update {$tablepre}bbsmenu set remenu='".$menu."',img_url='".$img_url."',img_url_display=1 where id=".$reid;
   mysql_query($sql);
   }
 
   if ($reid==""){
   mysql_query("update {$tablepre}bbsmenu set BoardID_1='".$BoardID_1."',BoardID_2='".$BoardID_2."' where pid=".$pid);
   }
   if (!empty($bbs_img_display) || $bbs_img_display!=""){
   mysql_query("update {$tablepre}bbstitle set bbs_img_display='$bbs_img_display',bbs_img='$bbs_img',redate='".$now."' where id=".$pid);
   }
   else{
   mysql_query("update {$tablepre}bbstitle set redate='".$now."' where id=".$pid);
   }
}
mysql_free_result($qsrs);
mysql_free_result($rs);
$db->close(); 
header("Location:".$reurl);	
?>