2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Message outputs configuration page
21 * @copyright 2011 Lancaster University Network Services Limited
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 require_once(__DIR__
. '/../config.php');
25 require_once($CFG->dirroot
. '/message/lib.php');
26 require_once($CFG->libdir
.'/adminlib.php');
28 // This is an admin page.
29 admin_externalpage_setup('managemessageoutputs');
32 $allprocessors = get_message_processors();
33 $processors = array_filter($allprocessors, function($processor) {
34 return $processor->enabled
;
36 $disabledprocessors = array_filter($allprocessors, function($processor) {
37 return !$processor->enabled
;
40 // Fetch message providers.
41 $providers = get_message_providers();
42 // Fetch the manage message outputs interface.
43 $preferences = get_message_output_default_preferences();
45 if (($form = data_submitted()) && confirm_sesskey()) {
46 $newpreferences = array();
47 // Prepare default message outputs settings.
48 foreach ($providers as $provider) {
49 $componentproviderbase = $provider->component
.'_'.$provider->name
;
50 $disableprovidersetting = $componentproviderbase.'_disable';
51 if (!isset($form->$disableprovidersetting)) {
52 $newpreferences[$disableprovidersetting] = 1;
54 $newpreferences[$disableprovidersetting] = 0;
57 $componentprovidersetting = $componentproviderbase.'_locked';
58 foreach ($processors as $processor) {
60 if (isset($form->{$componentprovidersetting}[$processor->name
])) {
61 $value = $form->{$componentprovidersetting}[$processor->name
];
67 // Record the site preference.
68 $newpreferences[$processor->name
.'_provider_'.$componentprovidersetting] = $value;
71 $componentprovidersetting = $componentproviderbase.'_enabled';
73 if (isset($form->$componentprovidersetting)) {
74 // Store defined comma-separated processors as setting value.
75 // Using array_filter eliminates elements set to 0 above.
76 $newsettings = array_keys(array_filter($form->{$componentprovidersetting}));
79 // Let's join existing setting values for disabled processors.
80 $property = 'message_provider_'.$componentprovidersetting;
81 if (property_exists($preferences, $property)) {
82 $existingsetting = $preferences->$property;
83 foreach ($disabledprocessors as $disable) {
84 if (strpos($existingsetting, $disable->name
) > -1) {
85 $newsettings[] = $disable->name
;
90 $value = join(',', $newsettings);
95 // Record the site preference.
96 $newpreferences['message_provider_'.$componentprovidersetting] = $value;
100 $transaction = $DB->start_delegated_transaction();
102 // Save processors enabled/disabled status.
103 foreach ($allprocessors as $processor) {
104 $enabled = isset($form->{$processor->name
});
105 $class = \core_plugin_manager
::resolve_plugininfo_class('message');
106 $class::enable_plugin($processor->name
, $enabled);
109 foreach ($newpreferences as $name => $value) {
110 $old = isset($preferences->$name) ?
$preferences->$name : '';
112 if ($old != $value) {
113 add_to_config_log($name, $old, $value, 'core');
116 set_config($name, $value, 'message');
118 $transaction->allow_commit();
120 core_plugin_manager
::reset_caches();
122 $url = new moodle_url('message.php');
127 $PAGE->set_context(context_system
::instance());
128 $renderer = $PAGE->get_renderer('core', 'message');
131 echo $OUTPUT->header();
132 echo $renderer->manage_messageoutput_settings($allprocessors, $processors, $providers, $preferences);
133 echo $OUTPUT->footer();