Proyectos de Subversion Moodle

Rev

Rev 1446 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Moodle frontpage.
19
 *
20
 * @package    core
21
 * @copyright  1999 onwards Martin Dougiamas (http://dougiamas.com)
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
if (!file_exists('./config.php')) {
26
    header('Location: install.php');
27
    die;
28
}
29
 
30
require_once('config.php');
1442 ariadna 31
require_once($CFG->dirroot . '/course/lib.php');
32
require_once($CFG->libdir . '/filelib.php');
1 efrain 33
 
34
redirect_if_major_upgrade_required();
35
 
1441 ariadna 36
// Redirect logged-in users to homepage if required.
37
$redirect = optional_param('redirect', 1, PARAM_BOOL);
38
 
1 efrain 39
$urlparams = array();
1442 ariadna 40
if (
41
    !empty($CFG->defaulthomepage) &&
42
    ($CFG->defaulthomepage == HOMEPAGE_MY || $CFG->defaulthomepage == HOMEPAGE_MYCOURSES) &&
43
    $redirect === 0
1 efrain 44
) {
45
    $urlparams['redirect'] = 0;
46
}
47
$PAGE->set_url('/', $urlparams);
48
$PAGE->set_pagelayout('frontpage');
49
$PAGE->add_body_class('limitedwidth');
50
$PAGE->set_other_editing_capability('moodle/course:update');
51
$PAGE->set_other_editing_capability('moodle/course:manageactivities');
52
$PAGE->set_other_editing_capability('moodle/course:activityvisibility');
53
 
54
// Prevent caching of this page to stop confusion when changing page after making AJAX changes.
55
$PAGE->set_cacheable(false);
56
 
57
require_course_login($SITE);
58
 
59
$hasmaintenanceaccess = has_capability('moodle/site:maintenanceaccess', context_system::instance());
60
 
61
// If the site is currently under maintenance, then print a message.
62
if (!empty($CFG->maintenance_enabled) and !$hasmaintenanceaccess) {
63
    print_maintenance_message();
64
}
65
 
66
$hassiteconfig = has_capability('moodle/site:config', context_system::instance());
67
 
68
if ($hassiteconfig && moodle_needs_upgrading()) {
1442 ariadna 69
    redirect($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
1 efrain 70
}
71
 
72
// If site registration needs updating, redirect.
73
\core\hub\registration::registration_reminder('/index.php');
74
 
1441 ariadna 75
$homepage = get_home_page();
76
if ($homepage != HOMEPAGE_SITE) {
1 efrain 77
    if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
78
        set_user_preference('user_home_page_preference', HOMEPAGE_SITE);
79
    } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && $redirect === 1) {
80
        // At this point, dashboard is enabled so we don't need to check for it (otherwise, get_home_page() won't return it).
1442 ariadna 81
        redirect($CFG->wwwroot . '/my/');
1 efrain 82
    } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MYCOURSES) && $redirect === 1) {
1442 ariadna 83
        redirect($CFG->wwwroot . '/my/courses.php');
1441 ariadna 84
    } else if ($homepage == HOMEPAGE_URL) {
85
        redirect(get_default_home_page_url());
1 efrain 86
    } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_USER)) {
87
        $frontpagenode = $PAGE->settingsnav->find('frontpage', null);
88
        if ($frontpagenode) {
89
            $frontpagenode->add(
90
                get_string('makethismyhome'),
91
                new moodle_url('/', array('setdefaulthome' => true)),
1442 ariadna 92
                navigation_node::TYPE_SETTING
93
            );
1 efrain 94
        } else {
95
            $frontpagenode = $PAGE->settingsnav->add(get_string('frontpagesettings'), null, navigation_node::TYPE_SETTING, null);
96
            $frontpagenode->force_open();
1442 ariadna 97
            $frontpagenode->add(
98
                get_string('makethismyhome'),
1 efrain 99
                new moodle_url('/', array('setdefaulthome' => true)),
1442 ariadna 100
                navigation_node::TYPE_SETTING
101
            );
1 efrain 102
        }
103
    }
104
}
105
 
106
// Trigger event.
107
course_view(context_course::instance(SITEID));
108
 
109
$PAGE->set_pagetype('site-index');
110
$PAGE->set_docs_path('');
111
$editing = $PAGE->user_is_editing();
112
$PAGE->set_title(get_string('home'));
113
$PAGE->set_heading($SITE->fullname);
114
$PAGE->set_secondary_active_tab('coursehome');
115
 
1441 ariadna 116
$siteformatoptions = course_get_format($SITE)->get_format_options();
117
$modinfo = get_fast_modinfo($SITE);
118
$modnamesused = $modinfo->get_used_module_names();
119
 
120
// The home page can have acitvities in the block aside. We should
121
// initialize the course editor before the page structure is rendered.
122
include_course_ajax($SITE, $modnamesused);
123
 
1 efrain 124
$courserenderer = $PAGE->get_renderer('core', 'course');
125
 
126
if ($hassiteconfig) {
127
    $editurl = new moodle_url('/course/view.php', ['id' => SITEID, 'sesskey' => sesskey()]);
128
    $editbutton = $OUTPUT->edit_button($editurl);
129
    $PAGE->set_button($editbutton);
130
}
131
 
132
echo $OUTPUT->header();
133
 
134
// Print Section or custom info.
135
if (!empty($CFG->customfrontpageinclude)) {
136
    // Pre-fill some variables that custom front page might use.
137
    $modnames = get_module_types_names();
138
    $modnamesplural = get_module_types_names(true);
139
    $mods = $modinfo->get_cms();
140
 
141
    include($CFG->customfrontpageinclude);
142
} else if ($siteformatoptions['numsections'] > 0) {
143
    echo $courserenderer->frontpage_section1();
144
}
145
 
146
echo $courserenderer->frontpage();
147
 
148
if ($editing && has_capability('moodle/course:create', context_system::instance())) {
149
    echo $courserenderer->add_new_course_button();
150
}
151
echo $OUTPUT->footer();