<?php
require "./Cart.php";

adminHeader('','');

if (!empty($BID))
     $wset[] = "o.BuyerID = '$BID'";

if (!empty($User))
     $wset[] = "b.Name LIKE '%$User%'";

if (!empty($Year) || !empty($Month) || !empty($Day))
     $wset[] = "o.Date LIKE '%$Year%-%$Month%-%$Day%'";

if (!empty($OrderNumber)) {
     unset($wset);
     $wset[] = "o.OrderNumber = '$OrderNumber'";
}

if (count($wset) > 0)
     $where = 'AND ' . implode(' AND ', $wset);

$sql =    "SELECT o.OrderNumber, o.Date, o.OrderTotal, o.OrderStatus, b.Name, o.PaymentCycle, o.bPayMethod, o.PaymentStatus " .
     "FROM Orders o, Buyers b " .
     "WHERE o.BuyerID = b.BuyerID $where " .
     "ORDER BY OrderNumber";
$result = mysql_query($sql);

blueFont("Arial","<B>Select the proper order to continue...</B><BR><BR>");
echo "<TABLE border=1>";
echo "<TR><TD>Ord#</td><td>Date</td><td>Buyer</td><td>Value</td><td>Payment Method</td><td>Payment Status</td><td>Status</td></tr>";
$i = 0;
while (list($onumber, $odate, $ototal, $ostatus, $bname, $opaymentcycle, $opaymentmethod, $opaymentstatus) = mysql_fetch_row($result)) {
     list($null,$null,$odate) = split(':',$odate);

     switch ($opaymentcycle) {
     case 'O': $PC = 'one time'; break;
     case 'W': $PC = 'weekly subscription'; break;
     case 'M': $PC = 'monthly subscription'; break;
     case 'Y': $PC = 'yearly subscription'; break;
     }

     $opaymentstatus = $opaymentstatus == 0 ? 'Not Paid' : 'Paid';

     fontFace("Arial","<TR><td>$onumber</td><td>$odate</td><td>$bname</td><td>$ototal ($PC)</td><td>$opaymentmethod</td><td>$opaymentstatus</td><td>$ostatus</td>");
     fontFace("Arial","<td><A href=$PHP_SELF?topic=receipt.php&ON=$onumber>View</a></td");
     fontFace("Arial","</TR>");
     $i++;
}
echo "</TABLE>";

if ($i == 0)
     blueFont("Arial","<B>No orders matched criteria</B><BR><BR>");

adminFooter($Relative);
?>
