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
) && ($CFG->defaulthomepage
== HOMEPAGE_MY
) && optional_param('redirect', 1, PARAM_BOOL
) === 0) {
38 $urlparams['redirect'] = 0;
40 $PAGE->set_url('/', $urlparams);
41 $PAGE->set_pagelayout('frontpage');
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');
46 // Prevent caching of this page to stop confusion when changing page after making AJAX changes.
47 $PAGE->set_cacheable(false);
49 require_course_login($SITE);
51 $hasmaintenanceaccess = has_capability('moodle/site:maintenanceaccess', context_system
::instance());
53 // If the site is currently under maintenance, then print a message.
54 if (!empty($CFG->maintenance_enabled
) and !$hasmaintenanceaccess) {
55 print_maintenance_message();
58 $hassiteconfig = has_capability('moodle/site:config', context_system
::instance());
60 if ($hassiteconfig && moodle_needs_upgrading()) {
61 redirect($CFG->wwwroot
.'/'. $CFG->admin
.'/index.php');
64 if (get_home_page() != HOMEPAGE_SITE
) {
65 // Redirect logged-in users to My Moodle overview if required.
66 $redirect = optional_param('redirect', 1, PARAM_BOOL
);
67 if (optional_param('setdefaulthome', false, PARAM_BOOL
)) {
68 set_user_preference('user_home_page_preference', HOMEPAGE_SITE
);
69 } else if (!empty($CFG->defaulthomepage
) && ($CFG->defaulthomepage
== HOMEPAGE_MY
) && $redirect === 1) {
70 redirect($CFG->wwwroot
.'/my/');
71 } else if (!empty($CFG->defaulthomepage
) && ($CFG->defaulthomepage
== HOMEPAGE_USER
)) {
72 $frontpagenode = $PAGE->settingsnav
->find('frontpage', null);
75 get_string('makethismyhome'),
76 new moodle_url('/', array('setdefaulthome' => true)),
77 navigation_node
::TYPE_SETTING
);
79 $frontpagenode = $PAGE->settingsnav
->add(get_string('frontpagesettings'), null, navigation_node
::TYPE_SETTING
, null);
80 $frontpagenode->force_open();
81 $frontpagenode->add(get_string('makethismyhome'),
82 new moodle_url('/', array('setdefaulthome' => true)),
83 navigation_node
::TYPE_SETTING
);
89 course_view(context_course
::instance(SITEID
));
91 // If the hub plugin is installed then we let it take over the homepage here.
92 if (file_exists($CFG->dirroot
.'/local/hub/lib.php') and get_config('local_hub', 'hubenabled')) {
93 require_once($CFG->dirroot
.'/local/hub/lib.php');
94 $hub = new local_hub();
95 $continue = $hub->display_homepage();
96 // Function display_homepage() returns true if the hub home page is not displayed
97 // ...mostly when search form is not displayed for not logged users.
98 if (empty($continue)) {
103 $PAGE->set_pagetype('site-index');
104 $PAGE->set_docs_path('');
105 $editing = $PAGE->user_is_editing();
106 $PAGE->set_title($SITE->fullname
);
107 $PAGE->set_heading($SITE->fullname
);
108 $courserenderer = $PAGE->get_renderer('core', 'course');
109 echo $OUTPUT->header();
111 // Print Section or custom info.
112 $siteformatoptions = course_get_format($SITE)->get_format_options();
113 $modinfo = get_fast_modinfo($SITE);
114 $modnames = get_module_types_names();
115 $modnamesplural = get_module_types_names(true);
116 $modnamesused = $modinfo->get_used_module_names();
117 $mods = $modinfo->get_cms();
119 if (!empty($CFG->customfrontpageinclude
)) {
120 include($CFG->customfrontpageinclude
);
122 } else if ($siteformatoptions['numsections'] > 0) {
124 // Make sure section with number 1 exists.
125 course_create_sections_if_missing($SITE, 1);
126 // Re-request modinfo in case section was created.
127 $modinfo = get_fast_modinfo($SITE);
129 $section = $modinfo->get_section_info(1);
130 if (($section && (!empty($modinfo->sections
[1]) or !empty($section->summary
))) or $editing) {
131 echo $OUTPUT->box_start('generalbox sitetopic');
133 // If currently moving a file then show the current clipboard.
134 if (ismoving($SITE->id
)) {
135 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname
));
136 echo '<p><font size="2">';
137 echo "$stractivityclipboard (<a href=\"course/mod.php?cancelcopy=true&sesskey=".sesskey()."\">";
138 echo get_string('cancel') . '</a>)';
142 $context = context_course
::instance(SITEID
);
144 // If the section name is set we show it.
145 if (trim($section->name
) !== '') {
146 echo $OUTPUT->heading(
147 format_string($section->name
, true, array('context' => $context)),
153 $summarytext = file_rewrite_pluginfile_urls($section->summary
,
159 $summaryformatoptions = new stdClass();
160 $summaryformatoptions->noclean
= true;
161 $summaryformatoptions->overflowdiv
= true;
163 echo format_text($summarytext, $section->summaryformat
, $summaryformatoptions);
165 if ($editing && has_capability('moodle/course:update', $context)) {
166 $streditsummary = get_string('editsummary');
167 echo "<a title=\"$streditsummary\" " .
168 " href=\"course/editsection.php?id=$section->id\">" . $OUTPUT->pix_icon('t/edit', $streditsummary) .
172 $courserenderer = $PAGE->get_renderer('core', 'course');
173 echo $courserenderer->course_section_cm_list($SITE, $section);
175 echo $courserenderer->course_section_add_cm_control($SITE, $section->section
);
176 echo $OUTPUT->box_end();
179 // Include course AJAX.
180 include_course_ajax($SITE, $modnamesused);
182 if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin
)) {
183 $frontpagelayout = $CFG->frontpageloggedin
;
185 $frontpagelayout = $CFG->frontpage
;
188 foreach (explode(',', $frontpagelayout) as $v) {
190 // Display the main part of the front page.
192 if ($SITE->newsitems
) {
193 // Print forums only when needed.
194 require_once($CFG->dirroot
.'/mod/forum/lib.php');
196 if (! $newsforum = forum_get_course_forum($SITE->id
, 'news')) {
197 print_error('cannotfindorcreateforum', 'forum');
200 // Fetch news forum context for proper filtering to happen.
201 $newsforumcm = get_coursemodule_from_instance('forum', $newsforum->id
, $SITE->id
, false, MUST_EXIST
);
202 $newsforumcontext = context_module
::instance($newsforumcm->id
, MUST_EXIST
);
204 $forumname = format_string($newsforum->name
, true, array('context' => $newsforumcontext));
205 echo html_writer
::link('#skipsitenews',
206 get_string('skipa', 'access', core_text
::strtolower(strip_tags($forumname))),
207 array('class' => 'skip-block skip'));
209 // Wraps site news forum in div container.
210 echo html_writer
::start_tag('div', array('id' => 'site-news-forum'));
213 $SESSION->fromdiscussion
= $CFG->wwwroot
;
215 if (\mod_forum\subscriptions
::is_subscribed($USER->id
, $newsforum)) {
216 if (!\mod_forum\subscriptions
::is_forcesubscribed($newsforum)) {
217 $subtext = get_string('unsubscribe', 'forum');
220 $subtext = get_string('subscribe', 'forum');
222 echo $OUTPUT->heading($forumname);
223 $suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $newsforum->id
, 'sesskey' => sesskey()));
224 echo html_writer
::tag('div', html_writer
::link($suburl, $subtext), array('class' => 'subscribelink'));
226 echo $OUTPUT->heading($forumname);
229 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems
, 'plain', 'p.modified DESC');
231 // End site news forum div container.
232 echo html_writer
::end_tag('div');
234 echo html_writer
::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipsitenews'));
238 case FRONTPAGEENROLLEDCOURSELIST
:
239 $mycourseshtml = $courserenderer->frontpage_my_courses();
240 if (!empty($mycourseshtml)) {
241 echo html_writer
::link('#skipmycourses',
242 get_string('skipa', 'access', core_text
::strtolower(get_string('mycourses'))),
243 array('class' => 'skip skip-block'));
245 // Wrap frontpage course list in div container.
246 echo html_writer
::start_tag('div', array('id' => 'frontpage-course-list'));
248 echo $OUTPUT->heading(get_string('mycourses'));
251 // End frontpage course list div container.
252 echo html_writer
::end_tag('div');
254 echo html_writer
::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipmycourses'));
257 // No "break" here. If there are no enrolled courses - continue to 'Available courses'.
259 case FRONTPAGEALLCOURSELIST
:
260 $availablecourseshtml = $courserenderer->frontpage_available_courses();
261 if (!empty($availablecourseshtml)) {
262 echo html_writer
::link('#skipavailablecourses',
263 get_string('skipa', 'access', core_text
::strtolower(get_string('availablecourses'))),
264 array('class' => 'skip skip-block'));
266 // Wrap frontpage course list in div container.
267 echo html_writer
::start_tag('div', array('id' => 'frontpage-course-list'));
269 echo $OUTPUT->heading(get_string('availablecourses'));
270 echo $availablecourseshtml;
272 // End frontpage course list div container.
273 echo html_writer
::end_tag('div');
275 echo html_writer
::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipavailablecourses'));
279 case FRONTPAGECATEGORYNAMES
:
280 echo html_writer
::link('#skipcategories',
281 get_string('skipa', 'access', core_text
::strtolower(get_string('categories'))),
282 array('class' => 'skip skip-block'));
284 // Wrap frontpage category names in div container.
285 echo html_writer
::start_tag('div', array('id' => 'frontpage-category-names'));
287 echo $OUTPUT->heading(get_string('categories'));
288 echo $courserenderer->frontpage_categories_list();
290 // End frontpage category names div container.
291 echo html_writer
::end_tag('div');
293 echo html_writer
::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipcategories'));
296 case FRONTPAGECATEGORYCOMBO
:
297 echo html_writer
::link('#skipcourses',
298 get_string('skipa', 'access', core_text
::strtolower(get_string('courses'))),
299 array('class' => 'skip skip-block'));
301 // Wrap frontpage category combo in div container.
302 echo html_writer
::start_tag('div', array('id' => 'frontpage-category-combo'));
304 echo $OUTPUT->heading(get_string('courses'));
305 echo $courserenderer->frontpage_combo_list();
307 // End frontpage category combo div container.
308 echo html_writer
::end_tag('div');
310 echo html_writer
::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipcourses'));
313 case FRONTPAGECOURSESEARCH
:
314 echo $OUTPUT->box($courserenderer->course_search_form('', 'short'), 'mdl-align');
320 if ($editing && has_capability('moodle/course:create', context_system
::instance())) {
321 echo $courserenderer->add_new_course_button();
323 echo $OUTPUT->footer();