예제 #1
0
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);
}
예제 #2
0
function displayCart($connection, &$template)
{
    // If the user has added items to their cart, then
    // the variable order_no will be registered
    if (isset($_SESSION["order_no"])) {
        // Set the action of the <form>
        $template->setVariable("S_UPDATECART", S_UPDATECART);
        // Find the items in the cart
        $cartQuery = "SELECT qty, price, wine_id, item_id \n                    FROM items WHERE cust_id = -1\n                    AND order_id = {$_SESSION["order_no"]}";
        $result = $connection->query($cartQuery);
        if (DB::isError($result)) {
            trigger_error($result->getMessage(), E_USER_ERROR);
        }
        $cartAmount = 0;
        $cartCount = 0;
        // Go through each of the wines in the cart
        while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
            // Keep a running total of the number of items
            // and dollar-value of the items in the cart
            $cartCount += $row["qty"];
            $lineTotal = $row["price"] * $row["qty"];
            $cartAmount += $lineTotal;
            $template->setCurrentBlock("item");
            $template->setVariable("QUANTITY_NAME", $row["item_id"]);
            $template->setVariable("QUANTITY_VALUE", $row["qty"]);
            $template->setVariable("WINE", showWine($row["wine_id"], $connection));
            $template->setVariable("ITEM_PRICE", sprintf("%-.2f", $row["price"]));
            $template->setVariable("TOTAL_VALUE", sprintf("%-.2f", $lineTotal));
            $template->parseCurrentBlock("item");
        }
        $template->setCurrentBlock("cart");
        $template->setVariable("TOTAL_ITEMS", $cartCount);
        $template->setVariable("TOTAL_COST", sprintf("%-.2f", $cartAmount));
        $template->parseCurrentBlock("cart");
    } else {
        // The user has not put anything in the cart
        $template->setCurrentBlock("emptycart");
        $template->setVariable("TEXT", "Your cart is empty");
        $template->parseCurrentBlock("emptycart");
    }
}
예제 #3
0
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);
        // --------------------------------------------
    }
}
예제 #4
0
    $stockResult = $connection->query($query);
    if (DB::isError($stockResult)) {
        trigger_error($stockResult->getMessage(), E_USER_ERROR);
    }
    $on_hand = $stockResult->fetchRow(DB_FETCHMODE_ASSOC);
    if ($on_hand["COUNT(on_hand)"] == 0) {
        $available = 0;
    } else {
        $available = $on_hand["SUM(on_hand)"];
    }
    // Is there more wine in the cart than is for sale?
    if ($cartRow[$winesInCart]["qty"] > $available) {
        if ($available == 0) {
            $_SESSION["message"] = "Sorry! We just sold out of " . showWine($cartRow[$winesInCart]["wine_id"], NULL) . "\n<br>";
        } else {
            $_SESSION["message"] .= "Sorry! We only have {$on_hand["SUM(on_hand)"]}  \n                     bottles left of " . showWine($cartRow[$winesInCart]["wine_id"], NULL) . "\n<br>";
        }
        // Update the user's quantity to match the available amount
        $query = "UPDATE items\n                SET qty = {$available}\n                WHERE cust_id = -1\n                AND order_id = {$_SESSION["order_no"]}\n                AND item_id = {$cartRow[$winesInCart]["item_id"]}";
        $result = $connection->query($query);
        if (DB::isError($result)) {
            trigger_error($result->getMessage(), E_USER_ERROR);
        }
    }
}
// for $winesInCart < $result->numRows()
// We have now checked if there is enough wine available.
// If there is, we can proceed with the order. If not, we
// send the user back to the amended cart to consider whether
// to proceed with the order.
if (empty($_SESSION["message"])) {