<?
	/**
	 * Main editor window where the contents of a file are displayed for user to edit.
	 *
	 * @author	$Author: suraj $
	 * @version	$Revision: 1.9 $, $Date: 2003/02/11 03:53:38 $
	 */

	require_once("assets/includes/config.inc.php");
	
	// check if path was set
	if(isset($path) && $path != "")
	{
		$path = realpath($path); // convert user input to a valid path
	}
	else
	{
		$path = ""; //$cfgVars['BROWSER_ROOT_PATH']; // default path
	}
	
	// check for path beyond top-most allowed directory
	if(!strstr($path, realpath($cfgVars['BROWSER_ROOT_PATH'])))
	{
		$path = "";
	}
	
	// boolean to check if the path is ready to be read from
	$path_ok = file_exists($path) && !is_dir($path) && is_readable($path);
	
	// start displaying page
	$page_title = $appVars['name'] . " - $path";
	include("assets/includes/page-header.inc.php");
?>
<script language="javascript" type="text/javascript" src="assets/libraries/cookies.lib.js"></script>
<script language="javascript" type="text/javascript" src="assets/libraries/editor.lib.js"></script>

<h1><?= $appVars['name'] . " v" . $appVars['version'] ?><br>
<tt class="filepath"><?= $path . ($path_ok ? " ~ ". fileSizeLabel($path) : "") ?></tt></h1>

<form id="EditorForm" name="EditorForm" method="post" action="">
	<input type="hidden" name="path" value="<?= $path ?>">
	<input type="hidden" name="is_file" value="<?= (is_file($path) ? 1 : 0) ?>">
	<input type="hidden" name="textRows" value="">
	<input type="hidden" name="textCols" value="">

	<table class="box" border="0" cellspacing="0" cellpadding="10">
	<tr>
		<td>
			<p>
				<input type="button" name="new" value="New File" onclick="newFile()">
				<input type="button" name="open" value="Open File" onclick="openFile()">
				<input type="button" name="close" value="Close File" onclick="closeFile()">
				 ;
				<input type="button" name="save" value="Save File" onclick="saveFile()">
				<input type="button" name="saveAs" value="Save File As..." onclick="saveFileAs()">
			</p>
			<p>
				<input type="button" name="download" value="Download" onclick="downloadFile()">
				<input type="button" name="upload" value="Upload" onclick="uploadFile()">
				<input type="button" name="refresh" value="Reload" onclick="refreshFile()">
				 ;
				<input type="button" name="spellcheck" value="SpellCheck" onclick="spellCheck()">
			</p>
		</td>
	</tr>
	<tr>
		<td><textarea name="file_contents" rows="10" cols="10" style="width: 100%"><?
		
			if($path_ok)
			{
				$fcontents = implode('', file($path));
				$file_contents = stripslashes($file_contents);
				$fcontents = htmlspecialchars($fcontents);
				
				echo $fcontents; // display contents
			}
		
		?></textarea></td>
	</tr>
	</table>
</form>
<?
	include("assets/includes/page-footer.inc.php");
?>
