File: filter.php

package info (click to toggle)
moodle 1.6.3-2%2Betch3
  • links: PTS
  • area: main
  • in suites: etch
  • size: 37,172 kB
  • ctags: 51,688
  • sloc: php: 231,916; sql: 5,631; xml: 2,688; sh: 1,185; perl: 638; makefile: 48; pascal: 36
file content (108 lines) | stat: -rw-r--r-- 3,589 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php // $Id: filter.php,v 1.10 2006/04/12 21:02:03 skodak Exp $
    // filter.php
    // Edit text filter settings

    require_once('../config.php');
    require_once($CFG->libdir.'/tablelib.php');

    // check for allowed access
    require_login();
    if (!isadmin()) {
        error( 'Only administrators can use the filters administration page' );
    }
    if (!$site = get_site()) {
        error( 'Site is not defined in filters administration page' );
    }

    // get parameters
    $param = new Object;

    $param->filter = required_param('filter', PARAM_PATH);
    $param->submit = optional_param('submit', 0, PARAM_BOOL);
    $param->reset  = optional_param('reset', 0, PARAM_BOOL);

    $filtername =  substr($param->filter, strpos( $param->filter, '/' )+1 ) ;

    // $CFG->pagepath is used to generate the body and id attributes for the body tag
    // of the page. It is also used to generate the link to the Moodle Docs for this view.
    $CFG->pagepath = 'filter/' . $filtername . '/config';
    
    // get translated strings for use on page
    $txt = new Object;
    $txt->managefilters = get_string( 'managefilters' );
    $txt->administration = get_string( 'administration' );
    $txt->configuration = get_string( 'configuration' );

    //======================
    // Process Actions
    //======================

    // if reset pressed let filter config page handle it
    $forcereset = false;
    if (!empty($param->reset)) {
        $forcereset = true;
    }
    else
    if ($config = data_submitted()) {

        // check session key
        if (!confirm_sesskey()) {
             error( get_string('confirmsesskeybad', 'error' ) );
        }

        $configpath = $CFG->dirroot.'/filter/'.$filtername.'/filterconfig.php';
        if (file_exists($configpath)) {
            require_once($configpath);
            $functionname = $filtername.'_process_config';
            if (function_exists($functionname)) {
                $functionname($config);
                $saved = true;
            }
        }

        if (empty($saved)) {
            // run through submitted data
            // reject if does not start with filter_
            foreach ($config as $name => $value) {
                set_config( $name,$value );
            }
        }
        redirect( "$CFG->wwwroot/$CFG->admin/filters.php", get_string('changessaved'), 1);
        exit;
    }

    //==============================
    // Display logic
    //==============================
    
    $filtername = ucfirst($filtername);
    print_header( "$site->shortname: $txt->managefilters", "$site->fullname",
        "<a href=\"index.php\">$txt->administration</a> -> <a href=\"configure.php\">$txt->configuration</a> " .
        "-> <a href=\"filters.php\">$txt->managefilters</a> -> $filtername" );

    print_heading( $txt->managefilters );

    print_simple_box("<center>".get_string("configwarning", "admin")."</center>", "center", "50%");
    echo "<br />";

    print_simple_box_start("center",'');

    ?>
    <form action="filter.php?filter=<?php echo urlencode($param->filter); ?>" method="post">
    <input type="hidden" name="sesskey" value="<?php echo sesskey(); ?>" />

    <?php include "$CFG->dirroot/$param->filter/filterconfig.html"; ?>

    <center>
        <input type="submit" name="submit" value="<?php print_string('savechanges'); ?>" />
        <input type="submit" name="reset" value="<?php echo print_string('resettodefaults'); ?>" />
    </center>
    </form>

    <?php
    print_simple_box_end();

    print_simple_box_end();

    print_footer();
?>