<?php
//////////////////////////////////////////////////////////////////////
//     Multi Forums Pro Host v1.3 - sebflipper Copyright 2004       //
//                   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, get and cookie info for newer versions of PHP
 if ( phpversion() >= "4.2.0")
    {
    extract($_POST);
    extract($_GET);
    extract($_COOKIE);
    }

// Turn off all error reporting
// Please remove if you are having problems
error_reporting(0);

//Starting script exe timer
$ss_timing_start_times = explode(' ', microtime());

// Loading configuration file for the rest of the modules use
require dirname(__FILE__)."/multiforums.config.inc.php";

// Check for setup
$resultlink = mysql_query("SELECT * FROM `multiforums_settings` LIMIT 0 , 1",$db);
if ($settings = mysql_fetch_array($resultlink)) {
	$setup = false;
}
else
{
	$setup = true;
}

// Version (Do not Change)
$this_version = "Pro Host v1.3.3 for phpBB v2.0.13";

// Upgrade checking/running (don't touch)
if ($this_version == true AND $setup == false) {
	if ($this_version != $multiforums_setting[version]) {
		if ($multiforums_setting[version] == "Pro Host v1.0 for phpBB v2.0.10")
		{
			$upgradesql[] = "ALTER TABLE `multiforums_forums` ADD `bannerless` INT( 1 ) DEFAULT '0' NOT NULL AFTER `online` ;";
		}
				
		$upgradesql[] = "UPDATE `multiforums_settings` SET `value` = '$this_version' WHERE `v_name` = 'version' LIMIT 1 ;";
			
		foreach ($upgradesql as $key => $value) {
    		$run_sql = mysql_query("$value")
			or die(mysql_error());
		}
		
		echo "<script language=javascript1.1>alert('Admin CP database upgrade to $this_version completed successfully');</script>";
	}
}

// Database stuff
$db_table_data = array("_auth_access", "_banlist", "_categories", "_config", "_confirm", "_disallow",
						"_forum_prune", "_forums", "_groups", "_posts", "_posts_text", "_privmsgs", "_privmsgs_text",
						"_ranks", "_search_results", "_search_wordlist", "_search_wordmatch", "_sessions", "_smilies", "_themes", "_themes_name",
						"_topics", "_topics_watch", "_user_group", "_users", "_vote_desc", "_vote_results", "_vote_voters", "_words");

$db_table_count = count($db_table_data); 

$full_query_string = "from=$from&max_show=$max_show&sortby=$sortby&sortmeth=$sortmeth";

// Loading configuration file for the rest of the modules use
require dirname(__FILE__)."/multiforums.config.inc.php";

