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
= (double)backup_todb($info['MOD']['#']['MAXGRADE']['0']['#']);
53 $scorm->updatefreq
= (int)backup_todb($info['MOD']['#']['UPDATEFREQ']['0']['#']);
54 $scorm->maxattempt
= (int)backup_todb($info['MOD']['#']['MAXATTEMPT']['0']['#']);
55 $scorm->grademethod
= (int)backup_todb($info['MOD']['#']['GRADEMETHOD']['0']['#']);
56 $scorm->whatgrade
= (int)backup_todb($info['MOD']['#']['WHATGRADE']['0']['#']);
57 if ($restore->backup_version
< 2005041500) {
58 $scorm->datadir
= substr(backup_todb($info['MOD']['#']['DATADIR']['0']['#']),1);
60 $scorm->datadir
= backup_todb($info['MOD']['#']['ID']['0']['#']);
62 $oldlaunch = backup_todb($info['MOD']['#']['LAUNCH']['0']['#']);
63 if ($restore->backup_version
< 2006102600) {
66 $scorm->skipview
= backup_todb($info['MOD']['#']['SKIPVIEW']['0']['#']);
68 $scorm->summary
= backup_todb($info['MOD']['#']['SUMMARY']['0']['#']);
69 $scorm->hidebrowse
= backup_todb($info['MOD']['#']['HIDEBROWSE']['0']['#']);
70 $scorm->hidetoc
= backup_todb($info['MOD']['#']['HIDETOC']['0']['#']);
71 $scorm->hidenav
= backup_todb($info['MOD']['#']['HIDENAV']['0']['#']);
72 $scorm->auto
= backup_todb($info['MOD']['#']['AUTO']['0']['#']);
73 if ($restore->backup_version
< 2005040200) {
74 $oldpopup = backup_todb($info['MOD']['#']['POPUP']['0']['#']);
75 if (!empty($oldpopup)) {
77 // Parse old popup field
79 $oldoptions = explode(',',$scorm->popup
);
80 foreach ($oldoptions as $oldoption) {
81 list($element,$value) = explode('=',$oldoption);
82 $element = trim($element);
83 $value = trim($value);
86 $scorm->width
= $value;
89 $scorm->height
= $value;
92 $options[] = $element.'='.$value;
96 $scorm->options
= implode($options,',');
100 $scorm->width
= '100%';
101 $scorm->height
= 500;
104 $scorm->popup
= backup_todb($info['MOD']['#']['POPUP']['0']['#']);
105 $scorm->width
= backup_todb($info['MOD']['#']['WIDTH']['0']['#']);
106 if ($scorm->width
== 0) {
107 $scorm->width
= '100%';
109 $scorm->height
= backup_todb($info['MOD']['#']['HEIGHT']['0']['#']);
110 if ($scorm->height
== 0) {
111 $scorm->height
= 500;
113 if (!empty($info['MOD']['#']['OPTIONS']['0']['#'])) {
114 $scorm->options
= backup_todb($info['MOD']['#']['OPTIONS']['0']['#']);
117 $scorm->timemodified
= time();
119 //The structure is equal to the db, so insert the scorm
120 $newid = insert_record ("scorm",$scorm);
122 if (!defined('RESTORE_SILENTLY')) {
123 echo "<li>".get_string("modulename","scorm")." \"".format_string(stripslashes($scorm->name
),true)."\"</li>";
128 //We have the newid, update backup_ids
129 backup_putid($restore->backup_unique_code
,$mod->modtype
,
132 //Now copy moddata associated files
133 $status = scorm_restore_files ($scorm, $restore);
136 $status = scorm_scoes_restore_mods ($newid,$info,$restore,$mod->id
);
138 $launchsco = backup_getid($restore->backup_unique_code
,"scorm_scoes",$oldlaunch);
139 $scorm->launch
= $launchsco->new_id
;
140 update_record('scorm',$scorm);
154 //This function restores the scorm_scoes
155 function scorm_scoes_restore_mods($scorm_id,$info,$restore,$oldmodid) {
162 $scoes = $info['MOD']['#']['SCOES']['0']['#']['SCO'];
165 for($i = 0; $i < sizeof($scoes); $i++
) {
166 $sub_info = $scoes[$i];
168 //We'll need this later!!
169 $oldid = backup_todb($sub_info['#']['ID']['0']['#']);
171 //Now, build the scorm_scoes record structure
172 $sco->scorm
= $scorm_id;
173 $sco->manifest
= backup_todb($sub_info['#']['MANIFEST']['0']['#']);
174 $sco->organization
= backup_todb($sub_info['#']['ORGANIZATION']['0']['#']);
175 $sco->parent
= backup_todb($sub_info['#']['PARENT']['0']['#']);
176 $sco->identifier
= backup_todb($sub_info['#']['IDENTIFIER']['0']['#']);
177 $sco->launch
= backup_todb($sub_info['#']['LAUNCH']['0']['#']);
178 $sco->title
= backup_todb($sub_info['#']['TITLE']['0']['#']);
179 if ($restore->backup_version
< 2005031300) {
180 $sco->scormtype
= backup_todb($sub_info['#']['TYPE']['0']['#']);
182 $sco->scormtype
= backup_todb($sub_info['#']['SCORMTYPE']['0']['#']);
185 //The structure is equal to the db, so insert the scorm_scoes
186 $newid = insert_record ("scorm_scoes",$sco);
189 //We have the newid, update backup_ids
190 backup_putid($restore->backup_unique_code
,"scorm_scoes", $oldid, $newid);
194 if ($status && !empty($sub_info['#']['SCO_DATAS'])) {
195 $status = scorm_scoes_data_restore_mods($newid, $sub_info['#']['SCO_DATAS'], $restore);
199 //Now check if want to restore user data and do it.
200 scorm_scoes_seq_objective_restore_mods ($newid,$info,$restore);
201 scorm_scoes_seq_rolluprule_restore_mods ($newid,$info,$restore);
202 scorm_scoes_seq_ruleconds_restore_mods ($newid,$info,$restore);
203 if (restore_userdata_selected($restore,'scorm',$oldmodid)) {
204 //Restore scorm_scoes
206 if ($restore->backup_version
< 2005031300) {
207 $status = scorm_scoes_tracks_restore_mods_pre15 ($scorm_id,$info,$restore);
209 $status = scorm_scoes_tracks_restore_mods ($scorm_id,$info,$restore);
217 //Restore scorm_scoes_data contents (executed from scorm_scoes_restore_mods)
218 function scorm_scoes_data_restore_mods ($new_scoe_id, $scoes_old_datas, $restore) {
223 $scoe_old_datas = $scoes_old_datas['0']['#']['SCO_DATA'];
225 //Iterate over scoe_data
226 for($i = 0; $i < sizeof($scoe_old_datas); $i++
) {
227 $scoe_old_data = $scoe_old_datas[$i];
228 unset($scoe_new_data);
230 $scoe_new_data->scoid
= $new_scoe_id;
231 $scoe_new_data->name
= backup_todb($scoe_old_data['#']['NAME']['0']['#']);
232 $scoe_new_data->value
= backup_todb($scoe_old_data['#']['VALUE']['0']['#']);
234 //The structure is equal to the db, so insert the scorm_scoes_data table
235 $new_scoe_data_id = insert_record ("scorm_scoes_data",$scoe_new_data);
237 $old_scoe_data_id = backup_todb($scoe_old_data['#']['ID']['0']['#']);
239 if ($new_scoe_data_id) {
240 //We have the newid, update backup_ids
241 backup_putid($restore->backup_unique_code
,"scorm_scoes_data", $old_scoe_data_id, $new_scoe_data_id);
249 function scorm_scoes_seq_objective_restore_mods($sco_id,$info,$restore) {
255 //Get the discussions array
256 $objectives = array();
258 if (!empty($info['MOD']['#']['SEQ_OBJECTIVES']['0']['#']['SEQ_OBJECTIVE'])) {
259 $objectives = $info['MOD']['#']['SEQ_OBJECTIVES']['0']['#']['SEQ_OBJECTIVE'];
262 //Iterate over discussions
263 for($i = 0; $i < sizeof($objectives); $i++
) {
264 $obj_info = $objectives[$i];
267 //We'll need this later!!
268 $oldid = backup_todb($obj_info['#']['ID']['0']['#']);
269 //Now, build the FORUM_DISCUSSIONS record structure
270 $objective->scoid
= $sco_id;
271 $objective->primaryobj
= backup_todb($obj_info['#']['PRIMARYOBJ']['0']['#']);
272 $objective->objectiveid
= backup_todb($obj_info['#']['OBJECTIVEID']['0']['#']);
273 $objective->satisfiedbymeasure
= backup_todb($obj_info['#']['SATISFIEDBYMEASURE']['0']['#']);
274 $objective->minnormalizedmeasure
= backup_todb($obj_info['#']['MINNORMALIZEDMEASURE']['0']['#']);
276 //The structure is equal to the db, so insert the forum_discussions
277 $newid = insert_record ("scorm_seq_objective",$objective);
280 //We have the newid, update backup_ids
281 backup_putid($restore->backup_unique_code
,"scorm_seq_objective", $oldid, $newid);
287 if (($i+
1) %
50 == 0) {
288 if (!defined('RESTORE_SILENTLY')) {
290 if (($i+
1) %
1000 == 0) {
297 //Now restore the scorm_seq_mapinfo for each objective
299 $status = scorm_seq_mapinfo_restore_mods ($sco_id,$newid,$obj_info,$restore);
308 function scorm_scoes_seq_rolluprule_restore_mods($sco_id,$info,$restore) {
314 //Get the discussions array
315 $rolluprules = array();
317 if (!empty($info['MOD']['#']['SEQ_ROLLUPRULES']['0']['#']['SEQ_ROLLUPRULE'])) {
318 $rolluprules = $info['MOD']['#']['SEQ_ROLLUPRULES']['0']['#']['SEQ_ROLLUPRULE'];
321 //Iterate over discussions
322 for($i = 0; $i < sizeof($rolluprules); $i++
) {
323 $rol_info = $rolluprules[$i];
326 //We'll need this later!!
327 $oldid = backup_todb($rol_info['#']['ID']['0']['#']);
328 //Now, build the FORUM_DISCUSSIONS record structure
329 $rolluprule->scoid
= $sco_id;
330 $rolluprule->childactivityset
= backup_todb($rol_info['#']['CHILDACTIVITYSET']['0']['#']);
331 $rolluprule->minimumrule
= backup_todb($rol_info['#']['MINIMUMCOUNT']['0']['#']);
332 $rolluprule->minimumpercent
= backup_todb($rol_info['#']['MINIMUMPERCENT']['0']['#']);
333 $rolluprule->conditioncombination
= backup_todb($rol_info['#']['CONDITIONCOMBINATION']['0']['#']);
334 $rolluprule->action
= backup_todb($rol_info['#']['ACTION']['0']['#']);
336 //The structure is equal to the db, so insert the forum_discussions
337 $newid = insert_record ("scorm_seq_rolluprule",$rolluprule);
340 //We have the newid, update backup_ids
341 backup_putid($restore->backup_unique_code
,"scorm_seq_rolluprule", $oldid, $newid);
347 if (($i+
1) %
50 == 0) {
348 if (!defined('RESTORE_SILENTLY')) {
350 if (($i+
1) %
1000 == 0) {
357 //Now restore the scorm_seq_mapinfo for each objective
359 $status = scorm_seq_rolluprulecond_restore_mods ($sco_id, $newid,$obj_info,$restore);
366 function scorm_scoes_seq_ruleconds_restore_mods($sco_id,$info,$restore) {
372 //Get the discussions array
373 $ruleconds = array();
375 if (!empty($info['MOD']['#']['SEQ_RULECONDS']['0']['#']['SEQ_RULECOND'])) {
376 $ruleconds = $info['MOD']['#']['SEQ_RULECONDS']['0']['#']['SEQ_RULECOND'];
379 //Iterate over discussions
380 for($i = 0; $i < sizeof($ruleconds); $i++
) {
381 $rul_info = $ruleconds[$i];
384 //We'll need this later!!
385 $oldid = backup_todb($rul_info['#']['ID']['0']['#']);
387 $rulecond->scoid
= $sco_id;
388 $rulecond->conditioncombination
= backup_todb($rul_info['#']['CONDITIONCOMBINATION']['0']['#']);
389 $rulecond->minimumpercent
= backup_todb($rul_info['#']['RULETYPE']['0']['#']);
390 $rulecond->action
= backup_todb($rul_info['#']['ACTION']['0']['#']);
392 //The structure is equal to the db, so insert the forum_discussions
393 $newid = insert_record ("scorm_seq_ruleconds",$rulecond);
396 //We have the newid, update backup_ids
397 backup_putid($restore->backup_unique_code
,"scorm_seq_ruleconds", $oldid, $newid);
403 if (($i+
1) %
50 == 0) {
404 if (!defined('RESTORE_SILENTLY')) {
406 if (($i+
1) %
1000 == 0) {
413 //Now restore the scorm_seq_mapinfo for each objective
415 $status = scorm_seq_rulecond_restore_mods ($sco_id, $newid,$obj_info,$restore);
422 function scorm_scoes_seq_rulecond_restore_mods($sco_id,$rulecondid,$info,$restore) {
428 //Get the discussions array
429 $rulecondsd = array();
431 if (!empty($info['MOD']['#']['SEQ_RULECOND_DATAS']['0']['#']['SEQ_RULECOND_DATA'])) {
432 $rulecondsd = $info['MOD']['#']['SEQ_RULECOND_DATAS']['0']['#']['SEQ_RULECOND_DATA'];
436 for($i = 0; $i < sizeof($rulecondsd); $i++
) {
437 $ruld_info = $rulecondsd[$i];
440 //We'll need this later!!
441 $oldid = backup_todb($rul_info['#']['ID']['0']['#']);
443 $rulecondd->scoid
= $sco_id;
444 $rulecondd->ruleconditions
= $rulecondid;
445 $rulecondd->refrencedobjective
= backup_todb($ruld_info['#']['REFRENCEDOBJECTIVE']['0']['#']);
446 $rulecondd->measurethreshold
= backup_todb($ruld_info['#']['MEASURETHRESHOLD']['0']['#']);
447 $rulecondd->operator
= backup_todb($ruld_info['#']['OPERATOR']['0']['#']);
448 $rulecondd->cond
= backup_todb($ruld_info['#']['COND']['0']['#']);
450 //The structure is equal to the db, so insert the forum_discussions
451 $newid = insert_record ("scorm_seq_rulecond",$rulecondd);
454 //We have the newid, update backup_ids
455 backup_putid($restore->backup_unique_code
,"scorm_seq_rulecond", $oldid, $newid);
461 if (($i+
1) %
50 == 0) {
462 if (!defined('RESTORE_SILENTLY')) {
464 if (($i+
1) %
1000 == 0) {
471 //Now restore the scorm_seq_mapinfo for each objective
478 function scorm_scoes_seq_rolluprulecond_restore_mods($sco_id,$rolluprule,$info,$restore) {
484 //Get the discussions array
485 $rollupruleconds = array();
487 if (!empty($info['MOD']['#']['SEQ_ROLLUPRULECONDS']['0']['#']['SEQ_ROLLUPRULECOND'])) {
488 $rollupruleconds = $info['MOD']['#']['SEQ_ROLLUPRULECONDS']['0']['#']['SEQ_ROLLUPRULECOND'];
492 for($i = 0; $i < sizeof($rollupruleconds); $i++
) {
493 $rulc_info = $rollupruleconds[$i];
496 //We'll need this later!!
497 $oldid = backup_todb($rulc_info['#']['ID']['0']['#']);
499 $rolluprulecond->scoid
= $sco_id;
500 $rolluprulecond->ruleconditions
= $rolluprule;
501 $rolluprulecond->cond
= backup_todb($rulc_info['#']['COND']['0']['#']);
502 $rolluprulecond->operator
= backup_todb($rulc_info['#']['OPERATOR']['0']['#']);
505 //The structure is equal to the db, so insert the forum_discussions
506 $newid = insert_record ("scorm_seq_rolluprulecond",$rolluprulecond);
509 //We have the newid, update backup_ids
510 backup_putid($restore->backup_unique_code
,"scorm_seq_rolluprulecond", $oldid, $newid);
516 if (($i+
1) %
50 == 0) {
517 if (!defined('RESTORE_SILENTLY')) {
519 if (($i+
1) %
1000 == 0) {
526 //Now restore the scorm_seq_mapinfo for each objective
533 function scorm_scoes_seq_mapinfo_restore_mods($sco_id,$objectiveid,$info,$restore) {
539 //Get the discussions array
541 //backward compatibility with old backups.
542 if (!empty($info['MOD']['#']['SEQ_MAPINFO']['0']['#']['SEQ_MAPINF'])) {
543 $mapinfos = $info['MOD']['#']['SEQ_MAPINFO']['0']['#']['SEQ_MAPINF'];
545 //correct way of getting data.
546 if (!empty($info['MOD']['#']['SEQ_MAPINFOS']['0']['#']['SEQ_MAPINFO'])) {
547 $mapinfos = $info['MOD']['#']['SEQ_MAPINFOS']['0']['#']['SEQ_MAPINFO'];
550 for($i = 0; $i < sizeof($mapinfos); $i++
) {
551 $map_info = $mapinfos[$i];
554 //We'll need this later!!
555 $oldid = backup_todb($map_info['#']['ID']['0']['#']);
557 $mapinfo->scoid
= $sco_id;
558 $mapinfo->objectiveid
= $ojectiveid;
559 $mapinfo->targetobjectiveid
= backup_todb($map_info['#']['TARGETOBJECTIVEID']['0']['#']);
560 $mapinfo->readsatisfiedstatus
= backup_todb($map_info['#']['READSATISFIEDSTATUS']['0']['#']);
561 $mapinfo->readnormalizedmeasure
= backup_todb($map_info['#']['READNORMALIZEDMEASURE']['0']['#']);
562 $mapinfo->writesatisfiedstatus
= backup_todb($map_info['#']['WRITESATISFIEDSTATUS']['0']['#']);
563 $mapinfo->writenormalizedmeasure
= backup_todb($map_info['#']['WRITENORMALIZEDMEASURE']['0']['#']);
566 //The structure is equal to the db, so insert the forum_discussions
567 $newid = insert_record ("scorm_seq_mapinfo",$mapinfo);
570 //We have the newid, update backup_ids
571 backup_putid($restore->backup_unique_code
,"scorm_seq_mapinfo", $oldid, $newid);
577 if (($i+
1) %
50 == 0) {
578 if (!defined('RESTORE_SILENTLY')) {
580 if (($i+
1) %
1000 == 0) {
590 //This function restores the scorm_scoes_track
591 function scorm_scoes_tracks_restore_mods($scorm_id,$info,$restore) {
599 if (!empty($info['MOD']['#']['SCO_TRACKS']['0']['#']['SCO_TRACK']))
600 $scotracks = $info['MOD']['#']['SCO_TRACKS']['0']['#']['SCO_TRACK'];
602 //Iterate over sco_users
603 for($i = 0; $i < sizeof($scotracks); $i++
) {
604 $sub_info = $scotracks[$i];
607 //Now, build the scorm_scoes_track record structure
608 $scotrack->scormid
= $scorm_id;
609 $scotrack->userid
= backup_todb($sub_info['#']['USERID']['0']['#']);
610 $scotrack->scoid
= backup_todb($sub_info['#']['SCOID']['0']['#']);
611 $scotrack->element
= backup_todb($sub_info['#']['ELEMENT']['0']['#']);
612 $scotrack->attempt
= backup_todb($sub_info['#']['ATTEMPT']['0']['#']);
613 $scotrack->value
= backup_todb($sub_info['#']['VALUE']['0']['#']);
615 //We have to recode the userid field
616 $user = backup_getid($restore->backup_unique_code
,"user",$scotrack->userid
);
618 $scotrack->userid
= $user->new_id
;
621 //We have to recode the scoid field
622 $sco = backup_getid($restore->backup_unique_code
,"scorm_scoes",$scotrack->scoid
);
624 $scotrack->scoid
= $sco->new_id
;
627 $scotrack->timemodified
= time();
628 //The structure is equal to the db, so insert the scorm_scoes_track
629 $newid = insert_record ("scorm_scoes_track",$scotrack);
632 if (($i+
1) %
50 == 0) {
633 if (!defined('RESTORE_SILENTLY')) {
635 if (($i+
1) %
1000 == 0) {
647 //This function restores the scorm_scoes_track from Moodle 1.4
648 function scorm_scoes_tracks_restore_mods_pre15 ($scorm_id,$info,$restore) {
656 if (!empty($info['MOD']['#']['SCO_USERS']['0']['#']['SCO_USER'])) {
657 $scousers = $info['MOD']['#']['SCO_USERS']['0']['#']['SCO_USER'];
660 $oldelements = array ('CMI_CORE_LESSON_LOCATION',
661 'CMI_CORE_LESSON_STATUS',
663 'CMI_CORE_TOTAL_TIME',
664 'CMI_CORE_SCORE_RAW',
666 $newelements = array ('cmi.core.lesson_location',
667 'cmi.core.lesson_status',
669 'cmi.core.total_time',
670 'cmi.core.score.raw',
673 //Iterate over sco_users
674 for ($i = 0; $i < sizeof($scousers); $i++
) {
675 $sub_info = $scousers[$i];
678 //We'll need this later!!
679 $oldid = backup_todb($sub_info['#']['ID']['0']['#']);
680 $oldscoid = backup_todb($sub_info['#']['SCOID']['0']['#']);
681 $olduserid = backup_todb($sub_info['#']['USERID']['0']['#']);
683 //Now, build the scorm_scoes_track record structure
684 $scotrack->scormid
= $scorm_id;
685 $scotrack->userid
= backup_todb($sub_info['#']['USERID']['0']['#']);
686 $scotrack->scoid
= backup_todb($sub_info['#']['SCOID']['0']['#']);
688 foreach ($oldelements as $oldelement) {
689 $elementvalue = backup_todb($sub_info['#'][$oldelement]['0']['#']);
690 if (!empty($elementvalue)) {
691 $scotrack->element
= $newelements[$pos];
692 $scotrack->value
= backup_todb($sub_info['#'][strtoupper($oldelement)]['0']['#']);
694 //We have to recode the userid field
695 $user = backup_getid($restore->backup_unique_code
,"user",$scotrack->userid
);
697 $scotrack->userid
= $user->new_id
;
700 //We have to recode the scoid field
701 $sco = backup_getid($restore->backup_unique_code
,"scorm_scoes",$scotrack->scoid
);
703 $scotrack->scoid
= $sco->new_id
;
706 //The structure is equal to the db, so insert the scorm_scoes_track
707 $newid = insert_record ("scorm_scoes_track",$scotrack);
713 if (($i+
1) %
50 == 0) {
714 if (!defined('RESTORE_SILENTLY')) {
716 if (($i+
1) %
1000 == 0) {
728 //This function copies the scorm related info from backup temp dir to course moddata folder,
729 //creating it if needed
730 function scorm_restore_files ($package, $restore) {
740 //First, we check to "course_id" exists and create is as necessary
742 $dest_dir = $CFG->dataroot
."/".$restore->course_id
;
743 $status = check_dir_exists($dest_dir,true);
745 //First, locate course's moddata directory
746 $moddata_path = $CFG->dataroot
."/".$restore->course_id
."/".$CFG->moddata
;
748 //Check it exists and create it
749 $status = check_dir_exists($moddata_path,true);
751 //Now, locate scorm directory
753 $scorm_path = $moddata_path."/scorm";
754 //Check it exists and create it
755 $status = check_dir_exists($scorm_path,true);
758 //Now locate the temp dir we are restoring from
760 $temp_path = $CFG->dataroot
."/temp/backup/".$restore->backup_unique_code
.
761 "/moddata/scorm/".$package->datadir
;
763 if (is_dir($temp_path)) {
768 //If todo, we create the neccesary dirs in course moddata/scorm
769 if ($status and $todo) {
770 //Make scorm package directory path
771 $this_scorm_path = $scorm_path."/".$package->id
;
772 $status = backup_copy_file($temp_path, $this_scorm_path);
778 //Return a content decoded to support interactivities linking. Every module
779 //should have its own. They are called automatically from
780 //scorm_decode_content_links_caller() function in each module
781 //in the restore process
782 function scorm_decode_content_links ($content,$restore) {
788 //Link to the list of scorms
790 $searchstring='/\$@(SCORMINDEX)\*([0-9]+)@\$/';
792 preg_match_all($searchstring,$content,$foundset);
793 //If found, then we are going to look for its new id (in backup tables)
795 //print_object($foundset); //Debug
796 //Iterate over foundset[2]. They are the old_ids
797 foreach($foundset[2] as $old_id) {
798 //We get the needed variables here (course id)
799 $rec = backup_getid($restore->backup_unique_code
,"course",$old_id);
800 //Personalize the searchstring
801 $searchstring='/\$@(SCORMINDEX)\*('.$old_id.')@\$/';
802 //If it is a link to this course, update the link to its new location
805 $result= preg_replace($searchstring,$CFG->wwwroot
.'/mod/scorm/index.php?id='.$rec->new_id
,$result);
807 //It's a foreign link so leave it as original
808 $result= preg_replace($searchstring,$restore->original_wwwroot
.'/mod/scorm/index.php?id='.$old_id,$result);
813 //Link to scorm view by moduleid
815 $searchstring='/\$@(SCORMVIEWBYID)\*([0-9]+)@\$/';
817 preg_match_all($searchstring,$result,$foundset);
818 //If found, then we are going to look for its new id (in backup tables)
820 //print_object($foundset); //Debug
821 //Iterate over foundset[2]. They are the old_ids
822 foreach($foundset[2] as $old_id) {
823 //We get the needed variables here (course_modules id)
824 $rec = backup_getid($restore->backup_unique_code
,"course_modules",$old_id);
825 //Personalize the searchstring
826 $searchstring='/\$@(SCORMVIEWBYID)\*('.$old_id.')@\$/';
827 //If it is a link to this course, update the link to its new location
830 $result= preg_replace($searchstring,$CFG->wwwroot
.'/mod/scorm/view.php?id='.$rec->new_id
,$result);
832 //It's a foreign link so leave it as original
833 $result= preg_replace($searchstring,$restore->original_wwwroot
.'/mod/scorm/view.php?id='.$old_id,$result);
841 //This function makes all the necessary calls to xxxx_decode_content_links()
842 //function in each module, passing them the desired contents to be decoded
843 //from backup format to destination site/course in order to mantain inter-activities
844 //working in the backup/restore process. It's called from restore_decode_content_links()
845 //function in restore process
846 function scorm_decode_content_links_caller($restore) {
850 if ($scorms = get_records_sql ("SELECT s.id, s.summary
851 FROM {$CFG->prefix}scorm s
852 WHERE s.course = $restore->course_id")) {
854 $i = 0; //Counter to send some output to the browser to avoid timeouts
855 foreach ($scorms as $scorm) {
858 $content = $scorm->summary
;
859 $result = restore_decode_content_links_worker($content,$restore);
861 if ($result != $content) {
863 $scorm->summary
= addslashes_js($result);
864 $status = update_record("scorm",$scorm);
866 if (!defined('RESTORE_SILENTLY')) {
867 echo '<br /><hr />'.htmlentities($content).'<br />changed to<br />'.htmlentities($result).'<hr /><br />';
872 if (($i+
1) %
5 == 0) {
873 if (!defined('RESTORE_SILENTLY')) {
875 if (($i+
1) %
100 == 0) {
886 //This function returns a log record with all the necessay transformations
887 //done. It's used by restore_log_module() to restore modules log.
888 function scorm_restore_logs($restore,$log) {