Merge branch 'MDL-64064' of https://github.com/NeillM/moodle
[moodle.git] / index.php
CommitLineData
474f6bfe 1<?php
af9f5430
PS
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 * Moodle frontpage.
19 *
20 * @package core
21 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
0cfb6a52 24
c9edde8b
DB
25if (!file_exists('./config.php')) {
26 header('Location: install.php');
27 die;
28}
29
30require_once('config.php');
31require_once($CFG->dirroot .'/course/lib.php');
32require_once($CFG->libdir .'/filelib.php');
33
34redirect_if_major_upgrade_required();
35
36$urlparams = array();
37if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && optional_param('redirect', 1, PARAM_BOOL) === 0) {
38 $urlparams['redirect'] = 0;
39}
40$PAGE->set_url('/', $urlparams);
e8a7f5ff 41$PAGE->set_pagelayout('frontpage');
c9edde8b
DB
42$PAGE->set_other_editing_capability('moodle/course:update');
43$PAGE->set_other_editing_capability('moodle/course:manageactivities');
44$PAGE->set_other_editing_capability('moodle/course:activityvisibility');
45
46// Prevent caching of this page to stop confusion when changing page after making AJAX changes.
47$PAGE->set_cacheable(false);
48
ce3f8046 49require_course_login($SITE);
c9edde8b 50
59c66f92 51$hasmaintenanceaccess = has_capability('moodle/site:maintenanceaccess', context_system::instance());
c9edde8b
DB
52
53// If the site is currently under maintenance, then print a message.
59c66f92 54if (!empty($CFG->maintenance_enabled) and !$hasmaintenanceaccess) {
c9edde8b
DB
55 print_maintenance_message();
56}
57
59c66f92
MD
58$hassiteconfig = has_capability('moodle/site:config', context_system::instance());
59
c9edde8b
DB
60if ($hassiteconfig && moodle_needs_upgrading()) {
61 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
62}
63
1095afa4
MG
64// If site registration needs updating, redirect.
65\core\hub\registration::registration_reminder('/index.php');
66
c9edde8b
DB
67if (get_home_page() != HOMEPAGE_SITE) {
68 // Redirect logged-in users to My Moodle overview if required.
69 $redirect = optional_param('redirect', 1, PARAM_BOOL);
70 if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
71 set_user_preference('user_home_page_preference', HOMEPAGE_SITE);
72 } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && $redirect === 1) {
73 redirect($CFG->wwwroot .'/my/');
74 } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_USER)) {
d9926e86
AG
75 $frontpagenode = $PAGE->settingsnav->find('frontpage', null);
76 if ($frontpagenode) {
77 $frontpagenode->add(
78 get_string('makethismyhome'),
79 new moodle_url('/', array('setdefaulthome' => true)),
80 navigation_node::TYPE_SETTING);
81 } else {
82 $frontpagenode = $PAGE->settingsnav->add(get_string('frontpagesettings'), null, navigation_node::TYPE_SETTING, null);
83 $frontpagenode->force_open();
84 $frontpagenode->add(get_string('makethismyhome'),
85 new moodle_url('/', array('setdefaulthome' => true)),
86 navigation_node::TYPE_SETTING);
87 }
98054db1 88 }
c9edde8b
DB
89}
90
22588835
JL
91// Trigger event.
92course_view(context_course::instance(SITEID));
c9edde8b 93
c9edde8b
DB
94$PAGE->set_pagetype('site-index');
95$PAGE->set_docs_path('');
c9edde8b
DB
96$editing = $PAGE->user_is_editing();
97$PAGE->set_title($SITE->fullname);
98$PAGE->set_heading($SITE->fullname);
99$courserenderer = $PAGE->get_renderer('core', 'course');
100echo $OUTPUT->header();
101
c9edde8b
DB
102$siteformatoptions = course_get_format($SITE)->get_format_options();
103$modinfo = get_fast_modinfo($SITE);
c9edde8b 104$modnamesused = $modinfo->get_used_module_names();
c9edde8b 105
dcce3575 106// Print Section or custom info.
c9edde8b 107if (!empty($CFG->customfrontpageinclude)) {
dcce3575
MG
108 // Pre-fill some variables that custom front page might use.
109 $modnames = get_module_types_names();
110 $modnamesplural = get_module_types_names(true);
111 $mods = $modinfo->get_cms();
112
c9edde8b
DB
113 include($CFG->customfrontpageinclude);
114
115} else if ($siteformatoptions['numsections'] > 0) {
a400dd2d 116 echo $courserenderer->frontpage_section1();
c9edde8b
DB
117}
118// Include course AJAX.
119include_course_ajax($SITE, $modnamesused);
120
dcce3575 121echo $courserenderer->frontpage();
0fd26350 122
c9edde8b
DB
123if ($editing && has_capability('moodle/course:create', context_system::instance())) {
124 echo $courserenderer->add_new_course_button();
125}
126echo $OUTPUT->footer();