2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * MRTODO: Brief description of this file
22 * @copyright 2011 onwards MRTODO
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once('../../config.php');
27 require_once($CFG->dirroot.'/mod/lti/lib.php');
29 $instanceid = required_param('instanceid', PARAM_INT);
31 $lti = $DB->get_record('lti', array('id' => $instanceid));
32 $course = $DB->get_record('course', array('id' => $lti->course));
34 require_login($course);
36 require_capability('mod/lti:requesttooladd', get_context_instance(CONTEXT_COURSE, $lti->course));
38 $baseurl = lti_get_domain_from_url($lti->toolurl);
40 $url = new moodle_url('/mod/lti/request_tool.php', array('instanceid' => $instanceid));
43 $pagetitle = strip_tags($course->shortname);
44 $PAGE->set_title($pagetitle);
45 $PAGE->set_heading($course->fullname);
47 $PAGE->set_pagelayout('incourse');
49 echo $OUTPUT->header();
51 //Add a tool type if one does not exist already
52 if (!lti_get_tool_by_url_match($lti->toolurl, $lti->course, LTI_TOOL_STATE_ANY)) {
53 //There are no tools (active, pending, or rejected) for the launch URL. Create a new pending tool
54 $tooltype = new stdClass();
55 $toolconfig = new stdClass();
57 $toolconfig->lti_toolurl = lti_get_domain_from_url($lti->toolurl);
58 $toolconfig->lti_typename = $toolconfig->lti_toolurl;
60 lti_add_type($tooltype, $toolconfig);
62 echo get_string('lti_tool_request_added', 'lti');
64 echo get_string('lti_tool_request_existing', 'lti');
67 echo $OUTPUT->footer();