MDL-28649 SCORM fix force new attempt when skipview is used
[moodle.git] / mod / scorm / view.php
CommitLineData
5c508e3f 1<?php
f7b5c6aa
DM
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
17require_once("../../config.php");
18require_once($CFG->dirroot.'/mod/scorm/locallib.php');
19
20$id = optional_param('id', '', PARAM_INT); // Course Module ID, or
21$a = optional_param('a', '', PARAM_INT); // scorm ID
22$organization = optional_param('organization', '', PARAM_INT); // organization ID
23
24if (!empty($id)) {
25 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
26 print_error('invalidcoursemodule');
f9d5371b 27 }
f7b5c6aa
DM
28 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
29 print_error('coursemisconf');
6381fa56 30 }
f7b5c6aa
DM
31 if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) {
32 print_error('invalidcoursemodule');
bd803ac7 33 }
f7b5c6aa
DM
34} else if (!empty($a)) {
35 if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
36 print_error('invalidcoursemodule');
d54e2145 37 }
f7b5c6aa
DM
38 if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) {
39 print_error('coursemisconf');
d54e2145 40 }
f7b5c6aa
DM
41 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
42 print_error('invalidcoursemodule');
30bce58e 43 }
f7b5c6aa
DM
44} else {
45 print_error('missingparameter');
46}
47
48$url = new moodle_url('/mod/scorm/view.php', array('id'=>$cm->id));
49if ($organization !== '') {
50 $url->param('organization', $organization);
51}
52$PAGE->set_url($url);
53$forcejs = get_config('scorm', 'forcejavascript');
54if (!empty($forcejs)) {
55 $PAGE->add_body_class('forcejavascript');
56}
57
58require_login($course->id, false, $cm);
59
60$context = get_context_instance(CONTEXT_COURSE, $course->id);
61$contextmodule = get_context_instance(CONTEXT_MODULE, $cm->id);
62
63if (isset($SESSION->scorm_scoid)) {
64 unset($SESSION->scorm_scoid);
65}
66
67$strscorms = get_string("modulenameplural", "scorm");
68$strscorm = get_string("modulename", "scorm");
69
70$pagetitle = strip_tags($course->shortname.': '.format_string($scorm->name));
71
72add_to_log($course->id, 'scorm', 'pre-view', 'view.php?id='.$cm->id, "$scorm->id", $cm->id);
73
4201a746 74if ((has_capability('mod/scorm:skipview', $contextmodule))) {
666efc14 75 scorm_simple_play($scorm, $USER, $contextmodule, $cm->id);
f7b5c6aa
DM
76}
77
78//
79// Print the page header
80//
81$PAGE->set_title($pagetitle);
82$PAGE->set_heading($course->fullname);
83echo $OUTPUT->header();
84
85$currenttab = 'info';
86require($CFG->dirroot . '/mod/scorm/tabs.php');
87
88// Print the main part of the page
89echo $OUTPUT->heading(format_string($scorm->name));
90$attemptstatus = '';
91if ($scorm->displayattemptstatus == 1) {
92 $attemptstatus = scorm_get_attempt_status($USER, $scorm);
93}
94echo $OUTPUT->box(format_module_intro('scorm', $scorm, $cm->id).$attemptstatus, 'generalbox boxaligncenter boxwidthwide', 'intro');
95
96$scormopen = true;
97$timenow = time();
98if (!empty($scorm->timeopen) && $scorm->timeopen > $timenow) {
99 echo $OUTPUT->box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "generalbox boxaligncenter");
100 $scormopen = false;
101}
102if (!empty($scorm->timeclose) && $timenow > $scorm->timeclose) {
103 echo $OUTPUT->box(get_string("expired", "scorm", userdate($scorm->timeclose)), "generalbox boxaligncenter");
104 $scormopen = false;
105}
106if ($scormopen) {
107 scorm_view_display($USER, $scorm, 'view.php?id='.$cm->id, $cm);
108}
109if (!empty($forcejs)) {
110 echo $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "generalbox boxaligncenter forcejavascriptmessage");
111}
112echo $OUTPUT->footer();