Fix for bug 2669:
[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');
4bab5275 16 require_once($CFG->dirroot .'/course/lib.php');
17 require_once($CFG->dirroot .'/lib/blocklib.php');
18 require_once($CFG->dirroot .'/mod/resource/lib.php');
19 require_once($CFG->dirroot .'/mod/forum/lib.php');
f9903ed0 20
78ba4d06 21 if (empty($SITE)) {
4bab5275 22 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
f9903ed0 23 }
24
0a45ffe3 25 if ($CFG->forcelogin) {
26 require_login();
27 }
28
53bfe78c 29 if (isadmin()) {
30 if (moodle_needs_upgrading()) {
4bab5275 31 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
53bfe78c 32 }
3565715c 33 }
34
35 if (empty($USER->id)) {
8a33e371 36 if (empty($CFG->loginhttps)) {
37 $wwwroot = $CFG->wwwroot;
38 } else {
4bab5275 39 $wwwroot = str_replace('http', 'https', $CFG->wwwroot);
8a33e371 40 }
0e18f827 41 $loginstring = "<div class=\"logininfo\"><a href=\"$wwwroot/login/index.php\">".get_string('login').'</a></div>';
4efeb8c3 42 } else {
fd5b9188 43 $loginstring = user_login_string($SITE);
34dd5900 44 add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
a325bd2b 45 }
a5e3644b 46
984a8bf3 47 if (empty($CFG->langmenu)) {
4bab5275 48 $langmenu = '';
984a8bf3 49 } else {
50 $currlang = current_language();
51 $langs = get_list_of_languages();
4bab5275 52 $langmenu = popup_form ($CFG->wwwroot .'/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true);
984a8bf3 53 }
a5e3644b 54
60fe9736 55 $PAGE = page_create_object(PAGE_COURSE_VIEW, SITEID);
3615b2b2 56 $pageblocks = blocks_setup($PAGE);
60fe9736 57 $editing = $PAGE->user_is_editing();
60fe9736 58 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), BLOCK_L_MAX_WIDTH);
59 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]), BLOCK_R_MAX_WIDTH);
df9e0f89 60
78ba4d06 61 print_header(strip_tags($SITE->fullname), $SITE->fullname, 'home', '',
62 '<meta name="description" content="'. s(strip_tags($SITE->summary)) .'" />',
0e18f827 63 true, '', $loginstring.$langmenu);
5921e0a0 64
f9903ed0 65?>
66
3054741a 67
e96ba29d 68<table id="layout-table">
3565715c 69 <tr>
89adb174 70 <?PHP
71
dffd4bb9 72 if(blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
e96ba29d 73 echo '<td style="width: '.$preferred_width_left.'px;" id="left-column">';
66492322 74 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
89adb174 75 echo '</td>';
76 }
77
e96ba29d 78 echo '<td id="middle-column">';
8c336db1 79
80
5fc2f2fd 81/// Print Section
78ba4d06 82 if ($SITE->numsections > 0) {
b5768b9e 83 print_simple_box_start('center', '100%', '', 5, 'sitetopic');
8c336db1 84
5fc2f2fd 85 /// If currently moving a file then show the current clipboard
78ba4d06 86 if (ismoving($SITE->id)) {
4bab5275 87 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname)));
88 echo '<p><font size="2">';
89 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true\">". get_string('cancel') .'</a>)';
90 echo '</font></p>';
5fc2f2fd 91 }
92
5fc2f2fd 93
78ba4d06 94 if (!$section = get_record('course_sections', 'course', $SITE->id, 'section', 1)) {
95 delete_records('course_sections', 'course', $SITE->id, 'section', 1); // Just in case
96 $section->course = $SITE->id;
45a6b40d 97 $section->section = 1;
98 $section->summary = '';
99 $section->visible = 1;
100 $section->id = insert_record('course_sections', $section);
101 }
5fc2f2fd 102
45a6b40d 103 echo format_text($section->summary, FORMAT_HTML);
5fc2f2fd 104
105 if ($editing) {
45a6b40d 106 $streditsummary = get_string('editsummary');
5fc2f2fd 107 echo "<a title=\"$streditsummary\" ".
45a6b40d 108 " href=\"course/editsection.php?id=$section->id\"><img src=\"$CFG->pixpath/t/edit.gif\" ".
dfc12289 109 " height=\"11\" width=\"11\" border=\"0\" alt=\"$streditsummary\" /></a><br /><br />";
5fc2f2fd 110 }
111
78ba4d06 112 get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused);
113 print_section($SITE, $section, $mods, $modnamesused, true);
5fc2f2fd 114
115 if ($editing) {
78ba4d06 116 print_section_add_menus($SITE, $section->section, $modnames);
5fc2f2fd 117 }
45a6b40d 118 print_simple_box_end();
119 print_spacer(10);
5fc2f2fd 120 }
121
89adb174 122 switch ($CFG->frontpage) { /// Display the main part of the front page.
123 case FRONTPAGENEWS:
78ba4d06 124 if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
4bab5275 125 error('Could not find or create a main news forum for the site');
89adb174 126 }
127
128 if (isset($USER->id)) {
4bab5275 129 $SESSION->fromdiscussion = $CFG->wwwroot;
89adb174 130 if (forum_is_subscribed($USER->id, $newsforum->id)) {
4bab5275 131 $subtext = get_string('unsubscribe', 'forum');
89adb174 132 } else {
4bab5275 133 $subtext = get_string('subscribe', 'forum');
89adb174 134 }
98ea2a6e 135 $headertext = "<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" class=\"headingblockcontent\"><tr>
89adb174 136 <td>$newsforum->name</td>
98ea2a6e 137 <td align=\"right\"><font size=\"1\">
89adb174 138 <a href=\"mod/forum/subscribe.php?id=$newsforum->id\">$subtext</a>
139 </td></tr></table>";
140 } else {
141 $headertext = $newsforum->name;
142 }
8c336db1 143
78ba4d06 144 if ($SITE->newsitems) { //print forums only when needed
63fa3f80 145 print_heading_block($headertext);
146 print_spacer(8,1);
78ba4d06 147 forum_print_latest_discussions($newsforum->id, $SITE->newsitems);
8c336db1 148 }
89adb174 149 break;
150
151 case FRONTPAGECOURSELIST:
152 case FRONTPAGECATEGORYNAMES:
153 if (isset($USER->id) and !isset($USER->admin)) {
4bab5275 154 print_heading_block(get_string('mycourses'));
89adb174 155 print_spacer(8,1);
156 print_my_moodle();
157 } else {
4bab5275 158 if (count_records('course_categories') > 1) {
89adb174 159 if ($CFG->frontpage == FRONTPAGECOURSELIST) {
4bab5275 160 print_heading_block(get_string('availablecourses'));
89adb174 161 } else {
4bab5275 162 print_heading_block(get_string('categories'));
89adb174 163 }
164 print_spacer(8,1);
4bab5275 165 print_simple_box_start('center', '100%');
89adb174 166 print_whole_category_list();
167 print_simple_box_end();
4bab5275 168 print_course_search('', false, 'short');
89adb174 169 } else {
4bab5275 170 print_heading_block(get_string('availablecourses'));
89adb174 171 print_spacer(8,1);
4bab5275 172 print_courses(0, '100%');
89adb174 173 }
174 }
175 break;
176
177 }
178
179 echo '</td>';
9b4b78fd 180
181
182 // The right column
dffd4bb9 183 if(blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing || isadmin()) {
e96ba29d 184 echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
89adb174 185 if (isadmin()) {
78ba4d06 186 echo '<div align="center">'.update_course_icon($SITE->id).'</div>';
89adb174 187 echo '<br />';
188 }
66492322 189 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
89adb174 190 echo '</td>';
191 }
192?>
d887b5a7 193
3565715c 194 </tr>
195</table>
f9903ed0 196
8c336db1 197<?php
8c336db1 198 print_footer('home'); // Please do not modify this line
b5768b9e 199?>