MDL-32053 question: Question bank table displayed inconsistently
[moodle.git] / tag / coursetags_edit.php
blob8bb33b4a74f97facb8552800ac1d83d768e71a8c
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
18 /**
19 * Displays personal tags for a course with some editing facilites
21 * @package core_tag
22 * @category tag
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);
42 if ($deltag !== 0) {
43 $url->param('del_tag', $deltag);
45 $PAGE->set_url($url);
47 require_login();
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');
57 } else {
58 print_error('errortagfrontpage', 'tag');
61 // Permissions
62 $sitecontext = get_context_instance(CONTEXT_SYSTEM);
63 require_login($course->id);
64 $canedit = has_capability('moodle/tag:create', $sitecontext);
66 // Language strings
67 $tagslang = 'block_tags';
69 // Store data
70 if ($data = data_submitted()) {
71 if (confirm_sesskey() and $courseid > 0 and $USER->id > 0 and $canedit) {
72 // store personal tag
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
79 if ($deltag > 0) {
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);
100 $outstr = '
101 <div class="coursetag_edit_centered">
102 <div>
103 '.get_string('editmytags', $tagslang).'
104 </div>
105 <div>';
107 if ($mytags) {
108 $outstr .= $mytags;
109 } else {
110 $outstr .= get_string('editnopersonaltags', $tagslang);
113 $outstr .= '
114 </div>
115 </div>';
116 echo $outstr;
118 // Personal tag editing
119 if ($canedit) {
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>';
125 $coursetabs = '';
126 if ($options = coursetag_get_records($courseid, $USER->id)) {
127 $coursetabs = '"';
128 foreach ($options as $option) {
129 $selectoptions .= '<option value="'.$option->id.'">'.$option->rawname.'</option>';
130 $coursetabs .= $option->rawname . ', ';
132 $coursetabs = rtrim($coursetabs, ', ');
133 $coursetabs .= '"';
135 if ($coursetabs) {
136 $outstr = '
137 <div class="coursetag_edit_centered">
138 '.get_string('editthiscoursetags', $tagslang, $coursetabs).'
139 </div>';
140 } else {
141 $outstr = '
142 <div class="coursetag_edit_centered">
143 '.get_string('editnopersonaltags', $tagslang).'
144 </div>';
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');
153 $outstr .= <<<EOT
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" />
158 </div>
159 <div class="coursetag_edit_centered">
160 <div class="coursetag_edit_row">
161 <div class="coursetag_edit_left">
162 $edittagthisunit
163 </div>
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" />
167 </div>
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" />
171 </div>
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()" />
175 </a>
176 </div>
177 </div>
178 </div>
179 EOT;
180 if ($coursetabs) {
181 $editdeletemytag = get_string('editdeletemytag', $tagslang);
182 $outstr .= <<<EOT1
183 <div class="coursetag_edit_row">
184 <div class="coursetag_edit_left">
185 $editdeletemytag
186 </div>
187 <div class="coursetag_edit_right">
188 <select name="del_tag">
189 $selectoptions
190 </select>
191 </div>
192 </div>
193 EOT1;
195 $submitstr = get_string('submit');
196 $outstr .= <<<EOT2
197 <div class="clearer"></div>
198 <div class="coursetag_edit_row">
199 <button type="submit">$submitstr</button>
200 </div>
201 </div>
202 </form>
203 EOT2;
204 echo $outstr;
207 echo $OUTPUT->footer();