MDL-60359 theme_boost: have correct mc question check mark not overlap
[moodle.git] / index.php
blobe95b0bb0d13e47a7bfdd12ca897377fcc659ad0e
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.
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/>.
17 /**
18 * Moodle frontpage.
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
25 if (!file_exists('./config.php')) {
26 header('Location: install.php');
27 die;
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();
36 $urlparams = array();
37 if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && optional_param('redirect', 1, PARAM_BOOL) === 0) {
38 $urlparams['redirect'] = 0;
40 $PAGE->set_url('/', $urlparams);
41 $PAGE->set_course($SITE);
42 $PAGE->set_pagelayout('frontpage');
43 $PAGE->set_other_editing_capability('moodle/course:update');
44 $PAGE->set_other_editing_capability('moodle/course:manageactivities');
45 $PAGE->set_other_editing_capability('moodle/course:activityvisibility');
47 // Prevent caching of this page to stop confusion when changing page after making AJAX changes.
48 $PAGE->set_cacheable(false);
50 if ($CFG->forcelogin) {
51 require_login();
52 } else {
53 user_accesstime_log();
56 $hasmaintenanceaccess = has_capability('moodle/site:maintenanceaccess', context_system::instance());
58 // If the site is currently under maintenance, then print a message.
59 if (!empty($CFG->maintenance_enabled) and !$hasmaintenanceaccess) {
60 print_maintenance_message();
63 $hassiteconfig = has_capability('moodle/site:config', context_system::instance());
65 if ($hassiteconfig && moodle_needs_upgrading()) {
66 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
69 // If site registration needs updating, redirect.
70 \core\hub\registration::registration_reminder('/index.php');
72 if (get_home_page() != HOMEPAGE_SITE) {
73 // Redirect logged-in users to My Moodle overview if required.
74 $redirect = optional_param('redirect', 1, PARAM_BOOL);
75 if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
76 set_user_preference('user_home_page_preference', HOMEPAGE_SITE);
77 } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && $redirect === 1) {
78 redirect($CFG->wwwroot .'/my/');
79 } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_USER)) {
80 $frontpagenode = $PAGE->settingsnav->find('frontpage', null);
81 if ($frontpagenode) {
82 $frontpagenode->add(
83 get_string('makethismyhome'),
84 new moodle_url('/', array('setdefaulthome' => true)),
85 navigation_node::TYPE_SETTING);
86 } else {
87 $frontpagenode = $PAGE->settingsnav->add(get_string('frontpagesettings'), null, navigation_node::TYPE_SETTING, null);
88 $frontpagenode->force_open();
89 $frontpagenode->add(get_string('makethismyhome'),
90 new moodle_url('/', array('setdefaulthome' => true)),
91 navigation_node::TYPE_SETTING);
96 // Trigger event.
97 course_view(context_course::instance(SITEID));
99 // If the hub plugin is installed then we let it take over the homepage here.
100 if (file_exists($CFG->dirroot.'/local/hub/lib.php') and get_config('local_hub', 'hubenabled')) {
101 require_once($CFG->dirroot.'/local/hub/lib.php');
102 $hub = new local_hub();
103 $continue = $hub->display_homepage();
104 // Function display_homepage() returns true if the hub home page is not displayed
105 // ...mostly when search form is not displayed for not logged users.
106 if (empty($continue)) {
107 exit;
111 $PAGE->set_pagetype('site-index');
112 $PAGE->set_docs_path('');
113 $editing = $PAGE->user_is_editing();
114 $PAGE->set_title($SITE->fullname);
115 $PAGE->set_heading($SITE->fullname);
116 $courserenderer = $PAGE->get_renderer('core', 'course');
117 echo $OUTPUT->header();
119 // Print Section or custom info.
120 $siteformatoptions = course_get_format($SITE)->get_format_options();
121 $modinfo = get_fast_modinfo($SITE);
122 $modnames = get_module_types_names();
123 $modnamesplural = get_module_types_names(true);
124 $modnamesused = $modinfo->get_used_module_names();
125 $mods = $modinfo->get_cms();
127 if (!empty($CFG->customfrontpageinclude)) {
128 include($CFG->customfrontpageinclude);
130 } else if ($siteformatoptions['numsections'] > 0) {
131 if ($editing) {
132 // Make sure section with number 1 exists.
133 course_create_sections_if_missing($SITE, 1);
134 // Re-request modinfo in case section was created.
135 $modinfo = get_fast_modinfo($SITE);
137 $section = $modinfo->get_section_info(1);
138 if (($section && (!empty($modinfo->sections[1]) or !empty($section->summary))) or $editing) {
139 echo $OUTPUT->box_start('generalbox sitetopic');
141 // If currently moving a file then show the current clipboard.
142 if (ismoving($SITE->id)) {
143 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
144 echo '<p><font size="2">';
145 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=".sesskey()."\">";
146 echo get_string('cancel') . '</a>)';
147 echo '</font></p>';
150 $context = context_course::instance(SITEID);
152 // If the section name is set we show it.
153 if (trim($section->name) !== '') {
154 echo $OUTPUT->heading(
155 format_string($section->name, true, array('context' => $context)),
157 'sectionname'
161 $summarytext = file_rewrite_pluginfile_urls($section->summary,
162 'pluginfile.php',
163 $context->id,
164 'course',
165 'section',
166 $section->id);
167 $summaryformatoptions = new stdClass();
168 $summaryformatoptions->noclean = true;
169 $summaryformatoptions->overflowdiv = true;
171 echo format_text($summarytext, $section->summaryformat, $summaryformatoptions);
173 if ($editing && has_capability('moodle/course:update', $context)) {
174 $streditsummary = get_string('editsummary');
175 echo "<a title=\"$streditsummary\" " .
176 " href=\"course/editsection.php?id=$section->id\">" . $OUTPUT->pix_icon('t/edit', $streditsummary) .
177 "</a><br /><br />";
180 $courserenderer = $PAGE->get_renderer('core', 'course');
181 echo $courserenderer->course_section_cm_list($SITE, $section);
183 echo $courserenderer->course_section_add_cm_control($SITE, $section->section);
184 echo $OUTPUT->box_end();
187 // Include course AJAX.
188 include_course_ajax($SITE, $modnamesused);
190 if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
191 $frontpagelayout = $CFG->frontpageloggedin;
192 } else {
193 $frontpagelayout = $CFG->frontpage;
196 foreach (explode(',', $frontpagelayout) as $v) {
197 switch ($v) {
198 // Display the main part of the front page.
199 case FRONTPAGENEWS:
200 if ($SITE->newsitems) {
201 // Print forums only when needed.
202 require_once($CFG->dirroot .'/mod/forum/lib.php');
204 if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
205 print_error('cannotfindorcreateforum', 'forum');
208 // Fetch news forum context for proper filtering to happen.
209 $newsforumcm = get_coursemodule_from_instance('forum', $newsforum->id, $SITE->id, false, MUST_EXIST);
210 $newsforumcontext = context_module::instance($newsforumcm->id, MUST_EXIST);
212 $forumname = format_string($newsforum->name, true, array('context' => $newsforumcontext));
213 echo html_writer::link('#skipsitenews',
214 get_string('skipa', 'access', core_text::strtolower(strip_tags($forumname))),
215 array('class' => 'skip-block skip'));
217 // Wraps site news forum in div container.
218 echo html_writer::start_tag('div', array('id' => 'site-news-forum'));
220 if (isloggedin()) {
221 $SESSION->fromdiscussion = $CFG->wwwroot;
222 $subtext = '';
223 if (\mod_forum\subscriptions::is_subscribed($USER->id, $newsforum)) {
224 if (!\mod_forum\subscriptions::is_forcesubscribed($newsforum)) {
225 $subtext = get_string('unsubscribe', 'forum');
227 } else {
228 $subtext = get_string('subscribe', 'forum');
230 echo $OUTPUT->heading($forumname);
231 $suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $newsforum->id, 'sesskey' => sesskey()));
232 echo html_writer::tag('div', html_writer::link($suburl, $subtext), array('class' => 'subscribelink'));
233 } else {
234 echo $OUTPUT->heading($forumname);
237 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
239 // End site news forum div container.
240 echo html_writer::end_tag('div');
242 echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipsitenews'));
244 break;
246 case FRONTPAGEENROLLEDCOURSELIST:
247 $mycourseshtml = $courserenderer->frontpage_my_courses();
248 if (!empty($mycourseshtml)) {
249 echo html_writer::link('#skipmycourses',
250 get_string('skipa', 'access', core_text::strtolower(get_string('mycourses'))),
251 array('class' => 'skip skip-block'));
253 // Wrap frontpage course list in div container.
254 echo html_writer::start_tag('div', array('id' => 'frontpage-course-list'));
256 echo $OUTPUT->heading(get_string('mycourses'));
257 echo $mycourseshtml;
259 // End frontpage course list div container.
260 echo html_writer::end_tag('div');
262 echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipmycourses'));
263 break;
265 // No "break" here. If there are no enrolled courses - continue to 'Available courses'.
267 case FRONTPAGEALLCOURSELIST:
268 $availablecourseshtml = $courserenderer->frontpage_available_courses();
269 if (!empty($availablecourseshtml)) {
270 echo html_writer::link('#skipavailablecourses',
271 get_string('skipa', 'access', core_text::strtolower(get_string('availablecourses'))),
272 array('class' => 'skip skip-block'));
274 // Wrap frontpage course list in div container.
275 echo html_writer::start_tag('div', array('id' => 'frontpage-course-list'));
277 echo $OUTPUT->heading(get_string('availablecourses'));
278 echo $availablecourseshtml;
280 // End frontpage course list div container.
281 echo html_writer::end_tag('div');
283 echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipavailablecourses'));
285 break;
287 case FRONTPAGECATEGORYNAMES:
288 echo html_writer::link('#skipcategories',
289 get_string('skipa', 'access', core_text::strtolower(get_string('categories'))),
290 array('class' => 'skip skip-block'));
292 // Wrap frontpage category names in div container.
293 echo html_writer::start_tag('div', array('id' => 'frontpage-category-names'));
295 echo $OUTPUT->heading(get_string('categories'));
296 echo $courserenderer->frontpage_categories_list();
298 // End frontpage category names div container.
299 echo html_writer::end_tag('div');
301 echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipcategories'));
302 break;
304 case FRONTPAGECATEGORYCOMBO:
305 echo html_writer::link('#skipcourses',
306 get_string('skipa', 'access', core_text::strtolower(get_string('courses'))),
307 array('class' => 'skip skip-block'));
309 // Wrap frontpage category combo in div container.
310 echo html_writer::start_tag('div', array('id' => 'frontpage-category-combo'));
312 echo $OUTPUT->heading(get_string('courses'));
313 echo $courserenderer->frontpage_combo_list();
315 // End frontpage category combo div container.
316 echo html_writer::end_tag('div');
318 echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipcourses'));
319 break;
321 case FRONTPAGECOURSESEARCH:
322 echo $OUTPUT->box($courserenderer->course_search_form('', 'short'), 'mdl-align');
323 break;
326 echo '<br />';
328 if ($editing && has_capability('moodle/course:create', context_system::instance())) {
329 echo $courserenderer->add_new_course_button();
331 echo $OUTPUT->footer();