<?php
////////////////////////////////////////////////////////////////////////
// EB Content Management System
// Copyright EB Dynamics, Inc., Edward Lemmers, P.E.
// Revised: 4/10/2010	ELL
// Added date picker and removed obsolete switch for HebrewDateConversion.
// Revised: 10/29/2010	ELL
// Complelely re-engineered for speed with many dates using AJAX.
// Revised:	2/17/2011	ELL
// Fixed bug in IE where jsDatePick did not work.  (DOCTYPE neede to be declared.)  Added sorting of dates.
// Revised: 2/8/2012	ELL
// Added table prefix handling.
// Revised: 4/26/2012	ELL
// Spare rows were missing table prefix for page list.  Added table prefix to fix missing page list.
// Revised: 7/3/2012	ELL
// Added user/group assigned events.
//
	include ("check_session.php");
	
	$spares = 100;
?>
<!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>
<title>EB Content Management System</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="manager.css" type="text/css">

<link rel="stylesheet" type="text/css" media="all" href="js/jsDatePick.css" />
<script type="text/javascript" src="js/jsDatePick.min.1.1.js"></script>

<script type="text/javascript" src="js/json2.js"></script>
<script type="text/javascript" src="js/ajax.js"></script>

<script language="JavaScript"  type="text/javascript">

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;

function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	if (tempX < 0){tempX = 0;}
	if (tempY < 0){tempY = 0;}  
	return true;
}

var pages = new Array();
<?php
	$query = "SELECT page_name FROM " . BWB_TABLE_PREFIX . "page_data ORDER BY page_name";
	$result = mysql_query($query, $bwb_link);
	$num_results = mysql_num_rows($result);
	for ($j = 0; $j < $num_results; $j++)
	{
		$row = mysql_fetch_array($result);
		$page_name = $row["page_name"];
		echo "pages[$j] = '$page_name';\n";
	}
?>	


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

//////////////////////////////////////////////////////////////////////////////////////
function DeleteConfirm(desc_remove, ID, y_offset)
{
	var ntop;
	ntop = tempY;
	if (ntop < 500)
		ntop = ntop + 20;
	else
		ntop = ntop - 20;
	var strtop = ntop + "px";
	
	document.getElementById("delete_confirm").style.display = "block";
	document.getElementById("delete_confirm").style.position = "absolute";
	document.getElementById("delete_confirm").style.top = strtop;
	document.getElementById("delete_confirm").style.left = "100px";
	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("event_to_delete").value = ID;
	document.getElementById("row_to_delete").value = y_offset;
	document.getElementById("delete_text").innerHTML = desc_remove;
}

function DeleteEvent()
{
	var params = "";

	if (document.getElementById("StatusMsg").innerHTML == " ")
	{
		document.getElementById("StatusMsg").innerHTML = "Starting delete...";
		document.getElementById("StatusMsg2").innerHTML = "Starting delete...";
	}
	var xmlhttp;
	xmlhttp = getXmlHttpRequestObject();

	if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0)
	{
		xmlhttp.open("POST","delete_event.php",true);
		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xmlhttp = UpdateMessage(xmlhttp, "StatusMsg", "DeleteEvent");
		params = "ID=" + document.getElementById("event_to_delete").value;
		params = params + "&desc_remove=" + document.getElementById("delete_text").innerHTML;
//		alert(params);
		xmlhttp.send(params);
	}
	document.getElementById("delete_confirm").style.display = "none";
}

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

