Proyectos de Subversion Moodle

Rev

Rev 1445 | Ir a la última revisión | | 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
 
1446 ariadna 30
 
31
 
1 efrain 32
require_once('config.php');
1442 ariadna 33
require_once($CFG->dirroot . '/course/lib.php');
34
require_once($CFG->libdir . '/filelib.php');
1 efrain 35
 
36
redirect_if_major_upgrade_required();
37
 
1441 ariadna 38
// Redirect logged-in users to homepage if required.
39
$redirect = optional_param('redirect', 1, PARAM_BOOL);
40
 
1 efrain 41
$urlparams = array();
1442 ariadna 42
if (
43
    !empty($CFG->defaulthomepage) &&
44
    ($CFG->defaulthomepage == HOMEPAGE_MY || $CFG->defaulthomepage == HOMEPAGE_MYCOURSES) &&
45
    $redirect === 0
1 efrain 46
) {
47
    $urlparams['redirect'] = 0;
48
}
49
$PAGE->set_url('/', $urlparams);
50
$PAGE->set_pagelayout('frontpage');
51
$PAGE->add_body_class('limitedwidth');
52
$PAGE->set_other_editing_capability('moodle/course:update');
53
$PAGE->set_other_editing_capability('moodle/course:manageactivities');
54
$PAGE->set_other_editing_capability('moodle/course:activityvisibility');
55
 
56
// Prevent caching of this page to stop confusion when changing page after making AJAX changes.
57
$PAGE->set_cacheable(false);
58
 
59
require_course_login($SITE);
60
 
61
$hasmaintenanceaccess = has_capability('moodle/site:maintenanceaccess', context_system::instance());
62
 
63
// If the site is currently under maintenance, then print a message.
64
if (!empty($CFG->maintenance_enabled) and !$hasmaintenanceaccess) {
65
    print_maintenance_message();
66
}
67
 
68
$hassiteconfig = has_capability('moodle/site:config', context_system::instance());
69
 
70
if ($hassiteconfig && moodle_needs_upgrading()) {
1442 ariadna 71
    redirect($CFG->wwwroot . '/' . $CFG->admin . '/index.php');
1 efrain 72
}
73
 
74
// If site registration needs updating, redirect.
75
\core\hub\registration::registration_reminder('/index.php');
76
 
1441 ariadna 77
$homepage = get_home_page();
78
if ($homepage != HOMEPAGE_SITE) {
1 efrain 79
    if (optional_param('setdefaulthome', false, PARAM_BOOL)) {
80
        set_user_preference('user_home_page_preference', HOMEPAGE_SITE);
81
    } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MY) && $redirect === 1) {
82
        // 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 83
        redirect($CFG->wwwroot . '/my/');
1 efrain 84
    } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_MYCOURSES) && $redirect === 1) {
1442 ariadna 85
        redirect($CFG->wwwroot . '/my/courses.php');
1441 ariadna 86
    } else if ($homepage == HOMEPAGE_URL) {
87
        redirect(get_default_home_page_url());
1 efrain 88
    } else if (!empty($CFG->defaulthomepage) && ($CFG->defaulthomepage == HOMEPAGE_USER)) {
89
        $frontpagenode = $PAGE->settingsnav->find('frontpage', null);
90
        if ($frontpagenode) {
91
            $frontpagenode->add(
92
                get_string('makethismyhome'),
93
                new moodle_url('/', array('setdefaulthome' => true)),
1442 ariadna 94
                navigation_node::TYPE_SETTING
95
            );
1 efrain 96
        } else {
97
            $frontpagenode = $PAGE->settingsnav->add(get_string('frontpagesettings'), null, navigation_node::TYPE_SETTING, null);
98
            $frontpagenode->force_open();
1442 ariadna 99
            $frontpagenode->add(
100
                get_string('makethismyhome'),
1 efrain 101
                new moodle_url('/', array('setdefaulthome' => true)),
1442 ariadna 102
                navigation_node::TYPE_SETTING
103
            );
1 efrain 104
        }
105
    }
106
}
107
 
108
// Trigger event.
109
course_view(context_course::instance(SITEID));
110
 
111
$PAGE->set_pagetype('site-index');
112
$PAGE->set_docs_path('');
113
$editing = $PAGE->user_is_editing();
114
$PAGE->set_title(get_string('home'));
115
$PAGE->set_heading($SITE->fullname);
116
$PAGE->set_secondary_active_tab('coursehome');
117
 
1441 ariadna 118
$siteformatoptions = course_get_format($SITE)->get_format_options();
119
$modinfo = get_fast_modinfo($SITE);
120
$modnamesused = $modinfo->get_used_module_names();
121
 
122
// The home page can have acitvities in the block aside. We should
123
// initialize the course editor before the page structure is rendered.
124
include_course_ajax($SITE, $modnamesused);
125
 
1 efrain 126
$courserenderer = $PAGE->get_renderer('core', 'course');
127
 
128
if ($hassiteconfig) {
129
    $editurl = new moodle_url('/course/view.php', ['id' => SITEID, 'sesskey' => sesskey()]);
130
    $editbutton = $OUTPUT->edit_button($editurl);
131
    $PAGE->set_button($editbutton);
132
}
133
 
134
echo $OUTPUT->header();
135
 
136
// Print Section or custom info.
137
if (!empty($CFG->customfrontpageinclude)) {
138
    // Pre-fill some variables that custom front page might use.
139
    $modnames = get_module_types_names();
140
    $modnamesplural = get_module_types_names(true);
141
    $mods = $modinfo->get_cms();
142
 
143
    include($CFG->customfrontpageinclude);
144
} else if ($siteformatoptions['numsections'] > 0) {
145
    echo $courserenderer->frontpage_section1();
146
}
147
 
148
echo $courserenderer->frontpage();
149
 
150
if ($editing && has_capability('moodle/course:create', context_system::instance())) {
151
    echo $courserenderer->add_new_course_button();
152
}
153
echo $OUTPUT->footer();