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")){
39 // Retrieve user tracking data for each learning object
42 $usertracks = array();
43 $optionaldatas = array();
44 foreach ($scoes as $sco) {
45 if (!empty($sco->launch
)) {
46 if ($usertrack=scorm_get_tracks($sco->id
,$user->id
,$attempt)) {
47 if ($usertrack->status
== '') {
48 $usertrack->status
= 'notattempted';
50 $usertracks[$sco->identifier
] = $usertrack;
52 if ($optionaldata = scorm_get_sco($sco->id
, SCO_DATA
)) {
53 $optionaldatas[$sco->identifier
] = $optionaldata;
64 foreach ($scoes as $sco) {
66 if (isset($optionaldatas[$sco->identifier
])) {
67 if (!isset($optionaldatas[$sco->identifier
]->isvisible
) ||
68 (isset($optionaldatas[$sco->identifier
]->isvisible
) && ($optionaldatas[$sco->identifier
]->isvisible
== 'true'))) {
72 if ($parents[$level]!=$sco->parent
) {
73 if ($newlevel = array_search($sco->parent
,$parents)) {
74 for ($i=0; $i<($level-$newlevel); $i++
) {
75 $result->toc
.= "\t\t</ul></li>\n";
81 while (($i > 0) && ($parents[$level] != $sco->parent
)) {
82 $closelist .= "\t\t</ul></li>\n";
85 if (($i == 0) && ($sco->parent
!= $currentorg)) {
87 if (isset($_COOKIE['hide:SCORMitem'.$sco->id
])) {
88 $style = ' style="display: none;"';
90 $result->toc
.= "\t\t<li><ul id='s$sublist' class='$liststyle'$style>\n";
93 $result->toc
.= $closelist;
96 $parents[$level]=$sco->parent
;
99 $nextsco = next($scoes);
100 $nextisvisible = false;
101 if (($nextsco !== false) && (isset($optionaldatas[$nextsco->identifier
]))) {
102 if (!isset($optionaldatas[$nextsco->identifier
]->isvisible
) ||
103 (isset($optionaldatas[$nextsco->identifier
]->isvisible
) && ($optionaldatas[$nextsco->identifier
]->isvisible
== 'true'))) {
104 $nextisvisible = true;
107 if ($nextisvisible && ($nextsco !== false) && ($sco->parent
!= $nextsco->parent
) &&
108 (($level==0) ||
(($level>0) && ($nextsco->parent
== $sco->identifier
)))) {
111 if (isset($_COOKIE['hide:SCORMitem'.$nextsco->id
])) {
114 $result->toc
.= "\t\t".'<li><a href="javascript:expandCollide(img'.$sublist.',s'.$sublist.','.$nextsco->id
.');">'.
115 '<img id="img'.$sublist.'" src="'.$scormpixdir.'/'.$icon.'.gif" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';
116 } else if ($isvisible) {
117 $result->toc
.= "\t\t".'<li><img src="'.$scormpixdir.'/spacer.gif" />';
119 if (empty($sco->title
)) {
120 $sco->title
= $sco->identifier
;
122 if (!empty($sco->launch
)) {
127 if (empty($scoid) && ($mode != 'normal')) {
130 if (isset($usertracks[$sco->identifier
])) {
131 $usertrack = $usertracks[$sco->identifier
];
132 $strstatus = get_string($usertrack->status
,'scorm');
133 if ($sco->scormtype
== 'sco') {
134 $statusicon = '<img src="'.$scormpixdir.'/'.$usertrack->status
.'.gif" alt="'.$strstatus.'" title="'.$strstatus.'" />';
136 $statusicon = '<img src="'.$scormpixdir.'/assetc.gif" alt="'.get_string('assetlaunched','scorm').'" title="'.get_string('assetlaunched','scorm').'" />';
139 if (($usertrack->status
== 'notattempted') ||
($usertrack->status
== 'incomplete') ||
($usertrack->status
== 'browsed')) {
141 if ($play && empty($scoid)) {
145 if ($usertrack->score_raw
!= '') {
146 $score = '('.get_string('score','scorm').': '.$usertrack->score_raw
.')';
148 $strsuspended = get_string('suspended','scorm');
149 if (isset($usertrack->{'cmi.core.exit'}) && ($usertrack->{'cmi.core.exit'} == 'suspend')) {
150 $statusicon = '<img src="'.$scormpixdir.'/suspend.gif" alt="'.$strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
153 if ($play && empty($scoid)) {
156 if ($sco->scormtype
== 'sco') {
157 $statusicon = '<img src="'.$scormpixdir.'/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
160 $statusicon = '<img src="'.$scormpixdir.'/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
164 if ($sco->id
== $scoid) {
168 $shownext = isset($optionaldatas[$sco->identifier
]->next
) ?
$optionaldatas[$sco->identifier
]->next
: 0;
169 $showprev = isset($optionaldatas[$sco->identifier
]->prev
) ?
$optionaldatas[$sco->identifier
]->prev
: 0;
172 if (($nextid == 0) && (scorm_count_launchable($scorm->id
,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
173 if (!empty($sco->launch
)) {
177 require_once('sequencinglib.php');
178 if (scorm_seq_evaluate($sco->id
,$usertracks)) {
179 if ($sco->id
== $scoid) {
180 $result->prerequisites
= true;
182 $url = $CFG->wwwroot
.'/mod/scorm/player.php?a='.$scorm->id
.'&currentorg='.$currentorg.$modestr.'&scoid='.$sco->id
;
183 $result->toc
.= $statusicon.' '.$startbold.'<a href="'.$url.'">'.format_string($sco->title
).'</a>'.$score.$endbold."</li>\n";
184 $tocmenus[$sco->id
] = scorm_repeater('−',$level) . '>' . format_string($sco->title
);
186 if ($sco->id
== $scoid) {
187 $result->prerequisites
= false;
189 $result->toc
.= ' '.format_string($sco->title
)."</li>\n";
193 $result->toc
.= ' '.format_string($sco->title
)."</li>\n";
195 if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
196 if (!empty($nextsco->launch
)) {
197 $nextid = $nextsco->id
;
201 for ($i=0;$i<$level;$i++
) {
202 $result->toc
.= "\t\t</ul></li>\n";
206 $sco = get_record('scorm_scoes','id',$scoid);
207 $sco->previd
= $previd;
208 $sco->nextid
= $nextid;
210 $result->incomplete
= $incomplete;
212 $result->incomplete
= $incomplete;
215 $result->toc
.= "\t</ul>\n";
216 if ($scorm->hidetoc
== 0) {
218 <script type="text/javascript">
220 function expandCollide(which,list,item) {
221 var nn=document.ids?true:false
222 var w3c=document.getElementById?true:false
223 var beg=nn?"document.ids.":w3c?"document.getElementById(":"document.all.";
224 var mid=w3c?").style":".style";
226 if (eval(beg+list+mid+".display") != "none") {
227 which.src = "'.$scormpixdir.'/plus.gif";
228 eval(beg+list+mid+".display=\'none\';");
229 new cookie("hide:SCORMitem" + item, 1, 356, "/").set();
231 which.src = "'.$scormpixdir.'/minus.gif";
232 eval(beg+list+mid+".display=\'block\';");
233 new cookie("hide:SCORMitem" + item, 1, -1, "/").set();
240 $url = $CFG->wwwroot
.'/mod/scorm/player.php?a='.$scorm->id
.'&currentorg='.$currentorg.$modestr.'&scoid=';
241 $result->tocmenu
= popup_form($url,$tocmenus, "tocmenu", $sco->id
, '', '', '', true);