//////////////////////////////////////////////////////////////////////////////////////
function Update(j)
{
	if (!chkForm(j))
		return;
	var params = "";
	var ID_str = "ID" + j;
	var Description_str = "Description" + j;
	var EventDate_str = "EventDate" + j;
	var StartTime_str = "StartTime" + j;
	var EndTime_str = "EndTime" + j;
	var URL_str = "URL" + j;
	var Active_str = "Active" + j;
	var user_table_str = "selectUserTable" + j;
	var UserID_str = "selectUserID" + j;
	var AccessLevel_str = "selectAccessLevel" + j;
	
	if (document.getElementById("StatusMsg").innerHTML == " ")
	{
		document.getElementById("StatusMsg").innerHTML = "Starting update...";
		document.getElementById("StatusMsg2").innerHTML = "Starting update...";
	}
	var xmlhttp;
	xmlhttp = getXmlHttpRequestObject();

	if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0)
	{
		xmlhttp.open("POST","save_event.php",true);
		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xmlhttp = UpdateMessage(xmlhttp, "StatusMsg", "Update");
		params = "ID=" + document.getElementById(ID_str).value;
		params = params + "&Description=" + document.getElementById(Description_str).value;
		params = params + "&EventDate=" + document.getElementById(EventDate_str).value;
		params = params + "&StartTime=" + document.getElementById(StartTime_str).value;
		params = params + "&EndTime=" + document.getElementById(EndTime_str).value;
		params = params + "&URL=" + document.getElementById(URL_str).value;
		if (document.getElementById(Active_str).checked == true) params = params + "&Active=1";
		else params = params + "&Active=0";
		params = params + "&user_table=" + document.getElementById(user_table_str).value;
		params = params + "&UserID=" + document.getElementById(UserID_str).value;
		params = params + "&AccessLevel=" + document.getElementById(AccessLevel_str).value;
//		alert(params);
		xmlhttp.send(params);
	}
}

function chkForm(j)
{
	var bOKtoSend = true;
	var strItem;
	var dateField;
	var strDateField;
	
	strItem = "EventDate" + j;
	dateField = document.getElementById(strItem);
	//Remove white space for fair cheking of length.
	dateField.value = (dateField.value).replace(/^\s*|\s*$/g,'');
	strDateField = dateField.value;
	// Check for blank, incorrect legnth, or slashes not found in correct spot.
//		if ((strDateField == "") || (strDateField.length != 10) || (strDateField.indexOf("/") != 2) || (strDateField.lastIndexOf("/") != 5))
	if ((strDateField == "") || (strDateField.length != 10) || (strDateField.indexOf("-") != 4) || (strDateField.lastIndexOf("-") != 7))
	{
//			alert("Please fill in the date in the format of 'mm/dd/yyyy'.");
		alert("Please fill in the date in the format of 'yyyy-mm-dd'.");
		dateField.focus();
		bOKtoSend = false;
	}
	return(bOKtoSend);
}

