print "<h1>Trade Entry Data Error</h1>\n                 \t<h3>There was an error in the submission of your trading data.</h3>\n                         Please ensure that you have submitted this data using the <a href=tradeentry.php>Trade Entry form</a>.";
     include "footer.php";
     exit;
 }
 if (!mysql_query("DELETE FROM transidlookup WHERE TransactionID = '{$TransactionID}'")) {
     mail($admin_email, "LETS DATABASE ERROR", "The LETS System was unable to delete Transaction {$TransactionID} from the transidlookup table.\n\nThe error reported was:\n\n" . mysql_error() . "\n\nThis message is generated automatically");
 }
 /* clean up the description */
 $Description = stripslashes($Description);
 /* Submit the transaction for the seller account */
 SubmitTrade($TransactionID, $SellerID, $Amount, $Description, $BuyerID);
 /* Submit the transaction for the buyer account */
 SubmitTrade($TransactionID, $BuyerID, -$Amount, $Description, $SellerID);
 /* Process the transaction fees */
 ProcessFee($TransactionID, $SellerID, $Amount, 'sell');
 ProcessFee($TransactionID, $BuyerID, $Amount, 'buy');
 /* Print a receipt */
 if ($EnteredBy == 'seller') {
     $AccountID = $SellerID;
 } else {
     $AccountID = $BuyerID;
 }
 $title = "Transaction Recorded";
 include "header.php";
 print "<h1>Transaction Recorded</h1>\n         \t<h3>This page is your record of transaction for this trade.</h3>\n                Please print this page if you wish to keep a copy for your records.<p>\n                <table noborder>\n                <tr><th align=center bgcolor=#D3D3D3 colspan=2>Transaction Record</th></tr>\n                <tr><th align=left>Transaction Number: </th><td>{$TransactionID}</td></tr>\n                <tr><th align=left>Member:</th><td>{$MemberID}: {$MemberFirstName}</td></tr>\n                <tr><th align=left>Credited to Account: </th><td>{$SellerID}</td></tr>\n                <tr><th align=left>Debited to Account: </th><td>{$BuyerID}</td></tr>\n                <tr><th align=left>Trade Amount: </th><td>{$Amount}</td></tr>\n                <tr><th align=left>Description: </th><td>{$Description}</td></tr>\n                <tr><th align=left valign=top>Service Fees: </td><td><table noborder>";
 if (!empty($SellerFee)) {
     print "<tr><td>To Seller: {$SellerFee}</td></tr>";
 }
 if (!empty($BuyerFee)) {
     print "<tr><td>To Buyer: {$BuyerFee}</td></tr>";
 }
    case 1:
        $title = 'Unable to Process';
        include "header.php";
        print "<h2>Account Balance Too High</h2>\n\t\tYour account, number {$ToAccount}, has a balance that exceeds the permitted maximum.  You cannot enter this cheque until your balance returns to within acceptable limits.";
        include "footer.php";
        exit;
        break;
    case 2:
        $SellerOver = "<strong>WARNING:</strong>";
        break;
    default:
}
// seems all is good.  Now we can record the trade.
include "recordtrade.php";
// get a transaction ID
$transIDtime = time();
mysql_query("INSERT INTO transidlookup\n\t\t VALUES ('','{$transIDtime}','{$MemberID}')");
$transIDlookup = mysql_query("SELECT TransactionID FROM transidlookup\n\t\t\t      WHERE Time = {$transIDtime}\n\t\t\t      AND MemberID = {$MemberID}");
$TransactionID = mysql_result($transIDlookup, 0, 'TransactionID');
// update the Cheque table to show Transaction ID
mysql_query("UPDATE cheques\n\t\tSET TransactionID = {$TransactionID}\n\t\tWHERE ChequeID = {$ChequeID}");
// enter the transaction
SubmitTrade($TransactionID, $Cheque["AccountID"], -$Amount, "Cheque {$ChequeID}: {$Memo}", $ToAccount);
SubmitTrade($TransactionID, $ToAccount, $Amount, "Cheque {$ChequeID}: {$Memo}", $Cheque["AccountID"]);
ProcessFee($TransactionID, $ToAccount, $Amount, 'sell');
ProcessFee($TransactionID, $Cheque["AccountID"], $Amount, 'buy');
$title = 'Cheque Registered';
include 'header.php';
print "<h2>Cheque Registered</h2>\n\tCheque {$ChequeID} has been registered, and the amount of {$Amount} Ecos has been transferred to Account {$ToAccount}.<p>\n\tTo have this transaction reversed, contact the <a href=mailto:{$SystemEmail}>system administrator</a><p>\n\t<hr><p>\n\t<strong>To register another cheque complete the form below:</strong><p>\n";
PrintForm('', '', '', '');
include 'footer.php';
             if (WasWarned($BuyerID["{$trade}"], $SellerID["{$trade}"], 'Over Limit')) {
                 $Result["{$trade}"] = "Not Processed.  <em>Seller Account is over limit and Buyer has received a previous warning</em>";
             }
         } else {
             /* Get a transactionID */
             $transidtime = time();
             if (!mysql_query("INSERT INTO transidlookup\n                                                  VALUES('','{$transidtime}','{$MemberID}')")) {
                 $Result["{$trade}"] = "Not Processed. <em>The database was unable to lookup a transaction ID</em>.";
             } else {
                 $lookuptransid = mysql_query("SELECT TransactionID\n                                                            FROM transidlookup\n                                                             WHERE Time = '{$transidtime}'\n                                                              AND MemberID = '{$MemberID}'");
                 $TransactionID = mysql_result($lookuptransid, 0, "TransactionID");
                 /* Submit the transactions */
                 SubmitTrade($TransactionID, $SellerID["{$trade}"], $Amount["{$trade}"], $Description["{$trade}"], $BuyerID["{$trade}"]);
                 SubmitTrade($TransactionID, $BuyerID["{$trade}"], -$Amount["{$trade}"], $Description["{$trade}"], $SellerID["{$trade}"]);
                 ProcessFee($TransactionID, $SellerID["{$trade}"], $Amount["{$trade}"], 'sell');
                 ProcessFee($TransactionID, $BuyerID["{$trade}"], $Amount["{$trade}"], 'buy');
                 /* And set the result variable */
                 $Result["{$trade}"] = "Processed.  Transaction ID #{$TransactionID}.";
                 /* Delete the transidlookup record and log the trade in the AdminActions Log */
                 mysql_query("DELETE FROM transidlookup\n                                                      WHERE TransactionID = '{$TransactionID}'");
                 mysql_query("INSERT INTO adminactions\n                                                      VALUES(NULL,'{$MemberID}','Registered Transaction {$TransactionID}')");
                 unset($TransactionID);
             }
         }
     }
 }
 /* Print a results table */
 $title = "Administration Trade Entry Results";
 include "header.php";
 print "<table width=100% noborder>\n                <tr><th colspan=5 bgcolor=#D3D3D3>Trade Entry Results</th></tr>\n                <tr><th>Trade</th><th>Seller</th><th>Buyer</th><th>Amount</th><th>Result</th></tr>\n";
 for ($trade = 0; $trade < 10; $trade++) {