Merge branch 'MDL-79705-402' of https://github.com/paulholden/moodle into MOODLE_402_...
[moodle.git] / message / output / airnotifier / checkconfiguration.php
blob4aa8d34d99122bd183831f4f1dd63461a1651fd7
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.
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/>.
17 /**
18 * Check and test Push notifications configuration.
20 * @package message_airnotifier
21 * @copyright 2020 Juan Leyva
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require('../../../config.php');
26 require_once($CFG->libdir . '/filelib.php');
28 $pageurl = new moodle_url('/message/output/airnotifier/checkconfiguration.php');
29 $PAGE->set_url($pageurl);
30 $PAGE->set_context(context_system::instance());
32 require_login();
33 require_capability('moodle/site:config', context_system::instance());
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);
44 $PAGE->set_heading($SITE->fullname);
45 $PAGE->set_title($strheading);
47 $manager = new message_airnotifier_manager();
49 // Sending a test Push notification.
50 if (data_submitted()) {
51 require_sesskey();
53 if (optional_param('confirm', 0, PARAM_INT)) {
54 $manager->send_test_notification($USER);
56 redirect($pageurl, get_string('eventnotificationsent', 'message'), 5);
57 } else {
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);
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();
72 die;
75 $checkresults = $manager->check_configuration();
77 $table = new \html_table();
78 $table->data = [];
79 $table->head = [
80 get_string('status'),
81 get_string('check'),
82 get_string('summary'),
84 $table->colclasses = [
85 'rightalign status',
86 'leftalign check',
87 'leftalign summary',
89 $table->id = 'message_airnotifier_checkconfiguration';
90 $table->attributes = ['class' => 'admintable generaltable'];
91 $table->data = [];
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;
98 $table->data[] = [$OUTPUT->check_result($result), $result->get_summary(), $result->get_details()];
101 echo $OUTPUT->header();
102 echo $OUTPUT->heading($strheading);
104 // Check table.
105 echo \html_writer::table($table);
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');
111 echo $OUTPUT->footer();