From 49c4d8caa4dc4669fddd4845eb0d9fc917e14fa6 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Fri, 2 Oct 2009 07:53:01 +0000 Subject: [PATCH] MDL-10221 Simulating the HTTP DELETE method by using a URL param (action), because some web servers don't allow DELETE. AJAX Course and Block deletion now works as expected. Merged from MOODLE_19_STABLE --- course/rest.php | 9 ++++++++- lib/ajax/block_classes.js | 2 +- lib/ajax/section_classes.js | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/course/rest.php b/course/rest.php index a0d766bb12..d8e5e161d0 100644 --- a/course/rest.php +++ b/course/rest.php @@ -39,6 +39,7 @@ $id = optional_param('id', 0, PARAM_INT); $summary = optional_param('summary', '', PARAM_RAW); $sequence = optional_param('sequence', '', PARAM_SEQUENCE); $visible = optional_param('visible', 0, PARAM_INT); +$pageaction = optional_param('action', '', PARAM_ALPHA); // Used to simulate a DELETE command $PAGE->set_url(new moodle_url($CFG->wwwroot.'/course/rest.php', array('courseId'=>$courseId,'class'=>$class))); @@ -53,7 +54,13 @@ require_login($course); require_capability('moodle/course:update', $context); // OK, now let's process the parameters and do stuff -switch($_SERVER['REQUEST_METHOD']) { +// MDL-10221 the DELETE method is not allowed on some web servers, so we simulate it with the action URL param +$requestmethod = $_SERVER['REQUEST_METHOD']; +if ($pageaction == 'DELETE') { + $requestmethod = 'DELETE'; +} + +switch($requestmethod) { case 'POST': switch ($class) { diff --git a/lib/ajax/block_classes.js b/lib/ajax/block_classes.js index 2823f3ed14..defcde7ef5 100644 --- a/lib/ajax/block_classes.js +++ b/lib/ajax/block_classes.js @@ -258,7 +258,7 @@ block_class.prototype.delete_button = function() { this.removeFromGroup('blocks'); // Remove from remote model. - main.connect('DELETE', 'class=block&instanceId='+this.instanceId); + main.connect('POST', 'class=block&action=DELETE&instanceId='+this.instanceId); // Remove from view main.blocks.splice(main.get_block_index(this), 1); diff --git a/lib/ajax/section_classes.js b/lib/ajax/section_classes.js index 3a99f67bf4..058d440cde 100755 --- a/lib/ajax/section_classes.js +++ b/lib/ajax/section_classes.js @@ -818,7 +818,7 @@ resource_class.prototype.delete_button = function() { return false; } this.parentObj.remove_resource(this); - main.connect('DELETE', 'class=resource&id='+this.id); + main.connect('POST', 'class=resource&action=DELETE&id='+this.id); } -- 2.39.5