<?php
/////////////////////////////////////////////
// Breeze Website Builder
// Copyright EB Dynamics, Inc., Edward Lemmers, P.E.
// For licensing, see license.txt.
// Revised: 2/10/2012	ELL
// Added table prefix handling.  Added reference to website folder configuration.
//
//	include ("check_session.php");

//	$cpanel_user_id = $_SESSION['cpanel_user_id'];
//	$cpanel_user_id_confirm = $_GET['cpanel_user_id_confirm'];
//	if ($cpanel_user_id != $cpanel_user_id_confirm)
//	{
//		header("Location: ../manage/main.php");
//		exit;
//	}

  $cpanel_user_id_confirm_json = (isset($_SERVER['HTTP_X_CPANELID']) ? $_SERVER['HTTP_X_CPANELID'] : false);

  include ("wizard_initialize.php");

    if (headers_sent()) {
      echo "FAILED";
      exit;
    }

//	include "/home/" . $cpanel_user_id . "/public_html/connect/db_connection.php";

	$query = "SELECT `page_name` FROM `" . BWB_TABLE_PREFIX . "page_data`";
	$result = $bwb_dbh->query($query);
	while ($row = $result->fetch(PDO::FETCH_ASSOC))
	{
		$page_name = $row['page_name'];
		// Before we go any farther, back these puppies up!
		$query2 = "SELECT * FROM " . BWB_TABLE_PREFIX . "page_data WHERE page_name='$page_name'";
		$result2 = $bwb_dbh->query($query2);
		$row2 = $result2->fetch(PDO::FETCH_ASSOC);
		$page_content = $row2["page_content"];
		$today = addslashes(date("m/d/Y  H:m:s"));
		$revised = $row["revised"];
		$page_content = addslashes(stripslashes($page_content));
		$query2 = "INSERT INTO " . BWB_TABLE_PREFIX . "page_data_bkup SET page_name='$page_name', page_content='$page_content', revised='$revised', deleted='$today'";
		$cnt = $bwb_dbh->exec($query2);

		// Now go ahead and delete page record from table.
		$query2 = "DELETE FROM " . BWB_TABLE_PREFIX . "page_data WHERE page_name = '$page_name'";
		$cnt = $bwb_dbh->exec($query2);

		// And delete actual page.
		$document_root = $_SERVER['DOCUMENT_ROOT'];
		if (BWB_BASE_DIR == '')
			$userfiles = '';
		else
			$userfiles = "/" . BWB_BASE_DIR;
		if (BWB_WEBPAGE_DIR == '')
			$website_path = '';
		else
			$website_path = "/" . BWB_WEBPAGE_DIR;
		$file_name = $document_root . $userfiles . $website_path . "/" . $page_name . ".php";
		if (file_exists($file_name))
			unlink($file_name);
	}

	echo "COMPLETE";

?>