MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / mod / scorm / datamodels / scorm_13lib.php
blobdb13ff66e438da20099dd02a9f22de4247c64ab1
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 $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
40 //
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;
58 $level=0;
59 $sublist=1;
60 $previd = 0;
61 $nextid = 0;
62 $findnext = false;
63 $parents[$level]='/';
64 foreach ($scoes as $sco) {
65 $isvisible = false;
66 if (isset($optionaldatas[$sco->identifier])) {
67 if (!isset($optionaldatas[$sco->identifier]->isvisible) ||
68 (isset($optionaldatas[$sco->identifier]->isvisible) && ($optionaldatas[$sco->identifier]->isvisible == 'true'))) {
69 $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";
77 $level = $newlevel;
78 } else {
79 $i = $level;
80 $closelist = '';
81 while (($i > 0) && ($parents[$level] != $sco->parent)) {
82 $closelist .= "\t\t</ul></li>\n";
83 $i--;
85 if (($i == 0) && ($sco->parent != $currentorg)) {
86 $style = '';
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";
91 $level++;
92 } else {
93 $result->toc .= $closelist;
94 $level = $i;
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)))) {
109 $sublist++;
110 $icon = 'minus';
111 if (isset($_COOKIE['hide:SCORMitem'.$nextsco->id])) {
112 $icon = 'plus';
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)) {
123 if ($isvisible) {
124 $startbold = '';
125 $endbold = '';
126 $score = '';
127 if (empty($scoid) && ($mode != 'normal')) {
128 $scoid = $sco->id;
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.'" />';
135 } else {
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')) {
140 $incomplete = true;
141 if ($play && empty($scoid)) {
142 $scoid = $sco->id;
145 if ($usertrack->score_raw != '') {
146 $score = '('.get_string('score','scorm').':&nbsp;'.$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.'" />';
152 } else {
153 if ($play && empty($scoid)) {
154 $scoid = $sco->id;
156 if ($sco->scormtype == 'sco') {
157 $statusicon = '<img src="'.$scormpixdir.'/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
158 $incomplete = true;
159 } else {
160 $statusicon = '<img src="'.$scormpixdir.'/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
164 if ($sco->id == $scoid) {
165 $startbold = '<b>';
166 $endbold = '</b>';
167 $findnext = true;
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)) {
174 $previd = $sco->id;
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.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid='.$sco->id;
183 $result->toc .= $statusicon.'&nbsp;'.$startbold.'<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score.$endbold."</li>\n";
184 $tocmenus[$sco->id] = scorm_repeater('&minus;',$level) . '&gt;' . format_string($sco->title);
185 } else {
186 if ($sco->id == $scoid) {
187 $result->prerequisites = false;
189 $result->toc .= '&nbsp;'.format_string($sco->title)."</li>\n";
192 } else {
193 $result->toc .= '&nbsp;'.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";
205 if ($play) {
206 $sco = get_record('scorm_scoes','id',$scoid);
207 $sco->previd = $previd;
208 $sco->nextid = $nextid;
209 $result->sco = $sco;
210 $result->incomplete = $incomplete;
211 } else {
212 $result->incomplete = $incomplete;
215 $result->toc .= "\t</ul>\n";
216 if ($scorm->hidetoc == 0) {
217 $result->toc .= '
218 <script type="text/javascript">
219 //<![CDATA[
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();
230 } else {
231 which.src = "'.$scormpixdir.'/minus.gif";
232 eval(beg+list+mid+".display=\'block\';");
233 new cookie("hide:SCORMitem" + item, 1, -1, "/").set();
236 //]]>
237 </script>'."\n";
240 $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid=';
241 $result->tocmenu = popup_form($url,$tocmenus, "tocmenu", $sco->id, '', '', '', true);
243 return $result;