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 if (!isteacheredit($id)) {
18 error(
"You need to be a teacher or admin user to use this page.",
"$CFG->wwwroot/login/index.php");
22 error(
"You need to be an admin user to use this page.",
"$CFG->wwwroot/login/index.php");
27 if (!$site = get_site()) {
28 error(
"Site not found!");
31 //Prepend dataroot to variable to have the absolute path
32 $file = $CFG-
>dataroot.
"/".$file;
34 //Start the main table
35 echo
"<table cellpadding=5>";
41 //Check the file exists
42 if (!is_file($file)) {
43 error (
"File not exists ($file)");
46 //Check the file name ends with .zip
47 if (!substr($file,-
4) ==
".zip") {
48 error (
"File has an incorrect extension");
51 //Now calculate the unique_code for this restore
52 $backup_unique_code = time();
54 //Now check and create the backup dir (if it doesn't exist)
55 $status = check_and_create_backup_dir($backup_unique_code);
58 echo
"<li>".get_string(
"creatingtemporarystructures");
59 $status = clear_backup_dir($backup_unique_code);
62 //Now delete old data and directories under dataroot/temp/backup
64 echo
"<li>".get_string(
"deletingolddata");
65 $status = backup_delete_old_data();
68 //Now copy he zip file to dataroot/temp/backup/backup_unique_code
70 echo
"<li>".get_string(
"copyingzipfile");
71 $status = backup_copy_file($file,$CFG-
>dataroot.
"/temp/backup/".$backup_unique_code.
"/".basename($file));
76 echo
"<li>".get_string(
"unzippingbackup");
77 $status = restore_unzip ($CFG-
>dataroot.
"/temp/backup/".$backup_unique_code.
"/".basename($file));
80 //Now check for the moodle.xml file
82 $xml_file = $CFG-
>dataroot.
"/temp/backup/".$backup_unique_code.
"/moodle.xml";
83 echo
"<li>".get_string(
"checkingbackup");
84 $status = restore_check_moodle_file ($xml_file);
90 //Now read the info tag (all)
92 echo
"<li>".get_string(
"readinginfofrombackup");
93 //Reading info from file
94 $info = restore_read_xml_info ($xml_file);
95 //Reading course_header from file
96 $course_header = restore_read_xml_course_header ($xml_file);
106 //Now we print in other table, the backup and the course it contains info
107 if ($info and $course_header and $status) {
108 //First, the course info
109 $status = restore_print_course_header($course_header);
110 //Now, the backup info
112 $status = restore_print_info($info);
116 //Save course header and info into php session
118 $SESSION-
>info = $info;
119 $SESSION-
>course_header = $course_header;
122 //Finally, a little form to continue
123 //with some hidden fields
126 $hidden[
"backup_unique_code"] = $backup_unique_code;
127 $hidden[
"launch"] =
"form";
128 $hidden[
"file"] = $file;
130 print_single_button(
"restore.php", $hidden, get_string(
"continue"),
"post");
135 error (
"An error has ocurred");