<?


include "config.php";
include "banners.php";
include "header.php";


?>


<table width="450" border="0" align="center" cellpadding="4" cellspacing="0">
  <tr>
    <td> 
      <? include "templates/IndexTemplate.php"; ?>
      <p><strong><font size="4">Categories<br>
        <br>
        </font></strong></p></td>
  </tr>
  <tr>
    <td> 
      <table width="475" border="0" align="center" cellpadding="4" cellspacing="0">
        <tr>
          <td>
            <?
	$result = MySQLQuery("SELECT id,sub_cat,name FROM links_cat WHERE sub_cat='0' ORDER BY name ASC", $QueryError_Email,$QueryError_Browser);
		$count=0;
		if(mysql_num_rows($result))
		{
			echo "<table cellpadding=\"0\" cellspacing=\"0\" style=\"border-style:none;width:100%;\">\n";
			while($row=mysql_fetch_array($result))
			{
				$count=$count+1;
				$id=$row["id"];
				$sub_cat=$row["sub_cat"];
				$name=$row["name"];
				$dsc=$row["dsc"];
				$link_count = MySQLQuery("SELECT * FROM links WHERE cat_id='".$id."' AND approved='yes' ORDER BY name ASC", $QueryError_Email,$QueryError_Browser);
				$link_count=mysql_num_rows($link_count);
				if($link_count==1){$link_text="";}else{$link_text="";}
				if($count <= $front_cols && $count==1){echo "<tr>\n<td align=\"left\" valign=\"top\" style=\"width:$front_perc;\">\n";}
				else if($count < $front_cols && $count > 1){echo "<td class=\"bodymd\">&nbsp;&nbsp;</td>\n<td align=\"left\" valign=\"top\" style=\"width:$front_perc;\">\n";}
				else if($count==$front_cols){echo "<td class=\"bodymd\">&nbsp;&nbsp;</td>\n<td align=\"left\" valign=\"top\" style=\"width:$front_perc;\">\n";}
				echo "<a class=categorylinks href=\"directory.php?ax=list&amp;sub=$id&amp;cat_id=$id\">$name</a> ($link_count $link_text)\n";
				$result2 = MySQLQuery("SELECT id,sub_cat,name FROM links_cat WHERE sub_cat='$id' ORDER BY name ASC", $QueryError_Email,$QueryError_Browser);
				if(mysql_num_rows($result2))
				{
					echo "<BR>";
					while($row2=mysql_fetch_array($result2))
					{
						$id2=$row2["id"];
						$sub_cat2=$row2["sub_cat"];
						$name2=$row2["name"];
						$link_count = MySQLQuery("SELECT * FROM links WHERE cat_id='".$id2."' AND approved='yes' ORDER BY name ASC", $QueryError_Email,$QueryError_Browser);
						$link_count=mysql_num_rows($link_count);
						if($link_count==1){$link_text="link";}else{$link_text="links";}
						echo "<a class=sub href=\"directory.php?ax=list&amp;sub=$sub_cat2&amp;cat_id=$id2\">$name2</a> ($link_count):\n";
					}
					echo "";
				}
				if($count <= $front_cols && $count==1){echo "<br /><br />\n</td>\n";}
				else if($count < $front_cols && $count > 1){echo "<br /><br />\n</td>\n";}
				else if($count==$front_cols){echo "<br /><br />\n</td>\n";}
				if($count==$front_cols){$count=0;}
			}
			if($count < $front_cols)
			{
				$spacer=($front_cols - $count) * 2;
				echo "\n<td class=\"bodymd\" colspan=\"$spacer\">&nbsp;&nbsp;</td>\n";
			}
			echo "</tr>\n</table>\n";
		}
		else
		{
			echo "<p class=\"bodymd\">No categories found</p>";
		}
		
		?>
          </td>
        </tr>
      </table></td>
  </tr>
</table>
<? 

include "footer.php";

?>