//////////////////////////////////////////////////////////////////////////////////////
	function UpdateMessage(xmlhttp, StatusMsg_control_name, Source)
	{
		var StatusMsg_control_name2 = StatusMsg_control_name + "2";
		var query_complete_no_record = "Query complete.  No records found.";
		var query_complete = "<b>Query complete</b><br/>";
		var query_read_to_send = "Query ready to send...";
		var query_sent = "Query sent";
		var query_starting = "Locating events...";
		if (Source == "DeleteEvent")
		{
			query_complete_no_record = "No records found. Could not delete event.";
			query_complete = "<b>Event deleted</b><br/>";
			query_starting = "Deleting event...";
		}
		else if (Source == "Update")
		{
			query_complete_no_record = "No records found. Could not update event.";
			query_complete = "<b>Event updated</b><br/>";
			query_starting = "Updating event...";
		}
		else if (Source == "Populate")
		{
			query_complete_no_record = "No records found. Could not update user lists.";
			query_complete = "<b>User lists updated</b><br/>";
			query_starting = "Updating user lists...";
		}
		
		xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4)
			{
				if (xmlhttp.responseText.length > 0)
				{
					var rows_str = xmlhttp.responseText;
					if (rows_str == "-no data-")
					{
						document.getElementById(StatusMsg_control_name).innerHTML = query_complete_no_record;
						document.getElementById(StatusMsg_control_name2).innerHTML = query_complete_no_record;
					}
					else
					{
						document.getElementById(StatusMsg_control_name).innerHTML = query_complete;
						document.getElementById(StatusMsg_control_name2).innerHTML = query_complete;
						if (Source == "DeleteEvent")
						{
							document.getElementById(StatusMsg_control_name).innerHTML = rows_str;
							document.getElementById(StatusMsg_control_name2).innerHTML = rows_str;
							var tr_j = "tr_" + document.getElementById("row_to_delete").value;
							document.getElementById(tr_j).style.display = "none";
						}
						else if (Source == "Update")
						{
							document.getElementById(StatusMsg_control_name).innerHTML = rows_str;
							document.getElementById(StatusMsg_control_name2).innerHTML = rows_str;
							// Look for insert.
							if ((rows_str.indexOf("has been added.", 5)) > 0)
							{
								var id_arr = rows_str.split("[");
								var id = id_arr[1];
								id_arr = "";
								id_arr = id.split("]");
								id = id_arr[0];
								j = document.getElementById("rec_cnt").value - 1;
								var ID_str = "ID" + j;
								document.getElementById(ID_str).value = id;
								var tr_j = "tr_" + j;
								if (j%2)
									document.getElementById(tr_j).bgColor = "#EEEEEE";
								else
									document.getElementById(tr_j).bgColor = "#DDDDDD";
							}
						}
						else if (Source == "Populate")
						{	PopulateUsers(rows_str);	}
					}
				}
				else
				{
					document.getElementById(StatusMsg_control_name).innerHTML = query_complete_no_record;
					document.getElementById(StatusMsg_control_name2).innerHTML = query_complete_no_record;
				}

				var ClearMessageString = "ClearMessage('" + StatusMsg_control_name + "');";
				mTimer = setTimeout(ClearMessageString, 2000);
			}
			else if (xmlhttp.readyState==1)
			{
				document.getElementById(StatusMsg_control_name).innerHTML = query_read_to_send;
				document.getElementById(StatusMsg_control_name2).innerHTML = query_read_to_send;
			}
			else if (xmlhttp.readyState==2)
			{
				document.getElementById(StatusMsg_control_name).innerHTML = query_sent;
				document.getElementById(StatusMsg_control_name2).innerHTML = query_sent;
			}
			else if (xmlhttp.readyState==3)
			{
				document.getElementById(StatusMsg_control_name).innerHTML = query_starting;
				document.getElementById(StatusMsg_control_name2).innerHTML = query_starting;
			}
		}
		return (xmlhttp);
	}

//////////////////////////////////////////////////////////////////////////////////////
function ClearMessage(StatusMsg_control_name)
{
	var StatusMsg_control_name2 = StatusMsg_control_name + "2";
	document.getElementById(StatusMsg_control_name).innerHTML = "&nbsp;";
	document.getElementById(StatusMsg_control_name2).innerHTML = "&nbsp;";
	clearInterval(mTimer);
}

////////////////////////////////////////////////////////////////////////////////////
function AddEvent()
{
	var j = document.getElementById("rec_cnt").value;
	var k = document.getElementById("row_cnt").value;
	var tr_j = "tr_" + j;
	document.getElementById(tr_j).style.display = "table-row";
	document.getElementById(tr_j).bgColor = "#FFFF99";

	/////////// Increment record count //////////////////
	j++;
	document.getElementById("rec_cnt").value = j;
	
	///// Check for spare rows, and if all used up, recommend save and refresh. /////
	if (j >= k)
	{
		var top = (k * 59);
		document.getElementById("refresh_required").style.display = "block";
		document.getElementById("refresh_required").style.position = "absolute";
		document.getElementById("refresh_required").style.top = top;
		document.getElementById("refresh_required").style.left = "100px";
		document.getElementById("refresh_required").style.width = "450px";
		document.getElementById("refresh_required").style.backgroundColor = "#FFF";
		document.getElementById("refresh_required").style.borderStyle = "solid";
		document.getElementById("refresh_required").style.borderWidth = "2px";
		document.getElementById("refresh_required").style.borderColor = "#000";
	}
}

