2 // index.php - the front page.
4 ///////////////////////////////////////////////////////////////////////////
6 // NOTICE OF COPYRIGHT //
8 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
9 // http://moodle.org //
11 // Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
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. //
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: //
23 // http://www.gnu.org/copyleft/gpl.html //
25 ///////////////////////////////////////////////////////////////////////////
28 if (!file_exists('./config.php')) {
29 header('Location: install.php');
33 require_once('config.php');
34 require_once($CFG->dirroot
.'/course/lib.php');
35 require_once($CFG->dirroot
.'/lib/blocklib.php');
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
56 redirect("$CFG->wwwroot/$CFG->admin/");
58 // Trigger 1.9 accesslib upgrade?
59 if ((int)$CFG->version
< 2007092000
61 && is_siteadmin($USER->id
)) { // this test is expensive, but is only triggered during the upgrade
62 redirect("$CFG->wwwroot/$CFG->admin/");
65 if ($CFG->forcelogin
) {
69 if ($CFG->rolesactive
) { // if already using roles system
70 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
))) {
71 if (moodle_needs_upgrading()) {
72 redirect($CFG->wwwroot
.'/'. $CFG->admin
.'/index.php');
74 } else if (!empty($CFG->mymoodleredirect
)) { // Redirect logged-in users to My Moodle overview if required
75 if (isloggedin() && $USER->username
!= 'guest') {
76 redirect($CFG->wwwroot
.'/my/index.php');
79 } else { // if upgrading from 1.6 or below
80 if (isadmin() && moodle_needs_upgrading()) {
81 redirect($CFG->wwwroot
.'/'. $CFG->admin
.'/index.php');
86 if (get_moodle_cookie() == '') {
87 set_moodle_cookie('nobody'); // To help search for cookies on login page
90 if (!empty($USER->id
)) {
91 add_to_log(SITEID
, 'course', 'view', 'view.php?id='.SITEID
, SITEID
);
94 if (empty($CFG->langmenu
)) {
97 $currlang = current_language();
98 $langs = get_list_of_languages();
99 $langlabel = get_accesshide(get_string('language'));
100 $langmenu = popup_form($CFG->wwwroot
.'/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true, 'self', $langlabel);
103 $PAGE = page_create_object(PAGE_COURSE_VIEW
, SITEID
);
104 $pageblocks = blocks_setup($PAGE);
105 $editing = $PAGE->user_is_editing();
106 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH
, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT
]),
108 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH
, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT
]),
110 print_header($SITE->fullname
, $SITE->fullname
, 'home', '',
111 '<meta name="description" content="'. s(strip_tags($SITE->summary
)) .'" />',
112 true, '', user_login_string($SITE).$langmenu);
117 <table id
="layout-table" summary
="layout">
120 $lt = (empty($THEME->layouttable
)) ?
array('left', 'middle', 'right') : $THEME->layouttable
;
121 foreach ($lt as $column) {
124 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT
) ||
$editing) {
125 echo '<td style="width: '.$preferred_width_left.'px;" id="left-column">';
126 print_container_start();
127 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT
);
128 print_container_end();
133 echo '<td id="middle-column">'. skip_main_destination();
135 print_container_start();
138 if ($SITE->numsections
> 0) {
140 if (!$section = get_record('course_sections', 'course', $SITE->id
, 'section', 1)) {
141 delete_records('course_sections', 'course', $SITE->id
, 'section', 1); // Just in case
142 $section->course
= $SITE->id
;
143 $section->section
= 1;
144 $section->summary
= '';
145 $section->sequence
= '';
146 $section->visible
= 1;
147 $section->id
= insert_record('course_sections', $section);
150 if (!empty($section->sequence
) or !empty($section->summary
) or $editing) {
151 print_box_start('generalbox sitetopic');
153 /// If currently moving a file then show the current clipboard
154 if (ismoving($SITE->id
)) {
155 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname
)));
156 echo '<p><font size="2">';
157 echo "$stractivityclipboard (<a href=\"course/mod.php?cancelcopy=true&sesskey=$USER->sesskey\">". get_string('cancel') .'</a>)';
162 $options->noclean
= true;
163 echo format_text($section->summary
, FORMAT_HTML
, $options);
166 $streditsummary = get_string('editsummary');
167 echo "<a title=\"$streditsummary\" ".
168 " href=\"course/editsection.php?id=$section->id\"><img src=\"$CFG->pixpath/t/edit.gif\" ".
169 " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
172 get_all_mods($SITE->id
, $mods, $modnames, $modnamesplural, $modnamesused);
173 print_section($SITE, $section, $mods, $modnamesused, true);
176 print_section_add_menus($SITE, $section->section
, $modnames);
182 if (isloggedin() and !isguest() and isset($CFG->frontpageloggedin
)) {
183 $frontpagelayout = $CFG->frontpageloggedin
;
185 $frontpagelayout = $CFG->frontpage
;
188 foreach (explode(',',$frontpagelayout) as $v) {
189 switch ($v) { /// Display the main part of the front page.
191 if ($SITE->newsitems
) { // Print forums only when needed
192 require_once($CFG->dirroot
.'/mod/forum/lib.php');
194 if (! $newsforum = forum_get_course_forum($SITE->id
, 'news')) {
195 error('Could not find or create a main news forum for the site');
198 if (!empty($USER->id
)) {
199 $SESSION->fromdiscussion
= $CFG->wwwroot
;
200 if (forum_is_subscribed($USER->id
, $newsforum->id
)) {
201 $subtext = get_string('unsubscribe', 'forum');
203 $subtext = get_string('subscribe', 'forum');
205 print_heading_block($newsforum->name
);
206 echo '<div class="subscribelink"><a href="mod/forum/subscribe.php?id='.$newsforum->id
.'">'.$subtext.'</a></div>';
208 print_heading_block($newsforum->name
);
211 forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems
, 'plain', 'p.modified DESC');
215 case FRONTPAGECOURSELIST
:
217 if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
)) and !isguest() and empty($CFG->disablemycourses
)) {
218 print_heading_block(get_string('mycourses'));
220 } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
)) and !isguest()) or (count_records('course') <= FRONTPAGECOURSELIMIT
)) {
221 // admin should not see list of courses when there are too many of them
222 print_heading_block(get_string('availablecourses'));
227 case FRONTPAGECATEGORYNAMES
:
229 print_heading_block(get_string('categories'));
230 print_box_start('generalbox categorybox');
231 print_whole_category_list(NULL, NULL, NULL, -1, false);
233 print_course_search('', false, 'short');
236 case FRONTPAGECATEGORYCOMBO
:
238 print_heading_block(get_string('categories'));
239 print_box_start('generalbox categorybox');
240 print_whole_category_list(NULL, NULL, NULL, -1, true);
242 print_course_search('', false, 'short');
245 case FRONTPAGETOPICONLY
: // Do nothing!! :-)
252 print_container_end();
258 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT
) ||
$editing ||
$PAGE->user_allowed_editing()) {
259 echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
260 print_container_start();
261 if ($PAGE->user_allowed_editing()) {
262 echo '<div style="text-align:center">'.update_course_icon($SITE->id
).'</div>';
265 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT
);
266 print_container_end();
278 print_footer('home'); // Please do not modify this line