Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-29454 qtype admin page does not work in some browsers.

The problem is that they were using input type=image, but they trying to
process that using optional_param. With input type=image, Firefox sends
inputname.x and inputname.y POST data, not inputname.

This fix is done by back-porting the working code from Moodle 2.1, so
the changes are bigger than the minimal changes required to fix this,
but that will make back-porting any future bug-fixes will be easier.
  • Loading branch information...
commit becf8f8a231437c59aa3724cae541772f9be3bf7 1 parent 0b45720
Tim Hunt timhunt authored

Showing 1 changed file with 41 additions and 48 deletions. Show diff stats Hide diff stats

  1. +41 48 admin/qtypes.php
89 admin/qtypes.php
@@ -36,6 +36,7 @@
36 36 $canviewreports = has_capability('report/questioninstances:view', $systemcontext);
37 37
38 38 admin_externalpage_setup('manageqtypes');
  39 +$thispageurl = new moodle_url('/admin/qtypes.php');
39 40
40 41 // Get some data we will need - question counts and which types are needed.
41 42 $counts = $DB->get_records_sql("
@@ -77,67 +78,67 @@
77 78 // Disable.
78 79 if (($disable = optional_param('disable', '', PARAM_SAFEDIR)) && confirm_sesskey()) {
79 80 if (!isset($QTYPES[$disable])) {
80   - print_error('unknownquestiontype', 'question', admin_url('qtypes.php'), $disable);
  81 + print_error('unknownquestiontype', 'question', $thispageurl, $disable);
81 82 }
82 83
83 84 set_config($disable . '_disabled', 1, 'question');
84   - redirect(admin_url('qtypes.php'));
  85 + redirect($thispageurl);
85 86 }
86 87
87 88 // Enable.
88 89 if (($enable = optional_param('enable', '', PARAM_SAFEDIR)) && confirm_sesskey()) {
89 90 if (!isset($QTYPES[$enable])) {
90   - print_error('unknownquestiontype', 'question', admin_url('qtypes.php'), $enable);
  91 + print_error('unknownquestiontype', 'question', $thispageurl, $enable);
91 92 }
92 93
93 94 if (!$QTYPES[$enable]->menu_name()) {
94   - print_error('cannotenable', 'question', admin_url('qtypes.php'), $enable);
  95 + print_error('cannotenable', 'question', $thispageurl, $enable);
95 96 }
96 97
97 98 unset_config($enable . '_disabled', 'question');
98   - redirect(admin_url('qtypes.php'));
  99 + redirect($thispageurl);
99 100 }
100 101
101 102 // Move up in order.
102 103 if (($up = optional_param('up', '', PARAM_SAFEDIR)) && confirm_sesskey()) {
103 104 if (!isset($QTYPES[$up])) {
104   - print_error('unknownquestiontype', 'question', admin_url('qtypes.php'), $up);
  105 + print_error('unknownquestiontype', 'question', $thispageurl, $up);
105 106 }
106 107
107 108 $neworder = question_reorder_qtypes($sortedqtypes, $up, -1);
108 109 question_save_qtype_order($neworder, $config);
109   - redirect(admin_url('qtypes.php'));
  110 + redirect($thispageurl);
110 111 }
111 112
112 113 // Move down in order.
113 114 if (($down = optional_param('down', '', PARAM_SAFEDIR)) && confirm_sesskey()) {
114 115 if (!isset($QTYPES[$down])) {
115   - print_error('unknownquestiontype', 'question', admin_url('qtypes.php'), $down);
  116 + print_error('unknownquestiontype', 'question', $thispageurl, $down);
116 117 }
117 118
118 119 $neworder = question_reorder_qtypes($sortedqtypes, $down, +1);
119 120 question_save_qtype_order($neworder, $config);
120   - redirect(admin_url('qtypes.php'));
  121 + redirect($thispageurl);
121 122 }
122 123
123 124 // Delete.
124 125 if (($delete = optional_param('delete', '', PARAM_SAFEDIR)) && confirm_sesskey()) {
125 126 // Check it is OK to delete this question type.
126 127 if ($delete == 'missingtype') {
127   - print_error('cannotdeletemissingqtype', 'admin', admin_url('qtypes.php'));
  128 + print_error('cannotdeletemissingqtype', 'admin', $thispageurl);
128 129 }
129 130
130 131 if (!isset($QTYPES[$delete])) {
131   - print_error('unknownquestiontype', 'question', admin_url('qtypes.php'), $delete);
  132 + print_error('unknownquestiontype', 'question', $thispageurl, $delete);
132 133 }
133 134
134 135 $qtypename = $QTYPES[$delete]->local_name();
135 136 if ($counts[$delete]->numquestions + $counts[$delete]->numhidden > 0) {
136   - print_error('cannotdeleteqtypeinuse', 'admin', admin_url('qtypes.php'), $qtypename);
  137 + print_error('cannotdeleteqtypeinuse', 'admin', $thispageurl, $qtypename);
137 138 }
138 139
139 140 if ($needed[$delete] > 0) {
140   - print_error('cannotdeleteqtypeneeded', 'admin', admin_url('qtypes.php'), $qtypename);
  141 + print_error('cannotdeleteqtypeneeded', 'admin', $thispageurl, $qtypename);
141 142 }
142 143
143 144 // If not yet confirmed, display a confirmation message.
@@ -146,8 +147,8 @@
146 147 echo $OUTPUT->header();
147 148 echo $OUTPUT->heading(get_string('deleteqtypeareyousure', 'admin', $qtypename));
148 149 echo $OUTPUT->confirm(get_string('deleteqtypeareyousuremessage', 'admin', $qtypename),
149   - admin_url('qtypes.php?delete=' . $delete . '&confirm=1'),
150   - admin_url('qtypes.php'));
  150 + new moodle_url($thispageurl, array('delete' => $delete, 'confirm' => 1)),
  151 + $thispageurl);
151 152 echo $OUTPUT->footer();
152 153 exit;
153 154 }
@@ -172,7 +173,7 @@
172 173 $a->qtype = $qtypename;
173 174 $a->directory = $QTYPES[$delete]->plugin_dir();
174 175 echo $OUTPUT->box(get_string('qtypedeletefiles', 'admin', $a), 'generalbox', 'notice');
175   - echo $OUTPUT->continue_button(admin_url('qtypes.php'));
  176 + echo $OUTPUT->continue_button($thispageurl);