function HideRefreshRequired()
{
	document.getElementById("refresh_required").style.display = "none";
}

//////////////////////////////////////////////////////////////////////////////////////
var selected_row = -1;

function RetrieveUsers(user_table, i)
{	
	selected_row = i;
	
	if (document.getElementById("StatusMsg").innerHTML == " ")
	{
		document.getElementById("StatusMsg").innerHTML = "Starting user query...";
		document.getElementById("StatusMsg2").innerHTML = "Starting user query...";
	}
	var xmlhttp;
	xmlhttp = getXmlHttpRequestObject();

	if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0)
	{
		xmlhttp.open("POST","populate_users.php",true);
		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		xmlhttp = UpdateMessage(xmlhttp, "StatusMsg", "Populate");
		params = "user_table=" + user_table;
//		alert(params);
		xmlhttp.send(params);
	}
}

function PopulateUsers(rows_str)
{
	var rows = new Array();

	var output_str = "<select name='selectUserID" + selected_row + "' id='selectUserID" + selected_row + "'>\n";
	output_str = output_str + "<option>-not selected-</option>\n";

	rows = rows_str.split("@@@@@");
	if (rows[0] == "-no data-")	// If no pages yet (first time).
		var i = 0;
	else	// Create options for access level list.
	{
		for (var i in rows)
		{
			var JSON_row = JSON.parse(rows[i]);
			if (JSON_row.UserID)
				output_str = output_str + "<option value='" + JSON_row.UserID + "'>" + JSON_row.UserID + "</option>\n";
		}
	}
	output_str = output_str + "<\/select>\n";
	
	var UserID_td_str = "UserID" + selected_row + "_td";
	document.getElementById(UserID_td_str).innerHTML = output_str;
}


</script>

</head>

<body>
<div align="center">

<table width="80%"><tr>
<td class="title">Revise Schedule</td>
<td align="center"><div id="StatusMsg"> </div></td>
<td align="right"><input type="button" name="Back" id="Back" value="Back to Main Menu" onClick="window.location.href='main.php?mode=edit';" /></td>
</tr></table>

