Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
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
 * URL module main user interface
20
 *
21
 * @package    mod_url
22
 * @copyright  2009 Petr Skoda  {@link http://skodak.org}
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
require('../../config.php');
27
require_once("$CFG->dirroot/mod/url/lib.php");
28
require_once("$CFG->dirroot/mod/url/locallib.php");
29
require_once($CFG->libdir . '/completionlib.php');
30
 
31
$id       = optional_param('id', 0, PARAM_INT);        // Course module ID
32
$u        = optional_param('u', 0, PARAM_INT);         // URL instance id
33
$redirect = optional_param('redirect', 0, PARAM_BOOL);
34
$forceview = optional_param('forceview', 0, PARAM_BOOL);
35
 
36
if ($u) {  // Two ways to specify the module
37
    $url = $DB->get_record('url', array('id'=>$u), '*', MUST_EXIST);
38
    $cm = get_coursemodule_from_instance('url', $url->id, $url->course, false, MUST_EXIST);
39
 
40
} else {
41
    $cm = get_coursemodule_from_id('url', $id, 0, false, MUST_EXIST);
42
    $url = $DB->get_record('url', array('id'=>$cm->instance), '*', MUST_EXIST);
43
}
44
 
45
$course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
46
 
47
require_course_login($course, true, $cm);
48
$context = context_module::instance($cm->id);
49
require_capability('mod/url:view', $context);
50
 
51
// Completion and trigger events.
52
url_view($url, $course, $cm, $context);
53
 
54
$PAGE->set_url('/mod/url/view.php', array('id' => $cm->id));
55
 
56
// Make sure URL exists before generating output - some older sites may contain empty urls
57
// Do not use PARAM_URL here, it is too strict and does not support general URIs!
58
$exturl = trim($url->externalurl);
59
if (empty($exturl) or $exturl === 'http://') {
60
    $PAGE->activityheader->set_description(url_get_intro($url, $cm));
61
    url_print_header($url, $cm, $course);
62
    notice(get_string('invalidstoredurl', 'url'), new moodle_url('/course/view.php', array('id'=>$cm->course)));
63
    die;
64
}
65
unset($exturl);
66
 
67
$displaytype = url_get_final_display_type($url);
68
if ($displaytype == RESOURCELIB_DISPLAY_OPEN) {
69
    $redirect = true;
70
}
71
 
72
if ($redirect && !$forceview) {
73
    // coming from course page or url index page,
74
    // the redirection is needed for completion tracking and logging
75
    $fullurl = str_replace('&amp;', '&', url_get_full_url($url, $cm, $course));
76
 
77
    if (!course_get_format($course)->has_view_page()) {
78
        // If course format does not have a view page, add redirection delay with a link to the edit page.
79
        // Otherwise teacher is redirected to the external URL without any possibility to edit activity or course settings.
80
        $editurl = null;
81
        if (has_capability('moodle/course:manageactivities', $context)) {
82
            $editurl = new moodle_url('/course/modedit.php', array('update' => $cm->id));
83
            $edittext = get_string('editthisactivity');
84
        } else if (has_capability('moodle/course:update', $context->get_course_context())) {
85
            $editurl = new moodle_url('/course/edit.php', array('id' => $course->id));
86
            $edittext = get_string('editcoursesettings');
87
        }
88
        if ($editurl) {
89
            redirect($fullurl, html_writer::link($editurl, $edittext)."<br/>".
90
                    get_string('pageshouldredirect'), 10);
91
        }
92
    }
93
    redirect($fullurl);
94
}
95
 
96
switch ($displaytype) {
97
    case RESOURCELIB_DISPLAY_EMBED:
98
        url_display_embed($url, $cm, $course);
99
        break;
100
    case RESOURCELIB_DISPLAY_FRAME:
101
        url_display_frame($url, $cm, $course);
102
        break;
103
    default:
104
        url_print_workaround($url, $cm, $course);
105
        break;
106
}