<?php
define('CURSCRIPT', 'thread');
require_once './engine/common.inc.php';
if(!array_key_exists($forid,$forumcategory)){
	showmsg("论坛分类或版块不存在");
}
@extract($forumcategory[$forid]);
accessforum();
$siteheadtitle=implode(' ',array($forumtitle,$forumname,$sitename,$sitekeywords));
$curpage=isset($page)?$page:1;
$startrecord=($curpage-1)*$pagerecords;
$totalrecord=$db->result($db->query("SELECT count(*) FROM g_threads WHERE forid=$forid and top = 0"),0);
$toptotalrecord=$db->result($db->query("SELECT count(*) FROM g_threads WHERE forid=$forid and top = 1"),0);

if($toptotalrecord){
	$topq = $db->query("SELECT * FROM g_threads WHERE forid=$forid and top = 1 ORDER BY ord DESC limit 0,10");
	$key = 0;
	while($topthread=$db->fetch_array($topq))
		{
			$topthreads[$key]=$topthread;
			$key++;
		}
	}
	$q = $db->query("SELECT * FROM g_threads WHERE forid=$forid and top = 0 ORDER BY ord DESC LIMIT $startrecord , $pagerecords");
	$key = 0;
	while($thread=$db->fetch_array($q))
		{
			$threads[$key]=$thread;
			$key++;
		}
	$multipage=multi($totalrecord, $pagerecords, $curpage, "forumdisplay.php?forid=".$forid);
	include($templatedir."forumdisplay.tpl.php");