MDL-19676 Blog improvements
[moodle.git] / mod / scorm / view.php
CommitLineData
f9d5371b 1<?php // $Id$
2
3 require_once("../../config.php");
4 require_once('locallib.php');
5
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
34 require_login($course->id, false, $cm);
35
77bf0c29 36 $context = get_context_instance(CONTEXT_COURSE, $course->id);
0d699c24 37
f9d5371b 38 if (isset($SESSION->scorm_scoid)) {
39 unset($SESSION->scorm_scoid);
40 }
41
42 $strscorms = get_string("modulenameplural", "scorm");
43 $strscorm = get_string("modulename", "scorm");
44
f9d5371b 45 $pagetitle = strip_tags($course->shortname.': '.format_string($scorm->name));
46
5b89dfbb 47 add_to_log($course->id, 'scorm', 'pre-view', 'view.php?id='.$cm->id, "$scorm->id", $cm->id);
f9d5371b 48
8e45ba45 49 if ((has_capability('mod/scorm:skipview', get_context_instance(CONTEXT_MODULE,$cm->id))) && scorm_simple_play($scorm,$USER)) {
50 exit;
51 }
52
f9d5371b 53 //
54 // Print the page header
55 //
01e38388 56 $navlinks = array();
66c7d373 57 $navigation = build_navigation($navlinks, $cm);
afd97d1c 58
59 print_header($pagetitle, $course->fullname, $navigation,
2b3447c3 60 '', '', true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm));
f9d5371b 61
dfe2fbc6 62 if (has_capability('mod/scorm:viewreport', $context)) {
d8c9d8a1 63
64 $trackedusers = scorm_get_count_users($scorm->id, $cm->groupingid);
65 if ($trackedusers > 0) {
9c5ba974 66 echo "<div class=\"reportlink\"><a $CFG->frametarget href=\"report.php?id=$cm->id\"> ".get_string('viewalluserreports','scorm',$trackedusers).'</a></div>';
2b3447c3 67 } else {
68 echo '<div class="reportlink">'.get_string('noreports','scorm').'</div>';
69 }
f9d5371b 70 }
2b3447c3 71
2b3447c3 72 // Print the main part of the page
465f165d 73 echo $OUTPUT->heading(format_string($scorm->name));
6381fa56 74 $attemptstatus = '';
ac3668bf 75 if ($scorm->displayattemptstatus == 1) {
6381fa56 76 $attemptstatus = scorm_get_attempt_status($USER,$scorm);
77 }
6aff538a 78 echo $OUTPUT->box(format_module_intro('scorm', $scorm, $cm->id).$attemptstatus, 'generalbox boxaligncenter boxwidthwide', 'intro');
d54e2145 79
80 $scormopen = true;
81 $timenow = time();
82 if ($scorm->timeclose !=0) {
83 if ($scorm->timeopen > $timenow) {
6aff538a 84 echo $OUTPUT->box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "generalbox boxaligncenter");
d54e2145 85 $scormopen = false;
86 } else if ($timenow > $scorm->timeclose) {
6aff538a 87 echo $OUTPUT->box(get_string("expired", "scorm", userdate($scorm->timeclose)), "generalbox boxaligncenter");
d54e2145 88 $scormopen = false;
89 }
90 }
91 if ($scormopen) {
92 scorm_view_display($USER, $scorm, 'view.php?id='.$cm->id, $cm);
93 }
670bc3e7 94 echo $OUTPUT->footer();
465f165d 95?>