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 $adminroot = admin_get_root();
8 admin_externalpage_setup('manageblocks', $adminroot);
9 require_once($CFG->libdir
.'/blocklib.php');
11 $blockid = required_param('block', PARAM_INT
);
13 if(($blockrecord = blocks_get_record($blockid)) === false) {
14 error('This block does not exist');
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.
26 'sesskey' => $USER->sesskey
29 /// If data submitted, then process and store.
31 if ($config = data_submitted()) {
33 if (!confirm_sesskey()) {
34 error(get_string('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);
48 /// Otherwise print the form.
50 $strmanageblocks = get_string('manageblocks');
51 $strblockname = $block->get_title();
53 // $CFG->pagepath is used to generate the body and id attributes for the body tag
54 // of the page. It is also used to generate the link to the Moodle Docs for this view.
55 $CFG->pagepath
= 'block/' . $block->name() . '/config';
58 admin_externalpage_print_header($adminroot);
60 print_heading($strblockname);
62 print_simple_box(get_string('configwarning', 'admin'), 'center', '50%');
65 echo '<form method="post" action="block.php">';
67 foreach($hiddendata as $name => $val) {
68 echo '<input type="hidden" name="'. $name .'" value="'. $val .'" />';
71 $block->config_print();
73 admin_externalpage_print_footer($adminroot);