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. 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 /** 18 * Page allowing instructors to configure course-level tools. 19 * 20 * @package mod_lti 21 * @copyright 2023 Jake Dallimore <jrhdallimore@gmail.com> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 use core\output\notification; 26 27 require_once('../../config.php'); 28 require_once($CFG->dirroot.'/mod/lti/edit_form.php'); 29 require_once($CFG->dirroot.'/mod/lti/lib.php'); 30 31 $courseid = required_param('course', PARAM_INT); 32 $typeid = optional_param('typeid', null, PARAM_INT); 33 34 // Permissions etc. 35 require_login($courseid, false); 36 require_capability('mod/lti:addcoursetool', context_course::instance($courseid)); 37 if (!empty($typeid)) { 38 $type = lti_get_type_type_config($typeid); 39 if ($type->course != $courseid || $type->course == get_site()->id) { 40 throw new moodle_exception('You do not have permissions to edit this tool type.'); 41 } 42 } else { 43 $type = (object) ['lti_clientid' => null]; 44 } 45 46 // Page setup. 47 $url = new moodle_url('/mod/lti/coursetooledit.php', ['courseid' => $courseid]); 48 $pageheading = !empty($typeid) ? get_string('courseexternaltooledit', 'mod_lti', $type->lti_typename) : 49 get_string('courseexternaltooladd', 'mod_lti'); 50 51 $PAGE->set_url($url); 52 $PAGE->set_pagelayout('incourse'); 53 $PAGE->set_title($pageheading); 54 $PAGE->set_secondary_active_tab('coursetools'); 55 $PAGE->add_body_class('limitedwidth'); 56 57 $form = new mod_lti_edit_types_form($url, (object)array('id' => $typeid, 'clientid' => $type->lti_clientid, 'iscoursetool' => true)); 58 if ($form->is_cancelled()) { 59 60 redirect(new moodle_url('/mod/lti/coursetools.php', ['id' => $courseid])); 61 } else if ($data = $form->get_data()) { 62 63 require_sesskey(); 64 65 if (!empty($data->typeid)) { 66 $type = (object) ['id' => $data->typeid]; 67 lti_load_type_if_cartridge($data); 68 lti_update_type($type, $data); 69 $redirecturl = new moodle_url('/mod/lti/coursetools.php', ['id' => $courseid]); 70 $notice = get_string('courseexternaltooleditsuccess', 'mod_lti'); 71 } else { 72 $type = (object) ['state' => LTI_TOOL_STATE_CONFIGURED, 'course' => $data->course]; 73 lti_load_type_if_cartridge($data); 74 lti_add_type($type, $data); 75 $redirecturl = new moodle_url('/mod/lti/coursetools.php', ['id' => $courseid]); 76 $notice = get_string('courseexternaltooladdsuccess', 'mod_lti', $type->name); 77 } 78 79 redirect($redirecturl, $notice, 0, notification::NOTIFY_SUCCESS); 80 } 81 82 // Display the form. 83 echo $OUTPUT->header(); 84 echo $OUTPUT->heading($pageheading); 85 86 if (!empty($typeid)) { 87 $form->set_data($type); 88 } 89 $form->display(); 90 91 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body