3 function scorm_eval_prerequisites($prerequisites,$usertracks) {
8 'completed' => 'completed',
10 'incomplete' => 'incomplete',
11 'browsed' => 'browsed',
12 'not attempted' => 'notattempted',
21 while ($i<strlen($prerequisites)) {
22 $symbol = $prerequisites[$i];
31 $element = trim($element);
33 if (!empty($element)) {
34 $element = trim($element);
35 if (isset($usertracks[$element])) {
36 $element = '((\''.$usertracks[$element]->status
.'\' == \'completed\') || '.
37 '(\''.$usertracks[$element]->status
.'\' == \'passed\'))';
38 } else if (($operator = strpos($element,'=')) !== false) {
39 $item = trim(substr($element,0,$operator));
40 if (!isset($usertracks[$item])) {
44 $value = trim(trim(substr($element,$operator+
1)),'"');
45 if (isset($statuses[$value])) {
46 $status = $statuses[$value];
51 $element = '(\''.$usertracks[$item]->status
.'\' == \''.$status.'\')';
52 } else if (($operator = strpos($element,'<>')) !== false) {
53 $item = trim(substr($element,0,$operator));
54 if (!isset($usertracks[$item])) {
58 $value = trim(trim(substr($element,$operator+
2)),'"');
59 if (isset($statuses[$value])) {
60 $status = $statuses[$value];
65 $element = '(\''.$usertracks[$item]->status
.'\' != \''.$status.'\')';
66 } else if (is_numeric($element)) {
69 $open = strpos($prerequisites,'{',$i);
72 for ($close=$open+
1; (($opened > $closed) && ($close<strlen($prerequisites))); $close++
) {
73 if ($prerequisites[$close] == '}') {
75 } else if ($prerequisites[$close] == '{') {
81 $setelements = explode(',', substr($prerequisites, $open+
1, $close-($open+
1)-1));
83 foreach ($setelements as $setelement) {
84 if (scorm_eval_prerequisites($setelement,$usertracks)) {
89 if ($settrue >= $element) {
99 array_push($stack,$element);
102 if ($symbol == '~') {
105 if (!empty($symbol)) {
106 array_push($stack,$symbol);
115 if (!empty($element)) {
116 $element = trim($element);
117 if (isset($usertracks[$element])) {
118 $element = '((\''.$usertracks[$element]->status
.'\' == \'completed\') || '.
119 '(\''.$usertracks[$element]->status
.'\' == \'passed\'))';
120 } else if (($operator = strpos($element,'=')) !== false) {
121 $item = trim(substr($element,0,$operator));
122 if (!isset($usertracks[$item])) {
126 $value = trim(trim(substr($element,$operator+
1)),'"');
127 if (isset($statuses[$value])) {
128 $status = $statuses[$value];
133 $element = '(\''.$usertracks[$item]->status
.'\' == \''.$status.'\')';
134 } else if (($operator = strpos($element,'<>')) !== false) {
135 $item = trim(substr($element,0,$operator));
136 if (!isset($usertracks[$item])) {
140 $value = trim(trim(substr($element,$operator+
1)),'"');
141 if (isset($statuses[$value])) {
142 $status = $statuses[$value];
147 $element = '(\''.$usertracks[$item]->status
.'\' != \''.trim($status).'\')';
152 array_push($stack,$element);
154 return eval('return '.implode($stack).';');
157 function scorm_get_toc($user,$scorm,$liststyle,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false) {
160 $strexpand = get_string('expcoll','scorm');
162 if ($mode == 'browse') {
163 $modestr = '&mode='.$mode;
165 $scormpixdir = $CFG->modpixpath
.'/scorm/pix';
167 $result = new stdClass();
168 $result->toc
= "<ul id='s0' class='$liststyle'>\n";
170 $result->prerequisites
= true;
174 // Get the current organization infos
176 $organizationsql = '';
177 if (!empty($currentorg)) {
178 if (($organizationtitle = get_field('scorm_scoes','title','scorm',$scorm->id
,'identifier',$currentorg)) != '') {
179 $result->toc
.= "\t<li>$organizationtitle</li>\n";
180 $tocmenus[] = $organizationtitle;
182 $organizationsql = "AND organization='$currentorg'";
185 // If not specified retrieve the last attempt number
187 if (empty($attempt)) {
188 $attempt = scorm_get_last_attempt($scorm->id
, $user->id
);
190 $result->attemptleft
= $scorm->maxattempt
- $attempt;
191 if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' $organizationsql order by id ASC")){
192 // drop keys so that we can access array sequentially
193 $scoes = array_values($scoes);
195 // Retrieve user tracking data for each learning object
197 $usertracks = array();
198 foreach ($scoes as $sco) {
199 if (!empty($sco->launch
)) {
200 if ($usertrack=scorm_get_tracks($sco->id
,$user->id
,$attempt)) {
201 if ($usertrack->status
== '') {
202 $usertrack->status
= 'notattempted';
204 $usertracks[$sco->identifier
] = $usertrack;
214 $parents[$level]='/';
216 foreach ($scoes as $pos=>$sco) {
218 $sco->title
= stripslashes($sco->title
);
219 if ($optionaldatas = scorm_get_sco($sco->id
, SCO_DATA
)) {
220 if (!isset($optionaldatas->isvisible
) ||
(isset($optionaldatas->isvisible
) && ($optionaldatas->isvisible
== 'true'))) {
227 if ($parents[$level]!=$sco->parent
) {
228 if ($newlevel = array_search($sco->parent
,$parents)) {
229 for ($i=0; $i<($level-$newlevel); $i++
) {
230 $result->toc
.= "\t\t</ul></li>\n";
236 while (($i > 0) && ($parents[$level] != $sco->parent
)) {
237 $closelist .= "\t\t</ul></li>\n";
240 if (($i == 0) && ($sco->parent
!= $currentorg)) {
242 if (isset($_COOKIE['hide:SCORMitem'.$sco->id
])) {
243 $style = ' style="display: none;"';
245 $result->toc
.= "\t\t<li><ul id='s$sublist' class='$liststyle'$style>\n";
248 $result->toc
.= $closelist;
251 $parents[$level]=$sco->parent
;
255 $result->toc
.= "\t\t<li>";
257 if (isset($scoes[$pos+
1])) {
258 $nextsco = $scoes[$pos+
1];
262 $nextisvisible = false;
263 if (($nextsco !== false) && ($optionaldatas = scorm_get_sco($nextsco->id
, SCO_DATA
))) {
264 if (!isset($optionaldatas->isvisible
) ||
(isset($optionaldatas->isvisible
) && ($optionaldatas->isvisible
== 'true'))) {
265 $nextisvisible = true;
268 if ($nextisvisible && ($nextsco !== false) && ($sco->parent
!= $nextsco->parent
) && (($level==0) ||
(($level>0) && ($nextsco->parent
== $sco->identifier
)))) {
271 if (isset($_COOKIE['hide:SCORMitem'.$nextsco->id
])) {
274 $result->toc
.= '<a href="javascript:expandCollide(\'img'.$sublist.'\','.$sublist.','.$nextsco->id
.');"><img id="img'.$sublist.'" src="'.$scormpixdir.'/'.$icon.'.gif" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';
275 // $result->toc .= '<a href="#" onclick="elementToggleHide(\''.$sublist.'\',true);"><img id="img'.$sublist.'" src="'.$scormpixdir.'/'.$icon.'.gif" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';
276 } else if ($isvisible) {
277 $result->toc
.= '<img src="'.$scormpixdir.'/spacer.gif" />';
279 if (empty($sco->title
)) {
280 $sco->title
= $sco->identifier
;
282 if (!empty($sco->launch
)) {
287 if (empty($scoid) && ($mode != 'normal')) {
290 if (isset($usertracks[$sco->identifier
])) {
291 $usertrack = $usertracks[$sco->identifier
];
292 $strstatus = get_string($usertrack->status
,'scorm');
293 if ($sco->scormtype
== 'sco') {
294 $statusicon = '<img src="'.$scormpixdir.'/'.$usertrack->status
.'.gif" alt="'.$strstatus.'" title="'.$strstatus.'" />';
296 $statusicon = '<img src="'.$scormpixdir.'/assetc.gif" alt="'.get_string('assetlaunched','scorm').'" title="'.get_string('assetlaunched','scorm').'" />';
299 if (($usertrack->status
== 'notattempted') ||
($usertrack->status
== 'incomplete') ||
($usertrack->status
== 'browsed')) {
301 if ($play && empty($scoid)) {
305 if ($usertrack->score_raw
!= '') {
306 $score = '('.get_string('score','scorm').': '.$usertrack->score_raw
.')';
308 $strsuspended = get_string('suspended','scorm');
309 if (isset($usertrack->{'cmi.core.exit'}) && ($usertrack->{'cmi.core.exit'} == 'suspend')) {
310 $statusicon = '<img src="'.$scormpixdir.'/suspend.gif" alt="'.$strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
313 if ($play && empty($scoid)) {
317 if ($sco->scormtype
== 'sco') {
318 $statusicon = '<img src="'.$scormpixdir.'/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
320 $statusicon = '<img src="'.$scormpixdir.'/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
323 if ($sco->id
== $scoid) {
324 $scodata = scorm_get_sco($sco->id
, SCO_DATA
);
328 $shownext = isset($scodata->next
) ?
$scodata->next
: 0;
329 $showprev = isset($scodata->previous
) ?
$scodata->previous
: 0;
332 if (($nextid == 0) && (scorm_count_launchable($scorm->id
,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
333 if (!empty($sco->launch
)) {
337 if (empty($sco->prerequisites
) ||
scorm_eval_prerequisites($sco->prerequisites
,$usertracks)) {
338 if ($sco->id
== $scoid) {
339 $result->prerequisites
= true;
341 $url = $CFG->wwwroot
.'/mod/scorm/player.php?a='.$scorm->id
.'&currentorg='.$currentorg.$modestr.'&scoid='.$sco->id
;
342 $result->toc
.= $statusicon.' '.$startbold.'<a href="'.$url.'">'.format_string($sco->title
).'</a>'.$score.$endbold."</li>\n";
343 $tocmenus[$sco->id
] = scorm_repeater('−',$level) . '>' . format_string($sco->title
);
345 if ($sco->id
== $scoid) {
346 $result->prerequisites
= false;
348 $result->toc
.= $statusicon.' '.format_string($sco->title
)."</li>\n";
352 $result->toc
.= ' '.format_string($sco->title
)."</li>\n";
354 if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
355 if (!empty($nextsco->launch
)) {
356 $nextid = $nextsco->id
;
360 for ($i=0;$i<$level;$i++
) {
361 $result->toc
.= "\t\t</ul></li>\n";
365 // it is possible that scoid is still not set, in this case we dont want an empty object
367 $sco = scorm_get_sco($scoid);
369 $sco->previd
= $previd;
370 $sco->nextid
= $nextid;
372 $result->incomplete
= $incomplete;
374 $result->incomplete
= $incomplete;
377 $result->toc
.= "\t</ul>\n";
378 if ($scorm->hidetoc
== 0) {
380 <script type="text/javascript">
382 function expandCollide(which,list,item) {
383 var nn=document.ids?true:false
384 var w3c=document.getElementById?true:false
385 var beg=nn?"document.ids.":w3c?"document.getElementById(":"document.all.";
387 var mid=w3c?").style":".style";
388 which = which.substring(0,(which.length));
390 if (eval(beg+list+mid+".display") != "none") {
391 document.getElementById(which).src = "'.$scormpixdir.'/plus.gif";
392 eval(beg+list+mid+".display=\'none\';");
393 new cookie("hide:SCORMitem" + item, 1, 356, "/").set();
395 document.getElementById(which).src = "'.$scormpixdir.'/minus.gif";
396 eval(beg+list+mid+".display=\'block\';");
397 new cookie("hide:SCORMitem" + item, 1, -1, "/").set();
404 $url = $CFG->wwwroot
.'/mod/scorm/player.php?a='.$scorm->id
.'&currentorg='.$currentorg.$modestr.'&scoid=';
405 $result->tocmenu
= popup_form($url,$tocmenus, "tocmenu", $sco->id
, '', '', '', true);