New help translation
[moodle.git] / backup / restore_precheck.html
blob9ebcfc9d30749ea026978a320076883d9f1620dc
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 (!empty($id)) {
17 if (!isteacheredit($id)) {
18 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
20 } else {
21 if (!isadmin()) {
22 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
26 //Check site
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>";
36 echo "<tr><td>";
38 //Start the mail ul
39 echo "<ul>";
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);
56 //Empty dir
57 if ($status) {
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
63 if ($status) {
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
69 if ($status) {
70 echo "<li>".get_string("copyingzipfile");
71 $status = backup_copy_file($file,$CFG->dataroot."/temp/backup/".$backup_unique_code."/".basename($file));
74 //Now unzip the file
75 if ($status) {
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
81 if ($status) {
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);
87 $info = "";
88 $course_header = "";
90 //Now read the info tag (all)
91 if ($status) {
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);
99 //End the main ul
100 echo "</ul>";
102 //End the main table
103 echo "</tr></td>";
104 echo "</table>";
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
111 if ($status) {
112 $status = restore_print_info($info);
116 //Save course header and info into php session
117 if ($status) {
118 $SESSION->info = $info;
119 $SESSION->course_header = $course_header;
122 //Finally, a little form to continue
123 //with some hidden fields
124 if ($status) {
125 echo "<br><CENTER>";
126 $hidden["backup_unique_code"] = $backup_unique_code;
127 $hidden["launch"] = "form";
128 $hidden["file"] = $file;
129 $hidden["id"] = $id;
130 print_single_button("restore.php", $hidden, get_string("continue"),"post");
131 echo "</CENTER>";
134 if (!$status) {
135 error ("An error has ocurred");