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