<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 4/3/2014	ELL
// 
	
	include ("check_session.php");
	$saved_page_name = $_GET['page_name'];
	$saved_plugin_name = $_GET['plugin_name'];
	$refresh_buttons = $_GET['refresh_buttons'];
?>

<!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;
}

.vertical_scroll_div	{
	max-height:550px;
	overflow-y:auto;
	overflow-x:hidden;
}
</style>

<script language="javascript" type="text/javascript" src="js/browser_detect.js"></script>
<script language="javascript" type="text/javascript" src="js/mouse_position.js"></script>
<script language="javascript" type="text/javascript" src="js/popup_msg.js"></script>
<script language="javascript" type="text/javascript" src="js/add_plugin_to_page_select.js"></script>

<script language="javascript" type="text/javascript">
<?php
	if (isset($saved_page_name) && ($saved_page_name != "") && isset($saved_plugin_name) && ($saved_plugin_name != ""))
	{
		echo "var saved_page_name = '$saved_page_name';\n";
		echo "var saved_plugin_name = '$saved_plugin_name';\n";
	}
?>
</script>

</head>

<body>

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

		<form name="frmAddPluginToPage" id="frmAddPluginToPage" method="post" action="add_plugin_to_page.php" enctype="multipart/form-data">
        <table width="90%" border="0" align="center">
          <tr>
            <td>
            <div class="button_heading_sub_level_1"><div class="button_heading_text_sub_level_1">Select Page</div></div>
            </td>
            <td>
            <div class="button_heading_sub_level_1"><div class="button_heading_text_sub_level_1">Select Plugin</div></div>
            </td>
          </tr>
          <tr>
           <td valign="top">
           <div class="vertical_scroll_div">
           <?php
			$query = "SELECT page_name FROM " . BWB_TABLE_PREFIX . "page_data ORDER BY page_name";
			$result = $bwb_dbh->query($query);
			$num_results = $result->rowCount();
			for ($i = 0; $i < $num_results; $i++)
			{
				$row = $result->fetch(PDO::FETCH_ASSOC);
				$page_name = $row["page_name"];
				if ($page_name == $saved_page_name)
					$selected = " down_sub";
				else
					$selected = "";

				if ($page_name == "index")
					$home = " (Home)";
				else
					$home = "";
					
				echo "<div id='page_name_select$i' class='button_sub_level_1$selected' onClick=\"SelectPage('$page_name', $i);\"><span class='button_text_sub_level_1'>$page_name$home</span></div>\n";
			}
			
			?>

            <input type="hidden" name="page_name" id="page_name" />
            <input type="hidden" name="page_cnt" id="page_cnt" value="<?php echo $i; ?>" />
            </div>
           </td>
           <td valign="top">
            <div class="vertical_scroll_div">
          <?php
            $query = "SELECT `id`, `name`, `description` FROM `" . BWB_TABLE_PREFIX . "plugins` WHERE `available`=1 ORDER BY `sort_order`";
            $result = $bwb_dbh->query($query);
            $num_results = $result->rowCount();
			for ($i = 0; $i < $num_results; $i++)
			{
				$row = $result->fetch(PDO::FETCH_ASSOC);
                $id = $row["id"];
				$plugin_name = $row["name"];
				$description = $row["description"];
				if ($description != "")
                	$description = " - " . $description;
					
				if ($plugin_name == $saved_plugin_name)
					$selected = " down_sub";
				else
					$selected = "";
					
				echo "<div id='plugin_select$i' class='button_sub_level_1$selected' style='width:100%;' onClick=\"SelectPlugin('$id', $i);\"><span class='button_text_sub_level_1'>$plugin_name$description</span></div>\n";
            }
            ?>
            
            <input type="hidden" name="plugin" id="plugin" />
            <input type="hidden" name="plugin_cnt" id="plugin_cnt" value="<?php echo $i; ?>" />
            </div>
            </td>
          </tr>
         </table>
         <br />
		<center>
          <div class='button_console_add' style="width:105px;" onClick="document.getElementById('frmAddPluginToPage').submit();"><span class='button_console_text_w_icon'>Install</span></div>
		</center>
	  </form>

<?php include("lib/popup_msg.html"); ?>

<script language="javascript" type="text/javascript">
	HidePopupMsg();
	
<?php	if (isset($saved_page_name) && ($saved_page_name != ""))	{	?>
	popup_msg.top_offset = 100;
	popup_msg.left_offset = 320;
	popup_msg.popup_msg_type = 1;
	popup_msg.popup_timeout = 3000;
	popup_msg.status_msg = 'The <b>' + saved_plugin_name + '</b> plugin has been inserted into the <b>' + saved_page_name + '</b> page.';
	popup_msg.ShowPopupMsg();
<?php	}	?>
		
<?php 
	if ($refresh_buttons)	{
		echo "	parent.LoadPluginButtons();\n";
	}
?>
</script>
</body>
</html>