Proyectos de Subversion Moodle

Rev

| 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
require_once("../../config.php");
18
require_once($CFG->dirroot.'/mod/scorm/lib.php');
19
require_once($CFG->dirroot.'/mod/scorm/locallib.php');
20
require_once($CFG->dirroot.'/course/lib.php');
21
 
22
$id = optional_param('id', '', PARAM_INT);       // Course Module ID, or
23
$a = optional_param('a', '', PARAM_INT);         // scorm ID
24
$organization = optional_param('organization', '', PARAM_INT); // organization ID.
25
$action = optional_param('action', '', PARAM_ALPHA);
26
$preventskip = optional_param('preventskip', '', PARAM_INT); // Prevent Skip view, set by javascript redirects.
27
 
28
if (!empty($id)) {
29
    if (! $cm = get_coursemodule_from_id('scorm', $id, 0, true)) {
30
        throw new \moodle_exception('invalidcoursemodule');
31
    }
32
    if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
33
        throw new \moodle_exception('coursemisconf');
34
    }
35
    if (! $scorm = $DB->get_record("scorm", array("id" => $cm->instance))) {
36
        throw new \moodle_exception('invalidcoursemodule');
37
    }
38
} else if (!empty($a)) {
39
    if (! $scorm = $DB->get_record("scorm", array("id" => $a))) {
40
        throw new \moodle_exception('invalidcoursemodule');
41
    }
42
    if (! $course = $DB->get_record("course", array("id" => $scorm->course))) {
43
        throw new \moodle_exception('coursemisconf');
44
    }
45
    if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id, true)) {
46
        throw new \moodle_exception('invalidcoursemodule');
47
    }
48
} else {
49
    throw new \moodle_exception('missingparameter');
50
}
51
 
52
$url = new moodle_url('/mod/scorm/view.php', array('id' => $cm->id));
53
if ($organization !== '') {
54
    $url->param('organization', $organization);
55
}
56
$PAGE->set_url($url);
57
$forcejs = get_config('scorm', 'forcejavascript');
58
if (!empty($forcejs)) {
59
    $PAGE->add_body_class('forcejavascript');
60
}
61
 
62
require_login($course, false, $cm);
63
 
64
$context = context_course::instance($course->id);
65
$contextmodule = context_module::instance($cm->id);
66
 
67
$launch = false; // Does this automatically trigger a launch based on skipview.
68
if (!empty($scorm->popup)) {
69
    $scoid = 0;
70
    $orgidentifier = '';
71
 
72
    $result = scorm_get_toc($USER, $scorm, $cm->id, TOCFULLURL);
73
    // Set last incomplete sco to launch first.
74
    if (!empty($result->sco->id)) {
75
        $sco = $result->sco;
76
    } else {
77
        $sco = scorm_get_sco($scorm->launch, SCO_ONLY);
78
    }
79
    if (!empty($sco)) {
80
        $scoid = $sco->id;
81
        if (($sco->organization == '') && ($sco->launch == '')) {
82
            $orgidentifier = $sco->identifier;
83
        } else {
84
            $orgidentifier = $sco->organization;
85
        }
86
    }
87
 
88
    if (empty($preventskip) && $scorm->skipview >= SCORM_SKIPVIEW_FIRST &&
89
        has_capability('mod/scorm:skipview', $contextmodule) &&
90
        !has_capability('mod/scorm:viewreport', $contextmodule)) { // Don't skip users with the capability to view reports.
91
 
92
        // Do we launch immediately and redirect the parent back ?
93
        if ($scorm->skipview == SCORM_SKIPVIEW_ALWAYS || !scorm_has_tracks($scorm->id, $USER->id)) {
94
            $launch = true;
95
        }
96
    }
97
    // Redirect back to the section with one section per page ?
98
 
99
    $courseformat = course_get_format($course)->get_course();
100
    if ($courseformat->format == 'singleactivity') {
101
        $courseurl = $url->out(false, array('preventskip' => '1'));
102
    } else {
103
        $courseurl = course_get_url($course, $cm->sectionnum)->out(false);
104
    }
105
    $PAGE->requires->data_for_js('scormplayerdata', Array('launch' => $launch,
106
                                                           'currentorg' => $orgidentifier,
107
                                                           'sco' => $scoid,
108
                                                           'scorm' => $scorm->id,
109
                                                           'courseurl' => $courseurl,
110
                                                           'cwidth' => $scorm->width,
111
                                                           'cheight' => $scorm->height,
112
                                                           'popupoptions' => $scorm->options), true);
113
    $PAGE->requires->string_for_js('popupsblocked', 'scorm');
114
    $PAGE->requires->string_for_js('popuplaunched', 'scorm');
115
    $PAGE->requires->js('/mod/scorm/view.js', true);
116
}
117
 
