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');
29 $courseid = required_param('course', PARAM_INT
);
31 require_login($courseid, false);
32 $url = new moodle_url('/mod/lti/instructor_edit_tool_type.php');
34 $PAGE->set_pagelayout('popup');
36 $action = optional_param('action', null, PARAM_TEXT
);
37 $typeid = optional_param('typeid', null, PARAM_INT
);
39 require_capability('mod/lti:addcoursetool', context_course
::instance($courseid));
41 if (!empty($typeid)) {
42 $type = lti_get_type($typeid);
43 if ($type->course
!= $courseid) {
44 throw new Exception('You do not have permissions to edit this tool type.');
49 $form = new mod_lti_edit_types_form();
50 if ($data = $form->get_data()) {
51 $type = new stdClass();
53 if (!empty($typeid)) {
55 $name = json_encode($data->lti_typename
);
57 lti_update_type($type, $data);
59 $fromdb = lti_get_type($typeid);
60 $json = json_encode($fromdb);
62 //Output script to update the calling window.
65 <script type=\"text/javascript\">
66 window.opener.M.mod_lti.editor.updateToolType({$json});
75 $type->state
= LTI_TOOL_STATE_CONFIGURED
;
76 $type->course
= $COURSE->id
;
78 $id = lti_add_type($type, $data);
80 $fromdb = lti_get_type($id);
81 $json = json_encode($fromdb);
83 //Output script to update the calling window.
86 <script type=\"text/javascript\">
87 window.opener.M.mod_lti.editor.addToolType({$json});
97 } else if ($form->is_cancelled()) {
100 <script type=\"text/javascript\">
110 //Delete action is called via ajax
111 if ($action == 'delete') {
112 lti_delete_type($typeid);
116 echo $OUTPUT->header();
118 echo $OUTPUT->heading(get_string('toolsetup', 'lti'));
120 if ($action == 'add') {
122 } else if ($action == 'edit') {
123 $type = lti_get_type_type_config($typeid);
124 $form->set_data($type);
128 echo $OUTPUT->footer();