6a3c0f5fb50c3beab937dd296fcd635f4f1a1856
[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->libdir .'/filelib.php');
37     redirect_if_major_upgrade_required();
39     if ($CFG->forcelogin) {
40         require_login();
41     } else {
42         user_accesstime_log();
43     }
45 /// If the site is currently under maintenance, then print a message
46     if (!empty($CFG->maintenance_enabled) and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
47         print_maintenance_message();
48     }
50     if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) {
51         if (moodle_needs_upgrading()) {
52             redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
53         }
54     } else if (!empty($CFG->mymoodleredirect)) {    // Redirect logged-in users to My Moodle overview if required
55         if (isloggedin() && !isguestuser()) {
56             redirect($CFG->wwwroot .'/my/index.php');
57         }
58     }
61     if (get_moodle_cookie() == '') {
62         set_moodle_cookie('nobody');   // To help search for cookies on login page
63     }
65     if (!empty($USER->id)) {
66         add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID);
67     }
69     $PAGE->set_pagetype('site-index');
70     $PAGE->set_course($SITE);
72     if (empty($CFG->langmenu)) {
73         $langmenu = '';
74     } else {
75         $currlang = current_language();
76         $langs = get_list_of_languages();
78         $select = html_select::make_popup_form($CFG->wwwroot .'/index.php', 'lang', $langs, 'chooselang', $currlang);
79         $select->nothinglabel = false;
80         $select->set_label(get_accesshide(get_string('language')));
81         $langmenu = $OUTPUT->select($select);
82     }
83     $PAGE->set_other_editing_capability('moodle/course:manageactivities');
84     $PAGE->set_url('');
85     $PAGE->set_docs_path('');
86     $PAGE->set_generaltype('home');
87     $editing = $PAGE->user_is_editing();
88     $PAGE->set_title($SITE->fullname);
89     $PAGE->set_heading($SITE->fullname);
90     $PAGE->set_headingmenu(user_login_string($SITE) . $langmenu);
91     echo $OUTPUT->header();
93 /// Print Section
94     if ($SITE->numsections > 0) {
96         if (!$section = $DB->get_record('course_sections', array('course'=>$SITE->id, 'section'=>1))) {
97             $DB->delete_records('course_sections', array('course'=>$SITE->id, 'section'=>1)); // Just in case
98             $section->course = $SITE->id;
99             $section->section = 1;
100             $section->summary = '';
101             $section->sequence = '';
102             $section->visible = 1;
103             $section->id = $DB->insert_record('course_sections', $section);
104         }
106         if (!empty($section->sequence) or !empty($section->summary) or $editing) {
107             echo $OUTPUT->box_start('generalbox sitetopic');
109             /// If currently moving a file then show the current clipboard
110             if (ismoving($SITE->id)) {
111                 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
112                 echo '<p><font size="2">';
113                 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"course/mod.php?cancelcopy=true&amp;sesskey=".sesskey()."\">". get_string('cancel') .'</a>)';
114                 echo '</font></p>';
115             }
117             $context = get_context_instance(CONTEXT_COURSE, SITEID);
118             $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course_section', $section->id);
119             $summaryformatoptions = new object();
120             $summaryformatoptions->noclean = true;
122             echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
124             if ($editing) {
125                 $streditsummary = get_string('editsummary');
126                 echo "<a title=\"$streditsummary\" ".
127                      " href=\"course/editsection.php?id=$section->id\"><img src=\"" . $OUTPUT->old_icon_url('t/edit') . "\" ".
128                      " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
129             }
131             get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused);
132             print_section($SITE, $section, $mods, $modnamesused, true);
134             if ($editing) {
135                 print_section_add_menus($SITE, $section->section, $modnames);
136             }
137             echo $OUTPUT->box_end();
138         }
139     }
141     if (isloggedin() and !isguest() and isset($CFG->frontpageloggedin)) {
142         $frontpagelayout = $CFG->frontpageloggedin;
143     } else {
144         $frontpagelayout = $CFG->frontpage;
145     }
147     foreach (explode(',',$frontpagelayout) as $v) {
148         switch ($v) {     /// Display the main part of the front page.
149             case FRONTPAGENEWS:
150                 if ($SITE->newsitems) { // Print forums only when needed
151                     require_once($CFG->dirroot .'/mod/forum/lib.php');
153                     if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) {
154                         print_error('cannotfindorcreateforum', 'forum');
155                     }
157                     if (!empty($USER->id)) {
158                         $SESSION->fromdiscussion = $CFG->wwwroot;
159                         $subtext = '';
160                         if (forum_is_subscribed($USER->id, $newsforum)) {
161                             if (!forum_is_forcesubscribed($newsforum)) {
162                                 $subtext = get_string('unsubscribe', 'forum');
163                             }
164                         } else {
165                             $subtext = get_string('subscribe', 'forum');
166                         }
167                         echo $OUTPUT->heading($newsforum->name, 2, 'headingblock header');
168                         echo '<div class="subscribelink"><a href="mod/forum/subscribe.php?id='.$newsforum->id.'">'.$subtext.'</a></div>';
169                     } else {
170                         echo $OUTPUT->heading($newsforum->name, 2, 'headingblock header');
171                     }
173                     forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC');
174                 }
175             break;
177             case FRONTPAGECOURSELIST:
179                 if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest() and empty($CFG->disablemycourses)) {
180                     echo $OUTPUT->heading(get_string('mycourses'), 2, 'headingblock header');
181                     print_my_moodle();
182                 } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguest()) or ($DB->count_records('course') <= FRONTPAGECOURSELIMIT)) {
183                     // admin should not see list of courses when there are too many of them
184                     echo $OUTPUT->heading(get_string('availablecourses'), 2, 'headingblock header');
185                     print_courses(0);
186                 }
187             break;
189             case FRONTPAGECATEGORYNAMES:
191                 echo $OUTPUT->heading(get_string('categories'), 2, 'headingblock header');
192                 echo $OUTPUT->box_start('generalbox categorybox');
193                 print_whole_category_list(NULL, NULL, NULL, -1, false);
194                 echo $OUTPUT->box_end();
195                 print_course_search('', false, 'short');
196             break;
198             case FRONTPAGECATEGORYCOMBO:
200                 echo $OUTPUT->heading(get_string('categories'), 2, 'headingblock header');
201                 echo $OUTPUT->box_start('generalbox categorybox');
202                 print_whole_category_list(NULL, NULL, NULL, -1, true);
203                 echo $OUTPUT->box_end();
204                 print_course_search('', false, 'short');
205             break;
207             case FRONTPAGETOPICONLY:    // Do nothing!!  :-)
208             break;
210         }
211         echo '<br />';
212     }
214     echo $OUTPUT->footer();