176 177 echo $OUTPUT->footer();
177 178 exit;
178 179 }
@@ -185,6 +186,7 @@
185 186
186 187 // Set up the table.
187 188 $table = new flexible_table('qtypeadmintable');
  189 +$table->define_baseurl($thispageurl);
188 190 $table->define_columns(array('questiontype', 'numquestions', 'version', 'requires',
189 191 'availableto', 'delete', 'settings'));
190 192 $table->define_headers(array(get_string('questiontype', 'admin'), get_string('numquestions', 'admin'),
@@ -214,8 +216,8 @@
214 216 $strcount = $counts[$qtypename]->numquestions;
215 217 }
216 218 if ($canviewreports) {
217   - $row[] = '<a href="' . admin_url('/report/questioninstances/index.php?qtype=' . $qtypename) .
218   - '" title="' . get_string('showdetails', 'admin') . '">' . $strcount . '</a>';
  219 + $row[] = html_writer::link(new moodle_url('/admin/report/questioninstances/index.php',
  220 + array('qtype' => $qtypename)), $strcount, array('title' => get_string('showdetails', 'admin')));
219 221 } else {
220 222 $strcount;
221 223 }
@@ -228,7 +230,7 @@
228 230 if ($version) {
229 231 $row[] = $version;
230 232 } else {
231   - $row[] = '<span class="disabled">' . get_string('nodatabase', 'admin') . '</span>';
  233 + $row[] = html_writer::tag('span', get_string('nodatabase', 'admin'), array('class' => 'disabled'));
232 234 }
233 235
234 236 // Other question types required by this one.
@@ -247,36 +249,35 @@
247 249 $rowclass = '';
248 250 if ($qtype->menu_name()) {
249 251 $createable = isset($createabletypes[$qtypename]);
250   - $icons = enable_disable_button($qtypename, $createable);
  252 + $icons = question_types_enable_disable_icons($qtypename, $createable);
251 253 if (!$createable) {
252 254 $rowclass = 'dimmed_text';
253 255 }
254 256 } else {
255   - $icons = '<img src="' . $OUTPUT->pix_url('spacer') . '" alt="" class="spacer" />';
  257 + $icons = $OUTPUT->spacer() . ' ';
256 258 }
257 259
258 260 // Move icons.
259   - $icons .= icon_html('up', $qtypename, 't/up', get_string('up'), '');
260   - $icons .= icon_html('down', $qtypename, 't/down', get_string('down'), '');
  261 + $icons .= question_type_icon_html('up', $qtypename, 't/up', get_string('up'), '');
  262 + $icons .= question_type_icon_html('down', $qtypename, 't/down', get_string('down'), '');
261 263 $row[] = $icons;
262 264
263 265 // Delete link, if available.
264 266 if ($needed[$qtypename]) {
265 267 $row[] = '';
266 268 } else {
267   - $row[] = '<a href="' . admin_url('qtypes.php?delete=' . $qtypename .
268   - '&amp;sesskey=' . sesskey()) . '" title="' .
269   - get_string('uninstallqtype', 'admin') . '">' . get_string('delete') . '</a>';
  269 + $row[] = html_writer::link(new moodle_url($thispageurl,
  270 + array('delete' => $qtypename, 'sesskey' => sesskey())), get_string('delete'),
  271 + array('title' => get_string('uninstallqtype', 'admin')));
270 272 }
271 273
272 274 // Settings link, if available.
273 275 $settings = admin_get_root()->locate('qtypesetting' . $qtypename);
274 276 if ($settings instanceof admin_externalpage) {
275   - $row[] = '<a href="' . $settings->url .
276   - '">' . get_string('settings') . '</a>';
  277 + $row[] = html_writer::link($settings->url, get_string('settings'));
277 278 } else if ($settings instanceof admin_settingpage) {
278   - $row[] = '<a href="' . admin_url('settings.php?section=qtypesetting' . $qtypename) .
279   - '">' . get_string('settings') . '</a>';
  279 + $row[] = html_writer::link(new moodle_url('/admin/settings.php',
  280 + array('section' => 'qtypesetting' . $qtypename)), get_string('settings'));
280 281 } else {
281 282 $row[] = '';
282 283 }
@@ -288,28 +289,20 @@
288 289
289 290 echo $OUTPUT->footer();
290 291
291   -function admin_url($endbit) {
292   - global $CFG;
293   - return $CFG->wwwroot . '/' . $CFG->admin . '/' . $endbit;
294   -}
295   -
296   -function enable_disable_button($qtypename, $createable) {
  292 +function question_types_enable_disable_icons($qtypename, $createable) {
297 293 if ($createable) {
298   - return icon_html('disable', $qtypename, 'i/hide', get_string('enabled', 'question'), get_string('disable'));
  294 + return question_type_icon_html('disable', $qtypename, 'i/hide',
  295 + get_string('enabled', 'question'), get_string('disable'));
299 296 } else {
300   - return icon_html('enable', $qtypename, 'i/show', get_string('disabled', 'question'), get_string('enable'));
  297 + return question_type_icon_html('enable', $qtypename, 'i/show',
  298 + get_string('disabled', 'question'), get_string('enable'));
301 299 }
302 300 }
303 301
304   -function icon_html($action, $qtypename, $icon, $alt, $tip) {
  302 +function question_type_icon_html($action, $qtypename, $icon, $alt, $tip) {
305 303 global $OUTPUT;
306   - if ($tip) {
307   - $tip = 'title="' . $tip . '" ';
308   - }
309   - $html = ' <form action="' . admin_url('qtypes.php') . '" method="post"><div>';
310   - $html .= '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
311   - $html .= '<input type="image" name="' . $action . '" value="' . $qtypename .
312   - '" src="' . $OUTPUT->pix_url($icon) . '" alt="' . $alt . '" ' . $tip . '/>';
313   - $html .= '</div></form>';
314   - return $html;
  304 + return $OUTPUT->action_icon(new moodle_url('/admin/qtypes.php',
  305 + array($action => $qtypename, 'sesskey' => sesskey())),
  306 + new pix_icon($icon, $alt, 'moodle', array('title' => '')),
  307 + null, array('title' => $tip)) . ' ';
315 308 }

0 comments on commit becf8f8

Please sign in to comment.
Something went wrong with that request. Please try again.