MDL-69521 core: Move all comments in code from 4.1 to 3.11
[moodle.git] / message / defaultoutputs.php
CommitLineData
1d72e9d4
RK
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
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.
8//
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.
13//
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/>.
16
17/**
18 * Default message outputs configuration page
19 *
6fbd60ef
AD
20 * @package core_message
21 * @copyright 2011 Lancaster University Network Services Limited
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4bbec310
AA
23 *
24 * @deprecated since Moodle 3.7 MDL-64495. Please use /admin/message.php instead.
74ee34fd 25 * @todo MDL-64866 This will be deleted in Moodle 3.11.
1d72e9d4 26 */
1fcf0ca8 27require_once(__DIR__ . '/../config.php');
60bbe768 28require_once($CFG->dirroot . '/message/lib.php');
1d72e9d4
RK
29require_once($CFG->libdir.'/adminlib.php');
30
31// This is an admin page
32admin_externalpage_setup('defaultmessageoutputs');
33
1d72e9d4
RK
34// Fetch processors
35$processors = get_message_processors(true);
36// Fetch message providers
7fcd3c30 37$providers = get_message_providers();
1d72e9d4
RK
38
39if (($form = data_submitted()) && confirm_sesskey()) {
40 $preferences = array();
41 // Prepare default message outputs settings
42 foreach ( $providers as $provider) {
43 $componentproviderbase = $provider->component.'_'.$provider->name;
fd0f7ac5
RT
44 $disableprovidersetting = $componentproviderbase.'_disable';
45 $providerdisabled = false;
46 if (!isset($form->$disableprovidersetting)) {
47 $providerdisabled = true;
48 $preferences[$disableprovidersetting] = 1;
49 } else {
50 $preferences[$disableprovidersetting] = 0;
51 }
52
1d72e9d4
RK
53 foreach (array('permitted', 'loggedin', 'loggedoff') as $setting){
54 $value = null;
55 $componentprovidersetting = $componentproviderbase.'_'.$setting;
56 if ($setting == 'permitted') {
57 // if we deal with permitted select element, we need to create individual
58 // setting for each possible processor. Note that this block will
59 // always be processed first after entring parental foreach iteration
60 // so we can change form values on this stage.
61 foreach($processors as $processor) {
62 $value = '';
63 if (isset($form->{$componentprovidersetting}[$processor->name])) {
64 $value = $form->{$componentprovidersetting}[$processor->name];
65 }
66 // Ensure that loggedin loggedoff options are set correctly
67 // for this permission
fd0f7ac5 68 if (($value == 'disallowed') || $providerdisabled) {
1d72e9d4
RK
69 // It might be better to unset them, but I can't figure out why that cause error
70 $form->{$componentproviderbase.'_loggedin'}[$processor->name] = 0;
71 $form->{$componentproviderbase.'_loggedoff'}[$processor->name] = 0;
fd0f7ac5
RT
72 } else if ($value == 'forced') {
73 $form->{$componentproviderbase.'_loggedin'}[$processor->name] = 1;
74 $form->{$componentproviderbase.'_loggedoff'}[$processor->name] = 1;
1d72e9d4
RK
75 }
76 // record the site preference
77 $preferences[$processor->name.'_provider_'.$componentprovidersetting] = $value;
78 }
f4feabb8 79 } else if (property_exists($form, $componentprovidersetting)) {
1d72e9d4
RK
80 // we must be processing loggedin or loggedoff checkboxes. Store
81 // defained comma-separated processors as setting value.
82 // Using array_filter eliminates elements set to 0 above
83 $value = join(',', array_keys(array_filter($form->{$componentprovidersetting})));
84 if (empty($value)) {
85 $value = null;
86 }
87 }
88 if ($setting != 'permitted') {
89 // we have already recoded site preferences for 'permitted' type
90 $preferences['message_provider_'.$componentprovidersetting] = $value;
91 }
92 }
93 }
94
95 // Update database
96 $transaction = $DB->start_delegated_transaction();
97 foreach ($preferences as $name => $value) {
98 set_config($name, $value, 'message');
99 }
100 $transaction->allow_commit();
101
102 // Redirect
103 $url = new moodle_url('defaultoutputs.php');
104 redirect($url);
105}
106
107
108
109// Page settings
bf0f06b1 110$PAGE->set_context(context_system::instance());
1d72e9d4
RK
111$PAGE->requires->js_init_call('M.core_message.init_defaultoutputs');
112
113// Grab the renderer
114$renderer = $PAGE->get_renderer('core', 'message');
115
116// Display the manage message outputs interface
814e3735 117$preferences = get_message_output_default_preferences();
1d72e9d4
RK
118$messageoutputs = $renderer->manage_defaultmessageoutputs($processors, $providers, $preferences);
119
120// Display the page
121echo $OUTPUT->header();
122echo $OUTPUT->heading(get_string('defaultmessageoutputs', 'message'));
123echo $messageoutputs;
6fbd60ef 124echo $OUTPUT->footer();