3 function scorm_get_toc($user,$scorm,$liststyle,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false) {
6 $strexpand = get_string('expcoll','scorm');
8 if ($mode == 'browse') {
9 $modestr = '&mode='.$mode;
11 $scormpixdir = $CFG->modpixpath
.'/scorm/pix';
13 $result = new stdClass();
14 $result->toc
= "<ul id='s0' class='$liststyle'>\n";
16 $result->prerequisites
= true;
20 // Get the current organization infos
22 if (!empty($currentorg)) {
23 if (($organizationtitle = get_field('scorm_scoes','title','scorm',$scorm->id
,'identifier',$currentorg)) != '') {
24 $result->toc
.= "\t<li>$organizationtitle</li>\n";
25 $tocmenus[] = $organizationtitle;
29 // If not specified retrieve the last attempt number
31 if (empty($attempt)) {
32 $attempt = scorm_get_last_attempt($scorm->id
, $user->id
);
34 $result->attemptleft
= $scorm->maxattempt
- $attempt;
35 if ($scoes = scorm_get_scoes($scorm->id
, $currentorg)){
37 // Retrieve user tracking data for each learning object
40 $usertracks = array();
41 foreach ($scoes as $sco) {
42 if (!empty($sco->launch
)) {
43 if ($usertrack = scorm_get_tracks($sco->id
,$user->id
,$attempt)) {
44 if ($usertrack->status
== '') {
45 $usertrack->status
= 'notattempted';
47 $usertracks[$sco->identifier
] = $usertrack;
58 foreach ($scoes as $pos => $sco) {
60 $sco->title
= stripslashes($sco->title
);
61 if (!isset($sco->isvisible
) ||
(isset($sco->isvisible
) && ($sco->isvisible
== 'true'))) {
64 if ($parents[$level]!=$sco->parent
) {
65 if ($newlevel = array_search($sco->parent
,$parents)) {
66 for ($i=0; $i<($level-$newlevel); $i++
) {
67 $result->toc
.= "\t\t</ul></li>\n";
73 while (($i > 0) && ($parents[$level] != $sco->parent
)) {
74 $closelist .= "\t\t</ul></li>\n";
77 if (($i == 0) && ($sco->parent
!= $currentorg)) {
79 if (isset($_COOKIE['hide:SCORMitem'.$sco->id
])) {
80 $style = ' style="display: none;"';
82 $result->toc
.= "\t\t<li><ul id='s$sublist' class='$liststyle'$style>\n";
85 $result->toc
.= $closelist;
88 $parents[$level]=$sco->parent
;
91 if (isset($scoes[$pos+
1])) {
92 $nextsco = $scoes[$pos+
1];
96 $nextisvisible = false;
97 if (!isset($nextsco->isvisible
) ||
(isset($nextsco->isvisible
) && ($nextsco->isvisible
== 'true'))) {
98 $nextisvisible = true;
100 if ($nextisvisible && ($nextsco !== false) && ($sco->parent
!= $nextsco->parent
) &&
101 (($level==0) ||
(($level>0) && ($nextsco->parent
== $sco->identifier
)))) {
104 if (isset($_COOKIE['hide:SCORMitem'.$nextsco->id
])) {
107 $result->toc
.= "\t\t".'<li><a href="javascript:expandCollide(\'img'.$sublist.'\',\'s'.$sublist.'\','.$nextsco->id
.');">'.
108 '<img id="img'.$sublist.'" src="'.$scormpixdir.'/'.$icon.'.gif" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';
109 } else if ($isvisible) {
110 $result->toc
.= "\t\t".'<li><img src="'.$scormpixdir.'/spacer.gif" />';
112 if (empty($sco->title
)) {
113 $sco->title
= $sco->identifier
;
115 if (!empty($sco->launch
)) {
120 if (empty($scoid) && ($mode != 'normal')) {
123 if (isset($usertracks[$sco->identifier
])) {
124 $usertrack = $usertracks[$sco->identifier
];
125 $strstatus = get_string($usertrack->status
,'scorm');
126 if ($sco->scormtype
== 'sco') {
127 $statusicon = '<img src="'.$scormpixdir.'/'.$usertrack->status
.'.gif" alt="'.$strstatus.'" title="'.$strstatus.'" />';
129 $statusicon = '<img src="'.$scormpixdir.'/assetc.gif" alt="'.get_string('assetlaunched','scorm').'" title="'.get_string('assetlaunched','scorm').'" />';
132 if (($usertrack->status
== 'notattempted') ||
($usertrack->status
== 'incomplete') ||
($usertrack->status
== 'browsed')) {
134 if ($play && empty($scoid)) {
138 if ($usertrack->score_raw
!= '') {
139 $score = '('.get_string('score','scorm').': '.$usertrack->score_raw
.')';
141 $strsuspended = get_string('suspended','scorm');
142 if (isset($usertrack->{'cmi.core.exit'}) && ($usertrack->{'cmi.core.exit'} == 'suspend')) {
143 if($usertrack->status
!='completed') {
144 $statusicon = '<img src="'.$scormpixdir.'/suspend.gif" alt="'.$strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
148 if ($play && empty($scoid)) {
151 if ($sco->scormtype
== 'sco') {
152 $statusicon = '<img src="'.$scormpixdir.'/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
155 $statusicon = '<img src="'.$scormpixdir.'/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
159 if ($sco->id
== $scoid) {
163 $shownext = isset($sco->next
) ?
$sco->next
: 0;
164 $showprev = isset($sco->prev
) ?
$sco->prev
: 0;
167 if (($nextid == 0) && (scorm_count_launchable($scorm->id
,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
168 if (!empty($sco->launch
)) {
172 require_once('sequencinglib.php');
173 if (scorm_seq_evaluate($sco->id
,$usertracks)) {
174 if ($sco->id
== $scoid) {
175 $result->prerequisites
= true;
177 $url = $CFG->wwwroot
.'/mod/scorm/player.php?a='.$scorm->id
.'&currentorg='.$currentorg.$modestr.'&scoid='.$sco->id
;
178 $result->toc
.= $statusicon.' '.$startbold.'<a href="'.$url.'">'.format_string($sco->title
).'</a>'.$score.$endbold."</li>\n";
179 $tocmenus[$sco->id
] = scorm_repeater('−',$level) . '>' . format_string($sco->title
);
181 if ($sco->id
== $scoid) {
182 $result->prerequisites
= false;
184 $result->toc
.= ' '.format_string($sco->title
)."</li>\n";
188 $result->toc
.= ' '.format_string($sco->title
)."</li>\n";
190 if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
191 if (!empty($nextsco->launch
)) {
192 $nextid = $nextsco->id
;
196 for ($i=0;$i<$level;$i++
) {
197 $result->toc
.= "\t\t</ul></li>\n";
201 $sco = get_record('scorm_scoes','id',$scoid);
202 $sco->previd
= $previd;
203 $sco->nextid
= $nextid;
205 $result->incomplete
= $incomplete;
207 $result->incomplete
= $incomplete;
210 $result->toc
.= "\t</ul>\n";
211 if ($scorm->hidetoc
== 0) {
213 <script type="text/javascript">
215 function expandCollide(which,list,item) {
216 var el = document.ids ? document.ids[list] : document.getElementById ? document.getElementById(list) : document.all[list];
217 which = which.substring(0,(which.length));
218 var el2 = document.ids ? document.ids[which] : document.getElementById ? document.getElementById(which) : document.all[which];
219 if (el.style.display != "none") {
220 el2.src = "'.$scormpixdir.'/plus.gif";
221 el.style.display=\'none\';
222 new cookie("hide:SCORMitem" + item, 1, 356, "/").set();
224 el2.src = "'.$scormpixdir.'/minus.gif";
225 el.style.display=\'block\';
226 new cookie("hide:SCORMitem" + item, 1, -1, "/").set();
233 $url = $CFG->wwwroot
.'/mod/scorm/player.php?a='.$scorm->id
.'&currentorg='.$currentorg.$modestr.'&scoid=';
234 $result->tocmenu
= popup_form($url,$tocmenus, "tocmenu", $sco->id
, '', '', '', true);