<?php
# Subroutine: adm_board_reindex.php called by Admin.php
# Xinfeng Chen, 2002.11.29
# Input: $bid

require_once('bin/config.php');
require_once('admin/adm.inc');

#--- Validate dministrator ---
include('admin/adm_validate.php');
if(!$adm_validated){jumpTo('admin.php?cmd=logon'); exit;}

#--- Start Processing ---
require_once('core/class_forum_base.php');
CForumBase::setFileBase("$filepath");
require_once('core/base_memo_file.php');
require_once('core/class_topic.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');

$oTpc=new CTopic;
$oTpcLst=new CTopicList;
$oTpcIdx=new CTopicIndex;

#--- Create topic list and index ---
$listpath=CForumBase::getFilePath('TLIST',$bid);
$oTpcLst->createFile($listpath, 256);
$idxpath=CForumBase::getFilePath('TINDEX',$bid);
$oTpcIdx->createFile($idxpath, 4);

#--- Process all files under board directory ---
$boardpath=CForumBase::getFilePath('BOARD',$bid);
$boardpath=dirname($boardpath);

$nTopic=$nTop=$nCollect=0;

$dir=opendir($boardpath);
$oTpcLst->open($bid);
$oTpcIdx->open($bid);
while (($item=readdir($dir)) != false){
 if(strlen($item)==14 && $oTpc->load($bid,$item)){
  $brief=$oTpc->getBrief();
  $istop=$oTpc->getFlag('TOPPED');

  $oTpcLst->insertTopic($item,$brief);
  $refid=$oTpcLst->getAbsolutePosition();

  $oTpc->refid=$refid;
  $oTpc->store($bid,$item);

  $nTopic++;
  
  if($istop){ $oTpcIdx->selectIndex(1); $nTop++;}
  else{ $oTpcIdx->selectIndex(0); }
  $oTpcIdx->activateTopic($refid);
  
  if($oTpc->getFlag('COLLECTED')){
   $oTpcIdx->selectIndex(2);
   $oTpcIdx->activateTopic($refid);
   $nCollect++;
  }
 }
}

$oTpcLst->close();
$oTpcIdx->close();
closedir($dir);

#--- Display result ---
$msg="论坛(ID=$bid)索引重建成功！<BR>";
$msg.="($nTopic 个主题, $nTop 个置顶, $nCollect 个精华)";
msgBox($msg,mINFORMATION,'操作成功','?cmd=board','返回论坛列表');

?>