3 function scorm_get_toc($user,$scorm,$toclink=TOCJSLINK,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false, $tocheader=false) {
4 global $CFG, $DB, $PAGE, $OUTPUT;
6 $strexpand = get_string('expcoll','scorm');
8 if ($mode == 'browse') {
9 $modestr = '&mode='.$mode;
12 $result = new stdClass();
14 $result->toc = '<div id="scorm_layout">';
15 $result->toc .= '<div id="scorm_toc">';
16 $result->toc .= '<div id="scorm_tree">';
18 $result->toc .= '<ul>';
20 $result->prerequisites = true;
24 // Get the current organization infos
26 if (!empty($currentorg)) {
27 if (($organizationtitle = $DB->get_field('scorm_scoes', 'title', array('scorm'=>$scorm->id,'identifier'=>$currentorg))) != '') {
29 $result->toctitle = "$organizationtitle";
32 $result->toc .= "\t<li>$organizationtitle</li>\n";
34 $tocmenus[] = $organizationtitle;
38 // If not specified retrieve the last attempt number
40 if (empty($attempt)) {
41 $attempt = scorm_get_last_attempt($scorm->id, $user->id);
43 $result->attemptleft = $scorm->maxattempt - $attempt;
44 if ($scoes = scorm_get_scoes($scorm->id, $currentorg)){
46 // Retrieve user tracking data for each learning object
49 $usertracks = array();
50 foreach ($scoes as $sco) {
51 if (!empty($sco->launch)) {
52 if ($usertrack = scorm_get_tracks($sco->id,$user->id,$attempt)) {
53 if ($usertrack->status == '') {
54 $usertrack->status = 'notattempted';
56 $usertracks[$sco->identifier] = $usertrack;
67 foreach ($scoes as $pos => $sco) {
69 $sco->title = $sco->title;
70 if (!isset($sco->isvisible) || (isset($sco->isvisible) && ($sco->isvisible == 'true'))) {
73 if ($parents[$level]!=$sco->parent) {
74 if ($newlevel = array_search($sco->parent,$parents)) {
75 for ($i=0; $i<($level-$newlevel); $i++) {
76 $result->toc .= "\t\t</li></ul></li>\n";
82 while (($i > 0) && ($parents[$level] != $sco->parent)) {
83 $closelist .= "\t\t</li></ul></li>\n";
86 if (($i == 0) && ($sco->parent != $currentorg)) {
88 if (isset($_COOKIE['hide:SCORMitem'.$sco->id])) {
89 $style = ' style="display: none;"';
91 //$result->toc .= "\t\t<li><ul id='s$sublist' class='$liststyle'$style>\n";
92 $result->toc .= "\t\t><ul>\n";
95 $result->toc .= $closelist;
98 $parents[$level]=$sco->parent;
102 $result->toc .= "<li>";
104 if (isset($scoes[$pos+1])) {
105 $nextsco = $scoes[$pos+1];
109 $nextisvisible = false;
110 if (!isset($nextsco->isvisible) || (isset($nextsco->isvisible) && ($nextsco->isvisible == 'true'))) {
111 $nextisvisible = true;
113 if ($nextisvisible && ($nextsco !== false) && ($sco->parent != $nextsco->parent) &&
114 (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
117 if (isset($_COOKIE['hide:SCORMitem'.$nextsco->id])) {
120 // $result->toc .= "\t\t".'<li><a href="javascript:expandCollide(\'img'.$sublist.'\',\'s'.$sublist.'\','.$nextsco->id.');">'.
121 // '<img id="img'.$sublist.'" src="'.$OUTPUT->pix_url($icon, 'scorm').'" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';
122 } else if ($isvisible) {
123 // $result->toc .= "\t\t".'<li><img src="'.$OUTPUT->pix_url('spacer', 'scorm').'" alt="" />';
125 if (empty($sco->title)) {
126 $sco->title = $sco->identifier;
128 if (!empty($sco->launch)) {
133 if (empty($scoid) && ($mode != 'normal')) {
136 if (isset($usertracks[$sco->identifier])) {
137 $usertrack = $usertracks[$sco->identifier];
138 $strstatus = get_string($usertrack->status,'scorm');
139 if ($sco->scormtype == 'sco') {
140 $statusicon = '<img src="'.$OUTPUT->pix_url($usertrack->status, 'scorm').'" alt="'.$strstatus.'" title="'.$strstatus.'" />';
142 $statusicon = '<img src="'.$OUTPUT->pix_url('assetc', 'scorm').'" alt="'.get_string('assetlaunched','scorm').'" title="'.get_string('assetlaunched','scorm').'" />';
145 if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {
147 if ($play && empty($scoid)) {
151 if ($usertrack->score_raw != '') {
152 $score = '('.get_string('score','scorm').': '.$usertrack->score_raw.')';
154 $strsuspended = get_string('suspended','scorm');
155 if ($incomplete && isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} == 'suspend')) {
156 $statusicon = '<img src="'.$OUTPUT->pix_url('suspend', 'scorm').'" alt="'.$strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
159 if ($play && empty($scoid)) {
162 if ($sco->scormtype == 'sco') {
163 $statusicon = '<img src="'.$OUTPUT->pix_url('notattempted', 'scorm').'" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
166 $statusicon = '<img src="'.$OUTPUT->pix_url('asset', 'scorm').'" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
170 if ($sco->id == $scoid) {
174 $shownext = isset($sco->next) ? $sco->next : 0;
175 $showprev = isset($sco->prev) ? $sco->prev : 0;
178 if (($nextid == 0) && (scorm_count_launchable($scorm->id,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
179 if (!empty($sco->launch)) {
183 require_once($CFG->dirroot.'/mod/scorm/datamodels/sequencinglib.php');
184 if (scorm_seq_evaluate($sco->id,$usertracks)) {
185 if ($sco->id == $scoid) {
186 $result->prerequisites = true;
189 if ($toclink == TOCFULLURL) { //display toc with urls for structure page
190 $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&currentorg='.$currentorg.$modestr.'&scoid='.$sco->id;
191 $result->toc .= $statusicon.' <a href="'.$url.'">'.format_string($sco->title).'</a>'.$score."\n";
194 $link = 'a='.$scorm->id.'&scoid='.$sco->id.'¤torg='.$currentorg.$modestr.'&attempt='.$attempt;
195 $result->toc .= '<a title="'.$link.'">'.$statusicon.' '.format_string($sco->title).' '.$score.'</a>';
197 $result->toc .= '<span>'.$statusicon.' '.format_string($sco->title).'</span>';
200 $tocmenus[$sco->id] = scorm_repeater('−',$level) . '>' . format_string($sco->title);
202 if ($sco->id == $scoid) {
203 $result->prerequisites = false;
205 //$result->toc .= $statusicon.' '.format_string($sco->title)."\n";
207 // should be disabled
208 $result->toc .= '<span>'.$statusicon.' '.format_string($sco->title).'</span>';
211 $result->toc .= $statusicon.' '.format_string($sco->title)."\n";
214 if (($nextsco === false) || $nextsco->parent == $sco->parent) {
215 $result->toc .= '</li>';
219 $result->toc .= ' '.format_string($sco->title)."</li>\n";
221 if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
222 if (!empty($nextsco->launch)) {
223 $nextid = $nextsco->id;
227 for ($i=0;$i<$level;$i++) {
228 $result->toc .= "\t\t</ul></li>\n";
232 $sco = $DB->get_record('scorm_scoes', array('id'=>$scoid));
233 $sco->previd = $previd;
234 $sco->nextid = $nextid;
236 $result->incomplete = $incomplete;
238 $result->incomplete = $incomplete;
241 $result->toc .= '</ul>';
246 $result->toc .= '</div></div></div>';
247 $result->toc .= '<div id="scorm_navpanel"></div>';
251 if ($scorm->hidetoc == 0) {
252 $PAGE->requires->data_for_js('scormdata', array(
253 'plusicon' => $OUTPUT->pix_url('plus', 'scorm'),
254 'minusicon' => $OUTPUT->pix_url('minus', 'scorm')));
255 $PAGE->requires->js('/lib/cookies.js');
256 $PAGE->requires->js('/mod/scorm/datamodels/scorm_datamodels.js');
259 $url = new moodle_url('/mod/scorm/player.php?a='.$scorm->id.'¤torg='.$currentorg.$modestr);
260 $result->tocmenu = $OUTPUT->single_select($url, 'scoid', $tocmenus, $sco->id, null, "tocmenu");