Fix a possible race condition in the PaintWeb DML code.
[moodle/mihaisucan.git] / index.php
blob24bc1d3b05d6eb38b72161dccf3b2bd10ac45a21
1 <?php // $Id$
2 // index.php - the front page.
4 ///////////////////////////////////////////////////////////////////////////
5 // //
6 // NOTICE OF COPYRIGHT //
7 // //
8 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
9 // http://moodle.org //
10 // //
11 // Copyright (C) 1999 onwards 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 ///////////////////////////////////////////////////////////////////////////
28 if (!file_exists('./config.php')) {
29 header('Location: install.php');
30 die;
33 require_once('config.php');
34 require_once($CFG->dirroot .'/course/lib.php');
35 require_once($CFG->dirroot .'/lib/blocklib.php');
37 if (empty($SITE)) {
38 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
41 // Bounds for block widths
42 // more flexible for theme designers taken from theme config.php
43 $lmin = (empty($THEME->block_l_min_width)) ? 100 : $THEME->block_l_min_width;
44 $lmax = (empty($THEME->block_l_max_width)) ? 210 : $THEME->block_l_max_width;
45 $rmin = (empty($THEME->block_r_min_width)) ? 100 : $THEME->block_r_min_width;
46 $rmax = (empty($THEME->block_r_max_width)) ? 210 : $THEME->block_r_max_width;
48 define('BLOCK_L_MIN_WIDTH', $lmin);
49 define('BLOCK_L_MAX_WIDTH', $lmax);
50 define('BLOCK_R_MIN_WIDTH', $rmin);
51 define('BLOCK_R_MAX_WIDTH', $rmax);
53 // check if major upgrade needed - also present in login/index.php
54 if ((int)$CFG->version < 2006101100) { //1.7 or older
55 @require_logout();
56 redirect("$CFG->wwwroot/$CFG->admin/");
58 // Trigger 1.9 accesslib upgrade?
59 if ((int)$CFG->version < 2007092000
60 && isset($USER->id)
61 && is_siteadmin($USER->id)) { // this test is expensive, but is only triggered during the upgrade
62 redirect("$CFG->wwwroot/$CFG->admin/");
65 if ($CFG->forcelogin) {
66 require_login();
67 } else {
68 user_accesstime_log();
71 if ($CFG->rolesactive) { // if already using roles system
72 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
73 if (moodle_needs_upgrading()) {
74 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
76 } else if (!empty($CFG->mymoodleredirect)) { // Redirect logged-in users to My Moodle overview if required
77 if (isloggedin() && $USER->username != 'guest') {
78 redirect($CFG->wwwroot .'/my/index.php');
81 } else { // if upgrading from 1.6 or below
82 if (isadmin() && moodle_needs_upgrading()) {
83 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
88 if (get_moodle_cookie() == '') {
89 set_moodle_cookie('nobody'); // To help search for cookies on login page
92 if (!empty($USER->id)) {
93 add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
96 if (empty($CFG->langmenu)) {
97 $langmenu = '';
98 } else {
99 $currlang = current_language();
100 $langs = get_list_of_languages();
101 $langlabel = get_accesshide(get_string('language'));
102 $langmenu = popup_form($CFG->wwwroot .'/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true, 'self', $langlabel);
105 $PAGE = page_create_object(PAGE_COURSE_VIEW, SITEID);
106 $pageblocks = blocks_setup($PAGE);
107 $editing = $PAGE->user_is_editing();
108 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
109 BLOCK_L_MAX_WIDTH);
110 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
111 BLOCK_R_MAX_WIDTH);
112 print_header($SITE->fullname, $SITE->fullname, 'home', '',
113 '<meta name="description" content="'. strip_tags(format_text($SITE->summary, FORMAT_HTML)) .'" />',
114 true, '', user_login_string($SITE).$langmenu);
119 <table id="layout-table" summary="layout">
120 <tr>
121 <?php
122 $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
123 foreach ($lt as $column) {
124 switch ($column) {
125 case 'left':
126 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
127 echo '<td style="width: '.$preferred_width_left.'px;" id="left-column">';
128 print_container_start();
129 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
130 print_container_end();
131 echo '</td>';
133 break;
134 case 'middle':
135 echo '<td id="middle-column">'. skip_main_destination();
137 print_container_start();
139 /// Print Section
140 if ($SITE->numsections > 0) {
142 if (!$section = get_record('course_sections', 'course', $SITE->id, 'section', 1)) {
143 delete_records('course_sections', 'course', $SITE->id, 'section', 1); // Just in case
144 $section->course = $SITE->id;
145 $section->section = 1;
146 $section->summary = '';
147 $section->sequence = '';
148 $section->visible = 1;
149 $section->id = insert_record('course_sections', $section);
152 if (!empty($section->sequence) or !empty($section->summary) or $editing) {
153 print_box_start('generalbox sitetopic');
155 /// If currently moving a file then show the current clipboard
156 if (ismoving($SITE->id)) {
157 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname)));
158 echo '<p><font size="2">';
159 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=$USER->sesskey\">". get_string('cancel') .'</a>)';
160 echo '</font></p>';
163 $options = NULL;
164 $options->noclean = true;
165 echo format_text($section->summary, FORMAT_HTML, $options);
167 if ($editing) {
168 $streditsummary = get_string('editsummary');
169 echo "<a title=\"$streditsummary\" ".
170 " href=\"course/editsection.php?id=$section->id\"><img src=\"$CFG->pixpath/t/edit.gif\" ".
171 " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
174 get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused);
175 print_section($SITE, $section, $mods, $modnamesused, true);
177 if ($editing) {
178 print_section_add_menus($SITE, $section->section, $modnames);
180 print_box_end();
184 if (isloggedin() and !isguest() and isset($CFG->frontpageloggedin)) {
185 $frontpagelayout = $CFG->frontpageloggedin;
186 } else {
187 $frontpagelayout = $CFG->frontpage;
190 foreach (explode(',',$frontpagelayout) as $v) {
191 switch ($v) { /// Display the main part of the front page.
192 case FRONTPAGENEWS:
193 if ($SITE->newsitems) { // Print forums only when needed
194 require_once($CFG->dirroot .'/mod/forum/lib.php');
196 if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
197 error('Could not find or create a main news forum for the site');
200 if (!empty($USER->id)) {
201 $SESSION->fromdiscussion = $CFG->wwwroot;
202 $subtext = '';
203 if (forum_is_subscribed($USER->id, $newsforum)) {
204 if (!forum_is_forcesubscribed($newsforum)) {
205 $subtext = get_string('unsubscribe', 'forum');
207 } else {
208 $subtext = get_string('subscribe', 'forum');
210 print_heading_block($newsforum->name);
211 echo '<div class="subscribelink"><a href="mod/forum/subscribe.php?id='.$newsforum->id.'">'.$subtext.'</a></div>';
212 } else {
213 print_heading_block($newsforum->name);
216 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
218 break;
220 case FRONTPAGECOURSELIST:
222 if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) {
223 print_heading_block(get_string('mycourses'));
224 print_my_moodle();
225 } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest()) or (count_records('course') <= FRONTPAGECOURSELIMIT)) {
226 // admin should not see list of courses when there are too many of them
227 print_heading_block(get_string('availablecourses'));
228 print_courses(0);
230 break;
232 case FRONTPAGECATEGORYNAMES:
234 print_heading_block(get_string('categories'));
235 print_box_start('generalbox categorybox');
236 print_whole_category_list(NULL, NULL, NULL, -1, false);
237 print_box_end();
238 print_course_search('', false, 'short');
239 break;
241 case FRONTPAGECATEGORYCOMBO:
243 print_heading_block(get_string('categories'));
244 print_box_start('generalbox categorybox');
245 print_whole_category_list(NULL, NULL, NULL, -1, true);
246 print_box_end();
247 print_course_search('', false, 'short');
248 break;
250 case FRONTPAGETOPICONLY: // Do nothing!! :-)
251 break;
254 echo '<br />';
257 print_container_end();
259 echo '</td>';
260 break;
261 case 'right':
262 // The right column
263 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing || $PAGE->user_allowed_editing()) {
264 echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
265 print_container_start();
266 if ($PAGE->user_allowed_editing()) {
267 echo '<div style="text-align:center">'.update_course_icon($SITE->id).'</div>';
268 echo '<br />';
270 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
271 print_container_end();
272 echo '</td>';
274 break;
279 </tr>
280 </table>
282 <?php
283 print_footer('home'); // Please do not modify this line