web service MDL-12886 return value fix for REST server
[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 .'/blocklib.php');
36 require_once($CFG->libdir .'/filelib.php');
364fffda 37
689456eb 38 // Bounds for block widths
39 // more flexible for theme designers taken from theme config.php
40 $lmin = (empty($THEME->block_l_min_width)) ? 100 : $THEME->block_l_min_width;
41 $lmax = (empty($THEME->block_l_max_width)) ? 210 : $THEME->block_l_max_width;
42 $rmin = (empty($THEME->block_r_min_width)) ? 100 : $THEME->block_r_min_width;
43 $rmax = (empty($THEME->block_r_max_width)) ? 210 : $THEME->block_r_max_width;
44
45 define('BLOCK_L_MIN_WIDTH', $lmin);
46 define('BLOCK_L_MAX_WIDTH', $lmax);
47 define('BLOCK_R_MIN_WIDTH', $rmin);
48 define('BLOCK_R_MAX_WIDTH', $rmax);
df9e0f89 49
5f0314ab 50 // check if major upgrade needed - also present in login/index.php
88582df4 51 if (empty($CFG->version) or (int)$CFG->version < 2009011900 or !empty($CFG->adminsetuppending)) { //1.9 or older
89d1efe4 52 @require_logout();
53 redirect("$CFG->wwwroot/$CFG->admin/");
54 }
55
0a45ffe3 56 if ($CFG->forcelogin) {
57 require_login();
341b5ed2 58 } else {
59 user_accesstime_log();
0a45ffe3 60 }
61
18818abf 62 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
63 if (moodle_needs_upgrading()) {
4bab5275 64 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
53bfe78c 65 }
18818abf 66 } else if (!empty($CFG->mymoodleredirect)) { // Redirect logged-in users to My Moodle overview if required
67 if (isloggedin() && $USER->username != 'guest') {
68 redirect($CFG->wwwroot .'/my/index.php');
69 }
3565715c 70 }
71
db0852c5 72
0ad6b20c 73 if (get_moodle_cookie() == '') {
74 set_moodle_cookie('nobody'); // To help search for cookies on login page
9f9e3576 75 }
76
c44d5d42 77 if (!empty($USER->id)) {
34dd5900 78 add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
a325bd2b 79 }
a5e3644b 80
984a8bf3 81 if (empty($CFG->langmenu)) {
4bab5275 82 $langmenu = '';
984a8bf3 83 } else {
84 $currlang = current_language();
85 $langs = get_list_of_languages();
0d0afd96 86 $langlabel = get_accesshide(get_string('language'));
2c6e998f 87 $langmenu = popup_form($CFG->wwwroot .'/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true, 'self', $langlabel);
984a8bf3 88 }
a5e3644b 89
60fe9736 90 $PAGE = page_create_object(PAGE_COURSE_VIEW, SITEID);
3615b2b2 91 $pageblocks = blocks_setup($PAGE);
60fe9736 92 $editing = $PAGE->user_is_editing();
364fffda 93 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
af328e4b 94 BLOCK_L_MAX_WIDTH);
364fffda 95 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
af328e4b 96 BLOCK_R_MAX_WIDTH);
704ba13c 97 print_header($SITE->fullname, $SITE->fullname, 'home', '',
78ba4d06 98 '<meta name="description" content="'. s(strip_tags($SITE->summary)) .'" />',
c44d5d42 99 true, '', user_login_string($SITE).$langmenu);
5921e0a0 100
f9903ed0 101?>
102
3054741a 103
6173f39e 104<table id="layout-table" summary="layout">
3565715c 105 <tr>
af328e4b 106 <?php
d55c9a1f 107 $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
108 foreach ($lt as $column) {
109 switch ($column) {
110 case 'left':
af328e4b 111 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
e96ba29d 112 echo '<td style="width: '.$preferred_width_left.'px;" id="left-column">';
9f7f1a74 113 print_container_start();
66492322 114 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
9f7f1a74 115 print_container_end();
89adb174 116 echo '</td>';
117 }
d55c9a1f 118 break;
119 case 'middle':
317d5ddc 120 echo '<td id="middle-column">'. skip_main_destination();
8c336db1 121
9f7f1a74 122 print_container_start();
8c336db1 123
5fc2f2fd 124/// Print Section
78ba4d06 125 if ($SITE->numsections > 0) {
5fc2f2fd 126
f33e1ed4 127 if (!$section = $DB->get_record('course_sections', array('course'=>$SITE->id, 'section'=>1))) {
8618fd2a 128 $DB->delete_records('course_sections', array('course'=>$SITE->id, 'section'=>1)); // Just in case
78ba4d06 129 $section->course = $SITE->id;
45a6b40d 130 $section->section = 1;
131 $section->summary = '';
a2b82263 132 $section->sequence = '';
45a6b40d 133 $section->visible = 1;
f33e1ed4 134 $section->id = $DB->insert_record('course_sections', $section);
45a6b40d 135 }
5fc2f2fd 136
a2b82263 137 if (!empty($section->sequence) or !empty($section->summary) or $editing) {
8cef9517 138 print_box_start('generalbox sitetopic');
5fc2f2fd 139
a2b82263 140 /// If currently moving a file then show the current clipboard
141 if (ismoving($SITE->id)) {
294ce987 142 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
a2b82263 143 echo '<p><font size="2">';
973d2660 144 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=".sesskey()."\">". get_string('cancel') .'</a>)';
a2b82263 145 echo '</font></p>';
146 }
5fc2f2fd 147
644d506a 148 $context = get_context_instance(CONTEXT_COURSE, SITEID);
149 $summarytext = file_convert_relative_pluginfiles($section->summary, 'pluginfile.php', "$context->id/course_section/$section->id/");
150 $summaryformatoptions = new object();
151 $summaryformatoptions->noclean = true;
152
153 echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
5fc2f2fd 154
a2b82263 155 if ($editing) {
156 $streditsummary = get_string('editsummary');
157 echo "<a title=\"$streditsummary\" ".
158 " href=\"course/editsection.php?id=$section->id\"><img src=\"$CFG->pixpath/t/edit.gif\" ".
0d905d9f 159 " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
a2b82263 160 }
161
162 get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused);
163 print_section($SITE, $section, $mods, $modnamesused, true);
364fffda 164
a2b82263 165 if ($editing) {
166 print_section_add_menus($SITE, $section->section, $modnames);
167 }
8cef9517 168 print_box_end();
5fc2f2fd 169 }
5fc2f2fd 170 }
171
6f24e48e 172 if (isloggedin() and !isguest() and isset($CFG->frontpageloggedin)) {
173 $frontpagelayout = $CFG->frontpageloggedin;
174 } else {
175 $frontpagelayout = $CFG->frontpage;
176 }
177
178 foreach (explode(',',$frontpagelayout) as $v) {
e1638d61 179 switch ($v) { /// Display the main part of the front page.
220a90c5 180 case FRONTPAGENEWS:
e1638d61 181 if ($SITE->newsitems) { // Print forums only when needed
182 require_once($CFG->dirroot .'/mod/forum/lib.php');
183
184 if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
33aa5723 185 print_error('cannotfindorcreateforum', 'forum');
e1638d61 186 }
187
86a1ba04 188 if (!empty($USER->id)) {
e1638d61 189 $SESSION->fromdiscussion = $CFG->wwwroot;
90f4745c 190 if (forum_is_subscribed($USER->id, $newsforum)) {
e1638d61 191 $subtext = get_string('unsubscribe', 'forum');
192 } else {
193 $subtext = get_string('subscribe', 'forum');
194 }
1c9d49c2 195 print_heading_block($newsforum->name);
196 echo '<div class="subscribelink"><a href="mod/forum/subscribe.php?id='.$newsforum->id.'">'.$subtext.'</a></div>';
af328e4b 197 } else {
1c9d49c2 198 print_heading_block($newsforum->name);
af328e4b 199 }
e1638d61 200
a5a9cd99 201 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
89adb174 202 }
e1638d61 203 break;
89adb174 204
e1638d61 205 case FRONTPAGECOURSELIST:
af328e4b 206
84c8ede0 207 if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) {
e1638d61 208 print_heading_block(get_string('mycourses'));
209 print_my_moodle();
c7da4357 210 } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest()) or ($DB->count_records('course') <= FRONTPAGECOURSELIMIT)) {
fe2920ad 211 // admin should not see list of courses when there are too many of them
e0140f24 212 print_heading_block(get_string('availablecourses'));
5f6b9c09 213 print_courses(0);
89adb174 214 }
e1638d61 215 break;
89adb174 216
e0140f24 217 case FRONTPAGECATEGORYNAMES:
218
219 print_heading_block(get_string('categories'));
986f093f 220 print_box_start('generalbox categorybox');
d157bd5b 221 print_whole_category_list(NULL, NULL, NULL, -1, false);
986f093f 222 print_box_end();
e0140f24 223 print_course_search('', false, 'short');
224 break;
225
6f24e48e 226 case FRONTPAGECATEGORYCOMBO:
227
228 print_heading_block(get_string('categories'));
986f093f 229 print_box_start('generalbox categorybox');
6f24e48e 230 print_whole_category_list(NULL, NULL, NULL, -1, true);
986f093f 231 print_box_end();
6f24e48e 232 print_course_search('', false, 'short');
233 break;
234
e1638d61 235 case FRONTPAGETOPICONLY: // Do nothing!! :-)
236 break;
5eafd948 237
e1638d61 238 }
239 echo '<br />';
89adb174 240 }
241
9f7f1a74 242 print_container_end();
86df6cc6 243
89adb174 244 echo '</td>';
d55c9a1f 245 break;
246 case 'right':
9b4b78fd 247 // The right column
f7016edc 248 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing || $PAGE->user_allowed_editing()) {
e96ba29d 249 echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
9f7f1a74 250 print_container_start();
f7016edc 251 if ($PAGE->user_allowed_editing()) {
535792b2 252 echo '<div style="text-align:center">'.update_course_icon($SITE->id).'</div>';
89adb174 253 echo '<br />';
254 }
66492322 255 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
9f7f1a74 256 print_container_end();
89adb174 257 echo '</td>';
258 }
d55c9a1f 259 break;
260 }
261 }
89adb174 262?>
d887b5a7 263
3565715c 264 </tr>
265</table>
f9903ed0 266
0768842c 267
8c336db1 268<?php
8c336db1 269 print_footer('home'); // Please do not modify this line
b5768b9e 270?>