<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created:	2/6/2021	ELL
// 
	include ("check_session.php");
		
	$query = "SELECT `language_folder` FROM " . BWB_TABLE_PREFIX . "plugins WHERE `name` = 'View Form Tables'";
	$result = $bwb_dbh->query($query);
	$row = $result->fetch(PDO::FETCH_ASSOC);
	$language_folder = $row['language_folder'];
	
	$document_root = $_SERVER['DOCUMENT_ROOT'];
	if ((defined("BWB_LANG")) && (file_exists($document_root . "/" . $language_folder . "/" . BWB_LANG . ".php")))
		include_once ($document_root . "/" . $language_folder . "/" . BWB_LANG . ".php");
	else
		include_once ($document_root . "/" . $language_folder . "/en.php");
	
	$manage_image_dir = "/manage/theme/" . $theme . "/images/";
	$rel_manage_image_dir = "../theme/" . $theme . "/images/";
	
	$id = $_REQUEST['id'];
	$table = $_REQUEST['table'];
	$form_page = $_REQUEST['form_page'];
	
	$query = "SELECT * FROM " . BWB_TABLE_PREFIX . "page_data WHERE page_name = '" . $form_page . "'";
	$result = $bwb_dbh->query($query);
	$row = $result->fetch(PDO::FETCH_ASSOC);
	$page_content = $row["page_content"];
	$page_content = stripslashes($page_content);
	
	if ((BWB_BASE_DIR == '') && (BWB_WEBPAGE_DIR == ''))
	{
		$webpage_dir = "/";
		$php_dir = "/" . BWB_LIB_DIR . "/";
		$scripts_dir = "/" . BWB_SCRIPTS_DIR . "/";
		$css_dir = "/" . BWB_CSS_DIR . "/";
		$webpage_dir_rel = "../../";
		$php_dir_rel = "../../" . BWB_LIB_DIR . "/";
		$scripts_dir_rel = "../../" . BWB_SCRIPTS_DIR . "/";
		$css_dir_rel = "../../" . BWB_CSS_DIR . "/";
	}
	elseif ((BWB_BASE_DIR == '') || (BWB_WEBPAGE_DIR == ''))
	{
		if (BWB_BASE_DIR == '')
		{
			$webpage_dir = "/" . BWB_WEBPAGE_DIR . "/";
			$php_dir = "/" . BWB_LIB_DIR . "/";
			$scripts_dir = "/" . BWB_SCRIPTS_DIR . "/";
			$css_dir = "/" . BWB_CSS_DIR . "/";
			$webpage_dir_rel = "../../" . BWB_WEBPAGE_DIR . "/";
			$php_dir_rel = "../../" . BWB_LIB_DIR . "/";
			$scripts_dir_rel = "../../" . BWB_SCRIPTS_DIR . "/";
			$css_dir_rel = "../../" . BWB_CSS_DIR . "/";
		}
		elseif (BWB_WEBPAGE_DIR == '')
		{
			$webpage_dir = "/" . BWB_BASE_DIR . "/";
			$php_dir = "/" . BWB_LIB_DIR . "/";
			$scripts_dir = "/" . BWB_SCRIPTS_DIR . "/";
			$css_dir = "/" . BWB_BASE_DIR ."/" . BWB_CSS_DIR . "/";
			$webpage_dir_rel = "../../" . BWB_BASE_DIR . "/";
			$php_dir_rel = "../../" . BWB_LIB_DIR . "/";
			$scripts_dir_rel = "../../" . BWB_BASE_DIR ."/" . BWB_SCRIPTS_DIR . "/";
			$css_dir_rel = "../../" . BWB_BASE_DIR ."/" . BWB_CSS_DIR . "/";
		}
	}
	else
	{
		$webpage_dir = "/" . BWB_BASE_DIR . "/" . BWB_WEBPAGE_DIR . "/";
		$php_dir = "/" . BWB_BASE_DIR . "/" . BWB_LIB_DIR . "/";
		$scripts_dir = "/" . BWB_BASE_DIR . "/" . BWB_SCRIPTS_DIR . "/";
		$css_dir = "/" . BWB_BASE_DIR ."/" . BWB_CSS_DIR . "/";
		$webpage_dir_rel = BWB_BASE_DIR . "/" . BWB_WEBPAGE_DIR . "/";
		$php_dir_rel = "../../" . BWB_LIB_DIR . "/";
		$scripts_dir_rel = "../../" . BWB_BASE_DIR . "/" . BWB_SCRIPTS_DIR . "/";
		$css_dir_rel = "../../" . BWB_BASE_DIR . "/" . BWB_CSS_DIR . "/";
	}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edit Form Record</title>
<link rel="stylesheet" href="<?php echo $css_dir; ?>mail_form.css" type="text/css">

<style>
#close_btn_div	{
	position: absolute;
	right: 10px;
	top: 5px;
	cursor: pointer;
}

#frmMailForm	{	width: auto;	}

.mail_form_div	{
	margin: inherit;
}
</style>

<script src="../js/jquery.min.js"></script>
<script src="../js/browser_detect.js"></script>
<script src="../js/mouse_position.js"></script>
<script src="../js/popup_msg.js"></script>
<script src="js/edit_form_record.js"></script>
<!--<script src="<?php //echo $scripts_dir; ?>form_processor.js"></script>-->

<script>
<?php
if (isset($id) && ($id != ""))	{
	echo "	var id = $id;\n";
	echo "	var mode = 'Update';\n";
}
else
	echo "	var mode = 'Add';\n";
echo "	var table = '$table';\n";

echo "	var webpage_dir = '" . $webpage_dir . "';\n";
echo "	var php_dir = '" . $php_dir . "';\n";
echo "	var scripts_dir = '" . $scripts_dir . "';\n";
echo "	var css_dir = '" . $css_dir . "';\n";
echo "	var webpage_dir_rel = '" . $webpage_dir_rel . "';\n";
echo "	var php_dir_rel = '" . $php_dir_rel . "';\n";
echo "	var css_dir_rel = '" . $css_dir_rel . "';\n";

//echo "	var login_required = false;\n";
//echo "	var this_page = '" . $form_page . ".php';\n";
?>
</script>
</head>

<body onLoad="InitializeForm();">
<div id="content_div">
<div id="close_btn_div">
	<img src="../theme/classic/images/close-button.png" alt="Close" onClick="window.parent.CloseEditForm();">
</div>
<?php	echo $page_content;	?>

</div>
</body>
</html>