Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 1... Línea 1...
1
<?php
1
<?php
2
 
-
 
3
// This file is part of Moodle - http://moodle.org/
2
// This file is part of Moodle - http://moodle.org/
4
//
3
//
5
// Moodle is free software: you can redistribute it and/or modify
4
// Moodle is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
5
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
6
// the Free Software Foundation, either version 3 of the License, or
Línea 24... Línea 23...
24
 */
23
 */
Línea 25... Línea 24...
25
 
24
 
26
require_once(__DIR__ . '/../config.php');
25
require_once(__DIR__ . '/../config.php');
Línea 27... Línea 26...
27
require_once($CFG->libdir . '/adminlib.php');
26
require_once($CFG->libdir . '/adminlib.php');
28
 
27
 
29
$contextid = required_param('contextid',PARAM_INT);
28
$contextid = required_param('contextid', PARAM_INT);
Línea 30... Línea 29...
30
$forfilter = optional_param('filter', '', PARAM_SAFEDIR);
29
$forfilter = optional_param('filter', '', PARAM_SAFEDIR);
Línea 31... Línea 30...
31
$returnto  = optional_param('return', null, PARAM_ALPHANUMEXT);
30
$returnto  = optional_param('return', null, PARAM_ALPHANUMEXT);
32
 
31
 
33
list($context, $course, $cm) = get_context_info_array($contextid);
32
list($context, $course, $cm) = get_context_info_array($contextid);
34
 
33
 
Línea 35... Línea 34...
35
/// Check login and permissions.
34
// Check login and permissions.
36
require_login($course, false, $cm);
35
require_login($course, false, $cm);
37
require_capability('moodle/filter:manage', $context);
36
require_capability('moodle/filter:manage', $context);
38
$PAGE->set_context($context);
37
$PAGE->set_context($context);
39
 
38
 
40
$args = array('contextid'=>$contextid);
39
$args = ['contextid' => $contextid];
41
$baseurl = new moodle_url('/filter/manage.php', $args);
40
$baseurl = new moodle_url('/filter/manage.php', $args);
42
if (!empty($forfilter)) {
41
if (!empty($forfilter)) {
43
    $args['filter'] = $forfilter;
42
    $args['filter'] = $forfilter;
Línea 44... Línea 43...
44
}
43
}
45
$PAGE->set_url($baseurl, $args);
44
$PAGE->set_url($baseurl, $args);
46
if ($returnto !== null) {
45
if ($returnto !== null) {
47
    $baseurl->param('return', $returnto);
46
    $baseurl->param('return', $returnto);
Línea 48... Línea 47...
48
}
47
}
Línea 63... Línea 62...
63
} else if ($context->contextlevel == CONTEXT_MODULE) {
62
} else if ($context->contextlevel == CONTEXT_MODULE) {
64
    // Must be module context.
63
    // Must be module context.
65
    $PAGE->set_heading($PAGE->activityrecord->name);
64
    $PAGE->set_heading($PAGE->activityrecord->name);
66
}
65
}
Línea 67... Línea 66...
67
 
66
 
68
/// Check login and permissions.
67
// Check login and permissions.
69
require_login($course, false, $cm);
68
require_login($course, false, $cm);
Línea 70... Línea 69...
70
require_capability('moodle/filter:manage', $context);
69
require_capability('moodle/filter:manage', $context);
Línea 71... Línea 70...
71
 
70
 
72
$PAGE->set_context($context);
71
$PAGE->set_context($context);
73
 
72
 
74
/// Get the list of available filters.
73
// Get the list of available filters.
75
$availablefilters = filter_get_available_in_context($context);
74
$availablefilters = filter_get_available_in_context($context);
Línea 76... Línea 75...
76
if (!$isfrontpage && empty($availablefilters)) {
75
if (!$isfrontpage && empty($availablefilters)) {
77
    throw new \moodle_exception('nofiltersenabled', 'error');
76
    throw new \moodle_exception('nofiltersenabled', 'error');
78
}
77
}
79
 
78
 
80
// If we are handling local settings for a particular filter, start processing.
79
// If we are handling local settings for a particular filter, start processing.
81
if ($forfilter) {
-
 
82
    if (!filter_has_local_settings($forfilter)) {
80
if ($forfilter) {
83
        throw new \moodle_exception('filterdoesnothavelocalconfig', 'error', $forfilter);
81
    if (!filter_has_local_settings($forfilter)) {
84
    }
82
        throw new \moodle_exception('filterdoesnothavelocalconfig', 'error', $forfilter);
85
    require_once($CFG->dirroot . '/filter/local_settings_form.php');
83
    }
86
    require_once($CFG->dirroot . '/filter/' . $forfilter . '/filterlocalsettings.php');
84
    require_once($CFG->dirroot . '/filter/' . $forfilter . '/filterlocalsettings.php');
Línea 92... Línea 90...
92
        $settingsform->save_changes($data);
90
        $settingsform->save_changes($data);
93
        redirect($baseurl);
91
        redirect($baseurl);
94
    }
92
    }
