forked from csev/py4e
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool_provider_outcome.php
More file actions
118 lines (104 loc) · 4.11 KB
/
tool_provider_outcome.php
File metadata and controls
118 lines (104 loc) · 4.11 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<html>
<head>
<title>IMS Learning Tools Interoperability</title>
</head>
<body style="font-family:sans-serif; background-color:#add8e6">
<p><b>Tool Provider Calling the IMS LIS/LTI Outcome Service</b></p>
<p>This is a simple implementation of the Simple Outcomes Service.</p>
<?php
// Load up the LTI Support code
require_once("../util/lti_util.php");
// Note - We avoid using the session in this file to avoid deadlocks
// If we were calling a web service on the same server
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
} else {
error_reporting(E_ALL & ~E_WARNING & ~E_NOTICE);
}
ini_set("display_errors", 1);
$oauth_consumer_secret = $_REQUEST['secret'];
if (strlen($oauth_consumer_secret) < 1 ) $oauth_consumer_secret = 'secret';
$sourcedid = $_REQUEST['sourcedid'];
if (get_magic_quotes_gpc()) $sourcedid = stripslashes($sourcedid);
?>
<p>
<form method="POST">
Service URL: <input type="text" name="url" size="100" disabled="true" value="<?php echo(htmlentities($_REQUEST['url']));?>"/></br>
lis_result_sourcedid: <input type="text" name="sourcedid" disabled="true" size="100" value="<?php echo(htmlentities($sourcedid));?>"/></br>
OAuth Consumer Key: <input type="text" name="key" disabled="true" size="80" value="<?php echo(htmlentities($_REQUEST['key']));?>"/></br>
OAuth Consumer Secret: <input type="text" name="secret" size="80" value="<?php echo(htmlentities($oauth_consumer_secret));?>"/></br>
</p><p>
Grade to Send to LMS: <input type="text" name="grade" value="<?php echo(htmlentities($_REQUEST['grade']));?>"/>
(i.e. 0.95)<br/>
<input type='submit' name='submit' value="Send Grade">
<input type='submit' name='submit' value="Read Grade">
<input type='submit' name='submit' value="Delete Grade"></br>
</form>
<?php
$url = $_REQUEST['url'];
if(!in_array($_SERVER['HTTP_HOST'],array('localhost','127.0.0.1')) && strpos($url,'localhost') > 0){ ?>
<p>
<b>Note</b> This service call may not work. It appears as though you are
calling a service running on <b>localhost</b> from a tool that
is not running on localhost.
Because these services are server-to-server calls if you are
running your LMS on "localhost", you must also run this script
on localhost as well. If your LMS has a real Internet
address you should be OK. You can get a copy of the test
tools to run locally at
to test your LMS instance running on localhost.
(<a href="../lti.zip" target="_new">Download</a>)
</p>
<?php
}
$oauth_consumer_key = $_REQUEST['key'];
$method="POST";
$endpoint = $_REQUEST['url'];
$content_type = "application/xml";
if ( $_REQUEST['submit'] == "Send Grade" && isset($_REQUEST['grade'] ) ) {
$operation = 'replaceResultRequest';
$postBody = str_replace(
array('SOURCEDID', 'GRADE', 'OPERATION','MESSAGE'),
array($sourcedid, $_REQUEST['grade'], $operation, uniqid()),
getPOXGradeRequest());
} else if ( $_REQUEST['submit'] == "Read Grade" ) {
$operation = 'readResultRequest';
$postBody = str_replace(
array('SOURCEDID', 'OPERATION','MESSAGE'),
array($sourcedid, $operation, uniqid()),
getPOXRequest());
} else if ( $_REQUEST['submit'] == "Delete Grade" ) {
$operation = 'deleteResultRequest';
$postBody = str_replace(
array('SOURCEDID', 'OPERATION','MESSAGE'),
array($sourcedid, $operation, uniqid()),
getPOXRequest());
} else {
exit();
}
$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();
}
echo("\n<pre>\n");
echo("Service Url:\n");
echo(htmlentities($endpoint)."\n\n");
print_r($retval);
echo("\n");
echo("------------ POST RETURNS ------------\n");
$response = str_replace("><",">\n<",$response);
$response = str_replace("<","<",$response);
$response = str_replace(">",">",$response);
echo($response);
echo("\n\n------------ WE SENT ------------\n");
$postBody = str_replace("<","<",$postBody);
$postBody = str_replace(">",">",$postBody);
echo($postBody);
echo("\nBase String:\n");
echo($lbs);
echo("\n</pre>\n");
?>