MDL-19756 Muting debugging error for optionsextra param of popup_form (used only...
[moodle.git] / index.php
CommitLineData
4bab5275 1<?php // $Id$
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
4fe2250a 45/// If the site is currently under maintenance, then print a message
46 if (!empty($CFG->maintenance_enabled) and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
47 print_maintenance_message();
48 }
49
18818abf 50 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
51 if (moodle_needs_upgrading()) {
4bab5275 52 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
53bfe78c 53 }
18818abf 54 } else if (!empty($CFG->mymoodleredirect)) { // Redirect logged-in users to My Moodle overview if required
4fe2250a 55 if (isloggedin() && !isguestuser()) {
18818abf 56 redirect($CFG->wwwroot .'/my/index.php');
57 }
3565715c 58 }
59
db0852c5 60
0ad6b20c 61 if (get_moodle_cookie() == '') {
62 set_moodle_cookie('nobody'); // To help search for cookies on login page
9f9e3576 63 }
64
c44d5d42 65 if (!empty($USER->id)) {
34dd5900 66 add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
a325bd2b 67 }
a5e3644b 68
f8065dd2 69 $PAGE->set_pagetype('site-index');
70 $PAGE->set_course($SITE);
71
984a8bf3 72 if (empty($CFG->langmenu)) {
4bab5275 73 $langmenu = '';
984a8bf3 74 } else {
75 $currlang = current_language();
76 $langs = get_list_of_languages();
d81b05e7 77
78 $select = moodle_select::make_popup_form($CFG->wwwroot .'/index.php', 'lang', $langs, 'chooselang', $currlang);
79 $select->nothinglabel = false;
80 $select->set_label(get_accesshide(get_string('language')));
81 $langmenu = $OUTPUT->select($select);
984a8bf3 82 }
cfcfb9f3 83 $PAGE->set_other_editing_capability('moodle/course:manageactivities');
ad52c04f 84 $PAGE->set_url('');
82611d8d 85 $PAGE->set_docs_path('');
34a2777c 86 $PAGE->set_generaltype('home');
ad52c04f 87 $editing = $PAGE->user_is_editing();
d4a03c00 88 $PAGE->set_title($SITE->fullname);
89 $PAGE->set_heading($SITE->fullname);
90 echo $OUTPUT->header('', user_login_string($SITE) . $langmenu);
8c336db1 91
5fc2f2fd 92/// Print Section
78ba4d06 93 if ($SITE->numsections > 0) {
5fc2f2fd 94
f33e1ed4 95 if (!$section = $DB->get_record('course_sections', array('course'=>$SITE->id, 'section'=>1))) {
8618fd2a 96 $DB->delete_records('course_sections', array('course'=>$SITE->id, 'section'=>1)); // Just in case
78ba4d06 97 $section->course = $SITE->id;
45a6b40d 98 $section->section = 1;
99 $section->summary = '';
a2b82263 100 $section->sequence = '';
45a6b40d 101 $section->visible = 1;
f33e1ed4 102 $section->id = $DB->insert_record('course_sections', $section);
45a6b40d 103 }
5fc2f2fd 104
a2b82263 105 if (!empty($section->sequence) or !empty($section->summary) or $editing) {
8cef9517 106 print_box_start('generalbox sitetopic');
5fc2f2fd 107
a2b82263 108 /// If currently moving a file then show the current clipboard
109 if (ismoving($SITE->id)) {
294ce987 110 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
a2b82263 111 echo '<p><font size="2">';
973d2660 112 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=".sesskey()."\">". get_string('cancel') .'</a>)';
a2b82263 113 echo '</font></p>';
114 }
5fc2f2fd 115
644d506a 116 $context = get_context_instance(CONTEXT_COURSE, SITEID);
edc0c493 117 $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course_section', $section->id);
644d506a 118 $summaryformatoptions = new object();
119 $summaryformatoptions->noclean = true;
120
121 echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
5fc2f2fd 122
a2b82263 123 if ($editing) {
124 $streditsummary = get_string('editsummary');
125 echo "<a title=\"$streditsummary\" ".
4096752d 126 " href=\"course/editsection.php?id=$section->id\"><img src=\"" . $OUTPUT->old_icon_url('t/edit') . "\" ".
0d905d9f 127 " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
a2b82263 128 }
129
130 get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused);
131 print_section($SITE, $section, $mods, $modnamesused, true);
364fffda 132
a2b82263 133 if ($editing) {
134 print_section_add_menus($SITE, $section->section, $modnames);
135 }
8cef9517 136 print_box_end();
5fc2f2fd 137 }
5fc2f2fd 138 }
139
6f24e48e 140 if (isloggedin() and !isguest() and isset($CFG->frontpageloggedin)) {
141 $frontpagelayout = $CFG->frontpageloggedin;
142 } else {
143 $frontpagelayout = $CFG->frontpage;
144 }
145
146 foreach (explode(',',$frontpagelayout) as $v) {
e1638d61 147 switch ($v) { /// Display the main part of the front page.
220a90c5 148 case FRONTPAGENEWS:
e1638d61 149 if ($SITE->newsitems) { // Print forums only when needed
150 require_once($CFG->dirroot .'/mod/forum/lib.php');
151
152 if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
33aa5723 153 print_error('cannotfindorcreateforum', 'forum');
e1638d61 154 }
155
86a1ba04 156 if (!empty($USER->id)) {
e1638d61 157 $SESSION->fromdiscussion = $CFG->wwwroot;
6e5e0c93 158 $subtext = '';
90f4745c 159 if (forum_is_subscribed($USER->id, $newsforum)) {
730535cb 160 if (!forum_is_forcesubscribed($newsforum)) {
161 $subtext = get_string('unsubscribe', 'forum');
162 }
e1638d61 163 } else {
164 $subtext = get_string('subscribe', 'forum');
165 }
706b82da 166 echo $OUTPUT->heading($newsforum->name, 2, 'headingblock header');
1c9d49c2 167 echo '<div class="subscribelink"><a href="mod/forum/subscribe.php?id='.$newsforum->id.'">'.$subtext.'</a></div>';
af328e4b 168 } else {
706b82da 169 echo $OUTPUT->heading($newsforum->name, 2, 'headingblock header');
af328e4b 170 }
e1638d61 171
a5a9cd99 172 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
89adb174 173 }
e1638d61 174 break;
89adb174 175
e1638d61 176 case FRONTPAGECOURSELIST:
af328e4b 177
84c8ede0 178 if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) {
706b82da 179 echo $OUTPUT->heading(get_string('mycourses'), 2, 'headingblock header');
e1638d61 180 print_my_moodle();
c7da4357 181 } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest()) or ($DB->count_records('course') <= FRONTPAGECOURSELIMIT)) {
fe2920ad 182 // admin should not see list of courses when there are too many of them
706b82da 183 echo $OUTPUT->heading(get_string('availablecourses'), 2, 'headingblock header');
5f6b9c09 184 print_courses(0);
89adb174 185 }
e1638d61 186 break;
89adb174 187
e0140f24 188 case FRONTPAGECATEGORYNAMES:
189
706b82da 190 echo $OUTPUT->heading(get_string('categories'), 2, 'headingblock header');
986f093f 191 print_box_start('generalbox categorybox');
d157bd5b 192 print_whole_category_list(NULL, NULL, NULL, -1, false);
986f093f 193 print_box_end();
e0140f24 194 print_course_search('', false, 'short');
195 break;
196
6f24e48e 197 case FRONTPAGECATEGORYCOMBO:
198
706b82da 199 echo $OUTPUT->heading(get_string('categories'), 2, 'headingblock header');
986f093f 200 print_box_start('generalbox categorybox');
6f24e48e 201 print_whole_category_list(NULL, NULL, NULL, -1, true);
986f093f 202 print_box_end();
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();