function show_HTML_receipt($cust_id, $connection, &$template) { // Retrieve the customer details $query = "SELECT * FROM customer WHERE cust_id = {$cust_id}"; $result = $connection->query($query); if (DB::isError($result)) { trigger_error($result->getMessage(), E_USER_ERROR); } $row = $result->fetchRow(DB_FETCHMODE_ASSOC); // Is there an optional phone field? If so, add it to the output if (!empty($row["phone"])) { $template->setCurrentBlock("phone"); $template->setVariable("PHONE", $row["phone"]); $template->parseCurrentBlock("address"); } // Now, add all the mandatory fields to the output $template->setCurrentBlock(); $template->setVariable("EMAIL", $_SESSION["loginUsername"]); $template->setVariable("FIRSTNAME", $row["firstname"]); $template->setVariable("SURNAME", $row["surname"]); $template->setVariable("INITIAL", $row["initial"]); $template->setVariable("ADDRESS", $row["address"]); $template->setVariable("CITY", $row["city"]); $template->setVariable("STATE", $row["state"]); $template->setVariable("ZIPCODE", $row["zipcode"]); $template->setVariable("DOB", $row["birth_date"]); $template->setVariable("CUSTTITLE", showTitle($row["title_id"], $connection)); $template->setVariable("COUNTRY", showCountry($row["country_id"], $connection)); }
function show_HTML_receipt($custID, $orderID, $connection) { $template = new winestoreTemplate(T_ORDERRECEIPT); // Find customer information $query = "SELECT * FROM customer, users\n WHERE customer.cust_id = {$custID}\n AND users.cust_id = customer.cust_id"; $result = $connection->query($query); if (DB::isError($result)) { trigger_error($result->getMessage(), E_USER_ERROR); } $row = $result->fetchRow(DB_FETCHMODE_ASSOC); // Now setup all the customer fields $template->setVariable("CUSTTITLE", showTitle($row["title_id"], $connection)); $template->setVariable("SURNAME", $row["surname"]); $template->setVariable("CUST_ID", $custID); $template->setVariable("ORDER_ID", $orderID); $template->setVariable("FIRSTNAME", $row["firstname"]); $template->setVariable("INITIAL", $row["initial"]); $template->setVariable("ADDRESS", $row["address"]); $template->setVariable("CITY", $row["city"]); $template->setVariable("STATE", $row["state"]); $template->setVariable("COUNTRY", showCountry($row["country_id"], $connection)); $template->setVariable("ZIPCODE", $row["zipcode"]); $orderTotalPrice = 0; // list the particulars of each item in the order $query = "SELECT i.qty, w.wine_name, i.price, \n w.wine_id, w.year, wi.winery_name\n FROM items i, wine w, winery wi\n WHERE i.cust_id = {$custID}\n AND i.order_id = {$orderID}\n AND i.wine_id = w.wine_id\n AND w.winery_id = wi.winery_id\n ORDER BY item_id"; $result = $connection->query($query); if (DB::isError($result)) { trigger_error($result->getMessage(), E_USER_ERROR); } // Add each item to the page while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) { // Work out the cost of this line item $itemsPrice = $row["qty"] * $row["price"]; $orderTotalPrice += $itemsPrice; $wineDetail = showWine($row["wine_id"], $connection); $template->setCurrentBlock("row"); $template->setVariable("QTY", $row["qty"]); $template->setVariable("WINE", $wineDetail); $template->setVariable("PRICE", sprintf("\$%4.2f", $row["price"]), 11); $template->setVariable("TOTAL", sprintf("\$%4.2f", $itemsPrice)); $template->parseCurrentBlock("row"); } $template->setCurrentBlock("items"); $template->setVariable("ORDER_TOTAL", sprintf("\$%4.2f\n", $orderTotalPrice)); $template->parseCurrentBlock("items"); $template->setCurrentBlock(); $template->showWinestore(NO_CART, B_HOME); }
function send_confirmation_email($custID, $orderID, $connection) { $template = new HTML_Template_ITX(D_TEMPLATES); $template->loadTemplatefile(T_EMAIL, true, true); // Find customer information $query = "SELECT * FROM customer, users\n WHERE customer.cust_id = {$custID}\n AND users.cust_id = customer.cust_id"; $result = $connection->query($query); if (DB::isError($result)) { trigger_error($result->getMessage(), E_USER_ERROR); } $row = $result->fetchRow(DB_FETCHMODE_ASSOC); // Start by setting up the "To:" email address $to = "{$row["firstname"]} {$row["surname"]} <{$row["user_name"]}>"; // Now setup all the customer fields $template->setVariable("TITLE", showTitle($row["title_id"], $connection)); $template->setVariable("SURNAME", $row["surname"]); $template->setVariable("CUST_ID", $custID); $template->setVariable("ORDER_ID", $orderID); $template->setVariable("FIRSTNAME", $row["firstname"]); $template->setVariable("INITIAL", $row["initial"]); $template->setVariable("ADDRESS", $row["address"]); $template->setVariable("CITY", $row["city"]); $template->setVariable("STATE", $row["state"]); $template->setVariable("COUNTRY", showCountry($row["country_id"], $connection)); $template->setVariable("ZIPCODE", $row["zipcode"]); $orderTotalPrice = 0; // list the particulars of each item in the order $query = "SELECT i.qty, w.wine_name, i.price, \n w.wine_id, w.year, wi.winery_name\n FROM items i, wine w, winery wi\n WHERE i.cust_id = {$custID}\n AND i.order_id = {$orderID}\n AND i.wine_id = w.wine_id\n AND w.winery_id = wi.winery_id\n ORDER BY item_id"; $result = $connection->query($query); if (DB::isError($result)) { trigger_error($result->getMessage(), E_USER_ERROR); } // Add each item to the email while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) { // Work out the cost of this line item $itemsPrice = $row["qty"] * $row["price"]; $orderTotalPrice += $itemsPrice; $wineDetail = showWine($row["wine_id"], $connection); $template->setCurrentBlock("row"); $template->setVariable("QTY", str_pad($row["qty"], 9)); $template->setVariable("WINE", str_pad(substr($wineDetail, 0, 53), 55)); $template->setVariable("PRICE", str_pad(sprintf("\$%4.2f", $row["price"]), 11)); $template->setVariable("TOTAL", str_pad(sprintf("\$%4.2f", $itemsPrice), 12)); $template->parseCurrentBlock("row"); } $template->setCurrentBlock("items"); $template->setVariable("ORDER_TOTAL", sprintf("\$%4.2f\n", $orderTotalPrice)); $template->parseCurrentBlock("items"); $template->setCurrentBlock(); $template->parseCurrentBlock(); $out = $template->get(); if (USE_PEAR == false) { // -------------------------------------------- // The internal PHP mail() function is used only if USE_PEAR is false // Now, setup the "Subject:" line $subject = "Hugh and Dave's Online Wines: Order Confirmation"; // And, last (before we build the email), set up some mail headers $headers = "From: Hugh and Dave's Online Wines " . "<*****@*****.**>\r\n"; $headers .= "X-Sender: <*****@*****.**>\r\n"; $headers .= "X-Mailer: PHP\r\n"; $headers .= "Return-Path: <*****@*****.**>\r\n"; // Send the email! mail($to, $subject, $out, $headers); // -------------------------------------------- } else { // -------------------------------------------- // Use the PEAR Mail package and SMTP since USE_PEAR is true // Now, setup the "Subject:" line $headers["Subject"] = "Hugh and Dave's Online Wines: Order Confirmation"; // And, last (before we build the email), set up some mail headers $headers["From"] = "Hugh and Dave's Online Wines " . "<*****@*****.**>"; $headers["X-Sender"] = "<*****@*****.**>"; $headers["X-Mailer"] = "PHP"; $headers["Return-Path"] = "<*****@*****.**>"; $smtpMail =& Mail::factory("smtp"); $smtpMail->send($to, $headers, $out); // -------------------------------------------- } }