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