2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
19 * Displays personal tags for a course with some editing facilites
23 * @copyright 2007 j.beedell@open.ac.uk
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require_once('../config.php');
28 require_once($CFG->dirroot
.'/tag/coursetagslib.php');
29 require_once($CFG->dirroot
.'/tag/lib.php');
31 $courseid = optional_param('courseid', 0, PARAM_INT
);
32 $keyword = optional_param('coursetag_new_tag', '', PARAM_TEXT
);
33 $deltag = optional_param('del_tag', 0, PARAM_INT
);
35 $url = new moodle_url('/tag/coursetags_edit.php');
36 if ($courseid !== 0) {
37 $url->param('courseid', $courseid);
39 if ($keyword !== '') {
40 $url->param('coursetag_new_tag', $keyword);
43 $url->param('del_tag', $deltag);
49 if (empty($CFG->usetags
)) {
50 print_error('tagsaredisabled', 'tag');
53 if ($courseid != SITEID
) {
54 if (! ($course = $DB->get_record('course', array('id' => $courseid), '*')) ) {
55 print_error('invalidcourse');
58 print_error('errortagfrontpage', 'tag');
62 $sitecontext = context_system
::instance();
63 require_login($course);
64 $canedit = has_capability('moodle/tag:create', $sitecontext);
67 $tagslang = 'block_tags';
70 if ($data = data_submitted()) {
71 if (confirm_sesskey() and $courseid > 0 and $USER->id
> 0 and $canedit) {
73 if (trim(strip_tags($keyword))) {
74 $myurl = 'tag/search.php';
75 $keywords = explode(',', $keyword);
76 coursetag_store_keywords($keywords, $courseid, $USER->id
, 'default', $myurl);
78 // delete personal tag
80 coursetag_delete_keyword($deltag, $USER->id
, $courseid);
85 // The title and breadcrumb
86 $title = get_string('edittitle', $tagslang);
87 $coursefullname = format_string($course->fullname
);
88 $courseshortname = format_string($course->shortname
, true, array('context' => context_course
::instance($course->id
)));
89 $PAGE->navbar
->add($title);
90 $PAGE->set_title($title);
91 $PAGE->set_heading($course->fullname
);
92 $PAGE->set_cacheable(false);
93 echo $OUTPUT->header();
95 // Print personal tags for all courses
96 $title = get_string('edittitle', $tagslang);
97 echo $OUTPUT->heading($title, 2, 'mdl-align');
99 $mytags = tag_print_cloud(coursetag_get_tags(0, $USER->id
, 'default'), 150, true);
101 <div class="coursetag_edit_centered">
103 '.get_string('editmytags', $tagslang).'
110 $outstr .= get_string('editnopersonaltags', $tagslang);
118 // Personal tag editing
120 $title = get_string('editmytagsfor', $tagslang, '"'.$coursefullname.' ('.$courseshortname.')"');
121 echo $OUTPUT->heading($title, 2, 'main mdl-align');
123 // Deletion here is open to the users own tags for this course only
124 $selectoptions = '<option value="0">'.get_string('select', $tagslang).'</option>';
126 if ($options = coursetag_get_records($courseid, $USER->id
)) {
128 foreach ($options as $option) {
129 $selectoptions .= '<option value="'.$option->id
.'">'.$option->rawname
.'</option>';
130 $coursetabs .= $option->rawname
. ', ';
132 $coursetabs = rtrim($coursetabs, ', ');
137 <div class="coursetag_edit_centered">
138 '.get_string('editthiscoursetags', $tagslang, $coursetabs).'
142 <div class="coursetag_edit_centered">
143 '.get_string('editnopersonaltags', $tagslang).'
147 // Print the add and delete form
148 coursetag_get_jscript();
149 $edittagthisunit = get_string('edittagthisunit', $tagslang);
150 $suggestedtagthisunit = get_string('suggestedtagthisunit', $tagslang);
151 $arrowtitle = get_string('arrowtitle', $tagslang);
152 $sesskey = sesskey();
153 $leftarrow = $OUTPUT->pix_url('t/arrow_left');
155 <form action="$CFG->wwwroot/tag/coursetags_edit.php" method="post" id="coursetag">
156 <div style="display: none;">
157 <input type="hidden" name="courseid" value="$course->id" />
158 <input type="hidden" name="sesskey" value="$sesskey" />
160 <div class="coursetag_edit_centered">
161 <div class="coursetag_edit_row">
162 <div class="coursetag_edit_left">
163 <label class="accesshide" for="coursetag_sug_keyword">$suggestedtagthisunit</label>
165 <div class="coursetag_edit_right">
166 <div class="coursetag_form_input1">
167 <input type="text" name="coursetag_sug_keyword" id="coursetag_sug_keyword" class="coursetag_form_input1a" disabled="disabled" />
171 <div class="coursetag_edit_row">
172 <div class="coursetag_edit_left">
173 <label for="coursetag_new_tag">$edittagthisunit</label>
175 <div class="coursetag_edit_right">
176 <div class="coursetag_form_input2">
177 <input type="text" name="coursetag_new_tag" id="coursetag_new_tag" class="coursetag_form_input2a"
178 onfocus="ctags_getKeywords()" onkeyup="ctags_getKeywords()" maxlength="50" />
180 <div class="coursetag_edit_input3" id="coursetag_sug_btn">
181 <a title="$arrowtitle">
182 <img src="$leftarrow" width="10" height="10" alt="enter" onclick="ctags_setKeywords()" />
189 $editdeletemytag = get_string('editdeletemytag', $tagslang);
191 <div class="coursetag_edit_row">
192 <div class="coursetag_edit_left">
193 <label for="del_tag">
197 <div class="coursetag_edit_right">
198 <select id="del_tag" name="del_tag">
205 $submitstr = get_string('submit');
207 <div class="clearer"></div>
208 <div class="coursetag_edit_row">
209 <button type="submit">$submitstr</button>
217 echo $OUTPUT->footer();