<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright Silver Dolphin Solutions, LLC, Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created:	11/28/2013	ELL
// Revised: 8/27/2014	ELL
// Added site title which is appended to page title if it exists.  If it does not, then default title is used and site title is not appended.
// 

	include ("check_session.php");
	
	$selected_page_name = $_REQUEST['selected_page_name'];
	$page_title_saved = $_REQUEST['page_title_saved'];
?>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Editing <?php echo $selected_page_name; ?> Title | Breeze Website Builder</title>
<link rel="stylesheet" href="theme/<?php echo $theme; ?>/manager.css" type="text/css">

<style type="text/css">
#manage_users_site_options_heading	{	width:300px;	}
#help_button	{	
	position:relative;
	display:block;
	top:-15px;
	left:215px;
	height:31px;
	width:31px;
	z-index:100;
}
#update_default_page_title_btn	{	width:110px;	}
#update_page_title_btn	{	width:110px;	}
</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/edit_title_select.js"></script>

</head>

<body>
<div id="sub_level_1_buttons">
<div class="button_heading_sub_level_1" id="edit_page_titles_heading"><div class="button_heading_text_sub_level_1"><?php echo EDIT_PAGE_TITLES_HEADING; ?></div><div class="help_button" id="help_button" onClick="OpenHelpWindow();">&nbsp;</div></div>

  <table border="0" width="100%">
		<tr>
			<td>
			  <form name="frmChangeDefaultTitle" id="frmChangeDefaultTitle" method="post" action="save_page_title.php">
			  <p align="center">
			  <?php echo EDIT_PAGE_TITLES_REVISE_DEFAULT_PAGE_TITLE; ?>:<br>
			  <?php
				$query = "SELECT title FROM " . BWB_TABLE_PREFIX . "page_titles WHERE page_name = '_default_'";
			
				$result = $bwb_dbh->query($query);
				$row = $result->fetch(PDO::FETCH_ASSOC);
				$title = $row["title"];
				$title = addslashes($title);
				echo "<input type='text' name='title' id='title' value='$title' size='40' />\r\n";
				?>
				</p>
				<center>
				<input type="hidden" name="page_name" id="page_name" value="_default_" />
                <div class='button_console_save' id="update_default_page_title_btn" onClick="document.getElementById('frmChangeDefaultTitle').submit();"><span class='button_console_text_w_icon'><?php echo UPDATE_WORD; ?></span></div>
				</center>
			  </form>
	  		</td>
	  		<td>
			  <form name="frmChangePageTitles" id="frmChangePageTitles" method="post" action="save_page_title.php">
			  <p align="center">
			  <?php echo EDIT_PAGE_TITLES_SELECT_PAGE; ?>:<br>
			  <select name='page_name' id='page_name' OnChange="FillInPageTitle(this.options[this.selectedIndex].value);" class="page_dropdown">
			  <?php
				$query = "SELECT page_name FROM " . BWB_TABLE_PREFIX . "page_data ORDER BY page_name";
				$result = $bwb_dbh->query($query);
				while ($row = $result->fetch(PDO::FETCH_ASSOC))
				{
					$page_name = $row["page_name"];
					$page_name = addslashes($page_name);
					if (($page_name == $selected_page_name) || (!$selected_page_name && !$page_selected))
					{
						echo "<option value='$page_name' selected='selected'>$page_name</option>\r\n";
						$query2 = "SELECT `title` FROM `" . BWB_TABLE_PREFIX . "page_titles` WHERE `page_name` = '" . $page_name . "'";
						$result2 = $bwb_dbh->query($query2);
						$row2 = $result2->fetch(PDO::FETCH_ASSOC);
						$title = $row2["title"];
						$title = addslashes($title);
						$page_selected = 1;
					}
					else
						echo "<option value='$page_name'>$page_name</option>\r\n";
				}
				?>
				</select>
				<input type='text' name='title' id='title' value='<?php echo $title; ?>' size='40' />
				</p>
				<center>
                <div class='button_console_save' id="update_page_title_btn" onClick="document.getElementById('frmChangePageTitles').submit();"><span class='button_console_text_w_icon'><?php echo UPDATE_WORD; ?></span></div>
				</center>
			  </form>
			</td>
	  	</tr>
        <tr><td colspan="2" height="50">&nbsp;</td></tr>
        <tr>
        	<td>
			  <form name="frmChangeTitle" id="frmChangeTitle" method="post" action="save_page_title.php">
			  <p align="center">
			  <?php echo EDIT_PAGE_TITLES_REVISE_SITE_TITLE; ?> <span class="small_message">(<?php echo EDIT_PAGE_TITLES_SITE_TITLE_NOTE; ?>)</span>:<br>
			  <?php
				$query = "SELECT title FROM " . BWB_TABLE_PREFIX . "page_titles WHERE page_name = '_append_'";
			
				$result = $bwb_dbh->query($query);
				$row = $result->fetch(PDO::FETCH_ASSOC);
				$title = $row["title"];
				$title = addslashes($title);
				echo "<input type='text' name='title' id='title' value='$title' size='40' />\r\n";
				?>
				</p>
				<center>
				<input type="hidden" name="page_name" id="page_name" value="_append_" />
                <div class='button_console_save' id="update_default_page_title_btn" onClick="document.getElementById('frmChangeTitle').submit();"><span class='button_console_text_w_icon'><?php echo UPDATE_WORD; ?></span></div>
				</center>
			  </form>
	  		</td>
            <td>&nbsp;</td>
        </tr>
	  </table>
	
</div>

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

<script language="JavaScript"  type="text/javascript">
	popup_msg.HidePopupMsg();
<?php	if ($page_title_saved == 1)	{	?>
	popup_msg.top_offset = 100;
	popup_msg.left_offset = 320;
	popup_msg.popup_msg_type = 1;
	popup_msg.popup_timeout = 2000;
	popup_msg.status_msg = "<?php echo EDIT_PAGE_TITLES_PAGE_TILE_SAVED_MSG; ?>";
	popup_msg.ShowPopupMsg();
<?php	}	?>
</script>
</body>
</html>