MDL-20700 coding style cleanup - cvs keywords removed, closign php tag removed, trail...
[moodle.git] / mod / scorm / view.php
CommitLineData
5c508e3f 1<?php
f9d5371b 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
5c508e3f 34 $url = new moodle_url($CFG->wwwroot.'/mod/scorm/view.php', array('id'=>$cm->id));
35 if ($organization !== '') {
36 $url->param('organization', $organization);
37 }
38 $PAGE->set_url($url);
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);
5c508e3f 64 $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'scorm'));
52869011 65 echo $OUTPUT->header();
f9d5371b 66
dfe2fbc6 67 if (has_capability('mod/scorm:viewreport', $context)) {
d8c9d8a1 68
69 $trackedusers = scorm_get_count_users($scorm->id, $cm->groupingid);
70 if ($trackedusers > 0) {
9c5ba974 71 echo "<div class=\"reportlink\"><a $CFG->frametarget href=\"report.php?id=$cm->id\"> ".get_string('viewalluserreports','scorm',$trackedusers).'</a></div>';
2b3447c3 72 } else {
73 echo '<div class="reportlink">'.get_string('noreports','scorm').'</div>';
74 }
f9d5371b 75 }
2b3447c3 76
2b3447c3 77 // Print the main part of the page
465f165d 78 echo $OUTPUT->heading(format_string($scorm->name));
6381fa56 79 $attemptstatus = '';
ac3668bf 80 if ($scorm->displayattemptstatus == 1) {
6381fa56 81 $attemptstatus = scorm_get_attempt_status($USER,$scorm);
82 }
6aff538a 83 echo $OUTPUT->box(format_module_intro('scorm', $scorm, $cm->id).$attemptstatus, 'generalbox boxaligncenter boxwidthwide', 'intro');
d54e2145 84
85 $scormopen = true;
86 $timenow = time();
87 if ($scorm->timeclose !=0) {
88 if ($scorm->timeopen > $timenow) {
6aff538a 89 echo $OUTPUT->box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "generalbox boxaligncenter");
d54e2145 90 $scormopen = false;
91 } else if ($timenow > $scorm->timeclose) {
6aff538a 92 echo $OUTPUT->box(get_string("expired", "scorm", userdate($scorm->timeclose)), "generalbox boxaligncenter");
d54e2145 93 $scormopen = false;
94 }
95 }
96 if ($scormopen) {
97 scorm_view_display($USER, $scorm, 'view.php?id='.$cm->id, $cm);
98 }
670bc3e7 99 echo $OUTPUT->footer();
465f165d 100?>