<?php
// This is the script that shows the user a list of
// wines, and allows them to select wines to add to
// their shopping cart
include 'include.inc';
set_error_handler("errorHandler");
function showPanel($query, $connection)
{
// Run the query on the database through
// the connection
if (!($result = @ mysql_query ($query, $connection)))
showerror( );
echo "<table border=0>\n";
// Process the three new wines
while ($row = @ mysql_fetch_array($result))
{
// Begin a heading for the wine
echo "<tr>\n\t<td bgcolor=\"maroon\">" .
"<b><font color=\"white\">" .
$row["year"] . " " .
$row["winery_name"] . " " .
$row["wine_name"] . " ";
// Print the varieties for this wine
echo showVarieties($connection, $row["wine_id"]);
// Finish the first row heading
echo "</font></b></td>\n</tr>\n";
// Print the wine review
if (!empty($row["description"]))
echo "<tr>\n\t<td bgcolor=\"silver\">" .
"<b>Review: </b>" .
$row["description"];
"</td>\n</tr>\n";
// Print the pricing information
echo "<tr>\n\t<td bgcolor=\"gray\">";
// Print out the pricing information
showPricing($connection, $row["wine_id"]);
echo "</td>\n</tr>\n";
// Show the single-bottle add to cart link
echo "<tr>\n\t<td align=\"right\">" .
"<a href=\"example.cart.3.php?" .
"qty=1&wineId=" .
$row["wine_id"] .
"\">Add a bottle to the cart</a>";
// Show the dozen add to cart link
echo " " .
"<a href=\"example.cart.3.php?qty=12&wineId=" .
$row["wine_id"] . "\">Add a dozen</a></td>\n";
echo "</tr>\n";
// Blank row for presentation
echo "\n<tr>\n\t<td></td>\n</tr>\n";
}
echo "</table>\n";
}
// ---------
// Initialize a session. This call either creates
// a new session or re-establishes an existing one.
session_start( );
// Open a connection to the DBMS
if (!($connection = @ mysql_connect($hostName,
$username,
$password)))
showerror( );
if (!mysql_select_db($databaseName, $connection))
showerror( );
?>
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html401/loose.dtd">
<html>
<head>
<title>Hugh and Dave's Online Wines</title>
</head>
<body bgcolor="white">
<?php
// Show the user login status
showLogin( );
// Show the dollar and item total of the cart
showCart($connection);
?>
<h1>Here are some Hot New Wines!</h1>
<?php
// Display any messages to the user
showMessage( );
// Show the "Hot New Wines"
$query = "SELECT wi.winery_name,
w.year,
w.wine_name,
w.wine_id,
w.description
FROM wine w, winery wi, inventory i
WHERE w.winery_id = wi.winery_id
AND w.wine_id = i.wine_id
AND w.description IS NOT NULL
GROUP BY w.wine_id
ORDER BY i.date_added DESC LIMIT 3";
// Include our disclaimer
require 'disclaimer';
// Show the user the "Hot New Wines" panel
showPanel($query, $connection);
echo "<form action=\"example.cart.5.php\"" .
" method=\"GET\">\n";
echo "<table>\n<tr>\n";
// If the cart has contents, offer the opportunity
// to view the cart or empty the cart.
if (session_is_registered("order_no"))
{
echo "\t<td><input type=\"submit\" " .
"name=\"empty\" value=\"Empty Cart\"></td>\n";
echo "\t<td><input type=\"submit\" " .
"name=\"view\" value=\"View Cart\"></td>\n";
}
// Show the user the search screen button
echo "\t<td><input type=\"submit\" " .
"name=\"search\" value=\"Search\"></td>\n";
// Show the user either a login or logout button
loginButtons( );
echo "\n</tr>\n</table>\n";
echo "</form>\n";
?>
<br><a href="http://validator.w3.org/check/referer">
<img src="http://www.w3.org/Icons/valid-html401"
height="31" width="88"
align="right" border="0" alt="Valid HTML 4.01!"></a>
</body>
</html>