-
Notifications
You must be signed in to change notification settings - Fork 5
/
contentitem_return.php
69 lines (61 loc) · 1.65 KB
/
contentitem_return.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
<h1>Item Selected</h1>
<!--
GET:
<?php
var_dump($_GET);
echo("POST:\n");
var_dump($_POST);
echo("-->\n");
// Compute the input tag in the parent document
$partno = $_GET['partno'];
$id = 'input_content_item_'.$partno;
$icon = 'input_content_icon_'.$partno;
// Check to see if we are doing the standard or faking Canvas
if ( isset($_POST['content_items'] ) ) {
$items = json_decode($_POST['content_items']);
echo("<!--\n");
var_dump($items);
echo("-->\n");
$graph = $items->{'@graph'};
$found = false;
foreach($graph as $item ) {
if ( strpos($item->{'@type'}, 'LtiLink') !== 0 ) continue;
$found = true;
break;
}
if ( ! $found ) {
echo("<p>Unable to find returned ContentItem data.</p>");
return;
}
} else {
if ( ! isset($_GET['url']) ) {
echo("<p>Missing return url parameter.</p>");
return;
}
$item = json_decode('{
"@type": "LtiLinkItem",
"url": "http:\/\/localhost:8888\/sakai-api-test\/tool.php?sakai=98765",
}');
$full_url = $_GET['url'];
echo("<!--\n");
echo(htmlentities($full_url)."\n");
echo("-->\n");
$pos = strpos($full_url,"url=");
if ( $pos === false ) {
echo("<p>Unable to parse url= parameter.</p>");
return;
}
$url = urldecode(substr($full_url,$pos+4));
echo("<!--\n");
echo(htmlentities($url)."\n");
echo("-->\n");
$item['url'] = $url;
}
?>
<script>
console.log(window.parent.$("#<?= $id ?>").val());
item = <?= json_encode($item) ?>;
window.parent.$("#<?= $id ?>").val(JSON.stringify(item));
window.parent.$("#<?= $icon ?>").show();
</script>
<p>You may now close the window</p>