Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / admin / block.php
blobf5165324e6d98e62937d97065059237c0dbee185
1 <?PHP // $Id$
3 // block.php - allows admin to edit all local configuration variables for a block
5 require_once('../config.php');
6 require_once($CFG->libdir.'/adminlib.php');
7 require_once($CFG->libdir.'/blocklib.php');
9 $blockid = required_param('block', PARAM_INT);
11 if(!$blockrecord = blocks_get_record($blockid)) {
12 error('This block does not exist');
15 admin_externalpage_setup('blocksetting'.$blockrecord->name);
17 $block = block_instance($blockrecord->name);
18 if($block === false) {
19 error('Problem in instantiating block object');
22 // Define the data we're going to silently include in the instance config form here,
23 // so we can strip them from the submitted data BEFORE handling it.
24 $hiddendata = array(
25 'block' => $blockid,
26 'sesskey' => $USER->sesskey
29 /// If data submitted, then process and store.
31 if ($config = data_submitted()) {
33 if (!confirm_sesskey()) {
34 print_error('confirmsesskeybad', 'error');
36 if(!$block->has_config()) {
37 error('This block does not support global configuration');
39 $remove = array_keys($hiddendata);
40 foreach($remove as $item) {
41 unset($config->$item);
43 $block->config_save($config);
44 redirect("$CFG->wwwroot/$CFG->admin/blocks.php", get_string("changessaved"), 1);
45 exit;
48 /// Otherwise print the form.
50 $strmanageblocks = get_string('manageblocks');
51 $strblockname = $block->get_title();
53 admin_externalpage_print_header();
55 print_heading($strblockname);
57 print_simple_box(get_string('configwarning', 'admin'), 'center', '50%');
58 echo '<br />';
60 echo '<form method="post" action="block.php">';
61 echo '<p>';
62 foreach($hiddendata as $name => $val) {
63 echo '<input type="hidden" name="'. $name .'" value="'. $val .'" />';
65 echo '</p>';
66 $block->config_print();
67 echo '</form>';
68 print_footer();