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;
}
function ct_getCreditTypes()
{
    try {
        $client = new SoapClient(WSDL_QS, array('location' => LOCATION_QS));
        $result = $client->getCreditTypes();
        $credittype = $result->creditType;
        $policy = $result->policy;
        $credittypes = array();
        $policies = array();
        if (is_array($credittype)) {
            $credittypes = array_merge($credittypes, $credittype);
        } else {
            if ($credittype != null) {
                array_push($credittypes, $credittype);
            }
        }
        if (is_array($policy)) {
            $policies = array_merge($policies, $policy);
        } else {
            if ($policy != null) {
                array_push($policies, $policy);
            }
        }
        $formattedCreditTypes = array();
        foreach ($credittypes as $credittype) {
            $course = db_getCourseById($credittype->courseId);
            foreach ($policies as $policy) {
                if ($policy->id == $credittype->policyId) {
                    $policyName = $policy->name . " : " . $policy->policyType;
                    break;
                }
            }
            $c = array($credittype->id, $credittype->name, $credittype->resource, $course->shortname, $policyName, $credittype->active, $credittype->assignable);
            array_push($formattedCreditTypes, $c);
        }
        return $formattedCreditTypes;
    } catch (Exception $e) {
        return array("success" => false, "message" => $e->getMessage());
    } catch (SoapFault $soapfault) {
        return array("success" => false, "message" => $soapfault->getMessage());
    }
}
 }
 if (isset($_POST['courseid'])) {
     $courseid = $_POST['courseid'];
 } else {
     $courseid = "";
 }
 if (isset($_POST['quantity'])) {
     $quantity = $_POST['quantity'];
 } else {
     $quantity = 0;
 }
 //Generate purchase id combining order number and item id
 $item = refactored_db_getItem($itemid);
 //echo "item array for itemid: " . $itemid . "::" . PHP_EOL;
 //var_dump($item);
 $course = db_getCourseById($courseid);
 $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) {
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;
}
Beispiel #5
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;
}