MDL-21694 usin new core_subsystesm() in renderers too; adding more docs
[moodle.git] / mod / scorm / view.php
CommitLineData
5c508e3f 1<?php
f9d5371b 2
3 require_once("../../config.php");
4 require_once('locallib.php');
e5dd8e3b 5
f9d5371b 6 $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
7 $a = optional_param('a', '', PARAM_INT); // scorm ID
0d699c24 8 $organization = optional_param('organization', '', PARAM_INT); // organization ID
f9d5371b 9
10 if (!empty($id)) {
0d699c24 11 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
08b56f93 12 print_error('invalidcoursemodule');
f9d5371b 13 }
bf347041 14 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
08b56f93 15 print_error('coursemisconf');
f9d5371b 16 }
bf347041 17 if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) {
08b56f93 18 print_error('invalidcoursemodule');
f9d5371b 19 }
20 } else if (!empty($a)) {
bf347041 21 if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
08b56f93 22 print_error('invalidcoursemodule');
f9d5371b 23 }
bf347041 24 if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) {
08b56f93 25 print_error('coursemisconf');
f9d5371b 26 }
27 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
08b56f93 28 print_error('invalidcoursemodule');
f9d5371b 29 }
30 } else {
08b56f93 31 print_error('missingparameter');
f9d5371b 32 }
33
a6855934 34 $url = new moodle_url('/mod/scorm/view.php', array('id'=>$cm->id));
5c508e3f 35 if ($organization !== '') {
36 $url->param('organization', $organization);
37 }
38 $PAGE->set_url($url);
e5dd8e3b 39
f9d5371b 40 require_login($course->id, false, $cm);
41
77bf0c29 42 $context = get_context_instance(CONTEXT_COURSE, $course->id);
0d699c24 43
f9d5371b 44 if (isset($SESSION->scorm_scoid)) {
45 unset($SESSION->scorm_scoid);
46 }
47
48 $strscorms = get_string("modulenameplural", "scorm");
49 $strscorm = get_string("modulename", "scorm");
50
f9d5371b 51 $pagetitle = strip_tags($course->shortname.': '.format_string($scorm->name));
52
5b89dfbb 53 add_to_log($course->id, 'scorm', 'pre-view', 'view.php?id='.$cm->id, "$scorm->id", $cm->id);
f9d5371b 54
8e45ba45 55 if ((has_capability('mod/scorm:skipview', get_context_instance(CONTEXT_MODULE,$cm->id))) && scorm_simple_play($scorm,$USER)) {
56 exit;
57 }
58
f9d5371b 59 //
60 // Print the page header
61 //
52869011 62 $PAGE->set_title($pagetitle);
63 $PAGE->set_heading($course->fullname);
52869011 64 echo $OUTPUT->header();
f9d5371b 65
dfe2fbc6 66 if (has_capability('mod/scorm:viewreport', $context)) {
e5dd8e3b 67
d8c9d8a1 68 $trackedusers = scorm_get_count_users($scorm->id, $cm->groupingid);
69 if ($trackedusers > 0) {
4aea3cc7 70 echo "<div class=\"reportlink\"><a href=\"report.php?id=$cm->id\"> ".get_string('viewalluserreports','scorm',$trackedusers).'</a></div>';
2b3447c3 71 } else {
72 echo '<div class="reportlink">'.get_string('noreports','scorm').'</div>';
73 }
f9d5371b 74 }
2b3447c3 75
2b3447c3 76 // Print the main part of the page
465f165d 77 echo $OUTPUT->heading(format_string($scorm->name));
6381fa56 78 $attemptstatus = '';
ac3668bf 79 if ($scorm->displayattemptstatus == 1) {
6381fa56 80 $attemptstatus = scorm_get_attempt_status($USER,$scorm);
81 }
6aff538a 82 echo $OUTPUT->box(format_module_intro('scorm', $scorm, $cm->id).$attemptstatus, 'generalbox boxaligncenter boxwidthwide', 'intro');
e5dd8e3b 83
d54e2145 84 $scormopen = true;
85 $timenow = time();
86 if ($scorm->timeclose !=0) {
87 if ($scorm->timeopen > $timenow) {
6aff538a 88 echo $OUTPUT->box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "generalbox boxaligncenter");
d54e2145 89 $scormopen = false;
90 } else if ($timenow > $scorm->timeclose) {
6aff538a 91 echo $OUTPUT->box(get_string("expired", "scorm", userdate($scorm->timeclose)), "generalbox boxaligncenter");
d54e2145 92 $scormopen = false;
93 }
94 }
95 if ($scormopen) {
96 scorm_view_display($USER, $scorm, 'view.php?id='.$cm->id, $cm);
97 }
670bc3e7 98 echo $OUTPUT->footer();
e5dd8e3b 99