Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/filter/manage.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00026 require_once(dirname(__FILE__) . '/../config.php');
00027 require_once($CFG->libdir . '/adminlib.php');
00028 
00029 $contextid = required_param('contextid',PARAM_INT);
00030 $forfilter = optional_param('filter', '', PARAM_SAFEPATH);
00031 
00032 list($context, $course, $cm) = get_context_info_array($contextid);
00033 
00035 require_login($course, false, $cm);
00036 require_capability('moodle/filter:manage', $context);
00037 $PAGE->set_context($context);
00038 
00039 $args = array('contextid'=>$contextid);
00040 $baseurl = new moodle_url('/filter/manage.php', $args);
00041 if (!empty($forfilter)) {
00042     $args['filter'] = $forfilter;
00043 }
00044 $PAGE->set_url($baseurl, $args);
00045 
00046 // This is a policy decision, rather than something that would be impossible to implement.
00047 if (!in_array($context->contextlevel, array(CONTEXT_COURSECAT, CONTEXT_COURSE, CONTEXT_MODULE))) {
00048     print_error('cannotcustomisefiltersblockuser', 'error');
00049 }
00050 
00051 $isfrontpage = ($context->contextlevel == CONTEXT_COURSE && $context->instanceid == SITEID);
00052 
00053 $contextname = print_context_name($context);
00054 
00055 if ($context->contextlevel == CONTEXT_COURSECAT) {
00056     $heading = "$SITE->fullname: ".get_string("categories");
00057 } else if ($context->contextlevel == CONTEXT_COURSE) {
00058     $heading = $course->fullname;
00059 } else if ($context->contextlevel == CONTEXT_MODULE) {
00060     // Must be module context.
00061     $heading = $PAGE->activityrecord->name;
00062 } else {
00063     $heading = '';
00064 }
00065 
00067 require_login($course, false, $cm);
00068 require_capability('moodle/filter:manage', $context);
00069 
00070 $PAGE->set_context($context);
00071 $PAGE->set_heading($heading);
00072 
00074 $availablefilters = filter_get_available_in_context($context);
00075 if (!$isfrontpage && empty($availablefilters)) {
00076     print_error('nofiltersenabled', 'error');
00077 }
00078 
00079 // If we are handling local settings for a particular filter, start processing.
00080 if ($forfilter) {
00081     if (!filter_has_local_settings($forfilter)) {
00082         print_error('filterdoesnothavelocalconfig', 'error', $forfilter);
00083     }
00084     require_once($CFG->dirroot . '/filter/local_settings_form.php');
00085     require_once($CFG->dirroot . '/' . $forfilter . '/filterlocalsettings.php');
00086     $formname = basename($forfilter) . '_filter_local_settings_form';
00087     $settingsform = new $formname($CFG->wwwroot . '/filter/manage.php', $forfilter, $context);
00088     if ($settingsform->is_cancelled()) {
00089         redirect($baseurl);
00090     } else if ($data = $settingsform->get_data()) {
00091         $settingsform->save_changes($data);
00092         redirect($baseurl);
00093     }
00094 }
00095 
00097 if ($forfilter == '' && optional_param('savechanges', false, PARAM_BOOL) && confirm_sesskey()) {
00098     foreach ($availablefilters as $filter => $filterinfo) {
00099         $newstate = optional_param(str_replace('/', '_', $filter), false, PARAM_INT);
00100         if ($newstate !== false && $newstate != $filterinfo->localstate) {
00101             filter_set_local_state($filter, $context->id, $newstate);
00102         }
00103     }
00104     redirect($CFG->wwwroot . '/filter/manage.php?contextid=' . $context->id, get_string('changessaved'), 1);
00105 }
00106 
00108 if ($forfilter) {
00109     $a = new stdClass;
00110     $a->filter = filter_get_name($forfilter);
00111     $a->context = $contextname;
00112     $title = get_string('filtersettingsforin', 'filters', $a);
00113 } else {
00114     $title = get_string('filtersettingsin', 'filters', $contextname);
00115 }
00116 $straction = get_string('filters', 'admin'); // Used by tabs.php
00117 
00119 if ($isfrontpage) {
00120     admin_externalpage_setup('frontpagefilters');
00121     echo $OUTPUT->header();
00122 } else {
00123     $PAGE->set_cacheable(false);
00124     $PAGE->set_title($title);
00125     $PAGE->set_pagelayout('admin');
00126     echo $OUTPUT->header();
00127 }
00128 
00130 echo $OUTPUT->heading_with_help($title, 'filtersettings', 'filters');
00131 
00132 if (empty($availablefilters)) {
00133     echo '<p class="centerpara">' . get_string('nofiltersenabled', 'filters') . "</p>\n";
00134 } else if ($forfilter) {
00135     $current = filter_get_local_config($forfilter, $contextid);
00136     $settingsform->set_data((object) $current);
00137     $settingsform->display();
00138 } else {
00139     $settingscol = false;
00140     foreach ($availablefilters as $filter => $notused) {
00141         $hassettings = filter_has_local_settings($filter);
00142         $availablefilters[$filter]->hassettings = $hassettings;
00143         $settingscol = $settingscol || $hassettings;
00144     }
00145 
00146     $strsettings = get_string('settings');
00147     $stroff = get_string('off', 'filters');
00148     $stron = get_string('on', 'filters');
00149     $strdefaultoff = get_string('defaultx', 'filters', $stroff);
00150     $strdefaulton = get_string('defaultx', 'filters', $stron);
00151     $activechoices = array(
00152         TEXTFILTER_INHERIT => '',
00153         TEXTFILTER_OFF => $stroff,
00154         TEXTFILTER_ON => $stron,
00155     );
00156 
00157     echo html_writer::start_tag('form', array('action'=>$baseurl->out(), 'method'=>'post'));
00158     echo html_writer::start_tag('div');
00159     echo html_writer::empty_tag('input', array('type'=>'hidden', 'name'=>'sesskey', 'value'=>sesskey()));
00160 
00161     $table = new html_table();
00162     $table->head  = array(get_string('filter'), get_string('isactive', 'filters'));
00163     $table->align = array('left', 'left');
00164     if ($settingscol) {
00165         $table->head[] = $strsettings;
00166         $table->align[] = 'left';
00167     }
00168     $table->width = ' ';
00169     $table->data = array();
00170 
00171     // iterate through filters adding to display table
00172     foreach ($availablefilters as $filter => $filterinfo) {
00173         $row = array();
00174 
00175         // Filter name.
00176         $row[] = filter_get_name($filter);
00177 
00178         // Default/on/off choice.
00179         if ($filterinfo->inheritedstate == TEXTFILTER_ON) {
00180             $activechoices[TEXTFILTER_INHERIT] = $strdefaulton;
00181         } else {
00182             $activechoices[TEXTFILTER_INHERIT] = $strdefaultoff;
00183         }
00184         $row[] = html_writer::select($activechoices, str_replace('/', '_', $filter), $filterinfo->localstate, false);
00185 
00186         // Settings link, if required
00187         if ($settingscol) {
00188             $settings = '';
00189             if ($filterinfo->hassettings) {
00190                 $settings = '<a href="' . $baseurl->out(true, array('filter'=>$filter)). '">' . $strsettings . '</a>';
00191             }
00192             $row[] = $settings;
00193         }
00194 
00195         $table->data[] = $row;
00196     }
00197 
00198     echo html_writer::table($table);
00199     echo html_writer::start_tag('div', array('class'=>'buttons'));
00200     echo html_writer::empty_tag('input', array('type'=>'submit', 'name'=>'savechanges', 'value'=>get_string('savechanges')));
00201     echo html_writer::end_tag('div');
00202     echo html_writer::end_tag('div');
00203     echo html_writer::end_tag('form');
00204 }
00205 
00207 if (!$isfrontpage) {
00208     echo html_writer::start_tag('div', array('class'=>'backlink'));
00209     echo html_writer::tag('a', get_string('backto', '', $contextname), array('href'=>get_context_url($context)));
00210     echo html_writer::end_tag('div');
00211 }
00212 
00213 echo $OUTPUT->footer();
00214 
 All Data Structures Namespaces Files Functions Variables Enumerations