Polished.
[moodle.git] / backup / restore_precheck.html
blobfdd6aa84a8a171daed99016c4a197871f8c8812f
1 <?PHP // $Id$
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
8 if (!isset($file)) {
9 error ("File not specified");
12 //Check login
13 require_login();
15 //Check admin
16 if (!isadmin()) {
17 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
20 //Check site
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>";
30 echo "<tr><td>";
32 //Start the mail ul
33 echo "<ul>";
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);
50 //Empty dir
51 if ($status) {
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
57 if ($status) {
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
63 if ($status) {
64 $status = backup_copy_file($file,$CFG->dataroot."/temp/backup/".$backup_unique_code."/".basename($file));
67 //Now unzip the file
68 if ($status) {
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
74 if ($status) {
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);
80 $info = "";
81 $course_header = "";
83 //Now read the info tag (all)
84 if ($status) {
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);
92 //End the main ul
93 echo "</ul>";
95 //End the main table
96 echo "</tr></td>";
97 echo "</table>";
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
104 if ($status) {
105 $status = restore_print_info($info);
109 //Save course header and info into php session
110 if ($status) {
111 $SESSION->info = $info;
112 $SESSION->course_header = $course_header;
115 //Finally, a little form to continue
116 //with some hidden fields
117 if ($status) {
118 echo "<br><CENTER>";
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");
123 echo "</CENTER>";
126 if (!$status) {
127 error ("An error has ocurred");