Splitted all the scorm/aicc library in type separeted files
[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;
338
339 // Added by Pham Minh Duc
340 $suspendscoid = scorm_get_suspendscoid($scorm->id,$user->id);
341 // End add
342
343 $strexpand = get_string('expcoll','scorm');
344 $modestr = '';
345 if ($mode == 'browse') {
346 $modestr = '&amp;mode='.$mode;
347 }
348 $scormpixdir = $CFG->modpixpath.'/scorm/pix';
349
350 $result = new stdClass();
351 $result->toc = "<ul id='0' class='$liststyle'>\n";
352 $tocmenus = array();
353 $result->prerequisites = true;
354 $incomplete = false;
355
356 //
357 // Get the current organization infos
358 //
359 $organizationsql = '';
360 if (!empty($currentorg)) {
361 if (($organizationtitle = get_field('scorm_scoes','title','scorm',$scorm->id,'identifier',$currentorg)) != '') {
362 $result->toc .= "\t<li>$organizationtitle</li>\n";
363 $tocmenus[] = $organizationtitle;
364 }
365 $organizationsql = "AND organization='$currentorg'";
366 }
367 //
368 // If not specified retrieve the last attempt number
369 //
370 if (empty($attempt)) {
371 $attempt = scorm_get_last_attempt($scorm->id, $user->id);
372 }
373 $result->attemptleft = $scorm->maxattempt - $attempt;
374 if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' $organizationsql order by id ASC")){
375 //
376 // Retrieve user tracking data for each learning object
377 //
378 $usertracks = array();
379 foreach ($scoes as $sco) {
380 if (!empty($sco->launch)) {
381 if ($usertrack=scorm_get_tracks($sco->id,$user->id,$attempt)) {
382 if ($usertrack->status == '') {
383 $usertrack->status = 'notattempted';
384 }
385 $usertracks[$sco->identifier] = $usertrack;
386 }
387 }
388 }
389
390 $level=0;
391 $sublist=1;
392 $previd = 0;
393 $nextid = 0;
394 $findnext = false;
395 $parents[$level]='/';
396
397 foreach ($scoes as $sco) {
398 if ($parents[$level]!=$sco->parent) {
399 if ($newlevel = array_search($sco->parent,$parents)) {
400 for ($i=0; $i<($level-$newlevel); $i++) {
401 $result->toc .= "\t\t</ul></li>\n";
402 }
403 $level = $newlevel;
404 } else {
405 $i = $level;
406 $closelist = '';
407 while (($i > 0) && ($parents[$level] != $sco->parent)) {
408 $closelist .= "\t\t</ul></li>\n";
409 $i--;
410 }
411 if (($i == 0) && ($sco->parent != $currentorg)) {
412 $style = '';
413 if (isset($_COOKIE['hide:SCORMitem'.$sco->id])) {
414 $style = ' style="display: none;"';
415 }
416 $result->toc .= "\t\t<li><ul id='$sublist' class='$liststyle'$style>\n";
417 $level++;
418 } else {
419 $result->toc .= $closelist;
420 $level = $i;
421 }
422 $parents[$level]=$sco->parent;
423 }
424 }
425 $result->toc .= "\t\t<li>";
426 $nextsco = next($scoes);
427 if (($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
428 $sublist++;
429 $icon = 'minus';
430 if (isset($_COOKIE['hide:SCORMitem'.$nextsco->id])) {
431 $icon = 'plus';
432 }
433 $result->toc .= '<a href="javascript:expandCollide(img'.$sublist.','.$sublist.','.$nextsco->id.');"><img id="img'.$sublist.'" src="'.$scormpixdir.'/'.$icon.'.gif" alt="'.$strexpand.'" title="'.$strexpand.'"/></a>';
434 } else {
435 $result->toc .= '<img src="'.$scormpixdir.'/spacer.gif" />';
436 }
437 if (empty($sco->title)) {
438 $sco->title = $sco->identifier;
439 }
440 if (!empty($sco->launch)) {
441 $startbold = '';
442 $endbold = '';
443 $score = '';
444 if (empty($scoid) && ($mode != 'normal')) {
445 $scoid = $sco->id;
446 }
447 // Modified by Pham Minh Duc
448 if ($suspendscoid == $sco->id){
449 $result->toc .= '<img src="'.$scormpixdir.'/suspend.gif" alt="Dang tam dung o day" title="Dang dung o day" />';
450 } else {
451 if (isset($usertracks[$sco->identifier])) {
452 $usertrack = $usertracks[$sco->identifier];
453 $strstatus = get_string($usertrack->status,'scorm');
454 $result->toc .= '<img src="'.$scormpixdir.'/'.$usertrack->status.'.gif" alt="'.$strstatus.'" title="'.$strstatus.'" />';
455
456 if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {
457 $incomplete = true;
458 if ($play && empty($scoid)) {
459 $scoid = $sco->id;
460 }
461 }
462 if ($usertrack->score_raw != '') {
463 $score = '('.get_string('score','scorm').':&nbsp;'.$usertrack->score_raw.')';
464 }
465 } else {
466 if ($play && empty($scoid)) {
467 $scoid = $sco->id;
468 }
469 if ($sco->scormtype == 'sco') {
470 $result->toc .= '<img src="'.$scormpixdir.'/notattempted.gif" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
471 $incomplete = true;
472 } else {
473 $result->toc .= '<img src="'.$scormpixdir.'/asset.gif" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
474 }
475 }
476 }
477 // End Modify
478 if ($sco->id == $scoid) {
479 $startbold = '<b>';
480 $endbold = '</b>';
481 $findnext = true;
482 $shownext = $sco->next;
483 $showprev = $sco->previous;
484 }
485
486 if (($nextid == 0) && (scorm_count_launchable($scorm->id,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
487 if (!empty($sco->launch)) {
488 $previd = $sco->id;
489 }
490 }
491 if (empty($sco->prerequisites) || scorm_eval_prerequisites($sco->prerequisites,$usertracks)) {
492 if ($sco->id == $scoid) {
493 $result->prerequisites = true;
494 }
495 // Modified by Pham Minh Duc
496 if (scorm_isChoice($scorm->id,$sco->id) == 1) {
497 $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid='.$sco->id;
498 $result->toc .= '&nbsp;'.$startbold.'<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score.$endbold."</li>\n";
499 $tocmenus[$sco->id] = scorm_repeater('&minus;',$level) . '&gt;' . format_string($sco->title);
500 } else {
501 $result->toc .= '&nbsp;'.$startbold.format_string($sco->title).$score.$endbold."</li>\n";
502 $tocmenus[$sco->id] = scorm_repeater('&minus;',$level) . '&gt;' . format_string($sco->title);
503 }
504 // End modify
505 } else {
506 if ($sco->id == $scoid) {
507 $result->prerequisites = false;
508 }
509 $result->toc .= '&nbsp;'.$sco->title."</li>\n";
510 }
511 } else {
512 $result->toc .= '&nbsp;'.$sco->title."</li>\n";
513 }
514 if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
515 if (!empty($nextsco->launch)) {
516 $nextid = $nextsco->id;
517 }
518 }
519 }
520 for ($i=0;$i<$level;$i++) {
521 $result->toc .= "\t\t</ul></li>\n";
522 }
523
524 if ($play) {
525 $sco = get_record('scorm_scoes','id',$scoid);
526 $sco->previd = $previd;
527 $sco->nextid = $nextid;
528 $result->sco = $sco;
529 $result->incomplete = $incomplete;
530 } else {
531 $result->incomplete = $incomplete;
532 }
533 }
534 $result->toc .= "\t</ul>\n";
535 if ($scorm->hidetoc == 0) {
536 $result->toc .= '
537 <script language="javascript" type="text/javascript">
538 <!--
539 function expandCollide(which,list,item) {
540 var nn=document.ids?true:false
541 var w3c=document.getElementById?true:false
542 var beg=nn?"document.ids.":w3c?"document.getElementById(":"document.all.";
543 var mid=w3c?").style":".style";
544
545 if (eval(beg+list+mid+".display") != "none") {
546 which.src = "'.$scormpixdir.'/plus.gif";
547 eval(beg+list+mid+".display=\'none\';");
548 new cookie("hide:SCORMitem" + item, 1, 356, "/").set();
549 } else {
550 which.src = "'.$scormpixdir.'/minus.gif";
551 eval(beg+list+mid+".display=\'block\';");
552 new cookie("hide:SCORMitem" + item, 1, -1, "/").set();
553 }
554 }
555 -->
556 </script>'."\n";
557 }
558
559 $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid=';
560 $result->tocmenu = popup_form($url,$tocmenus, "tocmenu", $sco->id, '', '', '', true);
561
562 return $result;
563}
564
565//
566// Functions added by Pham Minh Duc
567//
568function scorm_get_score_from_parent($sco,$userid,$grademethod=VALUESCOES) {
569 $scores = NULL;
570 $scores->scoes = 0;
571 $scores->values = 0;
572 $scores->scaled = 0;
573 $scores->max = 0;
574 $scores->sum = 0;
575
576 $scoes_total = 0;
577 $scoes_count = 0;
578 $attempt = scorm_get_last_attempt($sco->scorm, $userid);
579 $scoes = get_records('scorm_scoes', 'parent', $sco->identifier);
580 foreach ($scoes as $sco)
581 {
582 $scoes_total++;
583 if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {
584 if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) {
585 $scoes_count++;
586 }
587
588 $scoreraw = $userdata->score_raw;
589 if (!empty($userdata->score_raw)) {
590 $scores->values++;
591 $scores->sum += $userdata->score_raw;
592 $scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max;
593 }
594 if (!empty($userdata->score_scaled)) {
595 $scores->scaled = $scores->scaled + $userdata->score_scaled;
596 }
597 }
598 }
599 if ($scoes_count > 0) {
600 $scores->scaled = ($scores->scaled)/($scoes_count);
601 }
602 switch ($grademethod) {
603 case VALUEHIGHEST:
604 return $scores->max;
605 break;
606 case VALUEAVERAGE:
607 if ($scores->values > 0) {
608 return $scores->sum/$scores->values;
609 } else {
610 return 0;
611 }
612 break;
613 case VALUESUM:
614 return $scores->sum;
615 break;
616 case VALUESCOES:
617 return $scores->scaled;
618 break;
619 }
620}
621
622function scorm_get_user_sco_count($scormid, $userid) {
623 $scoes_count = 0;
624 $attempt = scorm_get_last_attempt($current->scorm, $userid);
625 $scoes = get_records('scorm_scoes', 'scorm', $scormid);
626
627 foreach ($scoes as $sco) {
628 if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {
629 if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) {
630 $scoes_count++;
631 }
632 }
633 }
634 return $scoes_count;
635}
636
637function scorm_grade_user_new($scoes, $userid, $grademethod=VALUESCOES) {
638 $scores = NULL;
639 $scores->scoes = 0;
640 $scores->values = 0;
641 $scores->scaled = 0;
642 $scores->max = 0;
643 $scores->sum = 0;
644
645 if (!$scoes) {
646 return '';
647 }
648 $current = current($scoes);
649 $attempt = scorm_get_last_attempt($current->scorm, $userid);
650 foreach ($scoes as $sco) {
651 if ($userdata=scorm_get_tracks($sco->id, $userid,$attempt)) {
652 if (($userdata->status == 'completed') || ($userdata->success_status == 'passed')) {
653 $scores->scoes++;
654 }
655 $scaled = $userdata->score_scaled;
656 $scoreraw = $userdata->score_raw;
657 if ($scaled ==0){
658 $scores->scaled = $scores->scaled / $scores->scoes;
659 }
660 if (!empty($userdata->score_raw)) {
661 $scores->values++;
662 $scores->sum += $userdata->score_raw;
663 $scores->max = ($userdata->score_raw > $scores->max)?$userdata->score_raw:$scores->max;
664 }
665 if (!empty($scaled)) {
666 $scores->scaled = (($scores->scaled) * ($scores->scoes-1) + $scaled)/($scores->scoes);
667 }
668 }
669 }
670 switch ($grademethod) {
671 case VALUEHIGHEST:
672 return $scores->max;
673 break;
674 case VALUEAVERAGE:
675 if ($scores->values > 0) {
676 return $scores->sum/$scores->values;
677 } else {
678 return 0;
679 }
680 break;
681 case VALUESUM:
682 return $scores->sum;
683 break;
684 case VALUESCOES:
685 return $scores->scaled;
686 break;
687 }
688}
689
690function scorm_insert_statistic($statisticInput){
691 $id = null;
692 if ($statistic = get_record_select('scorm_statistic',"userid='$statisticInput->userid' AND scormid='$statisticInput->scormid'")) {
693
694 $statistic->durationtime = $statisticInput->duration;
695 $statistic->accesstime = $statisticInput->accesstime;
696 $statistic->status = $statisticInput->status;
697 $statistic->attemptnumber = $statisticInput->attemptnumber;
698 $id = update_record('scorm_statistic',$statistic);
699 } else {
700 $id = insert_record('scorm_statistic',$statisticInput);
701 }
702 return $id;
703}
704
705function scorm_insert_trackmodel($userid,$scormid,$scoid,$attempt) {
706 $id = null;
707 if ($suspendtrack = get_record_select('scorm_suspendtrack',"userid='$userid' AND scormid='$scormid'")) {
708 $suspendtrack->suspendscoid = $scoid;
709 $suspendtrack->attempt = $attempt;
710 $id = update_record('scorm_suspendtrack',$suspendtrack);
711 } else {
712 $suspendtrack->scormid = $scormid;
713 $suspendtrack->suspendscoid = $scoid;
714 $suspendtrack->userid = $userid;
715 $suspendtrack->attempt = $attempt;
716 $id = insert_record('scorm_suspendtrack',$suspendtrack);
717 }
718 return $id;
719}
720
721function scorm_get_suspendscoid($scormid,$userid) {
722 if ($sco = get_record("scorm_suspendtrack","scormid",$scormid,"userid",$userid)) {
723 $suspendscoid = $sco->suspendscoid;
724 return $suspendscoid;
725 } else {
726 return 0;
727 }
728}
729
730function scorm_set_attempt($scoid,$userid) {
731 if ($scormid = get_field('scorm_scoes','scorm','id',$scoid)) {
732 $attempt = scorm_get_last_attempt($scormid,$userid);
733 } else {
734 $attempt = 1;
735 }
736 $scormtype = get_field('scorm_scoes','scormtype','id',$scoid) ;
737 if ($scormtype == 'sco'){
738 $element = 'cmi.attempt_status';
739 $value = 'attempted';
740 scorm_insert_track($userid,$scormid,$scoid,$attempt,$element,$value);
741 }
742}
743
744function scorm_get_AbsoluteTimeLimit($scoid){
745 $sco = get_record("scorm_scoes","id",$scoid);
746 if (!empty($sco)){
747 return $sco->attemptAbsoluteDurationLimit;
748 }
749 return 0;
750}
751
752function scorm_update_status($scormid,$scoid)
753{
754
755}
756
757function scorm_get_nextsco($scormid,$scoid)
758{
759
760}
761
762function scorm_get_presco($scormid,$scoid)
763{
764
765}
766
767function scorm_isChoice($scormid,$scoid)
768{
769 $sco = get_record("scorm_sequencing_controlmode","scormid",$scormid,"scoid",$scoid);
770 $scoparent = get_record("scorm_sequencing_controlmode","scormid",$scormid,"identifier",$sco->parent);
771
772 return $scoparent->choice;
773}
774
775function scorm_isChoiceexit($scormid,$scoid)
776{
777 $sco = get_record("scorm_sequencing_controlmode","scormid",$scormid,"scoid",$scoid);
778 $scoparent = get_record("scorm_sequencing_controlmode","scormid",$scormid,"identifier",$sco->parent);
779
780 return $scoparent->choiceexit;
781}
782// End add
783
784?>