<?php
//////////////////////////////////////////////////////////////////////
//              Multi Forums Pro Host v1.0 for phpBB                //
//                   sebflipper Copyright 2003                      //
//                   sebflipper.com                      //
//                        Main Script File                          //
//                                                                  //
// Please DO NOT edit this file unless you know what you are doing  //
//                                                                  //
//        By using this script you agree to the Licence             //
//                                                                  //
//////////////////////////////////////////////////////////////////////

// For getting post and get stuff for newer versions of PHP
if ( phpversion() >= "4.2.0")
{
	extract($_POST);
	extract($_GET);
} 

// Loading configuration file for the rest of the modules use
// dirname(__FILE__) is a command use to get the location of the script (eg C:\Program Files\EasyPHP\www or /user/bin/hostname/etc)
if(is_file(dirname(__FILE__)."/config/multiforums.config.inc.php")) 
{ 
	// If is does then load it into the script
	require dirname(__FILE__)."/config/multiforums.config.inc.php";
}
else
{
	header("Location: config");
	exit;
}

// Check if the system is offline
if ($multiforums_setting[master_offline] == true) 
{
	header("Location: $multiforums_setting[offline_error_url]");
	exit;
}

if ($_GET[go] == true)
{	
	$go_sql = mysql_query("SELECT `id` , `access_name` , `cat_hits` FROM `multiforums_forums` WHERE 1 AND `id` = $go LIMIT 0 , 1");
	
	if ($go_sql_result = mysql_fetch_array($go_sql))
	{		
		// check if counted already
		if ($_COOKIE[FreeForumsGo] != $_GET[go])
		{
			$new_hits = ($go_sql_result[cat_hits] + 1);
			$add_sql = mysql_query("UPDATE `multiforums_forums` SET `cat_hits` = '$new_hits' WHERE `id` = '$go_sql_result[id]' LIMIT 1 ;");
		}
	}
	else
	{
		echo "Forum not found";
	}
	// set viewed cookie
	setcookie ("FreeForumsGo", $_GET[go]);
	header("Location: $multiforums_setting[mf_url]/?mforum=$go_sql_result[access_name]");	
	exit;
}

if ($multiforums_setting[auto_cache_time] == true)
{
	// next cache
	$next_cache_secs = (($multiforums_setting[auto_cache_time] * 60) * 60);
	$next_cache = ($multiforums_setting[last_cache] + $next_cache_secs);
					
	// check last cache
	if (mktime() >= $next_cache OR $multiforums_setting[last_cache] == false) {
			echo "<b>Updating Forum Cache</b> Please wait...<!--Debug Status: ";

			$forums_sql = mysql_query("SELECT * FROM `multiforums_forums`");
			if ($forums_result = mysql_fetch_array($forums_sql)) {
				do {
							// start
							$on_no++;
							
							// get post count												
							$stats_sql = mysql_query("SELECT * FROM `$forums_result[access_name]_posts`");
							$total_posts = mysql_num_rows($stats_sql);
							
							// get member count
							$stats_sql = mysql_query("SELECT * FROM `$forums_result[access_name]_users`");
							$total_members = mysql_num_rows($stats_sql);
							$total_members = $total_members - 1; //remove guest count
														
							// get start date
							$stats_sql = mysql_query("SELECT * FROM `$forums_result[access_name]_config` WHERE 1 AND `config_name` = 'board_startdate' LIMIT 1");
							if ($stats_result = mysql_fetch_array($stats_sql)) {
								$sql_board_start = $stats_result[config_value];
							}
							
							// get board name
							$stats_sql = mysql_query("SELECT * FROM `$forums_result[access_name]_config` WHERE 1 AND `config_name` = 'sitename' LIMIT 1");
							if ($stats_result = mysql_fetch_array($stats_sql)) {
								$sql_board_name = $stats_result[config_value];
							}
							
							// get email address
							$stats_sql = mysql_query("SELECT * FROM `$forums_result[access_name]_config` WHERE 1 AND `config_name` = 'board_email' LIMIT 1");
							if ($stats_result = mysql_fetch_array($stats_sql)) {
								$sql_email_in = $stats_result[config_value];
							}							
																																																					
							// open file
							include "$multiforums_setting[mf_path]"."config/$forums_result[access_name].php";
							
							// get access name and cat from file
							$sql_freeforum_board_access_name = $multi_forums_board_access_name;
							$sql_cat = $multi_forums_cat;
							
							// addslashes to user editable data
							$sql_board_name = addslashes($sql_board_name);
							$sql_email_in = addslashes($sql_email_in);
							
							
							$updatesql = "UPDATE `multiforums_forums` SET `access_name` = '$sql_freeforum_board_access_name', `board_start` = '$sql_board_start', `forum_name` = '$sql_board_name', `cat` = '$sql_cat', `admin_email` = '$sql_email_in', `c_posts` = '$total_posts', `c_members` = '$total_members' WHERE `access_name` = '$forums_result[access_name]' LIMIT 1 ;";
							$updatesql_result = mysql_query($updatesql);						
							
							echo "$on_no ";
							
				} while ($forums_result = mysql_fetch_array($forums_sql));							
			}
			$mktime = mktime();
			$set_last_cache = mysql_query("UPDATE `multiforums_settings` SET `value` = '$mktime' WHERE `v_name` = 'last_cache' LIMIT 1 ;");
			echo "done!--><script language=javascript1.1>window.location='$PHP_SELF?cat=$cat';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript>";
			exit;
	}
}