<div id="Schedule">
<table><tbody>
<?php
	echo "<tr bgcolor='#CCCCCC'>\n";
	echo "<td><b>Description</b></td>\n";
	echo "<td><b>Date <font size=1>(YYYY-mm-dd)</font></b></td>\n";
	echo "<td><b>Start Time</b></td>\n";
	echo "<td><b>End Time</b></td>\n";
	echo "<td><b>Link</b></td>\n";
	echo "<td><b>Active</b></td>\n";
	echo "<td><b>User Table</b></td>\n";
	echo "<td><b>User ID</b></td>\n";
	echo "<td><b>Access Level</b></td>\n";
	echo "<td>&nbsp;</td>\n";
	echo "<td>&nbsp;</td>\n";
	echo "</tr>\n";
	$query = "SELECT * FROM " . BWB_TABLE_PREFIX . "schedule ORDER BY EventDateSort";
	$result = mysql_query($query, $bwb_link);
	$num_results = mysql_num_rows($result);
	for ($i = 0; $i < $num_results; $i++)
	{
		$row = mysql_fetch_array($result);
		
		$ID = $row["ID"];
		$Description = $row["Description"];
		$EventDate = $row["EventDate"];
		$StartTime = $row["StartTime"];
		$EndTime = $row["EndTime"];
		$URL = $row["URL"];
		$Active = $row["Active"];
		$user_table = $row["user_table"];
		$UserID = $row["UserID"];
		$AccessLevel = $row["AccessLevel"];
		$Description = stripslashes($Description);
		$EventDate = stripslashes($EventDate);
		$EventDateArr = explode("/", $EventDate);
		$EventDate = $EventDateArr[2] . "-" . $EventDateArr[0] . "-" . $EventDateArr[1];
		$StartTime = stripslashes($StartTime);
		$EndTime = stripslashes($EndTime);
		$URL = stripslashes($URL);
		
		if ($bgclr == "#DDDDDD")
			$bgclr = "#EEEEEE";
		else
			$bgclr = "#DDDDDD";
		
		echo "<tr bgcolor='$bgclr' id='tr_$i'>\n";
		echo "<td valign='top'><input type='hidden' id='ID$i' name='ID$i' value='$ID' /><textarea id='Description$i' name='Description$i'>$Description</textarea></td>\n";
		echo "<td valign='top'><input type='text' id='EventDate$i' name='EventDate$i' value='$EventDate' /></td>\n";
		echo "<td valign='top'><input type='text' id='StartTime$i' name='StartTime$i' value='$StartTime' /></td>\n";
		echo "<td valign='top'><input type='text' id='EndTime$i' name='EndTime$i' value='$EndTime' /></td>\n";
		
		echo "<td valign='top'>\n";
		echo "<select name=\"selectPage$i\" onChange=\"document.getElementById('URL$i').value=this.value+'.php';\">\n";
		echo "<option value=''>-not selected-</option>\n";
		$query2 = "SELECT page_name FROM " . BWB_TABLE_PREFIX . "page_data ORDER BY page_name";
		$result2 = mysql_query($query2, $bwb_link);
		$num_results2 = mysql_num_rows($result2);
		for ($j = 0; $j < $num_results2; $j++)
		{
			$row2 = mysql_fetch_array($result2);
			$page_name = $row2["page_name"];
			$page_name_tmp = $page_name . ".php";
			if ($page_name_tmp == $URL)
				echo "<option value='$page_name' selected='selected'>$page_name</option>\n";
			else
				echo "<option value='$page_name'>$page_name</option>\n";
		}
		echo "</select>\n";
		echo "<input type='text' id='URL$i' name='URL$i' value='$URL'></td>\n";
		
		echo "<td valign='top'>\n";
		if ($Active == 1)
			echo "<input id='Active$i' name='Active$i' type='checkbox' value='active' checked='checked'></td>\n";
		else
			echo "<input id='Active$i' name='Active$i' type='checkbox' value='active'></td>\n";
		
		echo "<td valign='top'>\n";
		echo "<select name=\"selectUserTable$i\" id=\"selectUserTable$i\" onChange=\"RetrieveUsers(this.value, $i);\">\n";
		echo "<option value=''>-not selected-</option>\n";
		$query2 = "SHOW TABLES";
		$result2 = mysql_query($query2, $bwb_link);
		$num_results2 = mysql_num_rows($result2);
		while ($row2 = mysql_fetch_array($result2))
		{
			$tmp_table = $row2[0];
			if ((substr($tmp_table, 0, strlen(BWB_TABLE_PREFIX)) != BWB_TABLE_PREFIX) || (BWB_TABLE_PREFIX == ""))
			{
				if ($tmp_table == $user_table)
					echo "<option value='$tmp_table' selected='selected'>$tmp_table</option>\n";
				else
					echo "<option value='$tmp_table'>$tmp_table</option>\n";
			}
		}
		echo "</select>\n";
		echo "</td>\n";
		
		echo "<td valign='top' id='UserID" . $i . "_td'>\n";
		echo "<select name=\"selectUserID$i\" id=\"selectUserID$i\">\n";
		echo "<option value=''>-not selected-</option>\n";
		if ($user_table != "")
		{
			$query2 = "SELECT `UserID` FROM `" . $user_table . "`";
			$result2 = mysql_query($query2, $bwb_link);
			while ($row2 = mysql_fetch_array($result2))
			{
				$tmp_UserID = $row2["UserID"];
				if (($tmp_UserID != "") && (!is_null($tmp_UserID)))
				{
					if ($tmp_UserID == $UserID)
						echo "<option value='$tmp_UserID' selected='selected'>$tmp_UserID</option>\n";
					else
						echo "<option value='$tmp_UserID'>$tmp_UserID</option>\n";
				}
			}
		}
		echo "</select>\n";
		echo "</td>\n";
		
		echo "<td valign='top'>\n";
		echo "<select name=\"selectAccessLevel$i\" id=\"selectAccessLevel$i\">\n";
		echo "<option value=''>-not selected-</option>\n";
		$query2 = "SELECT `access_level` FROM `" . BWB_TABLE_PREFIX . "access_levels`";
		$result2 = mysql_query($query2, $bwb_link);
		while ($row2 = mysql_fetch_array($result2))
		{
			$tmp_AccessLevel = $row2["access_level"];
			if ($tmp_AccessLevel == $AccessLevel)
				echo "<option value='$tmp_AccessLevel' selected='selected'>$tmp_AccessLevel</option>\n";
			else
				echo "<option value='$tmp_AccessLevel'>$tmp_AccessLevel</option>\n";
		}
		echo "</select>\n";
		echo "</td>\n";
		
		echo "<td valign='top'><img src='images/save.png' border=0 alt='Update' name='Update$i' onClick=\"Update($i);\" /></td>\n";
		$strSearch = array("\"", "'");
		$desc_remove = str_replace($strSearch, "", $Description);
		echo "<td valign='top'><img src='images/delete.png' border=0 alt='Delete' name='Delete' onClick=\"DeleteConfirm('$desc_remove', $ID, $i);\" /></td>\n";
		echo "</tr>\n";
	}
	
	/////////////////// Spare rows ////////////////////////
	for ($k = $i; $k < $i + $spares; $k++)
	{
		echo "<tr id='tr_$k' style='display:none;'>\n";
		echo "<td valign='top'><input type='hidden' id='ID$k' name='ID$k' value='-1' /><textarea id='Description$k' name='Description$k'></textarea></td>\n";
		echo "<td valign='top'><input type='text' id='EventDate$k' name='EventDate$k' value='' /></td>\n";
		echo "<td valign='top'><input type='text' id='StartTime$k' name='StartTime$k' value='' /></td>\n";
		echo "<td valign='top'><input type='text' id='EndTime$k' name='EndTime$k' value='' /></td>\n";
		
		echo "<td valign='top'>\n";
		echo "<select name=\"selectPage$k\" onChange=\"document.getElementById('URL$k').value=this.value+'.php';\">\n";
		echo "<option value=''>-not selected-</option>\n";
		$query2 = "SELECT page_name FROM " . BWB_TABLE_PREFIX . "page_data ORDER BY page_name";
		$result2 = mysql_query($query2, $bwb_link);
		$num_results2 = mysql_num_rows($result2);
		for ($j = 0; $j < $num_results2; $j++)
		{
			$row2 = mysql_fetch_array($result2);
			$page_name = $row2["page_name"];
			echo "<option value='$page_name'>$page_name</option>\n";
		}
		echo "</select>\n";
		echo "<input type='text' id='URL$k' name='URL$k' value=''></td>\n";
		
		echo "<td valign='top'>\n";
		echo "<input id='Active$k' name='Active$k' type='checkbox' value='active' checked='checked'></td>\n";
		
		echo "<td valign='top'>\n";
		echo "<select name=\"selectUserTable$i\" id=\"selectUserTable$i\" onChange=\"RetrieveUsers(this.value, $i);\">\n";
		echo "<option value=''>-not selected-</option>\n";
		$query2 = "SHOW TABLES";
		$result2 = mysql_query($query2, $bwb_link);
		$num_results2 = mysql_num_rows($result2);
		while ($row2 = mysql_fetch_array($result2))
		{
			$tmp_table = $row2[0];
			if ((substr($tmp_table, 0, strlen(BWB_TABLE_PREFIX)) != BWB_TABLE_PREFIX) || (BWB_TABLE_PREFIX == ""))
				echo "<option value='$tmp_table'>$tmp_table</option>\n";
		}
		echo "</select>\n";
		echo "</td>\n";
		
		echo "<td valign='top' id='UserID" . $i . "_td'>\n";
		echo "<select name=\"selectUserID$i\" id=\"selectUserID$i\">\n";
		echo "<option value=''>-not selected-</option>\n";
		if ($user_table != "")
		{
			$query2 = "SELECT `UserID` FROM `" . $user_table . "`";
			$result2 = mysql_query($query2, $bwb_link);
			while ($row2 = mysql_fetch_array($result2))
			{
				$tmp_UserID = $row2["UserID"];
				if (($tmp_UserID != "") && (!is_null($tmp_UserID)))
					echo "<option value='$tmp_UserID'>$tmp_UserID</option>\n";
			}
		}
		echo "</select>\n";
		echo "</td>\n";
		
		echo "<td valign='top'>\n";
		echo "<select name=\"selectAccessLevel$i\" id=\"selectAccessLevel$i\">\n";
		echo "<option value=''>-not selected-</option>\n";
		$query2 = "SELECT `access_level` FROM `" . BWB_TABLE_PREFIX . "access_levels`";
		$result2 = mysql_query($query2, $bwb_link);
		while ($row2 = mysql_fetch_array($result2))
		{
			$tmp_AccessLevel = $row2["access_level"];
			echo "<option value='$tmp_AccessLevel'>$tmp_AccessLevel</option>\n";
		}
		echo "</select>\n";
		echo "</td>\n";
		
		echo "<td valign='top'><img src='images/save.png' border=0 alt='Update' name='Update$i' onClick=\"Update($k);\" /></td>\n";
		echo "<td valign='top'><img src='images/delete.png' border=0 alt='Delete' name='Delete' onClick=\"DeleteConfirm('$desc_remove', -1, $k);\" /></td>\n";
		echo "</tr>\n";
	}
