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