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

	include ("check_session.php");
	
	$page_name = $_REQUEST['page_name'];
	$blog_id = $_REQUEST['blog_id'];
	$special = $_REQUEST['special'];	//Flag to tell if editing special page (header, footer, side panel...).
	$mode = $_REQUEST['mode'];
	$prepend = $_REQUEST['prepend'];
	$postpend = $_REQUEST['postpend'];
	
	if ($mode == "blog")
	{
		$query = "DELETE FROM " . BWB_TABLE_PREFIX . "blogs_draft WHERE blog_id='$blog_id'";
		$cnt = $bwb_dbh->exec($query);
		
		$query = "SELECT * FROM " . BWB_TABLE_PREFIX . "blogs WHERE id='$blog_id'";
		$result = $bwb_dbh->query($query);
		$row = $result->fetch(PDO::FETCH_ASSOC);
		$page_content = $row["post"];
	}
	else
	{
		$query = "DELETE FROM " . BWB_TABLE_PREFIX . "page_data_draft WHERE page_name='$page_name'";
		$cnt = $bwb_dbh->exec($query);
		
		if ($special == 1)
			$query = "SELECT * FROM " . BWB_TABLE_PREFIX . "page_data_special WHERE page_name='$page_name'";
		else
			$query = "SELECT * FROM " . BWB_TABLE_PREFIX . "page_data WHERE page_name='$page_name'";
		$result = $bwb_dbh->query($query);
		$row = $result->fetch(PDO::FETCH_ASSOC);
		$page_content = $row["page_content"];
	}
	
	$encap_delim = "<!-- WYSIWYG Encapsulation. Modify HTML inside of these comments only.  All code outside of these comments is discarded. -->";
	$page_content = $prepend . $encap_delim . $page_content . $encap_delim . $postpend;
	
	if ($cnt > 0)
		echo stripslashes($page_content);
	else
		echo "Revert failed";
?>