Commit | Line | Data |
---|---|---|
b7e436b0 CS |
1 | <?php\r |
2 | // This file is part of BasicLTI4Moodle\r | |
3 | //\r | |
4 | // BasicLTI4Moodle is an IMS BasicLTI (Basic Learning Tools for Interoperability)\r | |
5 | // consumer for Moodle 1.9 and Moodle 2.0. BasicLTI is a IMS Standard that allows web\r | |
6 | // based learning tools to be easily integrated in LMS as native ones. The IMS BasicLTI\r | |
7 | // specification is part of the IMS standard Common Cartridge 1.1 Sakai and other main LMS\r | |
8 | // are already supporting or going to support BasicLTI. This project Implements the consumer\r | |
9 | // for Moodle. Moodle is a Free Open source Learning Management System by Martin Dougiamas.\r | |
10 | // BasicLTI4Moodle is a project iniciated and leaded by Ludo(Marc Alier) and Jordi Piguillem\r | |
11 | // at the GESSI research group at UPC.\r | |
12 | // SimpleLTI consumer for Moodle is an implementation of the early specification of LTI\r | |
13 | // by Charles Severance (Dr Chuck) htp://dr-chuck.com , developed by Jordi Piguillem in a\r | |
14 | // Google Summer of Code 2008 project co-mentored by Charles Severance and Marc Alier.\r | |
15 | //\r | |
16 | // BasicLTI4Moodle is copyright 2009 by Marc Alier Forment, Jordi Piguillem and Nikolas Galanis\r | |
17 | // of the Universitat Politecnica de Catalunya http://www.upc.edu\r | |
18 | // Contact info: Marc Alier Forment granludo @ gmail.com or marc.alier @ upc.edu\r | |
19 | //\r | |
20 | // Moodle is free software: you can redistribute it and/or modify\r | |
21 | // it under the terms of the GNU General Public License as published by\r | |
22 | // the Free Software Foundation, either version 3 of the License, or\r | |
23 | // (at your option) any later version.\r | |
24 | //\r | |
25 | // Moodle is distributed in the hope that it will be useful,\r | |
26 | // but WITHOUT ANY WARRANTY; without even the implied warranty of\r | |
27 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r | |
28 | // GNU General Public License for more details.\r | |
29 | //\r | |
30 | // You should have received a copy of the GNU General Public License\r | |
31 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>.\r | |
32 | \r | |
33 | /**\r | |
34 | * This file contains all necessary code to view a basiclti activity instance\r | |
35 | *\r | |
73300339 | 36 | * @package lti\r |
b7e436b0 CS |
37 | * @copyright 2009 Marc Alier, Jordi Piguillem, Nikolas Galanis\r |
38 | * marc.alier@upc.edu\r | |
39 | * @copyright 2009 Universitat Politecnica de Catalunya http://www.upc.edu\r | |
40 | *\r | |
41 | * @author Marc Alier\r | |
42 | * @author Jordi Piguillem\r | |
43 | * @author Nikolas Galanis\r | |
44 | *\r | |
45 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\r | |
46 | */\r | |
47 | \r | |
48 | require_once('../../config.php');\r | |
73300339 CS |
49 | require_once($CFG->dirroot.'/mod/lti/lib.php');\r |
50 | require_once($CFG->dirroot.'/mod/lti/locallib.php');\r | |
b7e436b0 CS |
51 | \r |
52 | $id = optional_param('id', 0, PARAM_INT); // Course Module ID, or\r | |
73300339 | 53 | $a = optional_param('a', 0, PARAM_INT); // lti ID\r |
b7e436b0 CS |
54 | \r |
55 | if ($id) {\r | |
73300339 | 56 | if (! $cm = get_coursemodule_from_id("lti", $id)) {\r |
b7e436b0 CS |
57 | throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect');\r |
58 | }\r | |
59 | \r | |
60 | if (! $course = $DB->get_record("course", array("id" => $cm->course))) {\r | |
61 | throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured');\r | |
62 | }\r | |
63 | \r | |
73300339 | 64 | if (! $basiclti = $DB->get_record("lti", array("id" => $cm->instance))) {\r |
b7e436b0 CS |
65 | throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect');\r |
66 | }\r | |
67 | \r | |
68 | } else {\r | |
73300339 | 69 | if (! $basiclti = $DB->get_record("lti", array("id" => $a))) {\r |
b7e436b0 CS |
70 | throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course module is incorrect');\r |
71 | }\r | |
72 | if (! $course = $DB->get_record("course", array("id" => $basiclti->course))) {\r | |
73 | throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course is misconfigured');\r | |
74 | }\r | |
73300339 | 75 | if (! $cm = get_coursemodule_from_instance("lti", $basiclti->id, $course->id)) {\r |
b7e436b0 CS |
76 | throw new moodle_exception('generalexceptionmessage', 'error', '', 'Course Module ID was incorrect');\r |
77 | }\r | |
78 | }\r | |
79 | \r | |
73300339 | 80 | $tool = lti_get_tool_by_url_match($basiclti->toolurl);\r |
a0eeacf9 CS |
81 | if($tool){\r |
82 | $toolconfig = lti_get_type_config($tool->id);\r | |
83 | } else {\r | |
84 | $toolconfig = array('launchcontainer' => LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS);\r | |
85 | }\r | |
d97d72aa | 86 | \r |
b7e436b0 CS |
87 | $PAGE->set_cm($cm, $course); // set's up global $COURSE\r |
88 | $context = get_context_instance(CONTEXT_MODULE, $cm->id);\r | |
89 | $PAGE->set_context($context);\r | |
90 | \r | |
73300339 | 91 | $url = new moodle_url('/mod/lti/view.php', array('id'=>$cm->id));\r |
b7e436b0 | 92 | $PAGE->set_url($url);\r |
d97d72aa | 93 | \r |
73300339 | 94 | $launchcontainer = $basiclti->launchcontainer == LTI_LAUNCH_CONTAINER_DEFAULT ? \r |
d97d72aa CS |
95 | $toolconfig['launchcontainer'] :\r |
96 | $basiclti->launchcontainer;\r | |
97 | \r | |
73300339 | 98 | if($launchcontainer == LTI_LAUNCH_CONTAINER_EMBED_NO_BLOCKS){\r |
a4a07996 CS |
99 | $PAGE->set_pagelayout('frametop'); //Most frametops don't include footer, and pre-post blocks\r |
100 | $PAGE->blocks->show_only_fake_blocks(); //Disable blocks for layouts which do include pre-post blocks\r | |
d97d72aa CS |
101 | } else {\r |
102 | $PAGE->set_pagelayout('incourse');\r | |
103 | }\r | |
104 | \r | |
b7e436b0 CS |
105 | require_login($course);\r |
106 | \r | |
73300339 | 107 | add_to_log($course->id, "lti", "view", "view.php?id=$cm->id", "$basiclti->id");\r |
b7e436b0 CS |
108 | \r |
109 | $pagetitle = strip_tags($course->shortname.': '.format_string($basiclti->name));\r | |
110 | $PAGE->set_title($pagetitle);\r | |
111 | $PAGE->set_heading($course->fullname);\r | |
112 | \r | |
113 | /// Print the page header\r | |
114 | echo $OUTPUT->header();\r | |
115 | \r | |
d97d72aa CS |
116 | if($basiclti->showtitle) {\r |
117 | /// Print the main part of the page\r | |
118 | echo $OUTPUT->heading(format_string($basiclti->name));\r | |
119 | }\r | |
120 | \r | |
121 | if($basiclti->showdescription && $basiclti->intro){\r | |
122 | echo $OUTPUT->box($basiclti->intro, 'generalbox description', 'intro');\r | |
123 | }\r | |
b7e436b0 | 124 | \r |
b7e436b0 CS |
125 | if ($basiclti->instructorchoiceacceptgrades == 1) {\r |
126 | echo '<div class="reportlink">'.submittedlink($cm).'</div>';\r | |
127 | }\r | |
128 | \r | |
73300339 | 129 | if ( $launchcontainer == LTI_LAUNCH_CONTAINER_WINDOW ) {\r |
d97d72aa | 130 | echo "<script language=\"javascript\">//<![CDATA[\n";\r |
73300339 | 131 | echo "window.open('launch.php?id=".$cm->id."','lti');";\r |
d97d72aa CS |
132 | echo "//]]\n";\r |
133 | echo "</script>\n";\r | |
73300339 | 134 | echo "<p>".get_string("basiclti_in_new_window", "lti")."</p>\n";\r |
b7e436b0 CS |
135 | } else {\r |
136 | // Request the launch content with an object tag\r | |
d97d72aa CS |
137 | echo '<object id="contentframe" height="600px" width="100%" type="text/html" data="launch.php?id='.$cm->id.'&withobject=true"></object>';\r |
138 | \r | |
139 | //Output script to make the object tag be as large as possible\r | |
140 | $resize = <<<'SCRIPT'\r | |
141 | <script type='text/javascript'>\r | |
142 | //<![CDATA[\r | |
143 | (function(){\r | |
144 | //Take scrollbars off the outer document to prevent double scroll bar effect\r | |
145 | document.body.style.overflow = 'hidden';\r | |
146 | \r | |
147 | var dom = YAHOO.util.Dom;\r | |
148 | var frame = document.getElementById('contentframe');\r | |
149 | \r | |
150 | var lastHeight;\r | |
151 | \r | |
152 | var resize = function(){\r | |
153 | var viewportHeight = dom.getViewportHeight();\r | |
154 | \r | |
155 | if(lastHeight !== Math.min(dom.getDocumentHeight(), viewportHeight)){\r | |
156 | frame.style.height = viewportHeight - dom.getY(frame) + 'px';\r | |
157 | \r | |
158 | lastHeight = Math.min(dom.getDocumentHeight(), dom.getViewportHeight());\r | |
159 | }\r | |
160 | };\r | |
161 | \r | |
162 | resize();\r | |
163 | \r | |
164 | setInterval(resize, 250);\r | |
165 | })();\r | |
a4a07996 | 166 | //]]\r |
d97d72aa CS |
167 | </script>\r |
168 | SCRIPT;\r | |
169 | \r | |
170 | echo $resize;\r | |
b7e436b0 CS |
171 | }\r |
172 | \r | |
b7e436b0 CS |
173 | \r |
174 | /// Finish the page\r | |
175 | echo $OUTPUT->footer();\r |