<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright EB Dynamics, Inc., Edward Lemmers, P.E.
// For licensing, see license.txt.
// Revised: 6/15/2007
// Added head_name and WHERE clause for editing different head content.
// Revised: 3/26/2010	ELL
// Changed "Submit" to "Save"
// Fixed bug with ecape codes.
// Revised: 10/12/2010	ELL
// Added revision datetime tracking.
// Revised: 11/9/2010	ELL
// Added persitence of last head edited.
// Revised: 1/16/2012	ELL
// Added "Publish" button and changed "Save" button function to save to draft.  Also added "Revert" so that draft can be discarded.
// Revised: 2/8/2012	ELL
// Added table prefix handling.  Added reference to user files folder constant.
	
	include ("check_session.php");
		
	$head_name = $_REQUEST['head_name'];
	$_SESSION['last_head_edited'] = $head_name;
?>
<html>
<head>
<title>Breeze Website Builder</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="manager.css" type="text/css">
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<script language="javascript" type="text/javascript">
function OpenHelpWindow()
{
	window.open("http://breezewebsitebuilder.com/docs/cms/help.html#edit_head", "Help", "scrollbars=1,resizable=1,status=0,toolbar=0,menubar=0,location=0,height=700,width=800");
}
</script>
</head>

<body>

<form action="save_head.php" method="post">
<div style='text-align:center;'>
<?php
//include "../connect/db_connection.php";

	$query = "SELECT page_content FROM " . BWB_TABLE_PREFIX . "page_data_draft WHERE page_name='$head_name' AND `source`=2";
	$result = mysql_query($query, $bwb_link);
	if (mysql_num_rows($result) > 0)
	{
		$row = mysql_fetch_array($result);
		$head_content = $row["page_content"];
	}
	else
	{
		$query = "SELECT head_content FROM " . BWB_TABLE_PREFIX . "head WHERE head_name = '$head_name'";
		$result = mysql_query($query, $bwb_link);
		$row = mysql_fetch_array($result);
		$head_content = $row["head_content"];
	}
	
	// Before we go any farther, back this puppy up!
	$revised = $row['revised'];
	$query = "INSERT INTO " . BWB_TABLE_PREFIX . "page_data_bkup SET page_name='$head_name', page_content='$head_content', revised='$revised', source=2";
	$result = mysql_query($query, $bwb_link);
	
	$head_content = stripslashes($head_content);

	echo "<textarea name='textarea_head_content' rows='30' style='width:80%;'>$head_content</textarea>\n";
	
	if (BWB_BASE_DIR == '')
		$path = "../" . BWB_WEBPAGE_DIR . "/index.php";
	else
		$path = "../" . BWB_BASE_DIR . "/" . BWB_WEBPAGE_DIR . "/index.php";

?>
</div>
      <br>
	  <table width="80%" align="center"><tr>
      <td align="left">
      <input type="submit" name="save" value="Save" />
      <input type="hidden" name="head_name" value="<?php echo $head_name; ?>" />
      </td>
      <td align="center">
      <input type="submit" name="publish" value="Publish" />
      </td>
       <td align="center">
      <input type="submit" name="revert" value="Revert" />
      </td>
      <td align="center">
      <input type="button" value="See Site" name="live_view"  onClick="window.open('<?php echo $path; ?>', '_blank');"/>
	  </td>
	  <td align="center"><input type="button" name="Back" value="Back to Main Menu" onClick="window.location.href='main.php?mode=head';" /></td>
      <td align="right">
      <div id="help_button_sm" onClick="OpenHelpWindow();">
        &nbsp;
      </div>
      </td>
	  </tr></table>
</form>

</body>
</html>
