<?require ("global.php");?>
<?php

$userID = 0;
if (isset($_COOKIE['userID'])) { $userID = $_COOKIE['userID']; }
else { header("Location: /tick/login.html"); }

$ID = "0";
$tag = "0";
$date_start = ''; $year_start = 0; $month_start = 0; $day_start = 0;
$date_end = ''; $year_end = 0; $month_end = 0; $day_end = 0;
$name = '';
$header_html = ''; $footer_html = ''; $banner_html = ''; $tower_html = '';
$map_key = ""; $title = "";
$status = 'inactive';
$notes = '';

if (isset($_GET['tag']))
{	
    $tag = $_GET["tag"];
    $query = "SELECT * FROM events WHERE tag = '$tag'";
    $result = mysql_query($query, $db);
    if ($result)
    {
	while ($r = mysql_fetch_array($result))
	{
	    $ID = $r['ID'];
	    $name = $r['name'];

	    $date_start = $r['date_start'];
	    list($year_start, $month_start, $day_start) = split("-", $date_start);
	    $date_end = $r['date_end'];
	    list($year_end, $month_end, $day_end) = split("-", $date_end);

	    $header_html = $r['header_html'];
	    $footer_html = $r['footer_html'];
	    $banner_html = $r['banner_html'];
	    $tower_html = $r['tower_html'];
	    $status = $r['status'];
	    $map_key = $r['map_key'];
	    $title = $r['title'];
	    $notes = $r['notes'];
	}
    }
}

?>

<html>
<head>
<title>OneTicker :: Events</title>
<link rel=stylesheet type="text/css" href="tick.css">
<script src="banner.js" type="text/javascript"></script>
</head>

<body bgcolor=#000000 marginheight=4 marginwidth=15 leftmargin=15 topmargin=4>

<script type="text/javascript">banner(1);</script>

<form name="events" action="events_add.php" method="post">
<input type="hidden" name="tag" value="<? echo $tag ?>">
<input type="hidden" name="userID" value="<? echo $userID ?>">
<input type="hidden" name="status" value="active">

<table border=0 cellspacing=1 cellpadding=1 width="680">
<tr>
<td><div class=text><b>Name:</b></div></td>
<td><input class=blacktext type=text name="name" value="<? echo $name; ?>" size=50 maxlength=175></td>
</tr>

<tr>
<td><div class=text><b>Map key:</b></div></td>
<td><input class=blacktext type=text name="map_key" value="<? echo $map_key; ?>" size=50 maxlength=254></td>
</tr>

<tr>
<td><div class=text><b>Window title:</b></div></td>
<td><input class=blacktext type=text name="title" value="<? echo $title; ?>" size=50 maxlength=254></td>
</tr>

<!--
<tr>
<td><div class=text><b>Status:</b></div></td>
<td><div class=text>
<select name=status class=blacktext>
<option value="inactive"<? if ($status == 'inactive') { echo " selected"; } ?>>inactive</option>
<option value="active"<? if ($status == 'active') { echo " selected"; } ?>>active</option>
<option value="neither"<? if ($status == 'neither') { echo " selected"; } ?>>neither</option>
</select>
</div></td>
</tr>
-->

<tr>
<td><div class=text><b>Start date:</b></div></td>
<td><div class=text>
<select class=blacktext name=month_start>
<? 
while(list($key, $value) = each($month_names))
{
    $selected = "";
    $month_index = $key + 1;
    if ($month_index == $month_start) { $selected = " selected"; }
    echo "<option value=\"${month_index}\"$selected>${value}</option>";
}
?>
</select>&nbsp;
<select class=blacktext name=day_start>
<? 
for ($i=1; $i<32;$i++)
{
    $selected = "";
    if ($i == $day_start) { $selected = " selected"; }
    echo "<option value=\"$i\"$selected>$i</option>";
}
?>
</select>&nbsp;
<select class=blacktext name=year_start>
<?
for ($i=2006; $i<2015;$i++)
{
    $selected = "";
    if ($i == $year_start) { $selected = " selected"; }
    echo "<option value=\"$i\"$selected>$i</option>";
}
?>
</select>
</div></td>
</tr>

