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.
   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   * Request access key to AirNotifier
  19   *
  20   * @package    message_airnotifier
  21   * @copyright  2012 Jerome Mouneyrac
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require('../../../config.php');
  26  
  27  $PAGE->set_url(new moodle_url('/message/output/airnotifier/requestaccesskey.php'));
  28  $PAGE->set_context(context_system::instance());
  29  
  30  require_login();
  31  require_sesskey();
  32  require_capability('moodle/site:config', context_system::instance());
  33  
  34  $strheading = get_string('requestaccesskey', 'message_airnotifier');
  35  $PAGE->navbar->add(get_string('administrationsite'));
  36  $PAGE->navbar->add(get_string('plugins', 'admin'));
  37  $PAGE->navbar->add(get_string('messageoutputs', 'message'));
  38  $returl = new moodle_url('/admin/settings.php', array('section' => 'messagesettingairnotifier'));
  39  $PAGE->navbar->add(get_string('pluginname', 'message_airnotifier'), $returl);
  40  $PAGE->navbar->add($strheading);
  41  
  42  $PAGE->set_heading($strheading);
  43  $PAGE->set_title($strheading);
  44  
  45  $msg = "";
  46  
  47  // If we are requesting a key to the official message system, verify first that this site is registered.
  48  // This check is also done in Airnotifier.
  49  if (strpos($CFG->airnotifierurl, message_airnotifier_manager::AIRNOTIFIER_PUBLICURL) !== false ) {
  50      $adminrenderer = $PAGE->get_renderer('core', 'admin');
  51      $msg = $adminrenderer->warn_if_not_registered();
  52      if ($msg) {
  53          $msg .= html_writer::div(get_string('sitemustberegistered', 'message_airnotifier'));
  54  
  55          echo $OUTPUT->header();
  56          echo $OUTPUT->box($msg, 'generalbox');
  57          echo $OUTPUT->footer();
  58          die;
  59      }
  60  }
  61  
  62  echo $OUTPUT->header();
  63  
  64  $manager = new message_airnotifier_manager();
  65  $warnings = [];
  66  
  67  if ($key = $manager->request_accesskey()) {
  68      set_config('airnotifieraccesskey', $key);
  69      $msg = $OUTPUT->box(get_string('keyretrievedsuccessfully', 'message_airnotifier'), 'generalbox alert alert-success');
  70  
  71      // Check mobile notifications.
  72      $processors = get_message_processors();
  73      $enabled = false;
  74      foreach ($processors as $processor => $status) {
  75          if ($processor == 'airnotifier' && $status->enabled) {
  76              $enabled = true;
  77          }
  78      }
  79  
  80      if (!$enabled) {
  81          // Airnotifier processor isn't enabled. Warn the user.
  82          $warnings[] = [
  83              'msg' => get_string('mobilenotificationsdisabledwarning', 'tool_mobile'),
  84              'linkmsg' => get_string('enableprocessor', 'message_airnotifier'),
  85              'linkurl' => new moodle_url('/admin/message.php'),
  86          ];
  87      }
  88  
  89      if (empty($CFG->enablemobilewebservice)) {
  90          // Mobile web services not enabled. Warn the user.
  91          $warnings[] = [
  92              'msg' => get_string('mobilenotconfiguredwarning', 'admin'),
  93              'linkmsg' => get_string('enablemobilewebservice', 'admin'),
  94              'linkurl' => new moodle_url('/admin/settings.php', ['section' => 'mobilesettings']),
  95          ];
  96      }
  97  } else {
  98      $msg = $OUTPUT->box(get_string('errorretrievingkey', 'message_airnotifier'), 'generalbox alert alert-danger');
  99  }
 100  
 101  // Display the warnings.
 102  foreach ($warnings as $warning) {
 103      if (!empty($warning['linkurl'])) {
 104          $warning['msg'] = $warning['msg'] . '&nbsp;' . html_writer::tag('a', $warning['linkmsg'], ['href' => $warning['linkurl']]);
 105      }
 106  
 107      $msg .= $OUTPUT->box($warning['msg'], 'generalbox alert alert-warning');
 108  }
 109  
 110  $msg .= $OUTPUT->continue_button($returl);
 111  
 112  echo $OUTPUT->box($msg, 'generalbox ');
 113  echo $OUTPUT->footer();