<?php

// new startup: begin
define('REL_PATH', 'admin/help');
$relation_level = count( explode('/', REL_PATH) );
define('FULL_PATH', realpath(dirname(__FILE__) . str_repeat('/..', $relation_level) ) );
require_once FULL_PATH.'/kernel/startup.php';
// new startup: end

$pathtolocal = $pathtoroot."kernel/";
require_once ($pathtoroot.$admin."/include/elements.php");
//require_once ($pathtoroot."kernel/admin/include/navmenu.php");
//require_once ($pathtolocal."admin/include/navmenu.php");
require_once($pathtoroot.$admin."/toolbar.php");

$section = $_REQUEST["section"];

$envar = BuildEnv();
int_help_header();

$section = explode(':', $section);
if($section[0] == 'in-portal') $section[0] = 'kernel';

$help_directory = FULL_PATH.'/'.$section[0].'/'.$admin.'/include/help';
$topic_path = $help_directory.'/'.$section[1].'.txt';

// for debugging: save new help content
if( GetVar('action') == 'save_help' )
{
	$fp = fopen($topic_path, 'w');
	if ($fp) {
		fwrite($fp, stripslashes(GetVar('help_content')) );
		fclose($fp);
	}
	else {
		trigger_error('Help file was not saved to <b>'.$topic_path.'</b>', E_USER_WARNING);
	}
	
}

$help_data = file_exists($topic_path) ? file_get_contents($topic_path) : GetVar('help_content');
if($section[0] == 'kernel') $section[0] = 'in-portal';

?>
<table width="100%" border="0" cellspacing="0" cellpadding="4" class="tableborder">
	<tr>
		<td bgcolor="F6F6F6">
		<div class="help_box">
		<?php
			if( file_exists($topic_path) )
				echo $help_data;
			else
				echo defined('DBG_HELP') && DBG_HELP ? 'missing section help file <b>'.$section[1].'.txt</b><br>' : admin_language('la_help_in_progress');
				
			?>
		</div>
		<?php
			if( defined('DBG_HELP') && DBG_HELP )
			{
		?>
				<br><input type="button" onclick="document.save_help.submit();" value="Save Changes" style="font-weight: bolder; background-color: #F6F6F6;"><br>
				<form name="save_help" id="save_help" method="post" action="<?php echo $_SERVER['PHP_SELF'].'?env='.$envar; ?>">
					<textarea id="help_content" name="help_content" rows="15" cols="85"><?php echo $help_data; ?></textarea>
					<input type="hidden" name="section" value="<?php echo implode(':',$section); ?>">
					<input type="hidden" name="action" value="save_help">
					<?php if( GetVar('help_usage') ) { ?>
					<input type="hidden" name="help_usage" value="<?php echo GetVar('help_usage'); ?>">
					<?php } ?>
				</form>	
		<?php 
			}
		?>
		</td>
	</tr>
</table>
<? int_footer(); ?>