Fixes to the PaintWeb cron task.
[moodle/mihaisucan.git] / admin / filters.php
blob57d6c7c4c2b0ab6a911f2116e99185d65a9da941
1 <?php // $Id$
3 require_once('../config.php');
5 $action = optional_param('action', '', PARAM_ACTION);
6 $filterpath = optional_param('filterpath', '', PARAM_PATH);
8 require_login();
9 require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
11 $returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=managefilters";
13 if (!confirm_sesskey()) {
14 redirect($returnurl);
17 // get a list of installed filters
18 $installedfilters = array();
19 $filterlocations = array('mod','filter');
20 foreach ($filterlocations as $filterlocation) {
21 $plugins = get_list_of_plugins($filterlocation);
22 foreach ($plugins as $plugin) {
23 $pluginpath = "$CFG->dirroot/$filterlocation/$plugin/filter.php";
24 if (is_readable($pluginpath)) {
25 $installedfilters["$filterlocation/$plugin"] = "$filterlocation/$plugin";
30 // get all the currently selected filters
31 if (!empty($CFG->textfilters)) {
32 $activefilters = explode(',', $CFG->textfilters);
33 } else {
34 $activefilters = array();
37 //======================
38 // Process Actions
39 //======================
41 switch ($action) {
43 case 'hide':
44 $key=array_search($filterpath, $activefilters);
45 // check filterpath is valid
46 if ($key===false) {
47 break;
49 // just delete it
50 unset($activefilters[$key]);
51 break;
53 case 'show':
54 // check filterpath is valid
55 if (!array_key_exists($filterpath, $installedfilters)) {
56 error("Filter $filterpath is not currently installed", $url);
57 } elseif (array_search($filterpath,$activefilters)) {
58 // filterpath is already active - doubleclick??
59 } else {
60 // add it to installed filters
61 $activefilters[] = $filterpath;
62 $activefilters = array_unique($activefilters);
64 break;
66 case 'down':
67 $key=array_search($filterpath, $activefilters);
68 // check filterpath is valid
69 if ($key===false) {
70 error("Filter $filterpath is not currently active", $url);
71 } elseif ($key>=(count($activefilters)-1)) {
72 // cannot be moved any further down - doubleclick??
73 } else {
74 // swap with $key+1
75 $fsave = $activefilters[$key];
76 $activefilters[$key] = $activefilters[$key+1];
77 $activefilters[$key+1] = $fsave;
79 break;
81 case 'up':
82 $key=array_search($filterpath, $activefilters);
83 // check filterpath is valid
84 if ($key===false) {
85 error("Filter $filterpath is not currently active", $url);
86 } elseif ($key<1) {
87 //cannot be moved any further up - doubleclick??
88 } else {
89 // swap with $key-1
90 $fsave = $activefilters[$key];
91 $activefilters[$key] = $activefilters[$key-1];
92 $activefilters[$key-1] = $fsave;
94 break;
97 // save, reset cache and return
98 set_config('textfilters', implode(',', $activefilters));
99 reset_text_filters_cache();
100 redirect($returnurl);