Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 310]

   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   *
  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
  23   *
  24   * @deprecated since Moodle 3.7 MDL-64495. Please use /admin/message.php instead.
  25   * @todo       MDL-64866 This will be deleted in Moodle 3.11.
  26   */
  27  require_once(__DIR__ . '/../config.php');
  28  require_once($CFG->dirroot . '/message/lib.php');
  29  require_once($CFG->libdir.'/adminlib.php');
  30  
  31  // This is an admin page
  32  admin_externalpage_setup('defaultmessageoutputs');
  33  
  34  // Fetch processors
  35  $processors = get_message_processors(true);
  36  // Fetch message providers
  37  $providers = get_message_providers();
  38  
  39  if (($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;
  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  
  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
  68                      if (($value == 'disallowed') || $providerdisabled) {
  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;
  72                      } else if ($value == 'forced') {
  73                          $form->{$componentproviderbase.'_loggedin'}[$processor->name] = 1;
  74                          $form->{$componentproviderbase.'_loggedoff'}[$processor->name] = 1;
  75                      }
  76                      // record the site preference
  77                      $preferences[$processor->name.'_provider_'.$componentprovidersetting] = $value;
  78                  }
  79              } else if (property_exists($form, $componentprovidersetting)) {
  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
 110  $PAGE->set_context(context_system::instance());
 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
 117  $preferences = get_message_output_default_preferences();
 118  $messageoutputs = $renderer->manage_defaultmessageoutputs($processors, $providers, $preferences);
 119  
 120  // Display the page
 121  echo $OUTPUT->header();
 122  echo $OUTPUT->heading(get_string('defaultmessageoutputs', 'message'));
 123  echo $messageoutputs;
 124  echo $OUTPUT->footer();