Merge branch 'MDL-51017-master' of git://github.com/jleyva/moodle
[moodle.git] / course / tags.php
blob8e81fb1e79e660562104a96ed86dcca03eea2acc
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 . '/tag/lib.php');
27 require_once($CFG->dirroot . '/course/tags_form.php');
29 $id = required_param('id', PARAM_INT); // Course id.
30 $returnurl = optional_param('return', null, PARAM_LOCALURL);
31 $course = get_course($id);
33 require_login();
35 // Check capabilities but do not call require_login($course) - the user does not have to be enrolled.
36 $context = context_course::instance($course->id);
37 if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) {
38 print_error('coursehidden', '', $CFG->wwwroot .'/');
40 require_capability('moodle/course:tag', $context);
41 if (empty($CFG->usetags)) {
42 print_error('tagsaredisabled', 'tag');
45 $PAGE->set_course($course);
46 $PAGE->set_pagelayout('incourse');
47 $PAGE->set_url('/course/tags.php', array('id' => $course->id));
48 $PAGE->set_title(get_string('coursetags', 'tag'));
49 $PAGE->set_heading($course->fullname);
51 $form = new coursetags_form();
52 $data = array('id' => $course->id, 'tags' => tag_get_tags_array('course', $course->id));
53 $form->set_data($data);
55 $redirecturl = $returnurl ? new moodle_url($returnurl) : course_get_url($course);
56 if ($form->is_cancelled()) {
57 redirect($redirecturl);
58 } else if ($data = $form->get_data()) {
59 tag_set('course', $course->id, $data->tags, 'core', context_course::instance($course->id)->id);
60 redirect($redirecturl);
63 echo $OUTPUT->header();
64 echo $OUTPUT->heading(get_string('coursetags', 'tag'));
66 $form->display();
68 echo $OUTPUT->footer();