<?php\n// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Moodle frontpage.\n *\n * @package core\n * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nif (!file_exists('./config.php')) {\n header('Location: install.php');\n die;\n}\n\nrequire_once('config.php');\nrequire_once($CFG->dirroot .'/course/lib.php');\nrequire_once($CFG->libdir .'/filelib.php');\n\nredirect_if_major_upgrade_required();\n\n$urlparams = array();\nif (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && optional_param('redirect', 1, PARAM_BOOL) === 0) {\n $urlparams['redirect'] = 0;\n}\n$PAGE->set_url('/', $urlparams);\n$PAGE->set_course($SITE);\n$PAGE->set_pagelayout('frontpage');\n$PAGE->set_other_editing_capability('moodle/course:update');\n$PAGE->set_other_editing_capability('moodle/course:manageactivities');\n$PAGE->set_other_editing_capability('moodle/course:activityvisibility');\n\n// Prevent caching of this page to stop confusion when changing page after making AJAX changes.\n$PAGE->set_cacheable(false);\n\nif ($CFG->forcelogin) {\n require_login();\n} else {\n user_accesstime_log();\n}\n\n$hasmaintenanceaccess = has_capability('moodle/site:maintenanceaccess', context_system::instance());\n\n// If the site is currently under maintenance, then print a message.\nif (!empty($CFG->maintenance_enabled) and !$hasmaintenanceaccess) {\n print_maintenance_message();\n}\n\n$hassiteconfig = has_capability('moodle/site:config', context_system::instance());\n\nif ($hassiteconfig && moodle_needs_upgrading()) {\n redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');\n}\n\n// If site registration needs updating, redirect.\n\core\hub\registration::registration_reminder('/index.php');\n\nif (get_home_page() != HOMEPAGE_SITE) {\n // Redirect logged-in users to My Moodle overview if required.\n $redirect = optional_param('redirect', 1, PARAM_BOOL);\n if (optional_param('setdefaulthome', false, PARAM_BOOL)) {\n set_user_preference('user_home_page_preference', HOMEPAGE_SITE);\n } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && $redirect === 1) {\n redirect($CFG->wwwroot .'/my/');\n } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_USER)) {\n $frontpagenode = $PAGE->settingsnav->find('frontpage', null);\n if ($frontpagenode) {\n $frontpagenode->add(\n get_string('makethismyhome'),\n new moodle_url('/', array('setdefaulthome' => true)),\n navigation_node::TYPE_SETTING);\n } else {\n $frontpagenode = $PAGE->settingsnav->add(get_string('frontpagesettings'), null, navigation_node::TYPE_SETTING, null);\n $frontpagenode->force_open();\n $frontpagenode->add(get_string('makethismyhome'),\n new moodle_url('/', array('setdefaulthome' => true)),\n navigation_node::TYPE_SETTING);\n }\n }\n}\n\n// Trigger event.\ncourse_view(context_course::instance(SITEID));\n\n// If the hub plugin is installed then we let it take over the homepage here.\nif (file_exists($CFG->dirroot.'/local/hub/lib.php') and get_config('local_hub', 'hubenabled')) {\n require_once($CFG->dirroot.'/local/hub/lib.php');\n $hub = new local_hub();\n $continue = $hub->display_homepage();\n // Function display_homepage() returns true if the hub home page is not displayed\n // ...mostly when search form is not displayed for not logged users.\n if (empty($continue)) {\n exit;\n }\n}\n\n$PAGE->set_pagetype('site-index');\n$PAGE->set_docs_path('');\n$editing = $PAGE->user_is_editing();\n$PAGE->set_title($SITE->fullname);\n$PAGE->set_heading($SITE->fullname);\n$courserenderer = $PAGE->get_renderer('core', 'course');\necho $OUTPUT->header();\n\n// Print Section or custom info.\n$siteformatoptions = course_get_format($SITE)->get_format_options();\n$modinfo = get_fast_modinfo($SITE);\n$modnames = get_module_types_names();\n$modnamesplural = get_module_types_names(true);\n$modnamesused = $modinfo->get_used_module_names();\n$mods = $modinfo->get_cms();\n\nif (!empty($CFG->customfrontpageinclude)) {\n include($CFG->customfrontpageinclude);\n\n} else if ($siteformatoptions['numsections'] > 0) {\n if ($editing) {\n // Make sure section with number 1 exists.\n course_create_sections_if_missing($SITE, 1);\n // Re-request modinfo in case section was created.\n $modinfo = get_fast_modinfo($SITE);\n }\n $section = $modinfo->get_section_info(1);\n if (($section && (!empty($modinfo->sections[1]) or !empty($section->summary))) or $editing) {\n echo $OUTPUT->box_start('generalbox sitetopic');\n\n // If currently moving a file then show the current clipboard.\n if (ismoving($SITE->id)) {\n $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));\n echo '<p><font size="2">';\n echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=".sesskey()."\">";\n echo get_string('cancel') . '</a>)';\n echo '</font></p>';\n }\n\n $context = context_course::instance(SITEID);\n\n // If the section name is set we show it.\n if (trim($section->name) !== '') {\n echo $OUTPUT->heading(\n format_string($section->name, true, array('context' => $context)),\n 2,\n 'sectionname'\n );\n }\n\n $summarytext = file_rewrite_pluginfile_urls($section->summary,\n 'pluginfile.php',\n $context->id,\n 'course',\n 'section',\n $section->id);\n $summaryformatoptions = new stdClass();\n $summaryformatoptions->noclean = true;\n $summaryformatoptions->overflowdiv = true;\n\n echo format_text($summarytext, $section->summaryformat, $summaryformatoptions);\n\n if ($editing && has_capability('moodle/course:update', $context)) {\n $streditsummary = get_string('editsummary');\n echo "<a title=\"$streditsummary\" " .\n " href=\"course/editsection.php?id=$section->id\">" . $OUTPUT->pix_icon('t/edit', $streditsummary) .\n "</a><br /><br />";\n }\n\n $courserenderer = $PAGE->get_renderer('core', 'course');\n echo $courserenderer->course_section_cm_list($SITE, $section);\n\n echo $courserenderer->course_section_add_cm_control($SITE, $section->section);\n echo $OUTPUT->box_end();\n }\n}\n// Include course AJAX.\ninclude_course_ajax($SITE, $modnamesused);\n\nif (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {\n $frontpagelayout = $CFG->frontpageloggedin;\n} else {\n $frontpagelayout = $CFG->frontpage;\n}\n\nforeach (explode(',', $frontpagelayout) as $v) {\n switch ($v) {\n // Display the main part of the front page.\n case FRONTPAGENEWS:\n if ($SITE->newsitems) {\n // Print forums only when needed.\n require_once($CFG->dirroot .'/mod/forum/lib.php');\n\n if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {\n print_error('cannotfindorcreateforum', 'forum');\n }\n\n // Fetch news forum context for proper filtering to happen.\n $newsforumcm = get_coursemodule_from_instance('forum', $newsforum->id, $SITE->id, false, MUST_EXIST);\n $newsforumcontext = context_module::instance($newsforumcm->id, MUST_EXIST);\n\n $forumname = format_string($newsforum->name, true, array('context' => $newsforumcontext));\n echo html_writer::link('#skipsitenews',\n get_string('skipa', 'access', core_text::strtolower(strip_tags($forumname))),\n array('class' => 'skip-block skip'));\n\n // Wraps site news forum in div container.\n echo html_writer::start_tag('div', array('id' => 'site-news-forum'));\n\n if (isloggedin()) {\n $SESSION->fromdiscussion = $CFG->wwwroot;\n $subtext = '';\n if (\mod_forum\subscriptions::is_subscribed($USER->id, $newsforum)) {\n if (!\mod_forum\subscriptions::is_forcesubscribed($newsforum)) {\n $subtext = get_string('unsubscribe', 'forum');\n }\n } else {\n $subtext = get_string('subscribe', 'forum');\n }\n echo $OUTPUT->heading($forumname);\n $suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $newsforum->id, 'sesskey' => sesskey()));\n echo html_writer::tag('div', html_writer::link($suburl, $subtext), array('class' => 'subscribelink'));\n } else {\n echo $OUTPUT->heading($forumname);\n }\n\n forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');\n\n // End site news forum div container.\n echo html_writer::end_tag('div');\n\n echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipsitenews'));\n }\n break;\n\n case FRONTPAGEENROLLEDCOURSELIST:\n $mycourseshtml = $courserenderer->frontpage_my_courses();\n if (!empty($mycourseshtml)) {\n echo html_writer::link('#skipmycourses',\n get_string('skipa', 'access', core_text::strtolower(get_string('mycourses'))),\n array('class' => 'skip skip-block'));\n\n // Wrap frontpage course list in div container.\n echo html_writer::start_tag('div', array('id' => 'frontpage-course-list'));\n\n echo $OUTPUT->heading(get_string('mycourses'));\n echo $mycourseshtml;\n\n // End frontpage course list div container.\n echo html_writer::end_tag('div');\n\n echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipmycourses'));\n break;\n }\n // No "break" here. If there are no enrolled courses - continue to 'Available courses'.\n\n case FRONTPAGEALLCOURSELIST:\n $availablecourseshtml = $courserenderer->frontpage_available_courses();\n if (!empty($availablecourseshtml)) {\n echo html_writer::link('#skipavailablecourses',\n get_string('skipa', 'access', core_text::strtolower(get_string('availablecourses'))),\n array('class' => 'skip skip-block'));\n\n // Wrap frontpage course list in div container.\n echo html_writer::start_tag('div', array('id' => 'frontpage-course-list'));\n\n echo $OUTPUT->heading(get_string('availablecourses'));\n echo $availablecourseshtml;\n\n // End frontpage course list div container.\n echo html_writer::end_tag('div');\n\n echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipavailablecourses'));\n }\n break;\n\n case FRONTPAGECATEGORYNAMES:\n echo html_writer::link('#skipcategories',\n get_string('skipa', 'access', core_text::strtolower(get_string('categories'))),\n array('class' => 'skip skip-block'));\n\n // Wrap frontpage category names in div container.\n echo html_writer::start_tag('div', array('id' => 'frontpage-category-names'));\n\n echo $OUTPUT->heading(get_string('categories'));\n echo $courserenderer->frontpage_categories_list();\n\n // End frontpage category names div container.\n echo html_writer::end_tag('div');\n\n echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipcategories'));\n break;\n\n case FRONTPAGECATEGORYCOMBO:\n echo html_writer::link('#skipcourses',\n get_string('skipa', 'access', core_text::strtolower(get_string('courses'))),\n array('class' => 'skip skip-block'));\n\n // Wrap frontpage category combo in div container.\n echo html_writer::start_tag('div', array('id' => 'frontpage-category-combo'));\n\n echo $OUTPUT->heading(get_string('courses'));\n echo $courserenderer->frontpage_combo_list();\n\n // End frontpage category combo div container.\n echo html_writer::end_tag('div');\n\n echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipcourses'));\n break;\n\n case FRONTPAGECOURSESEARCH:\n echo $OUTPUT->box($courserenderer->course_search_form('', 'short'), 'mdl-align');\n break;\n\n }\n echo '<br />';\n}\nif ($editing && has_capability('moodle/course:create', context_system::instance())) {\n echo $courserenderer->add_new_course_button();\n}\necho $OUTPUT->footer();\n