more fixes for lockoptions behaviour; changes to forum/mod_form.php; removed forum...
[moodle.git] / mod / scorm / datamodels / scorm_13lib.php
CommitLineData
dc383b6f 1<?php
2/* // Added by Pham Minh Duc
3 case 'ADLNAV:PRESENTATION':
4 $parent = array_pop($parents);
5 array_push($parents, $parent);
6 foreach ($block['children'] as $adlnav) {
7 if ($adlnav['name'] == 'ADLNAV:NAVIGATIONINTERFACE') {
8 foreach ($adlnav['children'] as $adlnavInterface) {
9 if ($adlnavInterface['name'] == 'ADLNAV:HIDELMSUI') {
10 if ($adlnavInterface['tagData'] == 'continue') {
11 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->next = 1;
12 }
13 if ($adlnavInterface['tagData'] == 'previous') {
14 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->previous = 1;
15 }
16 }
17
18 }
19 }
20 }
21 break;
22 case 'IMSSS:SEQUENCING':
23 $parent = array_pop($parents);
24 array_push($parents, $parent);
25 foreach ($block['children'] as $sequencing) {
26 if ($sequencing['name']=='IMSSS:CONTROLMODE') {
27 if ($sequencing['attrs']['CHOICE'] == 'false') {
28 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->choice = 0;
29 }
30 if ($sequencing['attrs']['CHOICEEXIT'] == 'false') {
31 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->choiceexit = 0;
32 }
33 if ($sequencing['attrs']['FLOW'] == 'true') {
34 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->flow = 1;
35 }
36 if ($sequencing['attrs']['FORWARDONLY'] == 'true') {
37 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->forwardonly = 1;
38 }
39 if ($sequencing['attrs']['USECURRENTATTEMPTOBJECTINFO'] == 'true') {
40 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->usecurrentattemptobjectinfo = 1;
41 }
42 if ($sequencing['attrs']['USECURRENTATTEMPTPROGRESSINFO'] == 'true') {
43 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->usecurrentattemptprogressinfo = 1;
44 }
45 }
46 if ($sequencing['name']=='ADLSEQ:CONSTRAINEDCHOICECONSIDERATIONS') {
47 if ($sequencing['attrs']['CONSTRAINCHOICE'] == 'true') {
48 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->constrainChoice = 1;
49 }
50 if ($sequencing['attrs']['PREVENTACTIVATION'] == 'true') {
51 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->preventactivation = 1;
52 }
53
54 }
55 if ($sequencing['name']=='IMSSS:OBJECTIVES') {
56 foreach ($sequencing['children'] as $objective) {
57 if ($objective['name']=='IMSSS:PRIMARYOBJECTIVE') {
58 foreach ($objective['children'] as $primaryobjective) {
59 if ($primaryobjective['name']=='IMSSS:MINNORMALIZEDMEASURE') {
60 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->minnormalizedmeasure = $primaryobjective['tagData'];
61 }
62 }
63 }
64 }
65 }
66 if ($sequencing['name']=='IMSSS:LIMITCONDITIONS') {
67 if (!empty($sequencing['attrs']['ATTEMPTLIMIT'])) {
68 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->attemptLimit = $sequencing['attrs']['ATTEMPTLIMIT'];
69 }
70 if (!empty($sequencing['attrs']['ATTEMPTABSOLUTEDURATIONLIMIT'])) {
71 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->attemptAbsoluteDurationLimit = $sequencing['attrs']['ATTEMPTABSOLUTEDURATIONLIMIT'];
72 }
73 }
74 if ($sequencing['name']=='IMSSS:ROLLUPRULES') {
75 $rolluprules = array();
76 if (!empty($sequencing['attrs']['ROLLUPOBJECTIVESATISFIED'])) {
77 if ($sequencing['attrs']['ROLLUPOBJECTIVESATISFIED']== 'false') {
78 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->rollupobjectivesatisfied = 0;
79 }
80 }
81 if (!empty($sequencing['attrs']['ROLLUPPROGRESSCOMPLETION'])) {
82 if ($sequencing['attrs']['ROLLUPPROGRESSCOMPLETION']== 'false') {
83 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->rollupprogresscompletion = 0;
84 }
85 }
86 if (!empty($sequencing['attrs']['OBJECTIVEMEASUREWEIGHT'])) {
87 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->objectivemeasureweight = $sequencing['attrs']['OBJECTIVEMEASUREWEIGHT'];
88 }
89
90 if (!empty($sequencing['children'])){
91 foreach ($sequencing['children'] as $sequencingrolluprule) {
92 if ($sequencingrolluprule['name']=='IMSSS:ROLLUPRULE' ) {
93 $rolluprule = new stdClass();
94 if ($sequencingrolluprule['attrs']['CHILDACTIVITYSET'] !=' ') {
95 $rolluprule->childactivityset = $sequencingrolluprule['attrs']['CHILDACTIVITYSET'];
96 if (!empty($sequencingrolluprule['children'])) {
97 foreach ($sequencingrolluprule['children'] as $rolluproleconditions) {
98 if ($rolluproleconditions['name']=='IMSSS:ROLLUPCONDITIONS') {
99 $conditions = array();
100 if (!empty($rolluproleconditions['attrs']['conditionCombination'])) {
101 $rolluprule->conditionCombination = $rolluproleconditions['attrs']['conditionCombination'];
102 }
103 foreach ($rolluproleconditions['children'] as $rolluprulecondition) {
104 if ($rolluprulecondition['name']=='IMSSS:ROLLUPCONDITION') {
105 $condition = new stdClass();
106 if (!empty($rolluprulecondition['attrs']['OPERATOR'])) {
107 $condition->operator = $rolluprulecondition['attrs']['OPERATOR'];
108 }
109 if (!empty($rolluprulecondition['attrs']['CONDITION'])) {
110 $condition->condition = $rolluprulecondition['attrs']['CONDITION'];
111 }
112 array_push($conditions,$condition);
113 }
114 }
115 $rolluprule->conditions = $conditions;
116 }
117 if ($rolluproleconditions['name']=='IMSSS:ROLLUPACTION') {
118 $rolluprule->rollupruleaction = $rolluproleconditions['attrs']['ACTION'];
119 }
120 }
121 }
122 }
123 array_push($rolluprules, $rolluprule);
124 }
125 }
126 }
127 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->rolluprules = $rolluprules;
128 }
129
130 if ($sequencing['name']=='IMSSS:SEQUENCINGRULES') {
131 $sequencingrules = array();
132 foreach ($sequencing['children'] as $conditionrules) {
133 if ($conditionrules['name']=='IMSSS:EXITCONDITIONRULE') {
134 $sequencingrule = new stdClass();
135 if (!empty($conditionrules['children'])) {
136 foreach ($conditionrules['children'] as $conditionrule) {
137 if ($conditionrule['name']=='IMSSS:RULECONDITIONS') {
138 $ruleconditions = array();
139 if (!empty($conditionrule['attrs']['conditionCombination'])) {
140 $sequencingrule->conditionCombination = $conditionrule['attrs']['conditionCombination'];
141 }
142 foreach ($conditionrule['children'] as $rulecondition) {
143 if ($rulecondition['name']=='IMSSS:RULECONDITION') {
144 $condition = new stdClass();
145 if (!empty($rulecondition['attrs']['OPERATOR'])) {
146 $condition->operator = $rulecondition['attrs']['OPERATOR'];
147 }
148 if (!empty($rulecondition['attrs']['CONDITION'])) {
149 $condition->condition = $rulecondition['attrs']['CONDITION'];
150 }
151 if (!empty($rulecondition['attrs']['MEASURETHRESHOLD'])) {
152 $condition->measurethreshold = $rulecondition['attrs']['MEASURETHRESHOLD'];
153 }
154 if (!empty($rulecondition['attrs']['REFERENCEDOBJECTIVE'])) {
155 $condition->referencedobjective = $rulecondition['attrs']['REFERENCEDOBJECTIVE'];
156 }
157 array_push($ruleconditions,$condition);
158 }
159 }
160 $sequencingrule->ruleconditions = $ruleconditions;
161 }
162 if ($conditionrule['name']=='IMSSS:RULEACTION') {
163 $sequencingrule->exitconditionruleaction = $conditionrule['attrs']['ACTION'];
164 }
165 }
166 }
167 array_push($sequencingrules,$sequencingrule);
168 }
169 if ($conditionrules['name']=='IMSSS:PRECONDITIONRULE') {
170 $sequencingrule = new stdClass();
171 if (!empty($conditionrules['children'])) {
172 foreach ($conditionrules['children'] as $conditionrule) {
173 if ($conditionrule['name']=='IMSSS:RULECONDITIONS') {
174 $ruleconditions = array();
175 if (!empty($conditionrule['attrs']['conditionCombination'])) {
176 $sequencingrule->conditionCombination = $conditionrule['attrs']['conditionCombination'];
177 }
178 foreach ($conditionrule['children'] as $rulecondition) {
179 if ($rulecondition['name']=='IMSSS:RULECONDITION') {
180 $condition = new stdClass();
181 if (!empty($rulecondition['attrs']['OPERATOR'])) {
182 $condition->operator = $rulecondition['attrs']['OPERATOR'];
183 }
184 if (!empty($rulecondition['attrs']['CONDITION'])) {
185 $condition->condition = $rulecondition['attrs']['CONDITION'];
186 }
187 if (!empty($rulecondition['attrs']['MEASURETHRESHOLD'])) {
188 $condition->measurethreshold = $rulecondition['attrs']['MEASURETHRESHOLD'];
189 }
190 if (!empty($rulecondition['attrs']['REFERENCEDOBJECTIVE'])) {
191 $condition->referencedobjective = $rulecondition['attrs']['REFERENCEDOBJECTIVE'];
192 }
193 array_push($ruleconditions,$condition);
194 }
195 }
196 $sequencingrule->ruleconditions = $ruleconditions;
197 }
198 if ($conditionrule['name']=='IMSSS:RULEACTION') {
199 $sequencingrule->preconditionruleaction = $conditionrule['attrs']['ACTION'];
200 }
201 }
202 }
203 array_push($sequencingrules,$sequencingrule);
204 }
205 if ($conditionrules['name']=='IMSSS:POSTCONDITIONRULE') {
206 $sequencingrule = new stdClass();
207 if (!empty($conditionrules['children'])) {
208 foreach ($conditionrules['children'] as $conditionrule) {
209 if ($conditionrule['name']=='IMSSS:RULECONDITIONS'){
210 $ruleconditions = array();
211 if (!empty($conditionrule['attrs']['conditionCombination'])){
212 $sequencingrule->conditionCombination = $conditionrule['attrs']['conditionCombination'];
213 }
214 foreach ($conditionrule['children'] as $rulecondition){
215 if ($rulecondition['name']=='IMSSS:RULECONDITION'){
216 $condition = new stdClass();
217 if (!empty($rulecondition['attrs']['OPERATOR'])){
218 $condition->operator = $rulecondition['attrs']['OPERATOR'];
219 }
220 if (!empty($rulecondition['attrs']['CONDITION'])){
221 $condition->condition = $rulecondition['attrs']['CONDITION'];
222 }
223 if (!empty($rulecondition['attrs']['MEASURETHRESHOLD'])){
224 $condition->measurethreshold = $rulecondition['attrs']['MEASURETHRESHOLD'];
225 }
226 if (!empty($rulecondition['attrs']['REFERENCEDOBJECTIVE'])){
227 $condition->referencedobjective = $rulecondition['attrs']['REFERENCEDOBJECTIVE'];
228 }
229 array_push($ruleconditions,$condition);
230 }
231 }
232 $sequencingrule->ruleconditions = $ruleconditions;
233 }
234 if ($conditionrule['name']=='IMSSS:RULEACTION'){
235 $sequencingrule->postconditionruleaction = $conditionrule['attrs']['ACTION'];
236 }
237 }
238 }
239 array_push($sequencingrules,$sequencingrule);
240 }
241 $scoes->elements[$manifest][$parent->organization][$parent->identifier]->sequencingrules = $sequencingrules;
242 }
243 }
244 }
245 break;
246*/
247
248function scorm_parse_scorm($pkgdir,$scormid) {
249 global $CFG;
250
251 $launch = 0;
252 $manifestfile = $pkgdir.'/imsmanifest.xml';
253
254 if (is_file($manifestfile)) {
255
256 $xmlstring = file_get_contents($manifestfile);
257 $objXML = new xml2Array();
258 $manifests = $objXML->parse($xmlstring);
259 // print_r($manifests);
260 $scoes = new stdClass();
261 $scoes->version = '';
262 $scoes = scorm_get_manifest($manifests,$scoes);
263
264 if (count($scoes->elements) > 0) {
265 $olditems = get_records('scorm_scoes','scorm',$scormid);
266 foreach ($scoes->elements as $manifest => $organizations) {
267 foreach ($organizations as $organization => $items) {
268 foreach ($items as $identifier => $item) {
269 $item->scorm = $scormid;
270 $item->manifest = $manifest;
271 $item->organization = $organization;
272 if ($olditemid = scorm_array_search('identifier',$item->identifier,$olditems)) {
273 $item->id = $olditemid;
274 $id = update_record('scorm_scoes',$item);
275 unset($olditems[$olditemid]);
276 } else {
277 $id = insert_record('scorm_scoes',$item);
278 }
279 // Added by Pham Minh Duc
280 $item->scormid = $scormid;
281 $item->scoid = $id;
282 $idControlMode = insert_record('scorm_sequencing_controlmode',$item);
283
284 if (!empty($item->sequencingrules)) {
285 foreach($item->sequencingrules as $sequencingrule) {
286 $sequencingrule->scormid = $scormid;
287 $sequencingrule->scoid = $item->scoid;
288 $idruleconditions = insert_record('scorm_sequencing_ruleconditions',$sequencingrule);
289 foreach($sequencingrule->ruleconditions as $rulecondition) {
290 $rulecondition->scormid = $sequencingrule->scormid;
291 $rulecondition->scoid = $sequencingrule->scoid;
292 $rulecondition->ruleconditionsid = $idruleconditions;
293 $idrulecondition = insert_record('scorm_sequencing_rulecondition',$rulecondition);
294 }
295 }
296 }
297
298 if (!empty($item->rolluprules)) {
299 $idControlMode = insert_record('scorm_sequencing_rolluprules',$item);
300 foreach($item->rolluprules as $rollup) {
301 $rollup->rolluprulesid =$idControlMode;
302 $rollup->scormid = $scormid;
303 $rollup->scoid = $item->scoid;
304
305 $idRollupRule = insert_record('scorm_sequencing_rolluprule',$rollup);
306 $rollup->rollupruleid = $idRollupRule;
307 $idconditions = insert_record('scorm_sequencing_rollupruleconditions',$rollup);
308 foreach($rollup->conditions as $condition){
309 $condition->ruleconditionsid = $idconditions;
310 $condition->scormid = $rollup->scormid;
311 $condition->scoid = $rollup->scoid;
312 $idcondition = insert_record('scorm_sequencing_rolluprulecondition',$condition);
313 }
314 }
315 }
316 // End Add
317 if (($launch == 0) && ((empty($scoes->defaultorg)) || ($scoes->defaultorg == $identifier))) {
318 $launch = $id;
319 }
320 }
321 }
322 }
323 if (!empty($olditems)) {
324 foreach($olditems as $olditem) {
325 delete_records('scorm_scoes','id',$olditem->id);
326 delete_records('scorm_scoes_track','scoid',$olditem->id);
327 }
328 }
329 set_field('scorm','version',$scoes->version,'id',$scormid);
330 }
331 }
332
333 return $launch;
334}
335
336function scorm_get_toc($user,$scorm,$liststyle,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false) {
337 global $CFG;
dc383b6f 338
339 $strexpand = get_string('expcoll','scorm');
340 $modestr = '';
341 if ($mode == 'browse') {
342 $modestr = '&amp;mode='.$mode;
343 }
344 $scormpixdir = $CFG->modpixpath.'/scorm/pix';
345
346 $result = new stdClass();
347 $result->toc = "<ul id='0' class='$liststyle'>\n";
348 $tocmenus = array();
349 $result->prerequisites = true;
350 $incomplete = false;
351
352 //
353 // Get the current organization infos
354 //
355 $organizationsql = '';
356 if (!empty($currentorg)) {
357 if (($organizationtitle = get_field('scorm_scoes','title','scorm',$scorm->id,'identifier',$currentorg)) != '') {
358 $result->toc .= "\t<li>$organizationtitle</li>\n";
359 $tocmenus[] = $organizationtitle;
360 }
361 $organizationsql = "AND organization='$currentorg'";
362 }
363 //
364 // If not specified retrieve the last attempt number
365 //
366 if (empty($attempt)) {
367 $attempt = scorm_get_last_attempt($scorm->id, $user->id);
368 }
369 $result->attemptleft = $scorm->maxattempt - $attempt;
370 if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' $organizationsql order by id ASC")){
371 //
372 // Retrieve user tracking data for each learning object
373 //
530a61d5 374
375 // Added by Pham Minh Duc
376 $suspendedscoid = scorm_get_suspendedscoid($scorm->id,$user->id,$attempt);
377 // End add
378
dc383b6f 379 $usertracks = array();
380 foreach ($scoes as $sco) {
381 if (!empty($sco->launch)) {
382 if ($usertrack=scorm_get_tracks($sco->id,$user->id,$attempt)) {
383 if ($usertrack->status == '') {
384 $usertrack->status = 'notattempted';
385 }
386 $usertracks[$sco->identifier] = $usertrack;
387 }
388 }
389 }
390
391 $level=0;
392 $sublist=1;
393 $previd = 0;
394 $nextid = 0;
395 $findnext = false;
396 $parents[$level]='/';
397
398 foreach ($scoes as $sco) {
399 if ($parents[$level]!=$sco->parent) {
400 if ($newlevel = array_search($sco->parent,$parents)) {
401 for ($i=0; $i<($level-$newlevel); $i++) {
402 $result->toc .= "\t\t</ul></li>\n";
403 }
404 $level = $newlevel;
405 } else {
406 $i = $level;
407 $closelist = '';
408 while (($i > 0) && ($parents[$level] != $sco->parent)) {
409 $closelist .= "\t\t</ul></li>\n";
410 $i--;
411 }
412 if (($i == 0) && ($sco->parent != $currentorg)) {
413 $style = '';
414 if (isset($_COOKIE['hide:SCORMitem'.$sco->id])) {
415 $style = ' style="display: none;"';
416 }
417 $result->toc .= "\t\t<li><ul id='$sublist' class='$liststyle'$style>\n";
418 $level++;
419 } else {
420 $result->toc .= $closelist;
421 $level = $i;
422 }
423 $parents[$level]=$sco->parent;
424 }
425 }
426 $result->toc .= "\t\t<li>";
427 $nextsco = next($scoes);
428 if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
429 $sublist++;
430 $icon = 'minus';
431 if (isset($_COOKIE['hide:SCORMitem'.$nextsco->id])) {
432 $icon = 'plus';
433 }
434 $result->toc .= '<a href="javascript:expandCollide(img'.$sublist.','.$sublist.','.$nextsco->id.');"><img id="img'.$sublist.'" src="'.$scormpixdir.'/'.$icon.'.gif" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';
435 } else {
436 $result->toc .= '<img src="'.$scormpixdir.'/spacer.gif" />';
437 }
438 if (empty($sco->title)) {
439 $sco->title = $sco->identifier;
440 }
441 if (!empty($sco->launch)) {
442 $startbold = '';
443 $endbold = '';
444 $score = '';
445 if (empty($scoid) && ($mode != 'normal')) {
446 $scoid = $sco->id;
447 }
530a61d5 448 if (isset($usertracks[$sco->identifier])) {
449 $usertrack = $usertracks[$sco->identifier];
450 $strstatus = get_string($usertrack->status,'scorm');
451 if ($sco->scormtype == 'sco') {
452 $statusicon = '<img src="'.$scormpixdir.'/'.$usertrack->status.'.gif" alt="'.$strstatus.'" title="'.$strstatus.'" />';
dc383b6f 453 } else {
530a61d5 454 $statusicon = '<img src="'.$scormpixdir.'/assetc.gif" alt="'.get_string('assetlaunched','scorm').'" title="'.get_string('assetlaunched','scorm').'" />';
455 }
456
457 if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {
458 $incomplete = true;
dc383b6f 459 if ($play && empty($scoid)) {
460 $scoid = $sco->id;
461 }
530a61d5 462 }
463 if ($usertrack->score_raw != '') {
464 $score = '('.get_string('score','scorm').':&nbsp;'.$usertrack->score_raw.')';
465 }
466 $strsuspended = get_string('suspended','scorm');
e7433896 467 if (isset($usertrack->{'cmi.core.exit'}) && ($usertrack->{'cmi.core.exit'} == 'suspend')) {
530a61d5 468 $statusicon = '<img src="'.$scormpixdir.'/suspend.gif" alt="'.$strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
469 }
470 } else {
471 if ($play && empty($scoid)) {
472 $scoid = $sco->id;
473 }
474 if ($sco->scormtype == 'sco') {
475 $statusicon = '<img src="'.$scormpixdir.'/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
476 $incomplete = true;
477 } else {
478 $statusicon = '<img src="'.$scormpixdir.'/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
dc383b6f 479 }
480 }
530a61d5 481
dc383b6f 482 if ($sco->id == $scoid) {
483 $startbold = '<b>';
484 $endbold = '</b>';
485 $findnext = true;
486 $shownext = $sco->next;
487 $showprev = $sco->previous;
488 }
489
490 if (($nextid == 0) && (scorm_count_launchable($scorm->id,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
491 if (!empty($sco->launch)) {
492 $previd = $sco->id;
493 }
494 }
495 if (empty($sco->prerequisites) || scorm_eval_prerequisites($sco->prerequisites,$usertracks)) {
496 if ($sco->id == $scoid) {
497 $result->prerequisites = true;
498 }
499 // Modified by Pham Minh Duc
530a61d5 500 // if (scorm_isChoice($scorm->id,$sco->id) == 1) {
dc383b6f 501 $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid='.$sco->id;
e7433896 502 $result->toc .= $statusicon.'&nbsp;'.$startbold.'<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score.$endbold."</li>\n";
dc383b6f 503 $tocmenus[$sco->id] = scorm_repeater('&minus;',$level) . '&gt;' . format_string($sco->title);
530a61d5 504 // } else {
505 // $result->toc .= '&nbsp;'.$startbold.format_string($sco->title).$score.$endbold."</li>\n";
506 // $tocmenus[$sco->id] = scorm_repeater('&minus;',$level) . '&gt;' . format_string($sco->title);
507 // }
dc383b6f 508 // End modify
509 } else {
510 if ($sco->id == $scoid) {
511 $result->prerequisites = false;
512 }
513 $result->toc .= '&nbsp;'.$sco->title."</li>\n";
514 }
515 } else {
516 $result->toc .= '&nbsp;'.$sco->title."</li>\n";
517 }
518 if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
519 if (!empty($nextsco->launch)) {
520 $nextid = $nextsco->id;
521 }
522 }
523 }
524 for ($i=0;$i<$level;$i++) {
525 $result->toc .= "\t\t</ul></li>\n";
526 }
527
528 if ($play) {
529 $sco = get_record('scorm_scoes','id',$scoid);
530 $sco->previd = $previd;
531 $sco->nextid = $nextid;
532 $result->sco = $sco;
533 $result->incomplete = $incomplete;
534 } else {
535 $result->incomplete = $incomplete;
536 }
537 }
538 $result->toc .= "\t</ul>\n";
539 if ($scorm->hidetoc == 0) {
540 $result->toc .= '
541 <script language="javascript" type="text/javascript">
542 <!--
543 function expandCollide(which,list,item) {
544 var nn=document.ids?true:false
545 var w3c=document.getElementById?true:false
546 var beg=nn?"document.ids.":w3c?"document.getElementById(":"document.all.";
547 var mid=w3c?").style":".style";
548
549 if (eval(beg+list+mid+".display") != "none") {
550 which.src = "'.$scormpixdir.'/plus.gif";
551 eval(beg+list+mid+".display=\'none\';");
552 new cookie("hide:SCORMitem" + item, 1, 356, "/").set();
553 } else {
554 which.src = "'.$scormpixdir.'/minus.gif";
555 eval(beg+list+mid+".display=\'block\';");
556 new cookie("hide:SCORMitem" + item, 1, -1, "/").set();
557 }
558 }
559 -->
560 </script>'."\n";
561 }
562
563 $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid=';
564 $result->tocmenu = popup_form($url,$tocmenus, "tocmenu", $sco->id, '', '', '', true);
565
566 return $result;
567}
568
569//
570// Functions added by Pham Minh Duc
571//
572function scorm_get_score_from_parent($sco,$userid,$grademethod=VALUESCOES) {
573 $scores = NULL;
574 $scores->scoes = 0;
575 $scores->values = 0;
576 $scores->scaled = 0;
577 $scores->max = 0;
578 $scores->sum = 0;
579
580 $scoes_total = 0;
581 $scoes_count = 0;
582 $attempt = scorm_get_last_attempt($sco->scorm, $userid);
583 $scoes = get_records('scorm_scoes', 'parent', $sco->identifier);
584 foreach ($scoes as $sco)
585 {
586 $scoes_total++;
587 if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {
588 if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) {
589 $scoes_count++;
590 }
591
592 $scoreraw = $userdata->score_raw;
593 if (!empty($userdata->score_raw)) {
594 $scores->values++;
595 $scores->sum += $userdata->score_raw;
596 $scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max;
597 }
598 if (!empty($userdata->score_scaled)) {
599 $scores->scaled = $scores->scaled + $userdata->score_scaled;
600 }
601 }
602 }
603 if ($scoes_count > 0) {
604 $scores->scaled = ($scores->scaled)/($scoes_count);
605 }
606 switch ($grademethod) {
607 case VALUEHIGHEST:
608 return $scores->max;
609 break;
610 case VALUEAVERAGE:
611 if ($scores->values > 0) {
612 return $scores->sum/$scores->values;
613 } else {
614 return 0;
615 }
616 break;
617 case VALUESUM:
618 return $scores->sum;
619 break;
620 case VALUESCOES:
621 return $scores->scaled;
622 break;
623 }
624}
625
626function scorm_get_user_sco_count($scormid, $userid) {
627 $scoes_count = 0;
628 $attempt = scorm_get_last_attempt($current->scorm, $userid);
629 $scoes = get_records('scorm_scoes', 'scorm', $scormid);
630
631 foreach ($scoes as $sco) {
632 if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {
633 if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) {
634 $scoes_count++;
635 }
636 }
637 }
638 return $scoes_count;
639}
640
641function scorm_grade_user_new($scoes, $userid, $grademethod=VALUESCOES) {
642 $scores = NULL;
643 $scores->scoes = 0;
644 $scores->values = 0;
645 $scores->scaled = 0;
646 $scores->max = 0;
647 $scores->sum = 0;
648
649 if (!$scoes) {
650 return '';
651 }
652 $current = current($scoes);
653 $attempt = scorm_get_last_attempt($current->scorm, $userid);
654 foreach ($scoes as $sco) {
655 if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {
656 if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) {
657 $scores->scoes++;
658 }
659 $scaled = $userdata->score_scaled;
660 $scoreraw = $userdata->score_raw;
661 if ($scaled ==0){
662 $scores->scaled = $scores->scaled / $scores->scoes;
663 }
664 if (!empty($userdata->score_raw)) {
665 $scores->values++;
666 $scores->sum += $userdata->score_raw;
667 $scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max;
668 }
669 if (!empty($scaled)) {
670 $scores->scaled = (($scores->scaled) * ($scores->scoes-1) + $scaled)/($scores->scoes);
671 }
672 }
673 }
674 switch ($grademethod) {
675 case VALUEHIGHEST:
676 return $scores->max;
677 break;
678 case VALUEAVERAGE:
679 if ($scores->values > 0) {
680 return $scores->sum/$scores->values;
681 } else {
682 return 0;
683 }
684 break;
685 case VALUESUM:
686 return $scores->sum;
687 break;
688 case VALUESCOES:
689 return $scores->scaled;
690 break;
691 }
692}
693
530a61d5 694function scorm_get_suspendedscoid($scormid,$userid,$attempt) {
695 if ($sco = get_record_select("scorm_scoes_track","scormid=$scormid AND userid=$userid AND attempt=$attempt AND (element='cmi.exit' OR element='cmi.core.exit') AND value='suspend'")) {
696 return $sco->scoid;
dc383b6f 697 } else {
698 return 0;
699 }
700}
701
702function scorm_set_attempt($scoid,$userid) {
703 if ($scormid = get_field('scorm_scoes','scorm','id',$scoid)) {
704 $attempt = scorm_get_last_attempt($scormid,$userid);
705 } else {
706 $attempt = 1;
707 }
708 $scormtype = get_field('scorm_scoes','scormtype','id',$scoid) ;
709 if ($scormtype == 'sco'){
710 $element = 'cmi.attempt_status';
711 $value = 'attempted';
712 scorm_insert_track($userid,$scormid,$scoid,$attempt,$element,$value);
713 }
714}
715
dc383b6f 716function scorm_isChoice($scormid,$scoid)
717{
530a61d5 718 $sco = get_record("scorm_scoes","id",$scoid);
dc383b6f 719 $scoparent = get_record("scorm_sequencing_controlmode","scormid",$scormid,"identifier",$sco->parent);
720
721 return $scoparent->choice;
722}
723
724function scorm_isChoiceexit($scormid,$scoid)
725{
530a61d5 726 $sco = get_record("scorm_scoes","id",$scoid);
dc383b6f 727 $scoparent = get_record("scorm_sequencing_controlmode","scormid",$scormid,"identifier",$sco->parent);
728
729 return $scoparent->choiceexit;
730}
731// End add
732
733?>