function replaceResultRequest($grade, $sourcedid, $endpoint, $oauth_consumer_key, $oauth_consumer_secret) { $method = "POST"; $content_type = "application/xml"; $operation = 'replaceResultRequest'; $postBody = str_replace(array('SOURCEDID', 'GRADE', 'OPERATION', 'MESSAGE'), array($sourcedid, $grade, $operation, uniqid()), getPOXGradeRequest()); $response = sendOAuthBody($method, $endpoint, $oauth_consumer_key, $oauth_consumer_secret, $content_type, $postBody); return parseResponse($response); }
} $sourcedid = $context->getOutcomeSourceDID(); if ($sourcedid === false) { echo json_encode(array("status" => "failure", "detail" => "No grade entry available")); return; } if (isset($_SESSION['oauth_consumer_key']) && isset($_SESSION['oauth_consumer_secret'])) { $oauth_consumer_key = $_SESSION['oauth_consumer_key']; $oauth_consumer_secret = $_SESSION['oauth_consumer_secret']; } else { echo json_encode(array("status" => "failure", "detail" => "No key/secret in session")); return; } $method = "POST"; $content_type = "application/xml"; $operation = 'replaceResultRequest'; $postBody = str_replace(array('SOURCEDID', 'GRADE', 'OPERATION', 'MESSAGE'), array($sourcedid, '1.0', 'replaceResultRequest', uniqid()), getPOXGradeRequest()); $response = sendOAuthBodyPOST($method, $endpoint, $oauth_consumer_key, $oauth_consumer_secret, $content_type, $postBody); global $LastOAuthBodyBaseString; $lbs = $LastOAuthBodyBaseString; try { $retval = parseResponse($response); } catch (Exception $e) { $retval = $e->getMessage(); } $debug = array("endpoint" => $endpoint, "retval" => $retval, "wesent" => $postBody, "wegot" => $response, "base" => $lbs); $retval = array("status" => "success"); if (isset($_GET["debug"])) { $retval['debug'] = $debug; } echo json_encode($retval);
$sql = sprintf("UPDATE Responses SET note=%s, grade=%s WHERE id=%s\n", $db->quote($_POST['note']), $db->quote($_POST['grade']), $db->quote($_REQUEST['response_id'])); $rows = $db->exec($sql); if ($rows < 1) { $_SESSION['err'] = 'Unable to update Grade'; $context->redirect('index.php'); return; } $_SESSION['success'] = 'Grade Stored'; } if (strlen($response['sourcedid']) == 0 || strlen($response['service']) == 0) { $context->redirect('index.php'); return; } // Time to send the grade... $operation = 'replaceResultRequest'; $postBody = str_replace(array('SOURCEDID', 'GRADE', 'OPERATION', 'MESSAGE'), array($response['sourcedid'], $_POST['grade'], $operation, uniqid()), getPOXGradeRequest()); $oauth_consumer_key = '12345'; $oauth_consumer_secret = 'secret'; $content_type = 'application/xml'; $endpoint = $response['service']; $response = sendOAuthBodyPOST("POST", $endpoint, $oauth_consumer_key, $oauth_consumer_secret, $content_type, $postBody); $retval = parseResponse($response); if ($retval['imsx_codeMajor'] == 'success') { $_SESSION['success'] = 'Grade Uploaded to LMS'; } else { $_SESSION['err'] = 'Grade stored, but upload failed: ' . $retval['imsx_description']; } echo "<p>Grade sent...</p>\n"; echo '<p><a href="index.php">Continue...</a></p>'; echo "\n<pre>\n"; echo "Service Url:\n";
$content_type = 'application/xml'; if (isset($_REQUEST['action'])) { $action = $_REQUEST['action']; if ($action == 'read') { $grade = 'Not set'; $operation = 'readResultRequest'; $postBody = str_replace(array('SOURCEDID', 'OPERATION', 'MESSAGE'), array($sourcedid, $operation, uniqid()), getPOXRequest()); $response = parseResponse(sendOAuthBodyPOST($method, $endpoint, $oauth_consumer_key, $oauth_consumer_secret, $content_type, $postBody)); if ($response['imsx_codeMajor'] == 'success' && $response['textString'] != '') { $grade = $response['textString']; } } else { if ($action == 'write') { $grade = $_REQUEST['newgrade']; $operation = 'replaceResultRequest'; $postBody = str_replace(array('SOURCEDID', 'GRADE', 'OPERATION', 'MESSAGE'), array($sourcedid, $grade, $operation, uniqid()), getPOXGradeRequest()); $response = parseResponse(sendOAuthBodyPOST($method, $endpoint, $oauth_consumer_key, $oauth_consumer_secret, $content_type, $postBody)); if ($response['imsx_codeMajor'] == 'success') { $grade = 'success'; } else { $grade = 'failure'; } } else { if ($action = 'delete') { $operation = 'deleteResultRequest'; $postBody = str_replace(array('SOURCEDID', 'OPERATION', 'MESSAGE'), array($sourcedid, $operation, uniqid()), getPOXRequest()); $response = parseResponse(sendOAuthBodyPOST($method, $endpoint, $oauth_consumer_key, $oauth_consumer_secret, $content_type, $postBody)); } } } }