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   * Check and test Push notifications configuration.
  19   *
  20   * @package    message_airnotifier
  21   * @copyright  2020 Juan Leyva
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require('../../../config.php');
  26  require_once($CFG->libdir . '/filelib.php');
  27  
  28  $pageurl = new moodle_url('/message/output/airnotifier/checkconfiguration.php');
  29  $PAGE->set_url($pageurl);
  30  $PAGE->set_context(context_system::instance());
  31  
  32  require_login();
  33  require_capability('moodle/site:config', context_system::instance());
  34  
  35  // Build a path.
  36  $strheading = get_string('checkconfiguration', 'message_airnotifier');
  37  $PAGE->navbar->add(get_string('administrationsite'));
  38  $returl = new moodle_url('/admin/category.php', ['category' => 'messaging']);
  39  $PAGE->navbar->add(get_string('messagingcategory', 'admin'), $returl);
  40  $returl = new moodle_url('/admin/settings.php', ['section' => 'messagesettingairnotifier']);
  41  $PAGE->navbar->add(get_string('pluginname', 'message_airnotifier'), $returl);
  42  $PAGE->navbar->add($strheading);
  43  
  44  $PAGE->set_heading($SITE->fullname);
  45  $PAGE->set_title($strheading);
  46  
  47  $manager = new message_airnotifier_manager();
  48  
  49  // Sending a test Push notification.
  50  if (data_submitted()) {
  51      require_sesskey();
  52  
  53      if (optional_param('confirm', 0, PARAM_INT)) {
  54          $manager->send_test_notification($USER);
  55  
  56          redirect($pageurl, get_string('eventnotificationsent', 'message'), 5);
  57      } else {
  58  
  59          if (!$manager->has_enabled_devices($CFG->airnotifiermobileappname)) {
  60              // The user has not connected to the site with the app yet.
  61              redirect($pageurl, get_string('nodevices', 'message_airnotifier'), 5, \core\output\notification::NOTIFY_ERROR);
  62          }
  63  
  64          echo $OUTPUT->header();
  65          $message = get_string('sendtestconfirmation', 'message_airnotifier');
  66          $confirmurl = new moodle_url($pageurl->out(false), ['confirm' => 1]);
  67          $continueb = new single_button($confirmurl, get_string('continue'), 'post');
  68          $cancelb = new single_button($pageurl, get_string('cancel'), 'get');
  69          echo $OUTPUT->confirm($message, $continueb, $cancelb);
  70          echo $OUTPUT->footer();
  71      }
  72      die;
  73  }
  74  
  75  $checkresults = $manager->check_configuration();
  76  
  77  $table = new \html_table();
  78  $table->data = [];
  79  $table->head  = [
  80      get_string('status'),
  81      get_string('check'),
  82      get_string('summary'),
  83  ];
  84  $table->colclasses = [
  85      'rightalign status',
  86      'leftalign check',
  87      'leftalign summary',
  88  ];
  89  $table->id = 'message_airnotifier_checkconfiguration';
  90  $table->attributes = ['class' => 'admintable generaltable'];
  91  $table->data = [];
  92  
  93  $senddisabled = false;
  94  foreach ($checkresults as $result) {
  95      if ($result->get_status() == core\check\result::CRITICAL || $result->get_status() == core\check\result::ERROR) {
  96          $senddisabled = true;
  97      }
  98      $table->data[] = [$OUTPUT->check_result($result), $result->get_summary(), $result->get_details()];
  99  }
 100  
 101  echo $OUTPUT->header();
 102  echo $OUTPUT->heading($strheading);
 103  
 104  // Check table.
 105  echo \html_writer::table($table);
 106  
 107  // Test notification button.
 108  $button = $OUTPUT->single_button($PAGE->url, get_string('sendtest', 'message_airnotifier'), 'post', ['disabled' => $senddisabled]);
 109  echo $OUTPUT->box($button, 'clearfix mdl-align');
 110  
 111  echo $OUTPUT->footer();