2 function scorm_get_resources($blocks) {
4 foreach ($blocks as $block) {
5 if ($block['name'] == 'RESOURCES') {
6 foreach ($block['children'] as $resource) {
7 if ($resource['name'] == 'RESOURCE') {
8 $resources[addslashes($resource['attrs']['IDENTIFIER'])] = $resource['attrs'];
16 function scorm_get_manifest($blocks,$scoes) {
17 static $parents = array();
23 if (count($blocks) > 0) {
24 foreach ($blocks as $block) {
25 switch ($block['name']) {
27 if (isset($block['children'])) {
28 foreach ($block['children'] as $metadata) {
29 if ($metadata['name'] == 'SCHEMAVERSION') {
30 if (empty($scoes->version
)) {
31 if (isset($metadata['tagData']) && (preg_match("/^(1\.2)$|^(CAM )?(1\.3)$/",$metadata['tagData'],$matches))) {
32 $scoes->version
= 'SCORM_'.$matches[count($matches)-1];
34 if (isset($metadata['tagData']) && (preg_match("/^2004 3rd Edition$/",$metadata['tagData'],$matches))) {
35 $scoes->version
= 'SCORM_1.3';
37 $scoes->version
= 'SCORM_1.2';
46 $manifest = addslashes($block['attrs']['IDENTIFIER']);
49 $resources = scorm_get_resources($block['children']);
50 $scoes = scorm_get_manifest($block['children'],$scoes);
51 if (count($scoes->elements
) <= 0) {
52 foreach ($resources as $item => $resource) {
53 if (!empty($resource['HREF'])) {
54 $sco = new stdClass();
55 $sco->identifier
= $item;
58 $sco->launch
= addslashes($resource['HREF']);
59 $sco->scormtype
= addslashes($resource['ADLCP:SCORMTYPE']);
60 $scoes->elements
[$manifest][$organization][$item] = $sco;
66 if (!isset($scoes->defaultorg
)) {
67 $scoes->defaultorg
= addslashes($block['attrs']['DEFAULT']);
69 $scoes = scorm_get_manifest($block['children'],$scoes);
72 $identifier = addslashes($block['attrs']['IDENTIFIER']);
74 $scoes->elements
[$manifest][$organization][$identifier]->identifier
= $identifier;
75 $scoes->elements
[$manifest][$organization][$identifier]->parent
= '/';
76 $scoes->elements
[$manifest][$organization][$identifier]->launch
= '';
77 $scoes->elements
[$manifest][$organization][$identifier]->scormtype
= '';
80 $parent = new stdClass();
81 $parent->identifier
= $identifier;
82 $parent->organization
= $organization;
83 array_push($parents, $parent);
84 $organization = $identifier;
86 $scoes = scorm_get_manifest($block['children'],$scoes);
91 $parent = array_pop($parents);
92 array_push($parents, $parent);
94 $identifier = addslashes($block['attrs']['IDENTIFIER']);
95 $scoes->elements
[$manifest][$organization][$identifier]->identifier
= $identifier;
96 $scoes->elements
[$manifest][$organization][$identifier]->parent
= $parent->identifier
;
97 if (!isset($block['attrs']['ISVISIBLE'])) {
98 $block['attrs']['ISVISIBLE'] = 'true';
100 $scoes->elements
[$manifest][$organization][$identifier]->isvisible
= addslashes($block['attrs']['ISVISIBLE']);
101 if (!isset($block['attrs']['PARAMETERS'])) {
102 $block['attrs']['PARAMETERS'] = '';
104 $scoes->elements
[$manifest][$organization][$identifier]->parameters
= addslashes($block['attrs']['PARAMETERS']);
105 if (!isset($block['attrs']['IDENTIFIERREF'])) {
106 $scoes->elements
[$manifest][$organization][$identifier]->launch
= '';
107 $scoes->elements
[$manifest][$organization][$identifier]->scormtype
= 'asset';
109 $idref = addslashes($block['attrs']['IDENTIFIERREF']);
111 if (isset($resources[$idref]['XML:BASE'])) {
112 $base = $resources[$idref]['XML:BASE'];
114 $scoes->elements
[$manifest][$organization][$identifier]->launch
= addslashes($base.$resources[$idref]['HREF']);
115 if (empty($resources[$idref]['ADLCP:SCORMTYPE'])) {
116 $resources[$idref]['ADLCP:SCORMTYPE'] = 'asset';
118 $scoes->elements
[$manifest][$organization][$identifier]->scormtype
= addslashes($resources[$idref]['ADLCP:SCORMTYPE']);
121 $parent = new stdClass();
122 $parent->identifier
= $identifier;
123 $parent->organization
= $organization;
124 array_push($parents, $parent);
126 $scoes = scorm_get_manifest($block['children'],$scoes);
131 $parent = array_pop($parents);
132 array_push($parents, $parent);
133 if (!isset($block['tagData'])) {
134 $block['tagData'] = '';
136 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->title
= addslashes($block['tagData']);
138 case 'ADLCP:PREREQUISITES':
139 if ($block['attrs']['TYPE'] == 'aicc_script') {
140 $parent = array_pop($parents);
141 array_push($parents, $parent);
142 if (!isset($block['tagData'])) {
143 $block['tagData'] = '';
145 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->prerequisites
= addslashes($block['tagData']);
148 case 'ADLCP:MAXTIMEALLOWED':
149 $parent = array_pop($parents);
150 array_push($parents, $parent);
151 if (!isset($block['tagData'])) {
152 $block['tagData'] = '';
154 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->maxtimeallowed
= addslashes($block['tagData']);
156 case 'ADLCP:TIMELIMITACTION':
157 $parent = array_pop($parents);
158 array_push($parents, $parent);
159 if (!isset($block['tagData'])) {
160 $block['tagData'] = '';
162 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->timelimitaction
= addslashes($block['tagData']);
164 case 'ADLCP:DATAFROMLMS':
165 $parent = array_pop($parents);
166 array_push($parents, $parent);
167 if (!isset($block['tagData'])) {
168 $block['tagData'] = '';
170 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->datafromlms
= addslashes($block['tagData']);
172 case 'ADLCP:MASTERYSCORE':
173 $parent = array_pop($parents);
174 array_push($parents, $parent);
175 if (!isset($block['tagData'])) {
176 $block['tagData'] = '';
178 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->masteryscore
= addslashes($block['tagData']);
180 case 'ADLCP:COMPLETIONTHRESHOLD':
181 $parent = array_pop($parents);
182 array_push($parents, $parent);
183 if (!isset($block['tagData'])) {
184 $block['tagData'] = '';
186 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->threshold
= addslashes($block['tagData']);
188 case 'ADLNAV:PRESENTATION':
189 $parent = array_pop($parents);
190 array_push($parents, $parent);
191 if (!empty($block['children'])) {
192 foreach ($block['children'] as $adlnav) {
193 if ($adlnav['name'] == 'ADLNAV:NAVIGATIONINTERFACE') {
194 foreach ($adlnav['children'] as $adlnavInterface) {
195 if ($adlnavInterface['name'] == 'ADLNAV:HIDELMSUI') {
196 if ($adlnavInterface['tagData'] == 'continue') {
197 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->hidecontinue
= 1;
199 if ($adlnavInterface['tagData'] == 'previous') {
200 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->hideprevious
= 1;
202 if ($adlnavInterface['tagData'] == 'exit') {
203 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->hideexit
= 1;
205 if ($adlnavInterface['tagData'] == 'exitAll') {
206 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->hideexitall
= 1;
208 if ($adlnavInterface['tagData'] == 'abandon') {
209 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->hideabandon
= 1;
211 if ($adlnavInterface['tagData'] == 'abandonAll') {
212 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->hideabandonall
= 1;
214 if ($adlnavInterface['tagData'] == 'suspendAll') {
215 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->hidesuspendall
= 1;
223 case 'IMSSS:SEQUENCING':
224 $parent = array_pop($parents);
225 array_push($parents, $parent);
226 if (!empty($block['children'])) {
227 foreach ($block['children'] as $sequencing) {
228 if ($sequencing['name']=='IMSSS:CONTROLMODE') {
229 if (isset($sequencing['attrs']['CHOICE'])) {
230 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->choice
= $sequencing['attrs']['CHOICE'] == 'true'?
1:0;
232 if (isset($sequencing['attrs']['CHOICEEXIT'])) {
233 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->choiceexit
= $sequencing['attrs']['CHOICEEXIT'] == 'true'?
1:0;
235 if (isset($sequencing['attrs']['FLOW'])) {
236 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->flow
= $sequencing['attrs']['FLOW'] == 'true'?
1:0;
238 if (isset($sequencing['attrs']['FORWARDONLY'])) {
239 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->forwardonly
= $sequencing['attrs']['FORWARDONLY'] == 'true'?
1:0;
241 if (isset($sequencing['attrs']['USECURRENTATTEMPTOBJECTINFO'])) {
242 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->usecurrentattemptobjectinfo
= $sequencing['attrs']['USECURRENTATTEMPTOBJECTINFO'] == 'true'?
1:0;
244 if (isset($sequencing['attrs']['USECURRENTATTEMPTPROGRESSINFO'])) {
245 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->usecurrentattemptprogressinfo
= $sequencing['attrs']['USECURRENTATTEMPTPROGRESSINFO'] == 'true'?
1:0;
248 if ($sequencing['name']=='ADLSEQ:CONSTRAINEDCHOICECONSIDERATIONS') {
249 if (isset($sequencing['attrs']['CONSTRAINCHOICE'])) {
250 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->constrainChoice
= $sequencing['attrs']['CONSTRAINCHOICE'] == 'true'?
1:0;
252 if (isset($sequencing['attrs']['PREVENTACTIVATION'])) {
253 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->preventactivation
= $sequencing['attrs']['PREVENTACTIVATION'] == 'true'?
1:0;
256 if ($sequencing['name']=='IMSSS:OBJECTIVES') {
257 $objectives = array();
258 foreach ($sequencing['children'] as $objective) {
259 $objectivedata = new stdClass();
260 $objectivedata->primaryobj
= 0;
261 switch ($objective['name']) {
262 case 'IMSSS:PRIMARYOBJECTIVE':
263 $objectivedata->primaryobj
= 1;
264 case 'IMSSS:OBJECTIVE':
265 $objectivedata->satisfiedbymeasure
= 0;
266 if (isset($objective['attrs']['SATISFIEDBYMEASURE'])) {
267 $objectivedata->satisfiedbymeasure
= $objective['attrs']['SATISFIEDBYMEASURE']== 'true'?
1:0;
269 $objectivedata->objectiveid
= '';
270 if (isset($objective['attrs']['OBJECTIVEID'])) {
271 $objectivedata->objectiveid
= $objective['attrs']['OBJECTIVEID'];
273 $objectivedata->minnormalizedmeasure
= 1.0;
274 if (!empty($objective['children'])) {
276 foreach ($objective['children'] as $objectiveparam) {
277 if ($objectiveparam['name']=='IMSSS:MINNORMALIZEDMEASURE') {
278 $objectivedata->minnormalizedmeasure
= $objectiveparam['tagData'];
280 if ($objectiveparam['name']=='IMSSS:MAPINFO') {
281 $mapinfo = new stdClass();
282 $mapinfo->targetobjectiveid
= '';
283 if (isset($objectiveparam['attrs']['TARGETOBJECTIVEID'])) {
284 $mapinfo->targetobjectiveid
= $objectiveparam['attrs']['TARGETOBJECTIVEID'];
286 $mapinfo->readsatisfiedstatus
= 1;
287 if (isset($objectiveparam['attrs']['READSATISFIEDSTATUS'])) {
288 $mapinfo->readsatisfiedstatus
= $objectiveparam['attrs']['READSATISFIEDSTATUS'] == 'true'?
1:0;
290 $mapinfo->writesatisfiedstatus
= 0;
291 if (isset($objectiveparam['attrs']['WRITESATISFIEDSTATUS'])) {
292 $mapinfo->writesatisfiedstatus
= $objectiveparam['attrs']['WRITESATISFIEDSTATUS'] == 'true'?
1:0;
294 $mapinfo->readnormalizemeasure
= 1;
295 if (isset($objectiveparam['attrs']['READNORMALIZEDMEASURE'])) {
296 $mapinfo->readnormalizemeasure
= $objectiveparam['attrs']['READNORMALIZEDMEASURE'] == 'true'?
1:0;
298 $mapinfo->writenormalizemeasure
= 0;
299 if (isset($objectiveparam['attrs']['WRITENORMALIZEDMEASURE'])) {
300 $mapinfo->writenormalizemeasure
= $objectiveparam['attrs']['WRITENORMALIZEDMEASURE'] == 'true'?
1:0;
302 array_push($mapinfos,$mapinfo);
305 if (!empty($mapinfos)) {
306 $objectivesdata->mapinfos
= $mapinfos;
311 //print_object($objectivedata);
312 array_push($objectives,$objectivedata);
314 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->objectives
= $objectives;
316 if ($sequencing['name']=='IMSSS:LIMITCONDITIONS') {
317 if (isset($sequencing['attrs']['ATTEMPTLIMIT'])) {
318 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->attemptLimit
= $sequencing['attrs']['ATTEMPTLIMIT'];
320 if (isset($sequencing['attrs']['ATTEMPTABSOLUTEDURATIONLIMIT'])) {
321 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->attemptAbsoluteDurationLimit
= $sequencing['attrs']['ATTEMPTABSOLUTEDURATIONLIMIT'];
324 if ($sequencing['name']=='IMSSS:ROLLUPRULES') {
325 if (isset($sequencing['attrs']['ROLLUPOBJECTIVESATISFIED'])) {
326 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->rollupobjectivesatisfied
= $sequencing['attrs']['ROLLUPOBJECTIVESATISFIED'] == 'true'?
1:0;;
328 if (isset($sequencing['attrs']['ROLLUPPROGRESSCOMPLETION'])) {
329 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->rollupprogresscompletion
= $sequencing['attrs']['ROLLUPPROGRESSCOMPLETION'] == 'true'?
1:0;
331 if (isset($sequencing['attrs']['OBJECTIVEMEASUREWEIGHT'])) {
332 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->objectivemeasureweight
= $sequencing['attrs']['OBJECTIVEMEASUREWEIGHT'];
335 if (!empty($sequencing['children'])){
336 $rolluprules = array();
337 foreach ($sequencing['children'] as $sequencingrolluprule) {
338 if ($sequencingrolluprule['name']=='IMSSS:ROLLUPRULE' ) {
339 $rolluprule = new stdClass();
340 $rolluprule->childactivityset
= 'all';
341 if (isset($sequencingrolluprule['attrs']['CHILDACTIVITYSET'])) {
342 $rolluprule->childactivityset
= $sequencingrolluprule['attrs']['CHILDACTIVITYSET'];
344 $rolluprule->minimumcount
= 0;
345 if (isset($sequencingrolluprule['attrs']['MINIMUMCOUNT'])) {
346 $rolluprule->minimumcount
= $sequencingrolluprule['attrs']['MINIMUMCOUNT'];
348 $rolluprule->minimumpercent
= 0.0000;
349 if (isset($sequencingrolluprule['attrs']['MINIMUMPERCENT'])) {
350 $rolluprule->minimumpercent
= $sequencingrolluprule['attrs']['MINIMUMPERCENT'];
352 if (!empty($sequencingrolluprule['children'])) {
353 foreach ($sequencingrolluprule['children'] as $rolluproleconditions) {
354 if ($rolluproleconditions['name']=='IMSSS:ROLLUPCONDITIONS') {
355 $conditions = array();
356 $rolluprule->conditioncombination
= 'all';
357 if (isset($rolluproleconditions['attrs']['CONDITIONCOMBINATION'])) {
358 $rolluprule->conditioncombination
= $rolluproleconditions['attrs']['CONDITIONCOMBINATION'];
360 foreach ($rolluproleconditions['children'] as $rolluprulecondition) {
361 if ($rolluprulecondition['name']=='IMSSS:ROLLUPCONDITION') {
362 $condition = new stdClass();
363 if (isset($rolluprulecondition['attrs']['CONDITION'])) {
364 $condition->cond
= $rolluprulecondition['attrs']['CONDITION'];
366 $condition->operator
= 'noOp';
367 if (isset($rolluprulecondition['attrs']['OPERATOR'])) {
368 $condition->operator
= $rolluprulecondition['attrs']['OPERATOR'];
370 array_push($conditions,$condition);
373 $rolluprule->conditions
= $conditions;
375 if ($rolluproleconditions['name']=='IMSSS:ROLLUPACTION') {
376 $rolluprule->rollupruleaction
= $rolluproleconditions['attrs']['ACTION'];
380 array_push($rolluprules, $rolluprule);
383 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->rolluprules
= $rolluprules;
387 if ($sequencing['name']=='IMSSS:SEQUENCINGRULES') {
388 if (!empty($sequencing['children'])) {
389 $sequencingrules = array();
390 foreach ($sequencing['children'] as $conditionrules) {
392 switch($conditionrules['name']) {
393 case 'IMSSS:PRECONDITIONRULE':
396 case 'IMSSS:POSTCONDITIONRULE':
399 case 'IMSSS:EXITCONDITIONRULE':
403 if (!empty($conditionrules['children'])) {
404 $sequencingrule = new stdClass();
405 foreach ($conditionrules['children'] as $conditionrule) {
406 if ($conditionrule['name']=='IMSSS:RULECONDITIONS') {
407 $ruleconditions = array();
408 $sequencingrule->conditioncombination
= 'all';
409 if (isset($conditionrule['attrs']['CONDITIONCOMBINATION'])) {
410 $sequencingrule->conditioncombination
= $conditionrule['attrs']['CONDITIONCOMBINATION'];
412 foreach ($conditionrule['children'] as $rulecondition) {
413 if ($rulecondition['name']=='IMSSS:RULECONDITION') {
414 $condition = new stdClass();
415 if (isset($rulecondition['attrs']['CONDITION'])) {
416 $condition->cond
= $rulecondition['attrs']['CONDITION'];
418 $condition->operator
= 'noOp';
419 if (isset($rulecondition['attrs']['OPERATOR'])) {
420 $condition->operator
= $rulecondition['attrs']['OPERATOR'];
422 $condition->measurethreshold
= 0.0000;
423 if (isset($rulecondition['attrs']['MEASURETHRESHOLD'])) {
424 $condition->measurethreshold
= $rulecondition['attrs']['MEASURETHRESHOLD'];
426 $condition->referencedobjective
= '';
427 if (isset($rulecondition['attrs']['REFERENCEDOBJECTIVE'])) {
428 $condition->referencedobjective
= $rulecondition['attrs']['REFERENCEDOBJECTIVE'];
430 array_push($ruleconditions,$condition);
433 $sequencingrule->ruleconditions
= $ruleconditions;
435 if ($conditionrule['name']=='IMSSS:RULEACTION') {
436 $sequencingrule->action
= $conditionrule['attrs']['ACTION'];
438 $sequencingrule->type
= $conditiontype;
440 array_push($sequencingrules,$sequencingrule);
443 $scoes->elements
[$manifest][$parent->organization
][$parent->identifier
]->sequencingrules
= $sequencingrules;
455 function scorm_parse_scorm($pkgdir,$scormid) {
459 $manifestfile = $pkgdir.'/imsmanifest.xml';
461 if (is_file($manifestfile)) {
463 $xmltext = file_get_contents($manifestfile);
465 $pattern = '/&(?!\w{2,6};)/';
466 $replacement = '&';
467 $xmltext = preg_replace($pattern, $replacement, $xmltext);
469 $objXML = new xml2Array();
470 $manifests = $objXML->parse($xmltext);
471 //print_object($manifests);
472 $scoes = new stdClass();
473 $scoes->version
= '';
474 $scoes = scorm_get_manifest($manifests,$scoes);
475 //print_object($scoes);
476 if (count($scoes->elements
) > 0) {
477 $olditems = get_records('scorm_scoes','scorm',$scormid);
478 foreach ($scoes->elements
as $manifest => $organizations) {
479 foreach ($organizations as $organization => $items) {
480 foreach ($items as $identifier => $item) {
481 // This new db mngt will support all SCORM future extensions
482 $newitem = new stdClass();
483 $newitem->scorm
= $scormid;
484 $newitem->manifest
= $manifest;
485 $newitem->organization
= $organization;
486 $standarddatas = array('parent', 'identifier', 'launch', 'scormtype', 'title');
487 foreach ($standarddatas as $standarddata) {
488 $newitem->$standarddata = addslashes($item->$standarddata);
492 if (!empty($olditems) && ($olditemid = scorm_array_search('identifier',$newitem->identifier
,$olditems))) {
493 $newitem->id
= $olditemid;
494 $id = update_record('scorm_scoes',$newitem);
495 unset($olditems[$olditemid]);
496 delete_records('scorm_scoes_data','scoid',$olditemid);
498 $id = insert_record('scorm_scoes',$newitem);
501 if ($optionaldatas = scorm_optionals_data($item,$standarddatas)) {
502 $data = new stdClass();
504 foreach ($optionaldatas as $optionaldata) {
505 if (isset($item->$optionaldata)) {
506 $data->name
= $optionaldata;
507 $data->value
= addslashes($item->$optionaldata);
508 $dataid = insert_record('scorm_scoes_data',$data);
513 if (isset($item->sequencingrules
)) {
514 foreach($item->sequencingrules
as $sequencingrule) {
515 $rule = new stdClass();
517 $rule->ruletype
= $sequencingrule->type
;
518 $rule->conditioncombination
= $sequencingrule->conditioncombination
;
519 $rule->action
= $sequencingrule->action
;
520 $ruleid = insert_record('scorm_seq_ruleconds',$rule);
521 if (isset($sequencingrule->ruleconditions
)) {
522 foreach($sequencingrule->ruleconditions
as $rulecondition) {
523 $rulecond = new stdClass();
524 $rulecond->scoid
= $id;
525 $rulecond->ruleconditionsid
= $ruleid;
526 $rulecond->referencedobjective
= $rulecondition->referencedobjective
;
527 $rulecond->measurethreshold
= $rulecondition->measurethreshold
;
528 $rulecond->cond
= $rulecondition->cond
;
529 $rulecondid = insert_record('scorm_seq_rulecond',$rulecond);
535 if (isset($item->rolluprules
)) {
536 foreach($item->rolluprules
as $rolluprule) {
537 $rollup = new stdClass();
538 $rollup->scoid
= $id;
539 $rollup->childactivityset
= $rolluprule->childactivityset
;
540 $rollup->minimumcount
= $rolluprule->minimumcount
;
541 $rollup->minimumpercent
= $rolluprule->minimumpercent
;
542 $rollup->rollupruleaction
= $rolluprule->rollupruleaction
;
543 $rollup->conditioncombination
= $rolluprule->conditioncombination
;
545 $rollupruleid = insert_record('scorm_seq_rolluprule',$rollup);
546 if (isset($rollup->conditions
)) {
547 foreach($rollup->conditions
as $condition){
548 $cond = new stdClass();
549 $cond->scoid
= $rollup->scoid
;
550 $cond->rollupruleid
= $rollupruleid;
551 $cond->operator
= $condition->operator
;
552 $cond->cond
= $condition->cond
;
553 $conditionid = insert_record('scorm_seq_rolluprulecond',$cond);
559 if (isset($item->objectives
)) {
560 foreach($item->objectives
as $objective) {
561 $obj = new stdClass();
563 $obj->primaryobj
= $objective->primaryobj
;
564 $obj->satisfiedbumeasure
= $objective->satisfiedbymeasure
;
565 $obj->objectiveid
= $objective->objectiveid
;
566 $obj->minnormalizedmeasure
= $objective->minnormalizedmeasure
;
567 $objectiveid = insert_record('scorm_seq_objective',$obj);
568 if (isset($objective->mapinfos
)) {
569 //print_object($objective->mapinfos);
570 foreach($objective->mapinfos
as $objmapinfo) {
571 $mapinfo = new stdClass();
572 $mapinfo->scoid
= $id;
573 $mapinfo->objectiveid
= $objectiveid;
574 $mapinfo->targetobjectiveid
= $objmapinfo->targetobjectiveid
;
575 $mapinfo->readsatisfiedstatus
= $objmapinfo->readsatisfiedstatus
;
576 $mapinfo->writesatisfiedstatus
= $objmapinfo->writesatisfiedstatus
;
577 $mapinfo->readnormalizedmeasure
= $objmapinfo->readnormalizedmeasure
;
578 $mapinfo->writenormalizedmeasure
= $objmapinfo->writenormalizedmeasure
;
579 $mapinfoid = insert_record('scorm_seq_mapinfo',$mapinfo);
584 //print_object($item);
585 if (($launch == 0) && ((empty($scoes->defaultorg
)) ||
($scoes->defaultorg
== $identifier))) {
591 if (!empty($olditems)) {
592 foreach($olditems as $olditem) {
593 delete_records('scorm_scoes','id',$olditem->id
);
594 delete_records('scorm_scoes_data','scoid',$olditem->id
);
595 delete_records('scorm_scoes_track','scoid',$olditem->id
);
596 delete_records('scorm_seq_objective','scoid',$olditem->id
);
597 delete_records('scorm_seq_mapinfo','scoid',$olditem->id
);
598 delete_records('scorm_seq_ruleconds','scoid',$olditem->id
);
599 delete_records('scorm_seq_rulecond','scoid',$olditem->id
);
600 delete_records('scorm_seq_rolluprule','scoid',$olditem->id
);
601 delete_records('scorm_seq_rollupcond','scoid',$olditem->id
);
604 set_field('scorm','version',$scoes->version
,'id',$scormid);
611 function scorm_optionals_data($item, $standarddata) {
613 $sequencingdata = array('sequencingrules','rolluprules','objectives');
614 foreach ($item as $element => $value) {
615 if (! in_array($element, $standarddata)) {
616 if (! in_array($element, $sequencingdata)) {
617 $result[] = $element;
624 function scorm_is_leaf($sco) {
625 if (get_record('scorm_scoes','scorm',$sco->scorm
,'parent',$sco->identifier
)) {
631 function scorm_get_parent($sco) {
632 if ($sco->parent
!= '/') {
633 if ($parent = get_record('scorm_scoes','scorm',$sco->scorm
,'identifier',$sco->parent
)) {
634 return scorm_get_sco($parent->id
);
640 function scorm_get_children($sco) {
641 if ($children = get_records('scorm_scoes','scorm',$sco->scorm
,'parent',$sco->identifier
)) {//originally this said parent instead of childrean
647 function scorm_get_available_children($sco){
648 $res = get_record('scorm_scoes_track','scoid',$scoid,'userid',$userid,'element','availablechildren');
649 if(!$res ||
$res == null){
653 return unserialize($res->value
);
657 function scorm_get_available_descendent($descend = array(),$sco){
662 $avchildren = scorm_get_available_children($sco);
663 foreach($avchildren as $avchild){
664 array_push($descend,$avchild);
666 foreach($avchildren as $avchild){
667 scorm_get_available_descendent($descend,$avchild);
672 function scorm_get_siblings($sco) {
673 if ($siblings = get_records('scorm_scoes','scorm',$sco->scorm
,'parent',$sco->parent
)) {
674 unset($siblings[$sco->id
]);
675 if (!empty($siblings)) {
682 function scorm_get_ancestors($sco) {
683 if ($sco->parent
!= '/') {
684 return array_push(scorm_get_ancestors(scorm_get_parent($sco)));
690 function scorm_get_preorder($preorder=array(),$sco) {
694 array_push($preorder,$sco);
695 $children = scorm_get_children($sco);
696 foreach ($children as $child){
697 scorm_get_preorder($sco);
704 function scorm_find_common_ancestor($ancestors, $sco) {
705 $pos = scorm_array_search('identifier',$sco->parent
,$ancestors);
706 if ($sco->parent
!= '/') {
707 if ($pos === false) {
708 return scorm_find_common_ancestor($ancestors,scorm_get_parent($sco));
715 Grab some XML data, either from a file, URL, etc. however you want. Assume storage in $strYourXML;
717 $objXML = new xml2Array();
718 $arrOutput = $objXML->parse($strYourXML);
719 print_r($arrOutput); //print it out, or do whatever!
724 var $arrOutput = array();
729 * Convert a utf-8 string to html entities
731 * @param string $str The UTF-8 string
734 function utf8_to_entities($str) {
745 * Parse an XML text string and create an array tree that rapresent the XML structure
747 * @param string $strInputXML The XML string
750 function parse($strInputXML) {
751 $this->resParser
= xml_parser_create ('UTF-8');
752 xml_set_object($this->resParser
,$this);
753 xml_set_element_handler($this->resParser
, "tagOpen", "tagClosed");
755 xml_set_character_data_handler($this->resParser
, "tagData");
757 $this->strXmlData
= xml_parse($this->resParser
,$strInputXML );
758 if(!$this->strXmlData
) {
759 die(sprintf("XML error: %s at line %d",
760 xml_error_string(xml_get_error_code($this->resParser
)),
761 xml_get_current_line_number($this->resParser
)));
764 xml_parser_free($this->resParser
);
766 return $this->arrOutput
;
769 function tagOpen($parser, $name, $attrs) {
770 $tag=array("name"=>$name,"attrs"=>$attrs);
771 array_push($this->arrOutput
,$tag);
774 function tagData($parser, $tagData) {
776 if(isset($this->arrOutput
[count($this->arrOutput
)-1]['tagData'])) {
777 $this->arrOutput
[count($this->arrOutput
)-1]['tagData'] .= $this->utf8_to_entities($tagData);
779 $this->arrOutput
[count($this->arrOutput
)-1]['tagData'] = $this->utf8_to_entities($tagData);
784 function tagClosed($parser, $name) {
785 $this->arrOutput
[count($this->arrOutput
)-2]['children'][] = $this->arrOutput
[count($this->arrOutput
)-1];
786 array_pop($this->arrOutput
);