Merge branch 'w16_MDL-32447_m23_tcpdf' of git://github.com/skodak/moodle
[moodle.git] / index.php
blobe18d2c928836a93857db4ada2addb730dbb39f7b
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 $urlparams = array();
38 if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && optional_param('redirect', 1, PARAM_BOOL) === 0) {
39 $urlparams['redirect'] = 0;
41 $PAGE->set_url('/', $urlparams);
42 $PAGE->set_course($SITE);
44 if ($CFG->forcelogin) {
45 require_login();
46 } else {
47 user_accesstime_log();
50 $hassiteconfig = has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
52 /// If the site is currently under maintenance, then print a message
53 if (!empty($CFG->maintenance_enabled) and !$hassiteconfig) {
54 print_maintenance_message();
57 if ($hassiteconfig && moodle_needs_upgrading()) {
58 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
61 if (get_home_page() != HOMEPAGE_SITE) {
62 // Redirect logged-in users to My Moodle overview if required
63 if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
64 set_user_preference('user_home_page_preference', HOMEPAGE_SITE);
65 } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && optional_param('redirect', 1, PARAM_BOOL) === 1) {
66 redirect($CFG->wwwroot .'/my/');
67 } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_USER)) {
68 $PAGE->settingsnav->get('usercurrentsettings')->add(get_string('makethismyhome'), new moodle_url('/', array('setdefaulthome'=>true)), navigation_node::TYPE_SETTING);
72 if (isloggedin()) {
73 add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
76 /// If the hub plugin is installed then we let it take over the homepage here
77 if (get_config('local_hub', 'hubenabled') && file_exists($CFG->dirroot.'/local/hub/lib.php')) {
78 require_once($CFG->dirroot.'/local/hub/lib.php');
79 $hub = new local_hub();
80 $continue = $hub->display_homepage();
81 //display_homepage() return true if the hub home page is not displayed
82 //mostly when search form is not displayed for not logged users
83 if (empty($continue)) {
84 exit;
88 $PAGE->set_pagetype('site-index');
89 $PAGE->set_other_editing_capability('moodle/course:manageactivities');
90 $PAGE->set_docs_path('');
91 $PAGE->set_pagelayout('frontpage');
92 $editing = $PAGE->user_is_editing();
93 $PAGE->set_title($SITE->fullname);
94 $PAGE->set_heading($SITE->fullname);
95 echo $OUTPUT->header();
97 /// Print Section or custom info
98 if (!empty($CFG->customfrontpageinclude)) {
99 include($CFG->customfrontpageinclude);
101 } else if ($SITE->numsections > 0) {
103 if (!$section = $DB->get_record('course_sections', array('course'=>$SITE->id, 'section'=>1))) {
104 $DB->delete_records('course_sections', array('course'=>$SITE->id, 'section'=>1)); // Just in case
105 $section = new stdClass();
106 $section->course = $SITE->id;
107 $section->section = 1;
108 $section->summary = '';
109 $section->summaryformat = FORMAT_HTML;
110 $section->sequence = '';
111 $section->visible = 1;
112 $section->id = $DB->insert_record('course_sections', $section);
115 if (!empty($section->sequence) or !empty($section->summary) or $editing) {
116 echo $OUTPUT->box_start('generalbox sitetopic');
118 /// If currently moving a file then show the current clipboard
119 if (ismoving($SITE->id)) {
120 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
121 echo '<p><font size="2">';
122 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=".sesskey()."\">". get_string('cancel') .'</a>)';
123 echo '</font></p>';
126 $context = get_context_instance(CONTEXT_COURSE, SITEID);
127 $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course', 'section', $section->id);
128 $summaryformatoptions = new stdClass();
129 $summaryformatoptions->noclean = true;
130 $summaryformatoptions->overflowdiv = true;
132 echo format_text($summarytext, $section->summaryformat, $summaryformatoptions);
134 if ($editing) {
135 $streditsummary = get_string('editsummary');
136 echo "<a title=\"$streditsummary\" ".
137 " href=\"course/editsection.php?id=$section->id\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" ".
138 " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
141 get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused);
142 print_section($SITE, $section, $mods, $modnamesused, true);
144 if ($editing) {
145 print_section_add_menus($SITE, $section->section, $modnames);
147 echo $OUTPUT->box_end();
151 if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
152 $frontpagelayout = $CFG->frontpageloggedin;
153 } else {
154 $frontpagelayout = $CFG->frontpage;
157 foreach (explode(',',$frontpagelayout) as $v) {
158 switch ($v) { /// Display the main part of the front page.
159 case FRONTPAGENEWS:
160 if ($SITE->newsitems) { // Print forums only when needed
161 require_once($CFG->dirroot .'/mod/forum/lib.php');
163 if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
164 print_error('cannotfindorcreateforum', 'forum');
167 // fetch news forum context for proper filtering to happen
168 $newsforumcm = get_coursemodule_from_instance('forum', $newsforum->id, $SITE->id, false, MUST_EXIST);
169 $newsforumcontext = get_context_instance(CONTEXT_MODULE, $newsforumcm->id, MUST_EXIST);
171 $forumname = format_string($newsforum->name, true, array('context' => $newsforumcontext));
172 echo html_writer::tag('a', get_string('skipa', 'access', textlib::strtolower(strip_tags($forumname))), array('href'=>'#skipsitenews', 'class'=>'skip-block'));
174 if (isloggedin()) {
175 $SESSION->fromdiscussion = $CFG->wwwroot;
176 $subtext = '';
177 if (forum_is_subscribed($USER->id, $newsforum)) {
178 if (!forum_is_forcesubscribed($newsforum)) {
179 $subtext = get_string('unsubscribe', 'forum');
181 } else {
182 $subtext = get_string('subscribe', 'forum');
184 echo $OUTPUT->heading($forumname, 2, 'headingblock header');
185 $suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $newsforum->id, 'sesskey' => sesskey()));
186 echo html_writer::tag('div', html_writer::link($suburl, $subtext), array('class' => 'subscribelink'));
187 } else {
188 echo $OUTPUT->heading($forumname, 2, 'headingblock header');
191 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
192 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipsitenews'));
194 break;
196 case FRONTPAGECOURSELIST:
197 if (isloggedin() and !$hassiteconfig and !isguestuser() and empty($CFG->disablemycourses)) {
198 echo html_writer::tag('a', get_string('skipa', 'access', textlib::strtolower(get_string('mycourses'))), array('href'=>'#skipmycourses', 'class'=>'skip-block'));
199 echo $OUTPUT->heading(get_string('mycourses'), 2, 'headingblock header');
200 print_my_moodle();
201 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipmycourses'));
202 } else if ((!$hassiteconfig and !isguestuser()) or ($DB->count_records('course') <= FRONTPAGECOURSELIMIT)) {
203 // admin should not see list of courses when there are too many of them
204 echo html_writer::tag('a', get_string('skipa', 'access', textlib::strtolower(get_string('availablecourses'))), array('href'=>'#skipavailablecourses', 'class'=>'skip-block'));
205 echo $OUTPUT->heading(get_string('availablecourses'), 2, 'headingblock header');
206 print_courses(0);
207 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipavailablecourses'));
209 break;
211 case FRONTPAGECATEGORYNAMES:
212 echo html_writer::tag('a', get_string('skipa', 'access', textlib::strtolower(get_string('categories'))), array('href'=>'#skipcategories', 'class'=>'skip-block'));
213 echo $OUTPUT->heading(get_string('categories'), 2, 'headingblock header');
214 echo $OUTPUT->box_start('generalbox categorybox');
215 print_whole_category_list(NULL, NULL, NULL, -1, false);
216 echo $OUTPUT->box_end();
217 print_course_search('', false, 'short');
218 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipcategories'));
219 break;
221 case FRONTPAGECATEGORYCOMBO:
222 echo html_writer::tag('a', get_string('skipa', 'access', textlib::strtolower(get_string('courses'))), array('href'=>'#skipcourses', 'class'=>'skip-block'));
223 echo $OUTPUT->heading(get_string('courses'), 2, 'headingblock header');
224 $renderer = $PAGE->get_renderer('core','course');
225 // if there are too many courses, budiling course category tree could be slow,
226 // users should go to course index page to see the whole list.
227 $coursecount = $DB->count_records('course');
228 if (empty($CFG->numcoursesincombo)) {
229 // if $CFG->numcoursesincombo hasn't been set, use default value 500
230 $CFG->numcoursesincombo = 500;
232 if ($coursecount > $CFG->numcoursesincombo) {
233 $link = new moodle_url('/course/');
234 echo $OUTPUT->notification(get_string('maxnumcoursesincombo', 'moodle', array('link'=>$link->out(), 'maxnumofcourses'=>$CFG->numcoursesincombo, 'numberofcourses'=>$coursecount)));
235 } else {
236 echo $renderer->course_category_tree(get_course_category_tree());
238 print_course_search('', false, 'short');
239 echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipcourses'));
240 break;
242 case FRONTPAGETOPICONLY: // Do nothing!! :-)
243 break;
246 echo '<br />';
249 echo $OUTPUT->footer();