2 //This php script contains all the stuff to restore quiz mods
6 // whereever it says "/// We have to recode the .... field" we should put in a check
7 // to see if the recoding was successful and throw an appropriate error otherwise
9 //This is the "graphical" structure of the quiz mod:
10 //To see, put your terminal to 160cc
16 // -------------------------------------------------------------------
18 // | quiz_grades | quiz_question_versions
19 // | (UL,pk->id,fk->quiz) | (CL,pk->id,fk->quiz)
21 // quiz_attempts quiz_question_instances
22 // (UL,pk->id,fk->quiz) (CL,pk->id,fk->quiz,question)
24 // Meaning: pk->primary key field of the table
25 // fk->foreign key to link with parent
26 // nt->nested field (recursive data)
27 // SL->site level info
28 // CL->course level info
29 // UL->user level info
30 // files->table may have files
32 //-----------------------------------------------------------
34 // When we restore a quiz we also need to restore the questions and possibly
35 // the data about student interaction with the questions. The functions to do
36 // that are included with the following library
37 include_once("$CFG->dirroot/question/restorelib.php");
39 function quiz_restore_mods($mod,$restore) {
45 //Hook to call Moodle < 1.5 Quiz Restore
46 if ($restore->backup_version
< 2005043000) {
47 include_once("restorelibpre15.php");
48 return quiz_restore_pre15_mods($mod,$restore);
51 //Get record from backup_ids
52 $data = backup_getid($restore->backup_unique_code
,$mod->modtype
,$mod->id
);
55 //Now get completed xmlized object
57 //if necessary, write to restorelog and adjust date/time fields
58 if ($restore->course_startdateoffset
) {
59 restore_log_date_changes('Quiz', $restore, $info['MOD']['#'], array('TIMEOPEN', 'TIMECLOSE'));
61 //traverse_xmlize($info); //Debug
62 //print_object ($GLOBALS['traverse_array']); //Debug
63 //$GLOBALS['traverse_array']=""; //Debug
65 //Now, build the QUIZ record structure
67 $quiz->course
= $restore->course_id
;
68 $quiz->name
= backup_todb($info['MOD']['#']['NAME']['0']['#']);
69 $quiz->intro
= backup_todb($info['MOD']['#']['INTRO']['0']['#']);
70 $quiz->timeopen
= backup_todb($info['MOD']['#']['TIMEOPEN']['0']['#']);
71 $quiz->timeclose
= backup_todb($info['MOD']['#']['TIMECLOSE']['0']['#']);
72 $quiz->optionflags
= backup_todb($info['MOD']['#']['OPTIONFLAGS']['0']['#']);
73 $quiz->penaltyscheme
= backup_todb($info['MOD']['#']['PENALTYSCHEME']['0']['#']);
74 $quiz->attempts
= backup_todb($info['MOD']['#']['ATTEMPTS_NUMBER']['0']['#']);
75 $quiz->attemptonlast
= backup_todb($info['MOD']['#']['ATTEMPTONLAST']['0']['#']);
76 $quiz->grademethod
= backup_todb($info['MOD']['#']['GRADEMETHOD']['0']['#']);
77 $quiz->decimalpoints
= backup_todb($info['MOD']['#']['DECIMALPOINTS']['0']['#']);
78 $quiz->review
= backup_todb($info['MOD']['#']['REVIEW']['0']['#']);
79 $quiz->questionsperpage
= backup_todb($info['MOD']['#']['QUESTIONSPERPAGE']['0']['#']);
80 $quiz->shufflequestions
= backup_todb($info['MOD']['#']['SHUFFLEQUESTIONS']['0']['#']);
81 $quiz->shuffleanswers
= backup_todb($info['MOD']['#']['SHUFFLEANSWERS']['0']['#']);
82 $quiz->questions
= backup_todb($info['MOD']['#']['QUESTIONS']['0']['#']);
83 $quiz->sumgrades
= backup_todb($info['MOD']['#']['SUMGRADES']['0']['#']);
84 $quiz->grade
= backup_todb($info['MOD']['#']['GRADE']['0']['#']);
85 $quiz->timecreated
= backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']);
86 $quiz->timemodified
= backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
87 $quiz->timelimit
= backup_todb($info['MOD']['#']['TIMELIMIT']['0']['#']);
88 $quiz->password
= backup_todb($info['MOD']['#']['PASSWORD']['0']['#']);
89 $quiz->subnet
= backup_todb($info['MOD']['#']['SUBNET']['0']['#']);
90 $quiz->popup
= backup_todb($info['MOD']['#']['POPUP']['0']['#']);
91 $quiz->delay1
= isset($info['MOD']['#']['DELAY1']['0']['#'])?
backup_todb($info['MOD']['#']['DELAY1']['0']['#']):'';
92 $quiz->delay2
= isset($info['MOD']['#']['DELAY2']['0']['#'])?
backup_todb($info['MOD']['#']['DELAY2']['0']['#']):'';
93 //We have to recode the questions field (a list of questions id and pagebreaks)
94 $quiz->questions
= quiz_recode_layout($quiz->questions
, $restore);
96 //The structure is equal to the db, so insert the quiz
97 $newid = insert_record ("quiz",$quiz);
100 if (!defined('RESTORE_SILENTLY')) {
101 echo "<li>".get_string("modulename","quiz")." \"".format_string(stripslashes($quiz->name
),true)."\"</li>";
106 //We have the newid, update backup_ids
107 backup_putid($restore->backup_unique_code
,$mod->modtype
,
109 //We have to restore the question_instances now (course level table)
110 $status = quiz_question_instances_restore_mods($newid,$info,$restore);
111 //We have to restore the feedback now (course level table)
112 $status = quiz_feedback_restore_mods($newid, $info, $restore, $quiz);
113 //We have to restore the question_versions now (course level table)
114 $status = quiz_question_versions_restore_mods($newid,$info,$restore);
115 //Now check if want to restore user data and do it.
116 if (restore_userdata_selected($restore,'quiz',$mod->id
)) {
117 //Restore quiz_attempts
118 $status = quiz_attempts_restore_mods ($newid,$info,$restore);
120 //Restore quiz_grades
121 $status = quiz_grades_restore_mods ($newid,$info,$restore);
134 //This function restores the quiz_question_instances
135 function quiz_question_instances_restore_mods($quiz_id,$info,$restore) {
141 //Get the quiz_question_instances array
142 if (array_key_exists('QUESTION_INSTANCES', $info['MOD']['#'])) {
143 $instances = $info['MOD']['#']['QUESTION_INSTANCES']['0']['#']['QUESTION_INSTANCE'];
145 $instances = array();
148 //Iterate over question_instances
149 for($i = 0; $i < sizeof($instances); $i++
) {
150 $gra_info = $instances[$i];
151 //traverse_xmlize($gra_info); //Debug
152 //print_object ($GLOBALS['traverse_array']); //Debug
153 //$GLOBALS['traverse_array']=""; //Debug
155 //We'll need this later!!
156 $oldid = backup_todb($gra_info['#']['ID']['0']['#']);
158 //Now, build the QUESTION_INSTANCES record structure
159 $instance = new stdClass
;
160 $instance->quiz
= $quiz_id;
161 $instance->question
= backup_todb($gra_info['#']['QUESTION']['0']['#']);
162 $instance->grade
= backup_todb($gra_info['#']['GRADE']['0']['#']);
164 //We have to recode the question field
165 $question = backup_getid($restore->backup_unique_code
,"question",$instance->question
);
167 $instance->question
= $question->new_id
;
170 //The structure is equal to the db, so insert the quiz_question_instances
171 $newid = insert_record ("quiz_question_instances",$instance);
174 if (($i+
1) %
10 == 0) {
175 if (!defined('RESTORE_SILENTLY')) {
177 if (($i+
1) %
200 == 0) {
185 //We have the newid, update backup_ids
186 backup_putid($restore->backup_unique_code
,"quiz_question_instances",$oldid,
196 //This function restores the quiz_question_instances
197 function quiz_feedback_restore_mods($quiz_id, $info, $restore, $quiz) {
200 //Get the quiz_feedback array
201 if (array_key_exists('FEEDBACKS', $info['MOD']['#'])) {
202 $feedbacks = $info['MOD']['#']['FEEDBACKS']['0']['#']['FEEDBACK'];
204 //Iterate over the feedbacks
205 foreach ($feedbacks as $feedback_info) {
206 //traverse_xmlize($feedback_info); //Debug
207 //print_object ($GLOBALS['traverse_array']); //Debug
208 //$GLOBALS['traverse_array']=""; //Debug
210 //We'll need this later!!
211 $oldid = backup_todb($feedback_info['#']['ID']['0']['#']);
213 //Now, build the quiz_feedback record structure
214 $feedback = new stdClass();
215 $feedback->quizid
= $quiz_id;
216 $feedback->feedbacktext
= backup_todb($feedback_info['#']['FEEDBACKTEXT']['0']['#']);
217 $feedback->mingrade
= backup_todb($feedback_info['#']['MINGRADE']['0']['#']);
218 $feedback->maxgrade
= backup_todb($feedback_info['#']['MAXGRADE']['0']['#']);
220 //The structure is equal to the db, so insert the quiz_question_instances
221 $newid = insert_record('quiz_feedback', $feedback);
224 //We have the newid, update backup_ids
225 backup_putid($restore->backup_unique_code
, 'quiz_feedback', $oldid, $newid);
231 $feedback = new stdClass();
232 $feedback->quizid
= $quiz_id;
233 $feedback->feedbacktext
= '';
234 $feedback->mingrade
= 0;
235 $feedback->maxgrade
= $quiz->grade +
1;
236 insert_record('quiz_feedback', $feedback);
242 //This function restores the quiz_question_versions
243 function quiz_question_versions_restore_mods($quiz_id,$info,$restore) {
249 //Get the quiz_question_versions array
250 if (!empty($info['MOD']['#']['QUESTION_VERSIONS'])) {
251 $versions = $info['MOD']['#']['QUESTION_VERSIONS']['0']['#']['QUESTION_VERSION'];
256 //Iterate over question_versions
257 for($i = 0; $i < sizeof($versions); $i++
) {
258 $ver_info = $versions[$i];
259 //traverse_xmlize($ver_info); //Debug
260 //print_object ($GLOBALS['traverse_array']); //Debug
261 //$GLOBALS['traverse_array']=""; //Debug
263 //We'll need this later!!
264 $oldid = backup_todb($ver_info['#']['ID']['0']['#']);
266 //Now, build the QUESTION_VERSIONS record structure
267 $version = new stdClass
;
268 $version->quiz
= $quiz_id;
269 $version->oldquestion
= backup_todb($ver_info['#']['OLDQUESTION']['0']['#']);
270 $version->newquestion
= backup_todb($ver_info['#']['NEWQUESTION']['0']['#']);
271 $version->originalquestion
= backup_todb($ver_info['#']['ORIGINALQUESTION']['0']['#']);
272 $version->userid
= backup_todb($ver_info['#']['USERID']['0']['#']);
273 $version->timestamp
= backup_todb($ver_info['#']['TIMESTAMP']['0']['#']);
275 //We have to recode the oldquestion field
276 $question = backup_getid($restore->backup_unique_code
,"question",$version->oldquestion
);
278 $version->oldquestion
= $question->new_id
;
281 //We have to recode the newquestion field
282 $question = backup_getid($restore->backup_unique_code
,"question",$version->newquestion
);
284 $version->newquestion
= $question->new_id
;
287 //We have to recode the originalquestion field
288 $question = backup_getid($restore->backup_unique_code
,"question",$version->originalquestion
);
290 $version->newquestion
= $question->new_id
;
293 //We have to recode the userid field
294 $user = backup_getid($restore->backup_unique_code
,"user",$version->userid
);
296 $version->userid
= $user->new_id
;
297 } else { //Assign to current user
298 $version->userid
= $USER->id
;
301 //The structure is equal to the db, so insert the quiz_question_versions
302 $newid = insert_record ("quiz_question_versions",$version);
305 if (($i+
1) %
10 == 0) {
306 if (!defined('RESTORE_SILENTLY')) {
308 if (($i+
1) %
200 == 0) {
316 //We have the newid, update backup_ids
317 backup_putid($restore->backup_unique_code
,"quiz_question_versions",$oldid,
327 //This function restores the quiz_attempts
328 function quiz_attempts_restore_mods($quiz_id,$info,$restore) {
334 //Get the quiz_attempts array
335 if (array_key_exists('ATTEMPTS', $info['MOD']['#'])) {
336 $attempts = $info['MOD']['#']['ATTEMPTS']['0']['#']['ATTEMPT'];
341 //Iterate over attempts
342 for($i = 0; $i < sizeof($attempts); $i++
) {
343 $att_info = $attempts[$i];
344 //traverse_xmlize($att_info); //Debug
345 //print_object ($GLOBALS['traverse_array']); //Debug
346 //$GLOBALS['traverse_array']=""; //Debug
348 //We'll need this later!!
349 $oldid = backup_todb($att_info['#']['ID']['0']['#']);
350 $olduserid = backup_todb($att_info['#']['USERID']['0']['#']);
352 //Now, build the ATTEMPTS record structure
353 $attempt = new stdClass
;
354 $attempt->quiz
= $quiz_id;
355 $attempt->userid
= backup_todb($att_info['#']['USERID']['0']['#']);
356 $attempt->attempt
= backup_todb($att_info['#']['ATTEMPTNUM']['0']['#']);
357 $attempt->sumgrades
= backup_todb($att_info['#']['SUMGRADES']['0']['#']);
358 $attempt->timestart
= backup_todb($att_info['#']['TIMESTART']['0']['#']);
359 $attempt->timefinish
= backup_todb($att_info['#']['TIMEFINISH']['0']['#']);
360 $attempt->timemodified
= backup_todb($att_info['#']['TIMEMODIFIED']['0']['#']);
361 $attempt->layout
= backup_todb($att_info['#']['LAYOUT']['0']['#']);
362 $attempt->preview
= backup_todb($att_info['#']['PREVIEW']['0']['#']);
364 //We have to recode the userid field
365 $user = backup_getid($restore->backup_unique_code
,"user",$attempt->userid
);
367 $attempt->userid
= $user->new_id
;
370 //Set the uniqueid field
371 $attempt->uniqueid
= question_new_attempt_uniqueid();
373 //We have to recode the layout field (a list of questions id and pagebreaks)
374 $attempt->layout
= quiz_recode_layout($attempt->layout
, $restore);
376 //The structure is equal to the db, so insert the quiz_attempts
377 $newid = insert_record ("quiz_attempts",$attempt);
380 if (($i+
1) %
10 == 0) {
381 if (!defined('RESTORE_SILENTLY')) {
383 if (($i+
1) %
200 == 0) {
391 //We have the newid, update backup_ids
392 backup_putid($restore->backup_unique_code
,"quiz_attempts",$oldid,
394 //Now process question_states
395 // This function is defined in question/restorelib.php
396 $status = question_states_restore_mods($attempt->uniqueid
,$att_info,$restore);
405 //This function restores the quiz_grades
406 function quiz_grades_restore_mods($quiz_id,$info,$restore) {
412 //Get the quiz_grades array
413 if (array_key_exists('GRADES', $info['MOD']['#'])) {
414 $grades = $info['MOD']['#']['GRADES']['0']['#']['GRADE'];
419 //Iterate over grades
420 for($i = 0; $i < sizeof($grades); $i++
) {
421 $gra_info = $grades[$i];
422 //traverse_xmlize($gra_info); //Debug
423 //print_object ($GLOBALS['traverse_array']); //Debug
424 //$GLOBALS['traverse_array']=""; //Debug
426 //We'll need this later!!
427 $oldid = backup_todb($gra_info['#']['ID']['0']['#']);
428 $olduserid = backup_todb($gra_info['#']['USERID']['0']['#']);
430 //Now, build the GRADES record structure
431 $grade = new stdClass
;
432 $grade->quiz
= $quiz_id;
433 $grade->userid
= backup_todb($gra_info['#']['USERID']['0']['#']);
434 $grade->grade
= backup_todb($gra_info['#']['GRADEVAL']['0']['#']);
435 $grade->timemodified
= backup_todb($gra_info['#']['TIMEMODIFIED']['0']['#']);
437 //We have to recode the userid field
438 $user = backup_getid($restore->backup_unique_code
,"user",$grade->userid
);
440 $grade->userid
= $user->new_id
;
443 //The structure is equal to the db, so insert the quiz_grades
444 $newid = insert_record ("quiz_grades",$grade);
447 if (($i+
1) %
10 == 0) {
448 if (!defined('RESTORE_SILENTLY')) {
450 if (($i+
1) %
200 == 0) {
458 //We have the newid, update backup_ids
459 backup_putid($restore->backup_unique_code
,"quiz_grades",$oldid,
469 //Return a content decoded to support interactivities linking. Every module
470 //should have its own. They are called automatically from
471 //quiz_decode_content_links_caller() function in each module
472 //in the restore process
473 function quiz_decode_content_links ($content,$restore) {
479 //Link to the list of quizs
481 $searchstring='/\$@(QUIZINDEX)\*([0-9]+)@\$/';
483 preg_match_all($searchstring,$content,$foundset);
484 //If found, then we are going to look for its new id (in backup tables)
486 //print_object($foundset); //Debug
487 //Iterate over foundset[2]. They are the old_ids
488 foreach($foundset[2] as $old_id) {
489 //We get the needed variables here (course id)
490 $rec = backup_getid($restore->backup_unique_code
,"course",$old_id);
491 //Personalize the searchstring
492 $searchstring='/\$@(QUIZINDEX)\*('.$old_id.')@\$/';
493 //If it is a link to this course, update the link to its new location
496 $result= preg_replace($searchstring,$CFG->wwwroot
.'/mod/quiz/index.php?id='.$rec->new_id
,$result);
498 //It's a foreign link so leave it as original
499 $result= preg_replace($searchstring,$restore->original_wwwroot
.'/mod/quiz/index.php?id='.$old_id,$result);
504 //Link to quiz view by moduleid
506 $searchstring='/\$@(QUIZVIEWBYID)\*([0-9]+)@\$/';
508 preg_match_all($searchstring,$result,$foundset);
509 //If found, then we are going to look for its new id (in backup tables)
511 //print_object($foundset); //Debug
512 //Iterate over foundset[2]. They are the old_ids
513 foreach($foundset[2] as $old_id) {
514 //We get the needed variables here (course_modules id)
515 $rec = backup_getid($restore->backup_unique_code
,"course_modules",$old_id);
516 //Personalize the searchstring
517 $searchstring='/\$@(QUIZVIEWBYID)\*('.$old_id.')@\$/';
518 //If it is a link to this course, update the link to its new location
521 $result= preg_replace($searchstring,$CFG->wwwroot
.'/mod/quiz/view.php?id='.$rec->new_id
,$result);
523 //It's a foreign link so leave it as original
524 $result= preg_replace($searchstring,$restore->original_wwwroot
.'/mod/quiz/view.php?id='.$old_id,$result);
532 //This function makes all the necessary calls to xxxx_decode_content_links()
533 //function in each module, passing them the desired contents to be decoded
534 //from backup format to destination site/course in order to mantain inter-activities
535 //working in the backup/restore process. It's called from restore_decode_content_links()
536 //function in restore process
537 function quiz_decode_content_links_caller($restore) {
541 if ($quizs = get_records_sql ("SELECT q.id, q.intro
542 FROM {$CFG->prefix}quiz q
543 WHERE q.course = $restore->course_id")) {
544 //Iterate over each quiz->intro
545 $i = 0; //Counter to send some output to the browser to avoid timeouts
546 foreach ($quizs as $quiz) {
549 $content = $quiz->intro
;
550 $result = restore_decode_content_links_worker($content,$restore);
551 if ($result != $content) {
553 $quiz->intro
= addslashes($result);
554 $status = update_record("quiz",$quiz);
556 if (!defined('RESTORE_SILENTLY')) {
557 echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
562 if (($i+
1) %
5 == 0) {
563 if (!defined('RESTORE_SILENTLY')) {
565 if (($i+
1) %
100 == 0) {
577 //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
578 //some texts in the module
579 function quiz_restore_wiki2markdown ($restore) {
585 //Convert question->questiontext
586 if ($records = get_records_sql ("SELECT q.id, q.questiontext, q.questiontextformat
587 FROM {$CFG->prefix}question q,
588 {$CFG->prefix}backup_ids b
589 WHERE b.backup_code = $restore->backup_unique_code AND
590 b.table_name = 'question' AND
592 q.questiontextformat = ".FORMAT_WIKI
)) {
594 foreach ($records as $record) {
596 $record->questiontext
= restore_decode_wiki_content($record->questiontext
, $restore);
597 //Convert to Markdown
598 $wtm = new WikiToMarkdown();
599 $record->questiontext
= $wtm->convert($record->questiontext
, $restore->course_id
);
600 $record->questiontextformat
= FORMAT_MARKDOWN
;
601 $status = update_record('question', addslashes_object($record));
604 if (($i+
1) %
1 == 0) {
605 if (!defined('RESTORE_SILENTLY')) {
607 if (($i+
1) %
20 == 0) {
618 //This function returns a log record with all the necessay transformations
619 //done. It's used by restore_log_module() to restore modules log.
620 function quiz_restore_logs($restore,$log) {
624 //Depending of the action, we recode different things
625 switch ($log->action
) {
628 //Get the new_id of the module (to recode the info field)
629 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
631 $log->url
= "view.php?id=".$log->cmid
;
632 $log->info
= $mod->new_id
;
639 //Get the new_id of the module (to recode the info field)
640 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
642 $log->url
= "view.php?id=".$log->cmid
;
643 $log->info
= $mod->new_id
;
650 //Get the new_id of the module (to recode the info field)
651 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
653 $log->url
= "view.php?id=".$log->cmid
;
654 $log->info
= $mod->new_id
;
660 $log->url
= "index.php?id=".$log->course
;
665 //Get the new_id of the module (to recode the info field)
666 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
668 $log->url
= "report.php?id=".$log->cmid
;
669 $log->info
= $mod->new_id
;
676 //Get the new_id of the module (to recode the info field)
677 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
679 //Extract the attempt id from the url field
680 $attid = substr(strrchr($log->url
,"="),1);
681 //Get the new_id of the attempt (to recode the url field)
682 $att = backup_getid($restore->backup_unique_code
,"quiz_attempts",$attid);
684 $log->url
= "review.php?id=".$log->cmid
."&attempt=".$att->new_id
;
685 $log->info
= $mod->new_id
;
693 //Get the new_id of the module (to recode the info field)
694 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
696 //Extract the attempt id from the url field
697 $attid = substr(strrchr($log->url
,"="),1);
698 //Get the new_id of the attempt (to recode the url field)
699 $att = backup_getid($restore->backup_unique_code
,"quiz_attempts",$attid);
701 $log->url
= "review.php?id=".$log->cmid
."&attempt=".$att->new_id
;
702 $log->info
= $mod->new_id
;
710 //Get the new_id of the module (to recode the info field)
711 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
713 //Extract the attempt id from the url field
714 $attid = substr(strrchr($log->url
,"="),1);
715 //Get the new_id of the attempt (to recode the url field)
716 $att = backup_getid($restore->backup_unique_code
,"quiz_attempts",$attid);
718 $log->url
= "review.php?id=".$log->cmid
."&attempt=".$att->new_id
;
719 $log->info
= $mod->new_id
;
725 case "editquestions":
727 //Get the new_id of the module (to recode the url field)
728 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
730 $log->url
= "view.php?id=".$log->cmid
;
731 $log->info
= $mod->new_id
;
738 //Get the new_id of the module (to recode the url field)
739 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
741 $log->url
= "attempt.php?id=".$log->cmid
;
742 $log->info
= $mod->new_id
;
747 case "start attempt":
749 //Get the new_id of the module (to recode the info field)
750 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
752 //Extract the attempt id from the url field
753 $attid = substr(strrchr($log->url
,"="),1);
754 //Get the new_id of the attempt (to recode the url field)
755 $att = backup_getid($restore->backup_unique_code
,"quiz_attempts",$attid);
757 $log->url
= "review.php?id=".$log->cmid
."&attempt=".$att->new_id
;
758 $log->info
= $mod->new_id
;
764 case "close attempt":
766 //Get the new_id of the module (to recode the info field)
767 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
769 //Extract the attempt id from the url field
770 $attid = substr(strrchr($log->url
,"="),1);
771 //Get the new_id of the attempt (to recode the url field)
772 $att = backup_getid($restore->backup_unique_code
,"quiz_attempts",$attid);
774 $log->url
= "review.php?id=".$log->cmid
."&attempt=".$att->new_id
;
775 $log->info
= $mod->new_id
;
781 case "continue attempt":
783 //Get the new_id of the module (to recode the info field)
784 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
786 //Extract the attempt id from the url field
787 $attid = substr(strrchr($log->url
,"="),1);
788 //Get the new_id of the attempt (to recode the url field)
789 $att = backup_getid($restore->backup_unique_code
,"quiz_attempts",$attid);
791 $log->url
= "review.php?id=".$log->cmid
."&attempt=".$att->new_id
;
792 $log->info
= $mod->new_id
;
798 case "continue attemp":
800 //Get the new_id of the module (to recode the info field)
801 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
803 //Extract the attempt id from the url field
804 $attid = substr(strrchr($log->url
,"="),1);
805 //Get the new_id of the attempt (to recode the url field)
806 $att = backup_getid($restore->backup_unique_code
,"quiz_attempts",$attid);
808 $log->url
= "review.php?id=".$log->cmid
."&attempt=".$att->new_id
;
809 $log->info
= $mod->new_id
;
810 $log->action
= "continue attempt"; //To recover some bad actions
817 if (!defined('RESTORE_SILENTLY')) {
818 echo "action (".$log->module
."-".$log->action
.") unknown. Not restored<br />"; //Debug
829 function quiz_recode_layout($layout, $restore) {
830 //Recodes the quiz layout (a list of questions id and pagebreaks)
832 //Extracts question id from sequence
833 if ($questionids = explode(',', $layout)) {
834 foreach ($questionids as $id => $questionid) {
835 if ($questionid) { // If it is zero then this is a pagebreak, don't translate
836 $newq = backup_getid($restore->backup_unique_code
,"question",$questionid);
837 $questionids[$id] = $newq->new_id
;
841 return implode(',', $questionids);