95
}
93
}
Línea 96... Línea 94...
96
 
94
 
97
/// Process any form submission.
95
// Process any form submission.
98
if ($forfilter == '' && optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
96
if ($forfilter == '' && optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
99
    foreach ($availablefilters as $filter => $filterinfo) {
97
    foreach ($availablefilters as $filter => $filterinfo) {
100
        $newstate = optional_param($filter, false, PARAM_INT);
98
        $newstate = optional_param($filter, false, PARAM_INT);
101
        if ($newstate !== false && $newstate != $filterinfo->localstate) {
99
        if ($newstate !== false && $newstate != $filterinfo->localstate) {
102
            filter_set_local_state($filter, $context->id, $newstate);
100
            filter_set_local_state($filter, $context->id, $newstate);
103
        }
101
        }
104
    }
102
    }
105
    redirect($baseurl, get_string('changessaved'), 1);
103
    redirect($baseurl, get_string('changessaved'), 1);
Línea 106... Línea 104...
106
}
104
}
107
 
105
 
108
/// Work out an appropriate page title.
106
// Work out an appropriate page title.
109
if ($forfilter) {
107
if ($forfilter) {
110
    $a = new stdClass;
108
    $a = new stdClass;
111
    $a->filter = filter_get_name($forfilter);
109
    $a->filter = filter_get_name($forfilter);
112
    $a->context = $contextname;
110
    $a->context = $contextname;
113
    $title = get_string('filtersettingsforin', 'filters', $a);
111
    $title = get_string('filtersettingsforin', 'filters', $a);
114
} else {
112
} else {
115
    $title = get_string('filtersettingsin', 'filters', $contextname);
-
 
Línea 116... Línea 113...
116
}
113
    $title = get_string('filtersettingsin', 'filters', $contextname);
117
$straction = get_string('filters', 'admin'); // Used by tabs.php
114
}
118
 
115
 
119
// Print the header and tabs.
116
// Print the header and tabs.
120
$PAGE->set_cacheable(false);
117
$PAGE->set_cacheable(false);
121
$PAGE->set_title($title);
118
$PAGE->set_title($title);
Línea 122... Línea 119...
122
$PAGE->set_pagelayout('admin');
119
$PAGE->set_pagelayout('admin');
123
$PAGE->activityheader->disable();
120
$PAGE->activityheader->disable();
Línea 124... Línea 121...
124
echo $OUTPUT->header();
121
echo $OUTPUT->header();
125
 
122
 
126
/// Print heading.
123
// Print heading.
Línea 143... Línea 140...
143
    $strsettings = get_string('settings');
140
    $strsettings = get_string('settings');
144
    $stroff = get_string('off', 'filters');
141
    $stroff = get_string('off', 'filters');
145
    $stron = get_string('on', 'filters');
142
    $stron = get_string('on', 'filters');
146
    $strdefaultoff = get_string('defaultx', 'filters', $stroff);
143
    $strdefaultoff = get_string('defaultx', 'filters', $stroff);
147
    $strdefaulton = get_string('defaultx', 'filters', $stron);
144
    $strdefaulton = get_string('defaultx', 'filters', $stron);
148
    $activechoices = array(
145
    $activechoices = [
149
        TEXTFILTER_INHERIT => '',
146
        TEXTFILTER_INHERIT => '',
150
        TEXTFILTER_OFF => $stroff,
147
        TEXTFILTER_OFF => $stroff,
151
        TEXTFILTER_ON => $stron,
148
        TEXTFILTER_ON => $stron,
152
    );
149
    ];
Línea 153... Línea 150...
153
 
150
 
154
    echo html_writer::start_tag('form', array('action'=>$baseurl->out_omit_querystring(), 'method'=>'post'));
151
    echo html_writer::start_tag('form', ['action' => $baseurl->out_omit_querystring(), 'method' => 'post']);
155
    echo html_writer::start_tag('div');
152
    echo html_writer::start_tag('div');
156
    echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
153
    echo html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()]);
157
    foreach ($baseurl->params() as $key => $value) {
154
    foreach ($baseurl->params() as $key => $value) {
158
        echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>$key, 'value'=>$value));
155
        echo html_writer::empty_tag('input', ['type' => 'hidden', 'name' => $key, 'value' => $value]);
Línea 159... Línea 156...
159
    }
156
    }
160
 
157
 
161
    $table = new html_table();
158
    $table = new html_table();
162
    $table->head  = array(get_string('filter'), get_string('isactive', 'filters'));
