2 // index.php - the front page.
4 ///////////////////////////////////////////////////////////////////////////
6 // NOTICE OF COPYRIGHT //
8 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
9 // http://moodle.org //
11 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
13 // This program is free software; you can redistribute it and/or modify //
14 // it under the terms of the GNU General Public License as published by //
15 // the Free Software Foundation; either version 2 of the License, or //
16 // (at your option) any later version. //
18 // This program is distributed in the hope that it will be useful, //
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
21 // GNU General Public License for more details: //
23 // http://www.gnu.org/copyleft/gpl.html //
25 ///////////////////////////////////////////////////////////////////////////
28 if (!file_exists('./config.php')) {
29 header('Location: install.php');
33 require_once('config.php');
34 require_once($CFG->dirroot
.'/course/lib.php');
35 require_once($CFG->libdir
.'/filelib.php');
37 redirect_if_major_upgrade_required();
39 if ($CFG->forcelogin
) {
42 user_accesstime_log();
46 $PAGE->set_course($SITE);
48 /// If the site is currently under maintenance, then print a message
49 if (!empty($CFG->maintenance_enabled
) and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
))) {
50 print_maintenance_message();
53 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
))) {
54 if (moodle_needs_upgrading()) {
55 redirect($CFG->wwwroot
.'/'. $CFG->admin
.'/index.php');
57 } else if (get_home_page() != HOMEPAGE_SITE
) {
58 // Redirect logged-in users to My Moodle overview if required
59 if (optional_param('setdefaulthome', false, PARAM_BOOL
)) {
60 set_user_preference('user_home_page_preference', HOMEPAGE_SITE
);
61 } else if ($CFG->defaulthomepage
== HOMEPAGE_MY
&& optional_param('redirect', true, PARAM_BOOL
)) {
62 redirect($CFG->wwwroot
.'/my/');
63 } else if (!empty($CFG->defaulthomepage
) && $CFG->defaulthomepage
== HOMEPAGE_USER
) {
64 $PAGE->settingsnav
->get('usercurrentsettings')->add(get_string('makethismyhome'), new moodle_url('/', array('setdefaulthome'=>true)), navigation_node
::TYPE_SETTING
);
68 if (get_moodle_cookie() == '') {
69 set_moodle_cookie('nobody'); // To help search for cookies on login page
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 $hub->display_homepage();
84 $PAGE->set_pagetype('site-index');
85 $PAGE->set_other_editing_capability('moodle/course:manageactivities');
86 $PAGE->set_docs_path('');
87 $PAGE->set_pagelayout('frontpage');
88 $editing = $PAGE->user_is_editing();
89 $PAGE->set_title($SITE->fullname
);
90 $PAGE->set_heading($SITE->fullname
);
91 echo $OUTPUT->header();
94 if ($SITE->numsections
> 0) {
96 if (!$section = $DB->get_record('course_sections', array('course'=>$SITE->id
, 'section'=>1))) {
97 $DB->delete_records('course_sections', array('course'=>$SITE->id
, 'section'=>1)); // Just in case
98 $section->course
= $SITE->id
;
99 $section->section
= 1;
100 $section->summary
= '';
101 $section->summaryformat
= FORMAT_HTML
;
102 $section->sequence
= '';
103 $section->visible
= 1;
104 $section->id
= $DB->insert_record('course_sections', $section);
107 if (!empty($section->sequence
) or !empty($section->summary
) or $editing) {
108 echo $OUTPUT->box_start('generalbox sitetopic');
110 /// If currently moving a file then show the current clipboard
111 if (ismoving($SITE->id
)) {
112 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname
));
113 echo '<p><font size="2">';
114 echo "$stractivityclipboard (<a href=\"course/mod.php?cancelcopy=true&sesskey=".sesskey()."\">". get_string('cancel') .'</a>)';
118 $context = get_context_instance(CONTEXT_COURSE
, SITEID
);
119 $summarytext = file_rewrite_pluginfile_urls($section->summary
, 'pluginfile.php', $context->id
, 'course_section', $section->id
);
120 $summaryformatoptions = new object();
121 $summaryformatoptions->noclean
= true;
123 echo format_text($summarytext, $section->summaryformat
, $summaryformatoptions);
126 $streditsummary = get_string('editsummary');
127 echo "<a title=\"$streditsummary\" ".
128 " href=\"course/editsection.php?id=$section->id\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" ".
129 " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
132 get_all_mods($SITE->id
, $mods, $modnames, $modnamesplural, $modnamesused);
133 print_section($SITE, $section, $mods, $modnamesused, true);
136 print_section_add_menus($SITE, $section->section
, $modnames);
138 echo $OUTPUT->box_end();
142 if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin
)) {
143 $frontpagelayout = $CFG->frontpageloggedin
;
145 $frontpagelayout = $CFG->frontpage
;
148 foreach (explode(',',$frontpagelayout) as $v) {
149 switch ($v) { /// Display the main part of the front page.
151 if ($SITE->newsitems
) { // Print forums only when needed
152 require_once($CFG->dirroot
.'/mod/forum/lib.php');
154 if (! $newsforum = forum_get_course_forum($SITE->id
, 'news')) {
155 print_error('cannotfindorcreateforum', 'forum');
159 $SESSION->fromdiscussion
= $CFG->wwwroot
;
161 if (forum_is_subscribed($USER->id
, $newsforum)) {
162 if (!forum_is_forcesubscribed($newsforum)) {
163 $subtext = get_string('unsubscribe', 'forum');
166 $subtext = get_string('subscribe', 'forum');
168 echo $OUTPUT->heading($newsforum->name
, 2, 'headingblock header');
169 echo '<div class="subscribelink"><a href="mod/forum/subscribe.php?id='.$newsforum->id
.'">'.$subtext.'</a></div>';
171 echo $OUTPUT->heading($newsforum->name
, 2, 'headingblock header');
174 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems
, 'plain', 'p.modified DESC');
178 case FRONTPAGECOURSELIST
:
180 if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
)) and !isguestuser() and empty($CFG->disablemycourses
)) {
181 echo $OUTPUT->heading(get_string('mycourses'), 2, 'headingblock header');
183 } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
)) and !isguestuser()) or ($DB->count_records('course') <= FRONTPAGECOURSELIMIT
)) {
184 // admin should not see list of courses when there are too many of them
185 echo $OUTPUT->heading(get_string('availablecourses'), 2, 'headingblock header');
190 case FRONTPAGECATEGORYNAMES
:
192 echo $OUTPUT->heading(get_string('categories'), 2, 'headingblock header');
193 echo $OUTPUT->box_start('generalbox categorybox');
194 print_whole_category_list(NULL, NULL, NULL, -1, false);
195 echo $OUTPUT->box_end();
196 print_course_search('', false, 'short');
199 case FRONTPAGECATEGORYCOMBO
:
200 echo $OUTPUT->heading(get_string('categories'), 2, 'headingblock header');
201 $renderer = $PAGE->get_renderer('core','course');
202 echo $renderer->course_category_tree(get_course_category_tree());
203 print_course_search('', false, 'short');
206 case FRONTPAGETOPICONLY
: // Do nothing!! :-)
213 echo $OUTPUT->footer();