?>
	</tbody></table>
</div>
<?php 
	echo "<input type='hidden' name='rec_cnt' id='rec_cnt' value='$i' />\n";
	$k = $i + $spares;
	echo "<input type='hidden' name='row_cnt' id='row_cnt' value='$k' />\n";
?>
<table width="80%">
		<tr>
		<td>
		  <input type="submit" value="Add New Event" name="submit" onClick="AddEvent();" />
		</td>
        <td align="center" width="40%"><div id="StatusMsg2"> </div></td>
		<td align="center">
          <input type="button" name="Back" value="Back to Main Menu" onClick="window.location.href='main.php?mode=edit';" />
		</td>
        <td align="right"  width="10%">
        <div id="help_button_sm" onClick="OpenHelpWindow();">
        &nbsp;
        </div>
		</td>
		</tr>
	</table>
    Note: Changes will not be recorded unless you select <img src="images/save.png" width="16" height="16" alt="Save" />.
</div>

<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> event?</td>
  </tr>
  <tr>
	<td align="center"><input type="button" name="delete" id="delete" value="Yes" onClick="DeleteEvent();" /></td>
	<td align="center"><input type="button" name="hide_delete" value="No" onClick="HideDelete();" />
    <input type="hidden" name="event_to_delete" id="event_to_delete" />
    <input type="hidden" name="row_to_delete" id="row_to_delete" />
    </td>
  </tr>
</table>
</div>

<div id="refresh_required">
<table border="0" cellspacing="0" cellpadding="5" align="center">
  <tr>
    <td align="center">
	You have reached the memory limit of the number of events that can be added in one session.  To continue, save any unsaved events and refresh the page.<br>
    <input type="button" name="hide_refresh_required" value="Close" onClick="HideRefreshRequired();" />
     </td>
  </tr>
</table>
</div>

<script language="JavaScript" type="text/javascript">
window.onload = function(){
<?php
	$query = "SELECT * FROM " . BWB_TABLE_PREFIX . "schedule ORDER BY EventDateSort";
	$result = mysql_query($query, $bwb_link);
	$num_results = mysql_num_rows($result);
	for ($i = 0; $i < $num_results + $spares; $i++)
		echo <<<END
		
	g_globalObject$i = new JsDatePick({
		useMode:2,
		target:"EventDate$i"
	});
	
END;

?>
};
</script>

</body>
</html>