<?php
//////////////////////////////////////////////////////////////////////
//     Multi Forums Pro Host v1.3 - sebflipper Copyright 2003       //
//                   http://www.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__)."/conf_global/multiforums.config.inc.php")) { 
	// If is does then load it into the script
	require dirname(__FILE__)."/conf_global/multiforums.config.inc.php";
}
else
{
	header("Location: conf_global");
	exit;
}

if ($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)) {		
		$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 ;");
				
		header("Location: $mf_url/?mforum=$go_sql_result[access_name]");
	}
	else
	{
		echo "Forum not found";
	}
	exit;
}

if ($auto_cache_time == true) {
	// next cache
	$next_cache_secs = (($auto_cache_time * 60) * 60);
	$next_cache = ($last_cache + $next_cache_secs);
					
	// check last cache
	if (mktime() >= $next_cache OR $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 and member count
							$stats_sql = mysql_query("SELECT * FROM `$forums_result[access_name]_stats`");
							if ($stats_result = mysql_fetch_array($stats_sql)) {
								$total_posts = $stats_result[TOTAL_REPLIES] + $stats_result[TOTAL_TOPICS];
								$total_members = $stats_result[MEM_COUNT];
							}
							
							// open file
							include "$mf_path"."conf_global/$forums_result[access_name].php";
							
							$sql_freeforum_board_access_name = addslashes($INFO[freeforum_board_access_name]);
							$sql_board_start = addslashes($INFO[board_start]);
							$sql_board_name = addslashes($INFO[board_name]);
							$sql_email_in = addslashes($INFO[email_in]);
							$sql_cat = addslashes($INFO[cat]);
							
							$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);
							
							// 	reset
							$INFO[freeforum_board_access_name] = "";
							$INFO[board_start] = "";
							$INFO[board_name] = "";
							$INFO[email_in] = "";
							$INFO[cat] = "0";
							
							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" />
<style type="text/css">
TABLE, TR, TD { 
 font-family: Verdana, Tahoma, Arial;
 font-size: 12px;
 color: #000;
}


hr { 
	color: #7691AC;
}

.mainframe {
    background-color : #333333;
    border-top-width : 1px;
    border-top-color : #000;
    border-top-style : solid;
	
    border-right-width : 1px;
    border-right-color : #000;
    border-right-style : solid;
	
    border-bottom-width : 1px;
    border-bottom-color : #000;
    border-bottom-style : solid;
	
    border-left-width : 1px;
    border-left-color : #000;
    border-left-style : solid;
}

.contentbox {
	background-color : #FAFAFA;
	padding: 3px;
	
	color: #000;
    font-size : 12px;
    font-family : Verdana, Arial, Helvetica, sans-serif;
}

.contentbox a:link, a:visited {
	text-decoration: none;
	color: #000;
}

.contentbox a:hover, a:active {
	text-decoration: none;
	color: #222;
}

.copyright {
    border-top-width : 1px;
    border-top-color : #000;
    border-top-style : solid;

	background-color : #DCEDFF;
	padding: 2px;
	
	color: #000;
    font-size : 10px;
    font-family : Verdana, Arial, Helvetica, sans-serif;
}

/* Board Directory */
.title { font-size:14px;
color:#FFF; font-weight:bold; padding:5px 5px 5px 5px; border:1px solid #345487;
	background-image: url(html/sys-img/tile_sub.gif); }
	
.content {font-size:10px; color: #000; background-color:#EEF2F7; padding:2px 0px 2px 5px;
line-height:1.7em; border:1px solid #345487;}

.cattitle  {
		font-size:14px;
		font-weight:bold;
		line-height:150%;
		background-color:#C4DCF7;
		color:#000;
		padding:2px 2px 2px 2px;
		background-image: url(html/sys-img/tile_sub.gif);
		border-bottom:1px solid #345487;
		align:left;
			}
			
.catdesc {
		font-size:9px;
		color: #000;
		background-color:#DFE6EF;
		padding:2px 0px 2px 5px;
		line-height:1.2em;
		}
		
.tableborder { border:1px solid #345487;background-color:#FFF; }
.dd { background-color: #FFF; color:#000; font-size:10px; font-family: Verdana,Arial, Sans-Serif; padding:2px;  border:2px inset #BCD0ED; }

.barred   { border:1px solid #BCD0ED;background-color: #DFE6EF;font-size:10px;margin:5px px 5px 0px;color:#3A4F6C;font-weight:bold;}
.pages   { border:1px solid #BCD0ED;background-color: #DFE6EF;font-size:10px;margin:5px px 5px 0px;color:#3A4F6C;font-weight:bold;}
.menu   { border:1px solid #BCD0ED;background-color: #DFE6EF;font-size:11px;margin:5px px 5px 0px;color:#000000;font-weight:bold;}

a:hover { color: #FF0000; }

</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=mainframe cellSpacing=0 cellPadding=0 width=748 align=center border=0><TBODY><TR><TD class=contentbox vAlign=top> <DIV class=menu>» <a href=$PHP_SELF>Board Directory</a></DIV><BR><TABLE valign='top'><TBODY><TR><TD vAlign=top width='45%'>";
		do {
			echo "<table width=300 border=0 class=tableborder>
					  <tr><td class=cattitle><A href='$PHP_SELF?cat=$cat_diplay_result[id]'>$cat_diplay_result[name]</A></td></tr>
					  <tr><td class=catdesc>$cat_diplay_result[desc]</td></tr>
				   </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));
	}
	
	
	// diplay forums lists
}
else
{
	if ($sort == false) {
		$sort = "c_posts";
	}
	
	if ($sortmethod == false) {
		$sortmethod = "DESC";
	}
	
	$forum_diplay_sql = mysql_query("SELECT * FROM `multiforums_forums` WHERE 1 AND `cat` = $cat ORDER BY `$sort` $sortmethod LIMIT 0 , 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 "<TABLE class=mainframe cellSpacing=0 cellPadding=0 width=50% align=center border=0><TBODY><TR><TD class=contentbox vAlign=top> <DIV class=menu>» <a href=$PHP_SELF>Board Directory</a> » <a href=$PHP_SELF?cat=$cat>$cat_name</a></DIV><BR><TABLE valign='top'><TBODY><TR><TD class=contentbox vAlign=top>";

	if ($forum_diplay_result = mysql_fetch_array($forum_diplay_sql)) {
		?>
		<DIV class=menu align=right valign=middle> 
		<FORM name=sorter action=<?php echo "$PHP_SELF?cat=$cat&p=0"; ?> method=post>
				Sort By: 
				<SELECT class=dd 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 class=dd 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=pages>» 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>";
		
		// 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 hight=500 width=500 border=0><tr><td class=title><A href=$PHP_SELF?go=$forum_diplay_result[id] target=_blank>$forum_diplay_result[forum_name]</A></td></tr>
        <tr><td class=content><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>
		</td></tr></table>
        <BR>";			
		} while ($forum_diplay_result = mysql_fetch_array($forum_diplay_sql));
	}
	else
	{
		echo "No forums found in this category";
	}
}
echo "</table></table><br>";
$cache_time = date("j M, Y H:i T", $last_cache);
echo "<center><font size=1 face='Arial, Helvetica, sans-serif'>Last Update: $cache_time</font></center>";

	if ($copyright == "yes") {
		echo "<div align=center><font size=1 face='Arial, Helvetica, sans-serif'>Powered by <a href=http://www.sebflipper.com target=_blank>Multi-Forums</a> $version</div>";
	}
	else
	{
		echo "<!--Powered by Multi-Forums $version - http://www.sebflipper.com-->";
	}
?>
