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 $conditions = array();
23 if (!empty($currentorg)) {
24 if (($organizationtitle = $DB->get_field('scorm_scoes', 'title', array('scorm'=>$scorm->id,'identifier'=>$currentorg))) != '') {
25 $result->toc .= "\t<li>$organizationtitle</li>\n";
26 $tocmenus[] = $organizationtitle;
28 $conditions['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 $conditions['scorm'] = $scorm->id;
38 if ($scoes = $DB->get_records('scorm_scoes', $conditions, "id ASC")){
39 // drop keys so that we can access array sequentially
40 $scoes = array_values($scoes);
42 // Retrieve user tracking data for each learning object
45 $usertracks = array();
46 $optionaldatas = array();
47 foreach ($scoes as $sco) {
48 if (!empty($sco->launch)) {
49 if ($usertrack=scorm_get_tracks($sco->id,$user->id,$attempt)) {
50 if ($usertrack->status == '') {
51 $usertrack->status = 'notattempted';
53 $usertracks[$sco->identifier] = $usertrack;
55 if ($optionaldata = scorm_get_sco($sco->id, SCO_DATA)) {
56 $optionaldatas[$sco->identifier] = $optionaldata;
67 foreach ($scoes as $pos=>$sco) {
69 $sco->title = $sco->title;
70 if (isset($optionaldatas[$sco->identifier])) {
71 if (!isset($optionaldatas[$sco->identifier]->isvisible) ||
72 (isset($optionaldatas[$sco->identifier]->isvisible) && ($optionaldatas[$sco->identifier]->isvisible == 'true'))) {
76 if ($parents[$level]!=$sco->parent) {
77 if ($newlevel = array_search($sco->parent,$parents)) {
78 for ($i=0; $i<($level-$newlevel); $i++) {
79 $result->toc .= "\t\t</ul></li>\n";
85 while (($i > 0) && ($parents[$level] != $sco->parent)) {
86 $closelist .= "\t\t</ul></li>\n";
89 if (($i == 0) && ($sco->parent != $currentorg)) {
91 if (isset($_COOKIE['hide:SCORMitem'.$sco->id])) {
92 $style = ' style="display: none;"';
94 $result->toc .= "\t\t<li><ul id='s$sublist' class='$liststyle'$style>\n";
97 $result->toc .= $closelist;
100 $parents[$level]=$sco->parent;
103 if (isset($scoes[$pos+1])) {
104 $nextsco = $scoes[$pos+1];
108 $nextisvisible = false;
109 if (($nextsco !== false) && (isset($optionaldatas[$nextsco->identifier]))) {
110 if (!isset($optionaldatas[$nextsco->identifier]->isvisible) ||
111 (isset($optionaldatas[$nextsco->identifier]->isvisible) && ($optionaldatas[$nextsco->identifier]->isvisible == 'true'))) {
112 $nextisvisible = true;
115 if ($nextisvisible && ($nextsco !== false) && ($sco->parent != $nextsco->parent) &&
116 (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
119 if (isset($_COOKIE['hide:SCORMitem'.$nextsco->id])) {
122 $result->toc .= "\t\t".'<li><a href="javascript:expandCollide(\'img'.$sublist.'\',\'s'.$sublist.'\','.$nextsco->id.');">'.
123 '<img id="img'.$sublist.'" src="'.$scormpixdir.'/'.$icon.'.gif" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';
124 } else if ($isvisible) {
125 $result->toc .= "\t\t".'<li><img src="'.$scormpixdir.'/spacer.gif" />';
127 if (empty($sco->title)) {
128 $sco->title = $sco->identifier;
130 if (!empty($sco->launch)) {
135 if (empty($scoid) && ($mode != 'normal')) {
138 if (isset($usertracks[$sco->identifier])) {
139 $usertrack = $usertracks[$sco->identifier];
140 $strstatus = get_string($usertrack->status,'scorm');
141 if ($sco->scormtype == 'sco') {
142 $statusicon = '<img src="'.$scormpixdir.'/'.$usertrack->status.'.gif" alt="'.$strstatus.'" title="'.$strstatus.'" />';
144 $statusicon = '<img src="'.$scormpixdir.'/assetc.gif" alt="'.get_string('assetlaunched','scorm').'" title="'.get_string('assetlaunched','scorm').'" />';
147 if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {
149 if ($play && empty($scoid)) {
153 if ($usertrack->score_raw != '') {
154 $score = '('.get_string('score','scorm').': '.$usertrack->score_raw.')';
156 $strsuspended = get_string('suspended','scorm');
157 if (isset($usertrack->{'cmi.core.exit'}) && ($usertrack->{'cmi.core.exit'} == 'suspend')) {
158 $statusicon = '<img src="'.$scormpixdir.'/suspend.gif" alt="'.$strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
161 if ($play && empty($scoid)) {
164 if ($sco->scormtype == 'sco') {
165 $statusicon = '<img src="'.$scormpixdir.'/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
168 $statusicon = '<img src="'.$scormpixdir.'/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
172 if ($sco->id == $scoid) {
176 $shownext = isset($optionaldatas[$sco->identifier]->next) ? $optionaldatas[$sco->identifier]->next : 0;
177 $showprev = isset($optionaldatas[$sco->identifier]->prev) ? $optionaldatas[$sco->identifier]->prev : 0;
180 if (($nextid == 0) && (scorm_count_launchable($scorm->id,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
181 if (!empty($sco->launch)) {
185 require_once('sequencinglib.php');
186 if (scorm_seq_evaluate($sco->id,$usertracks)) {
187 if ($sco->id == $scoid) {
188 $result->prerequisites = true;
190 $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&currentorg='.$currentorg.$modestr.'&scoid='.$sco->id;
191 $result->toc .= $statusicon.' '.$startbold.'<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score.$endbold."</li>\n";
192 $tocmenus[$sco->id] = scorm_repeater('−',$level) . '>' . format_string($sco->title);
194 if ($sco->id == $scoid) {
195 $result->prerequisites = false;
197 $result->toc .= ' '.format_string($sco->title)."</li>\n";
201 $result->toc .= ' '.format_string($sco->title)."</li>\n";
203 if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
204 if (!empty($nextsco->launch)) {
205 $nextid = $nextsco->id;
209 for ($i=0;$i<$level;$i++) {
210 $result->toc .= "\t\t</ul></li>\n";
214 $sco = $DB->get_record('scorm_scoes', array('id'=>$scoid));
215 $sco->previd = $previd;
216 $sco->nextid = $nextid;
218 $result->incomplete = $incomplete;
220 $result->incomplete = $incomplete;
223 $result->toc .= "\t</ul>\n";
224 if ($scorm->hidetoc == 0) {
226 <script type="text/javascript">
228 function expandCollide(which,list,item) {
229 var el = document.ids ? document.ids[list] : document.getElementById ? document.getElementById(list) : document.all[list];
230 which = which.substring(0,(which.length));
231 var el2 = document.ids ? document.ids[which] : document.getElementById ? document.getElementById(which) : document.all[which];
232 if (el.style.display != "none") {
233 el2.src = "'.$scormpixdir.'/plus.gif";
234 el.style.display=\'none\';
235 new cookie("hide:SCORMitem" + item, 1, 356, "/").set();
237 el2.src = "'.$scormpixdir.'/minus.gif";
238 el.style.display=\'block\';
239 new cookie("hide:SCORMitem" + item, 1, -1, "/").set();
246 $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&currentorg='.$currentorg.$modestr.'&scoid=';
247 $result->tocmenu = popup_form($url,$tocmenus, "tocmenu", $sco->id, '', '', '', true);