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