MDL-51261 admin: Fix the heading when displaying all plugins
[moodle.git] / admin / index.php
CommitLineData
8580535b 1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * Main administration script.
20 *
d078f6d3 21 * @package core
8580535b 22 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
f9903ed0 25
00be1916 26// Check that config.php exists, if not then call the install script
27if (!file_exists('../config.php')) {
28 header('Location: ../install.php');
3ba28588 29 die();
00be1916 30}
31
32// Check that PHP is of a sufficient version as soon as possible
dbe0203b 33if (version_compare(phpversion(), '5.4.4') < 0) {
00be1916 34 $phpversion = phpversion();
35 // do NOT localise - lang strings would not work here and we CAN NOT move it to later place
dbe0203b 36 echo "Moodle 2.7 or later requires at least PHP 5.4.4 (currently using version $phpversion).<br />";
eab044a0 37 echo "Please upgrade your server software or install older Moodle version.";
3ba28588 38 die();
00be1916 39}
40
695940df
PS
41// make sure iconv is available and actually works
42if (!function_exists('iconv')) {
43 // this should not happen, this must be very borked install
7d85a4e2 44 echo 'Moodle requires the iconv PHP extension. Please install or enable the iconv extension.';
695940df
PS
45 die();
46}
695940df 47
3c9535dd
JC
48// Make sure php5-json is available.
49if (!function_exists('json_encode') || !function_exists('json_decode')) {
50 // This also shouldn't happen.
51 echo 'Moodle requires the json PHP extension. Please install or enable the json extension.';
52 die();
53}
54
cbad562e 55define('NO_OUTPUT_BUFFERING', true);
00be1916 56
fc281113
PS
57if ((isset($_GET['cache']) and $_GET['cache'] === '0')
58 or (isset($_POST['cache']) and $_POST['cache'] === '0')
59 or (!isset($_POST['cache']) and !isset($_GET['cache']) and empty($_GET['sesskey']) and empty($_POST['sesskey']))) {
e2e35e71
PS
60 // Prevent caching at all cost when visiting this page directly,
61 // we redirect to self once we known no upgrades are necessary.
62 // Note: $_GET and $_POST are used here intentionally because our param cleaning is not loaded yet.
bf8c71b7 63 // Note2: the sesskey is present in all block editing hacks, we can not redirect there, so enable caching.
e2e35e71 64 define('CACHE_DISABLE_ALL', true);
c05a5099
PS
65
66 // Force OPcache reset if used, we do not want any stale caches
67 // when detecting if upgrade necessary or when running upgrade.
68 if (function_exists('opcache_reset')) {
69 opcache_reset();
70 }
82b1cf00
PS
71 $cache = 0;
72
73} else {
74 $cache = 1;
e2e35e71
PS
75}
76
00be1916 77require('../config.php');
3274c5db
FM
78
79// Invalidate the cache of version.php in any circumstances to help core_component
80// detecting if the version has changed and component cache should be reset.
81if (function_exists('opcache_invalidate')) {
82 opcache_invalidate($CFG->dirroot . '/version.php', true);
83}
84// Make sure the component cache gets rebuilt if necessary, any method that
85// indirectly calls the protected init() method is good here.
86core_component::get_core_subsystems();
87
bc76b3c0 88require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions
89require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions
00be1916 90
00be1916 91$confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL);
92$confirmrelease = optional_param('confirmrelease', 0, PARAM_BOOL);
93$confirmplugins = optional_param('confirmplugincheck', 0, PARAM_BOOL);
b9934a17 94$showallplugins = optional_param('showallplugins', 0, PARAM_BOOL);
00be1916 95$agreelicense = optional_param('agreelicense', 0, PARAM_BOOL);
55585f3a 96$fetchupdates = optional_param('fetchupdates', 0, PARAM_BOOL);
0a6a344d 97$newaddonreq = optional_param('installaddonrequest', null, PARAM_RAW);
00be1916 98
e2e35e71
PS
99// Set up PAGE.
100$url = new moodle_url('/admin/index.php');
fc281113 101$url->param('cache', $cache);
e2e35e71
PS
102$PAGE->set_url($url);
103unset($url);
104
82b1cf00 105// Are we returning from an add-on installation request at moodle.org/plugins?
835f58eb 106if ($newaddonreq and !$cache and empty($CFG->disableonclickaddoninstall)) {
82b1cf00
PS
107 $target = new moodle_url('/admin/tool/installaddon/index.php', array(
108 'installaddonrequest' => $newaddonreq,
109 'confirm' => 0));
110 if (!isloggedin() or isguestuser()) {
111 // Login and go the the add-on tool page.
112 $SESSION->wantsurl = $target->out();
113 redirect(get_login_url());
114 }
115 redirect($target);
116}
117
6d80fad4 118$PAGE->set_pagelayout('admin'); // Set a default pagelayout
ee73b1ff 119
00be1916 120$documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>';
121
e2e35e71
PS
122// Check some PHP server settings
123
00be1916 124if (ini_get_bool('session.auto_start')) {
125 print_error('phpvaroff', 'debug', '', (object)array('name'=>'session.auto_start', 'link'=>$documentationlink));
126}
127
00be1916 128if (!ini_get_bool('file_uploads')) {
129 print_error('phpvaron', 'debug', '', (object)array('name'=>'file_uploads', 'link'=>$documentationlink));
130}
131
132if (is_float_problem()) {
133 print_error('phpfloatproblem', 'admin', '', $documentationlink);
134}
135
00be1916 136// Set some necessary variables during set-up to avoid PHP warnings later on this page
00be1916 137if (!isset($CFG->release)) {
bc76b3c0 138 $CFG->release = '';
00be1916 139}
140if (!isset($CFG->version)) {
bc76b3c0 141 $CFG->version = '';
00be1916 142}
ad394588
AB
143if (!isset($CFG->branch)) {
144 $CFG->branch = '';
145}
00be1916 146
147$version = null;
148$release = null;
ed01233a
AB
149$branch = null;
150require("$CFG->dirroot/version.php"); // defines $version, $release, $branch and $maturity
00be1916 151$CFG->target_release = $release; // used during installation and upgrades
152
153if (!$version or !$release) {
154 print_error('withoutversion', 'debug'); // without version, stop
155}
156
3316fe24 157if (!core_tables_exist()) {
78946b9b 158 $PAGE->set_pagelayout('maintenance');
d3875524 159 $PAGE->set_popup_notification_allowed(false);
00be1916 160
161 // fake some settings
162 $CFG->docroot = 'http://docs.moodle.org';
163
164 $strinstallation = get_string('installation', 'install');
165
166 // remove current session content completely
d79d5ac2 167 \core\session\manager::terminate_current();
00be1916 168
169 if (empty($agreelicense)) {
170 $strlicense = get_string('license');
cc359566 171
69d77c23 172 $PAGE->navbar->add($strlicense);
173 $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
174 $PAGE->set_heading($strinstallation);
175 $PAGE->set_cacheable(false);
cc359566 176
82b1cf00 177 /** @var core_admin_renderer $output */
da2fdc3f 178 $output = $PAGE->get_renderer('core', 'admin');
cc359566 179 echo $output->install_licence_page();
3ba28588 180 die();
249ab745 181 }
00be1916 182 if (empty($confirmrelease)) {
cc359566
TH
183 require_once($CFG->libdir.'/environmentlib.php');
184 list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
bc76b3c0 185 $strcurrentrelease = get_string('currentrelease');
cc359566 186
69d77c23 187 $PAGE->navbar->add($strcurrentrelease);
1a4d6a5b
DM
188 $PAGE->set_title($strinstallation);
189 $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release);
69d77c23 190 $PAGE->set_cacheable(false);
249ab745 191
82b1cf00 192 /** @var core_admin_renderer $output */
cc359566 193 $output = $PAGE->get_renderer('core', 'admin');
8d1da748 194 echo $output->install_environment_page($maturity, $envstatus, $environment_results, $release);
3ba28588 195 die();
1dd24519 196 }
197
39f15cc7
DM
198 // check plugin dependencies
199 $failed = array();
e87214bd 200 if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) {
39f15cc7
DM
201 $PAGE->navbar->add(get_string('pluginscheck', 'admin'));
202 $PAGE->set_title($strinstallation);
203 $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release);
204
205 $output = $PAGE->get_renderer('core', 'admin');
206 $url = new moodle_url('/admin/index.php', array('agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang));
207 echo $output->unsatisfied_dependencies_page($version, $failed, $url);
208 die();
209 }
210 unset($failed);
211
8d1da748
PS
212 //TODO: add a page with list of non-standard plugins here
213
bc76b3c0 214 $strdatabasesetup = get_string('databasesetup');
543f54d3 215 upgrade_init_javascript();
cc359566 216
69d77c23 217 $PAGE->navbar->add($strdatabasesetup);
218 $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
2ea05146 219 $PAGE->set_heading($strinstallation);
69d77c23 220 $PAGE->set_cacheable(false);
cc359566 221
da2fdc3f
TH
222 $output = $PAGE->get_renderer('core', 'admin');
223 echo $output->header();
d02bc6ce 224
00be1916 225 if (!$DB->setup_is_unicodedb()) {
226 if (!$DB->change_db_encoding()) {
227 // If could not convert successfully, throw error, and prevent installation
228 print_error('unicoderequired', 'admin');
db5af934 229 }
db5af934 230 }
90509582 231
00be1916 232 install_core($version, true);
233}
db5af934 234
db5af934 235
00be1916 236// Check version of Moodle code on disk compared with database
237// and upgrade if possible.
db5af934 238
1a361486
PS
239if (!$cache) {
240 // Do not try to do anything fancy in non-cached mode,
241 // this prevents themes from fetching data from non-existent tables.
242 $PAGE->set_pagelayout('maintenance');
243 $PAGE->set_popup_notification_allowed(false);
244}
245
00be1916 246$stradministration = get_string('administration');
bf006d2c 247$PAGE->set_context(context_system::instance());
db5af934 248
00be1916 249if (empty($CFG->version)) {
250 print_error('missingconfigversion', 'debug');
251}
db5af934 252
e2e35e71 253// Detect config cache inconsistency, this happens when you switch branches on dev servers.
82b1cf00
PS
254if ($CFG->version != $DB->get_field('config', 'value', array('name'=>'version'))) {
255 purge_all_caches();
256 redirect(new moodle_url('/admin/index.php'), 'Config cache inconsistency detected, resetting caches...');
e2e35e71
PS
257}
258
82b1cf00 259if (!$cache and $version > $CFG->version) { // upgrade
6e09cf98
DM
260
261 // Warning about upgrading a test site.
262 $testsite = false;
263 if (defined('BEHAT_SITE_RUNNING')) {
264 $testsite = 'behat';
265 }
266
b0dd08dd
SH
267 // We purge all of MUC's caches here.
268 // Caches are disabled for upgrade by CACHE_DISABLE_ALL so we must set the first arg to true.
269 // This ensures a real config object is loaded and the stores will be purged.
270 // This is the only way we can purge custom caches such as memcache or APC.
271 // Note: all other calls to caches will still used the disabled API.
272 cache_helper::purge_all(true);
273 // We then purge the regular caches.
a95682b2 274 purge_all_caches();
33082590 275
fc281113
PS
276 /** @var core_admin_renderer $output */
277 $output = $PAGE->get_renderer('core', 'admin');
278
9008ec16
PS
279 if (upgrade_stale_php_files_present()) {
280 $PAGE->set_title($stradministration);
281 $PAGE->set_cacheable(false);
282
9008ec16
PS
283 echo $output->upgrade_stale_php_files_page();
284 die();
285 }
286
00be1916 287 if (empty($confirmupgrade)) {
17854cb9 288 $a = new stdClass();
c22a579b
RT
289 $a->oldversion = "$CFG->release (".sprintf('%.2f', $CFG->version).")";
290 $a->newversion = "$release (".sprintf('%.2f', $version).")";
cc359566
TH
291 $strdatabasechecking = get_string('databasechecking', '', $a);
292
1a4d6a5b
DM
293 $PAGE->set_title($stradministration);
294 $PAGE->set_heading($strdatabasechecking);
69d77c23 295 $PAGE->set_cacheable(false);
cc359566 296
6e09cf98 297 echo $output->upgrade_confirm_page($a->newversion, $maturity, $testsite);
3ba28588 298 die();
db5af934 299
00be1916 300 } else if (empty($confirmrelease)){
cc359566
TH
301 require_once($CFG->libdir.'/environmentlib.php');
302 list($envstatus, $environment_results) = check_moodle_environment($release, ENV_SELECT_RELEASE);
bc76b3c0 303 $strcurrentrelease = get_string('currentrelease');
cc359566 304
69d77c23 305 $PAGE->navbar->add($strcurrentrelease);
306 $PAGE->set_title($strcurrentrelease);
52273536 307 $PAGE->set_heading($strcurrentrelease);
69d77c23 308 $PAGE->set_cacheable(false);
db5af934 309
faadd326
TH
310 echo $output->upgrade_environment_page($release, $envstatus, $environment_results);
311 die();
db5af934 312
cc359566 313 } else if (empty($confirmplugins)) {
00be1916 314 $strplugincheck = get_string('plugincheck');
cc359566 315
69d77c23 316 $PAGE->navbar->add($strplugincheck);
317 $PAGE->set_title($strplugincheck);
52273536 318 $PAGE->set_heading($strplugincheck);
69d77c23 319 $PAGE->set_cacheable(false);
b9934a17 320
fc281113 321 $reloadurl = new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0));
ead8ba3b 322
96dd9237 323 if ($fetchupdates) {
fc281113
PS
324 // No sesskey support guaranteed here, because sessions might not work yet.
325 $updateschecker = \core\update\checker::instance();
326 if ($updateschecker->enabled()) {
327 $updateschecker->fetch();
4db58f5f 328 }
96dd9237
DM
329 redirect($reloadurl);
330 }
331
e87214bd 332 $deployer = \core\update\deployer::instance();
bcc8397a
DM
333 if ($deployer->enabled()) {
334 $deployer->initialize($reloadurl, $reloadurl);
335
336 $deploydata = $deployer->submitted_data();
337 if (!empty($deploydata)) {
fc281113 338 // No sesskey support guaranteed here, because sessions might not work yet.
bcc8397a
DM
339 echo $output->upgrade_plugin_confirm_deploy_page($deployer, $deploydata);
340 die();
341 }
342 }
343
e87214bd 344 echo $output->upgrade_plugin_check_page(core_plugin_manager::instance(), \core\update\checker::instance(),
96dd9237 345 $version, $showallplugins, $reloadurl,
fc281113 346 new moodle_url('/admin/index.php', array('confirmupgrade'=>1, 'confirmrelease'=>1, 'confirmplugincheck'=>1, 'cache'=>0)));
00be1916 347 die();
db5af934 348
00be1916 349 } else {
fc281113
PS
350 // Always verify plugin dependencies!
351 $failed = array();
352 if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) {
fc281113
PS
353 $reloadurl = new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0));
354 echo $output->unsatisfied_dependencies_page($version, $failed, $reloadurl);
355 die();
356 }
357 unset($failed);
358
359 // Launch main upgrade.
00be1916 360 upgrade_core($version, true);
88582df4 361 }
00be1916 362} else if ($version < $CFG->version) {
80380bd7
PS
363 // better stop here, we can not continue with plugin upgrades or anything else
364 throw new moodle_exception('downgradedcore', 'error', new moodle_url('/admin/'));
00be1916 365}
366
367// Updated human-readable release version if necessary
82b1cf00 368if (!$cache and $release <> $CFG->release) { // Update the release version
bc76b3c0 369 set_config('release', $release);
00be1916 370}
371
82b1cf00 372if (!$cache and $branch <> $CFG->branch) { // Update the branch
ed01233a
AB
373 set_config('branch', $branch);
374}
375
82b1cf00 376if (!$cache and moodle_needs_upgrading()) {
575f245f 377 if (!$PAGE->headerprinted) {
2361b7dd 378 // means core upgrade or installation was not already done
fc281113 379
575f245f 380 if (!$confirmplugins) {
cc359566
TH
381 $strplugincheck = get_string('plugincheck');
382
575f245f
PS
383 $PAGE->navbar->add($strplugincheck);
384 $PAGE->set_title($strplugincheck);
385 $PAGE->set_heading($strplugincheck);
386 $PAGE->set_cacheable(false);
b9934a17 387
96dd9237 388 if ($fetchupdates) {
fc281113
PS
389 require_sesskey();
390 $updateschecker = \core\update\checker::instance();
391 if ($updateschecker->enabled()) {
392 $updateschecker->fetch();
393 }
96dd9237
DM
394 redirect($PAGE->url);
395 }
396
12890c57
SH
397 /** @var core_admin_renderer $output */
398 $output = $PAGE->get_renderer('core', 'admin');
399
e87214bd 400 $deployer = \core\update\deployer::instance();
292dbeac
DM
401 if ($deployer->enabled()) {
402 $deployer->initialize($PAGE->url, $PAGE->url);
403
404 $deploydata = $deployer->submitted_data();
405 if (!empty($deploydata)) {
fc281113 406 require_sesskey();
292dbeac
DM
407 echo $output->upgrade_plugin_confirm_deploy_page($deployer, $deploydata);
408 die();
409 }
410 }
411
fc281113 412 // Show plugins info.
e87214bd 413 echo $output->upgrade_plugin_check_page(core_plugin_manager::instance(), \core\update\checker::instance(),
96dd9237
DM
414 $version, $showallplugins,
415 new moodle_url($PAGE->url),
fc281113
PS
416 new moodle_url('/admin/index.php', array('confirmplugincheck'=>1, 'cache'=>0)));
417 die();
418 }
419
420 // Make sure plugin dependencies are always checked.
421 $failed = array();
422 if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) {
12890c57
SH
423 /** @var core_admin_renderer $output */
424 $output = $PAGE->get_renderer('core', 'admin');
fc281113
PS
425 $reloadurl = new moodle_url('/admin/index.php', array('cache' => 0));
426 echo $output->unsatisfied_dependencies_page($version, $failed, $reloadurl);
575f245f
PS
427 die();
428 }
fc281113 429 unset($failed);
575f245f 430 }
fc281113 431
575f245f
PS
432 // install/upgrade all plugins and other parts
433 upgrade_noncore(true);
434}
00be1916 435
31a99877 436// If this is the first install, indicate that this site is fully configured
437// except the admin password
438if (during_initial_install()) {
439 set_config('rolesactive', 1); // after this, during_initial_install will return false.
00be1916 440 set_config('adminsetuppending', 1);
c8ae55e9 441 // we need this redirect to setup proper session
00be1916 442 upgrade_finished("index.php?sessionstarted=1&amp;lang=$CFG->lang");
443}
444
445// make sure admin user is created - this is the last step because we need
446// session to be working properly in order to edit admin account
447 if (!empty($CFG->adminsetuppending)) {
448 $sessionstarted = optional_param('sessionstarted', 0, PARAM_BOOL);
449 if (!$sessionstarted) {
450 redirect("index.php?sessionstarted=1&lang=$CFG->lang");
451 } else {
452 $sessionverify = optional_param('sessionverify', 0, PARAM_BOOL);
453 if (!$sessionverify) {
454 $SESSION->sessionverify = 1;
455 redirect("index.php?sessionstarted=1&sessionverify=1&lang=$CFG->lang");
88582df4 456 } else {
00be1916 457 if (empty($SESSION->sessionverify)) {
458 print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang");
88582df4 459 }
00be1916 460 unset($SESSION->sessionverify);
88582df4 461 }
00be1916 462 }
88582df4 463
4f73591a
PS
464 // Cleanup SESSION to make sure other code does not complain in the future.
465 unset($SESSION->has_timed_out);
466 unset($SESSION->wantsurl);
467
a7c9609b 468 // at this stage there can be only one admin unless more were added by install - users may change username, so do not rely on that
f20edd52
PS
469 $adminids = explode(',', $CFG->siteadmins);
470 $adminuser = get_complete_user_data('id', reset($adminids));
88582df4 471
00be1916 472 if ($adminuser->password === 'adminsetuppending') {
473 // prevent installation hijacking
474 if ($adminuser->lastip !== getremoteaddr()) {
475 print_error('installhijacked', 'admin');
35d6a2a4 476 }
00be1916 477 // login user and let him set password and admin details
478 $adminuser->newadminuser = 1;
0342fc36 479 complete_user_login($adminuser);
00be1916 480 redirect("$CFG->wwwroot/user/editadvanced.php?id=$adminuser->id"); // Edit thyself
db5af934 481
5c144d60 482 } else {
00be1916 483 unset_config('adminsetuppending');
4da1a0a1 484 }
485
00be1916 486} else {
487 // just make sure upgrade logging is properly terminated
488 upgrade_finished('upgradesettings.php');
489}
b3732604 490
fc281113
PS
491if (has_capability('moodle/site:config', context_system::instance())) {
492 if ($fetchupdates) {
493 require_sesskey();
494 $updateschecker = \core\update\checker::instance();
495 if ($updateschecker->enabled()) {
496 $updateschecker->fetch();
497 }
498 redirect(new moodle_url('/admin/index.php', array('cache' => 0)));
499 }
500}
501
e2e35e71
PS
502// Now we can be sure everything was upgraded and caches work fine,
503// redirect if necessary to make sure caching is enabled.
82b1cf00
PS
504if (!$cache) {
505 redirect(new moodle_url('/admin/index.php', array('cache' => 1)));
e2e35e71
PS
506}
507
00be1916 508// Check for valid admin user - no guest autologin
509require_login(0, false);
fc1d0e82
510if (isguestuser()) {
511 // Login as real user!
512 $SESSION->wantsurl = (string)new moodle_url('/admin/index.php');
513 redirect(get_login_url());
514}
bf006d2c 515$context = context_system::instance();
336a8433
MG
516
517if (!has_capability('moodle/site:config', $context)) {
518 // Do not throw exception display an empty page with administration menu if visible for current user.
519 $PAGE->set_title($SITE->fullname);
520 $PAGE->set_heading($SITE->fullname);
521 echo $OUTPUT->header();
522 echo $OUTPUT->footer();
523 exit;
524}
00be1916 525
526// check that site is properly customized
527$site = get_site();
528if (empty($site->shortname)) {
529 // probably new installation - lets return to frontpage after this step
530 // remove settings that we want uninitialised
531 unset_config('registerauth');
d6e7a63d 532 unset_config('timezone'); // Force admin to select timezone!
00be1916 533 redirect('upgradesettings.php?return=site');
534}
535
00be1916 536// setup critical warnings before printing admin tree block
bc76b3c0 537$insecuredataroot = is_dataroot_insecure(true);
00be1916 538$SESSION->admin_critical_warning = ($insecuredataroot==INSECURE_DATAROOT_ERROR);
539
540$adminroot = admin_get_root();
541
542// Check if there are any new admin settings which have still yet to be set
543if (any_new_admin_settings($adminroot)){
544 redirect('upgradesettings.php');
545}
546
e87214bd
PS
547// Return to original page that started the plugin uninstallation if necessary.
548if (isset($SESSION->pluginuninstallreturn)) {
549 $return = $SESSION->pluginuninstallreturn;
550 unset($SESSION->pluginuninstallreturn);
551 if ($return) {
552 redirect($return);
553 }
554}
555
00be1916 556// Everything should now be set up, and the user is an admin
557
558// Print default admin page with notifications.
cc359566 559$errorsdisplayed = defined('WARN_DISPLAY_ERRORS_ENABLED');
a95682b2 560
d5fcf4b4
DP
561// We make the assumption that at least one schedule task should run once per day.
562$lastcron = $DB->get_field_sql('SELECT MAX(lastruntime) FROM {task_scheduled}');
cc359566
TH
563$cronoverdue = ($lastcron < time() - 3600 * 24);
564$dbproblems = $DB->diagnose();
565$maintenancemode = !empty($CFG->maintenance_enabled);
74944b73 566
ca6f3a8b 567// Available updates for Moodle core.
e87214bd 568$updateschecker = \core\update\checker::instance();
966bd785 569$availableupdates = array();
ca6f3a8b
FM
570$availableupdatesfetch = null;
571
572if (empty($CFG->disableupdatenotifications)) {
573 // Only compute the update information when it is going to be displayed to the user.
574 $availableupdates['core'] = $updateschecker->get_update_info('core',
575 array('minmaturity' => $CFG->updateminmaturity, 'notifybuilds' => $CFG->updatenotifybuilds));
576
577 // Available updates for contributed plugins
578 $pluginman = core_plugin_manager::instance();
579 foreach ($pluginman->get_plugins() as $plugintype => $plugintypeinstances) {
580 foreach ($plugintypeinstances as $pluginname => $plugininfo) {
581 if (!empty($plugininfo->availableupdates)) {
582 foreach ($plugininfo->availableupdates as $pluginavailableupdate) {
583 if ($pluginavailableupdate->version > $plugininfo->versiondisk) {
584 if (!isset($availableupdates[$plugintype.'_'.$pluginname])) {
585 $availableupdates[$plugintype.'_'.$pluginname] = array();
586 }
587 $availableupdates[$plugintype.'_'.$pluginname][] = $pluginavailableupdate;
966bd785 588 }
966bd785
DM
589 }
590 }
591 }
592 }
966bd785 593
ca6f3a8b
FM
594 // The timestamp of the most recent check for available updates
595 $availableupdatesfetch = $updateschecker->get_last_timefetched();
596}
55585f3a 597
0aff15c2 598$buggyiconvnomb = (!function_exists('mb_convert_encoding') and @iconv('UTF-8', 'UTF-8//IGNORE', '100'.chr(130).'€') !== '100€');
b3245b75
DP
599//check if the site is registered on Moodle.org
600$registered = $DB->count_records('registration_hubs', array('huburl' => HUB_MOODLEORGHUBURL, 'confirmed' => 1));
915140c9
SH
601// Check if there are any cache warnings.
602$cachewarnings = cache_helper::warnings();
0aff15c2 603
cc359566 604admin_externalpage_setup('adminnotifications');
55585f3a 605
915140c9 606/* @var core_admin_renderer $output */
cc359566 607$output = $PAGE->get_renderer('core', 'admin');
915140c9
SH
608
609echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, $cronoverdue, $dbproblems,
610 $maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb,
611 $registered, $cachewarnings);