<?php
include_once("../inc/config.php");
include_once("../inc/publicfun.php");
include_once("../inc/ftbbsdbclass.php");
include_once("../conn.php");
include_once("check_master.php");

$BBS_Cate_Name=trim($_POST["BBS_Cate_Name"]);
$BBS_Cate_Manager_Name=trim($_POST["BBS_Cate_Manager_Name"]);
$BBS_Cate_Manager_Email=trim($_POST["BBS_Cate_Manager_Email"]);
$BBS_Cate_Note=trim($_POST["BBS_Cate_Note"]);
$fangwenqs=trim($_POST["fangwenqs"]);
$treesign=trim($_POST["tree"]);
$menu=trim($_POST["menu"]);
$BBS_Cate_PID=$_POST["BBS_Cate_PID"];
$layer=$_POST["layer"];

if ($BBS_Cate_Name==""){
   echo "<BR><BR><center>请输入论坛名称！</center>";
   exit;
}

$query = "SELECT * FROM {$tablepre}ftbbsmb";
$ftbbsmb=adminmakecache('../cache/ftbbsmb.html',$query,$expire);
$treemb=$ftbbsmb[9];

if (strrpos($BBS_Cate_Manager_Name,"|")){
   $bzarr = explode("|",$BBS_Cate_Manager_Name);
   for($i=0; $i<count($bzarr); $i++){
       $sql="select clubuser_name from {$tablepre}clubuser where clubuser_name='".$bzarr[$i]."'";
       $rsbz=mysql_query($sql);
       $bzrow = mysql_fetch_array($rsbz);
       $bznumrows = mysql_num_rows($rsbz);
	   if ($bznumrows!=0){
       mysql_query("update {$tablepre}clubuser set bbsadmin=1 where clubuser_name='".$bzarr[$i]."'");
	   }
       else{
	   echo "<br><br><center>你所加入的版主中的用户名不存在！</center>";
	   exit;
	   }
   }
}
else{
  mysql_query("update {$tablepre}clubuser set bbsadmin=1 where clubuser_name='".$BBS_Cate_Manager_Name."'");
}

$strsql="select * from {$tablepre}bbs_cate where BBS_Cate_PID='".$BBS_Cate_PID."' order by BBS_ID desc";
$rs=mysql_query($strsql);
$myrow = mysql_fetch_array($rs);
$numrows = mysql_num_rows($rs);

if ($numrows==0){
    if ($layer!=0){
		$BBS_Cate_ID=$BBS_Cate_PID."_1";
		}
	else{
		$BBS_Cate_ID="A_1";
	}
}
else{
    $BBS_Cate_ID=$myrow["BBS_Cate_ID"];
    $k=strrchr($BBS_Cate_ID,"_");
    $k=str_replace("_","",$k);
    $str_2=intval($k);
	$str_2=$str_2+1;

    $m=strrev($BBS_Cate_ID);
    $m=strchr($m,"_");
    $str_1=strrev($m);
	$BBS_Cate_ID=$str_1.$str_2;
}
mysql_free_result($rs);
if ($layer!=0&&$layer!=""){
$sql="insert into {$tablepre}bbs_cate (BBS_Cate_ID,BBS_Cate_PID,BBS_Cate_Name,BBS_Cate_Topic,BBS_Cate_Reply,BBS_Cate_Manager_Name,BBS_Cate_Manager_Email,BBS_Cate_Note,BBS_Cate_Qs,treesign,BBS_Cate_Board) values('$BBS_Cate_ID','$BBS_Cate_PID','$BBS_Cate_Name',0,0,'$BBS_Cate_Manager_Name','$BBS_Cate_Manager_Email','$BBS_Cate_Note','$fangwenqs','$treesign','$menu')";
}
else{
$sql="insert into {$tablepre}bbs_cate (BBS_Cate_ID,BBS_Cate_PID,BBS_Cate_Name,BBS_Cate_Topic,BBS_Cate_Reply,BBS_Cate_Manager_Name,BBS_Cate_Manager_Email,BBS_Cate_Note,BBS_Cate_Qs,treesign) values('$BBS_Cate_ID','$BBS_Cate_PID','$BBS_Cate_Name',0,0,'$BBS_Cate_Manager_Name','$BBS_Cate_Manager_Email','$BBS_Cate_Note','$fangwenqs','$treesign')";
}

mysql_query($sql);

include_once("maketree.php");
include_once("makejs.php");
maketotree($treemb);
maketodh();
$db->close();
delcache("../cache/ftbbshome.txt");
delcache("../cache/default_list.txt");
header("Location:".$_SERVER["HTTP_REFERER"]);
?>
