3 // block.php - allows admin to edit all local configuration variables for a block
5 require_once('../config.php');
6 require_once($CFG->libdir
.'/blocklib.php');
11 error('Only an admin can use this page');
13 if (!$site = get_site()) {
14 error("Site isn't defined!");
17 $blockid = required_param('block', PARAM_INT
);
19 if(($blockrecord = blocks_get_record($blockid)) === false) {
20 error('This block does not exist');
23 $block = block_instance($blockrecord->name
);
24 if($block === false) {
25 error('Problem in instantiating block object');
28 // Define the data we're going to silently include in the instance config form here,
29 // so we can strip them from the submitted data BEFORE handling it.
32 'sesskey' => $USER->sesskey
35 /// If data submitted, then process and store.
37 if ($config = data_submitted()) {
39 if (!confirm_sesskey()) {
40 error(get_string('confirmsesskeybad', 'error'));
42 if(!$block->has_config()) {
43 error('This block does not support global configuration');
45 $remove = array_keys($hiddendata);
46 foreach($remove as $item) {
47 unset($config->$item);
49 $block->config_save($config);
50 redirect("$CFG->wwwroot/$CFG->admin/blocks.php", get_string("changessaved"), 1);
54 /// Otherwise print the form.
56 $stradmin = get_string('administration');
57 $strconfiguration = get_string('configuration');
58 $strmanageblocks = get_string('manageblocks');
59 $strblockname = $block->get_title();
61 // $CFG->pagepath is used to generate the body and id attributes for the body tag
62 // of the page. It is also used to generate the link to the Moodle Docs for this view.
63 $CFG->pagepath
= 'block/' . $block->name() . '/config';
65 print_header($site->shortname
.': '.$strblockname.": $strconfiguration", $site->fullname
,
66 "<a href=\"index.php\">$stradmin</a> -> ".
67 "<a href=\"configure.php\">$strconfiguration</a> -> ".
68 "<a href=\"blocks.php\">$strmanageblocks</a> -> ".$strblockname);
70 print_heading($strblockname);
72 print_simple_box('<center>'.get_string('configwarning', 'admin').'</center>', 'center', '50%');
75 echo '<form method="post" action="block.php">';
77 foreach($hiddendata as $name => $val) {
78 echo '<input type="hidden" name="'. $name .'" value="'. $val .'" />';
81 $block->config_print();