Corrected another silly mistake: extra comma before closing parenthesis.
[moodle.git] / index.php
CommitLineData
657423c8 1<?PHP // $Id$
2 // index.php - the front page.
89adb174 3
b0e3a925 4 require_once("config.php");
5 require_once("course/lib.php");
89adb174 6 require_once('lib/blocklib.php');
7 require_once("mod/resource/lib.php");
b0e3a925 8 require_once("mod/forum/lib.php");
f9903ed0 9
8553b700 10 if (! $site = get_site()) {
f33db1ce 11 redirect("$CFG->wwwroot/$CFG->admin/index.php");
f9903ed0 12 }
13
0a45ffe3 14 if ($CFG->forcelogin) {
15 require_login();
16 }
17
53bfe78c 18 if (isadmin()) {
19 if (moodle_needs_upgrading()) {
f33db1ce 20 redirect("$CFG->wwwroot/$CFG->admin/index.php");
53bfe78c 21 }
3565715c 22 }
23
24 if (empty($USER->id)) {
25 $loginstring = "<font size=2><a href=\"$CFG->wwwroot/login/index.php\">".get_string("login")."</a></font>";
4efeb8c3 26 } else {
3565715c 27 $loginstring = "<font size=1>".user_login_string($site)."</font>";
a325bd2b 28 }
a5e3644b 29
984a8bf3 30 if (empty($CFG->langmenu)) {
31 $langmenu = "";
32 } else {
33 $currlang = current_language();
34 $langs = get_list_of_languages();
e6d82585 35 $langmenu = popup_form ("$CFG->wwwroot/index.php?lang=", $langs, "chooselang", $currlang, "", "", "", true);
984a8bf3 36 }
a5e3644b 37
54c1a20c 38 print_header(strip_tags($site->fullname), "$site->fullname", "home", "",
958facf0 39 "<meta name=\"description\" content=\"".s(strip_tags($site->summary))."\">",
a711021a 40 true, "", "$loginstring$langmenu");
f9903ed0 41
89adb174 42 $editing = isediting($site->id);
43
44 $courseformat = COURSE_FORMAT_SITE;
45
46 // Doing this now so we can pass the results to block_action()
47 // and dodge the overhead of doing the same work twice.
19a55d67 48
89adb174 49 $blocks = $site->blockinfo;
50 $delimpos = strpos($blocks, ':');
51
52 if($delimpos === false) {
53 // No ':' found, we have all left blocks
54 $leftblocks = explode(',', $blocks);
55 $rightblocks = array();
56 }
57 else if($delimpos === 0) {
58 // ':' at start of string, we have all right blocks
59 $blocks = substr($blocks, 1);
60 $leftblocks = array();
61 $rightblocks = explode(',', $blocks);
62 }
63 else {
64 // Both left and right blocks
65 $leftpart = substr($blocks, 0, $delimpos);
66 $rightpart = substr($blocks, $delimpos + 1);
67 $leftblocks = explode(',', $leftpart);
68 $rightblocks = explode(',', $rightpart);
ee00b8b9 69 }
70
89adb174 71 if($editing) {
72 if (isset($_GET['blockaction'])) {
73 if (isset($_GET['blockid'])) {
74 block_action($site, $leftblocks, $rightblocks, strtolower($_GET['blockaction']), intval($_GET['blockid']));
75 }
76 }
77
78 // This has to happen after block_action() has possibly updated the two arrays
79 $allblocks = array_merge($leftblocks, $rightblocks);
80
81 $missingblocks = array();
82 $recblocks = get_records('blocks','visible','1');
83
84 // Note down which blocks are going to get displayed
85 blocks_used($allblocks, $recblocks);
86
87 if($editing && $recblocks) {
88 foreach($recblocks as $recblock) {
89 // If it's not hidden or displayed right now...
90 if(!in_array($recblock->id, $allblocks) && !in_array(-($recblock->id), $allblocks)) {
91 // And if it's applicable for display in this format...
92 if(block_method_result($recblock->name, 'applicable_formats') & $courseformat) {
93 // Add it to the missing blocks
94 $missingblocks[] = $recblock->id;
95 }
96 }
97 }
98 }
ee00b8b9 99 }
89adb174 100 else {
101 // Note down which blocks are going to get displayed
102 $allblocks = array_merge($leftblocks, $rightblocks);
103 $recblocks = get_records('blocks','visible','1');
104 blocks_used($allblocks, $recblocks);
105 }
106
107 // If the block width cache is not set, set it
108 if(!isset($SESSION->blockcache->width->{$site->id}) || $editing) {
109 // This query might be optimized away if we 're in editing mode
110 if(!isset($recblocks)) {
111 $recblocks = get_records('blocks','visible','1');
112 }
113 $preferred_width_left = blocks_preferred_width($leftblocks, $recblocks);
114 $preferred_width_right = blocks_preferred_width($rightblocks, $recblocks);
ee00b8b9 115
89adb174 116 // This may be kind of organizational overkill, granted...
117 // But is there any real need to simplify the structure?
118 $SESSION->blockcache->width->{$site->id}->left = $preferred_width_left;
119 $SESSION->blockcache->width->{$site->id}->right = $preferred_width_right;
120 }
121 else {
122 $preferred_width_left = $SESSION->blockcache->width->{$site->id}->left;
123 $preferred_width_right = $SESSION->blockcache->width->{$site->id}->right;
124 }
ee00b8b9 125
f9903ed0 126?>
127
3054741a 128
3565715c 129<table width="100%" border="0" cellspacing="5" cellpadding="5">
130 <tr>
89adb174 131 <?PHP
132
133 if(block_have_active($leftblocks) || $editing) {
134 echo '<td style="vertical-align: top; width: '.$preferred_width_left.'px;">';
135 print_course_blocks($site, $leftblocks, BLOCK_LEFT);
136 echo '</td>';
137 }
138
139 echo '<td style="vertical-align: top;">';
140 switch ($CFG->frontpage) { /// Display the main part of the front page.
141 case FRONTPAGENEWS:
142 if (! $newsforum = forum_get_course_forum($site->id, "news")) {
143 error("Could not find or create a main news forum for the site");
144 }
145
146 if (isset($USER->id)) {
147 $SESSION->fromdiscussion = "$CFG->wwwroot";
148 if (forum_is_subscribed($USER->id, $newsforum->id)) {
149 $subtext = get_string("unsubscribe", "forum");
150 } else {
151 $subtext = get_string("subscribe", "forum");
152 }
153 $headertext = "<table border=0 width=100% cellpadding=0 cellspacing=0 class=headingblockcontent><tr>
154 <td>$newsforum->name</td>
155 <td align=right><font size=1>
156 <a href=\"mod/forum/subscribe.php?id=$newsforum->id\">$subtext</a>
157 </td></tr></table>";
158 } else {
159 $headertext = $newsforum->name;
160 }
161 print_heading_block($headertext);
162 print_spacer(8,1);
163 forum_print_latest_discussions($newsforum->id, $site->newsitems);
164 break;
165
166 case FRONTPAGECOURSELIST:
167 case FRONTPAGECATEGORYNAMES:
168 if (isset($USER->id) and !isset($USER->admin)) {
169 print_heading_block(get_string("mycourses"));
170 print_spacer(8,1);
171 print_my_moodle();
172 } else {
173 if (count_records("course_categories") > 1) {
174 if ($CFG->frontpage == FRONTPAGECOURSELIST) {
175 print_heading_block(get_string("availablecourses"));
176 } else {
177 print_heading_block(get_string("categories"));
178 }
179 print_spacer(8,1);
180 print_simple_box_start("center", "100%");
181 print_whole_category_list();
182 print_simple_box_end();
183 print_course_search("", false, "short");
184 } else {
185 print_heading_block(get_string("availablecourses"));
186 print_spacer(8,1);
187 print_courses(0, "100%");
188 }
189 }
190 break;
191
192 }
193
194 echo '</td>';
195 if(block_have_active($rightblocks) || $editing || isadmin()) {
196 echo '<td style="vertical-align: top; width: '.$preferred_width_right.'px;">';
197 if (isadmin()) {
198 echo '<div align="center">'.update_course_icon($site->id).'</div>';
199 echo '<br />';
200 }
201 print_course_blocks($site, $rightblocks, BLOCK_RIGHT);
202 if ($editing && !empty($missingblocks)) {
203 block_print_blocks_admin($site->id, $missingblocks);
204 }
205 echo '</td>';
206 }
207?>
d887b5a7 208
3565715c 209 </tr>
210</table>
f9903ed0 211
89adb174 212<?PHP print_footer('home'); // Please do not modify this line ?>
f9903ed0 213