on-demand release 4.2dev+
[moodle.git] / mod / lti / request_tool.php
CommitLineData
c4d80efe 1<?php
61eb12d4
CS
2// This file is part of Moodle - http://moodle.org/
3//
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.
8//
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.
13//
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/>.
16
17/**
8f45215d 18 * Submits a request to administrators to add a tool configuration for the requested site.
61eb12d4 19 *
2b17ec3d 20 * @package mod_lti
8f45215d 21 * @copyright Copyright (c) 2011 Moodlerooms Inc. (http://www.moodlerooms.com)
61eb12d4 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
8f45215d 23 * @author Chris Scribner
61eb12d4 24 */
c4d80efe
CS
25
26require_once('../../config.php');
27require_once($CFG->dirroot.'/mod/lti/lib.php');
42a2c7f1 28require_once($CFG->dirroot.'/mod/lti/locallib.php');
c4d80efe
CS
29
30$instanceid = required_param('instanceid', PARAM_INT);
31
32$lti = $DB->get_record('lti', array('id' => $instanceid));
33$course = $DB->get_record('course', array('id' => $lti->course));
80fd0072 34$cm = get_coursemodule_from_instance('lti', $lti->id, $lti->course, false, MUST_EXIST);
35$context = context_module::instance($cm->id);
c4d80efe
CS
36
37require_login($course);
38
babaf596
DM
39require_sesskey();
40
c288a3db 41require_capability('mod/lti:requesttooladd', context_course::instance($lti->course));
c4d80efe
CS
42
43$baseurl = lti_get_domain_from_url($lti->toolurl);
44
45$url = new moodle_url('/mod/lti/request_tool.php', array('instanceid' => $instanceid));
46$PAGE->set_url($url);
47
48$pagetitle = strip_tags($course->shortname);
49$PAGE->set_title($pagetitle);
50$PAGE->set_heading($course->fullname);
51
52$PAGE->set_pagelayout('incourse');
53
54echo $OUTPUT->header();
80fd0072 55echo $OUTPUT->heading(format_string($lti->name, true, array('context' => $context)));
c4d80efe 56
e3f69b58 57// Add a tool type if one does not exist already.
ea04a9f9 58if (!lti_get_tool_by_url_match($lti->toolurl, $lti->course, LTI_TOOL_STATE_ANY)) {
e3f69b58 59 // There are no tools (active, pending, or rejected) for the launch URL. Create a new pending tool.
c4d80efe
CS
60 $tooltype = new stdClass();
61 $toolconfig = new stdClass();
62
e27cb316 63 $toolconfig->lti_toolurl = lti_get_domain_from_url($lti->toolurl);
c4d80efe
CS
64 $toolconfig->lti_typename = $toolconfig->lti_toolurl;
65
66 lti_add_type($tooltype, $toolconfig);
e27cb316 67
c4d80efe
CS
68 echo get_string('lti_tool_request_added', 'lti');
69} else {
70 echo get_string('lti_tool_request_existing', 'lti');
71}
72
61eb12d4 73echo $OUTPUT->footer();