118
if (isset($SESSION->scorm)) {
119
    unset($SESSION->scorm);
120
}
121
 
122
$strscorms = get_string("modulenameplural", "scorm");
123
$strscorm  = get_string("modulename", "scorm");
124
 
125
$shortname = format_string($course->shortname, true, array('context' => $context));
126
$pagetitle = strip_tags($shortname.': '.format_string($scorm->name));
127
 
128
// Trigger module viewed event.
129
scorm_view($scorm, $course, $cm, $contextmodule);
130
 
131
if (empty($preventskip) && empty($launch) && (has_capability('mod/scorm:skipview', $contextmodule))) {
132
    scorm_simple_play($scorm, $USER, $contextmodule, $cm->id);
133
}
134
 
135
// Print the page header.
136
 
137
$PAGE->set_title($pagetitle);
138
$PAGE->set_heading($course->fullname);
139
// Let the module handle the display.
140
if (!empty($action) && $action == 'delete' && confirm_sesskey() && has_capability('mod/scorm:deleteownresponses', $contextmodule)) {
141
    $PAGE->activityheader->disable();
142
} else {
143
    $PAGE->activityheader->set_description('');
144
}
145
 
146
echo $OUTPUT->header();
147
if (!empty($action) && confirm_sesskey() && has_capability('mod/scorm:deleteownresponses', $contextmodule)) {
148
    if ($action == 'delete') {
149
        $confirmurl = new moodle_url($PAGE->url, array('action' => 'deleteconfirm'));
150
        echo $OUTPUT->confirm(get_string('deleteuserattemptcheck', 'scorm'), $confirmurl, $PAGE->url);
151
        echo $OUTPUT->footer();
152
        exit;
153
    } else if ($action == 'deleteconfirm') {
154
        // Delete this users attempts.
155
        scorm_delete_tracks($scorm->id, null, $USER->id);
156
        scorm_update_grades($scorm, $USER->id, true);
157
        echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
158
    }
159
}
160
 
161
// Print the main part of the page.
162
$attemptstatus = '';
163
if (empty($launch) && ($scorm->displayattemptstatus == SCORM_DISPLAY_ATTEMPTSTATUS_ALL ||
164
         $scorm->displayattemptstatus == SCORM_DISPLAY_ATTEMPTSTATUS_ENTRY)) {
165
    $attemptstatus = scorm_get_attempt_status($USER, $scorm, $cm);
166
}
167
echo $OUTPUT->box(format_module_intro('scorm', $scorm, $cm->id), '', 'intro');
168
 
169
// Check if SCORM available. No need to display warnings because activity dates are displayed at the top of the page.
170
list($available, $warnings) = scorm_get_availability_status($scorm);
171
 
172
if ($available && empty($launch)) {
173
    scorm_print_launch($USER, $scorm, 'view.php?id='.$cm->id, $cm);
174
}
175
 
176
echo $OUTPUT->box($attemptstatus);
177
 
178
if (!empty($forcejs)) {
179
    $message = $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "forcejavascriptmessage");
180
    echo html_writer::tag('noscript', $message);
181
}
182
 
183
if (!empty($scorm->popup)) {
184
    $PAGE->requires->js_init_call('M.mod_scormform.init');
185
}
186
 
187
echo $OUTPUT->footer();