<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright EB Dynamics, Inc., Edward Lemmers, P.E.
// For licensing, see license.txt.
// Revised: 10/12/2010	ELL
// Changed timestamping of `revised` field due to change from VARCHAR to DATETIME in table structure.
// Revised: 1/13/2012	ELL
// Added deletion of draft copies as well.
// Revised: 2/8/2012	ELL
// Added table prefix handling. Added reference to user files folder constant.
//
	include ("check_session.php");

	$page_name = $_GET['page_name'];
	
	// Before we go any farther, back this puppy up!
	$query = "SELECT * FROM " . BWB_TABLE_PREFIX . "page_data WHERE page_name='$page_name'";
	$result = mysql_query($query, $bwb_link);
	$row = mysql_fetch_array($result);
	$page_content = $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='$page_name', page_content='$page_content', revised='$revised', deleted='$today'";
	$result = mysql_query($query, $bwb_link);
	
	// Now go ahead and delete page record from table.
	$query = "DELETE FROM " . BWB_TABLE_PREFIX . "page_data WHERE page_name = '$page_name'";
	$result = mysql_query($query, $bwb_link);
	// And remove draft while you are at it.
	$query = "DELETE FROM " . BWB_TABLE_PREFIX . "page_data_draft WHERE page_name = '$page_name' AND `source`=0";
	$result = mysql_query($query, $bwb_link);
	
	// And delete actual page.
	$document_root = $_SERVER['DOCUMENT_ROOT'];
	if (BWB_BASE_DIR == "")
		$file_name = $document_root . "/" . BWB_WEBPAGE_DIR . "/" . $page_name . ".php";
	else
		$file_name = $document_root . "/" . BWB_BASE_DIR . "/" . BWB_WEBPAGE_DIR . "/" . $page_name . ".php";
	
	if (file_exists($file_name))
	{
		// Delete file.
		$fh = fopen($file_name, 'w') or die("Can't open $file_name: $php_errormsg");
		fclose($fh) or die($php_errormsg);
		unlink($file_name);
	}
	
	header("Location: main.php?mode=delete");
	
?>
