MDL-30361 - mod/glossary/editcategories.php - fix spelling ($rightalignment)
[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
efbbe2f0 86if (right_to_left()) { // RTL table alignment support
10625d2e 87 $rightalignment = 'left';
efbbe2f0
NK
88 $leftalignment = 'right';
89} else {
10625d2e 90 $rightalignment = 'right';
efbbe2f0
NK
91 $leftalignment = 'left';
92
93}
94
5fa0208e 95if ( $hook >0 ) {
fb443f1a 96
5fa0208e 97 if ( $action == "edit" ) {
98 if ( $confirm ) {
99 $action = "";
39790bd8 100 $cat = new stdClass();
5fa0208e 101 $cat->id = $hook;
102 $cat->name = $name;
103 $cat->usedynalink = $usedynalink;
00083db4 104
5fa0208e 105 $DB->update_record("glossary_categories", $cat);
106 add_to_log($course->id, "glossary", "edit category", "editcategories.php?id=$cm->id", $hook,$cm->id);
fb443f1a 107
5fa0208e 108 } else {
d427d609 109 echo "<h3 class=\"main\">" . get_string("edit"). " " . get_string("category","glossary") . "</h3>";
fb443f1a 110
5fa0208e 111 $name = $category->name;
112 $usedynalink = $category->usedynalink;
113 require "editcategories.html";
114 echo $OUTPUT->footer();
115 die;
116 }
fb443f1a 117
5fa0208e 118 } elseif ( $action == "delete" ) {
119 if ( $confirm ) {
120 $DB->delete_records("glossary_entries_categories", array("categoryid"=>$hook));
121 $DB->delete_records("glossary_categories", array("id"=>$hook));
fb443f1a 122
5fa0208e 123 echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow');
d427d609 124 echo "<div>" . get_string("categorydeleted","glossary") ."</div>";
5fa0208e 125 echo $OUTPUT->box_end();
61c72439 126
5fa0208e 127 add_to_log($course->id, "glossary", "delete category", "editcategories.php?id=$cm->id", $hook,$cm->id);
61c72439 128
5fa0208e 129 redirect("editcategories.php?id=$cm->id");
130 } else {
d427d609 131 echo "<p>" . get_string("delete"). " " . get_string("category","glossary"). "</p>";
90ee78e2 132
5fa0208e 133 echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow');
bce3e3dc 134 echo "<div class=\"boxaligncenter deletecatconfirm\">".format_string($category->name, true, $fmtoptions)."<br/>";
61c72439 135
5fa0208e 136 $num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id));
137 if ( $num_entries ) {
138 print_string("deletingnoneemptycategory","glossary");
61c72439 139 }
5fa0208e 140 echo "<p>";
141 print_string("areyousuredelete","glossary");
142 echo "</p>";
61c72439 143?>
5bd76d7f 144
d427d609 145 <table border="0" width="100" class="confirmbuttons">
5bd76d7f 146 <tr>
efbbe2f0 147 <td align="$rightalignment" style="width:50%">
5bd76d7f 148 <form id="form" method="post" action="editcategories.php">
149 <div>
150 <input type="hidden" name="id" value="<?php p($cm->id) ?>" />
151 <input type="hidden" name="action" value="delete" />
152 <input type="hidden" name="confirm" value="1" />
153 <input type="hidden" name="mode" value="<?php echo $mode ?>" />
154 <input type="hidden" name="hook" value="<?php echo $hook ?>" />
155 <input type="submit" value=" <?php print_string("yes")?> " />
156 </div>
157 </form>
158 </td>
efbbe2f0 159 <td align="$leftalignment" style="width:50%">
61c72439 160
161<?php
5fa0208e 162 unset($options);
163 $options = array ("id" => $id);
5c2ed7e2 164 echo $OUTPUT->single_button(new moodle_url("editcategories.php", $options), get_string("no"));
5fa0208e 165 echo "</td></tr></table>";
166 echo "</div>";
167 echo $OUTPUT->box_end();
61c72439 168 }
5fa0208e 169 }
170
171} elseif ( $action == "add" ) {
172 if ( $confirm ) {
e99cfeb8 173 $dupcategory = $DB->get_records_sql("SELECT * FROM {glossary_categories} WHERE ".$DB->sql_like('name','?', false)." AND glossaryid=?", array($name, $glossary->id));
5fa0208e 174 if ( $dupcategory ) {
d427d609 175 echo "<h3 class=\"main\">" . get_string("add"). " " . get_string("category","glossary"). "</h3>";
5fa0208e 176
177 echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow');
b86f9306 178 echo "<div>" . get_string("duplicatecategory","glossary") ."</div>";
5fa0208e 179 echo $OUTPUT->box_end();
180
b86f9306 181 redirect("editcategories.php?id=$cm->id&amp;action=add&amp;name=$name");
61c72439 182
61c72439 183 } else {
5fa0208e 184 $action = "";
39790bd8 185 $cat = new stdClass();
5fa0208e 186 $cat->name = $name;
187 $cat->usedynalink = $usedynalink;
188 $cat->glossaryid = $glossary->id;
189
190 $cat->id = $DB->insert_record("glossary_categories", $cat);
191 add_to_log($course->id, "glossary", "add category", "editcategories.php?id=$cm->id", $cat->id,$cm->id);
61c72439 192 }
5fa0208e 193 } else {
d427d609 194 echo "<h3 class=\"main\">" . get_string("add"). " " . get_string("category","glossary"). "</h3>";
5fa0208e 195 $name="";
196 require "editcategories.html";
61c72439 197 }
5fa0208e 198}
ec81373f 199
5fa0208e 200if ( $action ) {
201 echo $OUTPUT->footer();
202 die;
203}
fb443f1a 204
205?>
206
b7dc2256 207<form method="post" action="editcategories.php">
5bd76d7f 208<table width="40%" class="boxaligncenter generalbox" cellpadding="5">
fb443f1a 209 <tr>
d427d609
PM
210 <th style="width:90%" align="center">
211 <?php p(get_string("categories","glossary")) ?></th>
212 <th style="width:10%" align="center">
213 <?php p(get_string("action")) ?></th>
fb443f1a 214 </tr>
5bd76d7f 215 <tr><td style="width:100%" colspan="2">
ec81373f 216
1adbd2c3 217
61c72439 218
ad58adac 219<?php
ae8c3566 220 $categories = $DB->get_records("glossary_categories", array("glossaryid"=>$glossary->id), "name ASC");
61c72439 221
222 if ( $categories ) {
5bd76d7f 223 echo '<table width="100%">';
61c72439 224 foreach ($categories as $category) {
ae8c3566 225 $num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id));
61c72439 226?>
fb443f1a 227
b8340d19 228 <tr>
efbbe2f0 229 <td style="width:80%" align="$leftalignment">
ad58adac 230 <?php
bce3e3dc 231 echo "<span class=\"bold\">".format_string($category->name, true, $fmtoptions)."</span> <span>($num_entries " . get_string("entries","glossary") . ")</span>";
fb443f1a 232 ?>
233 </td>
d427d609 234 <td style="width:19%" align="center" class="action">
ad58adac 235 <?php
b5d0cafc
PS
236 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> ";
237 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 238 ?>
d427d609 239 </td>
fb443f1a 240 </tr>
ec81373f 241
ad58adac 242 <?php
1adbd2c3 243
fb443f1a 244 }
5bd76d7f 245 echo '</table>';
fb443f1a 246 }
247?>
ec81373f 248
5bd76d7f 249 </td></tr>
fb443f1a 250 <tr>
5bd76d7f 251 <td style="width:100%" colspan="2" align="center">
ad58adac 252 <?php
ec81373f 253
fb443f1a 254 $options['id'] = $cm->id;
255 $options['action'] = "add";
ec81373f 256
efbbe2f0 257 echo "<table class=\"editbuttons\" border=\"0\"><tr><td align=\"$rightalignment\">";
5c2ed7e2 258 echo $OUTPUT->single_button(new moodle_url("editcategories.php", $options), get_string("add") . " " . get_string("category","glossary"));
efbbe2f0 259 echo "</td><td align=\"$leftalignment\">";
fb443f1a 260 unset($options['action']);
1ac87c73 261 $options['mode'] = 'cat';
262 $options['hook'] = $hook;
5c2ed7e2 263 echo $OUTPUT->single_button(new moodle_url("view.php", $options), get_string("back","glossary"));
fb443f1a 264 echo "</td></tr>";
32776fef 265 echo "</table>";
fb443f1a 266
267 ?>
268 </td>
269 </tr>
270 </table>
271
fb443f1a 272
273</form>
274
1adbd2c3 275<?php
0578c9a2 276echo $OUTPUT->footer();