MDL-45774 navigation: Version bump and upgrade.php edit.
[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);
41$PAGE->set_course($SITE);
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
49if ($CFG->forcelogin) {
50 require_login();
51} else {
52 user_accesstime_log();
53}
54
55$hassiteconfig = has_capability('moodle/site:config', context_system::instance());
56
57// If the site is currently under maintenance, then print a message.
58if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) {
59 print_maintenance_message();
60}
61
62if ($hassiteconfig && moodle_needs_upgrading()) {
63 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
64}
65
66if (get_home_page() != HOMEPAGE_SITE) {
67 // Redirect logged-in users to My Moodle overview if required.
68 $redirect = optional_param('redirect', 1, PARAM_BOOL);
69 if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
70 set_user_preference('user_home_page_preference', HOMEPAGE_SITE);
71 } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && $redirect === 1) {
72 redirect($CFG->wwwroot .'/my/');
73 } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_USER)) {
f495187d 74 $PAGE->settingsnav->find('usercurrentsettings', null)->add(
c9edde8b
DB
75 get_string('makethismyhome'),
76 new moodle_url('/', array('setdefaulthome' => true)),
77 navigation_node::TYPE_SETTING);
98054db1 78 }
c9edde8b
DB
79}
80
22588835
JL
81// Trigger event.
82course_view(context_course::instance(SITEID));
c9edde8b
DB
83
84// If the hub plugin is installed then we let it take over the homepage here.
85if (file_exists($CFG->dirroot.'/local/hub/lib.php') and get_config('local_hub', 'hubenabled')) {
86 require_once($CFG->dirroot.'/local/hub/lib.php');
87 $hub = new local_hub();
88 $continue = $hub->display_homepage();
89 // Function display_homepage() returns true if the hub home page is not displayed
90 // ...mostly when search form is not displayed for not logged users.
91 if (empty($continue)) {
92 exit;
0a45ffe3 93 }
c9edde8b
DB
94}
95
96$PAGE->set_pagetype('site-index');
97$PAGE->set_docs_path('');
98$PAGE->set_pagelayout('frontpage');
99$editing = $PAGE->user_is_editing();
100$PAGE->set_title($SITE->fullname);
101$PAGE->set_heading($SITE->fullname);
102$courserenderer = $PAGE->get_renderer('core', 'course');
103echo $OUTPUT->header();
104
105// Print Section or custom info.
106$siteformatoptions = course_get_format($SITE)->get_format_options();
107$modinfo = get_fast_modinfo($SITE);
108$modnames = get_module_types_names();
109$modnamesplural = get_module_types_names(true);
110$modnamesused = $modinfo->get_used_module_names();
111$mods = $modinfo->get_cms();
112
113if (!empty($CFG->customfrontpageinclude)) {
114 include($CFG->customfrontpageinclude);
115
116} else if ($siteformatoptions['numsections'] > 0) {
117 if ($editing) {
118 // Make sure section with number 1 exists.
119 course_create_sections_if_missing($SITE, 1);
120 // Re-request modinfo in case section was created.
121 $modinfo = get_fast_modinfo($SITE);
4fe2250a 122 }
c9edde8b
DB
123 $section = $modinfo->get_section_info(1);
124 if (($section && (!empty($modinfo->sections[1]) or !empty($section->summary))) or $editing) {
125 echo $OUTPUT->box_start('generalbox sitetopic');
126
127 // If currently moving a file then show the current clipboard.
128 if (ismoving($SITE->id)) {
129 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
130 echo '<p><font size="2">';
131 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=".sesskey()."\">";
132 echo get_string('cancel') . '</a>)';
133 echo '</font></p>';
18818abf 134 }
3565715c 135
c9edde8b 136 $context = context_course::instance(SITEID);
abf63f98 137
c9edde8b
DB
138 // If the section name is set we show it.
139 if (!is_null($section->name)) {
140 echo $OUTPUT->heading(
141 format_string($section->name, true, array('context' => $context)),
142 2,
143 'sectionname'
144 );
45a6b40d 145 }
fecca79d 146
c9edde8b
DB
147 $summarytext = file_rewrite_pluginfile_urls($section->summary,
148 'pluginfile.php',
149 $context->id,
150 'course',
151 'section',
152 $section->id);
153 $summaryformatoptions = new stdClass();
154 $summaryformatoptions->noclean = true;
155 $summaryformatoptions->overflowdiv = true;
156
157 echo format_text($summarytext, $section->summaryformat, $summaryformatoptions);
158
159 if ($editing && has_capability('moodle/course:update', $context)) {
160 $streditsummary = get_string('editsummary');
161 echo "<a title=\"$streditsummary\" ".
162 " href=\"course/editsection.php?id=$section->id\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" ".
163 " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
164 }
a2b82263 165
c9edde8b
DB
166 $courserenderer = $PAGE->get_renderer('core', 'course');
167 echo $courserenderer->course_section_cm_list($SITE, $section);
364fffda 168
c9edde8b
DB
169 echo $courserenderer->course_section_add_cm_control($SITE, $section->section);
170 echo $OUTPUT->box_end();
5fc2f2fd 171 }
c9edde8b
DB
172}
173// Include course AJAX.
174include_course_ajax($SITE, $modnamesused);
175
176if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
177 $frontpagelayout = $CFG->frontpageloggedin;
178} else {
179 $frontpagelayout = $CFG->frontpage;
180}
181
182foreach (explode(',', $frontpagelayout) as $v) {
183 switch ($v) {
184 // Display the main part of the front page.
185 case FRONTPAGENEWS:
186 if ($SITE->newsitems) {
187 // Print forums only when needed.
188 require_once($CFG->dirroot .'/mod/forum/lib.php');
189
190 if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
191 print_error('cannotfindorcreateforum', 'forum');
192 }
5fc2f2fd 193
c9edde8b
DB
194 // Fetch news forum context for proper filtering to happen.
195 $newsforumcm = get_coursemodule_from_instance('forum', $newsforum->id, $SITE->id, false, MUST_EXIST);
196 $newsforumcontext = context_module::instance($newsforumcm->id, MUST_EXIST);
6f24e48e 197
c9edde8b
DB
198 $forumname = format_string($newsforum->name, true, array('context' => $newsforumcontext));
199 echo html_writer::tag('a',
200 get_string('skipa', 'access', core_text::strtolower(strip_tags($forumname))),
201 array('href' => '#skipsitenews', 'class' => 'skip-block'));
e1638d61 202
c9edde8b
DB
203 // Wraps site news forum in div container.
204 echo html_writer::start_tag('div', array('id' => 'site-news-forum'));
c3b825e1 205
c9edde8b
DB
206 if (isloggedin()) {
207 $SESSION->fromdiscussion = $CFG->wwwroot;
208 $subtext = '';
209 if (\mod_forum\subscriptions::is_subscribed($USER->id, $newsforum)) {
210 if (!\mod_forum\subscriptions::is_forcesubscribed($newsforum)) {
211 $subtext = get_string('unsubscribe', 'forum');
e1638d61 212 }
af328e4b 213 } else {
c9edde8b 214 $subtext = get_string('subscribe', 'forum');
af328e4b 215 }
c9edde8b
DB
216 echo $OUTPUT->heading($forumname);
217 $suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $newsforum->id, 'sesskey' => sesskey()));
218 echo html_writer::tag('div', html_writer::link($suburl, $subtext), array('class' => 'subscribelink'));
219 } else {
220 echo $OUTPUT->heading($forumname);
221 }
e1638d61 222
c9edde8b 223 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
4c71a80a 224
c9edde8b
DB
225 // End site news forum div container.
226 echo html_writer::end_tag('div');
4c71a80a 227
c9edde8b
DB
228 echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipsitenews'));
229 }
230 break;
89adb174 231
c9edde8b
DB
232 case FRONTPAGEENROLLEDCOURSELIST:
233 $mycourseshtml = $courserenderer->frontpage_my_courses();
234 if (!empty($mycourseshtml)) {
235 echo html_writer::tag('a',
236 get_string('skipa', 'access', core_text::strtolower(get_string('mycourses'))),
237 array('href' => '#skipmycourses', 'class' => 'skip-block'));
4c71a80a 238
c9edde8b
DB
239 // Wrap frontpage course list in div container.
240 echo html_writer::start_tag('div', array('id' => 'frontpage-course-list'));
4c71a80a 241
c9edde8b
DB
242 echo $OUTPUT->heading(get_string('mycourses'));
243 echo $mycourseshtml;
4c71a80a 244
c9edde8b
DB
245 // End frontpage course list div container.
246 echo html_writer::end_tag('div');
4c71a80a 247
c9edde8b
DB
248 echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipmycourses'));
249 break;
250 }
251 // No "break" here. If there are no enrolled courses - continue to 'Available courses'.
0fd26350 252
c9edde8b
DB
253 case FRONTPAGEALLCOURSELIST:
254 $availablecourseshtml = $courserenderer->frontpage_available_courses();
255 if (!empty($availablecourseshtml)) {
256 echo html_writer::tag('a',
257 get_string('skipa', 'access', core_text::strtolower(get_string('availablecourses'))),
258 array('href' => '#skipavailablecourses', 'class' => 'skip-block'));
4c71a80a 259
c9edde8b
DB
260 // Wrap frontpage course list in div container.
261 echo html_writer::start_tag('div', array('id' => 'frontpage-course-list'));
4c71a80a 262
c9edde8b
DB
263 echo $OUTPUT->heading(get_string('availablecourses'));
264 echo $availablecourseshtml;
4c71a80a 265
c9edde8b
DB
266 // End frontpage course list div container.
267 echo html_writer::end_tag('div');
4c71a80a 268
c9edde8b
DB
269 echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipavailablecourses'));
270 }
271 break;
89adb174 272
c9edde8b
DB
273 case FRONTPAGECATEGORYNAMES:
274 echo html_writer::tag('a',
275 get_string('skipa', 'access', core_text::strtolower(get_string('categories'))),
276 array('href' => '#skipcategories', 'class' => 'skip-block'));
4c71a80a 277
c9edde8b
DB
278 // Wrap frontpage category names in div container.
279 echo html_writer::start_tag('div', array('id' => 'frontpage-category-names'));
4c71a80a 280
c9edde8b
DB
281 echo $OUTPUT->heading(get_string('categories'));
282 echo $courserenderer->frontpage_categories_list();
4c71a80a 283
c9edde8b
DB
284 // End frontpage category names div container.
285 echo html_writer::end_tag('div');
4c71a80a 286
c9edde8b
DB
287 echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipcategories'));
288 break;
e0140f24 289
c9edde8b
DB
290 case FRONTPAGECATEGORYCOMBO:
291 echo html_writer::tag('a',
292 get_string('skipa', 'access', core_text::strtolower(get_string('courses'))),
293 array('href' => '#skipcourses', 'class' => 'skip-block'));
4c71a80a 294
c9edde8b
DB
295 // Wrap frontpage category combo in div container.
296 echo html_writer::start_tag('div', array('id' => 'frontpage-category-combo'));
4c71a80a 297
c9edde8b
DB
298 echo $OUTPUT->heading(get_string('courses'));
299 echo $courserenderer->frontpage_combo_list();
4c71a80a 300
c9edde8b
DB
301 // End frontpage category combo div container.
302 echo html_writer::end_tag('div');
4c71a80a 303
c9edde8b
DB
304 echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipcourses'));
305 break;
6f24e48e 306
c9edde8b
DB
307 case FRONTPAGECOURSESEARCH:
308 echo $OUTPUT->box($courserenderer->course_search_form('', 'short'), 'mdl-align');
309 break;
5eafd948 310
ee11f4a7 311 }
c9edde8b
DB
312 echo '<br />';
313}
314if ($editing && has_capability('moodle/course:create', context_system::instance())) {
315 echo $courserenderer->add_new_course_button();
316}
317echo $OUTPUT->footer();