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

if (!empty($approved)) {
     $ON = $approved;
     mysql_query("UPDATE Orders SET OrderStatus = 'approved' WHERE OrderNumber = $ON");
}
if (!empty($denied)) {
     $ON = $denied;
     mysql_query("UPDATE Orders SET OrderStatus = 'denied' WHERE OrderNumber = $ON");
}
if (!empty($paid)) {
     $ON = $paid;
     mysql_query("UPDATE Orders SET PaymentStatus = 1 WHERE OrderNumber = $ON");
}

$order = mysql_query("SELECT * FROM Orders WHERE OrderNumber = $ON");
list(     $BuyerID, $UserID, $Date, $OrderTotal, $OrderNumber, $OrderStatus,
     $bName, $bAddress1, $bAddress2, $bCity, $bState, $bZip, $bDayPhone, $bEvePhone,
     $Contact, $PayMethod, $CCType, $CCNum, $CCExpire, $OrderOptions, $PaymentCycle, $PaymentStatus
) = mysql_fetch_row($order);
mysql_free_result($order);
$BNa=$bName;
$BA1=$bAddress1;
$BA2=$bAddress2;
$BCi=$bCity;
$BSt=$bState;
$BZi=$bZip;
$BDP=$bDayPhone;
$BEP=$bEvePhone;
$BCo=$Contact;
$BPM=$PayMethod;
$BCT=$CCType;
$BCN=$CCNum;
$BCE=$CCExpire;
$pStatus = $PaymentStatus == 0 ? 'Not Paid' : 'Paid';

adminHeader("$Company","Your receipt - Thank You!");

blueFont("Arial","<b>Order Number: </b>");
redFont ("Arial","$OrderNumber");

blueFont("Arial","<br><b>Order Status: </b>");
redFont ("Arial","$OrderStatus &nbsp; &nbsp; ");

if ($OrderStatus == 'processing') {
     redFont ("Arial","<a href=$PHP_SELF?topic=process.php&approved=$ON> Approve </a>");
     echo ' &nbsp; &nbsp; | &nbsp; &nbsp; ';
     redFont ("Arial","<a href=$PHP_SELF?topic=process.php&denied=$ON> Deny </a>");
} else {
     redFont ("Arial","<a href=$PHP_SELF?topic=process.php&deleted=$ON> Delete </a>");
}
blueFont("Arial","<br><b>Payment Method: </b>");
redFont ("Arial","$PayMethod");

blueFont("Arial","<br><b>Payment Status: </b>");
redFont ("Arial","$pStatus");
if ($PaymentStatus == 0) {
     redFont ("Arial","<a href=$PHP_SELF?topic=receipt.php&paid=$ON> Mark as Paid </a>");
}

echo '<br><br>';

echo "<table border='0' cellpadding='5' cellspacing='5' width='550'><tr>";
echo "<td valign='top' align='right'>";
if ($PayMethod == "Check") {
fontFace("Arial","<b>Make check payable to:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><br>");
} else {
echo "";
}
fontFace("Comic Sans MS,Arial","$Company<br>");
if ($PayMethod == "Check") {
fontFace("Arial","<b>Send check to:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b><br>");
} else {
echo "";
}
fontFace("Arial","$Address1<br>$Address2<br>");
fontFace("Arial","$City $State, $Zip<br>");
if ($Phone == "" ) {
echo "";
} else {
fontFace("Arial","<b>Phone:</b> $Phone<br>");
}
if ($Web == "" ) {
echo "";
} else {
fontFace("Arial","<b>World Wide Web:</b> $Web<br>");
}
if ($Email == "" ) {
echo "";
} else {
fontFace("Arial","<b>E-mail:</b> $Email<br>");
}

$ODa=$Date;

$pieces=explode(":",$ODa);

fontFace("Arial","<b>Order Date:</b> $pieces[2]");
echo "</td></tr><tr><td valign='top' align='left'>";

fontSize("+2","","Arial","Order For:<br>");
fontFace("Arial","$BNa<br>");
fontFace("Arial","<b>Address:</b> $BA1<br>");
if ($BA2 != "") {
fontFace("Courier","&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ");
fontFace("Arial"," $BA2<br>");
}
fontFace("Courier","&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ");
fontFace("Arial"," $BCi $BSt, $BZi<br>");
if ($BDP != "") {
fontFace("Arial"," $BDP<br>");
}
if ($BEP != "") {
fontFace("Arial"," $BEP<br>");
}
if ($BEm != "") {
fontFace("Arial"," $BEm<br>");
}
echo "</td></tr></table>";
blueFont("Arial","<b>You have ordered the following items...</b><br><br>");

