2 // Allows the admin to create, delete and rename course categories
4 require_once("../config.php");
6 optional_variable($iselect);
7 optional_variable($uselect);
8 optional_variable($add);
9 optional_variable($remove);
10 optional_variable($up);
11 optional_variable($down);
16 error("Only administrators can use this page!");
19 if (!$site = get_site()) {
20 error("Site isn't defined!");
25 $stradministration = get_string("administration");
26 $strconfiguration = get_string("configuration");
27 $strmanagefilters = get_string("managefilters");
28 $strversion = get_string("version");
29 $strsettings = get_string("settings");
30 $strup = get_string("up");
31 $strdown = get_string("down");
32 $stractive = get_string("active");
33 $strinactive = get_string("inactive");
34 $strcachetext = get_string("cachetext", "admin");
35 $strconfigcachetext = get_string("configcachetext", 'admin');
36 $strfilteruploadedfiles = get_string("filteruploadedfiles", "admin");
37 $strfilterall = get_string("filterall", "admin");
38 $strconfigfilteruploadedfiles = get_string("configfilteruploadedfiles", 'admin');
39 $strconfigfilterall = get_string("configfilterall", "admin");
41 print_header("$site->shortname: $strmanagefilters", "$site->fullname",
42 "<a href=\"index.php\">$stradministration</a> -> ".
43 "<a href=\"configure.php\">$strconfiguration</a> -> $strmanagefilters");
45 print_heading($strmanagefilters);
48 /// Make a list of all available filters and the best names for them we can find
49 $allfilters = array();
51 $filterlocations = array("mod", "filter");
53 foreach ($filterlocations as $filterlocation) {
54 $plugins = get_list_of_plugins($filterlocation);
55 foreach ($plugins as $key => $plugin) {
56 if (is_readable("$CFG->dirroot/$filterlocation/$plugin/filter.php")) {
57 $name = trim(get_string("filtername", $plugin));
58 if (empty($name) or $name == "[[filtername]]") {
61 $allfilters["$filterlocation/$plugin"] = $name;
67 /// Make an array of all the currently installed filters
69 $installedfilters = array();
70 if (!empty($CFG->textfilters
)) {
71 $installedfilters = explode(',',$CFG->textfilters
);
73 // Do a little cleanup for robustness
74 foreach ($installedfilters as $key => $installedfilter) {
75 if (empty($installedfilter)) {
76 unset($installedfilters[$key]);
77 set_config("textfilters", implode(',', $installedfilters));
82 $selectedfilter = "none";
84 /// If data submitted, then process and store.
86 if (!empty($options)) {
87 if (($config = data_submitted()) && confirm_sesskey()) {
88 unset($config->options
);
89 unset($config->sesskey
);
90 foreach ($config as $name => $value) {
91 set_config($name, $value);
96 if (!empty($add) and !empty($uselect) and confirm_sesskey()) {
97 $selectedfilter = $uselect;
98 if (!in_array($selectedfilter, $installedfilters)) {
99 $installedfilters[] = $selectedfilter;
100 set_config("textfilters", implode(',', $installedfilters));
103 } else if (!empty($remove) and !empty($iselect) and confirm_sesskey()) {
104 $selectedfilter = $iselect;
105 foreach ($installedfilters as $key => $installedfilter) {
106 if ($installedfilter == $selectedfilter) {
107 unset($installedfilters[$key]);
110 set_config("textfilters", implode(',', $installedfilters));
112 } else if ((!empty($up) or !empty($down)) and !empty($iselect) and confirm_sesskey()) {
115 if ($allfilters[$iselect]) {
116 foreach ($installedfilters as $key => $installedfilter) {
117 if ($installedfilter == $iselect) {
126 if ($allfilters[$iselect]) {
128 foreach ($installedfilters as $key => $installedfilter) {
133 if ($installedfilter == $iselect) {
140 if (isset($swapfilter) and isset($movefilter)) {
141 $tempfilter = $installedfilters[$swapfilter];
142 $installedfilters[$swapfilter] = $installedfilters[$movefilter];
143 $installedfilters[$movefilter] = $tempfilter;
144 set_config("textfilters", implode(',', $installedfilters));
146 $selectedfilter = $iselect;
151 /// Make an array of all the currently uninstalled filters
153 $uninstalledfilters = array();
154 foreach ($allfilters as $filter => $name) {
156 foreach ($installedfilters as $installedfilter) {
157 if ($installedfilter == $filter) {
162 $uninstalledfilters[] = $filter;
166 /// Print the current form
168 include("filters.html");