<?php

 
  $t_gif="<IMG SRC=\"$forum_url/images/t.gif\" WIDTH=12 HEIGHT=21 BORDER=0>";
  $l_gif="<IMG SRC=\"$forum_url/images/l.gif\" WIDTH=12 HEIGHT=21 BORDER=0>";
  $p_gif="<IMG SRC=\"$forum_url/images/p.gif\" WIDTH=9 HEIGHT=21 BORDER=0>";
  $m_gif="<IMG SRC=\"$forum_url/images/m.gif\" WIDTH=9 HEIGHT=21 BORDER=0>";
  $c_gif="<IMG SRC=\"$forum_url/images/c.gif\" WIDTH=9 HEIGHT=21 BORDER=0>";
  $i_gif="<IMG SRC=\"$forum_url/images/i.gif\" WIDTH=12 HEIGHT=21 BORDER=0>";
  $n_gif="<IMG SRC=\"$forum_url/images/n.gif\" WIDTH=9 HEIGHT=21 BORDER=0>";
  $space_gif="<IMG SRC=\"$forum_url/images/trans.gif\" WIDTH=5 HEIGHT=21 BORDER=0>";
  $trans_gif="<IMG SRC=\"$forum_url/images/trans.gif\" WIDTH=12 HEIGHT=21 BORDER=0>";
  
  function echo_data($image, $topic, $row_color){
    global $sess,$FORUM_URL;
	global $WEBMASTER_NAME, $WEBMASTER_IMG;
	
    GLOBAL $ForumTableWidth,$ForumTableHeaderColor,$ForumTableHeaderFontColor;
    GLOBAL $ForumTableBodyColor1,$ForumTableBodyFontColor1,$ForumTableBodyColor2,$ForumTableBodyFontColor2;
    GLOBAL $read_page,$ext,$collapse,$id,$UseCookies;
    GLOBAL $space_gif,$num,$old_message,$haveread,$use_haveread;
    GLOBAL $lNew, $GetVars;
    $thread_total="";
    
    if(($row_color%2)==0){
			$bgcolor="#FFFFFF";
      $font_color="#000000";
    }
    else{
			$bgcolor="#EFEFEF";
      $font_color="#000000";
    }  

    $subject ="<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0";
    if($bgcolor!=""){
        $subject.=" BGCOLOR=\"".$bgcolor."\"";
    }
    $subject.=">\n";
    $subject.="<TR>\n<TD>";
    $subject.=$space_gif;
    $subject.=$image."</TD>\n<TD class=smallDark>&nbsp;";

    if($id==$topic["id"] && $read=true){
        $subject .= "<span class=boldDark>".$topic["subject"]."</span>";
        $author = "<span class=smallBoldDark>".$topic["author"]."</span>";
        $datestamp = "<span class=smallBoldDark>".old_date_format($topic["datestamp"])."</span>";
    }
    else{
        $subject.="<a class=smallDarkLink href=\"".$sess->link3($FORUM_URL."$read_page.$ext","f=$num&i=".$topic["id"]
        ."&t=".$topic["thread"]."$GetVars")."\">".$topic["subject"]."</a>";
        $author = $topic["author"];
        $datestamp = old_date_format($topic["datestamp"]);
    }

	$author = setAuthor($topic["author"], "Name");
	/*
	if ($topic["author"] == $WEBMASTER_NAME)
	{
		$author .= "&nbsp;<img src=".$WEBMASTER_IMG." border=0>";
	}
	*/
	
    $subject.="&nbsp;&nbsp;</font>";

    if($UseCookies){
      $isnew=false;
      if($use_haveread==true){
        if ($old_message<$topic["id"]) {
          if(!IsSet($haveread[$topic["id"]])) $isnew=true;
        }
      }
      elseif($old_message<$topic["id"]){
        $isnew=true;
      }
      if($isnew){
        $subject.="<span class=smallDarkRed>".$lNew."</span>";
      }
    }

    $subject.="</TD>\n</TR>\n</TABLE>";
?>  
<TR VALIGN=middle>
<TD align=left <?PHP echo bgcolor($bgcolor);?>><?php echo $subject;?></TD>
<TD align=left <?PHP echo bgcolor($bgcolor);?> class=smallDark><?php echo $author;?></TD>
<TD align=right <?PHP echo bgcolor($bgcolor);?> nowrap class=smallDark><?php echo $datestamp;?>&nbsp;</TD>
</TR>
<?php
  }

  function thread($seed=0){

    GLOBAL $row_color_cnt;
    GLOBAL $messages,$threadtotal;
    GLOBAL $font_color, $bgcolor;
    GLOBAL $t_gif,$l_gif,$p_gif,$m_gif,$c_gif,$i_gif,$n_gif,$trans_gif;    
    
    $image="";
    $images="";
      
    if(!IsSet($row_color_cnt)){
      $row_color_cnt=0;
    }

    $row_color_cnt++;

    if($seed!="0"){
      $parent=$messages[$seed]["parent"];
      if($parent!=0){
        if(!IsSet($messages[$parent]["images"])){  
          $messages[$parent]["images"]="";
        }
        $image=$messages[$parent]["images"];
        if($messages[$parent]["max"]==$messages[$seed]["id"]){
          $image.=$l_gif;
        }
        else{
          $image.=$t_gif;
        }
      }

      if(@is_array($messages[$seed]["replies"])){
        if(IsSet($messages[$parent]["images"])){
          $messages[$seed]["images"]=$messages[$parent]["images"];
          if($seed==$messages["$parent"]["max"]){
            $messages[$seed]["images"].=$trans_gif;
          }
          else{
            $messages[$seed]["images"].=$i_gif;
          }  
        }
        $image.=$m_gif;
      }
      else{
        if($messages[$seed]["parent"]!=0){
          $image.=$c_gif;
        }
        else{
          if($threadtotal[$messages[$seed]["thread"]]>1){
            $image.=$p_gif;
          }
          else{
            $image.=$n_gif;
          }
        }
      }        

      echo_data($image, $messages[$seed], $row_color_cnt);
    }//end of: if($seed!="0")
    
    if(@is_array($messages[$seed]["replies"])){
      $count=count($messages[$seed]["replies"]);
      for($x=1;$x<=$count;$x++){
        $key=key($messages[$seed]["replies"]);
        thread($key);
        next($messages[$seed]["replies"]);
      } 
    }
  }  

  @reset($headers);
  $row=@current($headers);

  if(is_array($row)){
    if(!$read){
      reset($threads);
      $rec=current($threads);
      while(is_array($rec)){
        $thd=$rec["thread"];
        if(!isset($rec["tcount"])) $rec["tcount"]=0;
        $tcount=$rec["tcount"];
        $threadtotal[$thd]=$tcount;
        $rec=next($threads);
      }
    }
    else{
      $threadtotal[$thread]=count($headers);
    }
    $topics["max"]="0";
    $topics["min"]="0";
    While(is_array($row)){
      $x="".$row["id"]."";
      $p="".$row["parent"]."";
      $messages["$x"]=$row;
      $messages["$p"]["replies"]["$x"]="$x";
      $messages["$p"]["max"]=$row["id"];
      if(!isset($messages["max"])) $messages["max"]=0;
      if(!isset($messages["min"])) $messages["min"]=0;
      if($messages["max"]<$row["thread"]) $messages["max"]=$row["thread"];
      if($messages["min"]>$row["thread"]) $messages["min"]=$row["thread"];
      $row=next($headers);
    }
  }
  
?>
<TABLE WIDTH="<?php echo $ForumTableWidth;?>" CELLSPACING=0 CELLPADDING=0 BORDER=0>
<TR bgcolor="#FFFFFF">
    <TD height=21 align=left class=boldDarkGreen>&nbsp;<?php echo $lTopics;?></TD>
    <TD height=21 align=left class=boldDarkGreen><?php echo $lAuthor;?>&nbsp;</TD>
    <TD height=21 align=right class=boldDarkGreen><?php echo $lDate;?>&nbsp;&nbsp;</TD>
</TR>
<?php
  thread();
?>
</TABLE>
