<?php
$t->_tpl_vars['pgLayout'] = "file:layouts/admin.tpl";

// Like the load.config.php, figure out what config file we are using
//........ Be aware that any domains with "www." will be trimmed out.
$domain = strtolower (str_replace ('www.', '', $_SERVER['HTTP_HOST']));

//........ Prevent any hack attempts to override configuration values.
$temp_c = $c;

unset ($c);

//........ Find which Config file to use, if not found use default.
while (strstr ($domain, '.')) {
	if (file_exists ($file = SPADE_CONFIGS_PATH.$domain.'.php')) {
		include ($file);
		break;
	}
	elseif (strlen ($domain) < 5 ) {
		$file = SPADE_CONFIGS_PATH.'default.config.php';
		break;
	}
	else
		$domain = substr (strchr ($domain, '.'), 1);
}

$currentConfig = $c;
unset($c);
$c = $temp_c;
unset($temp_c);

$folderId = $db->query("SELECT id FROM _folders WHERE path='".SPADE_CONFIGS_PATH."' OR path='".preg_replace("/^[\.]?[\/]/", '', SPADE_CONFIGS_PATH)."'", DB_VAL);

$stPath = SPADE_SYSTEM_PATH.$GLOBALS['c']['system'].'/img/st/';

?><div align="center"><?php
echo openStyleTable($stPath.'chrome', '', '', '', 500);
?>
<table border="0" align="center" width="500">
<tr>
	<td colspan="3"><h2>Engine Info: </h2></span></td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td><span><b>Engine: </b></span></td>
	<td><span><?php echo ENGINE_NAME; ?></span></td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td><span><b>Version: </b></span></td>
	<td><span><?php echo ENGINE_VERSION; ?> rev <?php echo ENGINE_MINOR_VERSION; ?></span></td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td><span><b>Revision Date: </b></span></td>
	<td><span>
		<?php
		list($rev_month, $rev_day, $rev_year) = explode('.', ENGINE_REVISION_DATE);
		echo date("n/j/Y", mktime(0, 0, 0, intval($rev_month), intval($rev_day), (intval($rev_year) + 2000)));
		?>
	</span></td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td><span><b>License Key: </b></span></td>
	<td><span><?php echo $currentConfig['licenseKey']; ?></span></td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td><span><b>License Good Through: </b></span></td>
	<td><span><?php echo $currentConfig['licenseYear']; ?></span></td>
</tr>
<tr>
	<td colspan="3">&nbsp;</td>
</tr>
<tr>
	<td colspan="3"><h2>Current Config File: </h2></td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td colspan="2">
		<span><b><?php echo basename($file); ?></b></span>
		<?php
		if ($folderId) { ?>
		<form name="editConfigForm" action="index.php" method="post" target="fm">
		<input type="hidden" name="pg" value="fm/main">
		<input type="hidden" name="isChanged" value="true">
		<input type="hidden" name="filesAction" value="store">
		<input type="hidden" name="no_expire" value="true">
		<input type="hidden" name="no_expire_keep_alive" value="tab">
		<input type="hidden" name="tab" value="3">
		<input type="hidden" name="folderId" value="<?php echo $folderId; ?>">
		<input type="hidden" name="selectFolder" value="<?php echo $folderId; ?>">
		<input type="hidden" name="selectedFiles[]" value="<?php echo basename($file); ?>">
		<input type="submit" name="submitEditConfig" value="Edit This Configuration" class="btn">
		</form>
		<?php
		}
		?>
	</td>
</tr>
<tr>
	<td colspan="3">&nbsp;</td>
</tr>
<tr>
	<td colspan="3"><h2>Current Config Settings: </h2></td>
</tr>
<?php
if (is_array($currentConfig)) {
	foreach($currentConfig as $name=>$config) {
		echo '<tr><td width="20">&nbsp;</td><td valign="top" nowrap="nowrap"><span><b>'.niceText($name).'</b> : </span></td><td><span>';
		if (!$config)
			echo $config.' (<b>false</b>)';
		elseif ($config == 1)
			echo $config.' (<b>true</b>)';
		elseif (is_array($config))
			display($config);
		else
			echo $config;
		echo '</td></tr>'."\n";
	}
} else {
	echo '<tr><td>&nbsp;</td><td colspan="2"><span>Could not retrieve the current Config settings. The file may be empty or the \'paths.config.php\' file may be improperly configured.</span></td></tr>';
}
?>
<tr>
	<td colspan="3">&nbsp;</td>
</tr>
<tr>
	<td colspan="3"><h2>Available Modules: </h2></td>
</tr>
<?php
if (is_array($c['availableModules'])) {
	foreach($c['availableModules'] as $moduleName=>$modulePath) {
		$moduleInfo = getModuleInfo($moduleName);
		echo '<tr><td colspan="3"><hr noshade size="1"/><span><b><i>'.niceText($moduleName).'</i></b></span><hr noshade size="1"/></td></tr>'."\n";
		if (is_array($moduleInfo)) {
			foreach($moduleInfo as $subject=>$info) {
				echo '<tr><td>&nbsp;</td><td valign="top" nowrap="nowrap"><span><b>'.niceText($subject).'</b></span></td><td><span>';
				if ($subject == 'author-contact') {
					echo '<a href="mailto:'.$info.'">'.$info.'</a>';
				} elseif ($subject == 'author-website') {
					if (!preg_match("/^http\:\/\//", $info))
						echo '<a href="http://';
					else
						echo '<a href="';
					echo $info.'" target="_blank">'.$info.'</a>';
				} else {
					echo $info;
				}
				echo '</span></td></tr>'."\n";
			}
		} else {
			echo '<tr><td>&nbsp;</td><td colspan="2"><span>Could not get the details for this module.<br>The .mod file (<b>'.MODULES_DIR.$moduleName.'</b>) may be improperly configured.</span></td></tr>';
		}
	}

} else {
	echo '<tr><td>&nbsp;</td><td colspan="2"><span>Could not retrieve available modules details.<br>There may not be any modules available or the \'paths.config.php\' file may be improperly configured.</td></tr>';
}
?>
</table>
<?php
echo closeStyleTable($stPath.'chrome');
?></div>