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