merged fix on wrong counter
[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// //
11// Copyright (C) 1999-2999 Martin Dougiamas http://moodle.com //
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
33/// Bounds for block widths on this page
df9e0f89 34 define('BLOCK_L_MIN_WIDTH', 160);
35 define('BLOCK_L_MAX_WIDTH', 210);
36 define('BLOCK_R_MIN_WIDTH', 160);
37 define('BLOCK_R_MAX_WIDTH', 210);
38
8deb0ff5 39 require_once('config.php');
07b11e4f 40 require_once($CFG->dirroot .'/course/lib.php');
4bab5275 41 require_once($CFG->dirroot .'/lib/blocklib.php');
f9903ed0 42
78ba4d06 43 if (empty($SITE)) {
4bab5275 44 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
f9903ed0 45 }
46
0a45ffe3 47 if ($CFG->forcelogin) {
48 require_login();
49 }
50
89948e45 51 if ($CFG->rolesactive) { // if already using roles system
52 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
53 if (moodle_needs_upgrading()) {
54 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
55 }
56 }
57 } else { // if upgrading from 1.6 or below
58 if (isadmin() && moodle_needs_upgrading()) {
4bab5275 59 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
53bfe78c 60 }
3565715c 61 }
62
9f9e3576 63 if (get_moodle_cookie() == '') {
64 set_moodle_cookie('nobody'); // To help search for cookies on login page
65 }
66
c44d5d42 67 if (!empty($USER->id)) {
34dd5900 68 add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
a325bd2b 69 }
a5e3644b 70
984a8bf3 71 if (empty($CFG->langmenu)) {
4bab5275 72 $langmenu = '';
984a8bf3 73 } else {
74 $currlang = current_language();
75 $langs = get_list_of_languages();
4bab5275 76 $langmenu = popup_form ($CFG->wwwroot .'/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true);
984a8bf3 77 }
a5e3644b 78
60fe9736 79 $PAGE = page_create_object(PAGE_COURSE_VIEW, SITEID);
3615b2b2 80 $pageblocks = blocks_setup($PAGE);
60fe9736 81 $editing = $PAGE->user_is_editing();
af328e4b 82 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
83 BLOCK_L_MAX_WIDTH);
84 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
85 BLOCK_R_MAX_WIDTH);
df9e0f89 86
78ba4d06 87 print_header(strip_tags($SITE->fullname), $SITE->fullname, 'home', '',
88 '<meta name="description" content="'. s(strip_tags($SITE->summary)) .'" />',
c44d5d42 89 true, '', user_login_string($SITE).$langmenu);
5921e0a0 90
f9903ed0 91?>
92
3054741a 93
e96ba29d 94<table id="layout-table">
3565715c 95 <tr>
af328e4b 96 <?php
89adb174 97
af328e4b 98 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
e96ba29d 99 echo '<td style="width: '.$preferred_width_left.'px;" id="left-column">';
66492322 100 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
89adb174 101 echo '</td>';
102 }
103
e96ba29d 104 echo '<td id="middle-column">';
8c336db1 105
106
5fc2f2fd 107/// Print Section
78ba4d06 108 if ($SITE->numsections > 0) {
5fc2f2fd 109
78ba4d06 110 if (!$section = get_record('course_sections', 'course', $SITE->id, 'section', 1)) {
111 delete_records('course_sections', 'course', $SITE->id, 'section', 1); // Just in case
112 $section->course = $SITE->id;
45a6b40d 113 $section->section = 1;
114 $section->summary = '';
a2b82263 115 $section->sequence = '';
45a6b40d 116 $section->visible = 1;
117 $section->id = insert_record('course_sections', $section);
118 }
5fc2f2fd 119
a2b82263 120 if (!empty($section->sequence) or !empty($section->summary) or $editing) {
121 print_simple_box_start('center', '100%', '', 5, 'sitetopic');
5fc2f2fd 122
a2b82263 123 /// If currently moving a file then show the current clipboard
124 if (ismoving($SITE->id)) {
125 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname)));
126 echo '<p><font size="2">';
e9c99674 127 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=$USER->sesskey\">". get_string('cancel') .'</a>)';
a2b82263 128 echo '</font></p>';
129 }
5fc2f2fd 130
73e95f22 131 $options = NULL;
132 $options->noclean = true;
133 echo format_text($section->summary, FORMAT_HTML, $options);
5fc2f2fd 134
a2b82263 135 if ($editing) {
136 $streditsummary = get_string('editsummary');
137 echo "<a title=\"$streditsummary\" ".
138 " href=\"course/editsection.php?id=$section->id\"><img src=\"$CFG->pixpath/t/edit.gif\" ".
139 " height=\"11\" width=\"11\" border=\"0\" alt=\"$streditsummary\" /></a><br /><br />";
140 }
141
142 get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused);
143 print_section($SITE, $section, $mods, $modnamesused, true);
144
145 if ($editing) {
146 print_section_add_menus($SITE, $section->section, $modnames);
147 }
148 print_simple_box_end();
5fc2f2fd 149 }
5fc2f2fd 150 }
151
6f24e48e 152 if (isloggedin() and !isguest() and isset($CFG->frontpageloggedin)) {
153 $frontpagelayout = $CFG->frontpageloggedin;
154 } else {
155 $frontpagelayout = $CFG->frontpage;
156 }
157
158 foreach (explode(',',$frontpagelayout) as $v) {
e1638d61 159 switch ($v) { /// Display the main part of the front page.
160 case strval(FRONTPAGENEWS):
161 if ($SITE->newsitems) { // Print forums only when needed
162 require_once($CFG->dirroot .'/mod/forum/lib.php');
163
164 if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
165 error('Could not find or create a main news forum for the site');
166 }
167
86a1ba04 168 if (!empty($USER->id)) {
e1638d61 169 $SESSION->fromdiscussion = $CFG->wwwroot;
170 if (forum_is_subscribed($USER->id, $newsforum->id)) {
171 $subtext = get_string('unsubscribe', 'forum');
172 } else {
173 $subtext = get_string('subscribe', 'forum');
174 }
175 $headertext = '<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr>'.
176 '<td><div class="title">'.$newsforum->name.'</div></td>'.
177 '<td><div class="link"><a href="mod/forum/subscribe.php?id='.$newsforum->id.'">'.$subtext.'</a></div></td>'.
178 '</tr></table>';
af328e4b 179 } else {
e1638d61 180 $headertext = $newsforum->name;
af328e4b 181 }
e1638d61 182
183 print_heading_block($headertext);
a5a9cd99 184 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
89adb174 185 }
e1638d61 186 break;
89adb174 187
e1638d61 188 case FRONTPAGECOURSELIST:
af328e4b 189
51792df0 190 if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID)) and !isguest() and empty($CFG->disablemycourses)) {
e1638d61 191 print_heading_block(get_string('mycourses'));
192 print_my_moodle();
51792df0 193 } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID)) and !isguest()) or (count_records('course') <= FRONTPAGECOURSELIMIT)) {
fe2920ad 194 // admin should not see list of courses when there are too many of them
e0140f24 195 print_heading_block(get_string('availablecourses'));
8e227aa7 196 print_courses(0, '100%', true);
89adb174 197 }
e1638d61 198 break;
89adb174 199
e0140f24 200 case FRONTPAGECATEGORYNAMES:
201
202 print_heading_block(get_string('categories'));
203 print_simple_box_start('center', '100%', '', 5, 'categorybox');
d157bd5b 204 print_whole_category_list(NULL, NULL, NULL, -1, false);
e0140f24 205 print_simple_box_end();
206 print_course_search('', false, 'short');
207 break;
208
6f24e48e 209 case FRONTPAGECATEGORYCOMBO:
210
211 print_heading_block(get_string('categories'));
212 print_simple_box_start('center', '100%', '', 5, 'categorybox');
213 print_whole_category_list(NULL, NULL, NULL, -1, true);
214 print_simple_box_end();
215 print_course_search('', false, 'short');
216 break;
217
e1638d61 218 case FRONTPAGETOPICONLY: // Do nothing!! :-)
219 break;
5eafd948 220
e1638d61 221 }
222 echo '<br />';
89adb174 223 }
224
225 echo '</td>';
9b4b78fd 226
9b4b78fd 227 // The right column
51792df0 228 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing || has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
e96ba29d 229 echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
51792df0 230 if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
78ba4d06 231 echo '<div align="center">'.update_course_icon($SITE->id).'</div>';
89adb174 232 echo '<br />';
233 }
66492322 234 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
89adb174 235 echo '</td>';
236 }
237?>
d887b5a7 238
3565715c 239 </tr>
240</table>
f9903ed0 241
8c336db1 242<?php
8c336db1 243 print_footer('home'); // Please do not modify this line
b5768b9e 244?>