f0d29bbd05493d64e5655a1396fdc60860f1e06d
[moodle.git] / mod / scorm / playscorm.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
11     optional_variable($frameset, "");
13     if ($id) {
14         if (! $cm = get_record("course_modules", "id", $id)) {
15             error("Course Module ID was incorrect");
16         }
17     
18         if (! $course = get_record("course", "id", $cm->course)) {
19             error("Course is misconfigured");
20         }
21     
22         if (! $scorm = get_record("scorm", "id", $cm->instance)) {
23             error("Course module is incorrect");
24         }
26     } else {
27         if (! $scorm = get_record("scorm", "id", $a)) {
28             error("Course module is incorrect");
29         }
30         if (! $course = get_record("course", "id", $scorm->course)) {
31             error("Course is misconfigured");
32         }
33         if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
34             error("Course Module ID was incorrect");
35         }
36     }
38     require_login($course->id);
40     
41     $strscorms = get_string("modulenameplural", "scorm");
42     $strscorm  = get_string("modulename", "scorm");
43         
44     if ($course->category) {
45         $navigation = "<a target=\"{$CFG->framename}\" href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
46                        <a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";
47     } else {
48         $navigation = "<a target=\"{$CFG->framename}\" href=\"index.php?id=$course->id\">$strscorms</a> ->";
49     }
51     $pagetitle = strip_tags("$course->shortname: $scorm->name");
53     if (!$cm->visible and !isteacher($course->id)) {
54         print_header($pagetitle, "$course->fullname", "$navigation $scorm->name", "", "", true, 
55                      update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm));
56         notice(get_string("activityiscurrentlyhidden"));
57     }
58     
59     if (!empty($_POST["scoid"]))
60             $scoid = "&scoid=".$_POST["scoid"];
61     if (($scorm->popup != "") && (!empty($_POST["mode"])))
62         $mode = $_POST["mode"];
63     if (($scorm->popup == "") && (!empty($_GET["mode"])))
64         $mode = $_GET["mode"];
65     
66     if (($frameset == "top") || ($scorm->popup != "")) {
67         add_to_log($course->id, "scorm", "view", "playscorm.php?id=$cm->id", "$scorm->id");
68         //
69         // Print the page header
70         //
71         print_header($pagetitle, "$course->fullname",
72                 "$navigation <a target=\"{$CFG->framename}\" href=\"view.php?id=$cm->id\" title=\"$scorm->summary\">$scorm->name</a>",
73                 "", "", true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm, '_top'));
74         
75         echo "<table width=\"100%\">\n    <tr><td align=\"center\">".text_to_html($scorm->summary, true, false)."</td>\n";
76         if ($mode == "browse")
77             echo "<td align=\"right\" width=\"10%\" nowrap>".get_string("browsemode","scorm")."</td>\n";
78         echo "     </tr>\n</table>\n";
79         
80         if ($scorm->popup != "") {
81             echo "<script id=\"scormAPI\" language=\"JavaScript\" type=\"text/javascript\" src=\"scormAPI.php?id=$cm->id&mode=".$mode.$scoid."\"></script>\n";
82             $currentSCO = "";
83             if (!empty($_POST['scoid']))
84                 $currentSCO = $_POST['scoid'];
85         ?>
86             <br />
87             <script language="Javascript">
88             <!--
89                 function playSCO(scoid) {
90                     document.navform.scoid.value=scoid;
91                     document.navform.submit();
92                 }
93                 
94                 function expandCollide(which,list) {
95                     var nn=document.ids?true:false
96                     var w3c=document.getElementById?true:false
97                     var beg=nn?"document.ids.":w3c?"document.getElementById(":"document.all.";
98                     var mid=w3c?").style":".style";
99         
100                     if (eval(beg+list+mid+".display") != "none") {
101                         which.src = "pix/plus.gif";
102                         eval(beg+list+mid+".display='none';");
103                     } else {
104                         which.src = "pix/minus.gif";
105                         eval(beg+list+mid+".display='block';");
106                     }
107         
108                 }
109             -->
110             </script>
111             <style type="text/css">
112                 .scormlist { list-style-type:none; }
113             </style>
114         <?php
115             print_simple_box_start("CENTER");
116             echo "<table>\n";
117             echo "  <tr><th>".get_string("coursestruct","scorm")."</th></tr>\n";
118             echo "  <tr><td nowrap>\n<ul class=\"scormlist\"'>\n";
119             $incomplete = false;
120             if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' order by id ASC")){
121                 $level=0;
122                 $sublist=0;
123                 $parents[$level]="/";
124                 foreach ($scoes as $sco) {
125                     if ($parents[$level]!=$sco->parent) {
126                         if ($level>0 && $parents[$level-1]==$sco->parent) {
127                             echo "  </ul></li>\n";
128                             $level--;
129                         } else {
130                             echo "  <li><ul id='".$sublist."' class=\"scormlist\"'>\n";
131                             $level++;
132                             $parents[$level]=$sco->parent;
133                         }
134                     }
135                     echo "    <li>\n";
136                     $nextsco = next($scoes);
137                     if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent != $parents[$level-1])))) {
138                         $sublist++;
139                         echo "      <img src=\"pix/minus.gif\" onClick='expandCollide(this,".$sublist.");'/>\n";
140                     } else {
141                         echo "      <img src=\"pix/spacer.gif\" />\n";
142                     }
143                     
144                     if ($sco->launch) {
145                         $startbold = '';
146                         $endbold = '';
147                         if ($sco->id == $currentSCO) {
148                             $startbold = '-> <b><u>';
149                             $endbold = '</u></b> <-';
150                         }
151                         if ($sco_user=get_record("scorm_sco_users","scoid",$sco->id,"userid",$USER->id)) {
152                             if ( $sco_user->cmi_core_lesson_status == "")
153                                 $sco_user->cmi_core_lesson_status = "not attempted";
154                             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";
155                             if (($sco_user->cmi_core_lesson_status == "not attempted") || ($sco_user->cmi_core_lesson_status == "incomplete")) {
156                                 if ($currentSCO == "") {
157                                     $incomplete = true;
158                                     $currentSCO = $sco->id;
159                                     $startbold = '-> <b><u>';
160                                     $endbold = '</u></b> <-';
161                                 }
162                             }
163                         } else {
164                             echo "      <img src=\"pix/notattempted.gif\" alt=\"".get_string("notattempted","scorm")."\" />";
165                             $incomplete = true;
166                         }
167                         echo "      &nbsp;$startbold<a href=\"javascript:playSCO(".$sco->id.");\">$sco->title</a>$endbold\n    </li>\n";
168                     } else {
169                         echo "      &nbsp;$sco->title\n    </li>\n";
170                     }
171                 }
172                 for ($i=0;$i<$level;$i++){
173                     echo "  </ul></li>\n";
174                 }
175             }
176             echo "</ul></td></tr>\n";
177             echo "</table>\n";
178             print_simple_box_end();
179             
180         }
181             
182         echo "<table width=\"100%\">\n    <tr>\n";
183         echo "          <td align=\"center\" nowrap>
184                      <iframe name=\"cmi\" width=\"1\" height=\"1\" src=\"cmi.php?id=$cm->id\" style=\"visibility: hidden;\"></iframe>
185                      <form name=\"navform\" method=\"POST\" action=\"playscorm.php?id=$cm->id\" target=\"_top\">
186                         <input name=\"scoid\" type=\"hidden\" />
187                         <input name=\"mode\" type=\"hidden\" value=\"".$mode."\" />
188                         <input name=\"prev\" type=\"button\" value=\"".get_string("prev","scorm")."\" onClick=\"top.changeSco('prev');\" />&nbsp;\n";
189                         
190         if ($scorm->popup == "") {
191             if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' order by id ASC")){
192                 $level=0;                       
193                 $parents[$level]="/";
194                 foreach ($scoes as $sco) {
195                     if ($parents[$level]!=$sco->parent) {
196                         if ($level>0 && $parents[$level-1]==$sco->parent) {
197                             $level--;
198                         } else {
199                             $level++;
200                             $parents[$level]=$sco->parent;
201                         }
202                     }
203                     $indenting = "";
204                     for ($i=0;$i<$level;$i++) {
205                         $indenting .= "-";
206                     }
207                     $options[$sco->id] = $indenting."&gt; ".$sco->title;
208                 }
209             }
210             choose_from_menu($options, "courseStructure", "", "", "document.navform.scoid.value=document.navform.courseStructure.options[document.navform.courseStructure.selectedIndex].value;document.navform.submit();");
211         }
212         echo "          &nbsp;<input name=\"next\" type=\"button\" value=\"".get_string("next","scorm")."\" onClick=\"top.changeSco('next')\" />\n";
213         echo "       </form>
214                 </td>\n";
215         
216         echo "</tr>\n</table>\n";
217         
218         if ($scorm->popup != "") {
219         ?>
220             <script language="Javascript">
221                 top.main = window.open('','main','<?php echo $scorm->popup ?>');
222                 SCOInitialize();
223             </script>
224         <?php
225         }
226         
227         echo "</body>\n</html>\n";
228     } else {
229         if ($scorm->popup == "") {
230             // 
231             // Frameset
232             //
233             echo "<html>\n";
234             echo "<head><title>$course->shortname: $scorm->name</title></head>\n";
235             echo "<script id=\"scormAPI\" language=\"JavaScript\" type=\"text/javascript\" src=\"scormAPI.php?id=$cm->id&mode=".$mode.$scoid."\"></script>\n";
236             echo "<frameset rows=\"$CFG->scorm_framesize,*\" onLoad=\"SCOInitialize();\">\n";
237             echo "          <frame name=\"nav\" src=\"playscorm.php?id=$cm->id&mode=".$mode."&frameset=top\">\n";
238             echo "          <frame name=\"main\" src=\"\">\n";
239             echo "</frameset>\n";
240             echo "</html>\n";
241         }
242     }
243 ?>