echo  "<table border='1' cellpadding='5' cellspacing='5'><tr>";
echo  "<th>";
redFont( "Arial", "Product Code");
echo  "</th>";
echo  "<th>";
redFont( "Arial", "Product Name");
echo  "</th>";
echo  "<th>";
redFont( "Arial", "Product Options");
echo  "</th>";
echo  "<th>";
redFont( "Arial", "Quantity");
echo  "</th>";
echo  "<th>";
redFont( "Arial", "Cost");
echo  "</th>";
echo  "<th>";
redFont( "Arial", "Shipping");
echo  "</th>";
echo  "<th>";
redFont( "Arial", "Total");
echo  "</th>";
echo  "</th></tr>";

$result=mysql_query("SELECT * FROM Receipts WHERE OrderNumber='$OrderNumber'");
while ($row=mysql_fetch_row($result)) {
$RBI=$row[0];
$RUI=$row[1];
$RON=$row[2];
$RDa=$row[3];
$RII=$row[4];
$RIS=$row[5];
$RIN=$row[6];
$RIC=$row[7];
$RSC=$row[8];
$RIQ=$row[9];
$RTC=$row[10];
$ITO=nl2br($row[11]).'&nbsp;';
$IPC=$row[12];

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

$total=$total+$RTC;
echo "<tr><td>";
blueFont("Arial","$RIS");
echo "</td><td>";
blueFont("Arial","$RIN");
echo "</td><td>";
blueFont("Arial","$ITO");
echo "</td><td>";
blueFont("Arial","$RIQ");
echo "</td><td>";
$RIC=number_format($RIC,"2",".","thousands_sep");
blueFont("Arial","$$RIC ($PC)");
echo "</td><td>";
$RSC=number_format($RSC,"2",".","thousands_sep");
if ($RSC == "0.00") {
$ES = "1";
fontSize("-1","blue","Arial","$NoShipping");
} else {
blueFont("Arial","$$RSC"); }
echo "</td><td>";
$NRTC=number_format($RTC,"2",".","thousands_sep");
if ($RSC == "0.00") {
blueFont("Arial","$$NRTC");
fontSize("-1","blue","Arial"," Plus Shipping");
} else {
blueFont("Arial","$$NRTC"); }
echo "</td></tr>";
}

$Tot=number_format($total,"2",".","thousands_sep");
echo "<tr><td colspan=\"4\"></td><td>";
redFont("Arial","<b><i>Total:</i></b>");
echo "</td><td>";
if ($ES == "1") {
blueFont("Arial","<b>$$Tot</b>");
fontSize("-1","blue","Arial"," Plus Shipping");
} else {
blueFont("Arial","<b>$$Tot</b>"); }
echo "</td></tr>";

echo "</table>";

if (!empty($OrderOptions)) {
     blueFont("Arial","<br><br><b>Order Options</b><br>");
     echo nl2br($OrderOptions);
}

if ($PM == "Check") {
blueFont("Arial","<p>You have elected to pay via ");
redFont ("Arial","Check or Money Order");
blueFont("Arial",".<br>We will ship the products you ordered upon receipt of your payment.<br>");
} elseif ($PM == "Credit") {
blueFont("Arial","<p>You have elected to pay via ");
redFont ("Arial","$CT");
blueFont("Arial"," credit card.<br>We will ship the products you ordered upon credit approval.<br>");
} else {
blueFont ("Arial","<p>We will contact you to make payment arrangements.<br>");
}

if ($Contact == '1') {
blueFont("Arial","<p>We will contact you before fulfilling this order.<br>");
} else {
echo "";
}

echo "<br><br>";
redFont("Arial","If you have questions about this order, please contact us at:<br>");
blueFont("Arial","<a href=\"mailto:$Email\">$Email</a><br>");
redFont("Arial","or<br>");
blueFont("Arial","$Phone<br><br> <b>Please refer to order number</b>");
redfont("Arial"," $OrderNumber");

blueFont("Arial","<p><b>If you need acces to this document again, you can point your web browser to:</b><br>");
fontSize("-1","Red","Arial","<a href=\"http://$SERVER_NAME$PHP_SELF?topic=receipt.php&ON=$OrderNumber\">http://$SERVER_NAME$PHP_SELF?topic=receipt.php&ON=$OrderNumber</a>");

adminFooter($Relative);
?>
