Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / scorm / datamodels / scorm_13lib.php
blob2ab572277181acd63c832ec3b9fcc38e5fdbbf1b
1 <?php // $Id$
3 function scorm_get_toc($user,$scorm,$liststyle,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false) {
4 global $CFG;
6 $strexpand = get_string('expcoll','scorm');
7 $modestr = '';
8 if ($mode == 'browse') {
9 $modestr = '&amp;mode='.$mode;
11 $scormpixdir = $CFG->modpixpath.'/scorm/pix';
13 $result = new stdClass();
14 $result->toc = "<ul id='s0' class='$liststyle'>\n";
15 $tocmenus = array();
16 $result->prerequisites = true;
17 $incomplete = false;
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
38 //
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;
52 $level=0;
53 $sublist=1;
54 $previd = 0;
55 $nextid = 0;
56 $findnext = false;
57 $parents[$level]='/';
58 foreach ($scoes as $pos => $sco) {
59 $isvisible = false;
60 $sco->title = stripslashes($sco->title);
61 if (!isset($sco->isvisible) || (isset($sco->isvisible) && ($sco->isvisible == 'true'))) {
62 $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";
69 $level = $newlevel;
70 } else {
71 $i = $level;
72 $closelist = '';
73 while (($i > 0) && ($parents[$level] != $sco->parent)) {
74 $closelist .= "\t\t</ul></li>\n";
75 $i--;
77 if (($i == 0) && ($sco->parent != $currentorg)) {
78 $style = '';
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";
83 $level++;
84 } else {
85 $result->toc .= $closelist;
86 $level = $i;
88 $parents[$level]=$sco->parent;
91 if (isset($scoes[$pos+1])) {
92 $nextsco = $scoes[$pos+1];
93 } else {
94 $nextsco = false;
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)))) {
102 $sublist++;
103 $icon = 'minus';
104 if (isset($_COOKIE['hide:SCORMitem'.$nextsco->id])) {
105 $icon = 'plus';
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)) {
116 if ($isvisible) {
117 $startbold = '';
118 $endbold = '';
119 $score = '';
120 if (empty($scoid) && ($mode != 'normal')) {
121 $scoid = $sco->id;
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.'" />';
128 } else {
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')) {
133 $incomplete = true;
134 if ($play && empty($scoid)) {
135 $scoid = $sco->id;
138 if ($usertrack->score_raw != '') {
139 $score = '('.get_string('score','scorm').':&nbsp;'.$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.'" />';
147 } else {
148 if ($play && empty($scoid)) {
149 $scoid = $sco->id;
151 if ($sco->scormtype == 'sco') {
152 $statusicon = '<img src="'.$scormpixdir.'/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
153 $incomplete = true;
154 } else {
155 $statusicon = '<img src="'.$scormpixdir.'/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
159 if ($sco->id == $scoid) {
160 $startbold = '<b>';
161 $endbold = '</b>';
162 $findnext = true;
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)) {
169 $previd = $sco->id;
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.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid='.$sco->id;
178 $result->toc .= $statusicon.'&nbsp;'.$startbold.'<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score.$endbold."</li>\n";
179 $tocmenus[$sco->id] = scorm_repeater('&minus;',$level) . '&gt;' . format_string($sco->title);
180 } else {
181 if ($sco->id == $scoid) {
182 $result->prerequisites = false;
184 $result->toc .= '&nbsp;'.format_string($sco->title)."</li>\n";
187 } else {
188 $result->toc .= '&nbsp;'.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";
200 if ($play) {
201 $sco = get_record('scorm_scoes','id',$scoid);
202 $sco->previd = $previd;
203 $sco->nextid = $nextid;
204 $result->sco = $sco;
205 $result->incomplete = $incomplete;
206 } else {
207 $result->incomplete = $incomplete;
210 $result->toc .= "\t</ul>\n";
211 if ($scorm->hidetoc == 0) {
212 $result->toc .= '
213 <script type="text/javascript">
214 //<![CDATA[
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();
223 } else {
224 el2.src = "'.$scormpixdir.'/minus.gif";
225 el.style.display=\'block\';
226 new cookie("hide:SCORMitem" + item, 1, -1, "/").set();
229 //]]>
230 </script>'."\n";
233 $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid=';
234 $result->tocmenu = popup_form($url,$tocmenus, "tocmenu", $sco->id, '', '', '', true);
236 return $result;