Added translation of 'lax' : indulgent
[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
7dd82681 119 if(!isset($SESSION) or !isset($SESSION->blockcache) or
120 !isset($SESSION->blockcache->width->{$site->id}) or $editing) {
89adb174 121 // This query might be optimized away if we 're in editing mode
122 if(!isset($recblocks)) {
123 $recblocks = get_records('blocks','visible','1');
124 }
125 $preferred_width_left = blocks_preferred_width($leftblocks, $recblocks);
126 $preferred_width_right = blocks_preferred_width($rightblocks, $recblocks);
ee00b8b9 127
89adb174 128 // This may be kind of organizational overkill, granted...
129 // But is there any real need to simplify the structure?
130 $SESSION->blockcache->width->{$site->id}->left = $preferred_width_left;
131 $SESSION->blockcache->width->{$site->id}->right = $preferred_width_right;
7dd82681 132 } else {
89adb174 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) {
45a6b40d 160 print_simple_box_start('center', '100%', $THEME->cellcontent, 5, 'sitetopic');
5fc2f2fd 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)));
5fc2f2fd 165 echo "<p><font size=2>";
45a6b40d 166 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true\">".get_string("cancel")."</a>)";
5fc2f2fd 167 echo "</font></p>";
5fc2f2fd 168 }
169
5fc2f2fd 170
45a6b40d 171 if (!$section = get_record('course_sections', 'course', $site->id, 'section', 1)) {
172 delete_records('course_sections', 'course', $site->id, 'section', 1); // Just in case
173 $section->course = $site->id;
174 $section->section = 1;
175 $section->summary = '';
176 $section->visible = 1;
177 $section->id = insert_record('course_sections', $section);
178 }
5fc2f2fd 179
45a6b40d 180 echo format_text($section->summary, FORMAT_HTML);
5fc2f2fd 181
182 if ($editing) {
45a6b40d 183 $streditsummary = get_string('editsummary');
5fc2f2fd 184 echo "<a title=\"$streditsummary\" ".
45a6b40d 185 " href=\"course/editsection.php?id=$section->id\"><img src=\"$CFG->pixpath/t/edit.gif\" ".
5fc2f2fd 186 " height=11 width=11 border=0 alt=\"$streditsummary\"></a><br />";
187 }
188
189 echo '<br clear="all">';
190
45a6b40d 191 get_all_mods($site->id, $mods, $modnames, $modnamesplural, $modnamesused);
192 print_section($site, $section, $mods, $modnamesused, true);
5fc2f2fd 193
194 if ($editing) {
720754da 195 print_section_add_menus($site, $section->section, $modnames);
5fc2f2fd 196 }
45a6b40d 197 print_simple_box_end();
198 print_spacer(10);
5fc2f2fd 199 }
200
89adb174 201 switch ($CFG->frontpage) { /// Display the main part of the front page.
202 case FRONTPAGENEWS:
203 if (! $newsforum = forum_get_course_forum($site->id, "news")) {
204 error("Could not find or create a main news forum for the site");
205 }
206
207 if (isset($USER->id)) {
208 $SESSION->fromdiscussion = "$CFG->wwwroot";
209 if (forum_is_subscribed($USER->id, $newsforum->id)) {
210 $subtext = get_string("unsubscribe", "forum");
211 } else {
212 $subtext = get_string("subscribe", "forum");
213 }
214 $headertext = "<table border=0 width=100% cellpadding=0 cellspacing=0 class=headingblockcontent><tr>
215 <td>$newsforum->name</td>
216 <td align=right><font size=1>
217 <a href=\"mod/forum/subscribe.php?id=$newsforum->id\">$subtext</a>
218 </td></tr></table>";
219 } else {
220 $headertext = $newsforum->name;
221 }
222 print_heading_block($headertext);
223 print_spacer(8,1);
224 forum_print_latest_discussions($newsforum->id, $site->newsitems);
225 break;
226
227 case FRONTPAGECOURSELIST:
228 case FRONTPAGECATEGORYNAMES:
229 if (isset($USER->id) and !isset($USER->admin)) {
230 print_heading_block(get_string("mycourses"));
231 print_spacer(8,1);
232 print_my_moodle();
233 } else {
234 if (count_records("course_categories") > 1) {
235 if ($CFG->frontpage == FRONTPAGECOURSELIST) {
236 print_heading_block(get_string("availablecourses"));
237 } else {
238 print_heading_block(get_string("categories"));
239 }
240 print_spacer(8,1);
241 print_simple_box_start("center", "100%");
242 print_whole_category_list();
243 print_simple_box_end();
244 print_course_search("", false, "short");
245 } else {
246 print_heading_block(get_string("availablecourses"));
247 print_spacer(8,1);
248 print_courses(0, "100%");
249 }
250 }
251 break;
252
253 }
254
255 echo '</td>';
256 if(block_have_active($rightblocks) || $editing || isadmin()) {
257 echo '<td style="vertical-align: top; width: '.$preferred_width_right.'px;">';
258 if (isadmin()) {
259 echo '<div align="center">'.update_course_icon($site->id).'</div>';
260 echo '<br />';
261 }
262 print_course_blocks($site, $rightblocks, BLOCK_RIGHT);
263 if ($editing && !empty($missingblocks)) {
6236ed99 264 block_print_blocks_admin($site, $missingblocks);
89adb174 265 }
266 echo '</td>';
267 }
268?>
d887b5a7 269
3565715c 270 </tr>
271</table>
f9903ed0 272
89adb174 273<?PHP print_footer('home'); // Please do not modify this line ?>
f9903ed0 274