MDL-8898
[moodle-linuxchix.git] / index.php
blobcd1b5d84b9fc7bdc95713dc05230d8b439330732
1 <?php // $Id$
2 // index.php - the front page.
4 ///////////////////////////////////////////////////////////////////////////
5 // //
6 // NOTICE OF COPYRIGHT //
7 // //
8 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
9 // http://moodle.org //
10 // //
11 // Copyright (C) 1999-2999 Martin Dougiamas http://moodle.com //
12 // //
13 // This program is free software; you can redistribute it and/or modify //
14 // it under the terms of the GNU General Public License as published by //
15 // the Free Software Foundation; either version 2 of the License, or //
16 // (at your option) any later version. //
17 // //
18 // This program is distributed in the hope that it will be useful, //
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
21 // GNU General Public License for more details: //
22 // //
23 // http://www.gnu.org/copyleft/gpl.html //
24 // //
25 ///////////////////////////////////////////////////////////////////////////
28 if (!file_exists('./config.php')) {
29 header('Location: install.php');
30 die;
33 require_once('config.php');
34 require_once($CFG->dirroot .'/course/lib.php');
35 require_once($CFG->dirroot .'/lib/blocklib.php');
37 if (empty($SITE)) {
38 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
41 // Bounds for block widths
42 // more flexible for theme designers taken from theme config.php
43 $lmin = (empty($THEME->block_l_min_width)) ? 100 : $THEME->block_l_min_width;
44 $lmax = (empty($THEME->block_l_max_width)) ? 210 : $THEME->block_l_max_width;
45 $rmin = (empty($THEME->block_r_min_width)) ? 100 : $THEME->block_r_min_width;
46 $rmax = (empty($THEME->block_r_max_width)) ? 210 : $THEME->block_r_max_width;
48 define('BLOCK_L_MIN_WIDTH', $lmin);
49 define('BLOCK_L_MAX_WIDTH', $lmax);
50 define('BLOCK_R_MIN_WIDTH', $rmin);
51 define('BLOCK_R_MAX_WIDTH', $rmax);
53 // check if major upgrade needed - also present in login/index.php
54 if ((int)$CFG->version < 2006101100) { //1.7 or older
55 @require_logout();
56 redirect("$CFG->wwwroot/$CFG->admin/");
59 if ($CFG->forcelogin) {
60 require_login();
63 if ($CFG->rolesactive) { // if already using roles system
64 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
65 if (moodle_needs_upgrading()) {
66 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
68 } else if (!empty($CFG->mymoodleredirect)) { // Redirect logged-in users to My Moodle overview if required
69 if (isloggedin() && $USER->username != 'guest') {
70 redirect($CFG->wwwroot .'/my/index.php');
73 } else { // if upgrading from 1.6 or below
74 if (isadmin() && moodle_needs_upgrading()) {
75 redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
80 if (get_moodle_cookie() == '') {
81 set_moodle_cookie('nobody'); // To help search for cookies on login page
84 if (!empty($USER->id)) {
85 add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
88 if (empty($CFG->langmenu)) {
89 $langmenu = '';
90 } else {
91 $currlang = current_language();
92 $langs = get_list_of_languages();
93 $langlabel = '<span class="accesshide">'.get_string('language').':</span>';
94 $langmenu = popup_form($CFG->wwwroot .'/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true, 'self', $langlabel);
97 $PAGE = page_create_object(PAGE_COURSE_VIEW, SITEID);
98 $pageblocks = blocks_setup($PAGE);
99 $editing = $PAGE->user_is_editing();
100 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
101 BLOCK_L_MAX_WIDTH);
102 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
103 BLOCK_R_MAX_WIDTH);
105 print_header(strip_tags($SITE->fullname), $SITE->fullname, 'home', '',
106 '<meta name="description" content="'. s(strip_tags($SITE->summary)) .'" />',
107 true, '', user_login_string($SITE).$langmenu);
112 <table id="layout-table" summary="layout">
113 <tr>
114 <?php
115 $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
116 foreach ($lt as $column) {
117 switch ($column) {
118 case 'left':
119 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
120 echo '<td style="width: '.$preferred_width_left.'px;" id="left-column">';
121 if (!empty($THEME->roundcorners)) {
122 echo '<div class="bt"><div></div></div>';
123 echo '<div class="i1"><div class="i2"><div class="i3">';
125 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
126 if (!empty($THEME->roundcorners)) {
127 echo '</div></div></div>';
128 echo '<div class="bb"><div></div></div>';
130 echo '</td>';
132 break;
133 case 'middle':
134 echo '<td id="middle-column">';
136 if (!empty($THEME->roundcorners)) {
137 echo '<div class="bt"><div></div></div>';
138 echo '<div class="i1"><div class="i2"><div class="i3">';
141 /// Print Section
142 if ($SITE->numsections > 0) {
144 if (!$section = get_record('course_sections', 'course', $SITE->id, 'section', 1)) {
145 delete_records('course_sections', 'course', $SITE->id, 'section', 1); // Just in case
146 $section->course = $SITE->id;
147 $section->section = 1;
148 $section->summary = '';
149 $section->sequence = '';
150 $section->visible = 1;
151 $section->id = insert_record('course_sections', $section);
154 if (!empty($section->sequence) or !empty($section->summary) or $editing) {
155 print_box_start('generalbox sitetopic');
157 /// If currently moving a file then show the current clipboard
158 if (ismoving($SITE->id)) {
159 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname)));
160 echo '<p><font size="2">';
161 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=$USER->sesskey\">". get_string('cancel') .'</a>)';
162 echo '</font></p>';
165 $options = NULL;
166 $options->noclean = true;
167 echo format_text($section->summary, FORMAT_HTML, $options);
169 if ($editing) {
170 $streditsummary = get_string('editsummary');
171 echo "<a title=\"$streditsummary\" ".
172 " href=\"course/editsection.php?id=$section->id\"><img src=\"$CFG->pixpath/t/edit.gif\" ".
173 " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
176 get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused);
177 print_section($SITE, $section, $mods, $modnamesused, true);
179 if ($editing) {
180 print_section_add_menus($SITE, $section->section, $modnames);
182 print_box_end();
186 if (isloggedin() and !isguest() and isset($CFG->frontpageloggedin)) {
187 $frontpagelayout = $CFG->frontpageloggedin;
188 } else {
189 $frontpagelayout = $CFG->frontpage;
192 foreach (explode(',',$frontpagelayout) as $v) {
193 switch ($v) { /// Display the main part of the front page.
194 case strval(FRONTPAGENEWS):
195 if ($SITE->newsitems) { // Print forums only when needed
196 require_once($CFG->dirroot .'/mod/forum/lib.php');
198 if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
199 error('Could not find or create a main news forum for the site');
202 if (!empty($USER->id)) {
203 $SESSION->fromdiscussion = $CFG->wwwroot;
204 if (forum_is_subscribed($USER->id, $newsforum->id)) {
205 $subtext = get_string('unsubscribe', 'forum');
206 } else {
207 $subtext = get_string('subscribe', 'forum');
209 print_heading_block($newsforum->name);
210 echo '<div class="subscribelink"><a href="mod/forum/subscribe.php?id='.$newsforum->id.'">'.$subtext.'</a></div>';
211 } else {
212 print_heading_block($newsforum->name);
215 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
217 break;
219 case FRONTPAGECOURSELIST:
221 if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) {
222 print_heading_block(get_string('mycourses'));
223 print_my_moodle();
224 } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest()) or (count_records('course') <= FRONTPAGECOURSELIMIT)) {
225 // admin should not see list of courses when there are too many of them
226 print_heading_block(get_string('availablecourses'));
227 print_courses(0, true);
229 break;
231 case FRONTPAGECATEGORYNAMES:
233 print_heading_block(get_string('categories'));
234 print_box_start('generalbox categorybox');
235 print_whole_category_list(NULL, NULL, NULL, -1, false);
236 print_box_end();
237 print_course_search('', false, 'short');
238 break;
240 case FRONTPAGECATEGORYCOMBO:
242 print_heading_block(get_string('categories'));
243 print_box_start('generalbox categorybox');
244 print_whole_category_list(NULL, NULL, NULL, -1, true);
245 print_box_end();
246 print_course_search('', false, 'short');
247 break;
249 case FRONTPAGETOPICONLY: // Do nothing!! :-)
250 break;
253 echo '<br />';
256 if (!empty($THEME->roundcorners)) {
257 echo '</div></div></div>';
258 echo '<div class="bb"><div></div></div>';
261 echo '</td>';
262 break;
263 case 'right':
264 // The right column
265 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing || has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, SITEID))) {
266 echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
267 if (!empty($THEME->roundcorners)) {
268 echo '<div class="bt"><div></div></div>';
269 echo '<div class="i1"><div class="i2"><div class="i3">';
271 if (has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, SITEID))) {
272 echo '<div style="text-align:center">'.update_course_icon($SITE->id).'</div>';
273 echo '<br />';
275 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
276 if (!empty($THEME->roundcorners)) {
277 echo '</div></div></div>';
278 echo '<div class="bb"><div></div></div>';
280 echo '</td>';
282 break;
287 </tr>
288 </table>
290 <?php
291 print_footer('home'); // Please do not modify this line