First step for SCORM2004, new communication subsystem
[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, false, $cm);
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     //
55     // Print the page header
56     //
57     if (!$cm->visible and !isteacher($course->id)) {
58         print_header($pagetitle, "$course->fullname", "$navigation $scorm->name", "", "", true, 
59                      update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm));
60         notice(get_string("activityiscurrentlyhidden"));
61     } else {
62         print_header($pagetitle, "$course->fullname","$navigation <a target=\"{$CFG->framename}\" href=\"$ME?id=$cm->id\" title=\"$scorm->summary\">$scorm->name</a>",
63                  "", "", true, update_module_button($cm->id, $course->id, $strscorm), navmenu($course, $cm));
64         
65         if (isteacher($course->id)) {
66             if ($sco_users = get_records_select("scorm_sco_users", "scormid='$scorm->id' GROUP BY userid")) {
67                 echo "<p align=\"right\"><a target=\"{$CFG->framename}\" href=\"report.php?id=$cm->id\">".get_string("viewallreports","scorm",count($sco_users))."</a></p>";
68             } else {
69                 echo "<p align=\"right\">".get_string("noreports","scorm")."</p>";
70             }
71         }
72         // Print the main part of the page
74         print_heading($scorm->name);
76         print_simple_box(text_to_html($scorm->summary), "center");
78         if (isguest()) {
79             print_heading(get_string("guestsno", "scorm"));
80             print_footer($course);
81             exit;
82         }
83         echo "<br />";
84         $liststyle = "style=\"list-style-type:none;\"";
85         print_simple_box_start("center");
86         echo "<table>\n";
87         echo "  <tr><th>".get_string("coursestruct","scorm")."</th></tr>\n";
88         $organization = $scorm->launch;
89         if ($orgs = get_records_select_menu('scorm_scoes',"scorm='$scorm->id' AND organization='' AND launch=''",'id','id,title')) {
90             if (count($orgs) > 1) {
91                 if (isset($_POST['organization'])) {
92                     $organization = $_POST['organization'];
93                 }
94                 echo "<tr><td align='center'><form name='changeorg' method='post' action='view.php?id=$cm->id'>".get_string('organizations','scorm').": \n";
95                 choose_from_menu($orgs, 'organization', "$organization", '','submit()');
96                 echo "</form></td></tr>\n"; 
97             }
98         }
99         $orgidentifier = '';
100         if ($org = get_record('scorm_scoes','id',$organization)) {
101             if (($org->organization == '') && ($org->launch == '')) {
102                 $orgidentifier = $org->identifier;
103             } else {
104                 $orgidentifier = $org->organization;
105             }
106         }
107         echo "  <tr><td nowrap=\"nowrap\">\n<ul $liststyle>\n";
108         $incomplete = false;
109         if ($scoes = get_records_select("scorm_scoes","scorm='$scorm->id' AND organization='$orgidentifier' order by id ASC")){
110             $level=0;
111             $sublist=0;
112             $parents[$level]="/";
113             foreach ($scoes as $sco) {
114                 if ($parents[$level]!=$sco->parent) {
115                     if ($level>0 && $parents[$level-1]==$sco->parent) {
116                         echo "  </ul></li>\n";
117                         $level--;
118                     } else {
119                         $i = $level;
120                         $closelist = "";
121                         while (($i > 0) && ($parents[$level] != $sco->parent)) {
122                             $closelist .= "  </ul></li>\n";
123                             $i--;
124                         }
125                         if (($i == 0) && ($sco->parent != $orgidentifier)) {
126                             echo "  <li><ul id='s".$sublist."' $liststyle>\n";
127                             $level++;
128                         } else {
129                             echo $closelist;
130                             $level = $i;
131                         }
132                         $parents[$level]=$sco->parent;
133                     }
134                 } 
135                 
136                 echo "    <li>\n";
137                 $nextsco = next($scoes);
138                 if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
139                     $sublist++;
140                     echo "      <img src=\"pix/minus.gif\" onclick='expandCollide(this,\"s".$sublist."\");' alt=\"-\" title=\"".get_string('collide','scorm')."\" />\n";
141                 } else {
142                     echo "      <img src=\"pix/spacer.gif\" alt=\" \" />\n";
143                 }
144                 if ($sco->launch) {
145                     $score = "";
146                     if ($sco_user=get_record("scorm_sco_users","scoid",$sco->id,"userid",$USER->id)) {
147                         if ( $sco_user->cmi_core_lesson_status == "") {
148                             $sco_user->cmi_core_lesson_status = "not attempted";
149                         }
150                         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";
151                         if (($sco_user->cmi_core_lesson_status == "not attempted") || ($sco_user->cmi_core_lesson_status == "incomplete")) {
152                             $incomplete = true;
153                         }
154                         if ($sco_user->cmi_core_score_raw > 0) {
155                             $score = "(".get_string("score","scorm").":&nbsp;".$sco_user->cmi_core_score_raw.")";
156                         }
157                     } else {
158                         if ($sco->type == 'sco') {
159                             echo "      <img src=\"pix/notattempted.gif\" alt=\"".get_string("notattempted","scorm")."\" title=\"".get_string("notattempted","scorm")."\" />";
160                             $incomplete = true;
161                         } else {
162                             echo "      <img src=\"pix/asset.gif\" alt=\"".get_string("asset","scorm")."\" title=\"".get_string("asset","scorm")."\" />";
163                         }
164                     }
165                     echo "      &nbsp;<a href=\"javascript:playSCO(".$sco->id.")\">$sco->title</a> $score\n    </li>\n";
166                 } else {
167                     echo "      &nbsp;$sco->title\n    </li>\n";
168                 }
169             }
170             for ($i=0;$i<$level;$i++){
171                  echo "  </ul></li>\n";
172             }
173         }
174         echo "</ul></td></tr>\n";
175         echo "</table>\n";
176         print_simple_box_end();
177         echo "<form name=\"theform\" method=\"post\" action=\"playscorm.php?id=$cm->id\">\n";
178         echo "<table align=\"center\">\n<tr>\n<td align=\"center\">";
179         print_string("mode","scorm");
180         echo ": <input type=\"radio\" id=\"b\" name=\"mode\" value=\"browse\" /><label for=\"b\">".get_string("browse","scorm")."</label>\n";
181         if ($incomplete === true) {
182             echo "<input type=\"radio\" id=\"n\" name=\"mode\" value=\"normal\" checked=\"checked\" /><label for=\"n\">".get_string("normal","scorm")."</label>\n";
183         } else {
184             echo "<input type=\"radio\" id=\"r\" name=\"mode\" value=\"review\" checked=\"checked\" /><label for=\"r\">".get_string("review","scorm")."</label>\n";
185         }
186         echo "</td>\n</tr>\n<tr><td align=\"center\">";
187         echo '<input type="hidden" name="scoid" />
188         <input type="hidden" name="currentorg" value="'.$orgidentifier.'" />
189         <input type="submit" value="'.get_string("entercourse","scorm").'" />';
190         echo "\n</td>\n</tr>\n</table>\n</form><br />";
191 ?>
192 <script language="javascript" type="text/javascript">
193 <!--
194     function playSCO(scoid,status) {
195         document.theform.scoid.value = scoid;
196         document.theform.submit();
197     }
198     
199     function expandCollide(which,list) {
200         var nn=document.ids?true:false
201         var w3c=document.getElementById?true:false
202         var beg=nn?"document.ids.":w3c?"document.getElementById('":"document.all.";
203         var mid=w3c?"').style":".style";
204         
205         if (eval(beg+list+mid+".display") != "none") {
206             which.src = "pix/plus.gif";
207             which.alt = "+";
208             which.title = "<?php echo get_string('expand','scorm') ?>";
209             eval(beg+list+mid+".display='none';");
210         } else {
211             which.src = "pix/minus.gif";
212             which.alt = "-";
213             which.title = "<?php echo get_string('collide','scorm') ?>";
214             eval(beg+list+mid+".display='block';");
215         }
216         
217     }
218 -->
219 </script>
220 <?php
221         print_footer($course);
222     }
223 ?>