Automatically generated installer lang files
[moodle.git] / index.php
blob0a23cfb37774cfb1f65bcfe348cdbd5262407d03
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_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 site registration needs updating, redirect.
65 \core\hub\registration::registration_reminder('/index.php');
67 if (get_home_page() != HOMEPAGE_SITE) {
68 // Redirect logged-in users to My Moodle overview if required.
69 $redirect = optional_param('redirect', 1, PARAM_BOOL);
70 if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
71 set_user_preference('user_home_page_preference', HOMEPAGE_SITE);
72 } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && $redirect === 1) {
73 redirect($CFG->wwwroot .'/my/');
74 } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_USER)) {
75 $frontpagenode = $PAGE->settingsnav->find('frontpage', null);
76 if ($frontpagenode) {
77 $frontpagenode->add(
78 get_string('makethismyhome'),
79 new moodle_url('/', array('setdefaulthome' => true)),
80 navigation_node::TYPE_SETTING);
81 } else {
82 $frontpagenode = $PAGE->settingsnav->add(get_string('frontpagesettings'), null, navigation_node::TYPE_SETTING, null);
83 $frontpagenode->force_open();
84 $frontpagenode->add(get_string('makethismyhome'),
85 new moodle_url('/', array('setdefaulthome' => true)),
86 navigation_node::TYPE_SETTING);
91 // Trigger event.
92 course_view(context_course::instance(SITEID));
94 // If the hub plugin is installed then we let it take over the homepage here.
95 if (file_exists($CFG->dirroot.'/local/hub/lib.php') and get_config('local_hub', 'hubenabled')) {
96 require_once($CFG->dirroot.'/local/hub/lib.php');
97 $hub = new local_hub();
98 $continue = $hub->display_homepage();
99 // Function display_homepage() returns true if the hub home page is not displayed
100 // ...mostly when search form is not displayed for not logged users.
101 if (empty($continue)) {
102 exit;
106 $PAGE->set_pagetype('site-index');
107 $PAGE->set_docs_path('');
108 $editing = $PAGE->user_is_editing();
109 $PAGE->set_title($SITE->fullname);
110 $PAGE->set_heading($SITE->fullname);
111 $courserenderer = $PAGE->get_renderer('core', 'course');
112 echo $OUTPUT->header();
114 // Print Section or custom info.
115 $siteformatoptions = course_get_format($SITE)->get_format_options();
116 $modinfo = get_fast_modinfo($SITE);
117 $modnames = get_module_types_names();
118 $modnamesplural = get_module_types_names(true);
119 $modnamesused = $modinfo->get_used_module_names();
120 $mods = $modinfo->get_cms();
122 if (!empty($CFG->customfrontpageinclude)) {
123 include($CFG->customfrontpageinclude);
125 } else if ($siteformatoptions['numsections'] > 0) {
126 if ($editing) {
127 // Make sure section with number 1 exists.
128 course_create_sections_if_missing($SITE, 1);
129 // Re-request modinfo in case section was created.
130 $modinfo = get_fast_modinfo($SITE);
132 $section = $modinfo->get_section_info(1);
133 if (($section && (!empty($modinfo->sections[1]) or !empty($section->summary))) or $editing) {
134 echo $OUTPUT->box_start('generalbox sitetopic');
136 // If currently moving a file then show the current clipboard.
137 if (ismoving($SITE->id)) {
138 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
139 echo '<p><font size="2">';
140 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=".sesskey()."\">";
141 echo get_string('cancel') . '</a>)';
142 echo '</font></p>';
145 $context = context_course::instance(SITEID);
147 // If the section name is set we show it.
148 if (trim($section->name) !== '') {
149 echo $OUTPUT->heading(
150 format_string($section->name, true, array('context' => $context)),
152 'sectionname'
156 $summarytext = file_rewrite_pluginfile_urls($section->summary,
157 'pluginfile.php',
158 $context->id,
159 'course',
160 'section',
161 $section->id);
162 $summaryformatoptions = new stdClass();
163 $summaryformatoptions->noclean = true;
164 $summaryformatoptions->overflowdiv = true;
166 echo format_text($summarytext, $section->summaryformat, $summaryformatoptions);
168 if ($editing && has_capability('moodle/course:update', $context)) {
169 $streditsummary = get_string('editsummary');
170 echo "<a title=\"$streditsummary\" " .
171 " href=\"course/editsection.php?id=$section->id\">" . $OUTPUT->pix_icon('t/edit', $streditsummary) .
172 "</a><br /><br />";
175 $courserenderer = $PAGE->get_renderer('core', 'course');
176 echo $courserenderer->course_section_cm_list($SITE, $section);
178 echo $courserenderer->course_section_add_cm_control($SITE, $section->section);
179 echo $OUTPUT->box_end();
182 // Include course AJAX.
183 include_course_ajax($SITE, $modnamesused);
185 if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
186 $frontpagelayout = $CFG->frontpageloggedin;
187 } else {
188 $frontpagelayout = $CFG->frontpage;
191 $frontpageoptions = explode(',', $frontpagelayout);
192 foreach ($frontpageoptions as $v) {
193 switch ($v) {
194 // Display the main part of the front page.
195 case FRONTPAGENEWS:
196 if ($SITE->newsitems) {
197 // Print forums only when needed.
198 require_once($CFG->dirroot .'/mod/forum/lib.php');
200 if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
201 print_error('cannotfindorcreateforum', 'forum');
204 // Fetch news forum context for proper filtering to happen.
205 $newsforumcm = get_coursemodule_from_instance('forum', $newsforum->id, $SITE->id, false, MUST_EXIST);
206 $newsforumcontext = context_module::instance($newsforumcm->id, MUST_EXIST);
208 $forumname = format_string($newsforum->name, true, array('context' => $newsforumcontext));
209 echo html_writer::link('#skipsitenews',
210 get_string('skipa', 'access', core_text::strtolower(strip_tags($forumname))),
211 array('class' => 'skip-block skip'));
213 // Wraps site news forum in div container.
214 echo html_writer::start_tag('div', array('id' => 'site-news-forum'));
216 if (isloggedin()) {
217 $SESSION->fromdiscussion = $CFG->wwwroot;
218 $subtext = '';
219 if (\mod_forum\subscriptions::is_subscribed($USER->id, $newsforum)) {
220 if (!\mod_forum\subscriptions::is_forcesubscribed($newsforum)) {
221 $subtext = get_string('unsubscribe', 'forum');
223 } else {
224 $subtext = get_string('subscribe', 'forum');
226 echo $OUTPUT->heading($forumname);
227 $suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $newsforum->id, 'sesskey' => sesskey()));
228 echo html_writer::tag('div', html_writer::link($suburl, $subtext), array('class' => 'subscribelink'));
229 } else {
230 echo $OUTPUT->heading($forumname);
233 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
235 // End site news forum div container.
236 echo html_writer::end_tag('div');
238 echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipsitenews'));
240 break;
242 case FRONTPAGEENROLLEDCOURSELIST:
243 $mycourseshtml = $courserenderer->frontpage_my_courses();
244 if (!empty($mycourseshtml)) {
245 echo html_writer::link('#skipmycourses',
246 get_string('skipa', 'access', core_text::strtolower(get_string('mycourses'))),
247 array('class' => 'skip skip-block'));
249 // Wrap frontpage course list in div container.
250 echo html_writer::start_tag('div', array('id' => 'frontpage-course-list'));
252 echo $OUTPUT->heading(get_string('mycourses'));
253 echo $mycourseshtml;
255 // End frontpage course list div container.
256 echo html_writer::end_tag('div');
258 echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipmycourses'));
259 break;
260 } else {
261 // Temp fix/fallback in order to display available courses when enrolled courses should be shown,
262 // but user is not enrolled in any course.
263 if (array_search(FRONTPAGEALLCOURSELIST, $frontpageoptions)) {
264 break;
268 case FRONTPAGEALLCOURSELIST:
269 $availablecourseshtml = $courserenderer->frontpage_available_courses();
270 if (!empty($availablecourseshtml)) {
271 echo html_writer::link('#skipavailablecourses',
272 get_string('skipa', 'access', core_text::strtolower(get_string('availablecourses'))),
273 array('class' => 'skip skip-block'));
275 // Wrap frontpage course list in div container.
276 echo html_writer::start_tag('div', array('id' => 'frontpage-course-list'));
278 echo $OUTPUT->heading(get_string('availablecourses'));
279 echo $availablecourseshtml;
281 // End frontpage course list div container.
282 echo html_writer::end_tag('div');
284 echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipavailablecourses'));
286 break;
288 case FRONTPAGECATEGORYNAMES:
289 echo html_writer::link('#skipcategories',
290 get_string('skipa', 'access', core_text::strtolower(get_string('categories'))),
291 array('class' => 'skip skip-block'));
293 // Wrap frontpage category names in div container.
294 echo html_writer::start_tag('div', array('id' => 'frontpage-category-names'));
296 echo $OUTPUT->heading(get_string('categories'));
297 echo $courserenderer->frontpage_categories_list();
299 // End frontpage category names div container.
300 echo html_writer::end_tag('div');
302 echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipcategories'));
303 break;
305 case FRONTPAGECATEGORYCOMBO:
306 echo html_writer::link('#skipcourses',
307 get_string('skipa', 'access', core_text::strtolower(get_string('courses'))),
308 array('class' => 'skip skip-block'));
310 // Wrap frontpage category combo in div container.
311 echo html_writer::start_tag('div', array('id' => 'frontpage-category-combo'));
313 echo $OUTPUT->heading(get_string('courses'));
314 echo $courserenderer->frontpage_combo_list();
316 // End frontpage category combo div container.
317 echo html_writer::end_tag('div');
319 echo html_writer::tag('span', '', array('class' => 'skip-block-to', 'id' => 'skipcourses'));
320 break;
322 case FRONTPAGECOURSESEARCH:
323 echo $OUTPUT->box($courserenderer->course_search_form('', 'short'), 'mdl-align');
324 break;
327 echo '<br />';
329 if ($editing && has_capability('moodle/course:create', context_system::instance())) {
330 echo $courserenderer->add_new_course_button();
332 echo $OUTPUT->footer();