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