function ws_isResourceAvailable($itemId, $qty)
{
    session_start();
    $userId = $_SESSION["userid"];
    $item = db_getItem($itemId);
    $result = true;
    if ($item->type == "PACKAGE") {
        $packageItems = db_getPackageItem($item->id);
        foreach ($packageItems as $packageItem) {
            $item = db_getItem($id);
            if (!ws_isResourceAvailable($item->id, $packageItem->quantity * $qty)) {
                return false;
            }
        }
    } else {
        $timeZoneId = db_getUserTimeZone($userId)->data;
        $item = 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;
}
Ejemplo n.º 2
0
 case 'CHARGING':
     break;
 case 'CHARGED':
     $refundAmount = 0;
     $orderItemsSuccess = saveTransaction($dborder->id, true);
     $Gresponse->log->LogResponse("items count " . count($orderItemsSuccess));
     $itemsToCancel = array();
     //Iterate through the response
     foreach ($orderItemsSuccess as $ois) {
         $Gresponse->log->LogResponse("id " . $ois["id"] . " - success: " . $ois["success"]);
         //If item could not be saved in web service, it should be deleted form the order summary
         if (!$ois["success"]) {
             //cancel order item
             db_cancelOrderItem($dborder->id, $ois["id"]);
             //get item from database
             $dbItem = db_getItem($ois["id"]);
             $Gresponse->log->LogResponse("Get Order Item " . $dbItem->id . " from " . $dborder->ordernumber);
             //get item details
             $dbOrderItem = db_getOrderItem($dborder->ordernumber, $dbItem->id);
             $Gresponse->log->LogResponse("Creating Google item " . $dbItem->name);
             $Gresponse->log->LogResponse("quantity: " . $dbOrderItem->quantity);
             $Gresponse->log->LogResponse("price: " . $dbItem->price);
             //create a google item
             $gitem = new GoogleItem($dbItem->name, $dbItem->description, $dbOrderItem->quantity, $dbItem->price);
             // Unit price
             $refundAmount += $dbOrderItem->quantity * $dbItem->price;
             $Gresponse->log->LogResponse("refund subtotal: " . $refundAmount);
             //set item unique id
             $Gresponse->log->LogResponse("Set Merchant Id" . $dbItem->id);
             $gitem->SetMerchantItemId($dbItem->id);
             array_push($itemsToCancel, $gitem);
Ejemplo n.º 3
0
function deletePurchasedItems($orderid)
{
    session_start();
    $user = $_SESSION['userid'];
    if ($orderid) {
        $summary = db_getOrderItems($orderid);
        foreach ($summary as $s) {
            $item = db_getItem($s->itemid);
            $prefix = "i-";
            if ($item->type == "PACKAGE") {
                $prefix = "p-";
            }
            $_SESSION[$user . 'cart'] = deleteItem($prefix . "" . $item->id, $_SESSION[$user . 'cart']);
        }
    }
}
Ejemplo n.º 4
0
         }
     }
     $content = join('', $output);
     //echo "content is: " . PHP_EOL;
     //var_dump($content);
     //echo PHP_EOL;
     $response = array("content" => $content, "billable" => $billable, "prices" => $priceArr);
     echo json_encode($response);
 } else {
     if ($action == "getPackage") {
         if (isset($_POST['packageid'])) {
             $packageid = $_POST['packageid'];
         } else {
             $packageid = "";
         }
         $package = db_getItem($packageid);
         $packageItems = db_getPackageItems($packageid);
         $empty = !is_array($packageItems);
         if ($package != null) {
             $p = array("id" => $package->id, "name" => $package->name, "description" => $package->description, "billable" => $package->billable, "active" => $package->active, "price" => $package->price, "empty" => $empty);
         }
         echo json_encode($p);
     } else {
         if ($action == "addPkgItem") {
             if (isset($_POST['itemqty'])) {
                 $itemqty = $_POST['itemqty'];
             } else {
                 $itemqty = 0;
             }
             if (isset($_POST['itemid'])) {
                 $itemid = $_POST['itemid'];
Ejemplo n.º 5
0
 } else {
     if ($action == "deletePreassignment") {
         if (isset($_POST['id'])) {
             $id = $_POST['id'];
         } else {
             $id = "";
         }
         $preassignment = db_getPreassignmentById($id);
         $item = db_getItem($preassignment['itemid']);
         $purchaseId = $id . "" . $item->id;
         $assignments = array();
         $quantity = $preassignment['quantity'];
         if ($item->type == "PACKAGE") {
             $packageItems = db_getPackageItems($item->id);
             foreach ($packageItems as $pi) {
                 $item = 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_cancelCourseQuota($assignments);
         //Check that all assignments were added successfully
         $success = true;
         $message = "";
         foreach ($assignmentsResult as $ar) {
             if ($ar->active) {
                 $message = "Course assignment could not be cancelled";
                 $success = false;
Ejemplo n.º 6
0
function sto_getItemDescription($itemid)
{
    session_start();
    $userId = $_SESSION["userid"];
    $item = db_getItem($itemid);
    $timeZoneId = db_getUserTimeZone($userId)->data;
    $description = "";
    if ($item->type == "PACKAGE") {
        $items = array();
        $packageItems = db_getPackageItems($item->id);
        foreach ($packageItems as $packageItem) {
            $item = 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 cancelTransaction($orderid)
{
    //Get orde details
    $order = db_getOrderById($orderid);
    $user = db_getUserById($order->userid);
    $orderItems = db_getOrderItems($orderid);
    //Prepare request for the quota system cancel call
    $assignments = array();
    foreach ($orderItems as $orderItem) {
        $item = db_getItem($orderItem->itemid);
        $type = $item->type;
        if ($type == "ITEM") {
            $assignment = array("creditTypeId" => $item->referenceid, "quantity" => $orderItem->quantity, "purchaseId" => $order->ordernumber, "active" => !$orderItem->cancelled);
            array_push($assignments, $assignment);
        } else {
            if ($type == "PACKAGE") {
                //Get package items
                $packageitems = db_getPackageItems($item->id);
                //Initialize array to send a ws request for package items only with rollback true
                $packageItemsArr = array();
                //Save items in request array
                foreach ($packageitems as $packageitem) {
                    $item = db_getItem($packageitem->itemid);
                    $quantity = $orderItem->quantity * $packageitem->quantity;
                    $assignment = array("creditTypeId" => $item->referenceid, "quantity" => $quantity, "purchaseId" => $order->ordernumber . "" . $orderItem->itemid, "active" => !$orderItem->cancelled);
                    array_push($assignments, $assignment);
                }
            }
        }
    }
    //call web service
    $response = ws_cancelQuotaAssignment($assignments);
    $assignmentsResponse = array();
    if (!is_array($response)) {
        array_push($assignmentsResponse, $response);
    } else {
        $assignmentsResponse = array_merge($assignmentsResponse, $response);
    }
    return $assignmentsResponse;
}
                 }
             }
         }
     }
     $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 = 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 {
Ejemplo n.º 9
0
function ord_getItemDescription($itemid, $orderid)
{
    //Test with ordernumber:  IA4f310f1212c9b
    $order = db_getOrderById($orderid);
    //jh candidate for removal since this info was already obtained in calling section:  reloadOrderItems.  maybe is better to pass these individual values as arguments???
    //printr($order);
    $order_userid = "";
    foreach ($order as $o) {
        $order_userid = $o['userid'];
    }
    $item = db_getItem($itemid);
    //jh again candidate for removal, this was already obtained in calling section. maybe is better to pass these individual values as arguments???
    $itemtype = "";
    foreach ($item as $i) {
        $itemtype = $i['type'];
    }
    //	echo '<script type="text/javascript">alert("In orders.php ord_getItemDescription  after db_getItem itemid= '.$itemid .' orderid= ' . $orderid .'")</script>';
    $timeZoneId = 'GMT-05:00 US/Eastern';
    //jh original was(need input from the Professor): db_getUserTimeZone($order_userid)->data;
    $description = "";
    if ($itemtype == "PACKAGE") {
        //	echo '<script type="text/javascript">alert("In orders.php ord_getItemDescription in if package section")</script>';
        $items = array();
        $packageItems = db_getPackageItems($itemid);
        foreach ($packageItems as $packageItem) {
            //jh here the logic is getting the items
            $item = db_getItem($packageItem['itemid']);
            //$item->quantity = $packageItem->quantity; //replaced by foreach loop below.  I cannot use object->field because getting back  a mixed mysqli array
            foreach ($item as $i) {
                $i['quantity'] = $packageItem['quantity'];
            }
            array_push($items, $item);
            //			echo '<script type="text/javascript">alert("in orders.php $packageItems foreach loop i->quantity='. $packageItem['quantity'].'")</script>'; //jh remove this
        }
        //	echo '<script type="text/javascript">alert("in orders.php after $packageItems foreach loop")</script>';
        //	echo "items array with item array elements";
        //	var_dump($items);
        $description .= "<ul>";
        foreach ($items as $item) {
            //jh we also need to do a foreach loop for each $item
            $itemname = "";
            $itemquantity = "";
            $item_referenceid = "";
            //check array size first.
            //		echo '<script type="text/javascript">alert("in orders.php after $packageItems foreach loop first items foreach loop item size is:'.sizeof($item). '")</script>';
            foreach ($item as $i) {
                //echo "items sub loop, size of item is: " . sizeof($i);
                $itemname = $i['name'];
                $itemquantity = $i['quantity'];
                $item_referenceid = ['referenceid'];
            }
            //		echo '<script type="text/javascript">alert("in orders.php after $packageItems after foreach items, item before soap call")</script>';
            //echo "Right before ws_getCreditTypeById() call";
            $creditType = ws_getCreditTypeById($item_referenceid);
            //jh here another getCreditTypeById. Replace with Ajax call
            //jh CAREFUL!!!! NEED TO TEST IF creditType returned is null else it will look ugly
            //echo '<script type="text/javascript">alert("in orders.php after $packageItems about to dump creditType")</script>';
            //echo "credit type var_dump ";
            //var_dump($creditType);
            $course = db_getCourseById($creditType->courseId);
            //jh needs to be put back once credittype ajax call is available
            $course_name = "";
            foreach ($course as $c) {
                $course_name = $c['name'];
            }
            $description .= "<li>";
            $description .= "<strong>" . $itemname . "(" . $itemquantity . "):</strong> ";
            $description .= "This item allows students enrolled in the course " . $course_name . " to use the resource " . $creditType->resource . " for ";
            $description .= ord_getPolicyDescription($creditType->policyId, $timeZoneId);
            $description .= "</li>";
        }
        $description .= "</ul>";
    } else {
        $item_referenceid = "";
        foreach ($item as $i) {
            $item_referenceid = $i['referenceid'];
        }
        $creditType = ws_getCreditTypeById($item_referenceid);
        //echo "creditType vardump: ";
        //var_dump($creditType);
        $course = db_getCourseById($creditType->courseId);
        $course_name = "";
        foreach ($course as $c) {
            $course_name = $c['name'];
        }
        //	$description .=  "This item allows students enrolled in the course ".$course->shortname."  to use the resource ".$creditType->resource." for ";	//jh original code needs retrofitting, efront course table does not have a shortname field
        $description .= "This item allows students enrolled in the course " . $course_name . "  to use the resource " . $creditType->resource . " for ";
        //echo "description data: " . $description;
        $description .= ord_getPolicyDescription($creditType->policyId, $timeZoneId);
    }
    //		$description .=  "Else section Needs a lot of Work (orders.php ord_getItemDescription) ";	//jh remove
    //		$description .= "You have 1 millisecond left of Quota";  //jh remove
    return $description;
}
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 = 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;
}
Ejemplo n.º 11
0
         $itemid = 0;
     }
     if (isset($_POST['price'])) {
         $price = $_POST['price'];
     } else {
         $price = 0.0;
     }
     if (!isPackageBeingUsed($packageid)) {
         $sql = 'UPDATE mdl_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);
             $item = 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'])) {