<tr>
<td><div class=text><b>End date:</b></div></td>
<td><div class=text>
<select class=blacktext name=month_end>
<?
reset($month_names);
while(list($key, $value) = each($month_names))
{
    $selected = "";
    $month_index = $key + 1;
    if ($month_index == $month_end) { $selected = " selected"; }
    echo "<option value=\"${month_index}\"$selected>${value}</option>";
}
?>
</select>&nbsp;
<select class=blacktext name=day_end>
<? 
for ($i=1; $i<32;$i++)
{
    $selected = "";
    if ($i == $day_end) { $selected = " selected"; }
    echo "<option value=\"$i\"$selected>$i</option>";
}
?>
</select>&nbsp;
<select class=blacktext name=year_end>
<?
for ($i=2006; $i<2015;$i++)
{
    $selected = "";
    if ($i == $year_end) { $selected = " selected"; }
    echo "<option value=\"$i\"$selected>$i</option>";
}
?>
</select>
</div></td>
</tr>

<tr valign=top>
<td><div class=text><b>Header:</b><br>&nbsp;(HTML)</div></td>
<td><div class=blacktext>
<textarea class=blacktext name="header_html" cols=80 rows=5 wrap="virtual"><? echo "$header_html"; ?></textarea>
</div></td>
</tr>

<tr valign=top>
<td><div class=text><b>Footer:</b><br>&nbsp;(HTML)</div></td>
<td><div class=blacktext>
<textarea class=blacktext name="footer_html" cols=80 rows=5 wrap="virtual"><? echo "$footer_html"; ?></textarea>
</div></td>
</tr>

<tr valign=top>
<td><div class=text><b>Banner:</b><br>&nbsp;(HTML)</div></td>
<td><div class=blacktext>
<textarea class=blacktext name="banner_html" cols=80 rows=5 wrap="virtual"><? echo $banner_html; ?></textarea>
</div></td>
</tr>

<tr valign=top>
<td><div class=text><b>Tower:</b><br>&nbsp;(HTML)</div></td>
<td><div class=blacktext>
<textarea class=blacktext name="tower_html" cols=80 rows=5 wrap="virtual"><? echo $tower_html; ?></textarea>
</div></td>
</tr>

<tr valign=top>
<td><div class=text><b>Notes:</b></div></td>
<td><div class=blacktext>
<textarea class=blacktext name="notes" cols=80 rows=3 wrap="virtual"><? echo $notes; ?></textarea>
</div></td>
</tr>

<tr>
<td colspan="2" align=center>
<input class=boldtext type="submit" name="submit" value="add/update event"></td>
</tr>
</table>
</form>

<p><table border=0 cellpadding=0 cellspacing=0 bgcolor="#000000" width="700">
<tr><td>
<table border=0 cellpadding=3 cellspacing=1 bgcolor="#000000" width=100%>

<tr valign=top>
<td bgcolor=#cccccc align=center width="15%"><div class=blacktext><b>START</b></div></td>
<td bgcolor=#cccccc align=center width="15%"><div class=blacktext><b>FINISH</b></div></td>
<td bgcolor=#cccccc align=center><div class=blacktext><b>NAME</b></div></td>
<td bgcolor=#cccccc align=center width="10%"><div class=blacktext>&nbsp;</div></td>
</tr>

<?php

$query = "SELECT *, DATE_FORMAT(events.date_start, '%b %e, %Y') AS datef_start, DATE_FORMAT(events.date_end, '%b %e, %Y') AS datef_end FROM events WHERE userID = $userID ORDER BY date_start DESC";
$result = mysql_query($query, $db);

if ($result)
{
    while ($r = mysql_fetch_array($result))
    {
	$eventID = $r['ID'];
	$tag = $r['tag'];
	$status = $r['status'];
	$name = $r['name'];
	$date_start = $r['datef_start'];
	$date_end = $r['datef_end'];
	$default_flag = $r['default_flag'];

	if ($eventID == $ID) { echo "<tr bgcolor=#ffaaaa>"; }
	else { echo "<tr bgcolor=#ffffff>"; }
	echo "<td><div class=blacktext>&nbsp;<a href=\"events.php?tag=${tag}\">$date_start</a></div></td>";
	echo "<td><div class=blacktext>&nbsp;$date_end</div></td>";
	echo "<td><div class=blacktext>$name</div></td>";
	echo "<td>";
	//echo "<a href=\"javascript:popup('events_remove.php?tag=${tag}', 'event');\"><img src=\"images/x.gif\" border=0></a>&nbsp;";

	if ($default_flag == "yes")
	{
	    echo "<img src=\"images/checkmark.gif\" border=0>";
	}
	else
	{
	    echo "<a href=\"events_set_default.php?tag=${tag}\"><img src=\"images/checkmark_black.gif\" border=0 alt=\"make active\"></a>";
	}
	echo "</td>";
	echo "</tr>";
    }
}

?>

<tr valign=top>
<td bgcolor=#aaaaaa colspan=4><div class=blacktext>&nbsp;
</div></td>
</tr>

</table></td></tr>
</table>

</body>

</html>
