<pre>
<?php

		/*	Read the cart	*/

		$scquery = "SELECT * FROM carts WHERE cartID='" . $cartID . "' ORDER BY productID";
		$scresult = mysql_query($scquery);
		$i = 1;
		$message = "RECEIPT\n---------------------------------------------------\n";
		while ($scrow = mysql_fetch_array($scresult)) {

			/* get product details from products	*/
			$pquery = "SELECT * FROM products WHERE publicID='" . $scrow['productID'] . "'";
			$presult = mysql_query($pquery);
			$prow = mysql_fetch_array($presult);

			/* Generating the e-mail text	*/

			$message .= $scrow['quantity'] . " " . $prow['name'] . " " . $prow['type'];

			if ($scrow['quantity'] > 1) {	$message .= "s";	}
			$message .= " (" . $scrow['nb'] . ")\n";


			/* how base!!!
			print "$scrow\n";
			print_r($scrow);
			print "\n\n$prow\n";
			print_r($prow);
			*/

			$subtotal = $prow['price'] * $scrow['quantity'];
			$total = $total + $subtotal;
			$i++;
			}

			/* some address error-checking.	*/

			if (($_POST['ship_name'] != "") &&
				($_POST['ship_address'] != "") &&
				 ($_POST['ship_email'] != "") &&
				  ($_POST['ship_name'] != "") &&
				   ($_POST['ship_state'] != "") &&
				    ($_POST['ship_city'] != "") &&
				     ($_POST['ship_ZIP'] != "")) {

					if ($_POST['ship_country'] == "USA") {
						$total = $total + 2;
						} elseif ($_POST['ship_country'] == "CANADA") {
						$total = $total + 4;
						}

				} elseif (($_POST['ship_name'] != "") &&
				 ($_POST['ship_email'] != "") &&
				  ($_POST['ship_address'] != "") &&
				   ($_POST['ship_country'] == "other")) {
					$total = $total + 8;
				} else {
					print "You did not fill out your address information! It's awfully important, I'm sure you can figure out why.";
					print "<br>Please return to the <a href=cart.php>shopping cart</a>! Thanks.";
					die;
				}


			$message .= "\n TOTAL: $" . $total;

			/* Presenting that old md5 hash for verification	*/

			$tracking = strtoupper(chunk_split($cartID, 4, " "));
			$message .= "\n\nTRACKING No. " . $tracking . "\n Please keep this number handy, it is your reference code for this order.";

			$message .= "\n\nShip to:\n\n";
			$message .= $_POST['ship_name'] . "\n" . 
			             $_POST['ship_address'] . "\n" .
			   			  $_POST['ship_city'] . "\n" .
						   $_POST['ship_state'] . "\n" .
						    $_POST['ship_ZIP'] . "\n" .
						     $_POST['ship_country'] . "\n";

			$message .= "\nOrder Method: ";

			if ($_POST['button'] == "Order with PayPal") {
				$message .= "PayPal";
				} elseif ($_POST['button'] == "Printable Check Form") {
				$message .= "Check is in the mail";
				}

			print $message . "\n\nPlease allow 1-2 weeks for delivery.";

			mail($_POST['ship_email'], "Your order from the Waletzky Shirt Store", $message,
									"From: " . $_POST['ship_email'] . "\r\n" .
     								"Reply-To: store@waletzky.com\r\n");

			mail("store@waletzky.com", "Your order from the Waletzky Shirt Store", $message,
									"From: " . $_POST['ship_email'] . "\r\n" .
     								"Reply-To: store@waletzky.com\r\n");

?>
</pre>
<?php if ($_POST['button'] == "Order with PayPal") {	?>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="amount" value="<?php echo $total; ?>">
<input type="hidden" name="item_number" value="<?php echo $tracking; ?>">
<input type="hidden" name="business" value="dj@waletzky.com">
<input type="hidden" name="currency_code" value="USD">
<input
	type="image"
	src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif"
	border="0"
	name="submit"
	alt="Use PayPal">
</form>
<?php } elseif ($_POST['button'] == "Printable Check Form") { ?>
<br><br><b>Print this form and enclose a check made out to "D. J. WALETZKY" (that's Waletzky with a "z.")</b><br>
Then mail this check to:<br><br>
44 Willoughby Street<br>
4th Floor<br>
Brooklyn, NY 11201<br>

<?php } ?>
