2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
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');
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.
29 if (! $cm = get_coursemodule_from_id('scorm', $id, 0, true)) {
30 print_error('invalidcoursemodule');
32 if (! $course = $DB->get_record("course", array("id" => $cm->course
))) {
33 print_error('coursemisconf');
35 if (! $scorm = $DB->get_record("scorm", array("id" => $cm->instance
))) {
36 print_error('invalidcoursemodule');
38 } else if (!empty($a)) {
39 if (! $scorm = $DB->get_record("scorm", array("id" => $a))) {
40 print_error('invalidcoursemodule');
42 if (! $course = $DB->get_record("course", array("id" => $scorm->course
))) {
43 print_error('coursemisconf');
45 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id
, $course->id
, true)) {
46 print_error('invalidcoursemodule');
49 print_error('missingparameter');
52 $url = new moodle_url('/mod/scorm/view.php', array('id' => $cm->id
));
53 if ($organization !== '') {
54 $url->param('organization', $organization);
57 $forcejs = get_config('scorm', 'forcejavascript');
58 if (!empty($forcejs)) {
59 $PAGE->add_body_class('forcejavascript');
62 require_login($course, false, $cm);
64 $context = context_course
::instance($course->id
);
65 $contextmodule = context_module
::instance($cm->id
);
67 $launch = false; // Does this automatically trigger a launch based on skipview.
68 if (!empty($scorm->popup
)) {
74 $result = scorm_get_toc($USER, $scorm, $cm->id
, TOCFULLURL
);
75 // Set last incomplete sco to launch first.
76 if (!empty($result->sco
->id
)) {
77 $scoid = $result->sco
->id
;
79 if ($sco = scorm_get_sco($scorm->launch
, SCO_ONLY
)) {
80 if (($sco->organization
== '') && ($sco->launch
== '')) {
81 $orgidentifier = $sco->identifier
;
83 $orgidentifier = $sco->organization
;
89 if (empty($preventskip) && $scorm->skipview
>= SCORM_SKIPVIEW_FIRST
&&
90 has_capability('mod/scorm:skipview', $contextmodule) &&
91 !has_capability('mod/scorm:viewreport', $contextmodule)) { // Don't skip users with the capability to view reports.
93 // Do we launch immediately and redirect the parent back ?
94 if ($scorm->skipview
== SCORM_SKIPVIEW_ALWAYS ||
!scorm_has_tracks($scorm->id
, $USER->id
)) {
98 // Redirect back to the section with one section per page ?
100 $courseformat = course_get_format($course)->get_course();
101 if ($courseformat->format
== 'singleactivity') {
102 $courseurl = $url->out(false, array('preventskip' => '1'));
104 $courseurl = course_get_url($course, $cm->sectionnum
)->out(false);
106 $PAGE->requires
->data_for_js('scormplayerdata', Array('launch' => $launch,
107 'currentorg' => $orgidentifier,
109 'scorm' => $scorm->id
,
110 'courseurl' => $courseurl,
111 'cwidth' => $scorm->width
,
112 'cheight' => $scorm->height
,
113 'popupoptions' => $scorm->options
), true);
114 $PAGE->requires
->string_for_js('popupsblocked', 'scorm');
115 $PAGE->requires
->string_for_js('popuplaunched', 'scorm');
116 $PAGE->requires
->js('/mod/scorm/view.js', true);
119 if (isset($SESSION->scorm
)) {
120 unset($SESSION->scorm
);
123 $strscorms = get_string("modulenameplural", "scorm");
124 $strscorm = get_string("modulename", "scorm");
126 $shortname = format_string($course->shortname
, true, array('context' => $context));
127 $pagetitle = strip_tags($shortname.': '.format_string($scorm->name
));
129 // Trigger module viewed event.
130 scorm_view($scorm, $course, $cm, $contextmodule);
132 if (empty($preventskip) && empty($launch) && (has_capability('mod/scorm:skipview', $contextmodule))) {
133 scorm_simple_play($scorm, $USER, $contextmodule, $cm->id
);
136 // Print the page header.
138 $PAGE->set_title($pagetitle);
139 $PAGE->set_heading($course->fullname
);
140 echo $OUTPUT->header();
141 echo $OUTPUT->heading(format_string($scorm->name
));
143 if (!empty($action) && confirm_sesskey() && has_capability('mod/scorm:deleteownresponses', $contextmodule)) {
144 if ($action == 'delete') {
145 $confirmurl = new moodle_url($PAGE->url
, array('action' => 'deleteconfirm'));
146 echo $OUTPUT->confirm(get_string('deleteuserattemptcheck', 'scorm'), $confirmurl, $PAGE->url
);
147 echo $OUTPUT->footer();
149 } else if ($action == 'deleteconfirm') {
150 // Delete this users attempts.
151 $DB->delete_records('scorm_scoes_track', array('userid' => $USER->id
, 'scormid' => $scorm->id
));
152 scorm_update_grades($scorm, $USER->id
, true);
153 echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
157 $currenttab = 'info';
158 require($CFG->dirroot
. '/mod/scorm/tabs.php');
160 // Print the main part of the page.
162 if (empty($launch) && ($scorm->displayattemptstatus
== SCORM_DISPLAY_ATTEMPTSTATUS_ALL ||
163 $scorm->displayattemptstatus
== SCORM_DISPLAY_ATTEMPTSTATUS_ENTRY
)) {
164 $attemptstatus = scorm_get_attempt_status($USER, $scorm, $cm);
166 echo $OUTPUT->box(format_module_intro('scorm', $scorm, $cm->id
).$attemptstatus, 'container', 'intro');
168 // Check if SCORM available.
169 list($available, $warnings) = scorm_get_availability_status($scorm);
171 $reason = current(array_keys($warnings));
172 echo $OUTPUT->box(get_string($reason, "scorm", $warnings[$reason]), "container");
175 if ($available && empty($launch)) {
176 scorm_print_launch($USER, $scorm, 'view.php?id='.$cm->id
, $cm);
178 if (!empty($forcejs)) {
179 echo $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "container forcejavascriptmessage");
182 if (!empty($scorm->popup
)) {
183 $PAGE->requires
->js_init_call('M.mod_scormform.init');
186 echo $OUTPUT->footer();