<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created:	11/16/2014	ELL
// 

include ("check_session.php");

$file_name = $_POST["file_name"];
$folder = $_POST["folder"];
$draft_file_name = "." . $file_name . "_save";

if (strpos($file_name, "untitled", 0) === 0)	{
	echo "";
	exit;
}

$document_root = $_SERVER['DOCUMENT_ROOT'];
if ($folder == "pages")
{
	if (BWB_BASE_DIR == '')
		$path = $document_root . "/" . BWB_WEBPAGE_DIR;
	else
		$path = $document_root . "/" . BWB_BASE_DIR . "/" . BWB_WEBPAGE_DIR;
}
elseif ($folder == "scripts")
{
	if (BWB_BASE_DIR == '')
		$path = $document_root . "/" . BWB_SCRIPTS_DIR;
	else
		$path = $document_root . "/" . BWB_BASE_DIR . "/" . BWB_SCRIPTS_DIR;
}
elseif ($folder == "php")
	$path = $document_root . "/php";
else
{
	echo "Error: no folder specified\n";
	exit;
}

$file_path = $path . "/" . $draft_file_name;

if (!($fh = fopen($file_path, 'r')))
{	
	$file_path = $path . "/" . $file_name;
	
	if (!($fh = fopen($file_path, 'r'))) {
		echo "Error opening file.  Please contact your system administrator.\n$php_errormsg";
		exit;
	}
}

$contents = (fread($fh, filesize($file_path)));
fclose($fh);

echo $contents;
?>