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/>.
21 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 if (!file_exists('./config.php')) {
26 header('Location: install.php');
30 require_once('config.php');
31 require_once($CFG->dirroot
.'/course/lib.php');
32 require_once($CFG->libdir
.'/filelib.php');
34 redirect_if_major_upgrade_required();
37 if (!empty($CFG->defaulthomepage
) &&
38 ($CFG->defaulthomepage
== HOMEPAGE_MY ||
$CFG->defaulthomepage
== HOMEPAGE_MYCOURSES
) &&
39 optional_param('redirect', 1, PARAM_BOOL
) === 0
41 $urlparams['redirect'] = 0;
43 $PAGE->set_url('/', $urlparams);
44 $PAGE->set_pagelayout('frontpage');
45 $PAGE->add_body_class('limitedwidth');
46 $PAGE->set_other_editing_capability('moodle/course:update');
47 $PAGE->set_other_editing_capability('moodle/course:manageactivities');
48 $PAGE->set_other_editing_capability('moodle/course:activityvisibility');
50 // Prevent caching of this page to stop confusion when changing page after making AJAX changes.
51 $PAGE->set_cacheable(false);
53 require_course_login($SITE);
55 $hasmaintenanceaccess = has_capability('moodle/site:maintenanceaccess', context_system
::instance());
57 // If the site is currently under maintenance, then print a message.
58 if (!empty($CFG->maintenance_enabled
) and !$hasmaintenanceaccess) {
59 print_maintenance_message();
62 $hassiteconfig = has_capability('moodle/site:config', context_system
::instance());
64 if ($hassiteconfig && moodle_needs_upgrading()) {
65 redirect($CFG->wwwroot
.'/'. $CFG->admin
.'/index.php');
68 // If site registration needs updating, redirect.
69 \core\hub\registration
::registration_reminder('/index.php');
71 if (get_home_page() != HOMEPAGE_SITE
) {
72 // Redirect logged-in users to My Moodle overview if required.
73 $redirect = optional_param('redirect', 1, PARAM_BOOL
);
74 if (optional_param('setdefaulthome', false, PARAM_BOOL
)) {
75 set_user_preference('user_home_page_preference', HOMEPAGE_SITE
);
76 } else if (!empty($CFG->defaulthomepage
) && ($CFG->defaulthomepage
== HOMEPAGE_MY
) && $redirect === 1) {
77 // At this point, dashboard is enabled so we don't need to check for it (otherwise, get_home_page() won't return it).
78 redirect($CFG->wwwroot
.'/my/');
79 } else if (!empty($CFG->defaulthomepage
) && ($CFG->defaulthomepage
== HOMEPAGE_MYCOURSES
) && $redirect === 1) {
80 redirect($CFG->wwwroot
.'/my/courses.php');
81 } else if (!empty($CFG->defaulthomepage
) && ($CFG->defaulthomepage
== HOMEPAGE_USER
)) {
82 $frontpagenode = $PAGE->settingsnav
->find('frontpage', null);
85 get_string('makethismyhome'),
86 new moodle_url('/', array('setdefaulthome' => true)),
87 navigation_node
::TYPE_SETTING
);
89 $frontpagenode = $PAGE->settingsnav
->add(get_string('frontpagesettings'), null, navigation_node
::TYPE_SETTING
, null);
90 $frontpagenode->force_open();
91 $frontpagenode->add(get_string('makethismyhome'),
92 new moodle_url('/', array('setdefaulthome' => true)),
93 navigation_node
::TYPE_SETTING
);
99 course_view(context_course
::instance(SITEID
));
101 $PAGE->set_pagetype('site-index');
102 $PAGE->set_docs_path('');
103 $editing = $PAGE->user_is_editing();
104 $PAGE->set_title($SITE->fullname
);
105 $PAGE->set_heading($SITE->fullname
);
106 if (has_capability('moodle/course:update', context_system
::instance())) {
107 $PAGE->set_secondary_navigation(true);
108 $PAGE->set_secondary_active_tab('coursehome');
110 $PAGE->set_secondary_navigation(false);
113 $courserenderer = $PAGE->get_renderer('core', 'course');
115 if ($hassiteconfig) {
116 $editurl = new moodle_url('/course/view.php', ['id' => SITEID
, 'sesskey' => sesskey()]);
117 $editbutton = $OUTPUT->edit_button($editurl);
118 $PAGE->set_button($editbutton);
121 echo $OUTPUT->header();
123 $siteformatoptions = course_get_format($SITE)->get_format_options();
124 $modinfo = get_fast_modinfo($SITE);
125 $modnamesused = $modinfo->get_used_module_names();
127 // Print Section or custom info.
128 if (!empty($CFG->customfrontpageinclude
)) {
129 // Pre-fill some variables that custom front page might use.
130 $modnames = get_module_types_names();
131 $modnamesplural = get_module_types_names(true);
132 $mods = $modinfo->get_cms();
134 include($CFG->customfrontpageinclude
);
136 } else if ($siteformatoptions['numsections'] > 0) {
137 echo $courserenderer->frontpage_section1();
139 // Include course AJAX.
140 include_course_ajax($SITE, $modnamesused);
142 echo $courserenderer->frontpage();
144 if ($editing && has_capability('moodle/course:create', context_system
::instance())) {
145 echo $courserenderer->add_new_course_button();
147 echo $OUTPUT->footer();