Changed upper case words to lower case. I love vim.
[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
f8065dd2 76 $PAGE->set_pagetype('site-index');
cfcfb9f3 77 $PAGE->set_other_editing_capability('moodle/course:manageactivities');
82611d8d 78 $PAGE->set_docs_path('');
191b267b 79 $PAGE->set_pagelayout('frontpage');
ad52c04f 80 $editing = $PAGE->user_is_editing();
d4a03c00 81 $PAGE->set_title($SITE->fullname);
82 $PAGE->set_heading($SITE->fullname);
244a32c6 83 echo $OUTPUT->header();
8c336db1 84
5fc2f2fd 85/// Print Section
78ba4d06 86 if ($SITE->numsections > 0) {
5fc2f2fd 87
f33e1ed4 88 if (!$section = $DB->get_record('course_sections', array('course'=>$SITE->id, 'section'=>1))) {
8618fd2a 89 $DB->delete_records('course_sections', array('course'=>$SITE->id, 'section'=>1)); // Just in case
78ba4d06 90 $section->course = $SITE->id;
45a6b40d 91 $section->section = 1;
92 $section->summary = '';
a2b82263 93 $section->sequence = '';
45a6b40d 94 $section->visible = 1;
f33e1ed4 95 $section->id = $DB->insert_record('course_sections', $section);
45a6b40d 96 }
5fc2f2fd 97
a2b82263 98 if (!empty($section->sequence) or !empty($section->summary) or $editing) {
20486a5a 99 echo $OUTPUT->box_start('generalbox sitetopic');
5fc2f2fd 100
a2b82263 101 /// If currently moving a file then show the current clipboard
102 if (ismoving($SITE->id)) {
294ce987 103 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
a2b82263 104 echo '<p><font size="2">';
973d2660 105 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=".sesskey()."\">". get_string('cancel') .'</a>)';
a2b82263 106 echo '</font></p>';
107 }
5fc2f2fd 108
644d506a 109 $context = get_context_instance(CONTEXT_COURSE, SITEID);
edc0c493 110 $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course_section', $section->id);
644d506a 111 $summaryformatoptions = new object();
112 $summaryformatoptions->noclean = true;
113
114 echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
5fc2f2fd 115
a2b82263 116 if ($editing) {
117 $streditsummary = get_string('editsummary');
118 echo "<a title=\"$streditsummary\" ".
b5d0cafc 119 " href=\"course/editsection.php?id=$section->id\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" ".
0d905d9f 120 " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
a2b82263 121 }
122
123 get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused);
124 print_section($SITE, $section, $mods, $modnamesused, true);
364fffda 125
a2b82263 126 if ($editing) {
127 print_section_add_menus($SITE, $section->section, $modnames);
128 }
20486a5a 129 echo $OUTPUT->box_end();
5fc2f2fd 130 }
5fc2f2fd 131 }
132
474f6bfe 133 if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
6f24e48e 134 $frontpagelayout = $CFG->frontpageloggedin;
135 } else {
136 $frontpagelayout = $CFG->frontpage;
137 }
138
139 foreach (explode(',',$frontpagelayout) as $v) {
e1638d61 140 switch ($v) { /// Display the main part of the front page.
220a90c5 141 case FRONTPAGENEWS:
e1638d61 142 if ($SITE->newsitems) { // Print forums only when needed
143 require_once($CFG->dirroot .'/mod/forum/lib.php');
144
145 if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
33aa5723 146 print_error('cannotfindorcreateforum', 'forum');
e1638d61 147 }
148
4f0c2d00 149 if (isloggedin()) {
e1638d61 150 $SESSION->fromdiscussion = $CFG->wwwroot;
6e5e0c93 151 $subtext = '';
90f4745c 152 if (forum_is_subscribed($USER->id, $newsforum)) {
730535cb 153 if (!forum_is_forcesubscribed($newsforum)) {
154 $subtext = get_string('unsubscribe', 'forum');
155 }
e1638d61 156 } else {
157 $subtext = get_string('subscribe', 'forum');
158 }
706b82da 159 echo $OUTPUT->heading($newsforum->name, 2, 'headingblock header');
1c9d49c2 160 echo '<div class="subscribelink"><a href="mod/forum/subscribe.php?id='.$newsforum->id.'">'.$subtext.'</a></div>';
af328e4b 161 } else {
706b82da 162 echo $OUTPUT->heading($newsforum->name, 2, 'headingblock header');
af328e4b 163 }
e1638d61 164
a5a9cd99 165 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
89adb174 166 }
e1638d61 167 break;
89adb174 168
e1638d61 169 case FRONTPAGECOURSELIST:
af328e4b 170
474f6bfe 171 if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguestuser() and empty($CFG->disablemycourses)) {
706b82da 172 echo $OUTPUT->heading(get_string('mycourses'), 2, 'headingblock header');
e1638d61 173 print_my_moodle();
474f6bfe 174 } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguestuser()) or ($DB->count_records('course') <= FRONTPAGECOURSELIMIT)) {
fe2920ad 175 // admin should not see list of courses when there are too many of them
706b82da 176 echo $OUTPUT->heading(get_string('availablecourses'), 2, 'headingblock header');
5f6b9c09 177 print_courses(0);
89adb174 178 }
e1638d61 179 break;
89adb174 180
e0140f24 181 case FRONTPAGECATEGORYNAMES:
182
706b82da 183 echo $OUTPUT->heading(get_string('categories'), 2, 'headingblock header');
20486a5a 184 echo $OUTPUT->box_start('generalbox categorybox');
d157bd5b 185 print_whole_category_list(NULL, NULL, NULL, -1, false);
20486a5a 186 echo $OUTPUT->box_end();
e0140f24 187 print_course_search('', false, 'short');
188 break;
189
6f24e48e 190 case FRONTPAGECATEGORYCOMBO:
191
706b82da 192 echo $OUTPUT->heading(get_string('categories'), 2, 'headingblock header');
20486a5a 193 echo $OUTPUT->box_start('generalbox categorybox');
6f24e48e 194 print_whole_category_list(NULL, NULL, NULL, -1, true);
20486a5a 195 echo $OUTPUT->box_end();
6f24e48e 196 print_course_search('', false, 'short');
197 break;
198
e1638d61 199 case FRONTPAGETOPICONLY: // Do nothing!! :-)
200 break;
5eafd948 201
e1638d61 202 }
203 echo '<br />';
89adb174 204 }
205
d4a03c00 206 echo $OUTPUT->footer();