MDL-50550 wiki: Added unit tests for mod_wiki_get_wikis_by_courses
[moodle.git] / tag / user.php
CommitLineData
6bfe7aac 1<?php
c933a060 2
3require_once('../config.php');
3627b0e3 4require_once('lib.php');
c933a060 5
6$action = optional_param('action', '', PARAM_ALPHA);
3d535996 7$id = optional_param('id', 0, PARAM_INT);
8$tag = optional_param('tag', '', PARAM_TAG);
6bfe7aac 9
c933a060 10require_login();
11
12if (empty($CFG->usetags)) {
aad67397 13 print_error('tagdisabled');
c933a060 14}
15
d3d1fe07 16if (isguestuser()) {
cb1e9c74 17 print_error('noguest');
18}
19
20if (!confirm_sesskey()) {
21 print_error('sesskey');
22}
23
cc033d48 24$usercontext = context_user::instance($USER->id);
cb1e9c74 25
c933a060 26switch ($action) {
27 case 'addinterest':
3d535996 28 if (empty($tag) && $id) { // for backward-compatibility (people saving bookmarks, mostly..)
29 $tag = tag_get_name($id);
6bfe7aac
PS
30 }
31
cc033d48 32 tag_set_add('user', $USER->id, $tag, 'core', $usercontext->id);
c933a060 33
3d535996 34 redirect($CFG->wwwroot.'/tag/index.php?tag='. rawurlencode($tag));
c933a060 35 break;
36
3627b0e3 37 case 'removeinterest':
38 if (empty($tag) && $id) { // for backward-compatibility (people saving bookmarks, mostly..)
39 $tag = tag_get_name($id);
6bfe7aac 40 }
28f64040 41
cc033d48 42 tag_set_delete('user', $USER->id, $tag, 'core', $usercontext->id);
3627b0e3 43
44 redirect($CFG->wwwroot.'/tag/index.php?tag='. rawurlencode($tag));
45 break;
46
c933a060 47 case 'flaginappropriate':
b771b31e 48 require_capability('moodle/tag:flag', context_system::instance());
e11b8b16 49 $tagid = tag_get_id($tag);
e11b8b16
AA
50
51 tag_set_flag($tagid);
6bfe7aac 52
3d535996 53 redirect($CFG->wwwroot.'/tag/index.php?tag='. rawurlencode($tag), get_string('responsiblewillbenotified', 'tag'));
c933a060 54 break;
3627b0e3 55
56 default:
aad67397 57 print_error('unknowaction');
3627b0e3 58 break;
c933a060 59}