Commit | Line | Data |
---|---|---|
3570f5e2 JL |
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'); | |
3570f5e2 | 26 | |
2bb01d13 | 27 | define('AIRNOTIFIER_PUBLICURL', 'https://messages.moodle.net'); |
3570f5e2 JL |
28 | |
29 | $PAGE->set_url(new moodle_url('/message/output/airnotifier/requestaccesskey.php')); | |
30 | $PAGE->set_context(context_system::instance()); | |
31 | ||
32 | require_login(); | |
d62c3c6e | 33 | require_sesskey(); |
3570f5e2 JL |
34 | require_capability('moodle/site:config', context_system::instance()); |
35 | ||
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); | |
43 | ||
44 | $PAGE->set_heading($strheading); | |
45 | $PAGE->set_title($strheading); | |
46 | ||
47 | $msg = ""; | |
48 | ||
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 ) { | |
505bbe7c MG |
52 | $adminrenderer = $PAGE->get_renderer('core', 'admin'); |
53 | $msg = $adminrenderer->warn_if_not_registered(); | |
54 | if ($msg) { | |
55 | $msg .= html_writer::div(get_string('sitemustberegistered', 'message_airnotifier')); | |
3570f5e2 JL |
56 | |
57 | echo $OUTPUT->header(); | |
58 | echo $OUTPUT->box($msg, 'generalbox'); | |
59 | echo $OUTPUT->footer(); | |
60 | die; | |
61 | } | |
62 | } | |
63 | ||
64 | $manager = new message_airnotifier_manager(); | |
fbe3178a | 65 | $warnings = []; |
3570f5e2 JL |
66 | |
67 | if ($key = $manager->request_accesskey()) { | |
68 | set_config('airnotifieraccesskey', $key); | |
fbe3178a DP |
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 | } | |
3570f5e2 | 97 | } else { |
fbe3178a DP |
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'] . ' ' . html_writer::tag('a', $warning['linkmsg'], ['href' => $warning['linkurl']]); | |
105 | } | |
106 | ||
107 | $msg .= $OUTPUT->box($warning['msg'], 'generalbox alert alert-warning'); | |
3570f5e2 JL |
108 | } |
109 | ||
110 | $msg .= $OUTPUT->continue_button($returl); | |
111 | ||
112 | echo $OUTPUT->header(); | |
113 | echo $OUTPUT->box($msg, 'generalbox '); | |
114 | echo $OUTPUT->footer(); |