function ws_isResourceAvailable($itemId, $qty)
{
    session_start();
    $userId = $_SESSION["userid"];
    $item = refactored_db_getItem($itemId);
    $result = true;
    if ($item['type'] == "PACKAGE") {
        $packageItems = db_getPackageItem($item['id']);
        foreach ($packageItems as $packageItem) {
            $item = refactored_db_getItem($id);
            if (!ws_isResourceAvailable($item['id'], $packageItem['quantity'] * $qty)) {
                return false;
            }
        }
    } else {
        $timeZoneId = db_getUserTimeZone($userId)['data'];
        $item = refactored_db_getItem($itemId);
        $creditType = ws_getCreditTypeById($item['referenceid']);
        $course = db_getCourseById($creditType->courseId);
        $policy = ws_getPolicyById($creditType->policyId, $timeZoneId);
        $dates = ws_getItemStartAndEndDates($policy, $timeZoneId);
        $startDate = $dates['startDate'];
        $endDate = $dates['endDate'];
        $quota = $policy->quotaInPeriod * $qty;
        try {
            $params = array('course' => $course->fullname, 'resourceType' => $creditType->resource, 'start' => $startDate, 'end' => $endDate, 'quota' => $quota);
            $client = new SoapClient(WSDL_VL, array('location' => LOCATION_VL));
            $response = $client->isResourceAvailable($params);
            $result = $response->success;
        } catch (Exception $e) {
            $result = false;
        } catch (SoapFault $soapfault) {
            $result = false;
        }
    }
    return $result;
}
示例#2
0
     }
     if (isset($_POST['price'])) {
         $price = $_POST['price'];
     } else {
         $price = 0.0;
     }
     if (!isPackageBeingUsed($packageid)) {
         $sql = 'UPDATE module_vlabs_shoppingcart_package_summary ';
         $sql .= 'SET quantity = ' . $itemqty . ', ';
         $sql .= 'price = ' . $price . ' ';
         $sql .= 'WHERE id  = ' . $id;
         if (db_execute($sql)) {
             db_updatePackageTotal($packageid);
             $packageDetail = db_getPackageItem($id);
             //refactored db call : )
             $item = refactored_db_getItem($packageDetail['itemid']);
             $subtotal = $packageDetail['quantity'] * $packageDetail['price'];
             if ($item != null && $packageDetail != null) {
                 $packageItem = array("id" => $packageDetail['id'], "itemid" => $item['id'], "name" => $item['name'], "description" => $item['description'], "quantity" => $packageDetail['quantity'], "price" => $item['price'], "newprice" => $packageDetail['price'], "subtotal" => $subtotal);
             }
             $result = array('success' => true, 'item' => $packageItem);
         } else {
             $result = array('success' => false, 'message' => 'Item could not be modified succesfully');
         }
     } else {
         $result = array('success' => false, 'message' => 'Package item cannot be edited since package is being reference in existing orders');
     }
     echo json_encode($result);
 } else {
     if ($action == "deletePkgItem") {
         if (isset($_POST['id'])) {
function showCart()
{
    session_start();
    $user = $_SESSION['userid'];
    $cart = $_SESSION[$user . 'cart'];
    //No payment Checkout
    //----------------------------------
    $genericCart = new GenericCart();
    //----------------------------------
    //Google Checkout
    //----------------------------------
    $config_file = "checkout/google_checkout/google.conf";
    $comment = "#";
    $fp = fopen($config_file, "r");
    while (!feof($fp)) {
        $line = trim(fgets($fp));
        if ($line && !ereg("^{$comment}", $line)) {
            list($option, $value) = split("=", $line, 2);
            $config_values[$option] = $value;
        }
    }
    fclose($fp);
    $merchant_id = $config_values['CONFIG_MERCHANT_ID'];
    $merchant_key = $config_values['CONFIG_MERCHANT_KEY'];
    $server_type = $config_values['CONFIG_SERVER_TYPE'];
    $currency = $config_values['CONFIG_CURRENCY'];
    $editCartURL = $config_values['CONFIG_EDIT_URL'];
    $continueShoppingURL = $config_values['CONFIG_CONTINUE_URL'];
    $googlecart = new GoogleCart($merchant_id, $merchant_key, $server_type, $currency);
    $googlecart->SetEditCartUrl($editCartURL);
    $googlecart->SetContinueShoppingUrl($continueShoppingURL);
    //----------------------------------
    if ($cart) {
        $items = explode(',', $cart);
        $contents = array();
        foreach ($items as $item) {
            $contents[$item] = isset($contents[$item]) ? $contents[$item] + 1 : 1;
        }
        $formattedShopCartItems = array();
        $result = array();
        foreach ($contents as $i => $qty) {
            $type = substr($i, 0, 1);
            $id = substr($i, 2);
            $item = refactored_db_getItem($id);
            $subtotal = $item['price'] * $qty;
            $scitem = array($item['name'], $item['description'], $item['price'], $qty, $i, $subtotal, $item['id'], $type);
            array_push($formattedShopCartItems, $scitem);
            //No payment Checkout
            //----------------------------------
            if (!$item['billable']) {
                $genericItem = new GenericItem($item['name'], $item['description'], $qty, 0);
                // Unit price
                $genericCart->AddItem($genericItem);
            }
            //----------------------------------
            //Google Checkout
            //----------------------------------
            if ($item['billable']) {
                $googleitem = new GoogleItem($item['name'], $item['description'], $qty, $item['price']);
                // Unit price
                $googleitem->SetMerchantItemId($item['id']);
                //TODO:Change email to order email
                $googleitem->SetEmailDigitalDelivery("*****@*****.**");
                $googlecart->AddItem($googleitem);
            }
            //----------------------------------
        }
    }
    //Checkout Buttons
    $output[] = '<div id="checkoutButtonsContainer">';
    $buttonsCount = 0;
    if (count($genericCart->item_arr)) {
        $buttonsCount++;
        $output[] = $genericCart->CheckoutButtonCode();
    }
    if (count($googlecart->item_arr)) {
        $buttonsCount++;
        $output[] = $googlecart->CheckoutButtonCode("SMALL");
        $output[] = "<div class='ui-state-error' style='padding: 0pt 0.7em; float:left; width:30em;'><p><span class='ui-icon ui-icon-alert' style='float: left; margin-right: 0.3em;'></span>Please when you process the order with Google Checkout, <strong>DO NOT</strong> choose the option 'Keep my e-mail address confidential' because your order will be lost.</p></div>";
    }
    $output[] = '</div>';
    $shoppingCart = $formattedShopCartItems;
    $checkoutButtons = join('', $output);
    $response = array("shoppingCart" => json_encode($formattedShopCartItems), "checkoutButtons" => $checkoutButtons, "buttonsCount" => $buttonsCount);
    $_SESSION[$user . 'cart'] = $cart;
    return $response;
}
                 }
             }
         }
     }
     $items = explode(',', $newcart);
     $newcart = '';
     $contents = array();
     foreach ($items as $item) {
         $contents[$item] = isset($contents[$item]) ? $contents[$item] + 1 : 1;
     }
     $formattedShopCartItems = array();
     $result = array();
     foreach ($contents as $i => $qty) {
         $id = substr($i, 2);
         if (ws_isResourceAvailable($id, $qty)) {
             $item = refactored_db_getItem($id);
             $prefix = "i-";
             if ($item['type'] == "PACKAGE") {
                 $prefix = "p-";
             }
             for ($i = 0; $i < $qty; $i++) {
                 if ($newcart) {
                     $newcart .= ',' . $prefix . $id;
                 } else {
                     $newcart = $prefix . $id;
                 }
             }
         }
     }
     $_SESSION[$user . 'cart'] = $newcart;
 } else {
示例#5
0
function deletePurchasedItems($order_id)
{
    session_start();
    $user = $_SESSION['userid'];
    if ($order_id) {
        $summary = refactored_db_getOrderItems($order_id);
        foreach ($summary as $s) {
            $item = refactored_db_getItem($s['itemid']);
            $prefix = "i-";
            if ($item['type'] == "PACKAGE") {
                $prefix = "p-";
            }
            $_SESSION[$user . 'cart'] = deleteItem($prefix . "" . $item['id'], $_SESSION[$user . 'cart']);
        }
    }
}
 $course_id = "";
 $course_name = "";
 foreach ($course as $c) {
     $course_id = $c['id'];
     $course_name = $c['name'];
 }
 $preassignmentResponse = array("id" => $id, "courseId" => $course_id, "courseName" => $course_name, "itemId" => $item['id'], "itemName" => $item['name'], "quantity" => $quantity, "active" => 1);
 $purchaseId = $id . "" . $item['id'];
 $assignments = array();
 $preassignment = db_getPreassignmentById($purchaseId);
 //echo "refactored db call preassignment array is: " . PHP_EOL;
 //var_dump($preassignment);
 if ($item['type'] == "PACKAGE") {
     $packageItems = db_getPackageItems($item['id']);
     foreach ($packageItems as $pi) {
         $item = refactored_db_getItem($pi['itemid']);
         $assignment = array("purchaseId" => $purchaseId, "creditTypeId" => $item['referenceid'], "quantity" => $quantity * $pi['quantity'], "active" => true);
         array_push($assignments, $assignment);
     }
 } else {
     $assignment = array("purchaseId" => $purchaseId, "creditTypeId" => $item['referenceid'], "quantity" => $quantity, "active" => true);
     array_push($assignments, $assignment);
 }
 $assignmentsResult = ws_modifyCourseQuota($assignments);
 //Check that all assignments were added successfully
 $success = true;
 $assignmentsResultArr = array();
 if (!is_array($assignmentsResult)) {
     array_push($assignmentsResultArr, $assignmentsResult);
 } else {
     array_merge($assignmentsResultArr, $assignmentsResult);
示例#7
0
function sto_getItemDescription($itemid)
{
    session_start();
    $userId = $_SESSION["userid"];
    $item = refactored_db_getItem($itemid);
    $userdb = db_getUserTimeZone($userId);
    $timeZoneId = $userdb['timezone'];
    $description = "";
    if ($item['type'] == "PACKAGE") {
        $items = array();
        $packageItems = db_getPackageItems($item['id']);
        foreach ($packageItems as $packageItem) {
            $item = refactored_db_getItem($packageItem['itemid']);
            $item['quantity'] = $packageItem['quantity'];
            array_push($items, $item);
        }
        $description .= "<ul>";
        foreach ($items as $item) {
            $creditType = ws_getCreditTypeById($item['referenceid']);
            $course = db_getCourseById($creditType->courseId);
            $description .= "<li>";
            $description .= "<strong>" . $item['name'] . "(" . $item['quantity'] . "):</strong> ";
            $description .= "This item allows students enrolled in the course " . $course->shortname . " to use the resource " . $creditType->resource . " for ";
            $description .= sto_getPolicyDescription($creditType->policyId, $timeZoneId);
            $description .= "</li>";
        }
        $description .= "</ul>";
    } else {
        $creditType = ws_getCreditTypeById($item['referenceid']);
        $course = db_getCourseById($creditType->courseId);
        $description .= "This item allows students enrolled in the course " . $course->shortname . "  to use the resource " . $creditType->resource . " for ";
        $description .= sto_getPolicyDescription($creditType->policyId, $timeZoneId);
    }
    return $description;
}
function saveTransaction($orderid, $payment)
{
    //Get order from database
    $order = db_getOrderById($orderid);
    //Get buyer info from database
    $userId = "";
    $order_ordernumber = "";
    foreach ($order as $o) {
        $userId = $o['userid'];
        $order_ordernumber = $o['ordernumber'];
    }
    //Get order items
    $orderitems = db_getOrderItems($orderid);
    //Initialize array that will hold all order items ids and if the web service saved them succesfully
    $orderItemsSuccess = array();
    //Initialize array that will hold items that will be set through the web service with rollback false
    $itemsArr = array();
    //Initialize index of order items array
    $itemIndex = 0;
    $itemsIndexArr = array();
    //print_r($orderitems);
    //Iterate thorugh $orderItems obtained from db
    foreach ($orderitems as $orderitem) {
        //Get item from database
        $item = refactored_db_getItem($orderitem['itemid']);
        //print_r($item);
        //Initialize item success assuming it will be true
        $orderItemsSuccess[$itemIndex] = array("id" => $item['id'], "success" => false);
        //Get item type to see if it is a package or not
        $type = $item['type'];
        //echo $item->name."-".$item->type;
        if ($type == "ITEM") {
            //Save item in itemsArr to send the request to the web service
            $quantity = $orderitem['quantity'];
            array_push($itemsArr, array("creditTypeId" => $item['referenceid'], "quantity" => $quantity, "purchaseId" => $order_ordernumber, "active" => false));
            array_push($itemsIndexArr, $itemIndex);
        } else {
            if ($type == "PACKAGE") {
                $orderItemsSuccess[$itemIndex]["success"] = true;
                //Get package items
                $packageitems = db_getPackageItems($item['id']);
                //Initialize array to send a ws request for package items only with rollback true
                $packageItemsArr = array();
                //Initialize the response
                $success = true;
                //Save items in request array
                foreach ($packageitems as $packageitem) {
                    $item = refactored_db_getItem($packageitem['itemid']);
                    $quantity = $orderitem['quantity'] * $packageitem['quantity'];
                    array_push($packageItemsArr, array("creditTypeId" => $item['referenceid'], "quantity" => $quantity, "purchaseId" => $order_ordernumber . "" . $orderitem['itemid'], "active" => false));
                }
                //Send request for package
                $response = ws_assignQuota($packageItemsArr, $userId, $payment, true);
                //print_r($response);
                //Check if an item failed to be saved, if it did set success to False
                foreach ($response as $r) {
                    if (!$r->active) {
                        $orderItemsSuccess[$itemIndex]["success"] = $r->active;
                        break;
                    }
                }
            }
        }
        //echo "Item success = ".$orderItemsSuccess[$itemIndex]["success"];
        $itemIndex++;
    }
    //print_r($orderItemsSuccess);
    //print_r($itemsIndexArr);
    //echo "Single Items :";
    //print_r($itemsArr);
    //Send request for order items that were not packages. if there are any
    $successIndex = 0;
    $assignments = array();
    if (count($itemsArr) > 0) {
        $response = ws_assignQuota($itemsArr, $userId, $payment, false);
        if (is_array($response)) {
            $assignments = array_merge($assignments, $response);
        } else {
            array_push($assignments, $response);
        }
        //print_r("assign quota response ".$assignments);
        $i = 0;
        //Go thorugh the response to check which item failed
        foreach ($assignments as $assignment) {
            $index = $itemsIndexArr[$i++];
            //print_r("index ".$index);
            $orderItemsSuccess[$index]["success"] = $assignment->active;
        }
    }
    //echo "OrderItemsSuccess :";
    //print_r($orderItemsSuccess);
    return $orderItemsSuccess;
}
示例#9
0
                                 $gresponse  = $Grequest->SendCancelOrder($dbOrder->ordernumber,
                                                         "Order has been cancelled due to a partial or complete refund.".
                                                          "Contact the administrator for further details.");
                     
                                 */
                 } else {
                     db_cancelOrder($dbOrder_id);
                     $body = '<p>Order ' . $dbOrder_ordernumber . ' has been cancelled.<p>';
                     $user = db_getUserById($dbOrder_userid);
                     // sms: 5/19/2011
                     // sendEmail($user, 'Order['.$dbOrder->ordernumber.'] Cancellation', $body);
                 }
             }
             $orderitem = db_getOrderItemById($id);
             $subtotal = $orderitem['quantity'] * $orderitem['unitprice'];
             $item = refactored_db_getItem($orderitem['itemid']);
             $user = db_getUserById($dbOrder_userid);
             $description = ord_getItemDescription($item['id'], $dbOrder_id);
             $oi = array("id" => $orderitem['id'], "itemid" => $item['id'], "name" => $item['name'], "type" => $item['type'], "description" => $item['description'], "quantity" => $orderitem['quantity'], "price" => $orderitem['unitprice'], "subtotal" => $subtotal, "cancelled" => $orderitem['cancelled'], "description" => $description);
             if ($success) {
                 $body = '<p>The item ' . $dbItem_name . ' from order ' . $dbOrder_ordernumber . ' has been cancelled.<p>';
             } else {
                 $body = '<p>The item ' . $dbItem_name . ' from order ' . $dbOrder_ordernumber . ' has not been cancelled. The reason is: <cite>' . $message . '</cite><p>';
             }
             // sms: 5/19/2011
             // sendEmail($user, 'Item Cancellation from order['.$dbOrder->ordernumber.']', $body);
             $response = array("success" => $success, "orderitem" => $oi, "message" => $message);
             echo json_encode($response);
         }
     }
 }