5 * displays personal tags for a course with some editing facilites
6 * @author j.beedell@open.ac.uk June07
9 require_once('../config.php');
10 require_once($CFG->dirroot
.'/tag/coursetagslib.php');
11 require_once($CFG->dirroot
.'/tag/lib.php');
13 $courseid = optional_param('courseid', 0, PARAM_INT
);
14 $keyword = optional_param('coursetag_new_tag', '', PARAM_TEXT
);
15 $deltag = optional_param('del_tag', 0, PARAM_INT
);
17 $url = new moodle_url('/tag/coursetags_edit.php');
18 if ($courseid !== 0) {
19 $url->param('courseid', $courseid);
21 if ($keyword !== '') {
22 $url->param('coursetag_new_tag', $keyword);
25 $url->param('del_tag', $deltag);
31 if (empty($CFG->usetags
)) {
32 print_error('tagsaredisabled', 'tag');
35 if ($courseid != SITEID
) {
36 if (! ($course = $DB->get_record('course', array('id' => $courseid), '*')) ) {
37 print_error('invalidcourse');
40 print_error('errortagfrontpage', 'tag');
44 $sitecontext = get_context_instance(CONTEXT_SYSTEM
, SITEID
);
45 require_login($course->id
);
46 $canedit = has_capability('moodle/tag:create', $sitecontext);
49 $tagslang = 'block_tags';
52 if ($data = data_submitted()) {
53 if (confirm_sesskey() and $courseid > 0 and $USER->id
> 0 and $canedit) {
55 if (trim(strip_tags($keyword))) {
56 $myurl = 'tag/search.php';
57 $keywords = explode(',', $keyword);
58 coursetag_store_keywords($keywords, $courseid, $USER->id
, 'default', $myurl);
60 // delete personal tag
62 coursetag_delete_keyword($deltag, $USER->id
, $courseid);
67 // The title and breadcrumb
68 $title = get_string('edittitle', $tagslang);
69 $coursefullname = format_string($course->fullname
);
70 $courseshortname = format_string($course->shortname
, true, array('context' => get_context_instance(CONTEXT_COURSE
, $course->id
)));
71 $PAGE->navbar
->add($title);
72 $PAGE->set_title($title);
73 $PAGE->set_heading($course->fullname
);
74 $PAGE->set_cacheable(false);
75 echo $OUTPUT->header();
77 // Print personal tags for all courses
78 $title = get_string('edittitle', $tagslang);
79 echo $OUTPUT->heading($title, 2, 'mdl-align');
81 $mytags = coursetag_print_cloud(coursetag_get_tags(0, $USER->id
, 'default'), true);
83 <div class="coursetag_edit_centered">
85 '.get_string('editmytags', $tagslang).'
92 $outstr .= get_string('editnopersonaltags', $tagslang);
100 // Personal tag editing
102 $title = get_string('editmytagsfor', $tagslang, '"'.$coursefullname.' ('.$courseshortname.')"');
103 echo $OUTPUT->heading($title, 2, 'main mdl-align');
105 // Deletion here is open to the users own tags for this course only
106 $selectoptions = '<option value="0">'.get_string('select', $tagslang).'</option>';
108 if ($options = coursetag_get_records($courseid, $USER->id
)) {
110 foreach ($options as $option) {
111 $selectoptions .= '<option value="'.$option->id
.'">'.$option->rawname
.'</option>';
112 $coursetabs .= $option->rawname
. ', ';
114 $coursetabs = rtrim($coursetabs, ', ');
119 <div class="coursetag_edit_centered">
120 '.get_string('editthiscoursetags', $tagslang, $coursetabs).'
124 <div class="coursetag_edit_centered">
125 '.get_string('editnopersonaltags', $tagslang).'
129 // Print the add and delete form
130 coursetag_get_jscript();
131 $edittagthisunit = get_string('edittagthisunit', $tagslang);
132 $arrowtitle = get_string('arrowtitle', $tagslang);
133 $sesskey = sesskey();
134 $leftarrow = $OUTPUT->pix_url('t/arrow_left');
136 <form action="$CFG->wwwroot/tag/coursetags_edit.php" method="post" id="coursetag">
137 <div style="display: none;">
138 <input type="hidden" name="courseid" value="$course->id" />
139 <input type="hidden" name="sesskey" value="$sesskey" />
141 <div class="coursetag_edit_centered">
142 <div class="coursetag_edit_row">
143 <div class="coursetag_edit_left">
146 <div class="coursetag_edit_right">
147 <div class="coursetag_form_input1">
148 <input type="text" name="coursetag_sug_keyword" class="coursetag_form_input1a" disabled="disabled" />
150 <div class="coursetag_form_input2">
151 <input type="text" name="coursetag_new_tag" id="coursetag_new_tag" class="coursetag_form_input2a"
152 onfocus="ctags_getKeywords()" onkeyup="ctags_getKeywords()" maxlength="50" />
154 <div class="coursetag_edit_input3" id="coursetag_sug_btn">
155 <a title="$arrowtitle">
156 <img src="$leftarrow" width="10" height="10" alt="enter" onclick="ctags_setKeywords()" />
163 $editdeletemytag = get_string('editdeletemytag', $tagslang);
165 <div class="coursetag_edit_row">
166 <div class="coursetag_edit_left">
169 <div class="coursetag_edit_right">
170 <select name="del_tag">
177 $submitstr = get_string('submit');
179 <div class="clearer"></div>
180 <div class="coursetag_edit_row">
181 <button type="submit">$submitstr</button>
189 echo $OUTPUT->footer();