forked from mitodl/response-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grade.php
70 lines (61 loc) · 2.27 KB
/
grade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
require_once('lti.php');
if (empty($_SESSION['authenticated'])) {
echo 'Error: You do not have permission to visit this page.';
die();
}
// Only return mark is scoring is enabled
if (!empty($_SESSION['config']['lis_outcome_service_url'])) {
// Give participation mark
$student_grade = 1;
$outcome_url = $_SESSION['config']['lis_outcome_service_url'];
$consumer_key = $_SESSION['config']['oauth_consumer_key'];
$key_secret = json_decode($config->key_secret, true);
$consumer_secret = $key_secret[$consumer_key];
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
$body = '<?xml version = "1.0" encoding = "UTF-8"?>
<imsx_POXEnvelopeRequest xmlns = "http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
<imsx_POXHeader>
<imsx_POXRequestHeaderInfo>
<imsx_version>V1.0</imsx_version>
<imsx_messageIdentifier>' . $_SERVER['REQUEST_TIME'] . '</imsx_messageIdentifier>
</imsx_POXRequestHeaderInfo>
</imsx_POXHeader>
<imsx_POXBody>
<replaceResultRequest>
<resultRecord>
<sourcedGUID>
<sourcedId>' . $_SESSION['config']['lis_result_sourcedid'] . '</sourcedId>
</sourcedGUID>
<result>
<resultScore>
<language>en</language>
<textString>' . $student_grade . '</textString>
</resultScore>
</result>
</resultRecord>
</replaceResultRequest>
</imsx_POXBody>
</imsx_POXEnvelopeRequest>';
$hash = base64_encode(sha1($body, TRUE));
$params = array('oauth_body_hash' => $hash);
$token = '';
$content_type = 'application/xml';
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
$consumer = new OAuthConsumer($consumer_key, $consumer_secret);
$outcome_request = OAuthRequest::from_consumer_and_token($consumer, $token, 'POST', $outcome_url, $params);
$outcome_request->sign_request($hmac_method, $consumer, $token);
$header = $outcome_request->to_header();
$header = $header . "\r\nContent-type: " . $content_type . "\r\n";
$options = array(
'http' => array(
'method' => 'POST',
'content' => $body,
'header' => $header,
),
);
$ctx = stream_context_create($options);
$fp = @fopen($outcome_url, 'rb', FALSE, $ctx);
$response = @stream_get_contents($fp);
}
?>