?>
	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
	<html xmlns="http://www.w3.org/1999/xhtml">
	
<head>
<title>Board Directory</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="templates/subSilver/subSilver.css" type="text/css">
<style type="text/css">
<!--
/*
  The original subSilver Theme for phpBB version 2+
  Created by subBlue design
  http://www.subBlue.com
*/
/* General site text */
.siteTitle		{ font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; font-size : 22px; font-weight : bold; text-decoration : none; line-height : 120%; color : #006699; }

.siteTextSmall	{ font-size : 10px; font-family: Verdana, Arial, Helvetica, sans-serif}
.siteTextMed	{ font-size : 11px; font-family: Verdana, Arial, Helvetica, sans-serif}
.siteText,p		{ font-size : 12px; font-family: Verdana, Arial, Helvetica, sans-serif}

a.siteText,a.siteTextMed,a.siteTextSmall { color: #006699; text-decoration: none; }
a.siteText:hover,a.siteTextMed:hover,a.siteTextSmall:hover	{ color: #FF6600; text-decoration: underline; }

.siteBotLinks	{ font-size : 11px; color : #333333; ; font-family: Verdana, Arial, Helvetica, sans-serif }
a.siteBotLinks, a.siteBotLinks:visited	{ color: #333333; text-decoration: none; }
a.siteBotLinks:hover	{ color: #004c75; text-decoration: underline; }

.bgTop		{  background-image:  url(/images/bg_top.gif); background-repeat: repeat-x}
.bgBottom	{  background-color: #E8EEF2; background-image:  url(/images/bg_bottom.gif); background-repeat: repeat-x}
.bgMiddle	{  background-image:  url(/images/bgMiddle.gif); background-repeat: repeat-x}

th			{ background-image: url(/templates/subSilver/images/cellpic3.gif) }
td.cat		{ background-image: url(/templates/subSilver/images/cellpic1.gif) }
td.rowpic	{ background-image: url(/templates/subSilver/images/cellpic2.jpg); background-repeat: repeat-y }
td.catHead,td.catSides,td.catLeft,td.catRight,td.catBottom { background-image: url(/templates/subSilver/images/cellpic1.gif) }
-->
</style>
</head>
<body>	
<?php

if ($cat == false) {
	// diplay cat list
	$cat_diplay_sql = mysql_query("SELECT * FROM `multiforums_cats` WHERE 1 ORDER BY `name` ASC;");
	$cat_display_no = mysql_num_rows($cat_diplay_sql);
	$cat_cut_no = $cat_display_no / 2;
	$cat_cut_no = floor($cat_cut_no);
	
	if ($cat_diplay_result = mysql_fetch_array($cat_diplay_sql)) {
	echo "<TABLE class=bodyline bgcolor=white cellSpacing=0 cellPadding=0 width=748 align=center border=0><TBODY><TR><TD vAlign=top> <DIV class=cattitle>» <a href=$PHP_SELF>Board Directory</a></DIV><BR><TABLE valign='top'><TBODY><TR><TD vAlign=top width='45%'>";
		do {
			echo "<table align=center width=70% border=0 cellpadding=3 cellspacing=1 class=forumline>
				  <tbody>
					<tr>
					  <td class=catHead height=28><span class=cattitle><a href='$PHP_SELF?cat=$cat_diplay_result[id]'>$cat_diplay_result[name]</a></span></td>
					</tr>
					<tr>
					  <TD class=row1 vAlign=center align=left height=28><SPAN class=gensmall>$cat_diplay_result[desc]</SPAN></td>
					</tr>
				  </tbody>
				</table><br />";
				   			   
			$i++;
			if ($i == $cat_cut_no) {
				echo "</TD>
				  <TD width='10%'>&nbsp;</TD>
				  <TD vAlign=top width='45%'>";
			}
			
		} while ($cat_diplay_result = mysql_fetch_array($cat_diplay_sql));
		echo "</TD></TR></TBODY></TABLE></FORM><BR clear=all>";
	}
	
	
	// diplay forums lists
}
else
{
	if ($sort == false) {
		$sort = "c_posts";
	}
	
	if ($sortmethod == false) {
		$sortmethod = "DESC";
	}
	
	if ($p == false) {
		$p = "0";
	}
	
	$forum_diplay_sql = mysql_query("SELECT * FROM `multiforums_forums` WHERE 1 AND `cat` = $cat ORDER BY `$sort` $sortmethod LIMIT $p , 10");
	$cat_diplay_sql = mysql_query("SELECT * FROM `multiforums_cats` WHERE 1 AND `id` = $cat LIMIT 0 , 1");

	if ($cat_diplay_result = mysql_fetch_array($cat_diplay_sql)) {
		$cat_name = $cat_diplay_result[name];
	}
	else
	{
		$cat_name = "Category not found";
	}

	echo "";

	echo "<TABLE class=bodyline bgcolor=white cellSpacing=0 cellPadding=0 width=748 align=center border=0><TBODY><TR><TD vAlign=top> <DIV class=cattitle>» <a href=$PHP_SELF>Board Directory</a> » <a href=$PHP_SELF?cat=$cat>$cat_name</a></DIV><BR><TABLE valign='top'><TBODY><TR><TD vAlign=top width='45%'>";

	if ($forum_diplay_result = mysql_fetch_array($forum_diplay_sql)) {
		?>
		<DIV class=nav align=right valign=middle> 
		<FORM name=sorter action=<?php echo "$PHP_SELF?cat=$cat&p=0"; ?> method=post>
				Sort By: 
				<SELECT name=sort>
				  <OPTION value="board_start" <?php if ($sort == "board_start") { echo "selected"; }?>>Board Created Date</OPTION>
				  <OPTION value="c_posts" <?php if ($sort == "c_posts") { echo "selected"; }?>>Post Count</OPTION>
				  <OPTION value="c_members" <?php if ($sort == "c_members") { echo "selected"; }?>>Member Count</OPTION>
				  <OPTION value="forum_name" <?php if ($sort == "forum_name") { echo "selected"; }?>>Name of Board</OPTION>
				  <OPTION value="cat_hits" <?php if ($sort == "cat_hits") { echo "selected"; }?>>Hits</OPTION>
				</SELECT>
				in 
				<SELECT name=sortmethod>
				  <OPTION value="ASC" <?php if ($sortmethod == "ASC") { echo "selected"; }?>>Ascending</OPTION>
				  <OPTION value="DESC" <?php if ($sortmethod == "DESC") { echo "selected"; }?>>Descending</OPTION>
				</SELECT>
				Order. 
				<INPUT type=submit value=Go>
		  </FORM>
		</DIV><BR>
		<?php
		
		$total_forums_sql = "SELECT * FROM `multiforums_forums` WHERE 1 AND `cat` = $cat ";
		$total_forums_mysql = mysql_query($total_forums_sql); 
		$total_forums_result = mysql_num_rows($total_forums_mysql); 
		
		echo "<DIV class=nav>» Pages: ";
		// Works out how many pages there are
		$total_pages = ($total_forums_result / 10);
		$total_pages = ceil($total_pages);							
		for ($i = 1;;$i++) {
			if ($i > $total_pages) {
				break;
			}
			$jump = (($i * 10) - 10);
			if ($jump==$p)
			{
				print "<a href=$PHP_SELF?cat=$cat&p=$jump&sort=$sort&sortmethod=$sortmethod>[ $i ]</a> \n";
			}
			else
			{
				print "<a href=$PHP_SELF?cat=$cat&p=$jump&sort=$sort&sortmethod=$sortmethod>$i</a> \n";
			}
		}
		echo "</DIV><br>";
		
		// do this for each forum
		do {
			
			if ($forum_diplay_result[forum_name] == false) {
				$forum_diplay_result[forum_name] = $forum_diplay_result[access_name];				
			}
			
			$board_start = date("j M, Y", $forum_diplay_result[board_start]);
						
			echo "<TABLE class=forumline align=center cellSpacing=1 cellPadding=3 width=45% border=0><TBODY>
        <TR>
          <TD class=catHead height=28><SPAN 
            class=cattitle><A href=$PHP_SELF?go=$forum_diplay_result[id] target=_blank>$forum_diplay_result[forum_name]</A></SPAN></TD></TR>
        <TR>
          <TD class=row1 vAlign=center align=left height=28><SPAN 
            class=gensmall><B>Created on:</B> $board_start<BR>
						  <B>Posts:</B> $forum_diplay_result[c_posts]<BR>
						  <B>Members:</B> $forum_diplay_result[c_members]<BR>
						  <B>Hits:</B> $forum_diplay_result[cat_hits]<BR> 
            </SPAN></TD></TR></TBODY></TABLE><BR clear=all>";			
			
		} while ($forum_diplay_result = mysql_fetch_array($forum_diplay_sql));
	}
	else
	{
		echo "<SPAN class=siteText>No forums found in this category</SPAN>";
	}
}
echo "</table></table><br>";
$cache_time = date("j M, Y H:i T", $multiforums_setting[last_cache]);
echo "<DIV align=center class=copyright>Last Update: $cache_time</div>";

if ($multiforums_setting[copyright] == "yes") {
	echo "<DIV align=center class=copyright>Powered by <a href=sebflipper.com target=_blank>Multi-Forums</a> $multiforums_setting[version]</div>";
}
else
{
	echo "<!--Powered by Multi-Forums $multiforums_setting[version] - sebflipper.com-->";
}
?>
