Commit | Line | Data |
---|---|---|
474f6bfe | 1 | <?php |
0cfb6a52 | 2 | |
af9f5430 PS |
3 | // This file is part of Moodle - http://moodle.org/ |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * Moodle frontpage. | |
20 | * | |
21 | * @package core | |
22 | * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) | |
23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
24 | */ | |
0cfb6a52 | 25 | |
8b5b1028 | 26 | if (!file_exists('./config.php')) { |
27 | header('Location: install.php'); | |
28 | die; | |
29 | } | |
30 | ||
d41746c9 | 31 | require_once('config.php'); |
32 | require_once($CFG->dirroot .'/course/lib.php'); | |
644d506a | 33 | require_once($CFG->libdir .'/filelib.php'); |
364fffda | 34 | |
5e39d7aa | 35 | redirect_if_major_upgrade_required(); |
89d1efe4 | 36 | |
0a45ffe3 | 37 | if ($CFG->forcelogin) { |
38 | require_login(); | |
341b5ed2 | 39 | } else { |
40 | user_accesstime_log(); | |
0a45ffe3 | 41 | } |
42 | ||
4766a50c SH |
43 | $PAGE->set_url('/'); |
44 | $PAGE->set_course($SITE); | |
45 | ||
4fe2250a | 46 | /// If the site is currently under maintenance, then print a message |
47 | if (!empty($CFG->maintenance_enabled) and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { | |
48 | print_maintenance_message(); | |
49 | } | |
50 | ||
18818abf | 51 | if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { |
52 | if (moodle_needs_upgrading()) { | |
4bab5275 | 53 | redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php'); |
53bfe78c | 54 | } |
4766a50c SH |
55 | } else if (get_home_page() != HOMEPAGE_SITE) { |
56 | // Redirect logged-in users to My Moodle overview if required | |
57 | if (optional_param('setdefaulthome', false, PARAM_BOOL)) { | |
58 | set_user_preference('user_home_page_preference', HOMEPAGE_SITE); | |
59 | } else if ($CFG->defaulthomepage == HOMEPAGE_MY && optional_param('redirect', true, PARAM_BOOL)) { | |
60 | redirect($CFG->wwwroot .'/my/'); | |
61 | } else if (!empty($CFG->defaulthomepage) && $CFG->defaulthomepage == HOMEPAGE_USER) { | |
62 | $PAGE->settingsnav->get('usercurrentsettings')->add(get_string('makethismyhome'), new moodle_url('/', array('setdefaulthome'=>true)), navigation_node::TYPE_SETTING); | |
18818abf | 63 | } |
3565715c | 64 | } |
65 | ||
4f0c2d00 | 66 | if (isloggedin()) { |
34dd5900 | 67 | add_to_log(SITEID, 'course', 'view', 'view.php?id='.SITEID, SITEID); |
a325bd2b | 68 | } |
a5e3644b | 69 | |
825b6fdb | 70 | /// If the hub plugin is installed then we let it take over the homepage here |
abf63f98 | 71 | if (get_config('local_hub', 'hubenabled') && file_exists($CFG->dirroot.'/local/hub/lib.php')) { |
72 | require_once($CFG->dirroot.'/local/hub/lib.php'); | |
73 | $hub = new local_hub(); | |
a4e56bf3 | 74 | $continue = $hub->display_homepage(); |
75 | //display_homepage() return true if the hub home page is not displayed | |
76 | //mostly when search form is not displayed for not logged users | |
77 | if (empty($continue)) { | |
78 | exit; | |
79 | } | |
abf63f98 | 80 | } |
81 | ||
f8065dd2 | 82 | $PAGE->set_pagetype('site-index'); |
cfcfb9f3 | 83 | $PAGE->set_other_editing_capability('moodle/course:manageactivities'); |
82611d8d | 84 | $PAGE->set_docs_path(''); |
191b267b | 85 | $PAGE->set_pagelayout('frontpage'); |
ad52c04f | 86 | $editing = $PAGE->user_is_editing(); |
d4a03c00 | 87 | $PAGE->set_title($SITE->fullname); |
88 | $PAGE->set_heading($SITE->fullname); | |
244a32c6 | 89 | echo $OUTPUT->header(); |
8c336db1 | 90 | |
8275eab8 PS |
91 | /// Print Section or custom info |
92 | if (!empty($CFG->customfrontpageinclude)) { | |
93 | include($CFG->customfrontpageinclude); | |
94 | ||
95 | } else if ($SITE->numsections > 0) { | |
5fc2f2fd | 96 | |
f33e1ed4 | 97 | if (!$section = $DB->get_record('course_sections', array('course'=>$SITE->id, 'section'=>1))) { |
8618fd2a | 98 | $DB->delete_records('course_sections', array('course'=>$SITE->id, 'section'=>1)); // Just in case |
78ba4d06 | 99 | $section->course = $SITE->id; |
45a6b40d | 100 | $section->section = 1; |
101 | $section->summary = ''; | |
09eb2151 | 102 | $section->summaryformat = FORMAT_HTML; |
a2b82263 | 103 | $section->sequence = ''; |
45a6b40d | 104 | $section->visible = 1; |
f33e1ed4 | 105 | $section->id = $DB->insert_record('course_sections', $section); |
45a6b40d | 106 | } |
5fc2f2fd | 107 | |
64f93798 | 108 | if (!empty($section->sequence) or !empty($section->summary) or $editing) { |
20486a5a | 109 | echo $OUTPUT->box_start('generalbox sitetopic'); |
5fc2f2fd | 110 | |
a2b82263 | 111 | /// If currently moving a file then show the current clipboard |
112 | if (ismoving($SITE->id)) { | |
294ce987 | 113 | $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname)); |
a2b82263 | 114 | echo '<p><font size="2">'; |
973d2660 | 115 | echo "$stractivityclipboard (<a href=\"course/mod.php?cancelcopy=true&sesskey=".sesskey()."\">". get_string('cancel') .'</a>)'; |
a2b82263 | 116 | echo '</font></p>'; |
117 | } | |
5fc2f2fd | 118 | |
644d506a | 119 | $context = get_context_instance(CONTEXT_COURSE, SITEID); |
64f93798 | 120 | $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course', 'section', $section->id); |
a226a972 | 121 | $summaryformatoptions = new stdClass(); |
644d506a | 122 | $summaryformatoptions->noclean = true; |
367a75fa | 123 | $summaryformatoptions->overflowdiv = true; |
644d506a | 124 | |
e34a326f | 125 | echo format_text($summarytext, $section->summaryformat, $summaryformatoptions); |
5fc2f2fd | 126 | |
a2b82263 | 127 | if ($editing) { |
128 | $streditsummary = get_string('editsummary'); | |
129 | echo "<a title=\"$streditsummary\" ". | |
b5d0cafc | 130 | " href=\"course/editsection.php?id=$section->id\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" ". |
0d905d9f | 131 | " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />"; |
a2b82263 | 132 | } |
133 | ||
134 | get_all_mods($SITE->id, $mods, $modnames, $modnamesplural, $modnamesused); | |
135 | print_section($SITE, $section, $mods, $modnamesused, true); | |
364fffda | 136 | |
a2b82263 | 137 | if ($editing) { |
138 | print_section_add_menus($SITE, $section->section, $modnames); | |
139 | } | |
20486a5a | 140 | echo $OUTPUT->box_end(); |
5fc2f2fd | 141 | } |
5fc2f2fd | 142 | } |
143 | ||
64f93798 | 144 | if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) { |
6f24e48e | 145 | $frontpagelayout = $CFG->frontpageloggedin; |
146 | } else { | |
147 | $frontpagelayout = $CFG->frontpage; | |
148 | } | |
149 | ||
64f93798 | 150 | foreach (explode(',',$frontpagelayout) as $v) { |
e1638d61 | 151 | switch ($v) { /// Display the main part of the front page. |
220a90c5 | 152 | case FRONTPAGENEWS: |
e1638d61 | 153 | if ($SITE->newsitems) { // Print forums only when needed |
154 | require_once($CFG->dirroot .'/mod/forum/lib.php'); | |
155 | ||
156 | if (! $newsforum = forum_get_course_forum($SITE->id, 'news')) { | |
33aa5723 | 157 | print_error('cannotfindorcreateforum', 'forum'); |
e1638d61 | 158 | } |
fd2aa40b | 159 | echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower($newsforum->name)), array('href'=>'#skipsitenews', 'class'=>'skip-block')); |
e1638d61 | 160 | |
4f0c2d00 | 161 | if (isloggedin()) { |
e1638d61 | 162 | $SESSION->fromdiscussion = $CFG->wwwroot; |
6e5e0c93 | 163 | $subtext = ''; |
90f4745c | 164 | if (forum_is_subscribed($USER->id, $newsforum)) { |
730535cb | 165 | if (!forum_is_forcesubscribed($newsforum)) { |
166 | $subtext = get_string('unsubscribe', 'forum'); | |
167 | } | |
e1638d61 | 168 | } else { |
169 | $subtext = get_string('subscribe', 'forum'); | |
170 | } | |
706b82da | 171 | echo $OUTPUT->heading($newsforum->name, 2, 'headingblock header'); |
6f7d65c7 DM |
172 | $suburl = new moodle_url('/mod/forum/subscribe.php', array('id' => $newsforum->id, 'sesskey' => sesskey())); |
173 | echo html_writer::tag('div', html_writer::link($suburl, $subtext), array('class' => 'subscribelink')); | |
af328e4b | 174 | } else { |
706b82da | 175 | echo $OUTPUT->heading($newsforum->name, 2, 'headingblock header'); |
af328e4b | 176 | } |
e1638d61 | 177 | |
a5a9cd99 | 178 | forum_print_latest_discussions($SITE, $newsforum, $SITE->newsitems, 'plain', 'p.modified DESC'); |
fd2aa40b | 179 | echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipsitenews')); |
89adb174 | 180 | } |
e1638d61 | 181 | break; |
89adb174 | 182 | |
64f93798 | 183 | case FRONTPAGECOURSELIST: |
474f6bfe | 184 | if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguestuser() and empty($CFG->disablemycourses)) { |
fd2aa40b | 185 | echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('mycourses'))), array('href'=>'#skipmycourses', 'class'=>'skip-block')); |
706b82da | 186 | echo $OUTPUT->heading(get_string('mycourses'), 2, 'headingblock header'); |
e1638d61 | 187 | print_my_moodle(); |
fd2aa40b | 188 | echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipmycourses')); |
474f6bfe | 189 | } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM)) and !isguestuser()) or ($DB->count_records('course') <= FRONTPAGECOURSELIMIT)) { |
fe2920ad | 190 | // admin should not see list of courses when there are too many of them |
fd2aa40b | 191 | echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('availablecourses'))), array('href'=>'#skipavailablecourses', 'class'=>'skip-block')); |
706b82da | 192 | echo $OUTPUT->heading(get_string('availablecourses'), 2, 'headingblock header'); |
5f6b9c09 | 193 | print_courses(0); |
fd2aa40b | 194 | echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipavailablecourses')); |
64f93798 | 195 | } |
e1638d61 | 196 | break; |
89adb174 | 197 | |
e0140f24 | 198 | case FRONTPAGECATEGORYNAMES: |
fd2aa40b | 199 | echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('categories'))), array('href'=>'#skipcategories', 'class'=>'skip-block')); |
706b82da | 200 | echo $OUTPUT->heading(get_string('categories'), 2, 'headingblock header'); |
20486a5a | 201 | echo $OUTPUT->box_start('generalbox categorybox'); |
d157bd5b | 202 | print_whole_category_list(NULL, NULL, NULL, -1, false); |
20486a5a | 203 | echo $OUTPUT->box_end(); |
e0140f24 | 204 | print_course_search('', false, 'short'); |
fd2aa40b | 205 | echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipcategories')); |
e0140f24 | 206 | break; |
207 | ||
6f24e48e | 208 | case FRONTPAGECATEGORYCOMBO: |
fd2aa40b RW |
209 | echo html_writer::tag('a', get_string('skipa', 'access', moodle_strtolower(get_string('courses'))), array('href'=>'#skipcourses', 'class'=>'skip-block')); |
210 | echo $OUTPUT->heading(get_string('courses'), 2, 'headingblock header'); | |
24e27ac0 | 211 | $renderer = $PAGE->get_renderer('core','course'); |
2848b979 DC |
212 | // if there are too many courses, budiling course category tree could be slow, |
213 | // users should go to course index page to see the whole list. | |
214 | $coursecount = $DB->count_records('course'); | |
215 | if (empty($CFG->numcoursesincombo)) { | |
216 | // if $CFG->numcoursesincombo hasn't been set, use default value 500 | |
217 | $CFG->numcoursesincombo = 500; | |
218 | } | |
219 | if ($coursecount > $CFG->numcoursesincombo) { | |
220 | $link = new moodle_url('/course/'); | |
221 | echo $OUTPUT->notification(get_string('maxnumcoursesincombo', 'moodle', array('link'=>$link->out(), 'maxnumofcourses'=>$CFG->numcoursesincombo, 'numberofcourses'=>$coursecount))); | |
222 | } else { | |
223 | echo $renderer->course_category_tree(get_course_category_tree()); | |
224 | } | |
6f24e48e | 225 | print_course_search('', false, 'short'); |
fd2aa40b | 226 | echo html_writer::tag('span', '', array('class'=>'skip-block-to', 'id'=>'skipcourses')); |
6f24e48e | 227 | break; |
228 | ||
e1638d61 | 229 | case FRONTPAGETOPICONLY: // Do nothing!! :-) |
230 | break; | |
5eafd948 | 231 | |
e1638d61 | 232 | } |
233 | echo '<br />'; | |
89adb174 | 234 | } |
235 | ||
d4a03c00 | 236 | echo $OUTPUT->footer(); |