<?php
// Call in the XComponents engine and options file
define('MOD_PHP', substr(PHP_SAPI, 0, 3) != 'cgi'); // Are we running as mod_php?
define('DOCROOT', 
	MOD_PHP && isset($_SERVER['DOCUMENT_ROOT']) ? 
		$_SERVER['DOCUMENT_ROOT'] : 
		(
			MOD_PHP && isset($_SERVER['SCRIPT_FILENAME']) ? 
				substr($_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF'])) : 
				(
					substr(str_repeat('../', count(explode('/', preg_replace('_/+_', '/', $_SERVER['PHP_SELF'])))-2), 0, -1) != '' ?
						substr(str_repeat('../', count(explode('/', preg_replace('_/+_', '/', $_SERVER['PHP_SELF'])))-2), 0, -1) :
						'.'
				)
		)
	);
include(DOCROOT . '/dmx/dmx_options.php');
include(DOCROOT . '/dmx/core/php/dmx_shop_handler.php');
include(DOCROOT . '/dmx/core/php/dmx_shop_components.php');

unset($_SESSION['ABS_OPT'], $_SESSION['ABS_SEO'], $_SESSION['ABS_SUB']);  // Force Easy SEO recompile

// Abs code starts here
$abs_root = '';
@include(DOCROOT . '/abs_version_control.php');
include(DOCROOT . $abs_root . '/common/authenticate.php');
include(DOCROOT . $abs_root . '/common/header.php');


// mod-rewrite test 
$http = new HTTP(
	array(
		'http://' . $_SERVER['HTTP_HOST'] . '/dmx/server/mod_rewrite_test/a.html'
		)
);
$result = $http->request();
$mod_rw_active = strpos($result->response, '<title>B.html</title>') !== FALSE;

// Inbound URL mappings
$result_mapping = $mod_rw_active ? abs_create_inbound_url_mappings($abs_seo) : 'MOD_REWRITE_NOT_ACTIVE';
	
?>

<style type="text/css">

h3 { color: #111; }

</style>

<!-- MAIN CONTENT AREA -->
<div id="main_area" onmouseover="sub_menu_hide();">
	<div id="main_area_content">
		
		<div class="main_column">
		<!-- ----------------- -->
		<!-- BEGIN MAIN COLUMN -->
		<!-- ----------------- -->
			
		<?php if (count($abs_seo)) : ?>
		
			<h1><img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="" /> Easy SEO data has been reloaded</h1>
			
			<h3><img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="" /> Data for &lt;title&gt; and &lt;meta&gt; tags has been read</h3>
			
			<p>
			Your dmABS pages will now have custom &lt;title&gt; and &lt;meta&gt; tags, where such information has been specified.
			</p>
		
			<?php switch($result_mapping) :
				
				case 'SUCCESS' : ?>
				
					<h3><img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt=""> Server obeys mod_rewrite directives in .htaccess files
					
					<?php if (empty($abs_invalid_urls)) : ?>
					
						<h3><img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="" /> URL mappings sucessfully (re)generated</h3>
						
						<p>
						Your dmABS URLs should now be seamlessly remapped.
						</p>
					
					<?php else: ?>
					
						<h3><img src="/dmx/core/b0/images/sgm/interface/val_valid_14.gif" width="14" height="14" alt="" /> URL mappings (re)generated - with invalid URLs excluded</h3>
	
						<p>
						<b>Remapped URLs.</b>
						</p>
					
					<?php endif; ?>				
					
					<table border="0" width="100%" class="padded_table_thin active detailed">
						<tr>
							<td class="col1i"><b>Real URL</b></td>
							<td class="col1i"><b>Desired URL</b></td>
						</tr>
						<tr><td class="divider" colspan="2"><img src="/themes/baseline_brand/sgm/clear.gif" alt="" width="1" height="1" /></td></tr>
						<?php foreach($abs_seo as $real_url => $arr) : ?>
							<?php if (!$arr['desired_url']) continue; ?>
							<tr>
								<td class="col2f"><span style="float: right; margin-right: 5px;">=&gt;</span><?=$real_url;?></td>
								<td class="col1f"><?=(htmlentities($arr['desired_url']));?></td>
							</tr>
						<?php endforeach; ?>
						<tr><td class="divider" colspan="2"><img src="/themes/baseline_brand/sgm/clear.gif" alt="" width="1" height="1" /></td></tr>
					</table>
					
					<br />
										
					<?php break; ?>
			
				<?php case 'MOD_REWRITE_DISABLED' : ?>

					<h3><img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="" /> Server does not obey mod_rewrite directives in .htaccess files</h3>
					
					<p>
					To use URL mapping, please install/enable mod_rewrite, if you can.
					</p>

				<?php case 'URL_MAPPING_NOT_ENABLED' : ?>
				
					<?php $abs_invalid_urls = NULL ;?>
				
					<h3><img src="/dmx/core/b0/images/sgm/interface/val_maybe_14.gif" width="14" height="14" alt="" /> URL mapping is currently disabled</h3>
					
					<p>
					<b>Please enable it in <i>/config/abs_options.php</i> if you want to use this feature.</b>
					</p>
					
					<p>
					Find the option reading: <pre>$abs_opt['url_mapping'] = 0;</pre>
					<p>
					
					<p>
					Change it to read: <pre>$abs_opt['url_mapping'] = 1;</pre>
					</p>
					
					<?php break; ?>
					
				<?php case 'PERMISSION_DENIED' : ?>
				
					<h3><img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="" /> Inbound URL mapping file could not be created: permission denied</h3>
					
					<p>
					Please ensure the <i>.htaccess</i> file in your dmABS root directory is writable by the web server.
					</p>
					
					<p>
					Either using your FTP package, or a secure shell client, log into your webserver and change permissions to 777<br />
					<b>chmod 777 <?=DOCROOT;?>/.htaccess</b>
					</p>
	
					<?php break; ?>
	
				<?php case 'NO_MAPPINGS_DEFINED' : ?>
					
					<?php if (empty($abs_invalid_urls)) : ?>
					
						<h3><img src="/dmx/core/b0/images/sgm/interface/val_maybe_14.gif" width="14" height="14" alt="" /> No URL mappings have beed sucessfully defined</h3>

						<p>
						Please define some URL mappings in <i>/config/easy_seo.csv</i>.
						</p>
						
					<?php else: ?>
						
						<h3><img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="" /> No URL mappings have beed sucessfully defined</h3>

					<?php endif; ?>
						
					<?php break; ?>
	
			<?php endswitch; ?>
	
			<?php if (!empty($abs_invalid_urls)) : ?>
			
				<p>
				<b>The following URLs were not remapped.</b>
				</p>
			
				<table border="0" width="100%" class="padded_table_thin active detailed">
					<tr>
						<td class="col1i"><b>Real URL</b></td>
						<td class="col1i"><b>Desired URL</b></td>
					</tr>
					<tr><td class="divider" colspan="2"><img src="/themes/baseline_brand/sgm/clear.gif" alt="" width="1" height="1" /></td></tr>
					<?php foreach($abs_invalid_urls as $map) : ?>
						<tr>
							<td class="col2f"><span style="float: right; margin-right: 5px;">=&gt;</span><?=$map['real_url'];?></td>
							<td class="col1f"><?=(htmlentities($map['desired_url']));?></td>
						</tr>
					<?php endforeach; ?>
					<tr><td class="divider" colspan="2"><img src="/themes/baseline_brand/sgm/clear.gif" alt="" width="1" height="1" /></td></tr>
				</table>
			
			<?php endif; ?>
	
			<br /><br /><br />

		<?php else: ?>

			<h1><img src="/dmx/core/b0/images/sgm/interface/val_error_14.gif" width="14" height="14" alt="" /> No SEO data found</h1>
			
			<p>
			Please make sure that you have uploaded <i>/config/easy_seo.csv</i> set permissions on it to 777 (read, write and execute).
			</p>

		<?php endif; ?>
		
		<!-- --------------- -->
		<!-- END MAIN COLUMN -->
		<!-- --------------- -->
		</div>
		
		<div class="sidebar">
		<!-- ------- -->
		<!-- SIDEBAR -->
		<!-- ------- -->
					
			<div class="sidebar_box_heading">
				<h2>Controls</h2>
			</div>
			<div class="sidebar_box_content">
				<div>
					
					<h2>Content Management</h2>
					<p>
					<a href="manage_panels.php">Manage Panels and Panel Updates</a>
					<br>
					<a href="version_date.php">Set Edit Date &amp; Version</a>
					<br>
					<a href="adaptingbody/index.php">Show Adapting Bodies</a>
					</p>
					
					<h2>SEO</h2>
					<p>
					<a href="seo_regenerate.php">Reload Easy SEO Data</a>
					</p>
			
					<h2>Security</h2>
					<p>
					<a href="set_pw.php">Reset Username and Password</a>
					</p>
					
				</div>
			</div>

		<!-- ----------- -->
		<!-- END SIDEBAR -->
		<!-- ----------- -->
		</div>
		
	</div>
</div>
<!-- END MAIN CONTENT AREA -->

<br style="clear: both;">
<br>

<?php include(DOCROOT . $abs_root . '/common/footer.php'); ?>
