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; }
} else { $itemid = 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 {