<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright EB Dynamics, Inc., Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 6/3/2009
// Revised: 1/12/2/12	ELL
// Added saving to page_data_draft table to accomodate new upgrade for save to draft mode.
// Revised: 1/16/2012	ELL
// Added seed HTML to make it easier to start editing the page.
// Revised: 2/7/2012	ELL
// Added table prefix handling.
	
	include ("check_session.php");
		
	$area_type = $_REQUEST['area_type'];
	
	$query = "SELECT page_name FROM " . BWB_TABLE_PREFIX . "page_data_special WHERE page_name LIKE '". $area_type . "%' ORDER BY page_name DESC";
	$result = mysql_query($query, $bwb_link);
	$row = mysql_fetch_array($result);
	$page_name = $row["page_name"];
	
	if ($page_name == $area_type)
		$special_page_name = $area_type . "1";
	else
	{
		$index = array();
		$i = 1;
		$index[0] = substr($page_name, strlen($area_type));
		while ($row = mysql_fetch_array($result))
		{
			$page_name = $row["page_name"];
			$index[$i] = substr($page_name, strlen($area_type));
			$i++;
		}
		sort($index);
		$index[$i-1] = $index[$i-1] + 1;
		$special_page_name = $area_type . $index[$i-1];
	}
	$body_html = "\n<p>Enter your content here.</p>\n";
	$today = date("Y-m-d H:i:s");
	$query = "INSERT INTO " . BWB_TABLE_PREFIX . "page_data_special SET page_name='" . $special_page_name . "', page_content='" . $body_html . "', revised='" . $today . "'";
	$result = mysql_query($query, $bwb_link);
	// Copy page data to draft table.
	$query = "INSERT INTO " . BWB_TABLE_PREFIX . "page_data_draft SET page_name='" . $special_page_name . "', page_content='" . $body_html . "', revised='" . $today . "', `source`=1";
	
	header("Location: manage_special.php");
?>