Merge branch 'MDL-75910-39' of https://github.com/andrewnicols/moodle into MOODLE_39_...
[moodle.git] / tag / user.php
blobffcbfb93a68df6959afe9b807b69d952da1bb4fa
1 <?php
3 require_once('../config.php');
4 require_once('lib.php');
6 $action = optional_param('action', '', PARAM_ALPHA);
8 require_login();
10 if (empty($CFG->usetags)) {
11 print_error('tagdisabled');
14 if (isguestuser()) {
15 print_error('noguest');
18 if (!confirm_sesskey()) {
19 print_error('sesskey');
22 $usercontext = context_user::instance($USER->id);
24 switch ($action) {
25 case 'addinterest':
26 if (!core_tag_tag::is_enabled('core', 'user')) {
27 print_error('tagdisabled');
29 $tag = required_param('tag', PARAM_TAG);
30 core_tag_tag::add_item_tag('core', 'user', $USER->id, $usercontext, $tag);
31 $tc = core_tag_area::get_collection('core', 'user');
32 redirect(core_tag_tag::make_url($tc, $tag));
33 break;
35 case 'removeinterest':
36 if (!core_tag_tag::is_enabled('core', 'user')) {
37 print_error('tagdisabled');
39 $tag = required_param('tag', PARAM_TAG);
40 core_tag_tag::remove_item_tag('core', 'user', $USER->id, $tag);
41 $tc = core_tag_area::get_collection('core', 'user');
42 redirect(core_tag_tag::make_url($tc, $tag));
43 break;
45 case 'flaginappropriate':
46 require_capability('moodle/tag:flag', context_system::instance());
47 $id = required_param('id', PARAM_INT);
48 $tagobject = core_tag_tag::get($id, '*', MUST_EXIST);
49 $tagobject->flag();
50 redirect($tagobject->get_view_url(), get_string('responsiblewillbenotified', 'tag'));
51 break;
53 default:
54 print_error('unknowaction');
55 break;