159
    $table->head  = [get_string('filter'), get_string('isactive', 'filters')];
163
    $table->colclasses = array('leftalign', 'leftalign');
160
    $table->colclasses = ['leftalign', 'leftalign'];
164
    if ($settingscol) {
161
    if ($settingscol) {
165
        $table->head[] = $strsettings;
162
        $table->head[] = $strsettings;
166
        $table->colclasses[] = 'leftalign';
163
        $table->colclasses[] = 'leftalign';
167
    }
164
    }
168
    $table->id = 'frontpagefiltersettings';
165
    $table->id = 'frontpagefiltersettings';
Línea 169... Línea 166...
169
    $table->attributes['class'] = 'admintable generaltable';
166
    $table->attributes['class'] = 'admintable generaltable';
170
    $table->data = array();
167
    $table->data = [];
171
 
168
 
Línea 172... Línea 169...
172
    // iterate through filters adding to display table
169
    // Iterate through filters adding to display table.
173
    foreach ($availablefilters as $filter => $filterinfo) {
170
    foreach ($availablefilters as $filter => $filterinfo) {
Línea 174... Línea 171...
174
        $row = array();
171
        $row = [];
175
 
172
 
176
        // Filter name.
173
        // Filter name.
177
        $row[] = filter_get_name($filter);
174
        $row[] = filter_get_name($filter);
178
 
175
 
179
        // Default/on/off choice.
176
        // Default/on/off choice.
180
        if ($filterinfo->inheritedstate == TEXTFILTER_ON) {
177
        if ($filterinfo->inheritedstate == TEXTFILTER_ON) {
181
            $activechoices[TEXTFILTER_INHERIT] = $strdefaulton;
178
            $activechoices[TEXTFILTER_INHERIT] = $strdefaulton;
182
        } else {
179
        } else {
Línea 183... Línea 180...
183
            $activechoices[TEXTFILTER_INHERIT] = $strdefaultoff;
180
            $activechoices[TEXTFILTER_INHERIT] = $strdefaultoff;
184
        }
181
        }
185
        $select = html_writer::label($filterinfo->localstate, 'menu'. $filter, false, array('class' => 'accesshide'));
182
        $select = html_writer::label($filterinfo->localstate, 'menu'. $filter, false, ['class' => 'accesshide']);
186
        $select .= html_writer::select($activechoices, $filter, $filterinfo->localstate, false);
183
        $select .= html_writer::select($activechoices, $filter, $filterinfo->localstate, false);
187
        $row[] = $select;
184
        $row[] = $select;
188
 
185
 
189
        // Settings link, if required
186
        // Settings link, if required.
190
        if ($settingscol) {
187
        if ($settingscol) {
Línea 191... Línea 188...
191
            $settings = '';
188
            $settings = '';
192
            if ($filterinfo->hassettings) {
189
            if ($filterinfo->hassettings) {
Línea 193... Línea 190...
193
                $settings = '<a href="' . $baseurl->out(true, array('filter'=>$filter)). '">' . $strsettings . '</a>';
190
                $settings = '<a href="' . $baseurl->out(true, ['filter' => $filter]). '">' . $strsettings . '</a>';
194
            }
191
            }
195
            $row[] = $settings;
192
            $row[] = $settings;
196
        }
193
        }
197
 
194
 
198
        $table->data[] = $row;
195
        $table->data[] = $row;
199
    }
196
    }
200
 
197
 
Línea 201... Línea 198...
201
    echo html_writer::table($table);
198
    echo html_writer::table($table);
202
    echo html_writer::start_tag('div', array('class'=>'buttons'));
199
    echo html_writer::start_tag('div', ['class' => 'buttons']);
Línea 203... Línea 200...
203
    $submitattr = ['type' => 'submit', 'name' => 'savechanges', 'value' => get_string('savechanges'), 'class' => 'btn btn-primary'];
200
    $submitattr = ['type' => 'submit', 'name' => 'savechanges', 'value' => get_string('savechanges'), 'class' => 'btn btn-primary'];
204
    echo html_writer::empty_tag('input', $submitattr);
201
    echo html_writer::empty_tag('input', $submitattr);
205
    echo html_writer::end_tag('div');
202
    echo html_writer::end_tag('div');
206
    echo html_writer::end_tag('div');
203
    echo html_writer::end_tag('div');
207
    echo html_writer::end_tag('form');
204
    echo html_writer::end_tag('form');
Línea 208... Línea 205...
208
}
205
}
209
 
206
 
210
/// Appropriate back link.
207
// Appropriate back link.
211
if (!$isfrontpage) {
208
if (!$isfrontpage) {
Línea 212... Línea 209...
212
 
209
 
213
    if ($context->contextlevel === CONTEXT_COURSECAT && $returnto === 'management') {
-