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