$tblstart$tccell1>\"$t[title]\" has been added to your favorites.
".redirect("forum.php?id=$t[forum]",'return to the forum',0).$tblend.$footer;
    printtimedif($startingtime);
    die();
  }elseif($act=='rem'){
    $t=mysql_fetch_array(mysql_query("SELECT title,forum FROM threads WHERE id=$thread"));
    mysql_query("DELETE FROM favorites WHERE user=$loguserid AND thread=$thread");
    print "$header
$tblstart$tccell1>\"$t[title]\" has been removed from your favorites.
".redirect("forum.php?id=$t[forum]",'return to the forum',0).$tblend.$footer;
    printtimedif($startingtime);
    die();
  }
  if($id) $fonline=fonlineusers($id);
  $hotcount=mysql_result(mysql_query('SELECT hotcount FROM misc'),0,0);
  if($log && $id){
    $headlinks.=" | Mark forum read";
    $header=makeheader($header1,$headlinks,$header2);
  }
  if(!$ppp) $ppp=(!$log?20:$loguser[postsperpage]);
  if(!$tpp) $tpp=(!$log?50:$loguser[threadsperpage]);
  if($id) $newpost="
$newpollpic | $newthreadpic";
  print "
	$header
	$tblstart$tccell1s>$fonline$tblend
	
	$tblstart
  ";
  if($forum[minpower]>0 and ($log and $power<$forum[minpower]))
    print "
	$tccell1>Couldn't enter this restricted forum, as you don't have access to it. 
	".redirect('index.php','return to the board',0);
  elseif($forum[minpower]>0 and !$log)
    print "
	$tccell1>Couldn't enter this restricted forum, as you are not logged in. 
	".redirect('login.php','log in (then try again)',0);
  else{
    if($id){
	$anncs=mysql_query('SELECT user,date,announcements.title,name,sex,powerlevel FROM announcements,users WHERE forum=0 AND user=users.id ORDER BY date DESC LIMIT 1');
	if($annc=mysql_fetch_array($anncs)){
	  $namecolor=getnamecolor($annc[sex],$annc[powerlevel]);
	  print "
	     | Announcements | 
	    | $annc[title] -- Posted by $annc[name] on ".date($dateformat,$annc[date]+$tzoff)." | 
	  ";
	}
	$anncs=mysql_query("SELECT user,date,announcements.title,name,sex,powerlevel FROM announcements,users WHERE forum=$id AND user=users.id ORDER BY date DESC LIMIT 1");
	if($annc=mysql_fetch_array($anncs)){
	  $namecolor=getnamecolor($annc[sex],$annc[powerlevel]);
	  print "
	    $tccellhs colspan=7>Forum announcements
	    $tccell1l colspan=7>$annc[title] -- Posted by $annc[name] on ".date($dateformat,$annc[date]+$tzoff)."
	  ";
	}
    }
    print "
	$tccellh> 
	$tccellh colspan=2> Thread
	$tccellh>Started by
	$tccellh width=60> Replies
	$tccellh width=60> Views
	$tccellh width=150> Last post
    ";
    $min=$page*$tpp;
    if($id) $threads=mysql_query("SELECT t.*,u1.name AS name1,u1.sex AS sex1,u1.powerlevel AS power1,u2.name AS name2,u2.sex AS sex2,u2.powerlevel AS power2 FROM threads t,users u1,users u2 WHERE forum=$id AND u1.id=t.user AND u2.id=t.lastposter ORDER BY sticky DESC,lastpostdate DESC LIMIT $min,$tpp");
    elseif($user){
	$threadcount=mysql_result(mysql_query("SELECT COUNT(*) FROM threads where user=$user"),0,0);
	$threads=mysql_query("SELECT threads.*,'".addslashes($user1[name])."' AS name1,$user1[sex] AS sex1,$user1[powerlevel] AS power1,name AS name2,sex AS sex2,powerlevel AS power2,minpower FROM threads,users,forums WHERE user=$user AND users.id=threads.lastposter AND forums.id=forum ORDER BY sticky DESC,lastpostdate DESC LIMIT $min,$tpp");
    }elseif($fav){
	if(!$u or !$isadmin) $u=$loguserid;
	$threadcount=mysql_result(mysql_query("SELECT COUNT(*) FROM favorites where user=$u"),0,0);
	$threads=mysql_query("SELECT threads.*,u1.name AS name1,u1.sex AS sex1,u1.powerlevel AS power1,u2.name AS name2,u2.sex AS sex2,u2.powerlevel AS power2,minpower FROM threads,users AS u1,users AS u2,forums,favorites WHERE u1.id=threads.user AND u2.id=threads.lastposter AND favorites.thread=threads.id AND favorites.user=$u AND forums.id=forum ORDER BY sticky DESC,lastpostdate DESC LIMIT $min,$tpp");
    }
    if($threadcount>$tpp){
	$query=($id?"id=$id":"user=$user");
	$pagelinks2=$smallfont."Pages:";
	for($k=0;$k<($threadcount/$tpp);$k++)
	  $pagelinks2.=($k!=$page?" ".($k+1).'':' '.($k+1));
    }
    $sticklast=0;
    for($i=1;$thread=mysql_fetch_array($threads);$i++){
	if($sticklast and !$thread[sticky]) print "
";
	$sticklast=$thread[sticky];
	$hot=0;
	if($thread[replies]>=$hotcount and $hotcount) $hot=1;
	if(($thread[lastpostdate]>$postread[$id] and $log and $id) or ($thread[lastpostdate]>ctime()-3600 and (!$log or !$id))){
	  $new=' ';
	  if($hot) $new=' ';
	}else{
	  $new=' ';
	  if($hot) $new=' ';
	}
	if($thread[closed]) $new=' ';
	if($hot and $thread[closed]) $new=' ';
	$posticon=" ";
	$pagelinks='';
	if($thread[replies]>=$ppp){
	  $pagelinks=$smallfont.'(Pages:';
	  for($k=0;$k<(($thread[replies]+1)/$ppp);$k++) $pagelinks.=" ".($k+1).'';
	  $pagelinks.=')';
	}
	$thread[title]=str_replace('<','<',$thread[title]);
	$threadtitle="$thread[title]";
	$threadtitle=($thread[sticky]?'Sticky'.($thread[poll]?' poll':'').': ':($thread[poll]?'Poll: ':''))
			.(($thread[sticky] or $thread[poll])?"$threadtitle":$threadtitle);
	if(!$thread[icon]) $posticon=' ';
	if($i>1) print ' | 
';
	$namecolor1=getnamecolor($thread[sex1],$thread[power1]);
	$namecolor2=getnamecolor($thread[sex2],$thread[power2]);
	if((($user or $fav) && ($thread[minpower]<1 or $thread[minpower]<=$power)) or $id){
	  print "
	    $tccell1>$new
	    $tccell2>$posticon
	    $tccell2l>$threadtitle $pagelinks
	    $tccell2>$thread[name1]
	    $tccell1>$thread[replies]
	    $tccell1>$thread[views]
	    $tccell2>".date($dateformat,$thread[lastpostdate]+$tzoff)."$smallfont
by $thread[name2]";
	}else print "$tccell2s colspan=7>(restricted)";
    }
  }
  print "$tblend$pagelinks2
".doforumlist($id).$footer;
  printtimedif($startingtime);
?>