3 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
21 * @copyright 2007 Luiz Cruz <luiz.laydner@gmail.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once('../config.php');
26 require_once($CFG->libdir
.'/tablelib.php');
27 require_once('lib.php');
28 require_once($CFG->libdir
.'/adminlib.php');
30 define('SHOW_ALL_PAGE_SIZE', 50000);
31 define('DEFAULT_PAGE_SIZE', 30);
33 $tagschecked = optional_param_array('tagschecked', array(), PARAM_INT
);
34 $tagid = optional_param('tagid', null, PARAM_INT
);
35 $tagtype = optional_param('tagtype', null, PARAM_ALPHA
);
36 $action = optional_param('action', '', PARAM_ALPHA
);
37 $perpage = optional_param('perpage', DEFAULT_PAGE_SIZE
, PARAM_INT
);
38 $page = optional_param('page', 0, PARAM_INT
);
39 $notice = optional_param('notice', '', PARAM_ALPHA
);
43 if (empty($CFG->usetags
)) {
44 print_error('tagsaredisabled', 'tag');
48 if ($perpage != DEFAULT_PAGE_SIZE
) {
49 $params['perpage'] = $perpage;
52 $params['page'] = $page;
54 admin_externalpage_setup('managetags', '', $params, '', array('pagelayout' => 'report'));
56 $PAGE->set_blocks_editing_capability('moodle/tag:editblocks');
62 if (!$tagschecked && $tagid) {
63 $tagschecked = array($tagid);
65 tag_delete($tagschecked);
66 redirect(new moodle_url($PAGE->url
, array('notice' => 'deleted')));
72 redirect(new moodle_url($PAGE->url
, array('notice' => 'flagged')));
77 tag_unset_flag($tagid);
78 redirect(new moodle_url($PAGE->url
, array('notice' => 'resetflag')));
83 if ($tagtype === 'official' ||
$tagtype === 'default') {
84 if (tag_type_set($tagid, $tagtype)) {
85 redirect(new moodle_url($PAGE->url
, array('notice' => 'typechanged')));
91 case 'addofficialtag':
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
));
99 foreach ($newtags as $newotag) {
100 if ($newotagid = tag_get_id($newotag) ) {
101 // Tag exists, change the type.
102 tag_type_set($newotagid, 'official');
104 tag_add($newotag, 'official');
107 redirect(new moodle_url($PAGE->url
, array('notice' => 'added')));
111 echo $OUTPUT->header();
113 if ($notice && get_string_manager()->string_exists($notice, 'tag')) {
114 echo $OUTPUT->notification(get_string($notice, 'tag'), 'notifysuccess');
117 // Small form to add an official tag.
118 print('<form class="tag-addtags-form" method="post" action="'.$CFG->wwwroot
.'/tag/manage.php">');
119 print('<input type="hidden" name="action" value="addofficialtag" />');
120 print('<input type="hidden" name="perpage" value="'.$perpage.'" />');
121 print('<input type="hidden" name="page" value="'.$page.'" />');
122 print('<div class="tag-management-form generalbox"><label class="accesshide" for="id_otagsadd">' .
123 get_string('addotags', 'tag') .'</label>'.
124 '<input name="otagsadd" id="id_otagsadd" type="text" />'.
125 '<input type="hidden" name="sesskey" value="'.sesskey().'">'.
126 '<input name="addotags" value="'. get_string('addotags', 'tag') .
127 '" onclick="skipClientValidation = true;" id="id_addotags" type="submit" />'.
131 $table = new core_tag_manage_table();
132 echo '<form class="tag-management-form" method="post" action="'.$CFG->wwwroot
.'/tag/manage.php">';
133 echo html_writer
::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
134 echo html_writer
::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'delete'));
135 echo html_writer
::empty_tag('input', array('type' => 'hidden', 'name' => 'perpage', 'value' => $perpage));
136 echo html_writer
::empty_tag('input', array('type' => 'hidden', 'name' => 'page', 'value' => $page));
137 echo $table->out($perpage, true);
139 echo html_writer
::start_tag('p');
140 echo html_writer
::tag('button', get_string('deleteselected', 'tag'),
141 array('id' => 'tag-management-delete', 'type' => 'submit', 'class' => 'tagdeleteselected'));
142 echo html_writer
::end_tag('p');
145 $totalcount = $table->totalcount
;
146 if ($perpage == SHOW_ALL_PAGE_SIZE
) {
147 echo html_writer
::start_tag('div', array('id' => 'showall'));
148 $params = array('perpage' => DEFAULT_PAGE_SIZE
, 'page' => 0);
149 $url = new moodle_url($PAGE->url
, $params);
150 echo html_writer
::link($url, get_string('showperpage', '', DEFAULT_PAGE_SIZE
));
151 echo html_writer
::end_tag('div');
152 } else if ($totalcount > 0 and $perpage < $totalcount) {
153 echo html_writer
::start_tag('div', array('id' => 'showall'));
154 $params = array('perpage' => SHOW_ALL_PAGE_SIZE
, 'page' => 0);
155 $url = new moodle_url($PAGE->url
, $params);
156 echo html_writer
::link($url, get_string('showall', '', $totalcount));
157 echo html_writer
::end_tag('div');
160 echo $OUTPUT->footer();