type=="postgresql"){
$limit="";
$q->query($DB, "set QUERY_LIMIT TO '$ForumDisplay'");
}
else{
$limit=" limit $ForumDisplay";
}
if($thread==0 || $action==0){
$sSQL = "Select max(thread) as thread from $ForumTableName where approved='Y'";
$q->query($DB, $sSQL);
if($q->numrows()>1){
$rec=$q->getrow();
$maxthread=$rec["thread"];
}
else{
$maxthread=0;
}
$cutoff_thread=$maxthread-$cutoff;
if($$phcollapse==0){
$sSQL = "Select thread from $ForumTableName where thread > $cutoff_thread and approved='Y' order by thread desc".$limit;
}
else{
$sSQL = "Select thread, count(*) as tcount, max(datestamp) as latest, max(id) as maxid from $ForumTableName where thread > $cutoff_thread and approved='Y' group by thread order by thread desc".$limit;
// echo "\n";
}
}
else{
if($action==1){
$cutoff_thread=$thread+$cutoff;
$sSQL = "Select thread from $ForumTableName where thread < $cutoff_thread and thread > $thread and approved='Y' order by thread".$limit;
$q=new query($DB, $sSQL);
$rec=$q->getrow();
if(!empty($rec["thread"])){
$keepgoing=true;
$x=0;
while (is_array($rec) && $keepgoing){
$thread = $rec["thread"];
$rec=$q->getrow();
$x++;
if($DB->type=="oracle" && $x==$ForumDisplay){
$keepgoing=false;
}
}
}
$thread=$thread+1;
}
$cutoff_thread=$thread-$cutoff;
if($$phcollapse==0){
$sSQL = "Select thread from $ForumTableName where thread < $thread and thread > $cutoff_thread and approved='Y' order by thread desc".$limit;
}
else{
$sSQL = "Select thread, count(*) as tcount, max(datestamp) as latest, max(id) as maxid from $ForumTableName where thread < $thread and thread > $cutoff_thread group by thread order by thread desc".$limit;
}
}
$thread_list = new query($DB, $sSQL);
if($DB->type=="postgresql"){
$q->query($DB, "set QUERY_LIMIT TO '0'");
}
$rec=$thread_list->getrow();
if(empty($rec["thread"]) && $action!=0){
Header("Location: $forum_url/$list_page.$ext?f=$num$GetVars");
exit();
}
if(isset($rec['thread'])){
$max=$rec["thread"];
$keepgoing=true;
$x=0;
while (is_array($rec)){
$threads[]=$rec;
$min=$rec["thread"];
$rec=$thread_list->getrow();
}
}
else{
$threads="";
$max=0;
$min=0;
}
if($$phcollapse==0){
$sSQL = "Select id,parent,thread,subject,author,datestamp from $ForumTableName where thread<=$max and thread>=$min and approved='Y' order by thread desc, id asc";
}
else{
$sSQL = "Select id,thread,subject,author,datestamp from $ForumTableName where thread<=$max and thread>=$min and thread=id and approved='Y' order by thread desc";
}
$msg_list = new query($DB, $sSQL);
$rec=$msg_list->getrow();
While(is_array($rec)){
$headers[]=$rec;
$rec=$msg_list->getrow();
}
$rows=@count($headers);
if(file_exists("$include_path/header_$ForumConfigSuffix.php")){
include "$include_path/header_$ForumConfigSuffix.php";
}
else{
include "$include_path/header.php";
}
if($$phcollapse==0){
$collapse_link = "".$lCollapseThreads."";
}
else{
$collapse_link = "".$lViewThreads."";
}
if($ActiveForums>1){
$nav = "
";
}
else{
$nav = "";
}
$pagenav="";
if($action!=0) $pagenav=" $lNewerMessages";
if($rows>=$ForumDisplay){
if(!empty($pagenav)) $pagenav.=" | ";
$pagenav.="$lOlderMessages ";
}
?>