mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
155 lines
4.7 KiB
HTML
155 lines
4.7 KiB
HTML
<?php // $Id$
|
|
//This page copies th zip to the temp directory,
|
|
//unzip it, check that it is a valid backup file
|
|
//inform about its contents and fill all the necesary
|
|
//variables to continue with the restore.
|
|
|
|
//Checks we have the file variable
|
|
if (!isset($file)) {
|
|
error ("File not specified");
|
|
}
|
|
|
|
//Check login
|
|
require_login();
|
|
|
|
//Check admin
|
|
if (!empty($id)) {
|
|
if (!isteacheredit($id)) {
|
|
error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
|
|
}
|
|
} else {
|
|
if (!isadmin()) {
|
|
error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
|
|
}
|
|
}
|
|
|
|
//Check site
|
|
if (!$site = get_site()) {
|
|
error("Site not found!");
|
|
}
|
|
|
|
//Prepend dataroot to variable to have the absolute path
|
|
$file = $CFG->dataroot."/".$file;
|
|
|
|
//Start the main table
|
|
echo "<table cellpadding=\"5\">";
|
|
echo "<tr><td>";
|
|
|
|
//Start the mail ul
|
|
echo "<ul>";
|
|
|
|
//Check the file exists
|
|
if (!is_file($file)) {
|
|
error ("File not exists ($file)");
|
|
}
|
|
|
|
//Check the file name ends with .zip
|
|
if (!substr($file,-4) == ".zip") {
|
|
error ("File has an incorrect extension");
|
|
}
|
|
|
|
//Now calculate the unique_code for this restore
|
|
$backup_unique_code = time();
|
|
|
|
//Now check and create the backup dir (if it doesn't exist)
|
|
echo "<li>".get_string("creatingtemporarystructures");
|
|
$status = check_and_create_backup_dir($backup_unique_code);
|
|
//Empty dir
|
|
if ($status) {
|
|
$status = clear_backup_dir($backup_unique_code);
|
|
}
|
|
|
|
//Now delete old data and directories under dataroot/temp/backup
|
|
if ($status) {
|
|
echo "<li>".get_string("deletingolddata");
|
|
$status = backup_delete_old_data();
|
|
}
|
|
|
|
//Now copy he zip file to dataroot/temp/backup/backup_unique_code
|
|
if ($status) {
|
|
echo "<li>".get_string("copyingzipfile");
|
|
if (! $status = backup_copy_file($file,$CFG->dataroot."/temp/backup/".$backup_unique_code."/".basename($file))) {
|
|
notify("Error copying backup file. Invalid name or bad perms.");
|
|
}
|
|
}
|
|
|
|
//Now unzip the file
|
|
if ($status) {
|
|
echo "<li>".get_string("unzippingbackup");
|
|
if (! $status = restore_unzip ($CFG->dataroot."/temp/backup/".$backup_unique_code."/".basename($file))) {
|
|
notify("Error unzipping backup file. Invalid zip file.");
|
|
}
|
|
}
|
|
|
|
//Now check for the moodle.xml file
|
|
if ($status) {
|
|
$xml_file = $CFG->dataroot."/temp/backup/".$backup_unique_code."/moodle.xml";
|
|
echo "<li>".get_string("checkingbackup");
|
|
if (! $status = restore_check_moodle_file ($xml_file)) {
|
|
notify("Error checking backup file. Invalid or corrupted.");
|
|
}
|
|
}
|
|
|
|
$info = "";
|
|
$course_header = "";
|
|
|
|
//Now read the info tag (all)
|
|
if ($status) {
|
|
echo "<li>".get_string("readinginfofrombackup");
|
|
//Reading info from file
|
|
$info = restore_read_xml_info ($xml_file);
|
|
//Reading course_header from file
|
|
$course_header = restore_read_xml_course_header ($xml_file);
|
|
}
|
|
|
|
//End the main ul
|
|
echo "</ul>";
|
|
|
|
//End the main table
|
|
echo "</tr></td>";
|
|
echo "</table>";
|
|
|
|
//We compare Moodle's versions
|
|
if ($CFG->version < $info->backup_moodle_version && $status) {
|
|
$message->serverversion = $CFG->version;
|
|
$message->serverrelease = $CFG->release;
|
|
$message->backupversion = $info->backup_moodle_version;
|
|
$message->backuprelease = $info->backup_moodle_release;
|
|
print_simple_box(get_string('noticenewerbackup','',$message), "center", "70%", "$THEME->cellheading2", "20", "noticebox");
|
|
|
|
}
|
|
|
|
//Now we print in other table, the backup and the course it contains info
|
|
if ($info and $course_header and $status) {
|
|
//First, the course info
|
|
$status = restore_print_course_header($course_header);
|
|
//Now, the backup info
|
|
if ($status) {
|
|
$status = restore_print_info($info);
|
|
}
|
|
}
|
|
|
|
//Save course header and info into php session
|
|
if ($status) {
|
|
$SESSION->info = $info;
|
|
$SESSION->course_header = $course_header;
|
|
}
|
|
|
|
//Finally, a little form to continue
|
|
//with some hidden fields
|
|
if ($status) {
|
|
echo "<br /><center>";
|
|
$hidden["backup_unique_code"] = $backup_unique_code;
|
|
$hidden["launch"] = "form";
|
|
$hidden["file"] = $file;
|
|
$hidden["id"] = $id;
|
|
print_single_button("restore.php", $hidden, get_string("continue"),"post");
|
|
echo "</center>";
|
|
}
|
|
|
|
if (!$status) {
|
|
error ("An error has ocurred");
|
|
}
|
|
|
|
?>
|