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

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

$stageID = 0;
if (isset($_COOKIE['stageID'])) { $stageID = $_COOKIE['stageID']; }
else { header("Location: /tick/stages.php"); }

$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 AND events.userID = $userID";
$result = mysql_query($query, $db);

if ($result)
{
    while ($r = mysql_fetch_array($result))
    {
	$event_name = $r['event_name'];
	$stage_string = "[${r['datef']}] ${event_name} ${r['name']}";
    }
}
mysql_free_result($result);

$ID = 0;
$filename = '';
$caption = '';
$courtesy_of = '';
$default_flag = '';
if (isset($_GET['ID']))
{	
    $ID = $_GET["ID"];
    $query = "SELECT * FROM pics WHERE ID = $ID";
    $result = mysql_query($query, $db);
    if ($result)
    {
	while ($r = mysql_fetch_array($result))
	{
	    $filename = $r['filename'];
	    $caption = $r['caption'];
	    $courtesy_of = $r['courtesy_of'];
	    $default_flag = $r['default_flag'];
	}
    }
}

?>

<html>
<head>
<title>OneTicker :: Pics</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(4);</script>

<form name="pics" enctype="multipart/form-data" action="pics_add.php" method="post">
<input type="hidden" name="ID" value="<? echo $ID ?>">
<input type="hidden" name="stageID" value="<? echo $stageID ?>">

<table border=0 cellspacing=1 cellpadding=1 width="480">
<tr>
<td><div class=text><b>Stage:</b></div></td>
<td><div class=text><? echo "$stage_string"; ?></div></td>
</tr>

<tr valign=top>
<td><div class=text><b>Picture:</b></div></td>
<td><div class=text>
<input class=blacktext type=file name="pic" size=40>
<ul>
<li>image will be resized appropriately</li>
<li>leave blank to keep existing image</li>
<li>DO NOT put non-alphanumeric characters in image filenames</li>
<li>don't forget to activate images you want visible</li>
</ul>
</div></td>
</tr>

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

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

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

<p><table border=0 cellpadding=3 cellspacing=3 bgcolor="#000000" width="640">
<tr valign=top>
<?php

$count = 1;
$query = "SELECT * FROM pics WHERE stageID = $stageID ORDER BY default_flag";
$result = mysql_query($query, $db);

if ($result)
{
  while ($r = mysql_fetch_array($result))
    {
      $picID = $r['ID'];
      $caption = $r['caption'];
      $courtesy_of = $r['courtesy_of'];
      $fullname = $r['fullname'];
      $default_flag = $r['default_flag'];
      $bgcolor = "#888888";

      if ($default_flag == "yes" ) { $bgcolor = "#ffffff"; }
      if ($picID == $ID) { $bgcolor = "#ff6666"; }
      
      echo '<td align=center width="33%"><div class=text>';
      echo "<table cellpadding=2 cellspacing=0 border=0 bgcolor=${bgcolor}>";
      echo "<tr><td align=center>";
      echo "<a target=_blank href=\"/tick/html/black.php?img=/tick/images/gallery/${fullname}\"><img src=\"/tick/images/gallery/t_${fullname}\" border=0></a></td></tr></table>";
      if ($caption != "") { echo "<br>$caption"; }
      if ($courtesy_of != "") { echo "<br><i>by $courtesy_of</i>"; }
      echo "<br><a href=\"javascript:popup('pics_remove.php?ID=${picID}', 'picture');\"><img src=\"images/x.gif\" border=0></a>&nbsp;";
      echo "[<a href=\"pics.php?ID=${picID}\">edit</a>]&nbsp;";

      if ($default_flag == "yes")
	{
	  echo "[<a href=\"pics_set_default.php?stageID=${stageID}&become=no&ID=${picID}\">deactivate</a>]";
	}
      else
	{
	  echo "[<a href=\"pics_set_default.php?stageID=${stageID}&become=yes&ID=${picID}\">activate</a>]";
	}

      echo "</div></td>";
      if ($count % 3 == 0) { echo "</tr><tr valign=top>"; }
      $count++;
    }
}

?>
</tr>
</table>

</body>

</html>
