function processRequestConfirmed($page_id, $cid, $request)
{
    switch ($request) {
        case "delete":
            dbCustomerDelete($cid);
            foreach (dbGetOrdersForCustomer($cid) as $stuff) {
                foreach ($stuff as $order) {
                    print_r(dbGetOrdersForCustomer($cid));
                    dbOrderDelete($order["OID"]);
                }
            }
            break;
        default:
            echo "Dude.  Somehow there was a bad request.\n";
    }
}
function processRequestConfirmed($order, $page_id, $oid, $request, $deleteLink = "", $packingListLink = "", $shippingLink = "")
{
    $message = "";
    $errorMessage = "";
    switch ($request) {
        case "delete":
            if (current_user_can("can_delete_orders")) {
                dbOrderDelete($oid);
                dbOrderDeleteItems($oid);
            }
            backToLink($deleteLink);
            return;
        case "shipit":
            if (current_user_can("can_ship")) {
                backToLink($shippingLink, "OID={$oid}");
            }
            break;
        case "unshipit":
            if (current_user_can("can_ship")) {
                dbUpdate("orders", array("ShippedDate" => 0), "OID", $oid);
            }
            break;
        case "dup":
            if (current_user_can("can_duplicate_orders")) {
                $newoid = dbOrderDuplicate($oid);
                if (!$newoid) {
                    $errorMessage = "Could not duplicate the order!";
                }
                // bulk update the new record
                $updateOrder = array();
                $updateOrder["OrderedDate"] = time();
                $updateOrder["WasCanceled"] = false;
                $updateOrder["WasReceived"] = false;
                $updateOrder["RequestedPay"] = 0;
                $updateOrder["InvoiceNumber"] = 0;
                $updateOrder["InvoiceID"] = "";
                $updateOrder["InvoiceURL"] = "";
                $updateOrder["PaidDate"] = 0;
                $updateOrder["ShippedDate"] = 0;
                $updateOrder["ShippingFee"] = 0;
                $updateOrder["ExpediteFee"] = 0;
                $updateOrder["Discount"] = 0;
                $updateOrder["ReleasedToShipping"] = 0;
                // this is somewhat ugly - to put the link for the duplicate order, the text has to have
                // html in it.  Yuck.
                $updateOrder["AdminONotes"] = "ORDER DUPLICATE of <a href=\"?page_id={$page_id}&oid={$oid}\">{$oid}</a>";
                $updateOrder["CustomerONotes"] = "";
                dbOrderModify($newoid, $updateOrder);
                $message = "Order {$oid} duplicated to this new order.";
                $oid = $newoid;
            }
            break;
        case "cancel":
            if (current_user_can("can_cancel_orders")) {
                dbOrderCancel($oid);
                $retdata = paypalInvoiceCancel($oid);
                if ($retdata["success"]) {
                    $message = "Order canceled.  Any Paypal invoices canceled.";
                } else {
                    // upon error, some notice needs to be shown
                    $errorMessage = "Order canceled.  But Paypal rejected the request to cancel the invoice.";
                    $errorMessage .= " It said: " . $retdata["error"][0]["message"];
                }
            }
            break;
        case "uncancel":
            if (current_user_can("can_cancel_orders")) {
                $newoid = dbOrderDuplicate($oid);
                if (!$newoid) {
                    $errorMessage = "Could not duplicate the order!  Order still canceled.";
                }
                // bulk update the new record
                $updateOrder = array();
                $updateOrder["WasCanceled"] = false;
                $updateOrder["WasReceived"] = false;
                $updateOrder["RequestedPay"] = 0;
                $updateOrder["InvoiceNumber"] = 0;
                $updateOrder["InvoiceID"] = "";
                $updateOrder["InvoiceURL"] = "";
                $updateOrder["PaidDate"] = 0;
                $updateOrder["ShippedDate"] = 0;
                $updateOrder["ReleasedToShipping"] = 0;
                dbOrderModify($newoid, $updateOrder);
                $message = "Order UN-canceled.  New order number is {$newoid}.";
                $oid = $newoid;
            }
            break;
        case "cancelpayment":
            if (current_user_can("can_cancel_payment")) {
                flush();
                $retdata = paypalInvoiceCancel($oid);
                if ($retdata) {
                    dbCancelInvoice($oid);
                } else {
                    // TODO - upon error, soome notice needs to be shown
                }
            }
            break;
        case "repayment":
            if (current_user_can("can_request_repayment")) {
                flush();
                if ($order["InvoiceID"]) {
                    $retdata = paypalInvoiceReSend($oid);
                } else {
                    // apparently the original "invoice" request didn't go through Paypal, so send it there.
                    processRequestConfirmed($order, $page_id, $oid, "payment", $deleteLink, $packingListLink, $shippingLink);
                    return;
                    // should never get here...
                }
                if ($retdata["success"]) {
                    $message = "Payment request was resent, which was cool with Paypal.";
                } else {
                    // upon error, some notice needs to be shown
                    $errorMessage = "Paypal rejected the request to resend the invoice.";
                    $errorMessage .= "<br>It said: " . $retdata["error"][0]["message"];
                }
            }
            break;
        case "payment":
            if (current_user_can("can_request_payment")) {
                flush();
                // cause the page to send out something to make the user's wait easier...
                lockInFees($oid);
                // this locks in shipping and expedite fees
                $retdata = paypalInvoiceSend($oid);
                if ($retdata["success"]) {
                    // note that payerViewURL is used instead of invoiceURL because the latter requires login
                    dbUpdateInvoice($oid, time(), $retdata["invoiceID"], $retdata["invoiceNumber"], $retdata["payerViewURL"]);
                    $message = "Payment was requested, Paypal was cool with it..";
                } else {
                    // upon error, some notice needs to be shown
                    $errorMessage = "Paypal rejected the request to create the invoice.";
                    $errorMessage .= " It said: \"" . $retdata["error"][0]["message"] . "\".";
                }
            }
            break;
        case "release":
            if (current_user_can("can_release_to_shipping")) {
                dbOrderReleasedToShipping($oid);
                $message = "Order released to shipping.";
            }
            break;
        case "unrelease":
            if (current_user_can("can_release_to_shipping")) {
                dbOrderUnReleasedToShipping($oid);
                $message = "Order un-released to shipping.";
            }
            break;
        case 'paid':
            if (current_user_can("can_mark_paid")) {
                dbOrderModifyPaid($oid, time());
                $message = "Order marked paid.";
            }
            break;
        case 'unpaid':
            if (current_user_can("can_mark_paid")) {
                dbOrderModifyPaid($oid, false);
                $message = "Order marked un-paid.";
            }
            break;
        case 'charity':
            if (current_user_can("can_mark_charity")) {
                dbOrderModifyCharity($oid, true);
                $message = "Order marked as charity.";
            }
            break;
        case 'uncharity':
            if (current_user_can("can_mark_charity")) {
                dbOrderModifyCharity($oid, false);
                $message = "Order un-marked as charity.";
            }
            break;
        case 'packing':
            backToLink($packingListLink, "oid={$oid}");
            break;
        default:
            echo "Dude.  Somehow there was a bad request.\n";
    }
    // go back to the order
    if ($message) {
        $message = "&message=" . urlencode($message);
    }
    if ($errorMessage) {
        $errorMessage = "&errorMessage=" . urlencode($errorMessage);
    }
    backToWPPage($page_id, "oid={$oid}{$message}{$errorMessage}");
}
function dbOrderDuplicate($oid)
{
    $order = dbGetOrder($oid);
    if (!$order) {
        return null;
    }
    // remove the OID from $order, before insertion
    unset($order["OID"]);
    $newoid = dbInsertNewOrder($order["CID"], $order);
    if (!$newoid) {
        dbOrderDelete($newoid);
        return null;
    }
    $items = dbGetItems($oid);
    if ($items) {
        foreach ($items as $item) {
            unset($item["IID"]);
            $newiid = dbInsertNewItem($newoid, $item);
            if (!$newiid) {
                dbOrderDelete($newoid);
                // this still leaves orphan items
                return null;
            }
        }
    }
    return $newoid;
}