Added multiorg display and patched some typo
[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         echo "<style type=\"text/css\">.scormlist { list-style-type:none; }</style>\n";
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>\n<ul class=\"scormlist\"'>\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='".$sublist."' class=\"scormlist\"'>\n";
135                             $level++;
136                         } else {
137                             echo $closelist;
138                             $level = $i;
139                         }
140                         $parents[$level]=$sco->parent;
141                     }
142                 } 
143                 
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,".$sublist.");'/>\n";
149                 } else {
150                     echo "      <img src=\"pix/spacer.gif\" />\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                         echo "      <img src=\"pix/notattempted.gif\" alt=\"".get_string("notattempted","scorm")."\" />";
167                         $incomplete = true;
168                     }
169                     echo "      &nbsp;<a href=\"javascript:playSCO(".$sco->id.")\">$sco->title</a> $score\n    </li>\n";
170                 } else {
171                     echo "      &nbsp;$sco->title\n    </li>\n";
172                 }
173             }
174             for ($i=0;$i<$level;$i++){
175                  echo "  </ul></li>\n";
176             }
177         }
178         echo "</ul></td></tr>\n";
179         echo "</table>\n";
180         print_simple_box_end();
181         echo "<form name=\"theform\" method=\"POST\" action=\"playscorm.php?id=$cm->id\">\n";
182         echo "<table align=\"CENTER\">\n<tr>\n<td align=\"center\">";
183         print_string("mode","scorm");
184         echo ": <input type=\"radio\" id=\"b\" name=\"mode\" value=\"browse\" /><label for=\"b\">".get_string("browse","scorm")."</label>\n";
185         if ($incomplete === true) {
186             echo "<input type=\"radio\" id=\"n\" name=\"mode\" value=\"normal\" checked /><label for=\"n\">".get_string("normal","scorm")."</label>\n";
187         } else {
188             echo "<input type=\"radio\" id=\"r\" name=\"mode\" value=\"review\" checked /><label for=\"r\">".get_string("review","scorm")."</label>\n";
189         }
190         echo "</td>\n</tr>\n<tr><td align=\"center\">";
191         echo '<input type="hidden" name="scoid" />
192         <input type="hidden" name="currentorg" value="'.$orgidentifier.'" />
193         <input type="submit" value="'.get_string("entercourse","scorm").'" />';
194         echo "\n</td>\n</tr>\n</table>\n</form><br />";
195 ?>
196 <script language="javascript">
197 <!--
198     function playSCO(scoid,status) {
199         document.theform.scoid.value = scoid;
200         document.theform.submit();
201     }
202     
203     function expandCollide(which,list) {
204         var nn=document.ids?true:false
205         var w3c=document.getElementById?true:false
206         var beg=nn?"document.ids.":w3c?"document.getElementById(":"document.all.";
207         var mid=w3c?").style":".style";
208         
209         if (eval(beg+list+mid+".display") != "none") {
210             which.src = "pix/plus.gif";
211             eval(beg+list+mid+".display='none';");
212         } else {
213             which.src = "pix/minus.gif";
214             eval(beg+list+mid+".display='block';");
215         }
216         
217     }
218 -->
219 </script>
220 <?php
221         print_footer($course);
222     }
223 ?>