<?php
////////////////////////////////////////////////////////////////////////
// Breeze Website Builder
// Copyright EB Dynamics, Inc., Edward Lemmers, P.E.
// For licensing, see license.txt.
// Created: 6/4/2009
// Added table prefix handling.  Added references to website files folder configurations.
	
	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>Breeze Website Builder</title>

<link rel="stylesheet" href="manager.css" type="text/css">
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">

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

function DeleteConfirm()
{
	document.getElementById("delete_confirm").style.display = "block";
	document.getElementById("delete_confirm").style.position = "absolute";
	document.getElementById("delete_confirm").style.top = "200px";
	document.getElementById("delete_confirm").style.left = "300px";
	document.getElementById("delete_confirm").style.width = "450px";
	document.getElementById("delete_confirm").style.backgroundColor = "#FFF";
	document.getElementById("delete_confirm").style.borderStyle = "solid";
	document.getElementById("delete_confirm").style.borderWidth = "2px";
	document.getElementById("delete_confirm").style.borderColor = "#000";
	document.getElementById("delete_text").innerHTML = document.getElementById("head_name").value;
}

function DeleteHead()
{
	var head_name = document.getElementById("head_name").value;
	document.getElementById("delete_confirm").style.display = "none";
	var url = "delete_head.php?head_name=" + head_name;
	window.location = url;
}

function HideDelete()
{
	document.getElementById("delete_confirm").style.display = "none";
}
</script>

</head>

<body>
<p align="center" class="title">Head Content Assignment</p>
<table width="80%" border="1" align="center"><tr><td>
<span class="sub_title">Add Head Content</span>
<table width="100%" border="0" align="center">
<tr>
<td align="center">
  <form name="frmAddHead" method="post" action="add_head.php">
  <input type="submit" name="submit" value="Add Another Head Content" />
  </form>
</td>
</tr>
</table>
</td></tr></table>
<br />

<table width="80%" border="1" align="center"><tr><td>
<table width="100%" border="0" align="center">
<tr bgcolor="#CCCCCC">
  <td colspan="3"><span class="sub_title">Assign Head Content to Page</span></td></tr>
  <?php
  		$bgcolor = "#EEEEEE";
		$query = "SELECT page_name FROM " . BWB_TABLE_PREFIX . "page_data";
		$result = mysql_query($query, $bwb_link);
		$i = 1;
		while($row = mysql_fetch_array($result))
		{
			$page_name = $row["page_name"];
			echo "<form name='frmAssign$i' method='post' action='assign_head.php'>\n";
			echo "<tr bgcolor='$bgcolor'>\n";
			echo "<td>$page_name</td>";
			
			/////////////////////////////////////////
			//Test to see if file already exists.
			$document_root = $_SERVER['DOCUMENT_ROOT'];
			if (BWB_BASE_DIR == '')
				$file_name = $document_root . "/" . BWB_WEBPAGE_DIR . "/" . $page_name . ".php";
			else
				$file_name = $document_root . "/" . BWB_BASE_DIR . "/" . BWB_WEBPAGE_DIR . "/" . $page_name . ".php";
				
			if (!file_exists($file_name))
			{
				echo "Error: $file_name does not exists.  Click <a href=\"manage_special.php\" title=\"here\">here</a> to return to the area assignment page.";
				exit;
			}
	
			// Read file.
			$fh = fopen($file_name, 'r') or die("Can't read $file_name: $php_errormsg");
			$contents = fread($fh, filesize($file_name));
			fclose($fh) or die($php_errormsg);
		
			$search_str_head = "head_name='head";
		
			$start_pos = strpos($contents, $search_str_head, 1);
			$end_pos = strpos($contents, "\"", $start_pos) - 1;
			$start_pos = $start_pos + strlen("head_name='");
			$head_str = substr($contents, $start_pos, $end_pos - $start_pos);
			////////////////////////////////////
			
			echo "<td>\n";
			echo "<select name=\"head_name\">\n";
			$query2 = "SELECT head_name FROM " . BWB_TABLE_PREFIX . "head";
			$result2 = mysql_query($query2, $bwb_link);
			while($row2 = mysql_fetch_array($result2))
			{
				$head_name = $row2["head_name"];
				if ($head_name == $head_str)
					echo "<option value='$head_name' selected='selected'>$head_name</option>\n";
				else
					echo "<option value='$head_name'>$head_name</option>\n";
			}
			echo "</select>\n";
			echo "</td>\n";
			
			echo "<td>\n";
			echo "<input type='submit' name='submit' value='Assign' />\n";
			echo "<input type='hidden' name='page_name' value='$page_name' />\n";
			echo "</td>\n";
			echo "</tr>\n";
			echo "</form>";
			$i++;
			if ($bgcolor == "#EEEEEE")
				$bgcolor = "#DDDDDD";
			else
				$bgcolor = "#EEEEEE";
		}
   ?>
</table>
</td></tr></table>
<br />

	<table width="80%" border="1" align="center"><tr><td>
    <span class="sub_title">Delete Head Content</span>
	<table width="100%" align="center" border="0"><tr>
	  <td align="center">Select the head content you want to delete: </td>
	  <td>
		<select name="head_name" id="head_name">
	<?php
		$query = "SELECT head_name FROM " . BWB_TABLE_PREFIX . "head";
		$result = mysql_query($query, $bwb_link);
		while($row = mysql_fetch_array($result))
		{
			$head_name = $row["head_name"];
			if (($head_name != "head") && ($head_name != ""))
				echo "<option value='$head_name'>$head_name</option>";
		}
	?>
		</select>
	  </td>
	  <td align="center">
	  <input type="button" name="delete" value="Delete" onclick="DeleteConfirm();">
	  </td>
	</tr></table>
    </td></tr></table>

<br />
<table width="80%" border="0" cellspacing="0" cellpadding="0">
  <tr>
  <td align="center">
  <input type="button" name="Back" value="Back to Main Menu" onClick="window.location.href='main.php?mode=head';">
  </td>
  <td valign="top" align="right" width="10%">
      <div id="help_button" onClick="OpenHelpWindow();">
        &nbsp;
      </div>
  </td>
  </tr>
</table>

<div id="delete_confirm">
<table border="0" cellspacing="0" cellpadding="5" align="center">
  <tr>
    <td colspan="2">Are your sure you want to delete the <b><div id="delete_text">&nbsp;</div></b> menu?</td>
  </tr>
  <tr>
	<td align="center"><input type="button" name="delete" id="delete" value="Yes" onClick="DeleteHead();" /></td>
	<td align="center"><input type="button" name="hide_delete" value="No" onClick="HideDelete();" />
    </td>
  </tr>
</table>
</div>

</body>
</html>