MDL-18167 towareds reimplementing of win installer support
[moodle.git] / index.php
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 onwards  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;
31     }
33     require_once('config.php');
34     require_once($CFG->dirroot .'/course/lib.php');
35     require_once($CFG->dirroot .'/lib/blocklib.php');
37     // Bounds for block widths
38     // more flexible for theme designers taken from theme config.php
39     $lmin = (empty($THEME->block_l_min_width)) ? 100 : $THEME->block_l_min_width;
40     $lmax = (empty($THEME->block_l_max_width)) ? 210 : $THEME->block_l_max_width;
41     $rmin = (empty($THEME->block_r_min_width)) ? 100 : $THEME->block_r_min_width;
42     $rmax = (empty($THEME->block_r_max_width)) ? 210 : $THEME->block_r_max_width;
44     define('BLOCK_L_MIN_WIDTH', $lmin);
45     define('BLOCK_L_MAX_WIDTH', $lmax);
46     define('BLOCK_R_MIN_WIDTH', $rmin);
47     define('BLOCK_R_MAX_WIDTH', $rmax);
49     // check if major upgrade needed - also present in login/index.php
50     if (empty($CFG->version) or (int)$CFG->version < 2009011900 or !empty($CFG->adminsetuppending)) { //1.9 or older
51         @require_logout();
52         redirect("$CFG->wwwroot/$CFG->admin/");
53     }
55     if ($CFG->forcelogin) {
56         require_login();
57     } else {
58         user_accesstime_log();
59     }
61     if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
62         if (moodle_needs_upgrading()) {
63             redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
64         }
65     } else if (!empty($CFG->mymoodleredirect)) {    // Redirect logged-in users to My Moodle overview if required
66         if (isloggedin() && $USER->username != 'guest') {
67             redirect($CFG->wwwroot .'/my/index.php');
68         }
69     }
72     if (get_moodle_cookie() == '') {
73         set_moodle_cookie('nobody');   // To help search for cookies on login page
74     }
76     if (!empty($USER->id)) {
77         add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
78     }
80     if (empty($CFG->langmenu)) {
81         $langmenu = '';
82     } else {
83         $currlang = current_language();
84         $langs = get_list_of_languages();
85         $langlabel = get_accesshide(get_string('language'));
86         $langmenu = popup_form($CFG->wwwroot .'/index.php?lang=', $langs, 'chooselang', $currlang, '', '', '', true, 'self', $langlabel);
87     }
89     $PAGE       = page_create_object(PAGE_COURSE_VIEW, SITEID);
90     $pageblocks = blocks_setup($PAGE);
91     $editing    = $PAGE->user_is_editing();
92     $preferred_width_left  = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
93                                             BLOCK_L_MAX_WIDTH);
94     $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
95                                             BLOCK_R_MAX_WIDTH);
96     print_header($SITE->fullname, $SITE->fullname, 'home', '',
97                  '<meta name="description" content="'. s(strip_tags($SITE->summary)) .'" />',
98                  true, '', user_login_string($SITE).$langmenu);
100 ?>
103 <table id="layout-table" summary="layout">
104   <tr>
105   <?php
106     $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
107     foreach ($lt as $column) {
108         switch ($column) {
109             case 'left':
110     if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
111         echo '<td style="width: '.$preferred_width_left.'px;" id="left-column">';
112         print_container_start();
113         blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
114         print_container_end();
115         echo '</td>';
116     }
117             break;
118             case 'middle':
119     echo '<td id="middle-column">'. skip_main_destination();
121     print_container_start();
123 /// Print Section
124     if ($SITE->numsections > 0) {
126         if (!$section = $DB->get_record('course_sections', array('course'=>$SITE->id, 'section'=>1))) {
127             $DB->delete_records('course_sections', array('course'=>$SITE->id, 'section'=>1)); // Just in case
128             $section->course = $SITE->id;
129             $section->section = 1;
130             $section->summary = '';
131             $section->sequence = '';
132             $section->visible = 1;
133             $section->id = $DB->insert_record('course_sections', $section);
134         }
136         if (!empty($section->sequence) or !empty($section->summary) or $editing) {
137             print_box_start('generalbox sitetopic');
139             /// If currently moving a file then show the current clipboard
140             if (ismoving($SITE->id)) {
141                 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
142                 echo '<p><font size="2">';
143                 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=".sesskey()."\">". get_string('cancel') .'</a>)';
144                 echo '</font></p>';
145             }
147             $options = NULL;
148             $options->noclean = true;
149             echo format_text($section->summary, FORMAT_HTML, $options);
151             if ($editing) {
152                 $streditsummary = get_string('editsummary');
153                 echo "<a title=\"$streditsummary\" ".
154                      " href=\"course/editsection.php?id=$section->id\"><img src=\"$CFG->pixpath/t/edit.gif\" ".
155                      " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
156             }
158             get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused);
159             print_section($SITE, $section, $mods, $modnamesused, true);
161             if ($editing) {
162                 print_section_add_menus($SITE, $section->section, $modnames);
163             }
164             print_box_end();
165         }
166     }
168     if (isloggedin() and !isguest() and isset($CFG->frontpageloggedin)) {
169         $frontpagelayout = $CFG->frontpageloggedin;
170     } else {
171         $frontpagelayout = $CFG->frontpage;
172     }
174     foreach (explode(',',$frontpagelayout) as $v) {
175         switch ($v) {     /// Display the main part of the front page.
176             case FRONTPAGENEWS:
177                 if ($SITE->newsitems) { // Print forums only when needed
178                     require_once($CFG->dirroot .'/mod/forum/lib.php');
180                     if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
181                         print_error('cannotfindorcreateforum', 'forum');
182                     }
184                     if (!empty($USER->id)) {
185                         $SESSION->fromdiscussion = $CFG->wwwroot;
186                         if (forum_is_subscribed($USER->id, $newsforum)) {
187                             $subtext = get_string('unsubscribe', 'forum');
188                         } else {
189                             $subtext = get_string('subscribe', 'forum');
190                         }
191                         print_heading_block($newsforum->name);
192                         echo '<div class="subscribelink"><a href="mod/forum/subscribe.php?id='.$newsforum->id.'">'.$subtext.'</a></div>';
193                     } else {
194                         print_heading_block($newsforum->name);
195                     }
197                     forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
198                 }
199             break;
201             case FRONTPAGECOURSELIST:
203                 if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) {
204                     print_heading_block(get_string('mycourses'));
205                     print_my_moodle();
206                 } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest()) or ($DB->count_records('course') <= FRONTPAGECOURSELIMIT)) {
207                     // admin should not see list of courses when there are too many of them
208                     print_heading_block(get_string('availablecourses'));
209                     print_courses(0);
210                 }
211             break;
213             case FRONTPAGECATEGORYNAMES:
215                 print_heading_block(get_string('categories'));
216                 print_box_start('generalbox categorybox');
217                 print_whole_category_list(NULL, NULL, NULL, -1, false);
218                 print_box_end();
219                 print_course_search('', false, 'short');
220             break;
222             case FRONTPAGECATEGORYCOMBO:
224                 print_heading_block(get_string('categories'));
225                 print_box_start('generalbox categorybox');
226                 print_whole_category_list(NULL, NULL, NULL, -1, true);
227                 print_box_end();
228                 print_course_search('', false, 'short');
229             break;
231             case FRONTPAGETOPICONLY:    // Do nothing!!  :-)
232             break;
234         }
235         echo '<br />';
236     }
238     print_container_end();
240     echo '</td>';
241             break;
242             case 'right':
243     // The right column
244     if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing || $PAGE->user_allowed_editing()) {
245         echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
246         print_container_start();
247         if ($PAGE->user_allowed_editing()) {
248             echo '<div style="text-align:center">'.update_course_icon($SITE->id).'</div>';
249             echo '<br />';
250         }
251         blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
252         print_container_end();
253         echo '</td>';
254     }
255             break;
256         }
257     }
258 ?>
260   </tr>
261 </table>
264 <?php
265     print_footer('home');     // Please do not modify this line
266 ?>