<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 6/3/2009
// Revised: 1/13/2012	ELL
// Added deletion of draft copies as well.
// Revised: 2/8/2012	ELL
// Added table prefix handling.
// Revised: 11/21/2014	ELL
// Added "redirect" such that this module can be used in more than one place.

	include ("check_session.php");
		
	$area_name = $_REQUEST['area_name'];
	$redirect = $_REQUEST['redirect'];
	
	// Before we go any farther, back this puppy up!
	$query = "SELECT * FROM " . BWB_TABLE_PREFIX . "page_data_special WHERE page_name='$area_name'";
	$result = $bwb_dbh->query($query);
	$row = $result->fetch(PDO::FETCH_ASSOC);
	$page_content = addslashes(stripslashes($row["page_content"]));
	$revised = $row["revised"];
	$today = date("Y-m-d H:i:s");
	$query = "INSERT INTO " . BWB_TABLE_PREFIX . "page_data_bkup SET page_name='$area_name', page_content='$page_content', `source`=1, revised='$revised', deleted='$today'";
	$cnt = $bwb_dbh->exec($query);
	
	$query = "DELETE FROM " . BWB_TABLE_PREFIX . "page_data_special WHERE page_name = '". $area_name . "'";
	$cnt = $bwb_dbh->exec($query);
	
	$query = "DELETE FROM " . BWB_TABLE_PREFIX . "page_data_draft WHERE page_name = '". $area_name . "' AND `source`=1";
	$cnt2 = $bwb_dbh->exec($query);
	
	if (isset($redirect) && ($redirect != "-no redirect-"))
		header("Location: $redirect");
	else
		echo $cnt . "@@@@@" . $area_name;
?>