Polished, new files added.
[moodle.git] / index.php
CommitLineData
657423c8 1<?PHP // $Id$
2 // index.php - the front page.
89adb174 3
df9e0f89 4 // Bounds for block widths
5 define('BLOCK_L_MIN_WIDTH', 160);
6 define('BLOCK_L_MAX_WIDTH', 210);
7 define('BLOCK_R_MIN_WIDTH', 160);
8 define('BLOCK_R_MAX_WIDTH', 210);
9
b0e3a925 10 require_once("config.php");
11 require_once("course/lib.php");
89adb174 12 require_once('lib/blocklib.php');
13 require_once("mod/resource/lib.php");
b0e3a925 14 require_once("mod/forum/lib.php");
f9903ed0 15
8553b700 16 if (! $site = get_site()) {
f33db1ce 17 redirect("$CFG->wwwroot/$CFG->admin/index.php");
f9903ed0 18 }
19
0a45ffe3 20 if ($CFG->forcelogin) {
21 require_login();
22 }
23
53bfe78c 24 if (isadmin()) {
25 if (moodle_needs_upgrading()) {
f33db1ce 26 redirect("$CFG->wwwroot/$CFG->admin/index.php");
53bfe78c 27 }
3565715c 28 }
29
30 if (empty($USER->id)) {
8a33e371 31 if (empty($CFG->loginhttps)) {
32 $wwwroot = $CFG->wwwroot;
33 } else {
34 $wwwroot = str_replace('http','https',$CFG->wwwroot);
35 }
36 $loginstring = "<font size=2><a href=\"$wwwroot/login/index.php\">".get_string("login")."</a></font>";
4efeb8c3 37 } else {
3565715c 38 $loginstring = "<font size=1>".user_login_string($site)."</font>";
a325bd2b 39 }
a5e3644b 40
984a8bf3 41 if (empty($CFG->langmenu)) {
42 $langmenu = "";
43 } else {
44 $currlang = current_language();
45 $langs = get_list_of_languages();
e6d82585 46 $langmenu = popup_form ("$CFG->wwwroot/index.php?lang=", $langs, "chooselang", $currlang, "", "", "", true);
984a8bf3 47 }
a5e3644b 48
54c1a20c 49 print_header(strip_tags($site->fullname), "$site->fullname", "home", "",
958facf0 50 "<meta name=\"description\" content=\"".s(strip_tags($site->summary))."\">",
a711021a 51 true, "", "$loginstring$langmenu");
f9903ed0 52
89adb174 53 $editing = isediting($site->id);
54
55 $courseformat = COURSE_FORMAT_SITE;
56
57 // Doing this now so we can pass the results to block_action()
58 // and dodge the overhead of doing the same work twice.
19a55d67 59
89adb174 60 $blocks = $site->blockinfo;
61 $delimpos = strpos($blocks, ':');
62
63 if($delimpos === false) {
64 // No ':' found, we have all left blocks
65 $leftblocks = explode(',', $blocks);
66 $rightblocks = array();
67 }
68 else if($delimpos === 0) {
69 // ':' at start of string, we have all right blocks
70 $blocks = substr($blocks, 1);
71 $leftblocks = array();
72 $rightblocks = explode(',', $blocks);
73 }
74 else {
75 // Both left and right blocks
76 $leftpart = substr($blocks, 0, $delimpos);
77 $rightpart = substr($blocks, $delimpos + 1);
78 $leftblocks = explode(',', $leftpart);
79 $rightblocks = explode(',', $rightpart);
ee00b8b9 80 }
81
89adb174 82 if($editing) {
83 if (isset($_GET['blockaction'])) {
84 if (isset($_GET['blockid'])) {
85 block_action($site, $leftblocks, $rightblocks, strtolower($_GET['blockaction']), intval($_GET['blockid']));
86 }
87 }
88
89 // This has to happen after block_action() has possibly updated the two arrays
90 $allblocks = array_merge($leftblocks, $rightblocks);
91
92 $missingblocks = array();
93 $recblocks = get_records('blocks','visible','1');
94
95 // Note down which blocks are going to get displayed
96 blocks_used($allblocks, $recblocks);
97
98 if($editing && $recblocks) {
99 foreach($recblocks as $recblock) {
100 // If it's not hidden or displayed right now...
101 if(!in_array($recblock->id, $allblocks) && !in_array(-($recblock->id), $allblocks)) {
102 // And if it's applicable for display in this format...
103 if(block_method_result($recblock->name, 'applicable_formats') & $courseformat) {
104 // Add it to the missing blocks
105 $missingblocks[] = $recblock->id;
106 }
107 }
108 }
109 }
ee00b8b9 110 }
89adb174 111 else {
112 // Note down which blocks are going to get displayed
113 $allblocks = array_merge($leftblocks, $rightblocks);
114 $recblocks = get_records('blocks','visible','1');
115 blocks_used($allblocks, $recblocks);
116 }
117
118 // If the block width cache is not set, set it
119 if(!isset($SESSION->blockcache->width->{$site->id}) || $editing) {
120 // This query might be optimized away if we 're in editing mode
121 if(!isset($recblocks)) {
122 $recblocks = get_records('blocks','visible','1');
123 }
124 $preferred_width_left = blocks_preferred_width($leftblocks, $recblocks);
125 $preferred_width_right = blocks_preferred_width($rightblocks, $recblocks);
ee00b8b9 126
89adb174 127 // This may be kind of organizational overkill, granted...
128 // But is there any real need to simplify the structure?
129 $SESSION->blockcache->width->{$site->id}->left = $preferred_width_left;
130 $SESSION->blockcache->width->{$site->id}->right = $preferred_width_right;
131 }
132 else {
133 $preferred_width_left = $SESSION->blockcache->width->{$site->id}->left;
134 $preferred_width_right = $SESSION->blockcache->width->{$site->id}->right;
135 }
ee00b8b9 136
df9e0f89 137 $preferred_width_left = min($preferred_width_left, BLOCK_L_MAX_WIDTH);
138 $preferred_width_left = max($preferred_width_left, BLOCK_L_MIN_WIDTH);
139 $preferred_width_right = min($preferred_width_right, BLOCK_R_MAX_WIDTH);
140 $preferred_width_right = max($preferred_width_right, BLOCK_R_MIN_WIDTH);
141
f9903ed0 142?>
143
3054741a 144
3565715c 145<table width="100%" border="0" cellspacing="5" cellpadding="5">
146 <tr>
89adb174 147 <?PHP
148
149 if(block_have_active($leftblocks) || $editing) {
150 echo '<td style="vertical-align: top; width: '.$preferred_width_left.'px;">';
151 print_course_blocks($site, $leftblocks, BLOCK_LEFT);
152 echo '</td>';
153 }
154
155 echo '<td style="vertical-align: top;">';
5fc2f2fd 156
157
158/// Print Section
159 if ($site->numsections > 0) {
160 echo "<table class=\"topicsoutline\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\" width=\"100%\">";
161
162 /// If currently moving a file then show the current clipboard
163 if (ismoving($site->id)) {
164 $stractivityclipboard = strip_tags(get_string("activityclipboard", "", addslashes($USER->activitycopyname)));
165 $strcancel= get_string("cancel");
166 echo "<tr>";
167 echo "<td colspan=3 valign=top bgcolor=\"$THEME->cellcontent\" class=\"topicoutlineclip\" width=\"100%\">";
168 echo "<p><font size=2>";
169 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true\">$strcancel</a>)";
170 echo "</font></p>";
171 echo "</td>";
172 echo "</tr>";
173 echo "<tr><td colspan=3><img src=\"pix/spacer.gif\" width=1 height=1></td></tr>";
174 }
175
176 $streditsummary = get_string("editsummary");
177 $stradd = get_string("add");
178 $stractivities = get_string("activities");
179
180 $sections = get_all_sections($site->id);
181 get_all_mods($site->id, $mods, $modnames, $modnamesplural, $modnamesused);
182 $section = 0;
183 $thissection = $sections[$section];
184
185 echo '<tr id="section_0">';
186 echo "<td nowrap bgcolor=\"$THEME->cellheading\" class=\"topicsoutlineside\" valign=top width=20>&nbsp;</td>";
187 echo "<td valign=top bgcolor=\"$THEME->cellcontent\" class=\"topicsoutlinecontent\" width=\"100%\">";
188
189 echo format_text($thissection->summary, FORMAT_HTML);
190
191 if ($editing) {
192 echo "<a title=\"$streditsummary\" ".
193 " href=\"course/editsection.php?id=$thissection->id\"><img src=\"$CFG->pixpath/t/edit.gif\" ".
194 " height=11 width=11 border=0 alt=\"$streditsummary\"></a><br />";
195 }
196
197 echo '<br clear="all">';
198
199 print_section($site, $thissection, $mods, $modnamesused, true);
200
201 if ($editing) {
202 echo "<div align=right>";
203 popup_form("$CFG->wwwroot/course/mod.php?id=$site->id&amp;section=$section&add=",
204 $modnames, "section", "", "$stradd...", "mods", $stractivities);
205 echo "</div>";
206 }
207
208 echo "</td>";
209 echo "<td nowrap bgcolor=\"$THEME->cellheading\" class=\"topicsoutlineside\" valign=top align=center width=10>";
210 echo "&nbsp;</td></tr>";
211 echo "<tr><td colspan=3><img src=\"pix/spacer.gif\" width=1 height=1></td></tr>";
212 echo '</table>';
213 }
214
89adb174 215 switch ($CFG->frontpage) { /// Display the main part of the front page.
216 case FRONTPAGENEWS:
217 if (! $newsforum = forum_get_course_forum($site->id, "news")) {
218 error("Could not find or create a main news forum for the site");
219 }
220
221 if (isset($USER->id)) {
222 $SESSION->fromdiscussion = "$CFG->wwwroot";
223 if (forum_is_subscribed($USER->id, $newsforum->id)) {
224 $subtext = get_string("unsubscribe", "forum");
225 } else {
226 $subtext = get_string("subscribe", "forum");
227 }
228 $headertext = "<table border=0 width=100% cellpadding=0 cellspacing=0 class=headingblockcontent><tr>
229 <td>$newsforum->name</td>
230 <td align=right><font size=1>
231 <a href=\"mod/forum/subscribe.php?id=$newsforum->id\">$subtext</a>
232 </td></tr></table>";
233 } else {
234 $headertext = $newsforum->name;
235 }
236 print_heading_block($headertext);
237 print_spacer(8,1);
238 forum_print_latest_discussions($newsforum->id, $site->newsitems);
239 break;
240
241 case FRONTPAGECOURSELIST:
242 case FRONTPAGECATEGORYNAMES:
243 if (isset($USER->id) and !isset($USER->admin)) {
244 print_heading_block(get_string("mycourses"));
245 print_spacer(8,1);
246 print_my_moodle();
247 } else {
248 if (count_records("course_categories") > 1) {
249 if ($CFG->frontpage == FRONTPAGECOURSELIST) {
250 print_heading_block(get_string("availablecourses"));
251 } else {
252 print_heading_block(get_string("categories"));
253 }
254 print_spacer(8,1);
255 print_simple_box_start("center", "100%");
256 print_whole_category_list();
257 print_simple_box_end();
258 print_course_search("", false, "short");
259 } else {
260 print_heading_block(get_string("availablecourses"));
261 print_spacer(8,1);
262 print_courses(0, "100%");
263 }
264 }
265 break;
266
267 }
268
269 echo '</td>';
270 if(block_have_active($rightblocks) || $editing || isadmin()) {
271 echo '<td style="vertical-align: top; width: '.$preferred_width_right.'px;">';
272 if (isadmin()) {
273 echo '<div align="center">'.update_course_icon($site->id).'</div>';
274 echo '<br />';
275 }
276 print_course_blocks($site, $rightblocks, BLOCK_RIGHT);
277 if ($editing && !empty($missingblocks)) {
6236ed99 278 block_print_blocks_admin($site, $missingblocks);
89adb174 279 }
280 echo '</td>';
281 }
282?>
d887b5a7 283
3565715c 284 </tr>
285</table>
f9903ed0 286
89adb174 287<?PHP print_footer('home'); // Please do not modify this line ?>
f9903ed0 288