function name typos
[moodle.git] / index.php
CommitLineData
474f6bfe 1<?php
657423c8 2 // index.php - the front page.
89adb174 3
0cfb6a52 4///////////////////////////////////////////////////////////////////////////
5// //
6// NOTICE OF COPYRIGHT //
7// //
8// Moodle - Modular Object-Oriented Dynamic Learning Environment //
9// http://moodle.org //
10// //
3b365361 11// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
0cfb6a52 12// //
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. //
17// //
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: //
22// //
23// http://www.gnu.org/copyleft/gpl.html //
24// //
25///////////////////////////////////////////////////////////////////////////
26
27
8b5b1028 28 if (!file_exists('./config.php')) {
29 header('Location: install.php');
30 die;
31 }
32
d41746c9 33 require_once('config.php');
34 require_once($CFG->dirroot .'/course/lib.php');
644d506a 35 require_once($CFG->libdir .'/filelib.php');
364fffda 36
5e39d7aa 37 redirect_if_major_upgrade_required();
89d1efe4 38
0a45ffe3 39 if ($CFG->forcelogin) {
40 require_login();
341b5ed2 41 } else {
42 user_accesstime_log();
0a45ffe3 43 }
44
4766a50c
SH
45 $PAGE->set_url('/');
46 $PAGE->set_course($SITE);
47
4fe2250a 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();
51 }
52
18818abf 53 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
54 if (moodle_needs_upgrading()) {
4bab5275 55 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
53bfe78c 56 }
4766a50c
SH
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);
18818abf 65 }
3565715c 66 }
67
0ad6b20c 68 if (get_moodle_cookie() == '') {
69 set_moodle_cookie('nobody'); // To help search for cookies on login page
9f9e3576 70 }
71
4f0c2d00 72 if (isloggedin()) {
34dd5900 73 add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
a325bd2b 74 }
a5e3644b 75
825b6fdb 76/// If the hub plugin is installed then we let it take over the homepage here
abf63f98 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();
df997f84 80 $hub->display_homepage();
abf63f98 81 exit;
82 }
83
f8065dd2 84 $PAGE->set_pagetype('site-index');
cfcfb9f3 85 $PAGE->set_other_editing_capability('moodle/course:manageactivities');
82611d8d 86 $PAGE->set_docs_path('');
191b267b 87 $PAGE->set_pagelayout('frontpage');
ad52c04f 88 $editing = $PAGE->user_is_editing();
d4a03c00 89 $PAGE->set_title($SITE->fullname);
90 $PAGE->set_heading($SITE->fullname);
244a32c6 91 echo $OUTPUT->header();
8c336db1 92
5fc2f2fd 93/// Print Section
78ba4d06 94 if ($SITE->numsections > 0) {
5fc2f2fd 95
f33e1ed4 96 if (!$section = $DB->get_record('course_sections', array('course'=>$SITE->id, 'section'=>1))) {
8618fd2a 97 $DB->delete_records('course_sections', array('course'=>$SITE->id, 'section'=>1)); // Just in case
78ba4d06 98 $section->course = $SITE->id;
45a6b40d 99 $section->section = 1;
100 $section->summary = '';
09eb2151 101 $section->summaryformat = FORMAT_HTML;
a2b82263 102 $section->sequence = '';
45a6b40d 103 $section->visible = 1;
f33e1ed4 104 $section->id = $DB->insert_record('course_sections', $section);
45a6b40d 105 }
5fc2f2fd 106
a2b82263 107 if (!empty($section->sequence) or !empty($section->summary) or $editing) {
20486a5a 108 echo $OUTPUT->box_start('generalbox sitetopic');
5fc2f2fd 109
a2b82263 110 /// If currently moving a file then show the current clipboard
111 if (ismoving($SITE->id)) {
294ce987 112 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
a2b82263 113 echo '<p><font size="2">';
973d2660 114 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=".sesskey()."\">". get_string('cancel') .'</a>)';
a2b82263 115 echo '</font></p>';
116 }
5fc2f2fd 117
644d506a 118 $context = get_context_instance(CONTEXT_COURSE, SITEID);
edc0c493 119 $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course_section', $section->id);
644d506a 120 $summaryformatoptions = new object();
121 $summaryformatoptions->noclean = true;
122
e34a326f 123 echo format_text($summarytext, $section->summaryformat, $summaryformatoptions);
5fc2f2fd 124
a2b82263 125 if ($editing) {
126 $streditsummary = get_string('editsummary');
127 echo "<a title=\"$streditsummary\" ".
b5d0cafc 128 " href=\"course/editsection.php?id=$section->id\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" ".
0d905d9f 129 " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
a2b82263 130 }
131
132 get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused);
133 print_section($SITE, $section, $mods, $modnamesused, true);
364fffda 134
a2b82263 135 if ($editing) {
136 print_section_add_menus($SITE, $section->section, $modnames);
137 }
20486a5a 138 echo $OUTPUT->box_end();
5fc2f2fd 139 }
5fc2f2fd 140 }
141
474f6bfe 142 if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
6f24e48e 143 $frontpagelayout = $CFG->frontpageloggedin;
144 } else {
145 $frontpagelayout = $CFG->frontpage;
146 }
147
148 foreach (explode(',',$frontpagelayout) as $v) {
e1638d61 149 switch ($v) { /// Display the main part of the front page.
220a90c5 150 case FRONTPAGENEWS:
e1638d61 151 if ($SITE->newsitems) { // Print forums only when needed
152 require_once($CFG->dirroot .'/mod/forum/lib.php');
153
154 if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
33aa5723 155 print_error('cannotfindorcreateforum', 'forum');
e1638d61 156 }
157
4f0c2d00 158 if (isloggedin()) {
e1638d61 159 $SESSION->fromdiscussion = $CFG->wwwroot;
6e5e0c93 160 $subtext = '';
90f4745c 161 if (forum_is_subscribed($USER->id, $newsforum)) {
730535cb 162 if (!forum_is_forcesubscribed($newsforum)) {
163 $subtext = get_string('unsubscribe', 'forum');
164 }
e1638d61 165 } else {
166 $subtext = get_string('subscribe', 'forum');
167 }
706b82da 168 echo $OUTPUT->heading($newsforum->name, 2, 'headingblock header');
1c9d49c2 169 echo '<div class="subscribelink"><a href="mod/forum/subscribe.php?id='.$newsforum->id.'">'.$subtext.'</a></div>';
af328e4b 170 } else {
706b82da 171 echo $OUTPUT->heading($newsforum->name, 2, 'headingblock header');
af328e4b 172 }
e1638d61 173
a5a9cd99 174 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
89adb174 175 }
e1638d61 176 break;
89adb174 177
e1638d61 178 case FRONTPAGECOURSELIST:
af328e4b 179
474f6bfe 180 if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguestuser() and empty($CFG->disablemycourses)) {
706b82da 181 echo $OUTPUT->heading(get_string('mycourses'), 2, 'headingblock header');
e1638d61 182 print_my_moodle();
474f6bfe 183 } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguestuser()) or ($DB->count_records('course') <= FRONTPAGECOURSELIMIT)) {
fe2920ad 184 // admin should not see list of courses when there are too many of them
706b82da 185 echo $OUTPUT->heading(get_string('availablecourses'), 2, 'headingblock header');
5f6b9c09 186 print_courses(0);
89adb174 187 }
e1638d61 188 break;
89adb174 189
e0140f24 190 case FRONTPAGECATEGORYNAMES:
191
706b82da 192 echo $OUTPUT->heading(get_string('categories'), 2, 'headingblock header');
20486a5a 193 echo $OUTPUT->box_start('generalbox categorybox');
d157bd5b 194 print_whole_category_list(NULL, NULL, NULL, -1, false);
20486a5a 195 echo $OUTPUT->box_end();
e0140f24 196 print_course_search('', false, 'short');
197 break;
198
6f24e48e 199 case FRONTPAGECATEGORYCOMBO:
706b82da 200 echo $OUTPUT->heading(get_string('categories'), 2, 'headingblock header');
24e27ac0
SH
201 $renderer = $PAGE->get_renderer('core','course');
202 echo $renderer->course_category_tree(get_course_category_tree());
6f24e48e 203 print_course_search('', false, 'short');
204 break;
205
e1638d61 206 case FRONTPAGETOPICONLY: // Do nothing!! :-)
207 break;
5eafd948 208
e1638d61 209 }
210 echo '<br />';
89adb174 211 }
212
d4a03c00 213 echo $OUTPUT->footer();