<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright EB Dynamics, Inc., Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 7/12/2012	ELL
// 
//
	include ("check_session.php");

	$blog_id = $_REQUEST['blog_id'];
	$page_name = $_REQUEST['page_name'];
	$post_locate_string = "<!-- Post locate string for blog ID " . $blog_id . ". Do not remove this line. -->";
	
	// Get page name from blog table.
	$query = "SELECT page_name FROM " . BWB_TABLE_PREFIX . "blogs WHERE id=" . $blog_id;
	$result = mysql_query($query, $bwb_link);
	$row = mysql_fetch_array($result);
	$page_name = $row['page_name'];
	
	// Delete post form blogs.
	$query = "DELETE FROM " . BWB_TABLE_PREFIX . "blogs WHERE id=" . $blog_id;
	$result = mysql_query($query, $bwb_link);
	
	// Get page content from blog page.
	$query = "SELECT page_content 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'];
	
	// If post found on page, remove it.
	if (strpos($page_content, $post_locate_string) !== false)
	{
		$page_content_arr = explode($post_locate_string, $page_content);
		$page_content_wo_blog = $page_content_arr[0] . $page_content_arr[2];
		
		$query = "UPDATE " . BWB_TABLE_PREFIX . "page_data SET page_content='" . $page_content_wo_blog . "' WHERE page_name='" . $page_name . "'";
		$result = mysql_query($query, $bwb_link);
	}
	
	header("Location: main.php?mode=delete");
	
?>
