MDL-24896 no more returning explicit reference by get_mailer
[moodle.git] / index.php
blobdafc1ae62949fc69a7a63d0886d292d7f8ffe314
1 <?php
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.
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/>.
18 /**
19 * Moodle frontpage.
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
26 if (!file_exists('./config.php')) {
27 header('Location: install.php');
28 die;
31 require_once('config.php');
32 require_once($CFG->dirroot .'/course/lib.php');
33 require_once($CFG->libdir .'/filelib.php');
35 redirect_if_major_upgrade_required();
37 if ($CFG->forcelogin) {
38 require_login();
39 } else {
40 user_accesstime_log();
43 $PAGE->set_url('/');
44 $PAGE->set_course($SITE);
46 /// If the site is currently under maintenance, then print a message
47 if (!empty($CFG->maintenance_enabled) and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
48 print_maintenance_message();
51 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
52 if (moodle_needs_upgrading()) {
53 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
55 } else if (get_home_page() != HOMEPAGE_SITE) {
56 // Redirect logged-in users to My Moodle overview if required
57 if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
58 set_user_preference('user_home_page_preference', HOMEPAGE_SITE);
59 } else if ($CFG->defaulthomepage == HOMEPAGE_MY && optional_param('redirect', true, PARAM_BOOL)) {
60 redirect($CFG->wwwroot .'/my/');
61 } else if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_USER) {
62 $PAGE->settingsnav->get('usercurrentsettings')->add(get_string('makethismyhome'), new moodle_url('/', array('setdefaulthome'=>true)), navigation_node::TYPE_SETTING);
66 if (isloggedin()) {
67 add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
70 /// If the hub plugin is installed then we let it take over the homepage here
71 if (get_config('local_hub', 'hubenabled') && file_exists($CFG->dirroot.'/local/hub/lib.php')) {
72 require_once($CFG->dirroot.'/local/hub/lib.php');
73 $hub = new local_hub();
74 $continue = $hub->display_homepage();
75 //display_homepage() return true if the hub home page is not displayed
76 //mostly when search form is not displayed for not logged users
77 if (empty($continue)) {
78 exit;
82 $PAGE->set_pagetype('site-index');
83 $PAGE->set_other_editing_capability('moodle/course:manageactivities');
84 $PAGE->set_docs_path('');
85 $PAGE->set_pagelayout('frontpage');
86 $editing = $PAGE->user_is_editing();
87 $PAGE->set_title($SITE->fullname);
88 $PAGE->set_heading($SITE->fullname);
89 echo $OUTPUT->header();
91 /// Print Section
92 if ($SITE->numsections > 0) {
94 if (!$section = $DB->get_record('course_sections', array('course'=>$SITE->id, 'section'=>1))) {
95 $DB->delete_records('course_sections', array('course'=>$SITE->id, 'section'=>1)); // Just in case
96 $section->course = $SITE->id;
97 $section->section = 1;
98 $section->summary = '';
99 $section->summaryformat = FORMAT_HTML;
100 $section->sequence = '';
101 $section->visible = 1;
102 $section->id = $DB->insert_record('course_sections', $section);
105 if (!empty($section->sequence) or !empty($section->summary) or $editing) {
106 echo $OUTPUT->box_start('generalbox sitetopic');
108 /// If currently moving a file then show the current clipboard
109 if (ismoving($SITE->id)) {
110 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
111 echo '<p><font size="2">';
112 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=".sesskey()."\">". get_string('cancel') .'</a>)';
113 echo '</font></p>';
116 $context = get_context_instance(CONTEXT_COURSE, SITEID);
117 $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course', 'section', $section->id);
118 $summaryformatoptions = new stdClass();
119 $summaryformatoptions->noclean = true;
121 echo format_text($summarytext, $section->summaryformat, $summaryformatoptions);
123 if ($editing) {
124 $streditsummary = get_string('editsummary');
125 echo "<a title=\"$streditsummary\" ".
126 " href=\"course/editsection.php?id=$section->id\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" ".
127 " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
130 get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused);
131 print_section($SITE, $section, $mods, $modnamesused, true);
133 if ($editing) {
134 print_section_add_menus($SITE, $section->section, $modnames);
136 echo $OUTPUT->box_end();
140 if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
141 $frontpagelayout = $CFG->frontpageloggedin;
142 } else {
143 $frontpagelayout = $CFG->frontpage;
146 foreach (explode(',',$frontpagelayout) as $v) {
147 switch ($v) { /// Display the main part of the front page.
148 case FRONTPAGENEWS:
149 if ($SITE->newsitems) { // Print forums only when needed
150 require_once($CFG->dirroot .'/mod/forum/lib.php');
152 if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
153 print_error('cannotfindorcreateforum', 'forum');
155 echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower($newsforum->name)), array('href'=>'#skipsitenews', 'class'=>'skip-block'));
157 if (isloggedin()) {
158 $SESSION->fromdiscussion = $CFG->wwwroot;
159 $subtext = '';
160 if (forum_is_subscribed($USER->id, $newsforum)) {
161 if (!forum_is_forcesubscribed($newsforum)) {
162 $subtext = get_string('unsubscribe', 'forum');
164 } else {
165 $subtext = get_string('subscribe', 'forum');
167 echo $OUTPUT->heading($newsforum->name, 2, 'headingblock header');
168 echo '<div class="subscribelink"><a href="mod/forum/subscribe.php?id='.$newsforum->id.'">'.$subtext.'</a></div>';
169 } else {
170 echo $OUTPUT->heading($newsforum->name, 2, 'headingblock header');
173 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
174 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipsitenews'));
176 break;
178 case FRONTPAGECOURSELIST:
179 if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguestuser() and empty($CFG->disablemycourses)) {
180 echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('mycourses'))), array('href'=>'#skipmycourses', 'class'=>'skip-block'));
181 echo $OUTPUT->heading(get_string('mycourses'), 2, 'headingblock header');
182 print_my_moodle();
183 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipmycourses'));
184 } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguestuser()) or ($DB->count_records('course') <= FRONTPAGECOURSELIMIT)) {
185 // admin should not see list of courses when there are too many of them
186 echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('availablecourses'))), array('href'=>'#skipavailablecourses', 'class'=>'skip-block'));
187 echo $OUTPUT->heading(get_string('availablecourses'), 2, 'headingblock header');
188 print_courses(0);
189 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipavailablecourses'));
191 break;
193 case FRONTPAGECATEGORYNAMES:
194 echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('categories'))), array('href'=>'#skipcategories', 'class'=>'skip-block'));
195 echo $OUTPUT->heading(get_string('categories'), 2, 'headingblock header');
196 echo $OUTPUT->box_start('generalbox categorybox');
197 print_whole_category_list(NULL, NULL, NULL, -1, false);
198 echo $OUTPUT->box_end();
199 print_course_search('', false, 'short');
200 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipcategories'));
201 break;
203 case FRONTPAGECATEGORYCOMBO:
204 echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('courses'))), array('href'=>'#skipcourses', 'class'=>'skip-block'));
205 echo $OUTPUT->heading(get_string('courses'), 2, 'headingblock header');
206 $renderer = $PAGE->get_renderer('core','course');
207 echo $renderer->course_category_tree(get_course_category_tree());
208 print_course_search('', false, 'short');
209 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipcourses'));
210 break;
212 case FRONTPAGETOPICONLY: // Do nothing!! :-)
213 break;
216 echo '<br />';
219 echo $OUTPUT->footer();