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
505 $searchstring='/\$@(QUIZVIEWBYID)\*([0-9]+)@\$/';
507 preg_match_all($searchstring,$result,$foundset);
508 //If found, then we are going to look for its new id (in backup tables)
510 //print_object($foundset); //Debug
511 //Iterate over foundset[2]. They are the old_ids
512 foreach($foundset[2] as $old_id) {
513 //We get the needed variables here (course_modules id)
514 $rec = backup_getid($restore->backup_unique_code
,"course_modules",$old_id);
515 //Personalize the searchstring
516 $searchstring='/\$@(QUIZVIEWBYID)\*('.$old_id.')@\$/';
517 //If it is a link to this course, update the link to its new location
520 $result= preg_replace($searchstring,$CFG->wwwroot
.'/mod/quiz/view.php?id='.$rec->new_id
,$result);
522 //It's a foreign link so leave it as original
523 $result= preg_replace($searchstring,$restore->original_wwwroot
.'/mod/quiz/view.php?id='.$old_id,$result);
528 //Link to quiz view by quizid
529 $searchstring='/\$@(QUIZVIEWBYQ)\*([0-9]+)@\$/';
531 preg_match_all($searchstring,$result,$foundset);
532 //If found, then we are going to look for its new id (in backup tables)
534 //print_object($foundset); //Debug
535 //Iterate over foundset[2]. They are the old_ids
536 foreach($foundset[2] as $old_id) {
537 //We get the needed variables here (course_modules id)
538 $rec = backup_getid($restore->backup_unique_code
,'quiz',$old_id);
539 //Personalize the searchstring
540 $searchstring='/\$@(QUIZVIEWBYQ)\*('.$old_id.')@\$/';
541 //If it is a link to this course, update the link to its new location
544 $result= preg_replace($searchstring,$CFG->wwwroot
.'/mod/quiz/view.php?q='.$rec->new_id
,$result);
546 //It's a foreign link so leave it as original
547 $result= preg_replace($searchstring,$restore->original_wwwroot
.'/mod/quiz/view.php?q='.$old_id,$result);
555 //This function makes all the necessary calls to xxxx_decode_content_links()
556 //function in each module, passing them the desired contents to be decoded
557 //from backup format to destination site/course in order to mantain inter-activities
558 //working in the backup/restore process. It's called from restore_decode_content_links()
559 //function in restore process
560 function quiz_decode_content_links_caller($restore) {
564 if ($quizs = get_records_sql ("SELECT q.id, q.intro
565 FROM {$CFG->prefix}quiz q
566 WHERE q.course = $restore->course_id")) {
567 //Iterate over each quiz->intro
568 $i = 0; //Counter to send some output to the browser to avoid timeouts
569 foreach ($quizs as $quiz) {
572 $content = $quiz->intro
;
573 $result = restore_decode_content_links_worker($content,$restore);
574 if ($result != $content) {
576 $quiz->intro
= addslashes($result);
577 $status = update_record("quiz",$quiz);
579 if (!defined('RESTORE_SILENTLY')) {
580 echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
585 if (($i+
1) %
5 == 0) {
586 if (!defined('RESTORE_SILENTLY')) {
588 if (($i+
1) %
100 == 0) {
600 //This function converts texts in FORMAT_WIKI to FORMAT_MARKDOWN for
601 //some texts in the module
602 function quiz_restore_wiki2markdown ($restore) {
608 //Convert question->questiontext
609 if ($records = get_records_sql ("SELECT q.id, q.questiontext, q.questiontextformat
610 FROM {$CFG->prefix}question q,
611 {$CFG->prefix}backup_ids b
612 WHERE b.backup_code = $restore->backup_unique_code AND
613 b.table_name = 'question' AND
615 q.questiontextformat = ".FORMAT_WIKI
)) {
617 foreach ($records as $record) {
619 $record->questiontext
= restore_decode_wiki_content($record->questiontext
, $restore);
620 //Convert to Markdown
621 $wtm = new WikiToMarkdown();
622 $record->questiontext
= $wtm->convert($record->questiontext
, $restore->course_id
);
623 $record->questiontextformat
= FORMAT_MARKDOWN
;
624 $status = update_record('question', addslashes_object($record));
627 if (($i+
1) %
1 == 0) {
628 if (!defined('RESTORE_SILENTLY')) {
630 if (($i+
1) %
20 == 0) {
641 //This function returns a log record with all the necessay transformations
642 //done. It's used by restore_log_module() to restore modules log.
643 function quiz_restore_logs($restore,$log) {
647 //Depending of the action, we recode different things
648 switch ($log->action
) {
651 //Get the new_id of the module (to recode the info field)
652 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
654 $log->url
= "view.php?id=".$log->cmid
;
655 $log->info
= $mod->new_id
;
662 //Get the new_id of the module (to recode the info field)
663 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
665 $log->url
= "view.php?id=".$log->cmid
;
666 $log->info
= $mod->new_id
;
673 //Get the new_id of the module (to recode the info field)
674 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
676 $log->url
= "view.php?id=".$log->cmid
;
677 $log->info
= $mod->new_id
;
683 $log->url
= "index.php?id=".$log->course
;
688 //Get the new_id of the module (to recode the info field)
689 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
691 $log->url
= "report.php?id=".$log->cmid
;
692 $log->info
= $mod->new_id
;
699 //Get the new_id of the module (to recode the info field)
700 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
702 //Extract the attempt id from the url field
703 $attid = substr(strrchr($log->url
,"="),1);
704 //Get the new_id of the attempt (to recode the url field)
705 $att = backup_getid($restore->backup_unique_code
,"quiz_attempts",$attid);
707 $log->url
= "review.php?id=".$log->cmid
."&attempt=".$att->new_id
;
708 $log->info
= $mod->new_id
;
716 //Get the new_id of the module (to recode the info field)
717 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
719 //Extract the attempt id from the url field
720 $attid = substr(strrchr($log->url
,"="),1);
721 //Get the new_id of the attempt (to recode the url field)
722 $att = backup_getid($restore->backup_unique_code
,"quiz_attempts",$attid);
724 $log->url
= "review.php?id=".$log->cmid
."&attempt=".$att->new_id
;
725 $log->info
= $mod->new_id
;
733 //Get the new_id of the module (to recode the info field)
734 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
736 //Extract the attempt id from the url field
737 $attid = substr(strrchr($log->url
,"="),1);
738 //Get the new_id of the attempt (to recode the url field)
739 $att = backup_getid($restore->backup_unique_code
,"quiz_attempts",$attid);
741 $log->url
= "review.php?id=".$log->cmid
."&attempt=".$att->new_id
;
742 $log->info
= $mod->new_id
;
748 case "editquestions":
750 //Get the new_id of the module (to recode the url field)
751 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
753 $log->url
= "view.php?id=".$log->cmid
;
754 $log->info
= $mod->new_id
;
761 //Get the new_id of the module (to recode the url field)
762 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
764 $log->url
= "attempt.php?id=".$log->cmid
;
765 $log->info
= $mod->new_id
;
770 case "start attempt":
772 //Get the new_id of the module (to recode the info field)
773 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
775 //Extract the attempt id from the url field
776 $attid = substr(strrchr($log->url
,"="),1);
777 //Get the new_id of the attempt (to recode the url field)
778 $att = backup_getid($restore->backup_unique_code
,"quiz_attempts",$attid);
780 $log->url
= "review.php?id=".$log->cmid
."&attempt=".$att->new_id
;
781 $log->info
= $mod->new_id
;
787 case "close attempt":
789 //Get the new_id of the module (to recode the info field)
790 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
792 //Extract the attempt id from the url field
793 $attid = substr(strrchr($log->url
,"="),1);
794 //Get the new_id of the attempt (to recode the url field)
795 $att = backup_getid($restore->backup_unique_code
,"quiz_attempts",$attid);
797 $log->url
= "review.php?id=".$log->cmid
."&attempt=".$att->new_id
;
798 $log->info
= $mod->new_id
;
804 case "continue attempt":
806 //Get the new_id of the module (to recode the info field)
807 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
809 //Extract the attempt id from the url field
810 $attid = substr(strrchr($log->url
,"="),1);
811 //Get the new_id of the attempt (to recode the url field)
812 $att = backup_getid($restore->backup_unique_code
,"quiz_attempts",$attid);
814 $log->url
= "review.php?id=".$log->cmid
."&attempt=".$att->new_id
;
815 $log->info
= $mod->new_id
;
821 case "continue attemp":
823 //Get the new_id of the module (to recode the info field)
824 $mod = backup_getid($restore->backup_unique_code
,$log->module
,$log->info
);
826 //Extract the attempt id from the url field
827 $attid = substr(strrchr($log->url
,"="),1);
828 //Get the new_id of the attempt (to recode the url field)
829 $att = backup_getid($restore->backup_unique_code
,"quiz_attempts",$attid);
831 $log->url
= "review.php?id=".$log->cmid
."&attempt=".$att->new_id
;
832 $log->info
= $mod->new_id
;
833 $log->action
= "continue attempt"; //To recover some bad actions
840 if (!defined('RESTORE_SILENTLY')) {
841 echo "action (".$log->module
."-".$log->action
.") unknown. Not restored<br />"; //Debug
852 function quiz_recode_layout($layout, $restore) {
853 //Recodes the quiz layout (a list of questions id and pagebreaks)
855 //Extracts question id from sequence
856 if ($questionids = explode(',', $layout)) {
857 foreach ($questionids as $id => $questionid) {
858 if ($questionid) { // If it is zero then this is a pagebreak, don't translate
859 $newq = backup_getid($restore->backup_unique_code
,"question",$questionid);
860 $questionids[$id] = $newq->new_id
;
864 return implode(',', $questionids);