MDL-31822 course: Formatting the section name
[moodle.git] / index.php
CommitLineData
474f6bfe 1<?php
0cfb6a52 2
af9f5430
PS
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 * Moodle frontpage.
20 *
21 * @package core
22 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
0cfb6a52 25
8b5b1028 26 if (!file_exists('./config.php')) {
27 header('Location: install.php');
28 die;
29 }
30
d41746c9 31 require_once('config.php');
32 require_once($CFG->dirroot .'/course/lib.php');
644d506a 33 require_once($CFG->libdir .'/filelib.php');
364fffda 34
5e39d7aa 35 redirect_if_major_upgrade_required();
89d1efe4 36
98054db1 37 $urlparams = array();
ab6ec58a 38 if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && optional_param('redirect', 1, PARAM_BOOL) === 0) {
98054db1
PS
39 $urlparams['redirect'] = 0;
40 }
41 $PAGE->set_url('/', $urlparams);
42 $PAGE->set_course($SITE);
56b4d028
MG
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');
98054db1 46
fbb4c959
SH
47 // Prevent caching of this page to stop confusion when changing page after making AJAX changes
48 $PAGE->set_cacheable(false);
49
0a45ffe3 50 if ($CFG->forcelogin) {
51 require_login();
341b5ed2 52 } else {
53 user_accesstime_log();
0a45ffe3 54 }
55
bf0f06b1 56 $hassiteconfig = has_capability('moodle/site:config', context_system::instance());
32b9e80b 57
4fe2250a 58/// If the site is currently under maintenance, then print a message
32b9e80b 59 if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) {
4fe2250a 60 print_maintenance_message();
61 }
62
32b9e80b
SH
63 if ($hassiteconfig && moodle_needs_upgrading()) {
64 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
65 }
66
67 if (get_home_page() != HOMEPAGE_SITE) {
4766a50c
SH
68 // Redirect logged-in users to My Moodle overview if required
69 if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
70 set_user_preference('user_home_page_preference', HOMEPAGE_SITE);
ab6ec58a 71 } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && optional_param('redirect', 1, PARAM_BOOL) === 1) {
4766a50c 72 redirect($CFG->wwwroot .'/my/');
ab6ec58a 73 } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_USER)) {
4766a50c 74 $PAGE->settingsnav->get('usercurrentsettings')->add(get_string('makethismyhome'), new moodle_url('/', array('setdefaulthome'=>true)), navigation_node::TYPE_SETTING);
18818abf 75 }
3565715c 76 }
77
f49151c3
PS
78 $eventparams = array('context' => context_course::instance(SITEID));
79 $event = \core\event\course_viewed::create($eventparams);
80 $event->trigger();
a5e3644b 81
825b6fdb 82/// If the hub plugin is installed then we let it take over the homepage here
13f18ae1 83 if (file_exists($CFG->dirroot.'/local/hub/lib.php') and get_config('local_hub', 'hubenabled')) {
abf63f98 84 require_once($CFG->dirroot.'/local/hub/lib.php');
85 $hub = new local_hub();
a4e56bf3 86 $continue = $hub->display_homepage();
87 //display_homepage() return true if the hub home page is not displayed
88 //mostly when search form is not displayed for not logged users
89 if (empty($continue)) {
90 exit;
91 }
abf63f98 92 }
93
f8065dd2 94 $PAGE->set_pagetype('site-index');
82611d8d 95 $PAGE->set_docs_path('');
191b267b 96 $PAGE->set_pagelayout('frontpage');
ad52c04f 97 $editing = $PAGE->user_is_editing();
d4a03c00 98 $PAGE->set_title($SITE->fullname);
99 $PAGE->set_heading($SITE->fullname);
f4b571ab 100 $courserenderer = $PAGE->get_renderer('core', 'course');
244a32c6 101 echo $OUTPUT->header();
8c336db1 102
8275eab8 103/// Print Section or custom info
850acb35 104 $siteformatoptions = course_get_format($SITE)->get_format_options();
d57aa283
MG
105 $modinfo = get_fast_modinfo($SITE);
106 $modnames = get_module_types_names();
107 $modnamesplural = get_module_types_names(true);
108 $modnamesused = $modinfo->get_used_module_names();
109 $mods = $modinfo->get_cms();
110
8275eab8
PS
111 if (!empty($CFG->customfrontpageinclude)) {
112 include($CFG->customfrontpageinclude);
113
850acb35 114 } else if ($siteformatoptions['numsections'] > 0) {
d57aa283 115 if ($editing) {
4ede27b2
MG
116 // make sure section with number 1 exists
117 course_create_sections_if_missing($SITE, 1);
d57aa283
MG
118 // re-request modinfo in case section was created
119 $modinfo = get_fast_modinfo($SITE);
45a6b40d 120 }
d57aa283
MG
121 $section = $modinfo->get_section_info(1);
122 if (($section && (!empty($modinfo->sections[1]) or !empty($section->summary))) or $editing) {
20486a5a 123 echo $OUTPUT->box_start('generalbox sitetopic');
5fc2f2fd 124
a2b82263 125 /// If currently moving a file then show the current clipboard
126 if (ismoving($SITE->id)) {
294ce987 127 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
a2b82263 128 echo '<p><font size="2">';
973d2660 129 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=".sesskey()."\">". get_string('cancel') .'</a>)';
a2b82263 130 echo '</font></p>';
131 }
5fc2f2fd 132
fecca79d
DM
133 $context = context_course::instance(SITEID);
134
135 // If the section name is set we show it.
a7aae18c 136 if (!is_null($section->name)) {
fecca79d
DM
137 echo $OUTPUT->heading(
138 format_string($section->name, true, array('context' => $context)),
139 2,
140 'sectionname'
141 );
a7aae18c
DB
142 }
143
64f93798 144 $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course', 'section', $section->id);
a226a972 145 $summaryformatoptions = new stdClass();
644d506a 146 $summaryformatoptions->noclean = true;
367a75fa 147 $summaryformatoptions->overflowdiv = true;
644d506a 148
e34a326f 149 echo format_text($summarytext, $section->summaryformat, $summaryformatoptions);
5fc2f2fd 150
56b4d028 151 if ($editing && has_capability('moodle/course:update', $context)) {
a2b82263 152 $streditsummary = get_string('editsummary');
153 echo "<a title=\"$streditsummary\" ".
b5d0cafc 154 " href=\"course/editsection.php?id=$section->id\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" ".
0d905d9f 155 " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
a2b82263 156 }
157
54258889 158 $courserenderer = $PAGE->get_renderer('core', 'course');
9a36be73 159 echo $courserenderer->course_section_cm_list($SITE, $section);
364fffda 160
9a6aa5c1 161 echo $courserenderer->course_section_add_cm_control($SITE, $section->section);
20486a5a 162 echo $OUTPUT->box_end();
5fc2f2fd 163 }
5fc2f2fd 164 }
01e0e704 165 // Include course AJAX
697ff999 166 include_course_ajax($SITE, $modnamesused);
5fc2f2fd 167
64f93798 168 if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
6f24e48e 169 $frontpagelayout = $CFG->frontpageloggedin;
170 } else {
171 $frontpagelayout = $CFG->frontpage;
172 }
173
64f93798 174 foreach (explode(',',$frontpagelayout) as $v) {
e1638d61 175 switch ($v) { /// Display the main part of the front page.
220a90c5 176 case FRONTPAGENEWS:
e1638d61 177 if ($SITE->newsitems) { // Print forums only when needed
178 require_once($CFG->dirroot .'/mod/forum/lib.php');
179
180 if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
33aa5723 181 print_error('cannotfindorcreateforum', 'forum');
e1638d61 182 }
c3b825e1
EL
183
184 // fetch news forum context for proper filtering to happen
185 $newsforumcm = get_coursemodule_from_instance('forum', $newsforum->id, $SITE->id, false, MUST_EXIST);
bf0f06b1 186 $newsforumcontext = context_module::instance($newsforumcm->id, MUST_EXIST);
c3b825e1
EL
187
188 $forumname = format_string($newsforum->name, true, array('context' => $newsforumcontext));
2f1e464a 189 echo html_writer::tag('a', get_string('skipa', 'access', core_text::strtolower(strip_tags($forumname))), array('href'=>'#skipsitenews', 'class'=>'skip-block'));
e1638d61 190
4c71a80a
ME
191 // wraps site news forum in div container.
192 echo html_writer::start_tag('div', array('id'=>'site-news-forum'));
193
4f0c2d00 194 if (isloggedin()) {
e1638d61 195 $SESSION->fromdiscussion = $CFG->wwwroot;
6e5e0c93 196 $subtext = '';
59075a43
AN
197 if (\mod_forum\subscriptions::is_subscribed($USER->id, $newsforum)) {
198 if (!\mod_forum\subscriptions::is_forcesubscribed($newsforum)) {
730535cb 199 $subtext = get_string('unsubscribe', 'forum');
200 }
e1638d61 201 } else {
202 $subtext = get_string('subscribe', 'forum');
203 }
faf6010b 204 echo $OUTPUT->heading($forumname);
6f7d65c7
DM
205 $suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $newsforum->id, 'sesskey' => sesskey()));
206 echo html_writer::tag('div', html_writer::link($suburl, $subtext), array('class' => 'subscribelink'));
af328e4b 207 } else {
faf6010b 208 echo $OUTPUT->heading($forumname);
af328e4b 209 }
e1638d61 210
a5a9cd99 211 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
4c71a80a
ME
212
213 //end site news forum div container
214 echo html_writer::end_tag('div');
215
fd2aa40b 216 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipsitenews'));
89adb174 217 }
e1638d61 218 break;
89adb174 219
0fd26350
MG
220 case FRONTPAGEENROLLEDCOURSELIST:
221 $mycourseshtml = $courserenderer->frontpage_my_courses();
222 if (!empty($mycourseshtml)) {
2f1e464a 223 echo html_writer::tag('a', get_string('skipa', 'access', core_text::strtolower(get_string('mycourses'))), array('href'=>'#skipmycourses', 'class'=>'skip-block'));
4c71a80a
ME
224
225 //wrap frontpage course list in div container
226 echo html_writer::start_tag('div', array('id'=>'frontpage-course-list'));
227
faf6010b 228 echo $OUTPUT->heading(get_string('mycourses'));
99a36456 229 echo $mycourseshtml;
4c71a80a
ME
230
231 //end frontpage course list div container
232 echo html_writer::end_tag('div');
233
fd2aa40b 234 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipmycourses'));
0fd26350
MG
235 break;
236 }
237 // No "break" here. If there are no enrolled courses - continue to 'Available courses'.
238
239 case FRONTPAGEALLCOURSELIST:
240 $availablecourseshtml = $courserenderer->frontpage_available_courses();
241 if (!empty($availablecourseshtml)) {
2f1e464a 242 echo html_writer::tag('a', get_string('skipa', 'access', core_text::strtolower(get_string('availablecourses'))), array('href'=>'#skipavailablecourses', 'class'=>'skip-block'));
4c71a80a
ME
243
244 //wrap frontpage course list in div container
245 echo html_writer::start_tag('div', array('id'=>'frontpage-course-list'));
246
faf6010b 247 echo $OUTPUT->heading(get_string('availablecourses'));
0fd26350 248 echo $availablecourseshtml;
4c71a80a
ME
249
250 //end frontpage course list div container
251 echo html_writer::end_tag('div');
252
fd2aa40b 253 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipavailablecourses'));
64f93798 254 }
e1638d61 255 break;
89adb174 256
e0140f24 257 case FRONTPAGECATEGORYNAMES:
2f1e464a 258 echo html_writer::tag('a', get_string('skipa', 'access', core_text::strtolower(get_string('categories'))), array('href'=>'#skipcategories', 'class'=>'skip-block'));
4c71a80a
ME
259
260 //wrap frontpage category names in div container
261 echo html_writer::start_tag('div', array('id'=>'frontpage-category-names'));
262
faf6010b 263 echo $OUTPUT->heading(get_string('categories'));
99a36456 264 echo $courserenderer->frontpage_categories_list();
4c71a80a
ME
265
266 //end frontpage category names div container
267 echo html_writer::end_tag('div');
268
fd2aa40b 269 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipcategories'));
e0140f24 270 break;
271
6f24e48e 272 case FRONTPAGECATEGORYCOMBO:
2f1e464a 273 echo html_writer::tag('a', get_string('skipa', 'access', core_text::strtolower(get_string('courses'))), array('href'=>'#skipcourses', 'class'=>'skip-block'));
4c71a80a
ME
274
275 //wrap frontpage category combo in div container
276 echo html_writer::start_tag('div', array('id'=>'frontpage-category-combo'));
277
faf6010b 278 echo $OUTPUT->heading(get_string('courses'));
0fd26350 279 echo $courserenderer->frontpage_combo_list();
4c71a80a
ME
280
281 //end frontpage category combo div container
282 echo html_writer::end_tag('div');
283
fd2aa40b 284 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipcourses'));
6f24e48e 285 break;
286
0fd26350
MG
287 case FRONTPAGECOURSESEARCH:
288 echo $OUTPUT->box($courserenderer->course_search_form('', 'short'), 'mdl-align');
e1638d61 289 break;
5eafd948 290
e1638d61 291 }
292 echo '<br />';
89adb174 293 }
ee11f4a7
JF
294 if ($editing && has_capability('moodle/course:create', context_system::instance())) {
295 echo $courserenderer->add_new_course_button();
296 }
d4a03c00 297 echo $OUTPUT->footer();