<?php
/**
* products.php
* Artzy page to show products
*
* @author Ed Parrish
* @version 1.1 05/09/08
*/
ob_start();
require("includes/db.php");

main("Artzy Products");

// Control the operation of a page
function main($title = "") {
    include("includes/header.php");
    showContent($title);
    include("includes/footer.php");
}

// Display the content of a page
function showContent($title) {
    $db = new DB();
    $sql = "
        SELECT ID, ProductName, ProductDescription, Path2Image, Price
        FROM products
        ";
    $result = $db->query($sql);
    echo "<h1>$title</h1>\n";
    echo "<table width=\"100%\">\n";
    showCartLink();
    showHeading();
    while ($row = mysql_fetch_row($result)) {
        list($id, $prodName, $description, $imagePath, $price) = $row;
        $price = "$".number_format($price, 2);
        showItem($id, $prodName, $description, $imagePath, $price);
    }
    showCartLink();
    echo "</table>\n";
}

// Display the table heading
function showHeading() {
    echo <<<HTML
<tr>
  <td bgcolor="blue">
    <font face="verdana" size="2" color="white">
      &nbsp;<b>Image</b>&nbsp;
    </font>
  </td>
  <td bgcolor="blue">
    <font face="verdana" size="2" color="white">
      &nbsp;<b>Product</b>
    </font>
  </td>
  <td bgcolor="blue">
    <font face="verdana" size="2" color="white">&nbsp;<b>Price</b>&nbsp;</font>
  </td>
  <td bgcolor="blue">
    <font face="verdana" size="2" color="white">&nbsp;<b>Description</b></font>
  </td>
  <td bgcolor="blue" width="150">
    <font face="verdana" size="2" color="white">&nbsp;<b>Buy</b></font>
  </td>
</tr>

HTML;
}

// Display each table item
function showItem($id, $prodName, $description, $imagePath, $price) {
    echo <<<HTML
<tr>
  <td>
    <img src="images/$imagePath" width=50 align="top">
  </td>
  <td>
    <font face="verdana" size="2" color="black">$prodName</font>
  </td>
  <td>
      <font face="verdana" size="2" color="black">$price</font>
  </td>
  <td width="50%" height="25">
      <font face="verdana" size="2" color="black">$description</font>
  </td>
  <td>
      <font face="verdana" size="2" color="black">
          <a href="cart.php?add=$id&qty=1">Add Item</a>
      </font>
  </td>
</tr>
<tr>
  <td width="100%" colspan="5">
    <hr size="1" color="red" noshade>
  </td>
</tr>

HTML;
}

// Display a link to the shopping cart as a table item
function showCartLink() {
    echo <<<HTML
<tr>
  <td colspan="5">
    <font face="verdana" size="2" color="black">
      <a href="cart.php">View Shopping Cart &gt;&gt;</a>
    </font>
  </td>
</tr>

HTML;
}

?>