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 $organizationsql = '';
23 if (!empty($currentorg)) {
24 if (($organizationtitle = get_field('scorm_scoes','title','scorm',$scorm->id
,'identifier',$currentorg)) != '') {
25 $result->toc
.= "\t<li>$organizationtitle</li>\n";
26 $tocmenus[] = $organizationtitle;
28 $organizationsql = "AND organization='$currentorg'";
31 // If not specified retrieve the last attempt number
33 if (empty($attempt)) {
34 $attempt = scorm_get_last_attempt($scorm->id
, $user->id
);
36 $result->attemptleft
= $scorm->maxattempt
- $attempt;
37 if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' $organizationsql order by id ASC")){
38 // drop keys so that we can access array sequentially
39 $scoes = array_values($scoes);
41 // Retrieve user tracking data for each learning object
44 $usertracks = array();
45 $optionaldatas = array();
46 foreach ($scoes as $sco) {
47 if (!empty($sco->launch
)) {
48 if ($usertrack=scorm_get_tracks($sco->id
,$user->id
,$attempt)) {
49 if ($usertrack->status
== '') {
50 $usertrack->status
= 'notattempted';
52 $usertracks[$sco->identifier
] = $usertrack;
54 if ($optionaldata = scorm_get_sco($sco->id
, SCO_DATA
)) {
55 $optionaldatas[$sco->identifier
] = $optionaldata;
66 foreach ($scoes as $pos=>$sco) {
68 $sco->title
= stripslashes($sco->title
);
69 if (isset($optionaldatas[$sco->identifier
])) {
70 if (!isset($optionaldatas[$sco->identifier
]->isvisible
) ||
71 (isset($optionaldatas[$sco->identifier
]->isvisible
) && ($optionaldatas[$sco->identifier
]->isvisible
== 'true'))) {
75 if ($parents[$level]!=$sco->parent
) {
76 if ($newlevel = array_search($sco->parent
,$parents)) {
77 for ($i=0; $i<($level-$newlevel); $i++
) {
78 $result->toc
.= "\t\t</ul></li>\n";
84 while (($i > 0) && ($parents[$level] != $sco->parent
)) {
85 $closelist .= "\t\t</ul></li>\n";
88 if (($i == 0) && ($sco->parent
!= $currentorg)) {
90 if (isset($_COOKIE['hide:SCORMitem'.$sco->id
])) {
91 $style = ' style="display: none;"';
93 $result->toc
.= "\t\t<li><ul id='s$sublist' class='$liststyle'$style>\n";
96 $result->toc
.= $closelist;
99 $parents[$level]=$sco->parent
;
102 if (isset($scoes[$pos+
1])) {
103 $nextsco = $scoes[$pos+
1];
107 $nextisvisible = false;
108 if (($nextsco !== false) && (isset($optionaldatas[$nextsco->identifier
]))) {
109 if (!isset($optionaldatas[$nextsco->identifier
]->isvisible
) ||
110 (isset($optionaldatas[$nextsco->identifier
]->isvisible
) && ($optionaldatas[$nextsco->identifier
]->isvisible
== 'true'))) {
111 $nextisvisible = true;
114 if ($nextisvisible && ($nextsco !== false) && ($sco->parent
!= $nextsco->parent
) &&
115 (($level==0) ||
(($level>0) && ($nextsco->parent
== $sco->identifier
)))) {
118 if (isset($_COOKIE['hide:SCORMitem'.$nextsco->id
])) {
121 $result->toc
.= "\t\t".'<li><a href="javascript:expandCollide(\'img'.$sublist.'\',\'s'.$sublist.'\','.$nextsco->id
.');">'.
122 '<img id="img'.$sublist.'" src="'.$scormpixdir.'/'.$icon.'.gif" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';
123 } else if ($isvisible) {
124 $result->toc
.= "\t\t".'<li><img src="'.$scormpixdir.'/spacer.gif" />';
126 if (empty($sco->title
)) {
127 $sco->title
= $sco->identifier
;
129 if (!empty($sco->launch
)) {
134 if (empty($scoid) && ($mode != 'normal')) {
137 if (isset($usertracks[$sco->identifier
])) {
138 $usertrack = $usertracks[$sco->identifier
];
139 $strstatus = get_string($usertrack->status
,'scorm');
140 if ($sco->scormtype
== 'sco') {
141 $statusicon = '<img src="'.$scormpixdir.'/'.$usertrack->status
.'.gif" alt="'.$strstatus.'" title="'.$strstatus.'" />';
143 $statusicon = '<img src="'.$scormpixdir.'/assetc.gif" alt="'.get_string('assetlaunched','scorm').'" title="'.get_string('assetlaunched','scorm').'" />';
146 if (($usertrack->status
== 'notattempted') ||
($usertrack->status
== 'incomplete') ||
($usertrack->status
== 'browsed')) {
148 if ($play && empty($scoid)) {
152 if ($usertrack->score_raw
!= '') {
153 $score = '('.get_string('score','scorm').': '.$usertrack->score_raw
.')';
155 $strsuspended = get_string('suspended','scorm');
156 if (isset($usertrack->{'cmi.core.exit'}) && ($usertrack->{'cmi.core.exit'} == 'suspend')) {
157 $statusicon = '<img src="'.$scormpixdir.'/suspend.gif" alt="'.$strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
160 if ($play && empty($scoid)) {
163 if ($sco->scormtype
== 'sco') {
164 $statusicon = '<img src="'.$scormpixdir.'/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
167 $statusicon = '<img src="'.$scormpixdir.'/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
171 if ($sco->id
== $scoid) {
175 $shownext = isset($optionaldatas[$sco->identifier
]->next
) ?
$optionaldatas[$sco->identifier
]->next
: 0;
176 $showprev = isset($optionaldatas[$sco->identifier
]->prev
) ?
$optionaldatas[$sco->identifier
]->prev
: 0;
179 if (($nextid == 0) && (scorm_count_launchable($scorm->id
,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
180 if (!empty($sco->launch
)) {
184 require_once('sequencinglib.php');
185 if (scorm_seq_evaluate($sco->id
,$usertracks)) {
186 if ($sco->id
== $scoid) {
187 $result->prerequisites
= true;
189 $url = $CFG->wwwroot
.'/mod/scorm/player.php?a='.$scorm->id
.'&currentorg='.$currentorg.$modestr.'&scoid='.$sco->id
;
190 $result->toc
.= $statusicon.' '.$startbold.'<a href="'.$url.'">'.format_string($sco->title
).'</a>'.$score.$endbold."</li>\n";
191 $tocmenus[$sco->id
] = scorm_repeater('−',$level) . '>' . format_string($sco->title
);
193 if ($sco->id
== $scoid) {
194 $result->prerequisites
= false;
196 $result->toc
.= ' '.format_string($sco->title
)."</li>\n";
200 $result->toc
.= ' '.format_string($sco->title
)."</li>\n";
202 if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
203 if (!empty($nextsco->launch
)) {
204 $nextid = $nextsco->id
;
208 for ($i=0;$i<$level;$i++
) {
209 $result->toc
.= "\t\t</ul></li>\n";
213 $sco = get_record('scorm_scoes','id',$scoid);
214 $sco->previd
= $previd;
215 $sco->nextid
= $nextid;
217 $result->incomplete
= $incomplete;
219 $result->incomplete
= $incomplete;
222 $result->toc
.= "\t</ul>\n";
223 if ($scorm->hidetoc
== 0) {
225 <script type="text/javascript">
227 function expandCollide(which,list,item) {
228 var nn=document.ids?true:false
229 var w3c=document.getElementById?true:false
230 var beg=nn?"document.ids.":w3c?"document.getElementById(\'":"document.all.";
231 var mid=w3c?"\').style":".style";
233 which = which.substring(0,(which.length));
234 if (eval(beg+list+mid+".display") != "none") {
235 document.getElementById(which).src = "'.$scormpixdir.'/plus.gif";
236 eval(beg+list+mid+".display=\'none\';");
237 new cookie("hide:SCORMitem" + item, 1, 356, "/").set();
239 document.getElementById(which).src = "'.$scormpixdir.'/minus.gif";
240 eval(beg+list+mid+".display=\'block\';");
241 new cookie("hide:SCORMitem" + item, 1, -1, "/").set();
248 $url = $CFG->wwwroot
.'/mod/scorm/player.php?a='.$scorm->id
.'&currentorg='.$currentorg.$modestr.'&scoid=';
249 $result->tocmenu
= popup_form($url,$tocmenus, "tocmenu", $sco->id
, '', '', '', true);