7da65b563f4728838edf454911d1f5cd76d2e0e8
[moodle.git] / mod / scorm / view.php
1 <?php  // $Id$
3 /// This page prints a particular instance of scorm
4 /// (Replace scorm with the name of your module)
6     require_once("../../config.php");
7     require_once("lib.php");
9     optional_variable($id);    // Course Module ID, or
10     optional_variable($a);     // scorm ID
12     if ($id) {
13         if (! $cm = get_record("course_modules", "id", $id)) {
14             error("Course Module ID was incorrect");
15         }
17         if (! $course = get_record("course", "id", $cm->course)) {
18             error("Course is misconfigured");
19         }
21         if (! $scorm = get_record("scorm", "id", $cm->instance)) {
22             error("Course module is incorrect");
23         }
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     }
37     require_login($course->id, false, $cm);
40     $strscorms = get_string("modulenameplural", "scorm");
41     $strscorm  = get_string("modulename", "scorm");
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     }
50     $pagetitle = strip_tags("$course->shortname: $scorm->name");
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));
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
82         print_heading($scorm->name);
84         print_simple_box(text_to_html($scorm->summary), "center");
86         if (isguest()) {
87             print_heading(get_string("guestsno", "scorm"));
88             print_footer($course);
89             exit;
90         }
91         echo "<br />";
92         $liststyle = "style=\"list-style-type:none;\"";
93         print_simple_box_start("center");
94         echo "<table>\n";
95         echo "  <tr><th>".get_string("coursestruct","scorm")."</th></tr>\n";
96     $organization = $scorm->launch;
97     if ($orgs = get_records_select_menu('scorm_scoes',"scorm='$scorm->id' AND organization='' AND launch=''",'id','id,title')) {
98         if (count($orgs) > 1) {
99         if (isset($_POST['organization'])) {
100             $organization = $_POST['organization'];
101         }
102         echo "<tr><td align='center'><form name='changeorg' method='post' action='view.php?id=$cm->id'>".get_string('organizations','scorm').": \n";
103         choose_from_menu($orgs, 'organization', "$organization", '','submit()');
104         echo "</form></td></tr>\n";
105         }
106     }
107     $orgidentifier = '';
108     if ($org = get_record('scorm_scoes','id',$organization)) {
109         if (($org->organization == '') && ($org->launch == '')) {
110             $orgidentifier = $org->identifier;
111         } else {
112             $orgidentifier = $org->organization;
113         }
114     }
115         echo "  <tr><td nowrap=\"nowrap\">\n<ul $liststyle>\n";
116         $incomplete = false;
117         if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' AND organization='$orgidentifier' order by id ASC")){
118         $level=0;
119             $sublist=0;
120             $parents[$level]="/";
121             foreach ($scoes as $sco) {
122             if ($parents[$level]!=$sco->parent) {
123                 if ($level>0 && $parents[$level-1]==$sco->parent) {
124                 echo "  </ul></li>\n";
125                 $level--;
126                 } else {
127                 $i = $level;
128                 $closelist = "";
129                 while (($i > 0) && ($parents[$level] != $sco->parent)) {
130                     $closelist .= "  </ul></li>\n";
131                     $i--;
132                 }
133                 if (($i == 0) && ($sco->parent != $orgidentifier)) {
134                     echo "  <li><ul id='s".$sublist."' $liststyle>\n";
135                     $level++;
136                 } else {
137                     echo $closelist;
138                     $level = $i;
139                 }
140                 $parents[$level]=$sco->parent;
141                 }
142             }
144             echo "    <li>\n";
145             $nextsco = next($scoes);
146             if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
147                 $sublist++;
148                 echo "      <img src=\"pix/minus.gif\" onclick='expandCollide(this,\"s".$sublist."\");' alt=\"-\" title=\"".get_string('collide','scorm')."\" />\n";
149             } else {
150                 echo "      <img src=\"pix/spacer.gif\" alt=\" \" />\n";
151             }
152             if ($sco->launch) {
153                 $score = "";
154                 if ($sco_user=get_record("scorm_sco_users","scoid",$sco->id,"userid",$USER->id)) {
155                     if ( $sco_user->cmi_core_lesson_status == "") {
156                         $sco_user->cmi_core_lesson_status = "not attempted";
157                     }
158                 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";
159             if (($sco_user->cmi_core_lesson_status == "not attempted") || ($sco_user->cmi_core_lesson_status == "incomplete")) {
160                 $incomplete = true;
161             }
162             if ($sco_user->cmi_core_score_raw > 0) {
163                     $score = "(".get_string("score","scorm").":&nbsp;".$sco_user->cmi_core_score_raw.")";
164                     }
165                 } else {
166                 if ($sco->type == 'sco') {
167                     echo "      <img src=\"pix/notattempted.gif\" alt=\"".get_string("notattempted","scorm")."\" title=\"".get_string("notattempted","scorm")."\" />";
168                     $incomplete = true;
169                 } else {
170                     echo "      <img src=\"pix/asset.gif\" alt=\"".get_string("asset","scorm")."\" title=\"".get_string("asset","scorm")."\" />";
171                 }
172                 }
173                 echo "      &nbsp;<a href=\"javascript:playSCO(".$sco->id.")\">$sco->title</a> $score\n    </li>\n";
174             } else {
175             echo "      &nbsp;$sco->title\n    </li>\n";
176         }
177         }
178         for ($i=0;$i<$level;$i++){
179              echo "  </ul></li>\n";
180         }
181     }
182     echo "</ul></td></tr>\n";
183         echo "</table>\n";
184         print_simple_box_end();
185         echo "<form name=\"theform\" method=\"post\" action=\"playscorm.php?id=$cm->id\">\n";
186         echo "<table align=\"center\">\n<tr>\n<td align=\"center\">";
187         print_string("mode","scorm");
188         echo ": <input type=\"radio\" id=\"b\" name=\"mode\" value=\"browse\" /><label for=\"b\">".get_string("browse","scorm")."</label>\n";
189         if ($incomplete === true) {
190             echo "<input type=\"radio\" id=\"n\" name=\"mode\" value=\"normal\" checked=\"checked\" /><label for=\"n\">".get_string("normal","scorm")."</label>\n";
191         } else {
192             echo "<input type=\"radio\" id=\"r\" name=\"mode\" value=\"review\" checked=\"checked\" /><label for=\"r\">".get_string("review","scorm")."</label>\n";
193     }
194     echo "</td>\n</tr>\n<tr><td align=\"center\">";
195     echo '<input type="hidden" name="scoid" />
196     <input type="hidden" name="currentorg" value="'.$orgidentifier.'" />
197     <input type="submit" value="'.get_string("entercourse","scorm").'" />';
198         echo "\n</td>\n</tr>\n</table>\n</form><br />";
199 ?>
200 <script language="javascript" type="text/javascript">
201 <!--
202     function playSCO(scoid,status) {
203         document.theform.scoid.value = scoid;
204         document.theform.submit();
205     }
207     function expandCollide(which,list) {
208         var nn=document.ids?true:false
209     var w3c=document.getElementById?true:false
210     var beg=nn?"document.ids.":w3c?"document.getElementById('":"document.all.";
211     var mid=w3c?"').style":".style";
213         if (eval(beg+list+mid+".display") != "none") {
214             which.src = "pix/plus.gif";
215             which.alt = "+";
216             which.title = "<?php echo get_string('expand','scorm') ?>";
217             eval(beg+list+mid+".display='none';");
218         } else {
219             which.src = "pix/minus.gif";
220             which.alt = "-";
221             which.title = "<?php echo get_string('collide','scorm') ?>";
222             eval(beg+list+mid+".display='block';");
223         }
225     }
226 -->
227 </script>
228 <?php
229         print_footer($course);
230     }
231 ?>