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

$link = "dynamic";
if (isset($_GET['link'])) { $link = $_GET['link']; }

$stageID = 0;
if (isset($_GET['ID']))
{
  $stageID = $_GET['ID'];
  
  $query = "SELECT events.name as event_name, stages.*, DATE_FORMAT(stages.date, '%b %e, %Y') AS datef FROM events, stages WHERE events.ID = stages.eventID AND stages.ID = $stageID";
  $result = mysql_query($query, $db);
  
  if ($result)
    {
      while ($r = mysql_fetch_array($result))
	{
	  $event_name = $r['event_name'];
	  $eventID = $r['eventID'];
	  $name = $r['name'];
	  $date = $r['datef'];
	  $start_location = $r['start_location'];
	  $end_location = $r['end_location'];
	  $distance = $r['distance'];
	  $refresh = $r['refresh'];
	  $tick_sequence = $r['tick_sequence'];
	  $refresh_type = $r['refresh_type'];
	  $mobile_notes = $r['mobile_notes'];
	  $notes = $r['notes'];
	}
      mysql_free_result($result);
    }
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<META HTTP-EQUIV="charset" CONTENT="UTF-8">
<title>VeloNews :: Live Race Coverage</title>
<style type="text/css">
<!--

.text
{
font-family : Verdana, Arial, Geneva, Helvetica;
font-size : 11px;
color : #000000;
line-height : 120%;
}

.smtext
{
font-family : Verdana, Arial, Geneva, Helvetica;
font-size : 10px;
color : #000000;
line-height : 120%;
}

.bigtext
{
font-family : Verdana, Arial, Geneva, Helvetica;
font-size : 14px;
color : #000000;
line-height : 120%;
}

A
{
font-family : Verdana, Arial, Geneva, Helvetica;
font-weight : bold;
font-size : 11px;
color : #ed1c24;
text-decoration : none;
}

A:hover
{
color : #ed1c24;
font-family : Verdana, Arial, Geneva, Helvetica;
text-decoration : underline;
font-weight : bold;
}

-->
</style>
</head>

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

<form name="which">
<table cellspacing=1 cellpadding=1 width="300" border=1 align=center>

<tr> <!-- header -->
<td align=center width="100%"><? echo "$header_html"; ?></td>
</tr>

<tr bgcolor="#cccccc" valign=top> <!-- stage information -->
<td><table cellpadding=0 cellspacing=0 border=0 width="100%">
<tr valign=top>
<td><div class=text>
&nbsp;<span class=bigtext><b><? echo "$event_name $name"; ?></b></span>
<br>&nbsp;<? echo "$date"; ?>&nbsp;-&nbsp;
&nbsp;<? echo "$start_location"; ?>&nbsp;to&nbsp;<? echo "$end_location"; ?>
<br>&nbsp;<? echo "$distance"; ?>
<!--<? if ($notes != "") { echo "<br>&nbsp;${notes}"; } ?>-->
<? if ($mobile_notes != "") { echo "<br>&nbsp;${mobile_notes}"; } ?>
</div></td>
</tr>
</table></td>
</tr>

<tr bgcolor="#dddddd">
<td><table border=0 cellpadding=0 cellspacing=0 width="100%">
<tr>
<td align=center><div class=text>
<b>Other stages:&nbsp;</b>
<select name=stage class=text onChange="location.href = document.which.stage.options[document.which.stage.selectedIndex].value">

<?php

$query = "SELECT * FROM stages WHERE eventID = $eventID AND (status = 'ongoing' OR status = 'complete') ORDER BY date";
$result = mysql_query($query, $db);

if ($result)
{
    while ($r = mysql_fetch_array($result))
    {
      $location = "/tick/viewer_mobile.php?ID=" . $r['ID'];
      if ($link == "static")
	{
	  $location = "stage" . $r['ID'] . "_mobile.html";
	}
      $selected = "";
      if ($stageID == $r['ID']) { $selected = " selected"; }
      echo "<option value=\"${location}\"${selected}>${event_name} ${r['name']}</option>";
    }
}

?>
</select>
</div></td>

<?

if (($popup_link != "") && ($popup_position == "stages"))
{
  echo "<td align=center><div class=text>[";
  echo "<a href=\"javascript:popup('html/pop_stage" . $stageID . ".html', 300, 300);\">";
  echo "$popup_link" . '</a>]</div></td>';
}

?>

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

<tr valign=top><td><table border=0 cellpadding=0 cellspacing=0><tr valign=top>
<td><DIV ID="commentary" STYLE="overflow: auto; width: 300px; height: 300px;
            border-left: 1px gray solid; border-bottom: 1px gray solid;
            border-right: 1px gray solid; border-top: 1px gray solid;
            padding:0px; margin: 0px">
<dl>

<?php

$query = "SELECT *, DATE_FORMAT(ticks.timestamp, '%l:%i %p') AS timef FROM ticks WHERE ticks.stageID = $stageID ORDER BY timestamp" . $tick_sequence;
$result = mysql_query($query, $db);

if ($result)
{
  while ($r = mysql_fetch_array($result))
    {
      $timestamp = $r['timef'];
      $headline = $r['headline'];
      $body = $r['body'];
      
      echo "<dt class=text><b>&nbsp;${timestamp}&nbsp;&nbsp;${headline}</b></dt>";
      echo "<dd class=text>${body}<p></dd>";
    }
}
mysql_free_result($result);

?>
</dl></div></td>

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

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

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

</table>
</form>

</body>
</html>
