2 //This page copies th zip to the temp directory,
3 //unzip it, check that it is a valid backup file
4 //inform about its contents and fill all the necesary
5 //variables to continue with the restore.
7 //Checks we have the file variable
9 error (
"File not specified");
17 error(
"You need to be an admin user to use this page.",
"$CFG->wwwroot/login/index.php");
21 if (!$site = get_site()) {
22 error(
"Site not found!");
25 //Prepend dataroot to variable to have the absolute path
26 $file = $CFG-
>dataroot.
"/".$file;
28 //Start the main table
29 echo
"<table cellpadding=5>";
35 //Check the file exists
36 if (!is_file($file)) {
37 error (
"File not exists ($file)");
40 //Check the file name ends with .zip
41 if (!substr($file,-
4) ==
".zip") {
42 error (
"File has an incorrect extension");
45 //Now calculate the unique_code for this restore
46 $backup_unique_code = time();
48 //Now check and create the backup dir (if it doesn't exist)
49 $status = check_and_create_backup_dir($backup_unique_code);
52 echo
"<li>Creating temp dir";
53 $status = clear_backup_dir($backup_unique_code);
56 //Now delete old data and directories under dataroot/temp/backup
58 echo
"<li>Cleaning old data";
59 $status = backup_delete_old_data();
62 //Now copy he zip file to dataroot/temp/backup/backup_unique_code
64 $status = backup_copy_file($file,$CFG-
>dataroot.
"/temp/backup/".$backup_unique_code.
"/".basename($file));
69 echo
"<li>Retrieving backup file";
70 $status = restore_unzip ($CFG-
>dataroot.
"/temp/backup/".$backup_unique_code.
"/".basename($file),$moodle_home);
73 //Now check for the moodle.xml file
75 $xml_file = $CFG-
>dataroot.
"/temp/backup/".$backup_unique_code.
"/moodle.xml";
76 echo
"<li>Checking backup file";
77 $status = restore_check_moodle_file ($xml_file);
83 //Now read the info tag (all)
85 echo
"<li>Reading info from file";
86 //Reading info from file
87 $info = restore_read_xml_info ($xml_file);
88 //Reading course_header from file
89 $course_header = restore_read_xml_course_header ($xml_file);
99 //Now we print in other table, the backup and the course it contains info
100 if ($info and $course_header and $status) {
101 //First, the course info
102 $status = restore_print_course_header($course_header);
103 //Now, the backup info
105 $status = restore_print_info($info);
109 //Save course header and info into php session
111 $SESSION-
>info = $info;
112 $SESSION-
>course_header = $course_header;
115 //Finally, a little form to continue
116 //with some hidden fields
119 $hidden[
"backup_unique_code"] = $backup_unique_code;
120 $hidden[
"launch"] =
"form";
121 $hidden[
"file"] = $file;
122 print_single_button(
"restore.php", $hidden, get_string(
"continue"),
"post");
127 error (
"An error has ocurred");