MDL-50550 wiki: Added unit tests for mod_wiki_get_wikis_by_courses
[moodle.git] / tag / manage.php
CommitLineData
6bfe7aac 1<?php
c933a060 2
000ebd5c
DM
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * @package core
20 * @subpackage tag
21 * @copyright 2007 Luiz Cruz <luiz.laydner@gmail.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
c933a060 25require_once('../config.php');
70e9b59d 26require_once($CFG->libdir.'/tablelib.php');
c933a060 27require_once('lib.php');
823c593f 28require_once($CFG->libdir.'/adminlib.php');
70e9b59d 29
30define('SHOW_ALL_PAGE_SIZE', 50000);
31define('DEFAULT_PAGE_SIZE', 30);
32
18bd7573 33$tagschecked = optional_param_array('tagschecked', array(), PARAM_INT);
8e355853
MG
34$tagid = optional_param('tagid', null, PARAM_INT);
35$tagtype = optional_param('tagtype', null, PARAM_ALPHA);
70e9b59d 36$action = optional_param('action', '', PARAM_ALPHA);
37$perpage = optional_param('perpage', DEFAULT_PAGE_SIZE, PARAM_INT);
8e355853
MG
38$page = optional_param('page', 0, PARAM_INT);
39$notice = optional_param('notice', '', PARAM_ALPHA);
c933a060 40
41require_login();
42
70e9b59d 43if (empty($CFG->usetags)) {
f7ed2687 44 print_error('tagsaredisabled', 'tag');
c933a060 45}
46
0edd6535 47$params = array();
48if ($perpage != DEFAULT_PAGE_SIZE) {
49 $params['perpage'] = $perpage;
50}
8e355853
MG
51if ($page > 0) {
52 $params['page'] = $page;
53}
54admin_externalpage_setup('managetags', '', $params, '', array('pagelayout' => 'report'));
823c593f 55
0edd6535 56$PAGE->set_blocks_editing_capability('moodle/tag:editblocks');
823c593f 57
c933a060 58switch($action) {
3a597ace 59
c933a060 60 case 'delete':
8e355853
MG
61 require_sesskey();
62 if (!$tagschecked && $tagid) {
63 $tagschecked = array($tagid);
70e9b59d 64 }
3d535996 65 tag_delete($tagschecked);
8e355853 66 redirect(new moodle_url($PAGE->url, array('notice' => 'deleted')));
c933a060 67 break;
70e9b59d 68
8e355853
MG
69 case 'setflag':
70 require_sesskey();
71 tag_set_flag($tagid);
72 redirect(new moodle_url($PAGE->url, array('notice' => 'flagged')));
3a597ace 73 break;
70e9b59d 74
8e355853
MG
75 case 'resetflag':
76 require_sesskey();
77 tag_unset_flag($tagid);
78 redirect(new moodle_url($PAGE->url, array('notice' => 'resetflag')));
79081e87 79 break;
70e9b59d 80
8e355853
MG
81 case 'changetype':
82 require_sesskey();
83 if ($tagtype === 'official' || $tagtype === 'default') {
84 if (tag_type_set($tagid, $tagtype)) {
85 redirect(new moodle_url($PAGE->url, array('notice' => 'typechanged')));
70e9b59d 86 }
3a597ace 87 }
8e355853 88 redirect($PAGE->url);
c933a060 89 break;
8e355853 90
3d535996 91 case 'addofficialtag':
8e355853
MG
92 require_sesskey();
93 $otagsadd = optional_param('otagsadd', '', PARAM_RAW);
94 $newtags = preg_split('/\s*,\s*/', trim($otagsadd), -1, PREG_SPLIT_NO_EMPTY);
95 $newtags = array_filter(tag_normalize($newtags, TAG_CASE_ORIGINAL));
96 if (!$newtags) {
97 redirect($PAGE->url);
e35139b7 98 }
8e355853
MG
99 foreach ($newtags as $newotag) {
100 if ($newotagid = tag_get_id($newotag) ) {
101 // Tag exists, change the type.
102 tag_type_set($newotagid, 'official');
3d535996 103 } else {
8e355853 104 tag_add($newotag, 'official');
3d535996 105 }
3d535996 106 }
8e355853 107 redirect(new moodle_url($PAGE->url, array('notice' => 'added')));
3d535996 108 break;
c933a060 109}
110
8e355853
MG
111echo $OUTPUT->header();
112
113if ($notice && get_string_manager()->string_exists($notice, 'tag')) {
114 echo $OUTPUT->notification(get_string($notice, 'tag'), 'notifysuccess');
2d7e3f9b 115}
3a597ace 116
8e355853
MG
117// Small form to add an official tag.
118print('<form class="tag-addtags-form" method="post" action="'.$CFG->wwwroot.'/tag/manage.php">');
ec6a0e70 119print('<input type="hidden" name="action" value="addofficialtag" />');
8e355853
MG
120print('<input type="hidden" name="perpage" value="'.$perpage.'" />');
121print('<input type="hidden" name="page" value="'.$page.'" />');
122print('<div class="tag-management-form generalbox"><label class="accesshide" for="id_otagsadd">' .
123 get_string('addotags', 'tag') .'</label>'.
ec6a0e70 124 '<input name="otagsadd" id="id_otagsadd" type="text" />'.
e35139b7 125 '<input type="hidden" name="sesskey" value="'.sesskey().'">'.
8e355853
MG
126 '<input name="addotags" value="'. get_string('addotags', 'tag') .
127 '" onclick="skipClientValidation = true;" id="id_addotags" type="submit" />'.
3d535996 128 '</div>');
129print('</form>');
130
8e355853
MG
131$table = new core_tag_manage_table();
132echo '<form class="tag-management-form" method="post" action="'.$CFG->wwwroot.'/tag/manage.php">';
133echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
134echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'delete'));
135echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'perpage', 'value' => $perpage));
136echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'page', 'value' => $page));
137echo $table->out($perpage, true);
138
139echo html_writer::start_tag('p');
140echo html_writer::tag('button', get_string('deleteselected', 'tag'),
141 array('id' => 'tag-management-delete', 'type' => 'submit', 'class' => 'tagdeleteselected'));
142echo html_writer::end_tag('p');
143echo '</form>';
144
145$totalcount = $table->totalcount;
70e9b59d 146if ($perpage == SHOW_ALL_PAGE_SIZE) {
ca2d7327 147 echo html_writer::start_tag('div', array('id' => 'showall'));
8e355853
MG
148 $params = array('perpage' => DEFAULT_PAGE_SIZE, 'page' => 0);
149 $url = new moodle_url($PAGE->url, $params);
ca2d7327
RW
150 echo html_writer::link($url, get_string('showperpage', '', DEFAULT_PAGE_SIZE));
151 echo html_writer::end_tag('div');
70e9b59d 152} else if ($totalcount > 0 and $perpage < $totalcount) {
ca2d7327 153 echo html_writer::start_tag('div', array('id' => 'showall'));
8e355853
MG
154 $params = array('perpage' => SHOW_ALL_PAGE_SIZE, 'page' => 0);
155 $url = new moodle_url($PAGE->url, $params);
ca2d7327
RW
156 echo html_writer::link($url, get_string('showall', '', $totalcount));
157 echo html_writer::end_tag('div');
70e9b59d 158}
e3ff328b 159
1dd2ba54 160echo $OUTPUT->footer();