Fixed last Explorer popup bug and added user score view
[moodle.git] / mod / scorm / view.php
CommitLineData
98ca59f6 1<?PHP // $Id$
2
3/// This page prints a particular instance of scorm
4/// (Replace scorm with the name of your module)
5
6 require_once("../../config.php");
7 require_once("lib.php");
8
9 optional_variable($id); // Course Module ID, or
10 optional_variable($a); // scorm ID
11
12 if ($id) {
13 if (! $cm = get_record("course_modules", "id", $id)) {
14 error("Course Module ID was incorrect");
15 }
16
17 if (! $course = get_record("course", "id", $cm->course)) {
18 error("Course is misconfigured");
19 }
20
21 if (! $scorm = get_record("scorm", "id", $cm->instance)) {
22 error("Course module is incorrect");
23 }
24
25 } else {
26 if (! $scorm = get_record("scorm", "id", $a)) {
27 error("Course module is incorrect");
28 }
29 if (! $course = get_record("course", "id", $scorm->course)) {
30 error("Course is misconfigured");
31 }
32 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
33 error("Course Module ID was incorrect");
34 }
35 }
36
37 require_login($course->id);
38
39
40 $strscorms = get_string("modulenameplural", "scorm");
41 $strscorm = get_string("modulename", "scorm");
42
43 if ($course->category) {
44 $navigation = "<a target=\"{$CFG->framename}\" href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
45 <a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";
46 } else {
47 $navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";
48 }
49
50 $pagetitle = strip_tags("$course->shortname: $scorm->name");
51
52 add_to_log($course->id, "scorm", "pre-view", "view.php?id=$cm->id", "$scorm->id");
53 //
54 // Checking if parsed scorm manifest
55 //
56 if ($scorm->launch == 0) {
57 $basedir = $CFG->dataroot."/".$course->id;
58 $scormdir = "/moddata/scorm";
59 $scorm->launch = scorm_parse($basedir,$scormdir.$scorm->datadir."/imsmanifest.xml",$scorm->id);
60 set_field("scorm","launch",$scorm->launch,"id",$scorm->id);
61 }
62 //
63 // Print the page header
64 //
65 if (!$cm->visible and !isteacher($course->id)) {
66 print_header($pagetitle, "$course->fullname", "$navigation $scorm->name", "", "", true,
67 update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm));
68 notice(get_string("activityiscurrentlyhidden"));
69 } else {
70 print_header($pagetitle, "$course->fullname","$navigation <a target=\"{$CFG->framename}\" href=\"$ME?id=$cm->id\" title=\"$scorm->summary\">$scorm->name</a>",
71 "", "", true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm));
72
73 if (isteacher($course->id)) {
74 if ($sco_users = get_records_select("scorm_sco_users", "scormid='$scorm->id' GROUP BY userid")) {
75 echo "<p align=right><a target=\"{$CFG->framename}\" href=\"report.php?id=$cm->id\">".get_string("viewallreports","scorm",count($sco_users))."</a></p>";
76 } else {
77 echo "<p align=right>".get_string("noreports","scorm")."</p>";
78 }
79 }
80 // Print the main part of the page
81
82 print_heading($scorm->name);
83
84 print_simple_box(text_to_html($scorm->summary), "CENTER");
85
86 if (isguest()) {
87 print_heading(get_string("guestsno", "scorm"));
88 print_footer($course);
89 exit;
90 }
91 echo "<br />";
c5163bfd 92 echo "<style type=\"text/css\">.scormlist { list-style-type:none; }</style>\n";
98ca59f6 93 print_simple_box_start("CENTER");
94 echo "<table>\n";
95 echo " <tr><th>".get_string("coursestruct","scorm")."</th></tr>\n";
76d35423 96 echo " <tr><td nowrap>\n<ul class=\"scormlist\"'>\n";
fc1b2663 97 $incomplete = false;
98ca59f6 98 if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' order by id ASC")){
99 $level=0;
100 $sublist=0;
101 $parents[$level]="/";
98ca59f6 102 foreach ($scoes as $sco) {
103 if ($parents[$level]!=$sco->parent) {
104 if ($level>0 && $parents[$level-1]==$sco->parent) {
76d35423 105 echo " </ul></li>\n";
98ca59f6 106 $level--;
107 } else {
76d35423 108 echo " <li><ul id='".$sublist."' class=\"scormlist\"'>\n";
98ca59f6 109 $level++;
110 $parents[$level]=$sco->parent;
111 }
112 }
113 echo " <li>\n";
114 $nextsco = next($scoes);
fc1b2663 115 if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent != $parents[$level-1])))) {
98ca59f6 116 $sublist++;
117 echo " <img src=\"pix/minus.gif\" onClick='expandCollide(this,".$sublist.");'/>\n";
fc1b2663 118 } else {
98ca59f6 119 echo " <img src=\"pix/spacer.gif\" />\n";
fc1b2663 120 }
98ca59f6 121 if ($sco->launch) {
122 if ($sco_user=get_record("scorm_sco_users","scoid",$sco->id,"userid",$USER->id)) {
123 if ( $sco_user->cmi_core_lesson_status == "")
124 $sco_user->cmi_core_lesson_status = "not attempted";
125 echo " <img src=\"pix/".scorm_remove_spaces($sco_user->cmi_core_lesson_status).".gif\" alt=\"".get_string(scorm_remove_spaces($sco_user->cmi_core_lesson_status),"scorm")."\" title=\"".get_string(scorm_remove_spaces($sco_user->cmi_core_lesson_status),"scorm")."\" />\n";
5d8790cb 126 if (($sco_user->cmi_core_lesson_status == "not attempted") || ($sco_user->cmi_core_lesson_status == "incomplete"))
127 $incomplete = true;
98ca59f6 128 } else {
129 echo " <img src=\"pix/notattempted.gif\" alt=\"".get_string("notattempted","scorm")."\" />";
130 $incomplete = true;
131 }
02f5d439 132 $score = "";
133 if (($sco_user->cmi_core_lesson_status == "passed") || ($sco_user->cmi_core_lesson_status == "failed"))
134 $score = "(".get_string("score","scorm").": ".$sco_user->cmi_core_score_raw.")";
135 echo " &nbsp;<a href=\"javascript:playSCO(".$sco->id.")\">$sco->title</a> $score\n </li>\n";
98ca59f6 136 } else {
137 echo " &nbsp;$sco->title\n </li>\n";
138 }
139 }
c5163bfd 140 for ($i=0;$i<$level;$i++){
76d35423 141 echo " </ul></li>\n";
c5163bfd 142 }
98ca59f6 143 }
c5163bfd 144 echo "</ul></td></tr>\n";
98ca59f6 145 echo "</table>\n";
146 print_simple_box_end();
147 echo "<form name=\"theform\" method=\"POST\" action=\"playscorm.php?id=$cm->id\">\n";
148 echo "<table align=\"CENTER\">\n<tr>\n<td align=\"center\">";
149 print_string("mode","scorm");
150 echo ": <input type=\"radio\" id=\"b\" name=\"mode\" value=\"browse\" /><label for=\"b\">".get_string("browse","scorm")."</label>\n";
fc1b2663 151 if ($incomplete === true) {
98ca59f6 152 echo "<input type=\"radio\" id=\"n\" name=\"mode\" value=\"normal\" checked /><label for=\"n\">".get_string("normal","scorm")."</label>\n";
153 } else {
154 echo "<input type=\"radio\" id=\"r\" name=\"mode\" value=\"review\" checked /><label for=\"r\">".get_string("review","scorm")."</label>\n";
155 }
156 echo "</td>\n</tr>\n<tr><td align=\"center\">";
157 echo '<input type="hidden" name="scoid" />
158 <input type="submit" value="'.get_string("entercourse","scorm").'" />';
159 echo "\n</td>\n</tr>\n</table>\n</form><br />";
160?>
161<script language="javascript">
162<!--
163 function playSCO(scoid,status) {
164 document.theform.scoid.value = scoid;
165 document.theform.submit();
166 }
167
168 function expandCollide(which,list) {
169 var nn=document.ids?true:false
170 var w3c=document.getElementById?true:false
171 var beg=nn?"document.ids.":w3c?"document.getElementById(":"document.all.";
172 var mid=w3c?").style":".style";
173
174 if (eval(beg+list+mid+".display") != "none") {
175 which.src = "pix/plus.gif";
176 eval(beg+list+mid+".display='none';");
177 } else {
178 which.src = "pix/minus.gif";
179 eval(beg+list+mid+".display='block';");
180 }
181
182 }
183-->
184</script>
185<?php
186 print_footer($course);
187 }
188?>