MDL-13886 whitelist text-decoration in kses cleaning; merged from MOODLE_19_STABLE
[moodle.git] / mod / scorm / datamodels / scorm_13lib.php
CommitLineData
f4ba7e1a 1<?php // $Id$
dc383b6f 2
3function scorm_get_toc($user,$scorm,$liststyle,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false) {
4 global $CFG;
dc383b6f 5
6 $strexpand = get_string('expcoll','scorm');
7 $modestr = '';
8 if ($mode == 'browse') {
9 $modestr = '&amp;mode='.$mode;
10 }
11 $scormpixdir = $CFG->modpixpath.'/scorm/pix';
12
13 $result = new stdClass();
9b60b28a 14 $result->toc = "<ul id='s0' class='$liststyle'>\n";
dc383b6f 15 $tocmenus = array();
16 $result->prerequisites = true;
17 $incomplete = false;
18
19 //
20 // Get the current organization infos
21 //
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;
27 }
28 $organizationsql = "AND organization='$currentorg'";
29 }
30 //
31 // If not specified retrieve the last attempt number
32 //
33 if (empty($attempt)) {
34 $attempt = scorm_get_last_attempt($scorm->id, $user->id);
35 }
36 $result->attemptleft = $scorm->maxattempt - $attempt;
37 if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' $organizationsql order by id ASC")){
38 //
39 // Retrieve user tracking data for each learning object
40 //
530a61d5 41
dc383b6f 42 $usertracks = array();
10fd330f 43 $optionaldatas = array();
dc383b6f 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';
49 }
50 $usertracks[$sco->identifier] = $usertrack;
51 }
10fd330f 52 if ($optionaldata = scorm_get_sco($sco->id, SCO_DATA)) {
53 $optionaldatas[$sco->identifier] = $optionaldata;
54 }
dc383b6f 55 }
56 }
57
58 $level=0;
59 $sublist=1;
60 $previd = 0;
61 $nextid = 0;
62 $findnext = false;
63 $parents[$level]='/';
dc383b6f 64 foreach ($scoes as $sco) {
b3659259 65 $isvisible = false;
c852a628 66 $sco->title = stripslashes($sco->title);
10fd330f 67 if (isset($optionaldatas[$sco->identifier])) {
68 if (!isset($optionaldatas[$sco->identifier]->isvisible) ||
69 (isset($optionaldatas[$sco->identifier]->isvisible) && ($optionaldatas[$sco->identifier]->isvisible == 'true'))) {
b3659259 70 $isvisible = true;
71 }
72 }
dc383b6f 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</ul></li>\n";
77 }
78 $level = $newlevel;
79 } else {
80 $i = $level;
81 $closelist = '';
82 while (($i > 0) && ($parents[$level] != $sco->parent)) {
83 $closelist .= "\t\t</ul></li>\n";
84 $i--;
85 }
86 if (($i == 0) && ($sco->parent != $currentorg)) {
87 $style = '';
88 if (isset($_COOKIE['hide:SCORMitem'.$sco->id])) {
89 $style = ' style="display: none;"';
90 }
9b60b28a 91 $result->toc .= "\t\t<li><ul id='s$sublist' class='$liststyle'$style>\n";
dc383b6f 92 $level++;
93 } else {
94 $result->toc .= $closelist;
95 $level = $i;
96 }
97 $parents[$level]=$sco->parent;
98 }
99 }
dc383b6f 100 $nextsco = next($scoes);
b3659259 101 $nextisvisible = false;
10fd330f 102 if (($nextsco !== false) && (isset($optionaldatas[$nextsco->identifier]))) {
103 if (!isset($optionaldatas[$nextsco->identifier]->isvisible) ||
104 (isset($optionaldatas[$nextsco->identifier]->isvisible) && ($optionaldatas[$nextsco->identifier]->isvisible == 'true'))) {
b3659259 105 $nextisvisible = true;
106 }
107 }
10fd330f 108 if ($nextisvisible && ($nextsco !== false) && ($sco->parent != $nextsco->parent) &&
109 (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
dc383b6f 110 $sublist++;
111 $icon = 'minus';
112 if (isset($_COOKIE['hide:SCORMitem'.$nextsco->id])) {
113 $icon = 'plus';
114 }
9b60b28a 115 $result->toc .= "\t\t".'<li><a href="javascript:expandCollide(img'.$sublist.',s'.$sublist.','.$nextsco->id.');">'.
10fd330f 116 '<img id="img'.$sublist.'" src="'.$scormpixdir.'/'.$icon.'.gif" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';
b3659259 117 } else if ($isvisible) {
9b60b28a 118 $result->toc .= "\t\t".'<li><img src="'.$scormpixdir.'/spacer.gif" />';
dc383b6f 119 }
120 if (empty($sco->title)) {
121 $sco->title = $sco->identifier;
122 }
123 if (!empty($sco->launch)) {
b3659259 124 if ($isvisible) {
125 $startbold = '';
126 $endbold = '';
127 $score = '';
128 if (empty($scoid) && ($mode != 'normal')) {
129 $scoid = $sco->id;
530a61d5 130 }
b3659259 131 if (isset($usertracks[$sco->identifier])) {
132 $usertrack = $usertracks[$sco->identifier];
133 $strstatus = get_string($usertrack->status,'scorm');
134 if ($sco->scormtype == 'sco') {
135 $statusicon = '<img src="'.$scormpixdir.'/'.$usertrack->status.'.gif" alt="'.$strstatus.'" title="'.$strstatus.'" />';
136 } else {
137 $statusicon = '<img src="'.$scormpixdir.'/assetc.gif" alt="'.get_string('assetlaunched','scorm').'" title="'.get_string('assetlaunched','scorm').'" />';
138 }
139
140 if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {
141 $incomplete = true;
142 if ($play && empty($scoid)) {
143 $scoid = $sco->id;
144 }
145 }
146 if ($usertrack->score_raw != '') {
147 $score = '('.get_string('score','scorm').':&nbsp;'.$usertrack->score_raw.')';
148 }
149 $strsuspended = get_string('suspended','scorm');
150 if (isset($usertrack->{'cmi.core.exit'}) && ($usertrack->{'cmi.core.exit'} == 'suspend')) {
151 $statusicon = '<img src="'.$scormpixdir.'/suspend.gif" alt="'.$strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
152 }
153 } else {
dc383b6f 154 if ($play && empty($scoid)) {
155 $scoid = $sco->id;
156 }
b3659259 157 if ($sco->scormtype == 'sco') {
158 $statusicon = '<img src="'.$scormpixdir.'/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
159 $incomplete = true;
160 } else {
161 $statusicon = '<img src="'.$scormpixdir.'/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
162 }
530a61d5 163 }
530a61d5 164
dc383b6f 165 if ($sco->id == $scoid) {
b3659259 166 $startbold = '<b>';
167 $endbold = '</b>';
168 $findnext = true;
10fd330f 169 $shownext = isset($optionaldatas[$sco->identifier]->next) ? $optionaldatas[$sco->identifier]->next : 0;
170 $showprev = isset($optionaldatas[$sco->identifier]->prev) ? $optionaldatas[$sco->identifier]->prev : 0;
dc383b6f 171 }
b3659259 172
173 if (($nextid == 0) && (scorm_count_launchable($scorm->id,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
174 if (!empty($sco->launch)) {
175 $previd = $sco->id;
176 }
177 }
10fd330f 178 require_once('sequencinglib.php');
179 if (scorm_seq_evaluate($sco->id,$usertracks)) {
b3659259 180 if ($sco->id == $scoid) {
181 $result->prerequisites = true;
182 }
b3659259 183 $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid='.$sco->id;
184 $result->toc .= $statusicon.'&nbsp;'.$startbold.'<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score.$endbold."</li>\n";
185 $tocmenus[$sco->id] = scorm_repeater('&minus;',$level) . '&gt;' . format_string($sco->title);
b3659259 186 } else {
187 if ($sco->id == $scoid) {
188 $result->prerequisites = false;
189 }
190 $result->toc .= '&nbsp;'.format_string($sco->title)."</li>\n";
dc383b6f 191 }
dc383b6f 192 }
193 } else {
b3659259 194 $result->toc .= '&nbsp;'.format_string($sco->title)."</li>\n";
dc383b6f 195 }
196 if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
197 if (!empty($nextsco->launch)) {
198 $nextid = $nextsco->id;
199 }
200 }
201 }
202 for ($i=0;$i<$level;$i++) {
203 $result->toc .= "\t\t</ul></li>\n";
204 }
205
206 if ($play) {
207 $sco = get_record('scorm_scoes','id',$scoid);
208 $sco->previd = $previd;
209 $sco->nextid = $nextid;
210 $result->sco = $sco;
211 $result->incomplete = $incomplete;
212 } else {
213 $result->incomplete = $incomplete;
214 }
215 }
216 $result->toc .= "\t</ul>\n";
217 if ($scorm->hidetoc == 0) {
218 $result->toc .= '
f4ba7e1a 219 <script type="text/javascript">
220 //<![CDATA[
dc383b6f 221 function expandCollide(which,list,item) {
222 var nn=document.ids?true:false
223 var w3c=document.getElementById?true:false
224 var beg=nn?"document.ids.":w3c?"document.getElementById(":"document.all.";
225 var mid=w3c?").style":".style";
226
227 if (eval(beg+list+mid+".display") != "none") {
228 which.src = "'.$scormpixdir.'/plus.gif";
229 eval(beg+list+mid+".display=\'none\';");
230 new cookie("hide:SCORMitem" + item, 1, 356, "/").set();
231 } else {
232 which.src = "'.$scormpixdir.'/minus.gif";
233 eval(beg+list+mid+".display=\'block\';");
234 new cookie("hide:SCORMitem" + item, 1, -1, "/").set();
235 }
236 }
f4ba7e1a 237 //]]>
dc383b6f 238 </script>'."\n";
239 }
240
241 $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid=';
242 $result->tocmenu = popup_form($url,$tocmenus, "tocmenu", $sco->id, '', '', '', true);
243
244 return $result;
245}
246
dc383b6f 247?>