MDL-71913 mod_folder: Add tertiary navigation
[moodle.git] / course / tags.php
blob1c7ad66aedd2280a53d88f33c941fea879d86501
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 * Edit course tags
20 * @package core_course
21 * @copyright 2015 Marina Glancy
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once("../config.php");
26 require_once($CFG->dirroot . '/course/tags_form.php');
28 $id = required_param('id', PARAM_INT); // Course id.
29 $returnurl = optional_param('return', null, PARAM_LOCALURL);
30 $course = get_course($id);
32 require_login();
34 // Check capabilities but do not call require_login($course) - the user does not have to be enrolled.
35 $context = context_course::instance($course->id);
36 if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
37 print_error('coursehidden', '', $CFG->wwwroot .'/');
39 require_capability('moodle/course:tag', $context);
40 if (!core_tag_tag::is_enabled('core', 'course')) {
41 print_error('tagsaredisabled', 'tag');
44 $PAGE->set_course($course);
45 $PAGE->set_pagelayout('incourse');
46 $PAGE->set_url('/course/tags.php', array('id' => $course->id));
47 $PAGE->set_title(get_string('coursetags', 'tag'));
48 $PAGE->set_heading($course->fullname);
50 $form = new coursetags_form();
51 $data = array('id' => $course->id, 'tags' => core_tag_tag::get_item_tags_array('core', 'course', $course->id));
52 $form->set_data($data);
54 $redirecturl = $returnurl ? new moodle_url($returnurl) : course_get_url($course);
55 if ($form->is_cancelled()) {
56 redirect($redirecturl);
57 } else if ($data = $form->get_data()) {
58 core_tag_tag::set_item_tags('core', 'course', $course->id, context_course::instance($course->id), $data->tags);
59 redirect($redirecturl);
62 echo $OUTPUT->header();
63 echo $OUTPUT->heading(get_string('coursetags', 'tag'));
65 $form->display();
67 echo $OUTPUT->footer();