<?php
#------------------------------------------------------#
#               本程序为zChain.net提供                 #
#                zChain论坛(ZBB)v2.00                  #
#------------------------------------------------------#
# INPUT: $bid,$tid,$sv_user

require "bin/config.php";
require "bin/common.php";

require_once('core/class_forum_base.php');
CForumBase::setFileBase("$filepath");
require_once('core/base_memo_file.php');
require_once('core/class_board.php');
require_once('core/class_topic.php');
require_once('core/base_array_file.php');
require_once('core/class_reply_set.php');
require_once('core/base_record_file.php');
require_once('core/class_topic_list.php');
require_once('core/base_index_file.php');
require_once('core/class_topic_index.php');

$oBrd=new CBoard;
if(!$oBrd->load($bid)){errorview("指定论坛错误！");}
if(!$oBrd->isModerator($sv_user)){errorview("对不起，您没有此项操作的权限！");}

$oTpc=new CTopic;
if(!$oTpc->load($bid,$tid)){errorview('主题文件错误！');}

#--- Delete topic from topic_list ---
$oTpcLst=new CTopicList;
if($oTpcLst->open($bid)){
 $oTpcLst->deleteTopic($oTpc->refid,$tid);
 $oTpcLst->close();
}else{
 errorview('列表文件错误！');
}

$oTpcIdx=new CTopicIndex;
if($oTpcIdx->open($bid)){
 $oTpcIdx->selectIndex(0); // base list
 $oTpcIdx->deleteTopic($oTpc->refid);
 $oTpcIdx->selectIndex(1); // top list
 $oTpcIdx->deleteTopic($oTpc->refid);
 $oTpcIdx->selectIndex(2); // collection list
 $oTpcIdx->deleteTopic($oTpc->refid);
 $oTpcIdx->close();
}

#--- Delete reply file ---
$oRpl=new CReplySet;
if(!$oRpl->load($bid,$oTpc->replyid)){
 $oRpl->store('recycle',$oTpc->replyid);
 $oRpl->destroy($bid,$oTpc->replyid);
}

#--- Delete topic file ---
$oTpc->refid=0;
$oTpc->store('recycle',$tid);
$oTpc->destroy($bid,$tid);

require_once('core/class_log.php');
CLOG::writeLogEntry("Topic[bid=$bid,tid=$tid] is deleted by user [$sv_user]");

jumpTo("viewboard.php?bid=$bid","已经成功删除该主题!");

?>