MDL-28048 glossary - fix double ampersand & missing string
[moodle.git] / mod / glossary / editcategories.php
CommitLineData
5fa0208e 1<?php
fb443f1a 2
3/// This page allows to edit entries categories for a particular instance of glossary
4
5fa0208e 5require_once("../../config.php");
6require_once("lib.php");
7
8$id = required_param('id', PARAM_INT); // Course Module ID, or
9$usedynalink = optional_param('usedynalink', 0, PARAM_INT); // category ID
10$confirm = optional_param('confirm', 0, PARAM_INT); // confirm the action
11$name = optional_param('name', '', PARAM_CLEAN); // confirm the name
12
13$action = optional_param('action', '', PARAM_ALPHA ); // what to do
14$hook = optional_param('hook', '', PARAM_ALPHANUM); // category ID
15$mode = optional_param('mode', '', PARAM_ALPHA); // cat
16
17$action = strtolower($action);
18
a6855934 19$url = new moodle_url('/mod/glossary/editcategories.php', array('id'=>$id));
5fa0208e 20if ($usedynalink !== 0) {
21 $url->param('usedynalink', $usedynalink);
22}
23if ($confirm !== 0) {
24 $url->param('confirm', $confirm);
25}
26if ($name !== 'name') {
27 $url->param('name', $name);
28}
29if ($action !== 'action') {
30 $url->param('action', $action);
31}
32if ($hook !== 'hook') {
33 $url->param('hook', $hook);
34}
35if ($mode !== 'mode') {
36 $url->param('mode', $mode);
37}
38
39$PAGE->set_url($url);
40
41if (! $cm = get_coursemodule_from_id('glossary', $id)) {
42 print_error('invalidcoursemodule');
43}
44
45if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
46 print_error('coursemisconf');
47}
48
49if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
50 print_error('invalidcoursemodule');
51}
52
53if ($hook > 0) {
54 if ($category = $DB->get_record("glossary_categories", array("id"=>$hook))) {
55 //Check it belongs to the same glossary
56 if ($category->glossaryid != $glossary->id) {
57 print_error('invalidid', 'glossary');
58 }
59 } else {
60 print_error('invalidcategoryid');
61 }
62}
fb443f1a 63
5fa0208e 64require_login($course->id, false, $cm);
aa813941 65
5fa0208e 66$context = get_context_instance(CONTEXT_MODULE, $cm->id);
67require_capability('mod/glossary:managecategories', $context);
8a2fe407 68
5fa0208e 69$strglossaries = get_string("modulenameplural", "glossary");
70$strglossary = get_string("modulename", "glossary");
ec81373f 71
a6855934 72$PAGE->navbar->add($strglossaries, new moodle_url('/mod/glossary/index.php', array('id'=>$course->id)));
5fa0208e 73$PAGE->navbar->add(get_string("categories","glossary"));
2e4fd166
RW
74if (!empty($action)) {
75 $navaction = get_string($action). " " . moodle_strtolower(get_string("category","glossary"));
76 $PAGE->navbar->add($navaction);
77}
5fa0208e 78$PAGE->set_title(format_string($glossary->name));
2e4fd166 79$PAGE->set_heading($course->fullname);
5fa0208e 80echo $OUTPUT->header();
fb443f1a 81
bce3e3dc
EL
82// Prepare format_string/text options
83$fmtoptions = array(
84 'context' => $context);
85
5fa0208e 86if ( $hook >0 ) {
fb443f1a 87
5fa0208e 88 if ( $action == "edit" ) {
89 if ( $confirm ) {
90 $action = "";
39790bd8 91 $cat = new stdClass();
5fa0208e 92 $cat->id = $hook;
93 $cat->name = $name;
94 $cat->usedynalink = $usedynalink;
00083db4 95
5fa0208e 96 $DB->update_record("glossary_categories", $cat);
97 add_to_log($course->id, "glossary", "edit category", "editcategories.php?id=$cm->id", $hook,$cm->id);
fb443f1a 98
5fa0208e 99 } else {
d427d609 100 echo "<h3 class=\"main\">" . get_string("edit"). " " . get_string("category","glossary") . "</h3>";
fb443f1a 101
5fa0208e 102 $name = $category->name;
103 $usedynalink = $category->usedynalink;
104 require "editcategories.html";
105 echo $OUTPUT->footer();
106 die;
107 }
fb443f1a 108
5fa0208e 109 } elseif ( $action == "delete" ) {
110 if ( $confirm ) {
111 $DB->delete_records("glossary_entries_categories", array("categoryid"=>$hook));
112 $DB->delete_records("glossary_categories", array("id"=>$hook));
fb443f1a 113
5fa0208e 114 echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow');
d427d609 115 echo "<div>" . get_string("categorydeleted","glossary") ."</div>";
5fa0208e 116 echo $OUTPUT->box_end();
61c72439 117
5fa0208e 118 add_to_log($course->id, "glossary", "delete category", "editcategories.php?id=$cm->id", $hook,$cm->id);
61c72439 119
5fa0208e 120 redirect("editcategories.php?id=$cm->id");
121 } else {
d427d609 122 echo "<p>" . get_string("delete"). " " . get_string("category","glossary"). "</p>";
90ee78e2 123
5fa0208e 124 echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow');
bce3e3dc 125 echo "<div class=\"boxaligncenter deletecatconfirm\">".format_string($category->name, true, $fmtoptions)."<br/>";
61c72439 126
5fa0208e 127 $num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id));
128 if ( $num_entries ) {
129 print_string("deletingnoneemptycategory","glossary");
61c72439 130 }
5fa0208e 131 echo "<p>";
132 print_string("areyousuredelete","glossary");
133 echo "</p>";
61c72439 134?>
5bd76d7f 135
d427d609 136 <table border="0" width="100" class="confirmbuttons">
5bd76d7f 137 <tr>
1adbd2c3 138 <td align="right" style="width:50%">
5bd76d7f 139 <form id="form" method="post" action="editcategories.php">
140 <div>
141 <input type="hidden" name="id" value="<?php p($cm->id) ?>" />
142 <input type="hidden" name="action" value="delete" />
143 <input type="hidden" name="confirm" value="1" />
144 <input type="hidden" name="mode" value="<?php echo $mode ?>" />
145 <input type="hidden" name="hook" value="<?php echo $hook ?>" />
146 <input type="submit" value=" <?php print_string("yes")?> " />
147 </div>
148 </form>
149 </td>
150 <td align="left" style="width:50%">
61c72439 151
152<?php
5fa0208e 153 unset($options);
154 $options = array ("id" => $id);
5c2ed7e2 155 echo $OUTPUT->single_button(new moodle_url("editcategories.php", $options), get_string("no"));
5fa0208e 156 echo "</td></tr></table>";
157 echo "</div>";
158 echo $OUTPUT->box_end();
61c72439 159 }
5fa0208e 160 }
161
162} elseif ( $action == "add" ) {
163 if ( $confirm ) {
e99cfeb8 164 $dupcategory = $DB->get_records_sql("SELECT * FROM {glossary_categories} WHERE ".$DB->sql_like('name','?', false)." AND glossaryid=?", array($name, $glossary->id));
5fa0208e 165 if ( $dupcategory ) {
d427d609 166 echo "<h3 class=\"main\">" . get_string("add"). " " . get_string("category","glossary"). "</h3>";
5fa0208e 167
168 echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow');
b86f9306 169 echo "<div>" . get_string("duplicatecategory","glossary") ."</div>";
5fa0208e 170 echo $OUTPUT->box_end();
171
b86f9306 172 redirect("editcategories.php?id=$cm->id&amp;action=add&amp;name=$name");
61c72439 173
61c72439 174 } else {
5fa0208e 175 $action = "";
39790bd8 176 $cat = new stdClass();
5fa0208e 177 $cat->name = $name;
178 $cat->usedynalink = $usedynalink;
179 $cat->glossaryid = $glossary->id;
180
181 $cat->id = $DB->insert_record("glossary_categories", $cat);
182 add_to_log($course->id, "glossary", "add category", "editcategories.php?id=$cm->id", $cat->id,$cm->id);
61c72439 183 }
5fa0208e 184 } else {
d427d609 185 echo "<h3 class=\"main\">" . get_string("add"). " " . get_string("category","glossary"). "</h3>";
5fa0208e 186 $name="";
187 require "editcategories.html";
61c72439 188 }
5fa0208e 189}
ec81373f 190
5fa0208e 191if ( $action ) {
192 echo $OUTPUT->footer();
193 die;
194}
fb443f1a 195
196?>
197
b7dc2256 198<form method="post" action="editcategories.php">
5bd76d7f 199<table width="40%" class="boxaligncenter generalbox" cellpadding="5">
fb443f1a 200 <tr>
d427d609
PM
201 <th style="width:90%" align="center">
202 <?php p(get_string("categories","glossary")) ?></th>
203 <th style="width:10%" align="center">
204 <?php p(get_string("action")) ?></th>
fb443f1a 205 </tr>
5bd76d7f 206 <tr><td style="width:100%" colspan="2">
ec81373f 207
1adbd2c3 208
61c72439 209
ad58adac 210<?php
ae8c3566 211 $categories = $DB->get_records("glossary_categories", array("glossaryid"=>$glossary->id), "name ASC");
61c72439 212
213 if ( $categories ) {
5bd76d7f 214 echo '<table width="100%">';
61c72439 215 foreach ($categories as $category) {
ae8c3566 216 $num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id));
61c72439 217?>
fb443f1a 218
b8340d19 219 <tr>
d427d609 220 <td style="width:80%" align="left">
ad58adac 221 <?php
bce3e3dc 222 echo "<span class=\"bold\">".format_string($category->name, true, $fmtoptions)."</span> <span>($num_entries " . get_string("entries","glossary") . ")</span>";
fb443f1a 223 ?>
224 </td>
d427d609 225 <td style="width:19%" align="center" class="action">
ad58adac 226 <?php
b5d0cafc
PS
227 echo "<a href=\"editcategories.php?id=$cm->id&amp;action=delete&amp;mode=cat&amp;hook=$category->id\"><img alt=\"" . get_string("delete") . "\"src=\"" . $OUTPUT->pix_url('t/delete') . "\" class=\"iconsmall\" /></a> ";
228 echo "<a href=\"editcategories.php?id=$cm->id&amp;action=edit&amp;mode=cat&amp;hook=$category->id\"><img alt=\"" . get_string("edit") . "\" src=\"" . $OUTPUT->pix_url('t/edit') . "\" class=\"iconsmall\" /></a>";
fb443f1a 229 ?>
d427d609 230 </td>
fb443f1a 231 </tr>
ec81373f 232
ad58adac 233 <?php
1adbd2c3 234
fb443f1a 235 }
5bd76d7f 236 echo '</table>';
fb443f1a 237 }
238?>
ec81373f 239
5bd76d7f 240 </td></tr>
fb443f1a 241 <tr>
5bd76d7f 242 <td style="width:100%" colspan="2" align="center">
ad58adac 243 <?php
ec81373f 244
fb443f1a 245 $options['id'] = $cm->id;
246 $options['action'] = "add";
ec81373f 247
d427d609 248 echo "<table class=\"editbuttons\" border=\"0\"><tr><td align=\"right\">";
5c2ed7e2 249 echo $OUTPUT->single_button(new moodle_url("editcategories.php", $options), get_string("add") . " " . get_string("category","glossary"));
41905731 250 echo "</td><td align=\"left\">";
fb443f1a 251 unset($options['action']);
1ac87c73 252 $options['mode'] = 'cat';
253 $options['hook'] = $hook;
5c2ed7e2 254 echo $OUTPUT->single_button(new moodle_url("view.php", $options), get_string("back","glossary"));
fb443f1a 255 echo "</td></tr>";
32776fef 256 echo "</table>";
fb443f1a 257
258 ?>
259 </td>
260 </tr>
261 </table>
262
fb443f1a 263
264</form>
265
1adbd2c3 266<?php
0578c9a2 267echo $OUTPUT->footer();