2004-09-12 01:34:24 +00:00
|
|
|
<?php //$Id$
|
2003-05-04 21:29:27 +00:00
|
|
|
//This page prints the backup todo list to see everything
|
|
|
|
|
2003-05-18 17:15:05 +00:00
|
|
|
//Check login
|
|
|
|
require_login();
|
|
|
|
|
2003-08-01 14:42:14 +00:00
|
|
|
if (!empty($course->id)) {
|
2006-09-07 08:57:56 +00:00
|
|
|
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
2005-01-27 02:35:10 +00:00
|
|
|
if (empty($to)) {
|
|
|
|
error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
|
|
|
|
} else {
|
|
|
|
if (!isteacheredit($to)) {
|
|
|
|
error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
|
|
|
|
}
|
|
|
|
}
|
2003-08-01 14:42:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
2006-09-07 08:57:56 +00:00
|
|
|
if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
|
2003-08-01 14:42:14 +00:00
|
|
|
error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
|
|
|
|
}
|
2003-05-18 17:15:05 +00:00
|
|
|
}
|
|
|
|
|
2003-08-01 14:42:14 +00:00
|
|
|
|
2003-05-18 17:15:05 +00:00
|
|
|
//Check site
|
|
|
|
if (!$site = get_site()) {
|
|
|
|
error("Site not found!");
|
|
|
|
}
|
|
|
|
|
2006-01-16 00:39:01 +00:00
|
|
|
$preferences = new StdClass;
|
|
|
|
backup_fetch_prefs_from_request($preferences,$count,$course);
|
2003-05-06 22:48:25 +00:00
|
|
|
//Another Info
|
2003-08-01 14:34:11 +00:00
|
|
|
$preferences->moodle_version = $CFG->version;
|
|
|
|
$preferences->moodle_release = $CFG->release;
|
|
|
|
$preferences->backup_version = $CFG->backup_version;
|
|
|
|
$preferences->backup_release = $CFG->backup_release;
|
2003-05-04 23:24:48 +00:00
|
|
|
|
2003-05-04 21:29:27 +00:00
|
|
|
if ($count == 0) {
|
|
|
|
notice("No backupable modules are installed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-27 02:35:10 +00:00
|
|
|
if (empty($to)) {
|
|
|
|
//Start the main table
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<table cellpadding=\"5\">";
|
2005-01-27 02:35:10 +00:00
|
|
|
|
|
|
|
//Now print the Backup Name tr
|
|
|
|
echo "<tr>";
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<td align=\"right\"><b>";
|
2005-01-27 02:35:10 +00:00
|
|
|
echo get_string("name").":";
|
|
|
|
echo "</b></td><td>";
|
|
|
|
echo $preferences->backup_name;
|
|
|
|
echo "</td></tr>";
|
|
|
|
|
|
|
|
//Start the main tr, where all the backup progress is done
|
|
|
|
echo "<tr>";
|
|
|
|
echo "<td colspan=\"2\">";
|
|
|
|
|
|
|
|
//Start the main ul
|
|
|
|
echo "<ul>";
|
|
|
|
}
|
2003-05-04 23:24:48 +00:00
|
|
|
//Check for temp and backup and backup_unique_code directory
|
|
|
|
//Create them as needed
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("creatingtemporarystructures").'</li>';
|
2006-01-16 00:39:01 +00:00
|
|
|
$status = check_and_create_backup_dir($preferences->backup_unique_code);
|
2003-05-04 23:24:48 +00:00
|
|
|
//Empty dir
|
|
|
|
if ($status) {
|
2006-01-16 00:39:01 +00:00
|
|
|
$status = clear_backup_dir($preferences->backup_unique_code);
|
2003-05-04 23:24:48 +00:00
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
|
2003-05-16 17:36:47 +00:00
|
|
|
//Delete old_entries from backup tables
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("deletingolddata").'</li>';
|
2003-05-16 17:36:47 +00:00
|
|
|
$status = backup_delete_old_data();
|
|
|
|
if (!$status) {
|
2003-10-07 13:59:15 +00:00
|
|
|
error ("An error occurred deleting old backup data");
|
2003-05-16 17:36:47 +00:00
|
|
|
}
|
|
|
|
|
2003-05-06 22:48:25 +00:00
|
|
|
//Create the moodle.xml file
|
|
|
|
if ($status) {
|
2003-07-27 21:30:24 +00:00
|
|
|
echo "<li>".get_string("creatingxmlfile");
|
2003-05-06 22:48:25 +00:00
|
|
|
//Begin a new list to xml contents
|
|
|
|
echo "<ul>";
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("writingheader").'</li>';
|
2003-05-06 22:48:25 +00:00
|
|
|
//Obtain the xml file (create and open) and print prolog information
|
2006-01-16 00:39:01 +00:00
|
|
|
$backup_file = backup_open_xml($preferences->backup_unique_code);
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("writinggeneralinfo").'</li>';
|
2003-05-06 22:48:25 +00:00
|
|
|
//Prints general info about backup to file
|
|
|
|
if ($backup_file) {
|
2003-10-07 13:59:15 +00:00
|
|
|
if (!$status = backup_general_info($backup_file,$preferences)) {
|
|
|
|
notify("An error occurred while backing up general info");
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
}
|
2003-07-27 21:30:24 +00:00
|
|
|
echo "<li>".get_string("writingcoursedata");
|
2003-05-06 22:48:25 +00:00
|
|
|
|
2003-05-07 22:15:14 +00:00
|
|
|
//Start new ul (for course)
|
|
|
|
echo "<ul>";
|
|
|
|
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("courseinfo").'</li>';
|
2003-05-07 22:15:14 +00:00
|
|
|
//Prints course start (tag and general info)
|
|
|
|
if ($status) {
|
2003-10-07 13:59:15 +00:00
|
|
|
if (!$status = backup_course_start($backup_file,$preferences)) {
|
|
|
|
notify("An error occurred while backing up course start");
|
|
|
|
}
|
2003-05-07 22:15:14 +00:00
|
|
|
}
|
2005-02-04 14:33:51 +00:00
|
|
|
//Metacourse information
|
|
|
|
if ($status && $preferences->backup_metacourse) {
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("metacourse").'</li>';
|
2005-02-04 14:33:51 +00:00
|
|
|
if (!$status = backup_course_metacourse($backup_file,$preferences)) {
|
|
|
|
notify("An error occurred while backing up metacourse info");
|
|
|
|
}
|
|
|
|
}
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("blocks").'</li>';
|
2004-10-29 17:07:11 +00:00
|
|
|
//Blocks information
|
|
|
|
if ($status) {
|
|
|
|
if (!$status = backup_course_blocks($backup_file,$preferences)) {
|
|
|
|
notify("An error occurred while backing up course blocks");
|
|
|
|
}
|
|
|
|
}
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("sections").'</li>';
|
2003-05-07 22:15:14 +00:00
|
|
|
//Section info
|
|
|
|
if ($status) {
|
2003-10-07 13:59:15 +00:00
|
|
|
if (!$status = backup_course_sections($backup_file,$preferences)) {
|
|
|
|
notify("An error occurred while backing up course sections");
|
|
|
|
}
|
2003-05-07 22:15:14 +00:00
|
|
|
}
|
|
|
|
|
2003-05-09 14:57:41 +00:00
|
|
|
//End course contents (close ul)
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "</ul></li>";
|
2003-05-07 22:15:14 +00:00
|
|
|
|
|
|
|
//User info
|
2005-11-19 00:27:57 +00:00
|
|
|
if ($status) {
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("writinguserinfo").'</li>';
|
2003-10-07 13:59:15 +00:00
|
|
|
if (!$status = backup_user_info($backup_file,$preferences)) {
|
|
|
|
notify("An error occurred while backing up user info");
|
|
|
|
}
|
2003-05-09 14:57:41 +00:00
|
|
|
}
|
2003-06-10 09:25:27 +00:00
|
|
|
|
2005-02-13 02:59:04 +00:00
|
|
|
//If we have selected to backup messages and we are
|
|
|
|
//doing a SITE backup, let's do it
|
|
|
|
if ($status && $preferences->backup_messages && $preferences->backup_course == SITEID) {
|
|
|
|
echo "<li>".get_string("writingmessagesinfo").'</li>';
|
|
|
|
if (!$status = backup_messages($backup_file,$preferences)) {
|
|
|
|
notify("An error occurred while backing up messages");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-10 09:25:27 +00:00
|
|
|
//If we have selected to backup quizzes, backup categories and
|
|
|
|
//questions structure (step 1). See notes on mod/quiz/backuplib.php
|
2006-06-03 19:45:19 +00:00
|
|
|
if ($status and !empty($preferences->mods['quiz']->backup)) {
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("writingcategoriesandquestions").'</li>';
|
2006-01-16 00:39:01 +00:00
|
|
|
require_once($CFG->dirroot.'/mod/quiz/backuplib.php');
|
2006-03-21 16:50:42 +00:00
|
|
|
if (!$status = backup_question_categories($backup_file,$preferences)) {
|
2003-10-07 13:59:15 +00:00
|
|
|
notify("An error occurred while backing up quiz categories");
|
|
|
|
}
|
2003-06-10 09:25:27 +00:00
|
|
|
}
|
2003-05-09 20:05:15 +00:00
|
|
|
|
|
|
|
//Print logs if selected
|
2003-05-10 17:25:20 +00:00
|
|
|
if ($status) {
|
|
|
|
if ($preferences->backup_logs) {
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("writingloginfo").'</li>';
|
2003-10-07 13:59:15 +00:00
|
|
|
if (!$status = backup_log_info($backup_file,$preferences)) {
|
|
|
|
notify("An error occurred while backing up log info");
|
|
|
|
}
|
2003-05-09 20:05:15 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-07 22:15:14 +00:00
|
|
|
|
2003-08-18 00:00:22 +00:00
|
|
|
//Print scales info
|
|
|
|
if ($status) {
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("writingscalesinfo").'</li>';
|
2003-10-07 13:59:15 +00:00
|
|
|
if (!$status = backup_scales_info($backup_file,$preferences)) {
|
|
|
|
notify("An error occurred while backing up scales");
|
2004-01-25 19:26:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Print groups info
|
|
|
|
if ($status) {
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("writinggroupsinfo").'</li>';
|
2004-01-25 19:26:24 +00:00
|
|
|
if (!$status = backup_groups_info($backup_file,$preferences)) {
|
|
|
|
notify("An error occurred while backing up groups");
|
2004-02-21 01:30:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Print events info
|
|
|
|
if ($status) {
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("writingeventsinfo").'</li>';
|
2004-02-21 01:30:22 +00:00
|
|
|
if (!$status = backup_events_info($backup_file,$preferences)) {
|
|
|
|
notify("An error occurred while backing up events");
|
2003-10-07 13:59:15 +00:00
|
|
|
}
|
2003-08-18 00:00:22 +00:00
|
|
|
}
|
|
|
|
|
2005-04-19 23:21:45 +00:00
|
|
|
//Print gradebook info
|
|
|
|
if ($status) {
|
|
|
|
echo "<li>".get_string("writinggradebookinfo").'</li>';
|
|
|
|
if (!$status = backup_gradebook_info($backup_file,$preferences)) {
|
|
|
|
notify("An error occurred while backing up gradebook");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-10 17:25:20 +00:00
|
|
|
//Module info, this unique function makes all the work!!
|
|
|
|
//db export and module fileis copy
|
|
|
|
if ($status) {
|
|
|
|
$mods_to_backup = false;
|
|
|
|
//Check if we have any mod to backup
|
|
|
|
foreach ($preferences->mods as $module) {
|
|
|
|
if ($module->backup) {
|
|
|
|
$mods_to_backup = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//If we have to backup some module
|
|
|
|
if ($mods_to_backup) {
|
2003-07-27 21:30:24 +00:00
|
|
|
echo "<li>".get_string("writingmoduleinfo");
|
2003-05-10 17:25:20 +00:00
|
|
|
//Start modules tag
|
2003-10-07 13:59:15 +00:00
|
|
|
if (!$status = backup_modules_start ($backup_file,$preferences)) {
|
|
|
|
notify("An error occurred while backing up module info");
|
|
|
|
}
|
2003-05-10 17:25:20 +00:00
|
|
|
//Open ul for module list
|
|
|
|
echo "<ul>";
|
2003-05-31 15:19:59 +00:00
|
|
|
//Iterate over modules and call backup
|
2003-05-10 17:25:20 +00:00
|
|
|
foreach ($preferences->mods as $module) {
|
|
|
|
if ($module->backup and $status) {
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("modulenameplural",$module->name).'</li>';
|
2003-10-07 13:59:15 +00:00
|
|
|
if (!$status = backup_module($backup_file,$preferences,$module->name)) {
|
|
|
|
notify("An error occurred while backing up '$module->name'");
|
|
|
|
}
|
2003-05-10 17:25:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//Close ul for module list
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "</ul></li>";
|
2003-05-10 17:25:20 +00:00
|
|
|
//Close modules tag
|
2003-10-07 13:59:15 +00:00
|
|
|
if (!$status = backup_modules_end ($backup_file,$preferences)) {
|
|
|
|
notify("An error occurred while finishing the module backups");
|
|
|
|
}
|
2003-05-10 17:25:20 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-07 22:15:14 +00:00
|
|
|
|
|
|
|
//Prints course end
|
|
|
|
if ($status) {
|
2003-10-07 13:59:15 +00:00
|
|
|
if (!$status = backup_course_end($backup_file,$preferences)) {
|
|
|
|
notify("An error occurred while closing the course backup");
|
|
|
|
}
|
2003-05-07 22:15:14 +00:00
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
//Close the xml file and xml data
|
|
|
|
if ($backup_file) {
|
2003-05-07 22:15:14 +00:00
|
|
|
backup_close_xml($backup_file);
|
2003-05-06 22:48:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//End xml contents (close ul)
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "</ul></li>";
|
2003-05-06 22:48:25 +00:00
|
|
|
}
|
2003-05-10 17:44:08 +00:00
|
|
|
|
|
|
|
//Now, if selected, copy user files
|
|
|
|
if ($status) {
|
|
|
|
if ($preferences->backup_user_files) {
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("copyinguserfiles").'</li>';
|
2003-10-07 13:59:15 +00:00
|
|
|
if (!$status = backup_copy_user_files ($preferences)) {
|
|
|
|
notify("An error occurred while copying user files");
|
|
|
|
}
|
2003-05-10 17:44:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Now, if selected, copy course files
|
|
|
|
if ($status) {
|
|
|
|
if ($preferences->backup_course_files) {
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("copyingcoursefiles").'</li>';
|
2003-10-07 13:59:15 +00:00
|
|
|
if (!$status = backup_copy_course_files ($preferences)) {
|
|
|
|
notify("An error occurred while copying course files");
|
|
|
|
}
|
2003-05-10 17:44:08 +00:00
|
|
|
}
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
|
2003-05-11 11:06:23 +00:00
|
|
|
//Now, zip all the backup directory contents
|
|
|
|
if ($status) {
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("zippingbackup").'</li>';
|
2003-10-07 13:59:15 +00:00
|
|
|
if (!$status = backup_zip ($preferences)) {
|
|
|
|
notify("An error occurred while zipping the backup");
|
|
|
|
}
|
2003-05-11 17:45:56 +00:00
|
|
|
}
|
2003-05-11 11:06:23 +00:00
|
|
|
|
2003-05-11 17:45:56 +00:00
|
|
|
//Now, copy the zip file to course directory
|
|
|
|
if ($status) {
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("copyingzipfile").'</li>';
|
2003-10-07 13:59:15 +00:00
|
|
|
if (!$status = copy_zip_to_course_dir ($preferences)) {
|
|
|
|
notify("An error occurred while copying the zip file to the course directory");
|
|
|
|
}
|
2003-05-11 17:45:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Now, clean temporary data (db and filesystem)
|
|
|
|
if ($status) {
|
2005-02-05 01:00:33 +00:00
|
|
|
echo "<li>".get_string("cleaningtempdata").'</li>';
|
2003-10-07 13:59:15 +00:00
|
|
|
if (!$status = clean_temp_data ($preferences)) {
|
|
|
|
notify("An error occurred while cleaning up temporary data");
|
|
|
|
}
|
2003-05-11 11:06:23 +00:00
|
|
|
}
|
|
|
|
|
2003-05-06 22:48:25 +00:00
|
|
|
//Ends th main ul
|
|
|
|
echo "</ul>";
|
2003-05-04 21:29:27 +00:00
|
|
|
|
2003-05-04 23:24:48 +00:00
|
|
|
//End the main tr, where all the backup is done
|
2003-05-06 22:48:25 +00:00
|
|
|
echo "</td></tr>";
|
2003-05-04 21:29:27 +00:00
|
|
|
|
2003-05-04 23:24:48 +00:00
|
|
|
//End the main table
|
|
|
|
echo "</table>";
|
2003-07-07 18:42:19 +00:00
|
|
|
|
|
|
|
if (!$status) {
|
2003-10-07 13:59:15 +00:00
|
|
|
error ("The backup did not complete successfully",
|
|
|
|
"$CFG->wwwroot/course/view.php?id=$course->id");
|
2003-07-07 18:42:19 +00:00
|
|
|
}
|
2003-05-11 17:45:56 +00:00
|
|
|
|
2005-01-27 02:35:10 +00:00
|
|
|
if (empty($to)) {
|
|
|
|
//Print final message
|
|
|
|
print_simple_box(get_string("backupfinished"),"center");
|
2005-02-05 01:00:33 +00:00
|
|
|
print_continue("$CFG->wwwroot/files/index.php?id=".$preferences->backup_course."&wdir=/backupdata");
|
2005-01-27 02:35:10 +00:00
|
|
|
} else {
|
|
|
|
print_simple_box(get_string('importdataexported'),"CENTER");
|
|
|
|
if (!empty($preferences->backup_destination)) {
|
|
|
|
$filename = $preferences->backup_destination."/".$preferences->backup_name;
|
|
|
|
} else {
|
|
|
|
$filename = $preferences->backup_course."/backupdata/".$preferences->backup_name;
|
|
|
|
}
|
|
|
|
error_log($filename);
|
|
|
|
$SESSION->import_preferences = $preferences;
|
2005-11-08 07:01:12 +00:00
|
|
|
print_continue($CFG->wwwroot.'/course/import/activities/index.php?id='.$to.'&fromcourse='.$id.'&filename='.$filename);
|
2005-01-27 02:35:10 +00:00
|
|
|
}
|
2006-01-16 00:39:01 +00:00
|
|
|
|
|
|
|
$SESSION->backupprefs[$course->id] = null; // unset it so we're clear next time.
|
2003-05-04 21:29:27 +00:00
|
|
|
?>
|