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