block.php 2.19 KB
Newer Older
1
2
3
4
5
<?PHP  // $Id$

// block.php - allows admin to edit all local configuration variables for a block

    require_once('../config.php');
6
    require_once($CFG->libdir.'/adminlib.php');
7

skodak's avatar
skodak committed
8
    $blockid = required_param('block', PARAM_INT);
9

10
    if(!$blockrecord = blocks_get_record($blockid)) {
11
        print_error('blockdoesnotexist', 'error');
12
13
    }

14
15
    admin_externalpage_setup('blocksetting'.$blockrecord->name);

16
    $block = block_instance($blockrecord->name);
17
    if($block === false) {
18
        print_error('blockcannotinistantiate', 'error');
19
20
    }

21
22
23
24
    // Define the data we're going to silently include in the instance config form here,
    // so we can strip them from the submitted data BEFORE handling it.
    $hiddendata = array(
        'block' => $blockid,
skodak's avatar
skodak committed
25
        'sesskey' => sesskey()
26
27
28
    );

    /// If data submitted, then process and store.
29

30
    if ($config = data_submitted()) {
31
32

        if (!confirm_sesskey()) {
33
             print_error('confirmsesskeybad', 'error');
34
        }
35
        if(!$block->has_config()) {
36
            print_error('blockcannotconfig', 'error');
37
38
39
40
41
42
        }
        $remove = array_keys($hiddendata);
        foreach($remove as $item) {
            unset($config->$item);
        }
        $block->config_save($config);
43
44
        redirect("$CFG->wwwroot/$CFG->admin/blocks.php", get_string("changessaved"), 1);
        exit;
45
    }
46

47
    /// Otherwise print the form.
48
49
50

    $strmanageblocks = get_string('manageblocks');
    $strblockname = $block->get_title();
51

52
    admin_externalpage_print_header();
53

54
    echo $OUTPUT->heading($strblockname);
55

56
57
58
59
    notify('This block still uses an old-style config_global.html file. ' .
            'It must be updated by a developer to use a settings.php file.');

    print_box(get_string('configwarning', 'admin'), 'generalbox boxwidthnormal boxaligncenter');
60
61
    echo '<br />';

62
63
64
65
66
67
    echo '<form method="post" action="block.php">';
    echo '<p>';
    foreach($hiddendata as $name => $val) {
        echo '<input type="hidden" name="'. $name .'" value="'. $val .'" />';
    }
    echo '</p>';
68
69
70
71
72

    print_box_start();
    include($CFG->dirroot.'/blocks/'. $block->name() .'/config_global.html');
    print_box_end();

73
    echo '</form>';
74
    echo $OUTPUT->footer();
75
76

?>