MDL-44616 behat: Adding steps to test MDLQA-1709 and MDLQA-62
[moodle.git] / mod / lti / instructor_edit_tool_type.php
blob2a2cefbaebb4a9d7115c7be448a9360909204017
1 <?php
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.
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/>.
17 /**
18 * This page allows instructors to configure course level tool providers.
20 * @package mod_lti
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');
33 $PAGE->set_url($url);
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.');
45 die;
49 $form = new mod_lti_edit_types_form();
50 if ($data = $form->get_data()) {
51 $type = new stdClass();
53 if (!empty($typeid)) {
54 $type->id = $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.
63 $script = "
64 <html>
65 <script type=\"text/javascript\">
66 window.opener.M.mod_lti.editor.updateToolType({$json});
67 window.close();
68 </script>
69 </html>
72 echo $script;
73 die;
74 } else {
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.
84 $script = "
85 <html>
86 <script type=\"text/javascript\">
87 window.opener.M.mod_lti.editor.addToolType({$json});
88 window.close();
89 </script>
90 </html>
93 echo $script;
95 die;
97 } else if ($form->is_cancelled()) {
98 $script = "
99 <html>
100 <script type=\"text/javascript\">
101 window.close();
102 </script>
103 </html>
106 echo $script;
107 die;
110 //Delete action is called via ajax
111 if ($action == 'delete') {
112 lti_delete_type($typeid);
113 die;
116 echo $OUTPUT->header();
118 echo $OUTPUT->heading(get_string('toolsetup', 'lti'));
120 if ($action == 'add') {
121 $form->display();
122 } else if ($action == 'edit') {
123 $type = lti_get_type_type_config($typeid);
124 $form->set_data($type);
125 $form->display();
128 echo $OUTPUT->footer();