Putting SCORM into maintree CVS, to make it easier to test.
[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         }
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         }
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);
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     }
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
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         print_simple_box_start("CENTER");
93         echo "<table>\n";
94         echo "  <tr><th>".get_string("coursestruct","scorm")."</th></tr>\n";
95         echo "  <tr><td nowrap>\n<ul compact style='list-style-type:none'>\n";
96         if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' order by id ASC")){
97             $level=0;
98             $sublist=0;
99             $parents[$level]="/";
100             $incomplete=false;
101             foreach ($scoes as $sco) {
102                 if ($parents[$level]!=$sco->parent) {
103                     if ($level>0 && $parents[$level-1]==$sco->parent) {
104                         echo "  </ul>\n";
105                         $level--;
106                     } else {
107                         echo "  <ul id='".$sublist."'compact style='list-style-type:none;'>\n";
108                         $level++;
109                         $parents[$level]=$sco->parent;
110                     }
111                 }
112                 echo "    <li>\n";
113                 $nextsco = next($scoes);
114                 if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && ($nextsco->parent != $parents[$level-1])) {
115                     $sublist++;
116                     echo "      <img src=\"pix/minus.gif\" onClick='expandCollide(this,".$sublist.");'/>\n";
117                 } else
118                     echo "      <img src=\"pix/spacer.gif\" />\n";
119                 if ($sco->launch) {
120                     if ($sco_user=get_record("scorm_sco_users","scoid",$sco->id,"userid",$USER->id)) {
121                         if ( $sco_user->cmi_core_lesson_status == "")
122                             $sco_user->cmi_core_lesson_status = "not attempted";
123                         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";
124                         switch ($sco_user->cmi_core_lesson_status) {
125                                 case "not attempted":
126                                 case "incomplete":
127                                 case "browsed":
128                                     $incomplete = true;
129                         }
130                     } else {
131                         echo "      <img src=\"pix/notattempted.gif\" alt=\"".get_string("notattempted","scorm")."\" />";
132                         $incomplete = true;
133                     }
134                     echo "      &nbsp;<a href=\"javascript:playSCO(".$sco->id.")\">$sco->title</a>\n    </li>\n";
135                 } else {
136                     echo "      &nbsp;$sco->title\n    </li>\n";
137                 }
138             }
139         }
140         echo "</ul>\n</td></tr>\n";
141         echo "</table>\n";
142         print_simple_box_end();
143         echo "<form name=\"theform\" method=\"POST\" action=\"playscorm.php?id=$cm->id\">\n";
144         echo "<table align=\"CENTER\">\n<tr>\n<td align=\"center\">";
145         print_string("mode","scorm");
146         echo ": <input type=\"radio\" id=\"b\" name=\"mode\" value=\"browse\" /><label for=\"b\">".get_string("browse","scorm")."</label>\n";
147         if ($incomplete) {
148             echo "<input type=\"radio\" id=\"n\" name=\"mode\" value=\"normal\" checked /><label for=\"n\">".get_string("normal","scorm")."</label>\n";
149         } else {
150             echo "<input type=\"radio\" id=\"r\" name=\"mode\" value=\"review\" checked /><label for=\"r\">".get_string("review","scorm")."</label>\n";
151         }
152         echo "</td>\n</tr>\n<tr><td align=\"center\">";
153         echo '<input type="hidden" name="scoid" />
154         <input type="submit" value="'.get_string("entercourse","scorm").'" />';
155         echo "\n</td>\n</tr>\n</table>\n</form><br />";
156 ?>
157 <script language="javascript">
158 <!--
159     function playSCO(scoid,status) {
160         document.theform.scoid.value = scoid;
161         document.theform.submit();
162     }
163     
164     function expandCollide(which,list) {
165         var nn=document.ids?true:false
166         var w3c=document.getElementById?true:false
167         var beg=nn?"document.ids.":w3c?"document.getElementById(":"document.all.";
168         var mid=w3c?").style":".style";
169         
170         if (eval(beg+list+mid+".display") != "none") {
171             which.src = "pix/plus.gif";
172             eval(beg+list+mid+".display='none';");
173         } else {
174             which.src = "pix/minus.gif";
175             eval(beg+list+mid+".display='block';");
176         }
177         
178     }
179 -->
180 </script>
181 <?php
182         print_footer($course);
183     }
184 ?>