Exemple #1
0
        } else {
            echo getOrder($pathParts[1]);
        }
        break;
        // Create product on database using POST and view it using GET Method
    // Create product on database using POST and view it using GET Method
    case 'POST':
        postOrders(json_decode(file_get_contents('php://input')));
        break;
        // Delete requrested product from database using DELETE Method
    // Delete requrested product from database using DELETE Method
    case 'DELETE':
        if (empty($pathParts[1])) {
            echo "you can delete everthing!!";
        } else {
            deleteOrders($pathParts[1]);
        }
        break;
        // Allow the user to Edit/Update Products on Database
    // Allow the user to Edit/Update Products on Database
    case 'PATCH':
        if (isset($pathParts[1])) {
            updateOrders($pathParts[1]);
        }
}
// End of Switch Statement
function postOrders($postBody)
{
    //var_dump($postBody);
    foreach ($postBody as $key => $value) {
        echo $value;
function ordersCustomPage()
{
    if (!$_GET['action']) {
        // Default page
        ordersPage();
    } else {
        //If exist action
        $act = $_GET['action'];
        $orderID = $_GET['id'];
        if ($act == '' || $orderID == '') {
            ordersPage();
        } else {
            if ($act == 'View') {
                ordersDetailPage($orderID);
            }
            if ($act == 'Delete') {
                deleteOrders($orderID);
                echo 'Xóa thành công';
                wp_redirect(admin_url() . "admin.php?page=hoa-don");
                $link = admin_url() . 'admin.php?page=hoa-don';
                echo "<script>setTimeout(function(){window.location.href = '" . $link . "';},0);</script>";
            }
            if ($act == 'Edit') {
            }
        }
    }
}