2 //This php script contains all the stuff to backup/restore
5 //This is the "graphical" structure of the scorm mod:
8 // (CL,pk->id)---------------------
13 // (UL,pk->id, fk->scorm) |
17 // scorm_scoes_track |
18 // (UL,pk->id, fk->scormid, fk->scoid, fk->userid)--
20 // Meaning: pk->primary key field of the table
21 // fk->foreign key to link with parent
22 // nt->nested field (recursive data)
23 // CL->course level info
24 // UL->user level info
25 // files->table may have files)
27 //-----------------------------------------------------------
29 //This function executes all the restore procedure about this mod
30 function scorm_restore_mods($mod,$restore) {
36 //Get record from backup_ids
37 $data = backup_getid($restore->backup_unique_code
,$mod->modtype
,$mod->id
);
40 //Now get completed xmlized object
42 //traverse_xmlize($info); //Debug
43 //print_object ($GLOBALS['traverse_array']); //Debug
44 //$GLOBALS['traverse_array']=""; //Debug
46 //Now, build the SCORM record structure
47 $scorm->course
= $restore->course_id
;
48 $scorm->name
= backup_todb($info['MOD']['#']['NAME']['0']['#']);
49 $scorm->reference
= backup_todb($info['MOD']['#']['REFERENCE']['0']['#']);
50 $scorm->version
= backup_todb($info['MOD']['#']['VERSION']['0']['#']);
51 $scorm->md5hash
= backup_todb($info['MOD']['#']['MD5HASH']['0']['#']);
52 $scorm->maxgrade
= backup_todb($info['MOD']['#']['MAXGRADE']['0']['#']);
53 if (!is_int($scorm->maxgrade
)) {
56 $scorm->updatefreq
= backup_todb($info['MOD']['#']['UPDATEFREQ']['0']['#']);
57 if (!is_int($scorm->updatefreq
)) {
58 $scorm->updatefreq
= 0;
60 $scorm->maxattempt
= backup_todb($info['MOD']['#']['MAXATTEMPT']['0']['#']);
61 if (!is_int($scorm->maxattempt
)) {
62 $scorm->maxattempt
= 0;
64 $scorm->grademethod
= backup_todb($info['MOD']['#']['GRADEMETHOD']['0']['#']);
65 if (!is_int($scorm->grademethod
)) {
66 $scorm->grademethod
= 0;
68 if ($restore->backup_version
< 2005041500) {
69 $scorm->datadir
= substr(backup_todb($info['MOD']['#']['DATADIR']['0']['#']),1);
71 $scorm->datadir
= backup_todb($info['MOD']['#']['ID']['0']['#']);
73 $oldlaunch = backup_todb($info['MOD']['#']['LAUNCH']['0']['#']);
74 if ($restore->backup_version
< 2006102600) {
77 $scorm->skipview
= backup_todb($info['MOD']['#']['SKIPVIEW']['0']['#']);
79 $scorm->summary
= backup_todb($info['MOD']['#']['SUMMARY']['0']['#']);
80 $scorm->hidebrowse
= backup_todb($info['MOD']['#']['HIDEBROWSE']['0']['#']);
81 $scorm->hidetoc
= backup_todb($info['MOD']['#']['HIDETOC']['0']['#']);
82 $scorm->hidenav
= backup_todb($info['MOD']['#']['HIDENAV']['0']['#']);
83 $scorm->auto
= backup_todb($info['MOD']['#']['AUTO']['0']['#']);
84 if ($restore->backup_version
< 2005040200) {
85 $oldpopup = backup_todb($info['MOD']['#']['POPUP']['0']['#']);
86 if (!empty($oldpopup)) {
88 // Parse old popup field
90 $oldoptions = explode(',',$scorm->popup
);
91 foreach ($oldoptions as $oldoption) {
92 list($element,$value) = explode('=',$oldoption);
93 $element = trim($element);
94 $value = trim($value);
97 $scorm->width
= $value;
100 $scorm->height
= $value;
103 $options[] = $element.'='.$value;
107 $scorm->options
= implode($options,',');
110 $scorm->options
= '';
111 $scorm->width
= '100%';
112 $scorm->height
= 500;
115 $scorm->popup
= backup_todb($info['MOD']['#']['POPUP']['0']['#']);
116 $scorm->width
= backup_todb($info['MOD']['#']['WIDTH']['0']['#']);
117 if ($scorm->width
== 0) {
118 $scorm->width
= '100%';
120 $scorm->height
= backup_todb($info['MOD']['#']['HEIGHT']['0']['#']);
121 if ($scorm->height
== 0) {
122 $scorm->height
= 500;
125 $scorm->timemodified
= time();
127 //The structure is equal to the db, so insert the scorm
128 $newid = insert_record ("scorm",$scorm);
130 if (!defined('RESTORE_SILENTLY')) {
131 echo "<li>".get_string("modulename","scorm")." \"".format_string(stripslashes($scorm->name
),true)."\"</li>";
136 //We have the newid, update backup_ids
137 backup_putid($restore->backup_unique_code
,$mod->modtype
,
140 //Now copy moddata associated files
141 $status = scorm_restore_files ($scorm, $restore);
144 $status = scorm_scoes_restore_mods ($newid,$info,$restore,$mod->id
);
146 $launchsco = backup_getid($restore->backup_unique_code
,"scorm_scoes",$oldlaunch);
147 $scorm->launch
= $launchsco->new_id
;
148 update_record('scorm',$scorm);
162 //This function restores the scorm_scoes
163 function scorm_scoes_restore_mods($scorm_id,$info,$restore,$oldmodid) {
170 $scoes = $info['MOD']['#']['SCOES']['0']['#']['SCO'];
173 for($i = 0; $i < sizeof($scoes); $i++
) {
174 $sub_info = $scoes[$i];
176 //We'll need this later!!
177 $oldid = backup_todb($sub_info['#']['ID']['0']['#']);
179 //Now, build the scorm_scoes record structure
180 $sco->scorm
= $scorm_id;
181 $sco->manifest
= backup_todb($sub_info['#']['MANIFEST']['0']['#']);
182 $sco->organization
= backup_todb($sub_info['#']['ORGANIZATION']['0']['#']);
183 $sco->parent
= backup_todb($sub_info['#']['PARENT']['0']['#']);
184 $sco->identifier
= backup_todb($sub_info['#']['IDENTIFIER']['0']['#']);
185 $sco->launch
= backup_todb($sub_info['#']['LAUNCH']['0']['#']);
186 $sco->title
= backup_todb($sub_info['#']['TITLE']['0']['#']);
187 if ($restore->backup_version
< 2005031300) {
188 $sco->scormtype
= backup_todb($sub_info['#']['TYPE']['0']['#']);
190 $sco->scormtype
= backup_todb($sub_info['#']['SCORMTYPE']['0']['#']);
193 //The structure is equal to the db, so insert the scorm_scoes
194 $newid = insert_record ("scorm_scoes",$sco);
197 //We have the newid, update backup_ids
198 backup_putid($restore->backup_unique_code
,"scorm_scoes", $oldid, $newid);
204 //Now check if want to restore user data and do it.
205 scorm_scoes_seq_objective_restore_mods ($newid,$info,$restore);
206 scorm_scoes_seq_rolluprule_restore_mods ($newid,$info,$restore);
207 scorm_scoes_seq_ruleconds_restore_mods ($newid,$info,$restore);
208 if (restore_userdata_selected($restore,'scorm',$oldmodid)) {
209 //Restore scorm_scoes
211 if ($restore->backup_version
< 2005031300) {
212 $status = scorm_scoes_tracks_restore_mods_pre15 ($scorm_id,$info,$restore);
214 $status = scorm_scoes_tracks_restore_mods ($scorm_id,$info,$restore);
223 function scorm_scoes_seq_objective_restore_mods($sco_id,$info,$restore) {
229 //Get the discussions array
230 $objectives = array();
232 if (!empty($info['MOD']['#']['SEQ_OBJECTIVES']['0']['#']['SEQ_OBJECTIVE'])) {
233 $objectives = $info['MOD']['#']['SEQ_OBJECTIVES']['0']['#']['SEQ_OBJECTIVE'];
236 //Iterate over discussions
237 for($i = 0; $i < sizeof($objectives); $i++
) {
238 $obj_info = $objectives[$i];
241 //We'll need this later!!
242 $oldid = backup_todb($obj_info['#']['ID']['0']['#']);
243 //Now, build the FORUM_DISCUSSIONS record structure
244 $objective->scoid
= $sco_id;
245 $objective->primaryobj
= backup_todb($obj_info['#']['PRIMARYOBJ']['0']['#']);
246 $objective->objectiveid
= backup_todb($obj_info['#']['OBJECTIVEID']['0']['#']);
247 $objective->satisfiedbymeasure
= backup_todb($obj_info['#']['SATISFIEDBYMEASURE']['0']['#']);
248 $objective->minnormalizedmeasure
= backup_todb($obj_info['#']['MINNORMALIZEDMEASURE']['0']['#']);
250 //The structure is equal to the db, so insert the forum_discussions
251 $newid = insert_record ("scorm_seq_objective",$objective);
254 //We have the newid, update backup_ids
255 backup_putid($restore->backup_unique_code
,"scorm_seq_objective", $oldid, $newid);
261 if (($i+
1) %
50 == 0) {
262 if (!defined('RESTORE_SILENTLY')) {
264 if (($i+
1) %
1000 == 0) {
271 //Now restore the scorm_seq_mapinfo for each objective
273 $status = scorm_seq_mapinfo_restore_mods ($sco_id,$newid,$obj_info,$restore);
282 function scorm_scoes_seq_rolluprule_restore_mods($sco_id,$info,$restore) {
288 //Get the discussions array
289 $rolluprules = array();
291 if (!empty($info['MOD']['#']['SEQ_ROLLUPRULES']['0']['#']['SEQ_ROLLUPRULE'])) {
292 $rolluprules = $info['MOD']['#']['SEQ_ROLLUPRULES']['0']['#']['SEQ_ROLLUPRULE'];
295 //Iterate over discussions
296 for($i = 0; $i < sizeof($rolluprules); $i++
) {
297 $rol_info = $rolluprules[$i];
300 //We'll need this later!!
301 $oldid = backup_todb($rol_info['#']['ID']['0']['#']);
302 //Now, build the FORUM_DISCUSSIONS record structure
303 $rolluprule->scoid
= $sco_id;
304 $rolluprule->childactivityset
= backup_todb($rol_info['#']['CHILDACTIVITYSET']['0']['#']);
305 $rolluprule->minimumrule
= backup_todb($rol_info['#']['MINIMUMCOUNT']['0']['#']);
306 $rolluprule->minimumpercent
= backup_todb($rol_info['#']['MINIMUMPERCENT']['0']['#']);
307 $rolluprule->conditioncombination
= backup_todb($rol_info['#']['CONDITIONCOMBINATION']['0']['#']);
308 $rolluprule->action
= backup_todb($rol_info['#']['ACTION']['0']['#']);
310 //The structure is equal to the db, so insert the forum_discussions
311 $newid = insert_record ("scorm_seq_rolluprule",$rolluprule);
314 //We have the newid, update backup_ids
315 backup_putid($restore->backup_unique_code
,"scorm_seq_rolluprule", $oldid, $newid);
321 if (($i+
1) %
50 == 0) {
322 if (!defined('RESTORE_SILENTLY')) {
324 if (($i+
1) %
1000 == 0) {
331 //Now restore the scorm_seq_mapinfo for each objective
333 $status = scorm_seq_rolluprulecond_restore_mods ($sco_id, $newid,$obj_info,$restore);
340 function scorm_scoes_seq_ruleconds_restore_mods($sco_id,$info,$restore) {
346 //Get the discussions array
347 $ruleconds = array();
349 if (!empty($info['MOD']['#']['SEQ_RULECONDS']['0']['#']['SEQ_RULECOND'])) {
350 $ruleconds = $info['MOD']['#']['SEQ_RULECONDS']['0']['#']['SEQ_RULECOND'];
353 //Iterate over discussions
354 for($i = 0; $i < sizeof($ruleconds); $i++
) {
355 $rul_info = $ruleconds[$i];
358 //We'll need this later!!
359 $oldid = backup_todb($rul_info['#']['ID']['0']['#']);
361 $rulecond->scoid
= $sco_id;
362 $rulecond->conditioncombination
= backup_todb($rul_info['#']['CONDITIONCOMBINATION']['0']['#']);
363 $rulecond->minimumpercent
= backup_todb($rul_info['#']['RULETYPE']['0']['#']);
364 $rulecond->action
= backup_todb($rul_info['#']['ACTION']['0']['#']);
366 //The structure is equal to the db, so insert the forum_discussions
367 $newid = insert_record ("scorm_seq_ruleconds",$rulecond);
370 //We have the newid, update backup_ids
371 backup_putid($restore->backup_unique_code
,"scorm_seq_ruleconds", $oldid, $newid);
377 if (($i+
1) %
50 == 0) {
378 if (!defined('RESTORE_SILENTLY')) {
380 if (($i+
1) %
1000 == 0) {
387 //Now restore the scorm_seq_mapinfo for each objective
389 $status = scorm_seq_rulecond_restore_mods ($sco_id, $newid,$obj_info,$restore);
396 function scorm_scoes_seq_rulecond_restore_mods($sco_id,$rulecondid,$info,$restore) {
402 //Get the discussions array
403 $rulecondsd = array();
405 if (!empty($info['MOD']['#']['SEQ_RULECOND_DATAS']['0']['#']['SEQ_RULECOND_DATA'])) {
406 $rulecondsd = $info['MOD']['#']['SEQ_RULECOND_DATAS']['0']['#']['SEQ_RULECOND_DATA'];
410 for($i = 0; $i < sizeof($rulecondsd); $i++
) {
411 $ruld_info = $rulecondsd[$i];
414 //We'll need this later!!
415 $oldid = backup_todb($rul_info['#']['ID']['0']['#']);
417 $rulecondd->scoid
= $sco_id;
418 $rulecondd->ruleconditions
= $rulecondid;
419 $rulecondd->refrencedobjective
= backup_todb($ruld_info['#']['REFRENCEDOBJECTIVE']['0']['#']);
420 $rulecondd->measurethreshold
= backup_todb($ruld_info['#']['MEASURETHRESHOLD']['0']['#']);
421 $rulecondd->operator
= backup_todb($ruld_info['#']['OPERATOR']['0']['#']);
422 $rulecondd->cond
= backup_todb($ruld_info['#']['COND']['0']['#']);
424 //The structure is equal to the db, so insert the forum_discussions
425 $newid = insert_record ("scorm_seq_rulecond",$rulecondd);
428 //We have the newid, update backup_ids
429 backup_putid($restore->backup_unique_code
,"scorm_seq_rulecond", $oldid, $newid);
435 if (($i+
1) %
50 == 0) {
436 if (!defined('RESTORE_SILENTLY')) {
438 if (($i+
1) %
1000 == 0) {
445 //Now restore the scorm_seq_mapinfo for each objective
452 function scorm_scoes_seq_rolluprulecond_restore_mods($sco_id,$rolluprule,$info,$restore) {
458 //Get the discussions array
459 $rollupruleconds = array();
461 if (!empty($info['MOD']['#']['SEQ_ROLLUPRULECONDS']['0']['#']['SEQ_ROLLUPRULECOND'])) {
462 $rollupruleconds = $info['MOD']['#']['SEQ_ROLLUPRULECONDS']['0']['#']['SEQ_ROLLUPRULECOND'];
466 for($i = 0; $i < sizeof($rollupruleconds); $i++
) {
467 $rulc_info = $rollupruleconds[$i];
470 //We'll need this later!!
471 $oldid = backup_todb($rulc_info['#']['ID']['0']['#']);
473 $rolluprulecond->scoid
= $sco_id;
474 $rolluprulecond->ruleconditions
= $rolluprule;
475 $rolluprulecond->cond
= backup_todb($rulc_info['#']['COND']['0']['#']);
476 $rolluprulecond->operator
= backup_todb($rulc_info['#']['OPERATOR']['0']['#']);
479 //The structure is equal to the db, so insert the forum_discussions
480 $newid = insert_record ("scorm_seq_rolluprulecond",$rolluprulecond);
483 //We have the newid, update backup_ids
484 backup_putid($restore->backup_unique_code
,"scorm_seq_rolluprulecond", $oldid, $newid);
490 if (($i+
1) %
50 == 0) {
491 if (!defined('RESTORE_SILENTLY')) {
493 if (($i+
1) %
1000 == 0) {
500 //Now restore the scorm_seq_mapinfo for each objective
507 function scorm_scoes_seq_mapinfo_restore_mods($sco_id,$objectiveid,$info,$restore) {
513 //Get the discussions array
516 if (!empty($info['MOD']['#']['SEQ_MAPINFO']['0']['#']['SEQ_MAPINF'])) {
517 $mapinfos = $info['MOD']['#']['SEQ_MAPINFO']['0']['#']['SEQ_MAPINF'];
521 for($i = 0; $i < sizeof($mapinfos); $i++
) {
522 $map_info = $mapinfos[$i];
525 //We'll need this later!!
526 $oldid = backup_todb($map_info['#']['ID']['0']['#']);
528 $mapinfo->scoid
= $sco_id;
529 $mapinfo->objectiveid
= $ojectiveid;
530 $mapinfo->targetobjectiveid
= backup_todb($map_info['#']['TARGETOBJECTIVEID']['0']['#']);
531 $mapinfo->readsatisfiedstatus
= backup_todb($map_info['#']['READSATISFIEDSTATUS']['0']['#']);
532 $mapinfo->readnormalizedmeasure
= backup_todb($map_info['#']['READNORMALIZEDMEASURE']['0']['#']);
533 $mapinfo->writesatisfiedstatus
= backup_todb($map_info['#']['WRITESATISFIEDSTATUS']['0']['#']);
534 $mapinfo->writenormalizedmeasure
= backup_todb($map_info['#']['WRITENORMALIZEDMEASURE']['0']['#']);
537 //The structure is equal to the db, so insert the forum_discussions
538 $newid = insert_record ("scorm_seq_mapinfo",$mapinfo);
541 //We have the newid, update backup_ids
542 backup_putid($restore->backup_unique_code
,"scorm_seq_mapinfo", $oldid, $newid);
548 if (($i+
1) %
50 == 0) {
549 if (!defined('RESTORE_SILENTLY')) {
551 if (($i+
1) %
1000 == 0) {
561 //This function restores the scorm_scoes_track
562 function scorm_scoes_tracks_restore_mods($scorm_id,$info,$restore) {
570 if (!empty($info['MOD']['#']['SCO_TRACKS']['0']['#']['SCO_TRACK']))
571 $scotracks = $info['MOD']['#']['SCO_TRACKS']['0']['#']['SCO_TRACK'];
573 //Iterate over sco_users
574 for($i = 0; $i < sizeof($scotracks); $i++
) {
575 $sub_info = $scotracks[$i];
578 //Now, build the scorm_scoes_track record structure
579 $scotrack->scormid
= $scorm_id;
580 $scotrack->userid
= backup_todb($sub_info['#']['USERID']['0']['#']);
581 $scotrack->scoid
= backup_todb($sub_info['#']['SCOID']['0']['#']);
582 $scotrack->element
= backup_todb($sub_info['#']['ELEMENT']['0']['#']);
583 $scotrack->attempt
= backup_todb($sub_info['#']['ATTEMPT']['0']['#']);
584 $scotrack->value
= backup_todb($sub_info['#']['VALUE']['0']['#']);
586 //We have to recode the userid field
587 $user = backup_getid($restore->backup_unique_code
,"user",$scotrack->userid
);
589 $scotrack->userid
= $user->new_id
;
592 //We have to recode the scoid field
593 $sco = backup_getid($restore->backup_unique_code
,"scorm_scoes",$scotrack->scoid
);
595 $scotrack->scoid
= $sco->new_id
;
598 $scotrack->timemodified
= time();
599 //The structure is equal to the db, so insert the scorm_scoes_track
600 $newid = insert_record ("scorm_scoes_track",$scotrack);
603 if (($i+
1) %
50 == 0) {
604 if (!defined('RESTORE_SILENTLY')) {
606 if (($i+
1) %
1000 == 0) {
618 //This function restores the scorm_scoes_track from Moodle 1.4
619 function scorm_scoes_tracks_restore_mods_pre15 ($scorm_id,$info,$restore) {
627 if (!empty($info['MOD']['#']['SCO_USERS']['0']['#']['SCO_USER'])) {
628 $scousers = $info['MOD']['#']['SCO_USERS']['0']['#']['SCO_USER'];
631 $oldelements = array ('CMI_CORE_LESSON_LOCATION',
632 'CMI_CORE_LESSON_STATUS',
634 'CMI_CORE_TOTAL_TIME',
635 'CMI_CORE_SCORE_RAW',
637 $newelements = array ('cmi.core.lesson_location',
638 'cmi.core.lesson_status',
640 'cmi.core.total_time',
641 'cmi.core.score.raw',
644 //Iterate over sco_users
645 for ($i = 0; $i < sizeof($scousers); $i++
) {
646 $sub_info = $scousers[$i];
649 //We'll need this later!!
650 $oldid = backup_todb($sub_info['#']['ID']['0']['#']);
651 $oldscoid = backup_todb($sub_info['#']['SCOID']['0']['#']);
652 $olduserid = backup_todb($sub_info['#']['USERID']['0']['#']);
654 //Now, build the scorm_scoes_track record structure
655 $scotrack->scormid
= $scorm_id;
656 $scotrack->userid
= backup_todb($sub_info['#']['USERID']['0']['#']);
657 $scotrack->scoid
= backup_todb($sub_info['#']['SCOID']['0']['#']);
659 foreach ($oldelements as $oldelement) {
660 $elementvalue = backup_todb($sub_info['#'][$oldelement]['0']['#']);
661 if (!empty($elementvalue)) {
662 $scotrack->element
= $newelements[$pos];
663 $scotrack->value
= backup_todb($sub_info['#'][strtoupper($oldelement)]['0']['#']);
665 //We have to recode the userid field
666 $user = backup_getid($restore->backup_unique_code
,"user",$scotrack->userid
);
668 $scotrack->userid
= $user->new_id
;
671 //We have to recode the scoid field
672 $sco = backup_getid($restore->backup_unique_code
,"scorm_scoes",$scotrack->scoid
);
674 $scotrack->scoid
= $sco->new_id
;
677 //The structure is equal to the db, so insert the scorm_scoes_track
678 $newid = insert_record ("scorm_scoes_track",$scotrack);
684 if (($i+
1) %
50 == 0) {
685 if (!defined('RESTORE_SILENTLY')) {
687 if (($i+
1) %
1000 == 0) {
699 //This function copies the scorm related info from backup temp dir to course moddata folder,
700 //creating it if needed
701 function scorm_restore_files ($package, $restore) {
711 //First, we check to "course_id" exists and create is as necessary
713 $dest_dir = $CFG->dataroot
."/".$restore->course_id
;
714 $status = check_dir_exists($dest_dir,true);
716 //First, locate course's moddata directory
717 $moddata_path = $CFG->dataroot
."/".$restore->course_id
."/".$CFG->moddata
;
719 //Check it exists and create it
720 $status = check_dir_exists($moddata_path,true);
722 //Now, locate scorm directory
724 $scorm_path = $moddata_path."/scorm";
725 //Check it exists and create it
726 $status = check_dir_exists($scorm_path,true);
729 //Now locate the temp dir we are restoring from
731 $temp_path = $CFG->dataroot
."/temp/backup/".$restore->backup_unique_code
.
732 "/moddata/scorm/".$package->datadir
;
734 if (is_dir($temp_path)) {
739 //If todo, we create the neccesary dirs in course moddata/scorm
740 if ($status and $todo) {
741 //Make scorm package directory path
742 $this_scorm_path = $scorm_path."/".$package->id
;
743 $status = backup_copy_file($temp_path, $this_scorm_path);
749 //Return a content decoded to support interactivities linking. Every module
750 //should have its own. They are called automatically from
751 //scorm_decode_content_links_caller() function in each module
752 //in the restore process
753 function scorm_decode_content_links ($content,$restore) {
759 //Link to the list of scorms
761 $searchstring='/\$@(SCORMINDEX)\*([0-9]+)@\$/';
763 preg_match_all($searchstring,$content,$foundset);
764 //If found, then we are going to look for its new id (in backup tables)
766 //print_object($foundset); //Debug
767 //Iterate over foundset[2]. They are the old_ids
768 foreach($foundset[2] as $old_id) {
769 //We get the needed variables here (course id)
770 $rec = backup_getid($restore->backup_unique_code
,"course",$old_id);
771 //Personalize the searchstring
772 $searchstring='/\$@(SCORMINDEX)\*('.$old_id.')@\$/';
773 //If it is a link to this course, update the link to its new location
776 $result= preg_replace($searchstring,$CFG->wwwroot
.'/mod/scorm/index.php?id='.$rec->new_id
,$result);
778 //It's a foreign link so leave it as original
779 $result= preg_replace($searchstring,$restore->original_wwwroot
.'/mod/scorm/index.php?id='.$old_id,$result);
784 //Link to scorm view by moduleid
786 $searchstring='/\$@(SCORMVIEWBYID)\*([0-9]+)@\$/';
788 preg_match_all($searchstring,$result,$foundset);
789 //If found, then we are going to look for its new id (in backup tables)
791 //print_object($foundset); //Debug
792 //Iterate over foundset[2]. They are the old_ids
793 foreach($foundset[2] as $old_id) {
794 //We get the needed variables here (course_modules id)
795 $rec = backup_getid($restore->backup_unique_code
,"course_modules",$old_id);
796 //Personalize the searchstring
797 $searchstring='/\$@(SCORMVIEWBYID)\*('.$old_id.')@\$/';
798 //If it is a link to this course, update the link to its new location
801 $result= preg_replace($searchstring,$CFG->wwwroot
.'/mod/scorm/view.php?id='.$rec->new_id
,$result);
803 //It's a foreign link so leave it as original
804 $result= preg_replace($searchstring,$restore->original_wwwroot
.'/mod/scorm/view.php?id='.$old_id,$result);
812 //This function makes all the necessary calls to xxxx_decode_content_links()
813 //function in each module, passing them the desired contents to be decoded
814 //from backup format to destination site/course in order to mantain inter-activities
815 //working in the backup/restore process. It's called from restore_decode_content_links()
816 //function in restore process
817 function scorm_decode_content_links_caller($restore) {
821 if ($scorms = get_records_sql ("SELECT s.id, s.summary
822 FROM {$CFG->prefix}scorm s
823 WHERE s.course = $restore->course_id")) {
825 $i = 0; //Counter to send some output to the browser to avoid timeouts
826 foreach ($scorms as $scorm) {
829 $content = $scorm->summary
;
830 $result = restore_decode_content_links_worker($content,$restore);
832 if ($result != $content) {
834 $scorm->summary
= addslashes($result);
835 $status = update_record("scorm",$scorm);
837 if (!defined('RESTORE_SILENTLY')) {
838 echo '<br /><hr />'.htmlentities($content).'<br />changed to<br />'.htmlentities($result).'<hr /><br />';
843 if (($i+
1) %
5 == 0) {
844 if (!defined('RESTORE_SILENTLY')) {
846 if (($i+
1) %
100 == 0) {
857 //This function returns a log record with all the necessay transformations
858 //done. It's used by restore_log_module() to restore modules log.
859 function scorm_restore_logs($restore,$log) {