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 = get_context_instance(CONTEXT_SYSTEM
);
63 require_login($course->id
);
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' => get_context_instance(CONTEXT_COURSE
, $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 = coursetag_print_cloud(coursetag_get_tags(0, $USER->id
, 'default'), 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 $arrowtitle = get_string('arrowtitle', $tagslang);
151 $sesskey = sesskey();
152 $leftarrow = $OUTPUT->pix_url('t/arrow_left');
154 <form action="$CFG->wwwroot/tag/coursetags_edit.php" method="post" id="coursetag">
155 <div style="display: none;">
156 <input type="hidden" name="courseid" value="$course->id" />
157 <input type="hidden" name="sesskey" value="$sesskey" />
159 <div class="coursetag_edit_centered">
160 <div class="coursetag_edit_row">
161 <div class="coursetag_edit_left">
164 <div class="coursetag_edit_right">
165 <div class="coursetag_form_input1">
166 <input type="text" name="coursetag_sug_keyword" class="coursetag_form_input1a" disabled="disabled" />
168 <div class="coursetag_form_input2">
169 <input type="text" name="coursetag_new_tag" id="coursetag_new_tag" class="coursetag_form_input2a"
170 onfocus="ctags_getKeywords()" onkeyup="ctags_getKeywords()" maxlength="50" />
172 <div class="coursetag_edit_input3" id="coursetag_sug_btn">
173 <a title="$arrowtitle">
174 <img src="$leftarrow" width="10" height="10" alt="enter" onclick="ctags_setKeywords()" />
181 $editdeletemytag = get_string('editdeletemytag', $tagslang);
183 <div class="coursetag_edit_row">
184 <div class="coursetag_edit_left">
187 <div class="coursetag_edit_right">
188 <select name="del_tag">
195 $submitstr = get_string('submit');
197 <div class="clearer"></div>
198 <div class="coursetag_edit_row">
199 <button type="submit">$submitstr</button>
207 echo $OUTPUT->footer();