Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   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   * Inbound Message Settings pages.
  19   *
  20   * @package    tool_messageinbound
  21   * @copyright  2014 Andrew NIcols
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once(__DIR__ . '/../../../config.php');
  26  require_once($CFG->libdir.'/adminlib.php');
  27  require_once($CFG->libdir.'/tablelib.php');
  28  
  29  admin_externalpage_setup('messageinbound_handlers');
  30  
  31  $classname = optional_param('classname', '', PARAM_RAW);
  32  
  33  $pageurl = new moodle_url('/admin/tool/messageinbound/index.php');
  34  
  35  $PAGE->set_primary_active_tab('siteadminnode');
  36  
  37  $PAGE->navbar->add(get_string('message_handlers', 'tool_messageinbound'), $PAGE->url);
  38  
  39  if (empty($classname)) {
  40      $renderer = $PAGE->get_renderer('tool_messageinbound');
  41  
  42      $records = $DB->get_recordset('messageinbound_handlers', null, 'enabled desc', 'classname');
  43      $instances = array();
  44      foreach ($records as $record) {
  45          $instances[] = \core\message\inbound\manager::get_handler($record->classname);
  46      }
  47      $records->close();
  48  
  49      echo $OUTPUT->header();
  50      echo $renderer->messageinbound_handlers_table($instances);
  51      echo $OUTPUT->footer();
  52  
  53  } else {
  54      // Retrieve the handler and its record.
  55      $handler = \core\message\inbound\manager::get_handler($classname);
  56      $record = \core\message\inbound\manager::record_from_handler($handler);
  57  
  58      $formurl = new moodle_url($PAGE->url, array('classname' => $classname));
  59      $mform = new tool_messageinbound_edit_handler_form($formurl, array(
  60              'handler' => $handler,
  61      ));
  62  
  63      if ($mform->is_cancelled()) {
  64          redirect($PAGE->url);
  65      } else if ($data = $mform->get_data()) {
  66  
  67          // Update the record from the form.
  68          if ($handler->can_change_defaultexpiration()) {
  69              $record->defaultexpiration = (int) $data->defaultexpiration;
  70          }
  71  
  72          if ($handler->can_change_validateaddress()) {
  73              $record->validateaddress = !empty($data->validateaddress);
  74          }
  75  
  76          if ($handler->can_change_enabled()) {
  77              $record->enabled = !empty($data->enabled);
  78          }
  79          $DB->update_record('messageinbound_handlers', $record);
  80          redirect($PAGE->url);
  81      }
  82  
  83      // Add the breadcrumb.
  84      $pageurl->param('classname', $handler->classname);
  85      $PAGE->navbar->add($handler->name, $pageurl);
  86      echo $OUTPUT->header();
  87      echo $OUTPUT->heading(get_string('editinghandler', 'tool_messageinbound', $handler->name));
  88      $mform->set_data($record);
  89      $mform->display();
  90      echo $OUTPUT->footer();
  91  
  92  }