<?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");
include_once("check_admin_qs.php");

$id=intval($_GET["id"]);
$ptuser=$_GET["ptuser"];
$flag=$_GET["flag"];
$filepath=$_GET["filepath"];
if (strrpos($filepath,"/")){
   $arr=explode("/",$filepath);
   $refilepath=$arr[0]."/".$id;
}

$sql="select id,name,BoardID_1,BoardID_2,rep from {$tablepre}bbstitle Where id=".$id;
$rs=mysql_query($sql);
$myrow = mysql_fetch_array($rs);
$numrows = mysql_num_rows($rs);
if ($numrows!=0){
	   mysql_query("delete from {$tablepre}bbstitle where id='".$id."'");
	   mysql_query("update {$tablepre}bbs_cate set BBS_Cate_Topic=BBS_Cate_Topic-1 where BBS_Cate_ID='".$myrow["BoardID_1"]."'");
	   mysql_query("update {$tablepre}bbs_cate set BBS_Cate_Topic=BBS_Cate_Topic-1 where BBS_Cate_ID='".$myrow["BoardID_2"]."'");
       mysql_query("update {$tablepre}clubuser set postnum=postnum-1 where clubuser_name='".$myrow["name"]."'");
}
$sql="select BoardID_1,BoardID_2 from {$tablepre}bbsmenu where pid=".$id;
$rsx=mysql_query($sql);
$myrowx = mysql_fetch_array($rsx);
$numrowsx = mysql_num_rows($rsx);
if ($numrowsx!=0){
	   mysql_query("delete from {$tablepre}bbsmenu where pid='".$id."'");
	   mysql_query("update {$tablepre}bbs_cate set BBS_Cate_Reply=BBS_Cate_Reply-".$numrowsx." where BBS_Cate_ID='".$myrowx["BoardID_1"]."'");
	   mysql_query("update {$tablepre}bbs_cate set BBS_Cate_Reply=BBS_Cate_Reply-".$numrowsx." where BBS_Cate_ID='".$myrowx["BoardID_2"]."'");
}

$str="select id,upload_pic from {$tablepre}ftbbs_upload where upload_htm='".$filepath."' and upload_htm<>'' and upload_htm is not NULL";
$rsp=mysql_query($str);
$myrowp = mysql_fetch_array($rsp);
$numrowsp = mysql_num_rows($rsp);
if ($numrowsp!=0){
   do {
   $id=$myrowp["id"];
   $pic=$myrowp["upload_pic"];
   if (file_exists("../".$pic)){
       unlink("../".$pic);
   }
   mysql_query("delete from {$tablepre}ftbbs_upload where id='".$id."'");
   }
   while ($myrowp = mysql_fetch_array($rsp));
}

//bbsad
//default_listbbsad
$db->close();
delcache("../cache/ftbbshome.txt");
delcache("../cache/default_list.txt");
header("Location:".$_SERVER["HTTP_REFERER"]);
?>
