Пример #1
0
function retrieveOrder($resultT, $db)
{
    $row = $resultT->FetchRow();
    $name = $row['name'];
    $customerId = $row['customerId'];
    $phone = htmlentities($_GET['phone'], ENT_QUOTES);
    //BRIDGE TABLE
    $query1 = "select * from customerToOrder where customerId ='{$customerId}'";
    $result1 = $db->Execute($query1);
    if (!$result1) {
        printError();
        return;
    }
    //PIZZA ORDER TABLE
    $row1 = $result1->FetchRow();
    $orderId = $row1['orderId'];
    $query2 = "select * from pizzaOrder where orderId ='{$orderId}'";
    $result2 = $db->Execute($query2);
    if (!$result2) {
        printError();
        return;
    }
    $row2 = $result2->FetchRow();
    $toppings = $row2['toppingId'];
    $size = $row2['sizeId'];
    showOrderForm($phone, $name, $toppings, $size);
}
function main($OID)
{
    global $repeatTimes;
    if (!array_key_exists("orderForm", $_GET)) {
        $data = takeOrderFromDataBase($OID);
        showOrderForm($data, "");
    } else {
        $badFields = orderValidate($_GET);
        if (count($badFields) != 0) {
            showOrderForm($_GET, "", $badFields);
        } else {
            dbUpdate("orders", formatNonItemFields($_GET), "OID", $OID);
            for ($i = 1; $i < $repeatTimes; $i++) {
                $item = selectItem($_GET, $i);
                if (!empty($item)) {
                    // checks to be sure the item actually has info
                    if ($item["Quantity"] != 0) {
                        if ($_GET["iid{$i}"] != "") {
                            dbUpdate("items", $item, "OID", $OID, "IID", $_GET["iid{$i}"]);
                        } else {
                            // if the item does not yet exist in the database
                            dbInsertNewItem($OID, $item);
                        }
                    } else {
                        // if the quantity of an item is set to zero
                        dbDeleteItem($_GET["iid{$i}"]);
                    }
                }
            }
            // go back to the order page
            $config = getConfigData();
            $backToOrder = getSpecialVariable("backToOrder", $config);
            backToWPPage($backToOrder, "oid={$OID}");
        }
    }
}