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 * This page allows instructors to configure course level tool providers.
21 * @copyright Copyright (c) 2011 Moodlerooms Inc. (http://www.moodlerooms.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @author Chris Scribner
26 require_once('../../config.php');
27 require_once($CFG->dirroot
.'/mod/lti/edit_form.php');
28 require_once($CFG->dirroot
.'/mod/lti/lib.php');
30 $courseid = required_param('course', PARAM_INT
);
32 require_login($courseid, false);
33 $url = new moodle_url('/mod/lti/instructor_edit_tool_type.php');
35 $PAGE->set_pagelayout('popup');
36 $PAGE->set_title(get_string('edittype', 'mod_lti'));
38 $action = optional_param('action', null, PARAM_TEXT
);
39 $typeid = optional_param('typeid', null, PARAM_INT
);
43 require_capability('mod/lti:addcoursetool', context_course
::instance($courseid));
45 if (!empty($typeid)) {
46 $type = lti_get_type($typeid);
47 if ($type->course
!= $courseid) {
48 throw new Exception('You do not have permissions to edit this tool type.');
53 // Delete action is called via ajax.
54 if ($action == 'delete') {
55 lti_delete_type($typeid);
59 // Add a timeout for closing for behat so it can check for errors before switching back to the main window.
61 if (defined('BEHAT_SITE_RUNNING') && BEHAT_SITE_RUNNING
) {
65 echo $OUTPUT->header();
67 if ($action == 'edit') {
68 $type = lti_get_type_type_config($typeid);
70 $type = new stdClass();
71 $type->lti_clientid
= null;
74 $form = new mod_lti_edit_types_form($url, (object)array('id' => $typeid, 'clientid' => $type->lti_clientid
));
76 // If the user just opened an add or edit form.
77 if ($action == 'add' ||
$action == 'edit') {
78 if ($action == 'edit') {
79 $form->set_data($type);
81 echo $OUTPUT->heading(get_string('toolsetup', 'lti'));
86 setTimeout(function() {
91 if ($data = $form->get_data()) {
92 $type = new stdClass();
94 if (!empty($typeid)) {
97 lti_load_type_if_cartridge($data);
99 lti_update_type($type, $data);
101 $fromdb = lti_get_type($typeid);
102 $json = json_encode($fromdb);
104 // Output script to update the calling window.
106 window.opener.M.mod_lti.editor.updateToolType({$json});
109 $type->state
= LTI_TOOL_STATE_CONFIGURED
;
110 $type->course
= $COURSE->id
;
112 lti_load_type_if_cartridge($data);
114 $id = lti_add_type($type, $data);
116 $fromdb = lti_get_type($id);
117 $json = json_encode($fromdb);
119 // Output script to update the calling window.
121 window.opener.M.mod_lti.editor.addToolType({$json});
124 echo html_writer
::script($script . $closewindow);
125 } else if ($form->is_cancelled()) {
126 echo html_writer
::script($closewindow);
128 echo $OUTPUT->heading(get_string('toolsetup', 'lti'));
133 echo $OUTPUT->footer();