$id = optional_param('id', 0, PARAM_INT);
$name = optional_param('name');
$blockaction = optional_param('blockaction');
- $instanceid = optional_param('instanceid', 0, PARAM_INT);
- $blockid = optional_param('blockid', 0, PARAM_INT);
if (empty($id) && empty($name)) {
error("Must specify course id or short name");
set_section_visible($course->id, $show, '1');
}
- if (!empty($blockaction) && confirm_sesskey()) {
- if (!empty($blockid)) {
- blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), intval($blockid));
-
- }
- else if (!empty($instanceid)) {
- $instance = blocks_find_instance($instanceid, $pageblocks);
- blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
- }
+ if (!empty($blockaction)) {
+ blocks_execute_url_action($PAGE, $pageblocks);
// This re-query could be eliminated by judicious programming in blocks_execute_action(),
// but I 'm not sure if it's worth the complexity increase...
$pageblocks = blocks_get_by_page($PAGE);
redirect($page->url_get_full());
}
+// You can use this to get the blocks to respond to URL actions without much hassle
+function blocks_execute_url_action(&$PAGE, &$pageblocks) {
+ $blockaction = optional_param('blockaction');
+
+ if (empty($blockaction) || !confirm_sesskey()) {
+ return;
+ }
+
+ $instanceid = optional_param('instanceid', 0, PARAM_INT);
+ $blockid = optional_param('blockid', 0, PARAM_INT);
+
+ if (!empty($blockid)) {
+ blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $blockid);
+
+ }
+ else if (!empty($instanceid)) {
+ $instance = blocks_find_instance($instanceid, $pageblocks);
+ blocks_execute_action($PAGE, $pageblocks, strtolower($blockaction), $instance);
+ }
+}
+
// This shouldn't be used externally at all, it's here for use by blocks_execute_action()
// in order to reduce code repetition.
function blocks_execute_repositioning(&$instance, $newpos, $newweight) {