function startHTML() {
?>
	<!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>Multi-Forums Admin</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	
	<style type="text/css">
	  TABLE, TR, TD                   { font-family: Verdana,Arial; font-size: 10px; color: #333333 }
	  BODY                            { background-color: #E5E5E5;
										scrollbar-face-color: #DEE3E7;
										scrollbar-highlight-color: #FFFFFF;
										scrollbar-shadow-color: #DEE3E7;
										scrollbar-3dlight-color: #D1D7DC;
										scrollbar-arrow-color:  #006699;
										scrollbar-track-color: #EFEFEF;
										scrollbar-darkshadow-color: #98AAB1; }
	  a:link, a:visited, a:active     { color: #000055 }
	  a:hover                         { color: #333377; text-decoration: underline }
	  FORM                            { padding: 0; margin: 0 }
	
	  .textbox                        { border: 1px solid black; padding: 1px; width: 100% }
	  .headertable                    { background-color: #FFFFFF; border: 1px solid black; padding: 2px }
	  .title                          { font-size: 10px; font-weight: bold; line-height: 150%; color: #FFA34F; height: 26px; background-image: url(../templates/subSilver/images/cellpic3.gif) }
	  .table1                         { background-color: #FFFFFF; width: 100%; align: center; border: 1px solid black }
	  .tablewrap                      { border: 1px dashed #777777; background-color: ##EFEFEF; vertical-align: middle }
	  .tdrow1                         { background-color: #F4F4F4; padding: 3px }
	  .tdrow2                         { background-color: #FFFFFF; padding: 3px }
	  .tdrowMenu					  { background-color: #CED6DC; padding: 3px }
	  .tdtop                          { font-weight: bold; height: 24px; line-height: 150%; color: #FFFFFF; background-image: url(../templates/subSilver/images/cellpic1.gif) }
	  .note                           { margin: 10px; padding: 5px; border: 1px dashed #555555; background-color: #FFFFFF }
	  .menuskin						  { BORDER-RIGHT: black 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: black 1px solid; PADDING-LEFT: 5px; Z-INDEX: 100; VISIBILITY: hidden; PADDING-BOTTOM: 8px; FONT: 8pt Verdana, Arial, sans-serif; BORDER-LEFT: black 1px solid; WIDTH: 250px; PADDING-TOP: 3px; BORDER-BOTTOM: black 1px solid; POSITION: absolute; BACKGROUND-COLOR: #eeeeee }
	  .menuskin A 					  { PADDING-RIGHT: 10px; PADDING-LEFT: 10px; COLOR: black; TEXT-DECORATION: none }

	</style>
	</head>
	<body>	
<?php
}

function deldir($dir){
  $current_dir = opendir($dir);
  while($entryname = readdir($current_dir)){
	 if(is_dir("$dir/$entryname") and ($entryname != "." and $entryname!="..")){
		deldir("${dir}/${entryname}");
	 }elseif($entryname != "." and $entryname!=".."){
		unlink("${dir}/${entryname}");
	 }
  }
  closedir($current_dir);
  rmdir(${dir});
} 

if ($act == "login") {


	$input_password = md5($input_password);
	setcookie("FreeForumAdminCookie", $input_password);
	header("Location: $_SERVER[PHP_SELF]");
	exit;
}

if ($setup == true) {
	if ($Submit==true) {
		// Check the form
		if ($mf_url==false OR $mf_path==false OR $phpbb_server_name==false OR $phpbb_script_path==false OR $email==false OR $noforum_error_url==false OR $exist_error_url==false OR $offline_error_url==false OR $password==false OR $reg_no==false) {
			echo "<html><body><script language=javascript1.1>alert('Please fill in the form'); javascript:history.back();</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";
			exit;
		}
		
		if ($password!=$password2) {
			echo "<html><body><script language=javascript1.1>alert('Admin passwords do not match'); javascript:history.back();</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";
			exit;	
		}
		
		$password = md5($password);
	
		// Save config
		
			$filename = dirname(__FILE__)."/settings.sql";
	
			$filesize       = filesize($filename);
			$file_position  = isset($HTTP_GET_VARS['pos']) ? $HTTP_GET_VARS['pos'] : 0;
			$errors         = isset($HTTP_GET_VARS['ignore_errors']) ? 0 : 1;
	
			if (!$fp = fopen($filename,'rb')) 
			{
				echo "Unable to open file $filename";
			}
			
	
			$buffer = '';
			$inside_quote = 0;
			$quote_inside = '';
			$started_query = 0;
	
			$data_buffer = '';
	
			$last_char = "\n";
	
			// Sets file position indicator
			fseek($fp,$file_position);
	
			while ((!feof($fp) || strlen($buffer))) 
			{
				do 
				{
					// Deals with the length of the buffer
					if (!strlen($buffer)) 
					{
						$buffer .= fread ($fp,1024);
					}
	
					// Fiddle around with the buffers
					$current_char = $buffer[0];
					$buffer = substr($buffer, 1);
	
	
					if ($started_query)
					{
						$data_buffer .= $current_char;
					} 
					elseif (preg_match("/[A-Za-z]/i",$current_char) && $last_char == "\n") 
					{
						$started_query = 1;
						$data_buffer = $current_char;
					} 
					else 
					{
						$last_char = $current_char;
					}
				} while (!$started_query && (!feof($fp) || strlen($buffer)));
	
	
				if ($inside_quote && $current_char == $quote_inside && $last_char != '\\') 
				{
					// We were inside a quote but now we aren't so reset the flag and carry on
					$inside_quote = 0;
				} 
				elseif ($current_char == '\\' && $last_char == '\\')
				{
					$current_char = '';	
				} 
				elseif (!$inside_quote && ($current_char == '"' || $current_char == '`' || $current_char == '\''))
				{
					// We have just entered a new quote
					$inside_quote = 1;
					$quote_inside = $current_char;
				} 
				elseif (!$inside_quote && $current_char == ';') 
				{
					
					// edit database
					$data_buffer = str_replace("Please Note: Do NOT run this file on its own, as its edited automatically by Admin Setup", "", $data_buffer);
					$data_buffer = str_replace("%mf_url", "$mf_url", $data_buffer);
					$data_buffer = str_replace("%mf_path", "$mf_path", $data_buffer);
					$data_buffer = str_replace("%server_name", "$phpbb_server_name", $data_buffer);
					$data_buffer = str_replace("%script_path", "$phpbb_script_path", $data_buffer);
					$data_buffer = str_replace("%email", "$email", $data_buffer);					
					$data_buffer = str_replace("%password", "$password", $data_buffer);					
					$data_buffer = str_replace("%noforum_error_url", "$noforum_error_url", $data_buffer);
					$data_buffer = str_replace("%exist_error_url", "$exist_error_url", $data_buffer);															
					$data_buffer = str_replace("%offline_error_url", "$offline_error_url", $data_buffer);
					$data_buffer = str_replace("%reg_no", "$reg_no", $data_buffer);					
				
					// End of query so execute query, clear data buffer and advance counter
					mysql_query($data_buffer);
	
					if ($errors && mysql_errno())
					{
						//$new_position = ftell($fp) - strlen($buffer);
						//return $this->restore_error($data_buffer, $new_position);
						echo "<font color=red>There has been a MySQL error, check error message below for details, if this doesn't help check that your connection details are correct, and the MySQL server is stable and running.<br><br><b>MySQL Error Details:</b><br>".mysql_errno().": ".mysql_error()."</font>";
						exit;				
					}
	
	
					$data_buffer = '';
					$last_char = "\n";
					$started_query = 0;
				}
	
				$last_char = $current_char;
			}
	
	
			$new_position = ftell($fp) - strlen($buffer) - strlen($data_buffer);
	
			fclose($fp);
			
			unlink("settings.sql");


		echo "<html><body><script language=javascript1.1>alert('Setup Complete!'); window.location='$_SERVER[PHP_SELF]';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";
		exit;		
	}
	
	$mf_url = "http://$_SERVER[HTTP_HOST]$_SERVER[SCRIPT_NAME]";
	$mf_url = str_replace("/config/index.php", "", $mf_url);
	
	$mf_path = $_SERVER['SCRIPT_FILENAME'];
	$mf_path = str_replace("config/index.php", "", $mf_path);	
	
	$phpbb_server_name = $_SERVER['SERVER_NAME'];
	$phpbb_script_path = $_SERVER['SCRIPT_NAME'];
	$phpbb_script_path = str_replace("config/index.php", "", $phpbb_script_path);		
	startHTML(); 
	?>
	
			  
		  <table align="center" class="tablewrap" cellpadding="0" cellspacing="3" width="450">
        <tr>
          <td align="center" class="title">Multi-Forums Setup</td>
        </tr>
        <tr>
          <td>
            <table class="table1" align="center" width="100%">
              <tr>
<td class="tdrow2" colspan="2"><div align="center">
<p align="center"><strong>Multi-Forums Admin</strong><br>(More options can be configured once the script has been setup)</p>
<div align="center">
<form name="setupform" action="<?php echo $_SERVER[PHP_SELF] ?>" method="post">
  <table border="1" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
    <tr> 
      <td>Script URL:</td>
      <td><input name="mf_url" type="text" id="mf_url" value="<?php echo $mf_url; ?>"></td>
    </tr>
    <tr> 
      <td>Script Path:</td>
      <td><input name="mf_path" type="text" id="mf_path" value="<?php echo $mf_path; ?>"></td>
    </tr>
    <tr> 
      <td>Server Name for phpBB:</td>
      <td><input name="phpbb_server_name" type="text" id="phpbb_server_name" value="<?php echo $phpbb_server_name; ?>"></td>
    </tr>
    <tr> 
      <td>Server Script Path for phpBB:</td>
      <td><input name="phpbb_script_path" type="text" id="phpbb_script_path" value="<?php echo $phpbb_script_path; ?>"></td>
    </tr>		
    <tr> 
      <td>No Forum Selected Error Page: (<a href="http://www.multi-forums.net/?page=freeforum_noforum" target="_blank">eg</a>)</td>
      <td><input name="noforum_error_url" type="text" id="noforum_error_url"></td>
    </tr>
    <tr>
      <td>Forum Doesn't Exist Error Page: (<a href="http://www.multi-forums.net/?page=freeforum_noexist" target="_blank">eg</a>)</td>
      <td><input name="exist_error_url" type="text" id="exist_error_url"></td>
    </tr>
    <tr>
      <td>Offline Error Page: (<a href="http://www.multi-forums.net/?page=freeforum_offline" target="_blank">eg</a>)</td>
      <td><input name="offline_error_url" type="text" id="offline_error_url"></td>
    </tr>	
    <tr> 
      <td>Set Admin Password:</td>
      <td><input name="password" type="password" id="password"></td>
    </tr>
    <tr> 
      <td>Confirm Password:</td>
      <td><input name="password2" type="password" id="password2"></td>
    </tr>
    <tr> 
      <td>Admin Email:</td>
      <td><input name="email" type="text" id="email"></td>
    </tr>
    <tr> 
      <td>Registration Number (from email):</td>
      <td><input name="reg_no" type="text" id="reg_no"></td>
    </tr>	
  </table>
  <br>
  <br>
  <input type="submit" name="Submit" value="Ok">
			  </td>
			  </tr>			  
            </table>
          </td>
        </tr>
      </table>  
  <?php
	exit;
}

if ($FreeForumAdminCookie == true) {
	if ($FreeForumAdminCookie == $multiforums_setting[password]) {
				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) {
						if ($bypass == false) {
							echo "<html><body><script language=javascript1.1>alert('Starting Auto System Cache...'); window.location='$_SERVER[PHP_SELF]?act=update_cache&bypass=true';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";	
							exit;
						}
					}
				}
				
				if ($multiforums_setting[latest_version] == "01") {
					echo "System Halted! Error Number 01";
					exit;
				}
				
				if ($act == "mail") {
				// Check the form
				if ($subject==false OR $message==false) {
					echo "<html><body><script language=javascript1.1>alert('Please fill in the form'); javascript:history.back();</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";
					exit;
				}
				$mail_count = "0";

				// Start email loop
				$result = mysql_query("SELECT * FROM `multiforums_forums`");
				while($r=mysql_fetch_array($result))
				{	
					$mail_count++;
								
					$send_subject = "Multi-Forums Admin Message - $subject";
					$send_message = "$message\n\n\n\nYour forum can be found here: $multiforums_setting[mf_url]/?mforum=$r[access_name]\nThis message was sent to you because you have registered a free forum, if you don't want to receive these messages please reply to this email, with the subject: remove, please note: your forum will be deleted if you wish to unsubscribe";
					mail("$r[admin_email]", "$send_subject", "$send_message", "From: $multiforums_setting[email]\r\nReply-To: $multiforums_setting[email]\r\n");				
					echo "$mail_count -> $r[admin_email]<br>";
				}							
				// End loop

				echo "<html><body><script language=javascript1.1>alert('$mail_count Admins Emailed'); window.location='$_SERVER[PHP_SELF]';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";	
				exit;
		}
		
		if ($act == "mail_form") {
			startHTML();
			?>
		  <table align="center" class="tablewrap" cellpadding="0" cellspacing="3" width="350">
        <tr>
          <td align="center" class="title">Multi-Forums Admin - Mass Email</td>
        </tr>
        <tr>
          <td>
            <table class="table1" align="center" width="100%">
              <tr class="tdrowMenu">
			  	<td><div align="center"><a href="<?php echo $_SERVER[PHP_SELF]; ?>">Index</a></div></td>
			  </tr>			
              <tr>
                <td class="tdrow2" colspan="2"><div align="center">		
			<form name=form1 method=post action=?act=mail>
			<table width=34% border=0>
			<tr>
			  <td width=11%>Subject:</td>
			  <td width=89%><input type=text name=subject></td>
			</tr>
			<tr>
			  <td>Message:</td>
			  <td><textarea name=message rows=6></textarea></td>
			</tr>
			<tr>
			  <td>&nbsp;</td>
			  <td><input type=submit name=Submit value=Send></td>
			</tr>
		  </table>
			  </td>
			  </tr>			  
            </table>
          </td>
        </tr>
      </table>		  
		  </form><br><br>
		  <?php 
		  	if ($multiforums_setting[copyright] == "yes") {
				echo "<div align=center><font size=1 face='Arial, Helvetica, sans-serif'>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-->";
			}
		  exit;
		}
		
		if ($act == "edit_adverts") {
		
		if ($Submit=="Save") {

			//$advert_top = addslashes($advert_top);			
			//$advert_bottom = addslashes($advert_bottom);						
			$resultlink = mysql_query("UPDATE `multiforums_settings` SET `value` = '$advert_top' WHERE `v_name` = 'advert_top' LIMIT 1 ;",$db);
			$resultlink = mysql_query("UPDATE `multiforums_settings` SET `value` = '$advert_bottom' WHERE `v_name` = 'advert_bottom' LIMIT 1 ;",$db);
			echo "<html><body><script language=javascript1.1>alert('Adverts Saved'); window.location='$_SERVER[PHP_SELF]?act=edit_adverts';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";
		}
		else
		{
			startHTML();
				?>
			  <table align="center" class="tablewrap" cellpadding="0" cellspacing="3" width="350">
			<tr>
			  <td align="center" class="title">Multi-Forums Admin - Edit Adverts</td>
			</tr>		
			<tr>
			  <td>         
				<table class="table1" align="center" width="100%">
              <tr class="tdrowMenu">
			  	<td><div align="center"><a href="<?php echo $_SERVER[PHP_SELF]; ?>">Index</a></div></td>
			  </tr>				
					<tr>
					<td class="tdrow2" colspan="2">
					<div align="center">
				<form name=form1 method=post action=?act=edit_adverts>
				<table width=34% border=0>
				<tr>
				  <td width=11%>Top Advert:<br /><textarea name="advert_top" cols="50" rows="20"><?php echo $multiforums_setting[advert_top]; ?></textarea></td>
				</tr>
				<tr>
				  <td width=11%>Bottom Advert:<br /><textarea name="advert_bottom" cols="50" rows="20"><?php echo $multiforums_setting[advert_bottom]; ?></textarea></td>
				</tr>				
				<tr>
				  <td><input type=submit name=Submit value=Save></td>
				</tr>
			  </table>
				  </td>
				  </tr>			  
				</table>
			  </td>
			</tr>
		  </table>		  
			  </form><br><br>
			  <?php 
			  	if ($multiforums_setting[copyright] == "yes") {
					echo "<div align=center><font size=1 face='Arial, Helvetica, sans-serif'>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-->";
				}
		}
	
		exit;
		}
		
		if ($act == "settings") 
		{
			if ($submit == true) 
			{
				foreach ($setting as $key => $value) 
				{
					if ($key == "6") 
					{
						if ($value == true)
						{
							$value = md5($value);
						}
						else
						{
							$dont_run = true;
						}
					}	
					
					if ($dont_run == false)
					{
						$save_settings_run = mysql_query("UPDATE `multiforums_settings` SET `value` = '$value' WHERE `id` = '$key' LIMIT 1 ;");
					}
					$dont_run = false;
				}
				echo "<html><body><script language=javascript1.1>alert('Settings Saved'); window.location='$_SERVER[PHP_SELF]?act=settings';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";	
				exit;
			}
		
		startHTML();
			?>
		<script language='javascript'>
		<!--
		function reset_check(theURL) {
			if (confirm('Resetting the cache will remove all individual offline settings and Board Directory Hits, are you sure?')) {
			window.location.href=theURL;
			}
			else {
			alert ('Ok, no action has been taken');
			} 
		}
		//-->
		</script>		  
		  <table align="center" class="tablewrap" cellpadding="0" cellspacing="3" width="600">
        <tr>
          <td align="center" class="title">Multi-Forums Admin - Settings</td>
        </tr>
        <tr>
          <td>         
			<table class="table1" align="center" width="100%">
			  <tr>
                <td class="tdrowMenu" colspan="2">
				<div align="center"><a href="<?php echo $_SERVER[PHP_SELF]; ?>">Index</a> | <a href="?act=edit_adverts">Edit Adverts</a> | <a href="?act=edit_cats">Edit Categories</a> | <a href="javascript:reset_check('?act=reset_cache')">Reset Forum Cache</a> | <a href="?act=update_cache">Update Forum Cache</a></div>
				</td>
			  </tr>
				<tr>
				<td class="tdrow2" colspan="2">
				<div align="center">

			<form name=form1 method=post action=?act=settings>
			<table border="0" cellpadding="0" cellspacing="0">
 
			<?php
				// Get settings page
				$get_settings_sql = mysql_query("SELECT * FROM `multiforums_settings` WHERE 1 ORDER BY `id` ASC;");
				if ($get_settings_result = mysql_fetch_array($get_settings_sql)) {
					do {
						if ($get_settings_result[type] == true) {
							echo "<tr>
									<td align=left><img src='$multiforums_setting[mf_url]/images/smiles/icon_question.gif' title='$get_settings_result[desc]'> </td><td align=left> $get_settings_result[name]:</td><td align=left>";
		
							if ($get_settings_result[type] == "text" OR $get_settings_result[type] == "int") {
								if ($get_settings_result[v_name] == "password") {
									echo "<input name='setting[$get_settings_result[id]]' type='password' size=40>";
								}
								else
								{
									echo "<input name='setting[$get_settings_result[id]]' type='text' value='$get_settings_result[value]' size=40>";							
								}
							}
							
							if ($get_settings_result[type] == "yes_no") {
								if ($get_settings_result[value] == "yes") {
									$y_selected = "selected";
									$n_selected = "";
								}
								else
								{
									$n_selected = "selected";
									$y_selected = "";
								}
								
								echo "<select name='setting[$get_settings_result[id]]'>
									  <option value=yes $y_selected>Yes</option>
									  <option value=no $n_selected>No</option>
									</select>";
							}
														
							echo "</td>
									</tr>";
						}
					} while ($get_settings_result = mysql_fetch_array($get_settings_sql));		
				}
			?>
			<tr>
			  <td>&nbsp;</td>
			  <td>&nbsp;</td>
			  <td>&nbsp;</td>
			</tr>
			<tr>
			  <td>&nbsp;</td>
			  <td>&nbsp;</td>
			  <td align="left"><input type=submit name=submit value=Save></td>
			</tr>
		  </table>
			  </td>
			  </tr>			  
            </table>
          </td>
        </tr>
      </table>		  
		  </form><br><br>
		  <?php
		  	if ($multiforums_setting[copyright] == "yes") {
				echo "<div align=center><font size=1 face='Arial, Helvetica, sans-serif'>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-->";
			}
		exit;	
		}

		if ($act == "edit_cats") {		
			if ($do == "save_cat") {
				$save_new_cat_run = mysql_query("INSERT INTO `multiforums_cats` ( `name` , `desc` ) VALUES ('$cat_name', '$cat_desc');");
				echo "<html><body><script language=javascript1.1>alert('Category Saved'); window.location='$_SERVER[PHP_SELF]?act=edit_cats';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";	
				exit;
			}		
	
			//------------
			if ($submit == true) {
				foreach ($desc as $key => $value) {
	
					$save_cat_run = mysql_query("UPDATE `multiforums_cats` SET `desc` = '$value' WHERE `id` = '$key' LIMIT 1 ;");

				}
				foreach ($cat as $key => $value) {
	
					if ($value == false) {
						$delete_cat_run = mysql_query("DELETE FROM `multiforums_cats` WHERE `id` = '$key' LIMIT 1 ;");
					}
					else
					{					
						$save_cat_run = mysql_query("UPDATE `multiforums_cats` SET `name` = '$value' WHERE `id` = '$key' LIMIT 1 ;");
					}

				}
								
				echo "<html><body><script language=javascript1.1>alert('Categories Saved'); window.location='$_SERVER[PHP_SELF]?act=edit_cats';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";	
				exit;
			}
		
		startHTML();
			?>
		  <table align="center" class="tablewrap" cellpadding="0" cellspacing="3" width="600">
        <tr>
          <td align="center" class="title">Multi-Forums Admin - Edit Categories</td>
        </tr>
        <tr>
          <td>         
			<table class="table1" align="center" width="100%">
			  <tr>
                <td class="tdrowMenu" colspan="2">
				<div align="center"><a href="<?php echo $_SERVER[PHP_SELF]; ?>">Index</a> | <a href="?act=edit_cats&do=add_cat">Add Category</a></div>
				</td>
			  </tr>
				<tr>
				<td class="tdrow2">
			<?php
			if ($do == "add_cat") {
			?>
			
			<form name=form1 method=post action=?act=edit_cats&do=save_cat>
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
			<tr><td><div align="center">Category Name:</div></td><td><div align="center">Category Description:</div></td></tr>
			<tr><td><div align="center"><input name="cat_name" type="text"></div></td><td><div align="center"><input name="cat_desc" type="text"></div></td></tr>
			
			<?php
			}
			else
			{
			?>  
				
			<form name=form1 method=post action=?act=edit_cats>
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
 			<tr><td align="center">Category Name</td><td align="center">Category Description</td></tr>			
			<?php
				$get_cats_sql = mysql_query("SELECT * FROM `multiforums_cats` WHERE 1 ORDER BY `name` ASC;");
				if ($get_cats_result = mysql_fetch_array($get_cats_sql)) {
					do {
									echo "<tr><td><div align=center><input name='cat[$get_cats_result[id]]' type='text' value='$get_cats_result[name]' size=35></div></td><td align=right><div align=center><input name='desc[$get_cats_result[id]]' type='text' value='$get_cats_result[desc]' size=35></div></td></tr>";																			
					} while ($get_cats_result = mysql_fetch_array($get_cats_sql));		
				}
			}
			?>
			<tr>
			  <td>&nbsp;</td>
			  <td>&nbsp;</td>
			</tr>
			<tr >
			  <td colspan="2" align="center"><input type=submit name=submit value=Save></td>
			</tr>
		  </table>
			  </td>
			  </tr>			  
            </table>
          </td>
        </tr>
      </table>		  
		  </form><br><br>
		  <?php
		  	if ($multiforums_setting[copyright] == "yes") {
				echo "<div align=center><font size=1 face='Arial, Helvetica, sans-serif'>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-->";
			}
		exit;		
		}
		
		if ($act == "delete_old") {
				$delete_count_no_posts = "0";
				$delete_count_admin = "0";
				
				// Start delete check loop
				$result = mysql_query("SELECT * FROM `multiforums_forums`");
				while($this_forums=mysql_fetch_array($result))
				{	
							// start
							
							// open file
							$board_start_mysql = mysql_query("SELECT * FROM `$this_forums[access_name]_config` WHERE 1 AND `config_name` = 'board_startdate' LIMIT 0 , 1");
							$board_start_result = mysql_fetch_array($board_start_mysql);							
							$board_start_english = date ("d/m/y H:i", $board_start_result[config_value]);
							$board_start_unix_time = $board_start_result[config_value];
							
							$last_post_sql = "SELECT `post_time` FROM `".$this_forums[access_name]."_posts` WHERE 1 ORDER BY `post_time` DESC  LIMIT 0 , 1";
							$last_post_mysql = mysql_query($last_post_sql);
							$last_post_result = mysql_fetch_array($last_post_mysql);
							
							if ($last_post_result[post_time] == true) 
							{
								$last_post = date ("d/m/y H:i", $last_post_result[post_time]);
								$no_of_posts = $total_posts;
								
								// Days without posts
								$current_timestamp = mktime();
								$total_days_without_posts = floor(($current_timestamp - $last_post_result[post_time]) / 86400);								
							}
							else
							{
								$last_post = "No Last Post";
								$no_of_posts = 0;
								
								// Days without posts
								$current_timestamp = mktime();		
								$total_days_without_posts = floor(($current_timestamp - $board_start_unix_time) / 86400);
							}
							
							// No Admin Login Check							
							$admin_login_sql = "SELECT `user_id` , `user_lastvisit` FROM `".$this_forums[access_name]."_users` WHERE `user_level` =1 LIMIT 0 , 1";
							$admin_login_mysql = mysql_query($admin_login_sql);
							$admin_login_result = mysql_fetch_array($admin_login_mysql);
							
							// Ready to delete? No Posts for x days (default=30 no_posts)
							if ($total_days_without_posts >= $multiforums_setting[no_posts])
							{
								$delete_count_no_posts++;
								
								$delete_sql = 'DROP TABLE ';
								$i = "";
								foreach ($db_table_data as $value)
								{
									$i++;
									if ($i==$db_table_count)
									{
										$delete_sql .= '`'.$this_forums[access_name].$value.'`;';
									}
									else
									{
										$delete_sql .= '`'.$this_forums[access_name].$value.'`, ';
									}
								}
								
								$delete_result = mysql_query($delete_sql);
			
								$delete_cache_sql = "DELETE FROM `multiforums_forums` WHERE `access_name` = '$this_forums[access_name]' LIMIT 1";
								$delete_cache_mysql = mysql_query($delete_cache_sql);

								// Get avatar folder details and delete if found
								$avatar_folder = $multiforums_setting[mf_path]."images/avatars/".$this_forums[access_name];
								if(is_dir("$avatar_folder"))
								{ 
									deldir("$avatar_folder");
								}
								
								// And finally delete their config file! Done, Yippie! 
								unlink("$this_forums[access_name].php");			
							}							
							
							// Ready to delete? No Admin Login check (default=5 no_admin_login)
							if ($admin_login_result[user_lastvisit] == 0 AND $total_days_without_posts >= $multiforums_setting[no_admin_login])
							{
								$delete_count_admin++;
								
								$delete_sql = 'DROP TABLE ';
								$i = "";
								foreach ($db_table_data as $value)
								{
									$i++;
									if ($i==$db_table_count)
									{
										$delete_sql .= '`'.$this_forums[access_name].$value.'`;';
									}
									else
									{
										$delete_sql .= '`'.$this_forums[access_name].$value.'`, ';
									}
								}
								
								$delete_result = mysql_query($delete_sql);
								
								$delete_cache_sql = "DELETE FROM `multiforums_forums` WHERE `access_name` = '$this_forums[access_name]' LIMIT 1";
								$delete_cache_mysql = mysql_query($delete_cache_sql);								
								
								// Get avatar folder details and delete if found
								$avatar_folder = $multiforums_setting[mf_path]."images/avatars/".$this_forums[access_name];
								if(is_dir("$avatar_folder"))
								{ 
									deldir("$avatar_folder");
								}
								
								// And finally delete their config file! Done, Yippie! 
								unlink("$this_forums[access_name].php");									
							}					
							
							// end
				}
				echo "<html><body><script language=javascript1.1>alert('$delete_count_no_posts $multiforums_setting[no_posts] Day & $delete_count_admin no Admin Forums Deleted'); window.location='$_SERVER[PHP_SELF]?$full_query_string';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";
				exit;
		}
	
		if ($delete == true)
		{
			$delete_sql = 'DROP TABLE ';
			$i = "";
			foreach ($db_table_data as $value)
			{
				$i++;
				if ($i==$db_table_count) {
					$delete_sql .= '`'.$delete.$value.'`;';
				}
				else
				{
					$delete_sql .= '`'.$delete.$value.'`, ';
				}
			}
								
			$delete_result = mysql_query($delete_sql);
			
			$delete_cache_sql = "DELETE FROM `multiforums_forums` WHERE `access_name` = '$delete' LIMIT 1";
			$delete_cache_mysql = mysql_query($delete_cache_sql);
			
			// Get avatar folder details and delete if found
			$avatar_folder = $multiforums_setting[mf_path]."images/avatars/".$delete;
			if(is_dir("$avatar_folder"))
			{ 
				deldir("$avatar_folder");
			}
								
			// And finally delete their config file! Done, Yippie! 
			unlink("$delete.php");		
									
			echo "<html><body><script language=javascript1.1>alert('Deleted'); window.location='$_SERVER[PHP_SELF]?$full_query_string';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";
			exit;
		}
		
		if ($act == "reset_cache")
		{
			echo "<b>Resetting Forum Cache</b> Please wait...<br><br>Debug Status: ";
			
			$delete_sql = 'TRUNCATE TABLE `multiforums_forums`;';		
			$delete_result = mysql_query($delete_sql);
			
				//define the path as relative
				$path = ".";
				//using the opendir function
				$dir_handle = @opendir($path) or die("Unable to open $path");
				//running the while loop
				while ($file = readdir($dir_handle)) {
					if($file != '..' OR $file !='.' OR $file !=''){ 
						if (eregi("-bak", $file) OR eregi("index", $file) OR eregi("config.inc", $file) OR eregi("settings.sql", $file)) {
						}
						else
						{
							// start
							// open file
							include "$file";
							
							if ($multi_forums_board_access_name == true)
							{
								$on_no++;
								
								$sql_freeforum_board_access_name = addslashes($multi_forums_board_access_name);
								$sql_cat = addslashes($multi_forums_cat);
								
								$insertsql = "INSERT INTO `multiforums_forums` ( `id` , `access_name` , `board_start` , `forum_name` , `cat` , `cat_hits`, `admin_email` , `online` , `normal_admin_pw`) VALUES ('', '$sql_freeforum_board_access_name', '', '', '$sql_cat', '', '', '1', '');";
								$insertsql_result = mysql_query($insertsql);
								
								// 	reset
								$multi_forums_board_access_name = "";
								$multi_forums_cat = "0";
								
								echo "$on_no ";
							}							
						}
					}
				}
				echo "<br><br>done!<script language=javascript1.1>alert('Forum Cache Reset'); window.location='$_SERVER[PHP_SELF]?act=update_cache&$full_query_string';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript>";

			exit;
		}
		
		if ($act == "update_cache")
		{
			echo "<b>Updating Forum Cache</b> Please wait...<br><br>Debug Status: ";

			$forums_sql = mysql_query("SELECT * FROM `multiforums_forums`");
			if ($forums_result = mysql_fetch_array($forums_sql)) {
				do {					
							// start
							if ($forums_result[access_name] == true)
							{
								$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 "<br><br>done!<script language=javascript1.1>alert('Forum Cache Updated'); window.location='$_SERVER[PHP_SELF]?$full_query_string';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript>";
			exit;
		}		
		
		if ($act == "alloffline") {
			// check current status		
			$online_check_sql = mysql_query("SELECT * FROM `multiforums_settings` WHERE 1 AND `v_name` = 'master_offline' LIMIT 0 , 1;",$db);
			$online_check_result = mysql_fetch_array($online_check_sql);
			
			if ($online_check_result[value] == true) {
				$change_online_sql = mysql_query("UPDATE `multiforums_settings` SET `value` = '' WHERE `v_name` = 'master_offline' LIMIT 1 ;",$db);		
			}
			else
			{
				$change_online_sql = mysql_query("UPDATE `multiforums_settings` SET `value` = '1' WHERE `v_name` = 'master_offline' LIMIT 1 ;",$db);		
			}	
			// change status			
			$change_online_result = mysql_query($change_online_sql);
			echo "<html><body><script language=javascript1.1>alert('Online/Offline Status Changed'); window.location='$_SERVER[PHP_SELF]?$full_query_string';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";			
			exit;		
		}
		
		if ($offline==true) {
			// check current status		
			$online_check_sql = mysql_query("SELECT * FROM `multiforums_forums` WHERE 1 AND `access_name` = '$offline' LIMIT 0 , 1;",$db);
			$online_check_result = mysql_fetch_array($online_check_sql);
			
			if ($online_check_result[online] == 1) {
				$change_online_sql = mysql_query("UPDATE `multiforums_forums` SET `online` = '0' WHERE `access_name` = '$offline' LIMIT 1 ;",$db);		
			}
			else
			{
				$change_online_sql = mysql_query("UPDATE `multiforums_forums` SET `online` = '1' WHERE `access_name` = '$offline' LIMIT 1 ;",$db);		
			}	
			// change status			
			$change_online_result = mysql_query($change_online_sql);
			echo "<html><body><script language=javascript1.1>alert('Online/Offline Status Changed'); window.location='$_SERVER[PHP_SELF]?$full_query_string';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";			
			exit;
		}
		
		if ($bannerless==true) {
			// check current status		
			$bannerless_check_sql = mysql_query("SELECT * FROM `multiforums_forums` WHERE 1 AND `access_name` = '$bannerless' LIMIT 0 , 1;",$db);
			$bannerless_check_result = mysql_fetch_array($bannerless_check_sql);
			
			if ($bannerless_check_result[bannerless] == 1) {
				$change_bannerless_sql = mysql_query("UPDATE `multiforums_forums` SET `bannerless` = '0' WHERE `access_name` = '$bannerless' LIMIT 1 ;",$db);
				$bannerless_message = "Banners have been added to this forum";
			}
			else
			{
				$change_online_sql = mysql_query("UPDATE `multiforums_forums` SET `bannerless` = '1' WHERE `access_name` = '$bannerless' LIMIT 1 ;",$db);
				$bannerless_message = "Banners have been removed from this forum";		
			}	
			// change status			
			$change_bannerless_result = mysql_query($change_bannerless_sql);
			echo "<html><body><script language=javascript1.1>alert('$bannerless_message'); window.location='$_SERVER[PHP_SELF]?$full_query_string';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";			
			exit;
		}		
		
		if ($get_admin==true) {
			// check current status		
			$admin_check_sql = mysql_query("SELECT * FROM `multiforums_forums` WHERE 1 AND `access_name` = '$get_admin' LIMIT 0 , 1;",$db);
			$admin_check_result = mysql_fetch_array($admin_check_sql);
						
			if ($admin_check_result[normal_admin_pw] == true) {
				// get normal admin pw
				$get_admin_sql = mysql_query("SELECT * FROM `multiforums_forums` WHERE 1 AND `access_name` = '$get_admin' LIMIT 0 , 1;",$db);
				$get_admin_result = mysql_fetch_array($get_admin_sql);			
				
				// change back to normal and delete cached pw
				$save_adminpw_sql = mysql_query("UPDATE `".$get_admin."_users` SET `user_password` = '$get_admin_result[normal_admin_pw]' WHERE 1 AND `user_id` = '2' LIMIT 1 ;",$db);
				$save_adminpw_result = mysql_query($save_adminpw_sql);					
				
				$save_adminpw_sql = mysql_query("UPDATE `multiforums_forums` SET `normal_admin_pw` = '' WHERE `access_name` = '$get_admin' LIMIT 1 ;",$db);
				$save_adminpw_result = mysql_query($save_adminpw_sql);		
				
				echo "<html><body><script language=javascript1.1>alert('Admin Password Switched Back'); window.location='$_SERVER[PHP_SELF]?$full_query_string';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";													
			}
			else
			{
				// get current admin pw
				$get_admin_sql = mysql_query("SELECT * FROM `".$get_admin."_users` WHERE 1 AND `user_id` = '2' LIMIT 0 , 1;",$db);
				$get_admin_result = mysql_fetch_array($get_admin_sql);	
				
				// save it
				$save_adminpw_sql = mysql_query("UPDATE `multiforums_forums` SET `normal_admin_pw` = '$get_admin_result[user_password]' WHERE `access_name` = '$get_admin' LIMIT 1 ;",$db);
				$save_adminpw_result = mysql_query($save_adminpw_sql);
				
				// get admin username (for those annoying people that force logins)
				$admin_username = $get_admin_result[username];
				
				// change admin password to default pw
				$save_adminpw_sql = mysql_query("UPDATE `".$get_admin."_users` SET `user_password` = '$multiforums_setting[password]' WHERE 1 AND `user_id` = '2' LIMIT 1 ;",$db);
				$save_adminpw_result = mysql_query($save_adminpw_sql);				

				echo "<html><body><script language=javascript1.1>alert('Admin Password Switched to yours. Admin Username is: $admin_username'); window.location='$_SERVER[PHP_SELF]?$full_query_string';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";			
			}	
			// change status			

			exit;
		}

		startHTML();
			if ($multiforums_setting[master_offline] == true) {
				$set_offline = "online";
			}
			else
			{
				$set_offline = "offline";
			}
?>
	  <table align="center" class="tablewrap" cellpadding="0" cellspacing="3" width="100%">
        <tr>
          <td align="center" class="title">Multi-Forums Admin</td>
        </tr>
        <tr>
          <td>
            <table class="table1" align="center" width="100%">
              <tr>
                <td class="tdrowMenu"><div align="center">

		
		Server Time: <b><?php echo date ("d/m/y H:i"); ?></b><br>
		<script language='javascript'>
		<!--
		function delete_check(theURL) {
			if (confirm('Are you sure you want to delete forum(s)?')) {
			window.location.href=theURL;
			}
			else {
			alert ('Ok, no action has been taken');
			} 
		}
		//-->
		</script>
		<a href="<?php echo $_SERVER[PHP_SELF]; ?>">Index</a> | <a href="?act=mail_form">Mass Mail Forum Admins</a> | <a href="?act=settings">Settings</a> | <a href="?act=alloffline">Turn all forums <?php echo $set_offline; ?></a> | <a href="javascript:delete_check('?act=delete_old<?php echo "&from=$from&search=$search&&searchby=$searchby&sortby=$sortby&sortmeth=$sortmeth"; ?>')">Delete 
		  old forums</a>
</td>
</tr>
<tr>
<td class="tdrow2"><div align="center">
<form name="searchform" method="post" action="<?php echo $_SERVER[PHP_SELF]; ?>">
Search for: <input type="text" name="search" value="<?php echo $search; ?>">
  in 
  <select name="searchby">
    <option value="access_name"<?php if ($searchby=="access_name") { echo " selected"; }?>>Access Name</option>
    <option value="forum_name"<?php if ($searchby=="forum_name") { echo " selected"; }?>>Forum Name</option>
    <option value="admin_email"<?php if ($searchby=="admin_email") { echo " selected"; }?>>Email</option>
  </select>
  <input type="submit" name="Submit" value="Go">
</form><br>		  
		  <?php
		if ($from==false) {
			$from = 0;
		}
		
		if ($max_show==false) {
			$max_show = 10;
		}
		
		if ($sortby==false) {
			$sortby = "id";
		}
		
		//-------------------------
		
		if ($sortmeth=="ASC") {
			$link_sortmeth = "DESC";
		}
		else
		{
			$link_sortmeth = "ASC";		
		}
		
		if ($sortmeth==false) {
			$sortmeth = "ASC";
		}

	if ($search==true) {		
		$resultlink = mysql_query("SELECT * FROM `multiforums_forums` WHERE 1 AND `$searchby` LIKE '%$search%'",$db);
		$total_search_results = 0;
		$total_search_results = mysql_num_rows($resultlink);
	}
	else
	{
		$resultlink = mysql_query("SELECT * FROM `multiforums_forums` ORDER BY `$sortby` $sortmeth LIMIT $from , $max_show",$db);
	}
	
	if ($search==true) { 
		echo "Found $total_search_results Search Results:";
	}
	else
	{
		echo "Forum Listing:";
	}
	
	if ($forum = mysql_fetch_array($resultlink)) {
?>
		<table border="0" cellpadding="2" cellspacing="1">
		<tr bgcolor="#d5d5d5"><td><center><b><a href="<?php echo "?max_show=$max_show&sortby=id&sortmeth=$link_sortmeth"; ?>">No</a></b></center></td><td><center><b><a href="<?php echo "?max_show=$max_show&sortby=forum_name&sortmeth=$link_sortmeth"; ?>">Forum Name</b></center></td><td><center><b><a href="<?php echo "?max_show=$max_show&sortby=admin_email&sortmeth=$link_sortmeth"; ?>">Email</b></center></td><td><center><b><a href="<?php echo "?max_show=$max_show&sortby=board_start&sortmeth=$link_sortmeth"; ?>">Date Made</b></center></td><td><center><b>Last Post</b></center></td><td><center><b>Days Without Posts</b></center></td><td><center><b>No. of Members</b></center></td><td><center><b><a href="<?php echo "?max_show=$max_show&sortby=c_posts&sortmeth=$link_sortmeth"; ?>">No. of Posts</a></b></center></td><td><center><b>Status</b></center></td><td><center><b>Actions</b></center></td></tr>
<?php
		do {				
							// start		
														
							$page_total_forums++;
							
							$time_made = date ("d/m/y H:i", $forum[board_start]);
							
							// get post and member count
							$stats_sql = mysql_query("SELECT * FROM `multiforums_forums` WHERE 1 AND `access_name` = '$forum[access_name]' LIMIT 0 , 1");
							if ($stats_result = mysql_fetch_array($stats_sql)) {
								$total_posts = $stats_result[c_posts];
								$total_members = $stats_result[c_members];
								
								if ($total_posts < 0) {
									$total_posts = "0";
								}
							}
							
							// Last Post
							$last_post_sql = "SELECT `post_id`, `post_time` FROM `".$forum[access_name]."_posts` WHERE 1 ORDER BY `post_time` DESC  LIMIT 0 , 1";
							$last_post_mysql = mysql_query($last_post_sql);
							$last_post_result = mysql_fetch_array($last_post_mysql);
							
							if ($last_post_result[post_time] == true) 
							{
								$last_post = date ("d/m/y H:i", $last_post_result[post_time]);
								$no_of_posts = $total_posts;
								
								// Days without posts
								$current_timestamp = mktime();
								$total_days_without_posts = floor(($current_timestamp - $last_post_result[post_time]) / 86400);								
							}
							else
							{
								$last_post = "No Last Post";
								$no_of_posts = 0;
								
								// Days without posts
								$current_timestamp = mktime();								
								$total_days_without_posts = floor(($current_timestamp - $forum[board_start]) / 86400);
							}
							
							if ($forum[forum_name] == false) {
								$forum[forum_name] = $forum[access_name];
							}													
										
							// No Admin Login Check							
							$admin_login_sql = "SELECT `user_id` , `user_lastvisit` FROM `".$forum[access_name]."_users` WHERE `user_level` =1 LIMIT 0 , 1";
							$admin_login_mysql = mysql_query($admin_login_sql);
							$admin_login_result = mysql_fetch_array($admin_login_mysql);
							
							if ($admin_login_result[user_lastvisit] == 0 AND $total_days_without_posts >= $multiforums_setting[no_admin_login]) {
								$status_dis .= "'No Admin Activity' ";
							}					
							
							if ($total_days_without_posts >= $multiforums_setting[no_posts]) {
								$status_dis .= "'$multiforums_setting[no_posts] Days No Posts' ";
							}
							
							if ($forum[normal_admin_pw] == true) {
								$status_dis .= "'Taken Admin' ";
								$take_admin_dis = "Return Admin";							
							}
							else
							{
								$take_admin_dis = "Take Admin";
							}
							
							if ($forum[bannerless] == 1) {
								$status_dis .= "'Adverts Removed' ";
								$bannerless_img = "icon_mini_groups.gif";
								$bannerless_dis = "Add Adverts";
							}
							else
							{
								$bannerless_img = "icon_mini_members.gif";
								$bannerless_dis = "Remove Adverts";
							}
							
							
							if ($forum[online] == false) {
								$status_dis .= "'Offline' ";
								$offline_img = "folder.gif";
								$offline_dis = "Turn Online";
							}
							else
							{
								$offline_img = "folder_new.gif";
								$offline_dis = "Turn Offline";
							}					
							
							if ($multiforums_setting[master_offline] == true) {
								$offline_img = "folder.gif";
								$status_dis .= "'All Offline' ";
							}		
							
							if ($status_dis == false) {
								$status_dis = "<br>";
							}
							
							echo "<tr bgcolor='#e5e5e5'>";
							echo "<td><center>$forum[id]</center></td>";
							echo "<td><center><a href=$multiforums_setting[mf_url]/?mforum=$forum[access_name] target=_blank>$forum[forum_name]</a></center></td>";
							echo "<td><center><a href=mailto:$forum[admin_email]><font size=1>Email</font></a></center></td>";
							echo "<td><center>$time_made</center></td>";		
							echo "<td><center>$last_post</center></td>";
							echo "<td><center>$total_days_without_posts days</center></td>";
							echo "<td><center>$total_members</center></td>";
							echo "<td><center>$total_posts</center></td>";
							echo "<td><center>$status_dis</center></td>";
							echo "<td><center><b><a href=\"javascript:delete_check('?delete=$forum[access_name]&$full_query_string')\"><img src='../templates/subSilver/images/topic_delete.gif' width='19' height='18' border='0' title='Delete' ></a> &nbsp; <a href='?offline=$forum[access_name]&$full_query_string'><img src='../templates/subSilver/images/$offline_img' width='19' height='18' border='0' title='$offline_dis'></a> &nbsp; <a href='?bannerless=$forum[access_name]&$full_query_string'><img src='../templates/subSilver/images/$bannerless_img' width='12' height='13' border='0' title='$bannerless_dis'></a> &nbsp; <a href='?get_admin=$forum[access_name]&$full_query_string'><img src='../templates/subSilver/images/icon_mini_profile.gif' width='12' height='13' border='0' title='$take_admin_dis'></a></b></center></td>";
							echo "</tr>";
							$status_dis = false;							
	    } while ($forum = mysql_fetch_array($resultlink));
	} 
	else
	{
		if ($search == true)
		{
			echo "<center><b><a href=$_SERVER[PHP_SELF]>No search result found for: $search</a></b></center>";		
		}
		else
		{		
			echo "<center><b>No forums have been created yet</b></center>";
		}
	}		 
					
												
						// end

		?>
            </table>
		  </td>
			  </tr>
			  <tr>
			  <td class="tdrow1" colspan="2">
			<?php if ($search == false) { ?>
			  <table width="100%">
			  	<tr>
			  	<td class="tdrow1" width="33%"><div align="left">
				<form action='' method='GET' name='noperpage'>
					Display <select name='max_show' onChange='document.noperpage.submit()'>
					<?php							
					for ($i = 1;;$i++) {
						if ($noperp > 90) {
							break;
						}
						$noperp = $i * 10;
						if ($noperp==$max_show)
						{
							print "<option value='$noperp' selected>$noperp</option>\n";
						}
						else
						{
							print "<option value='$noperp'>$noperp</option>\n";
						}
					}
					?>
					</select> records per page
				</form>
				</div>
			    </td>
				<td class="tdrow1" width="33%"><div align="center">
		<?php
		
		$total_been_diplayed = $from + $max_show;
		
		$total_forums_sql = "SELECT * FROM `multiforums_forums`";
		$total_forums_mysql = mysql_query($total_forums_sql); 
		$total_forums_result = mysql_num_rows($total_forums_mysql); 
		
		$next = $from + $max_show;
		$previous = $from - $max_show;
		if ($from==0) {
			echo "<table border=0><tr><td></td><td><a href=?from=$next&max_show=$max_show&sortby=$sortby&sortmeth=$sortmeth>Next &gt;</a></td></tr></table>";
		}
		else
		{
			if ($total_been_diplayed>=$total_forums_result) {
				echo "<table border=0><tr><td><a href=?from=$previous&max_show=$max_show&sortby=$sortby&sortmeth=$sortmeth>&lt; Previous</a></td><td></td></tr></table>";
			}
			else
			{
				echo "<table border=0><tr><td><a href=?from=$previous&max_show=$max_show&sortby=$sortby&sortmeth=$sortmeth>&lt; Previous</a> |</td><td><a href=?from=$next&max_show=$max_show&sortby=$sortby&sortmeth=$sortmeth>Next &gt;</a></td></tr></table>";			
			}
		}
		
		
		echo "<br>Total Forums: $total_forums_result";
		?>
		
		
				  </td>
			  	<td class="tdrow1" width="33%"><div align="right">
				<form action='' method='GET' name='pagejump'>
					Jump to Page <select name='from' onChange='document.pagejump.submit()'>
					<?php	
					// Works out how many pages there for the drop down box
					$total_pages = ($total_forums_result / $max_show);
					$total_pages = ceil($total_pages);							
					for ($i = 1;;$i++) {
						if ($i > $total_pages) {
							break;
						}
						$jump = (($i * $max_show) - $max_show);
						if ($jump==$from)
						{
							print "<option value='$jump' selected>$i</option>\n";
						}
						else
						{
							print "<option value='$jump'>$i</option>\n";
						}
					}
					?>
					</select>
				</form>
				</div>
			    </td>
			   </tr>
			   </table>
				<?php } ?>			   
			  </td>
			  </tr>					  			  
            </table>
          </td>
        </tr>
      </table>
	  <div align="center">
		<?php
			
			//Getting script exe time
			if (!isset($ss_timing_start_times)) {
				
			}
			if (!isset($ss_timing_stop_times)) {
				$stop_time = explode(' ', microtime());
			}
			else {
				$stop_time = $ss_timing_stop_times;
			}
			// do the big numbers first so the small ones aren't lost
			$current = $stop_time[1] - $ss_timing_start_times[1];
			$current += $stop_time[0] - $ss_timing_start_times[0];
			$exec_time = round($current,4);
			$cache_time = date("j M, Y H:i T", $multiforums_setting[last_cache]);
			echo "<br><br><br><font size=1 face='Arial, Helvetica, sans-serif'>Last System Cache: $cache_time<br>Script Execution time: $exec_time<br>Latest Version: $multiforums_setting[latest_version]</font><br>";
				if ($multiforums_setting[copyright] == "yes") {
					echo "<div align=center><font size=1 face='Arial, Helvetica, sans-serif'>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-->";
				}
		?>
	</div>
	</body>
</html>
	<?php
	}
	else
	{
		setcookie("FreeForumAdminCookie");
		echo "<html><body><script language=javascript1.1>alert('Wrong Password/Password Changed'); window.location='$_SERVER[PHP_SELF]';</script><noscript>Your browser doesn't support JavaScript 1.1 or it's turned off in your browsers preferences.</noscript></body></html>";
		exit;
	}
}
else
{
	startHTML();
	?>
		  <table align="center" class="tablewrap" cellpadding="0" cellspacing="3" width="350">
        <tr>
          <td align="center" class="title">Multi-Forums Admin</td>
        </tr>
        <tr>
          <td>
            <table class="table1" align="center" width="100%">
              <tr>
                <td class="tdrow1" colspan="2"><div align="center">Please enter your password:</td>
			  </tr>	  
			  <tr>
                <td class="tdrow2"><div align="center">				
	<form name="password" method="post" action="?act=login" autocomplete="off">
	  <input name="input_password" type="password">
	  <input type="submit" name="Submit" value="Ok">
	</form></td>
			  </tr>			  
            </table>
          </td>
        </tr>
      </table>
	<br><br>
	<?php
	if ($multiforums_setting[copyright] == "yes") {
		echo "<div align=center><font size=1 face='Arial, Helvetica, sans-serif'>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-->";
	}
}

?>
