window.location=\"index.php\";"; } //function to display the invoice function ShowInvoice() { //header wrapper include("wrapper_head2.php"); //call global variables global $host, $username, $password, $database, $cookie; //retrieve client information $name = $_POST['name']; $company =$_POST['company']; $email =$_POST['email']; $dayphone =$_POST['dayphone']; $ext =$_POST['ext']; $nitephone =$_POST['nitephone']; $fax =$_POST['fax']; $address =$_POST['address']; $city =$_POST['city']; $state =$_POST['state']; $country =$_POST['country']; $zipcode =$_POST['zipcode']; $arrangement =$_POST['arrangement']; //check required fields. $injection_attack = 0; reset($_POST); foreach($_POST as $key => $value){ if(eregi("\r",$value) || eregi("\n",$value)) $injection_attack = 1; } //echo ""; if ($injection_attack || ($name=="" || $dayphone=="" || $address=="" || $city=="" || $state=="" || $country=="" || $zipcode=="" || strstr($email, '@')==FALSE || strstr($email, '.')==FALSE)) { echo " Error: Your order did not contain a required piece of information, or there was a problem veryfing your specified email address. Please click here to go back and review the form."; } //if required info is present, continue script.. else { //Set recipient variable { $recipient="chris@tte.ca"; } //generate contact info for invoice variable $invoice .= "
Customer Information
Name: $name
"; if ($company != "") { $invoice .= "Company: $company
"; } $invoice .= " Email: $email

Address Information:
$address
$city,$state
$country
$zipcode
"; if ($ext != "") { $invoice .= "Daytime Phone: $dayphone "; $invoice .= "Ext: $ext
"; } else { $invoice .= "Daytime Phone: $dayphone
"; } if ($nitephone != "") { $invoice .= "Evening Phone: $nitephone
"; } if ($fax != "") { $invoice .= "Fax Number: $fax
"; } $invoice .= "
Ordering Options
Delivery Arrangements: $arrangement


"; //generate contact info for order log variable $orderName .= "$name"; if ($company != "") {$orderName .= ", $company";} $orderPhone .= "$dayphone"; if ($ext != "") {$orderPhone .= " Ext: $ext";} if ($nitephone != "") {$orderPhone .= ", $nitephone";} if ($fax != "") {$orderPhone .= ", Fax: $fax";} $orderAddress .= "$address, $city, $state, $country, $zipcode"; $orderPrefs .= "$arrangement"; //create product table for the invoice variable $invoice .= " "; //connect to the database mysql_connect($host,$username,$password); @mysql_select_db($database) or die("ERROR: Could not open database."); //retrieve ordered items $result=mysql_query("SELECT * from cart INNER JOIN inventory ON cart.itemId=inventory.part WHERE cookieId= '$cookie'"); //$cartresult=mysql_query($query); //$num=mysql_numrows($cartresult); //subtotal variable $subtotal="0"; //main loop to generate product list //$i=0; while ($row=mysql_fetch_assoc($result)) { /* $part=mysql_result($cartresult,$i,"name"); $itemId=mysql_result($cartresult,$i,"itemId"); $qty=mysql_result($cartresult,$i,"qty"); $price=mysql_result($cartresult, $i, "price"); $saleprice=mysql_result($cartresult, $i, "saleprice"); $onsale=mysql_result($cartresult, $i, "onsale"); */ if ($row["cartwar"] == $row["stdwar"]) { if ($row["onsale"] == "yes") $total=($row["saleprice"]*$row["qty"]); else $total=($row["price"]*$row["qty"]); } else { if ($row["onsale"] == "yes") $total=(($row["saleprice"]+30)*$row["qty"]); else $total=(($row["price"]+30)*$row["qty"]); } //add product to the invoice variable if (current($row) % 2 == 0) $invoice .= ""; else $invoice .= ""; $invoice .= " "; if ($row["cartwar"] == $row["stdwar"]) { if ($row["onsale"] == "yes") $invoice .= ""; else $invoice .= ""; } else { if ($row["onsale"] == "yes") $invoice .= ""; else $invoice .= ""; } $invoice.= " "; //add product to the order log variable if ($row["onsale"] == "yes") $log .= $row["qty"] ." x ". $row["itemId"] ." @ $".$row["saleprice"] ."(ON SALE)"; else $log .= $row["qty"] ." x ". $row["itemId"] ." @ $".$row["price"]; $subtotal += $total; //$i++; } //generate invoice subtotal information $invoice .= "
Part Number Item Price Quantity Total
".$row["itemId"]."
".$row["name"]."
Warranty: ".$row["cartwar"]."
$".$row["saleprice"]."
$".$row["price"]."
$".$row["saleprice"]."
+ $30.00
$".$row["price"]."
+ $30.00
".$row["qty"]."
$$total
Subtotal*:
$$subtotal
*Please note, once again, that the subtotal above does not include taxes or shipping. These charges will be discussed once we have validated your order.
"; //open page content table echo "
"; //tell the user the order went through echo "
Order Summary

Your order has been successfully sent. Our staff will contact you for confirmation as soon as they receive this form.
In the mean time, here is your order summary. While this is not your final reciept, you may still want to print a copy for your records.


"; //email invoice mail($recipient, "New Website Order", $invoice, "From: \"tte.ca Ordering System\" <$email>\nContent-Type: text/html"); //display invoice echo "$invoice"; //dispay a cart resetting button echo "

Finish Up!

You're done! When ready, click the button below to reset your shopping cart and return to the main page.

"; //close page content table echo"
"; //create the log entry for the order mysql_query("INSERT INTO orders (orderCart, orderTotal, orderName, orderEmail, orderPhone, orderAddress, orderPrefs, orderTime) VALUES ('$log', '$$subtotal', '$orderName', '$email', '$orderPhone', '$orderAddress', '$orderPrefs', NOW())"); } //footer wrapper include("wrapper_tail2.php"); } ?>