2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * Request access key to AirNotifier
20 * @package message_airnotifier
21 * @copyright 2012 Jerome Mouneyrac
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require('../../../config.php');
27 define('AIRNOTIFIER_PUBLICURL', 'https://messages.moodle.net');
29 $PAGE->set_url(new moodle_url('/message/output/airnotifier/requestaccesskey.php'));
30 $PAGE->set_context(context_system::instance());
34 require_capability('moodle/site:config', context_system::instance());
36 $strheading = get_string('requestaccesskey', 'message_airnotifier');
37 $PAGE->navbar->add(get_string('administrationsite'));
38 $PAGE->navbar->add(get_string('plugins', 'admin'));
39 $PAGE->navbar->add(get_string('messageoutputs', 'message'));
40 $returl = new moodle_url('/admin/settings.php', array('section' => 'messagesettingairnotifier'));
41 $PAGE->navbar->add(get_string('pluginname', 'message_airnotifier'), $returl);
42 $PAGE->navbar->add($strheading);
44 $PAGE->set_heading($strheading);
45 $PAGE->set_title($strheading);
49 // If we are requesting a key to the official message system, verify first that this site is registered.
50 // This check is also done in Airnotifier.
51 if (strpos($CFG->airnotifierurl, AIRNOTIFIER_PUBLICURL) !== false ) {
52 $adminrenderer = $PAGE->get_renderer('core', 'admin');
53 $msg = $adminrenderer->warn_if_not_registered();
55 $msg .= html_writer::div(get_string('sitemustberegistered', 'message_airnotifier'));
57 echo $OUTPUT->header();
58 echo $OUTPUT->box($msg, 'generalbox');
59 echo $OUTPUT->footer();
64 $manager = new message_airnotifier_manager();
66 if ($key = $manager->request_accesskey()) {
67 set_config('airnotifieraccesskey', $key);
68 $msg = get_string('keyretrievedsuccessfully', 'message_airnotifier');
70 $msg = get_string('errorretrievingkey', 'message_airnotifier');
73 $msg .= $OUTPUT->continue_button($returl);
75 echo $OUTPUT->header();
76 echo $OUTPUT->box($msg, 'generalbox ');
77 echo $OUTPUT->footer();