示例#1
0
  return $num;
}

// ------------------------------------------------------- //

$dblogin = "******";
$dbpass  = "******";
$database = "ticketdb";

$num = $_POST['num'];
$Username = trim(strtoupper($_COOKIE['username']));

$action = $_POST['action'];
if ($action == "reserve")
{
  reserveTickets(generateReserveID($Username, $REMOTE_ADDR, $dblogin, $dbpass, $database), $num, $dblogin, $dbpass, $database);
}

if ($action == "unreserve")
{
  unreserveTickets($Username, $REMOTE_ADDR, $num, $dblogin, $dbpass, $database);
}

$numReserved = numReserved($Username, $REMOVE_ADDR, $dblogin, $dbpass, $database);

ECHO "<P><table width=250 align='center' border=1 cellpadding=0 cellspacing=0><tr><td align=center>You currently have <B>$numReserved</B> general admission tickets reserved.</td></tr></table><BR>";

ECHO "
         <P><form action='general.php' method='post'>
         <input type=hidden name=action value='reserve'>
         Number of Tickets to RESERVE: <input type=text name=num value='0'> <input type=submit name='Reserve' value='Reserve'>
function displayPremiumTicketSelection($title, $dblogin, $dbpass, $db, $ip)
{
  global $X_LEFT, $X_RIGHT, $Y_TOP, $Y_BOTTOM, $YEAR, $ACTIONPAGE;

  $ReserveID = trim(strtoupper($_COOKIE['ReserveID']));
  $Username = trim(strtoupper($_COOKIE['username']));

  if ($ReserveID == "" || ($ReserveID != $Username && $ReserveID != "IP:" . $ip))
  {
    $ReserveID = trim(strtoupper(generateReserveID($Username, $ip, $dblogin, $dbpass, $db)));
    setcookie("ReserveID", $ReserveID, time() + 86400);  // cookie valid for 1 day
    ECHO "ReserveID: .." . $ReserveID . "<BR>";
    ECHO "IP:" . $ip . "<BR>";
  }

  ECHO "<CENTER><B><h2>$title</h2></B></CENTER>";

  mysql_connect(localhost, $dblogin, $dbpass);
  @mysql_select_db($db) or die("Unable to select database.");

  // release all expired tickets!
  $c = time();
  $q = "SELECT * FROM tickets, ticketStatus WHERE tickets.TicketStatusID = ticketStatus.TicketStatusID and Available = 'N' and TempHold = 'Y' and HoldTimestamp < $c";
  $r = mysql_query($q) or die("Query failed:<BR>$q<BR>Error: " . mysql_error());
  for ($i = 0; $i < mysql_numrows($r); $i++)
  {
    $TicketID = mysql_result($r, $i, 'TicketID');
    $uq = "UPDATE tickets SET TicketStatusID = 2 Where TicketID = $TicketID";
    $ur = mysql_query($uq) or die("Query failed:<BR>$uq<BR>Error: " . mysql_error());
  }


  $keyquery = "SELECT DISTINCT tickets.TicketTypeID, ticketTypes.Color, ticketTypes.ColorNotForSale, ticketTypes.TicketTypeText FROM ticketTypes, tickets WHERE tickets.TicketTypeID = ticketTypes.TicketTypeID and tickets.X >= $X_LEFT and tickets.X <= $X_RIGHT and tickets.Y >= $Y_BOTTOM and tickets.Y <= $Y_TOP  and tickets.Year = $YEAR ORDER BY tickets.TicketTypeID ASC";
  $keyresult = mysql_query($keyquery) or die ("Query failed:<BR>$keyquery<BR>Error: " . mysql_error());

  ECHO "<CENTER><B>SEATING CHART KEY:</B></CENTER>";
  ECHO "<table width=440 border=1 cellpadding=0 cellspacing=0 align=center><tr><td>";
  ECHO "<table width=430 border=0 cellpadding=0 cellspacing=2 align=center>";
  for ($j = 0; $j < mysql_numrows($keyresult); $j++)
  {
    $Color = mysql_result($keyresult, $j, "Color");
    $ColorNotForSale = mysql_result($keyresult, $j, "ColorNotForSale");
    $Text = mysql_result($keyresult, $j, "TicketTypeText");
    if ($Color == $ColorNotForSale)
    {
      ECHO "
          <tr>
            <td width=15 bgcolor=$Color><font color=$Color size=1>.</font></td>
            <td width=200 align=left>$Text (Unavailable)</td>
            <td width=15><font color=#FFFFFF size=1>.</font></td>
            <td width=200 align=left><font color=#FFFFFF size=1>.</font></td>
            </tr>
            <tr><td></td><td></td></tr>
          ";
    }
    else
    {
      ECHO "
          <tr>
            <td width=15 bgcolor=$Color><font color=$Color size=1>.</font></td>
            <td width=200 align=left>Available $Text</td>
            <td width=15 bgcolor=$ColorNotForSale><font color=$ColorNotForSale 
                size=1>.</font></td>
            <td width=200 align=left>Unavailable $Text</td>
          </tr>
          <tr><td></td><td></td></tr>
          ";
    }
  }
  ECHO "</table>";
  ECHO "</td></tr></table>";

  ECHO "<font size=1>";
  ECHO "<form action=$ACTIONPAGE method=post>";
  ECHO "<input type=hidden name=action value=reserve>";
  ECHO "<input type=hidden name=ReserveID value=$ReserveID>";
  ECHO "<input type=hidden name=XLEFT value=$X_LEFT>";
  ECHO "<input type=hidden name=XRIGHT value=$X_RIGHT>";
  ECHO "<input type=hidden name=YTOP value=$Y_TOP>";
  ECHO "<input type=hidden name=YBOTTOM value=$Y_BOTTOM>";
  ECHO "<input type=hidden name=YEAR value=$YEAR>";
  ECHO "<input type=hidden name=TITLE value='$title'>";
  ECHO "<P><table border=0 cellpadding=0 cellspacing=0 bordercolor=#000000 align=center>";

//tickets.Row, tickets.Seat, tickets.TicketTypeID, tickets.TicketID, tickets.X, tickets.Y, ticketTypes.Color, tickets.Year, ticketStatus.Available, ticketStatus.Hold FROM tickets, ticketTypes, ticketStatus

  $query = "SELECT * FROM tickets, ticketTypes, ticketStatus WHERE tickets.TicketStatusID = ticketStatus.TicketStatusID and tickets.TicketTypeID = ticketTypes.ticketTypeID and tickets.X >= $X_LEFT and tickets.X <= $X_RIGHT and tickets.Y >= $Y_BOTTOM and tickets.Y <= $Y_TOP and tickets.Year = $YEAR ORDER BY Y DESC, X ASC";

  $result = mysql_query($query) or die("Query failed:<BR>$query<BR>Error: " . mysql_error());


  for ($i = 0; $i < mysql_numrows($result); $i++)
  {
    $X = mysql_result($result, $i, "X");
    $Y = mysql_result($result, $i, "Y");
    $Color = mysql_result($result, $i, "Color");
    $ColorNotForSale = mysql_result($result, $i, "ColorNotForSale");
    $TicketID = mysql_result($result, $i, "TicketID");
    $TicketTypeID = mysql_result($result, $i, "TicketTypeID");
    $Available = mysql_result($result, $i, "Available");
    $TempHold = mysql_result($result, $i, "TempHold");
    $TicketStatusID = mysql_result($result, $i, "TicketStatusID");
    $HoldID = mysql_result($result, $i, "HoldID");
    $HoldTimestamp = mysql_result($result, $i, "HoldTimestamp");

    if ($X == $X_LEFT)
    {
      beginRow();
      $Row = mysql_result($result, $i, "Row");
      ECHO "<td>$Row</td>";
    }
    
    // release ticket?
    if ($TempHold == 'Y' && $HoldTimestamp < time())
    {
      $updateTicketQuery = "UPDATE tickets SET TicketStatusID = 2 WHERE TicketID = $TicketID";
      $updateTicketResult = mysql_query($updateTicketQuery) or die("Query failed:<BR>$updateTicketQuery<BR>Error: " . mysql_error());
      $Available = 'Y';
    }

    // display ticket
    if ($Available == 'N' && ($HoldID == $Username || $HoldID == "IP:" . $ip))
    {
      putCell($ColorNotForSale, $TicketID, "checked", "");
    }
    elseif ($Available == 'N')
    {
      putBlankCell($ColorNotForSale);
    }
    else
    {
      putCell($Color, $TicketID, "", "");
    }

    if ($X == $X_RIGHT)
    {
      endRow();
    }

  }

  beginRow();
  ECHO "<td></td>"; // row labels
  for ($i = $X_LEFT; $i <= $X_RIGHT; $i++)
  {
    if ($i == -50 || $i == -26 || $i == 0 || $i == 22 || 
        $i == 44 || $i == 66 || $i == 92 || $i == 115)
    {
      ECHO "<td></td>";
    }
    elseif ($i >= -49 && $i <= -27)
    {
      $seatnum = $i + 50;
      ECHO "<td align=center>$seatnum</td>";
    }
    elseif ($i >= -25 && $i <= -1)
    {
      $seatnum = $i + 26;
      ECHO "<td align=center>$seatnum</td>";
    }
    elseif ($i >= 1 && $i <= 21)
    {
      $seatnum = $i;
      ECHO "<td align=center>$seatnum</td>";
    }
    elseif ($i >= 23 && $i <= 43)
    {
      $seatnum = $i - 22;
      ECHO "<td align=center>$seatnum</td>";
    }
    elseif ($i >= 45 && $i <= 65)
    {
      $seatnum = $i - 44;
      ECHO "<td align=center>$seatnum</td>";
    }
    elseif ($i >= 67 && $i <= 91)
    {
      $seatnum = $i - 66;
      ECHO "<td align=center>$seatnum</td>";
    }
    elseif ($i >= 93 && $i <= 114)
    {
      $seatnum = $i - 92;
      ECHO "<td align=center>$seatnum</td>";
    }
    else
    {
      ECHO "<td align=center>X</td>";
    }
  }
  endRow();

  mysql_close();

  ECHO "</table>";

  ECHO "<p align=center><input type=submit value='Reserve Selected Tickets' name='ReserveSelectedTicketsButton'> <input type=submit value='View Cart / Checkout' name='Checkout'> <input type=submit value='Continue Shopping' name='ContinueShopping'></p>";
  ECHO "</form>";
  ECHO "</font>";

}