Proyectos de Subversion Moodle

Rev

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