<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 11/28/2013	ELL
// 
	
	include ("check_session.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Create Page Select</title>

<link rel="stylesheet" href="manager.css" type="text/css">

<style type="text/css">
#help_button	{	
	position:relative;
	display:block;
	top:-15px;
	left:215px;
	height:31px;
	width:31px;
	z-index:100;
}
</style>

<script language="javascript" type="text/javascript">
function UpdateTemplateImage()
{
	var i;
	<?php
	$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "options` WHERE `option_name` = 'Template' ORDER BY `sort_order`";
	$result = $bwb_dbh->query($query);
	$num_results = $result->rowCount();
	echo "var image = new Array($num_results);\n";
	for ($i = 0; $i < $num_results; $i++)
	{
		$row = $result->fetch(PDO::FETCH_ASSOC);
		$option_image = $row["option_image"];
		echo "image[$i] = \"$option_image\";\n";
	}
	?>
	
	i = document.getElementById("template_name").selectedIndex;
	document.getElementById("template_pic").src = "images/" + image[i];
}

function OpenHelpWindow()
{
	window.open("http://breezewebsitebuilder.com/docs/cms/help.html#create", "Help", "scrollbars=1,resizable=1,status=0,toolbar=0,menubar=0,location=0,height=700,width=800");
}
</script>

</head>

<body onload="UpdateTemplateImage();">
<div id="create_page">

<table width="90%" border="0" align="center">
    <tr><td>
<div class="button_heading_sub_level_1" id="create_page_heading"><div class="button_heading_text_sub_level_1">Create Page</div><div class="help_button" id="help_button" onclick="OpenHelpWindow();">&nbsp;</div></div>
	</td></tr>
</table>

		<form name="frmCreatePage" id="frmCreatePage" method="post" action="create_page.php">
		<table width="90%" border="0" align="center">
           <tr>
               <td valign="bottom">Enter the name of the page you want to create:</td>
               <td valign="bottom">Select a layout:</td>
               <td rowspan="2" width="100" height="100"><img id="template_pic" src="images/basic.jpg" border="0"></td>
          </tr>
          <tr>
			<td valign="top"><input name="createPage" type="text" id="createPage" style="width:200px;" /></td>
            <td valign="top">
            <select name="template_name" id="template_name" onChange="UpdateTemplateImage();" >
          <?php
		  	$query2 = "SELECT * FROM `" . BWB_TABLE_PREFIX . "options_selected` WHERE `option_name` = 'Template'";
			$result2 = $bwb_dbh->query($query2);
			$row2 = $result2->fetch(PDO::FETCH_ASSOC);
			$option_value_selected = $row2["option_value"];
		
		  	$query = "SELECT * FROM `" . BWB_TABLE_PREFIX . "options` WHERE `option_name` = 'Template' ORDER BY `sort_order`";
			$result = $bwb_dbh->query($query);
			$i = 0;
			while ($row = $result->fetch(PDO::FETCH_ASSOC))
			{
				$option_value = $row["option_value"];				
				if ($option_value_selected == $option_value)
					echo "<option value='$option_value' selected='selected'>$option_value</option>\n";
				else
					echo "<option value='$option_value'>$option_value</option>\n";
			 	$i++;
			}
			?>
            </select>
            </td>
         </tr>
        </table>
        <table width="90%" border="0" align="center">
          <tr>
            <td>Select a plugin you want to install into new page (optional):</td>
          </tr>
          <tr>
           <td>
          <select name="plugin" id="plugin" >
          	<option value='-not selected-'>-not selected-</option>
          <?php
            $query = "SELECT `id`, `name`, `description` FROM `" . BWB_TABLE_PREFIX . "plugins` WHERE `available`=1 ORDER BY `sort_order`";
            $result = $bwb_dbh->query($query);
            while ($row = $result->fetch(PDO::FETCH_ASSOC))
            {
                $id = $row["id"];
				$name = $row["name"];
				$description = $row["description"];
				if ($description == "")
                	echo "<option value='$id'>$name</option>\n";
				else
					echo "<option value='$id'>$name - $description</option>\n";
            }
            ?>
            </select>
            </td>
          </tr>
         </table>
         <br /><br />
		<center>
          <div class='button_console_add' style="width:105px;" onClick="document.getElementById('frmCreatePage').submit();"><span class='button_console_text_w_icon'>Create</span></div>
          <input type="hidden" name="mode" value="create" />
		</center>
	  </form>
      <br /><br /><br /><br /><br /><br />
      <p align="center">
			<span class="small_message">Note: To create a printable calendar, first change the template type to "basic" under "Change Site Options".
			(This requires admin access.)</span>
		</p>
		<p align="center" class="small_message">Note: Do NOT include file extension, i.e. ".htm".  This will be added automatically.
		Spaces will be replaced with under scores and non-compatible Unix characters will be removed.</p>
</div>
</body>
</html>