Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/filters.php
Go to the documentation of this file.
00001 <?php
00002 
00004 //                                                                       //
00005 // NOTICE OF COPYRIGHT                                                   //
00006 //                                                                       //
00007 // Moodle - Modular Object-Oriented Dynamic Learning Environment         //
00008 //          http://moodle.org                                            //
00009 //                                                                       //
00010 // Copyright (C) 1999 onwards Martin Dougiamas  http://dougiamas.com     //
00011 //                                                                       //
00012 // This program is free software; you can redistribute it and/or modify  //
00013 // it under the terms of the GNU General Public License as published by  //
00014 // the Free Software Foundation; either version 2 of the License, or     //
00015 // (at your option) any later version.                                   //
00016 //                                                                       //
00017 // This program is distributed in the hope that it will be useful,       //
00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of        //
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         //
00020 // GNU General Public License for more details:                          //
00021 //                                                                       //
00022 //          http://www.gnu.org/copyleft/gpl.html                         //
00023 //                                                                       //
00025 
00034     require_once(dirname(__FILE__) . '/../config.php');
00035     require_once($CFG->libdir . '/adminlib.php');
00036 
00037     $action = optional_param('action', '', PARAM_ACTION);
00038     $filterpath = optional_param('filterpath', '', PARAM_PATH);
00039 
00040     require_login();
00041     $systemcontext = get_context_instance(CONTEXT_SYSTEM);
00042     require_capability('moodle/site:config', $systemcontext);
00043 
00044     $returnurl = "$CFG->wwwroot/$CFG->admin/filters.php";
00045     admin_externalpage_setup('managefilters');
00046 
00047     $filters = filter_get_global_states();
00048 
00049     // In case any new filters have been installed, but not put in the table yet.
00050     $fitlernames = filter_get_all_installed();
00051     $newfilters = $fitlernames;
00052     foreach ($filters as $filter => $notused) {
00053         unset($newfilters[$filter]);
00054     }
00055 
00057 
00058     if ($action) {
00059         if (!isset($filters[$filterpath]) && !isset($newfilters[$filterpath])) {
00060             throw new moodle_exception('filternotinstalled', 'error', $returnurl, $filterpath);
00061         }
00062 
00063         if (!confirm_sesskey()) {
00064             redirect($returnurl);
00065         }
00066     }
00067 
00068     switch ($action) {
00069 
00070     case 'setstate':
00071         if ($newstate = optional_param('newstate', '', PARAM_INTEGER)) {
00072             filter_set_global_state($filterpath, $newstate);
00073             if ($newstate == TEXTFILTER_DISABLED) {
00074                 filter_set_applies_to_strings($filterpath, false);
00075             }
00076             unset($newfilters[$filterpath]);
00077         }
00078         break;
00079 
00080     case 'setapplyto':
00081         $applytostrings = optional_param('stringstoo', false, PARAM_BOOL);
00082         filter_set_applies_to_strings($filterpath, $applytostrings);
00083         break;
00084 
00085     case 'down':
00086         if (isset($filters[$filterpath])) {
00087             $oldpos = $filters[$filterpath]->sortorder;
00088             if ($oldpos <= count($filters)) {
00089                 filter_set_global_state($filterpath, $filters[$filterpath]->active, $oldpos + 1);
00090             }
00091         }
00092         break;
00093 
00094     case 'up':
00095         if (isset($filters[$filterpath])) {
00096             $oldpos = $filters[$filterpath]->sortorder;
00097             if ($oldpos >= 1) {
00098                 filter_set_global_state($filterpath, $filters[$filterpath]->active, $oldpos - 1);
00099             }
00100         }
00101         break;
00102 
00103     case 'delete':
00104         if (!empty($filternames[$filterpath])) {
00105             $filtername = $filternames[$filterpath];
00106         } else {
00107             $filtername = $filterpath;
00108         }
00109 
00110         if (substr($filterpath, 0, 4) == 'mod/') {
00111             $mod = basename($filterpath);
00112             $a = new stdClass;
00113             $a->filter = $filtername;
00114             $a->module = get_string('modulename', $mod);
00115             print_error('cannotdeletemodfilter', 'admin', $returnurl, $a);
00116         }
00117 
00118         // If not yet confirmed, display a confirmation message.
00119         if (!optional_param('confirm', '', PARAM_BOOL)) {
00120             $title = get_string('deletefilterareyousure', 'admin', $filtername);
00121             echo $OUTPUT->header();
00122             echo $OUTPUT->heading($title);
00123 
00124             $linkcontinue = new moodle_url($returnurl, array('action' => 'delete', 'filterpath' => $filterpath, 'confirm' => 1));
00125             $formcancel = new single_button(new moodle_url($returnurl), get_string('no'), 'get');
00126             echo $OUTPUT->confirm(get_string('deletefilterareyousuremessage', 'admin', $filtername), $linkcontinue, $formcancel);
00127             echo $OUTPUT->footer();
00128             exit;
00129         }
00130 
00131         // Do the deletion.
00132         $title = get_string('deletingfilter', 'admin', $filtername);
00133         echo $OUTPUT->header();
00134         echo $OUTPUT->heading($title);
00135 
00136         // Delete all data for this plugin.
00137         filter_delete_all_for_filter($filterpath);
00138 
00139         $a = new stdClass;
00140         $a->filter = $filtername;
00141         $a->directory = $filterpath;
00142         echo $OUTPUT->box(get_string('deletefilterfiles', 'admin', $a), 'generalbox', 'notice');
00143         echo $OUTPUT->continue_button($returnurl);
00144         echo $OUTPUT->footer();
00145         exit;
00146     }
00147 
00148     // Add any missing filters to the DB table.
00149     foreach ($newfilters as $filter => $notused) {
00150         filter_set_global_state($filter, TEXTFILTER_DISABLED);
00151     }
00152 
00153     // Reset caches and return
00154     if ($action) {
00155         reset_text_filters_cache();
00156         redirect($returnurl);
00157     }
00158 
00160 
00162     echo $OUTPUT->header();
00163     echo $OUTPUT->heading(get_string('filtersettings', 'admin'));
00164 
00165     $activechoices = array(
00166         TEXTFILTER_DISABLED => get_string('disabled', 'filters'),
00167         TEXTFILTER_OFF => get_string('offbutavailable', 'filters'),
00168         TEXTFILTER_ON => get_string('on', 'filters'),
00169     );
00170     $applytochoices = array(
00171         0 => get_string('content', 'filters'),
00172         1 => get_string('contentandheadings', 'filters'),
00173     );
00174 
00175     $filters = filter_get_global_states();
00176 
00177     // In case any new filters have been installed, but not put in the table yet.
00178     $filternames = filter_get_all_installed();
00179     $newfilters = $filternames;
00180     foreach ($filters as $filter => $notused) {
00181         unset($newfilters[$filter]);
00182     }
00183     $stringfilters = filter_get_string_filters();
00184 
00185     $table = new html_table();
00186     $table->head  = array(get_string('filter'), get_string('isactive', 'filters'),
00187             get_string('order'), get_string('applyto', 'filters'), get_string('settings'), get_string('delete'));
00188     $table->align = array('left', 'left', 'center', 'left', 'left');
00189     $table->width = '100%';
00190     $table->data  = array();
00191 
00192     $lastactive = null;
00193     foreach ($filters as $filter => $filterinfo) {
00194         if ($filterinfo->active != TEXTFILTER_DISABLED) {
00195             $lastactive = $filter;
00196         }
00197     }
00198 
00199     // iterate through filters adding to display table
00200     $firstrow = true;
00201     foreach ($filters as $filter => $filterinfo) {
00202         $applytostrings = isset($stringfilters[$filter]) && $filterinfo->active != TEXTFILTER_DISABLED;
00203         $row = get_table_row($filterinfo, $firstrow, $filter == $lastactive, $applytostrings);
00204         $table->data[] = $row;
00205         if ($filterinfo->active == TEXTFILTER_DISABLED) {
00206             $table->rowclasses[] = 'dimmed_text';
00207         } else {
00208             $table->rowclasses[] = '';
00209         }
00210         $firstrow = false;
00211     }
00212     foreach ($newfilters as $filter => $filtername) {
00213         $filterinfo = new stdClass;
00214         $filterinfo->filter = $filter;
00215         $filterinfo->active = TEXTFILTER_DISABLED;
00216         $row = get_table_row($filterinfo, false, false, false);
00217         $table->data[] = $row;
00218         $table->rowclasses[] = 'dimmed_text';
00219     }
00220 
00221     echo html_writer::table($table);
00222     echo '<p class="filtersettingnote">' . get_string('filterallwarning', 'filters') . '</p>';
00223     echo $OUTPUT->footer();
00224 
00226 
00227 function filters_action_url($filterpath, $action) {
00228     return new moodle_url('/admin/filters.php', array('sesskey'=>sesskey(), 'filterpath'=>$filterpath, 'action'=>$action));
00229 }
00230 
00231 function get_table_row($filterinfo, $isfirstrow, $islastactive, $applytostrings) {
00232     global $CFG, $OUTPUT, $activechoices, $applytochoices, $filternames; //TODO: this is sloppy coding style!!
00233     $row = array();
00234     $filter = $filterinfo->filter;
00235 
00236     // Filter name
00237     if (!empty($filternames[$filter])) {
00238         $row[] = $filternames[$filter];
00239     } else {
00240         $row[] = '<span class="error">' . get_string('filemissing', '', $filter) . '</span>';
00241     }
00242 
00243     // Disable/off/on
00244     $select = new single_select(filters_action_url($filter, 'setstate'), 'newstate', $activechoices, $filterinfo->active, null, 'active' . basename($filter));
00245     $row[] = $OUTPUT->render($select);
00246 
00247     // Re-order
00248     $updown = '';
00249     $spacer = '<img src="' . $OUTPUT->pix_url('spacer') . '" class="iconsmall" alt="" /> ';
00250     if ($filterinfo->active != TEXTFILTER_DISABLED) {
00251         if (!$isfirstrow) {
00252             $updown .= $OUTPUT->action_icon(filters_action_url($filter, 'up'), new pix_icon('t/up', get_string('up')));
00253         } else {
00254             $updown .= $spacer;
00255         }
00256         if (!$islastactive) {
00257             $updown .= $OUTPUT->action_icon(filters_action_url($filter, 'down'), new pix_icon('t/down', get_string('down')));
00258         } else {
00259             $updown .= $spacer;
00260         }
00261     }
00262     $row[] = $updown;
00263 
00264     // Apply to strings.
00265     $select = new single_select(filters_action_url($filter, 'setapplyto'), 'stringstoo', $applytochoices, $applytostrings, null, 'applyto' . basename($filter));
00266     $select->disabled = $filterinfo->active == TEXTFILTER_DISABLED;
00267     $row[] = $OUTPUT->render($select);
00268 
00269     // Settings link, if required
00270     if (filter_has_global_settings($filter)) {
00271         $row[] = '<a href="' . $CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=filtersetting' .
00272                 str_replace('/', '',$filter) . '">' . get_string('settings') . '</a>';
00273     } else {
00274         $row[] = '';
00275     }
00276 
00277     // Delete
00278     if (substr($filter, 0, 4) != 'mod/') {
00279         $row[] = '<a href="' . filters_action_url($filter, 'delete') . '">' . get_string('delete') . '</a>';
00280     } else {
00281         $row[] = '';
00282     }
00283 
00284     return $row;
00285 }
 All Data Structures Namespaces Files Functions Variables Enumerations