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)) {
|
2003-08-16 06:37:06 +00:00
|
|
|
if (!isteacheredit($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 {
|
|
|
|
if (!isadmin()) {
|
|
|
|
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!");
|
|
|
|
}
|
|
|
|
|
2003-05-04 21:29:27 +00:00
|
|
|
//Checks for the required files/functions to backup every mod
|
|
|
|
//And check if there is data about it
|
|
|
|
$count = 0;
|
|
|
|
if ($allmods = get_records("modules") ) {
|
|
|
|
foreach ($allmods as $mod) {
|
|
|
|
$modname = $mod->name;
|
2003-08-01 14:34:11 +00:00
|
|
|
$modfile = "$CFG->dirroot/mod/$modname/backuplib.php";
|
2003-05-04 21:29:27 +00:00
|
|
|
$modbackup = $modname."_backup_mods";
|
|
|
|
$modcheckbackup = $modname."_check_backup_mods";
|
|
|
|
if (file_exists($modfile)) {
|
|
|
|
include_once($modfile);
|
|
|
|
if (function_exists($modbackup) and function_exists($modcheckbackup)) {
|
|
|
|
$var = "exists_".$modname;
|
|
|
|
$$var = true;
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Check data
|
|
|
|
//Check module info
|
|
|
|
$var = "backup_".$modname;
|
|
|
|
if (!isset($$var)) {
|
2003-05-09 23:21:55 +00:00
|
|
|
//Every undefined backup_XXXX isn't exported
|
|
|
|
$$var = 0;
|
2003-05-04 21:29:27 +00:00
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
//Now stores all the mods preferences into an array into preferences
|
|
|
|
$preferences->mods[$modname]->backup = $$var;
|
|
|
|
|
2003-05-04 21:29:27 +00:00
|
|
|
//Check include user info
|
|
|
|
$var = "backup_user_info_".$modname;
|
|
|
|
if (!isset($$var)) {
|
|
|
|
$$var = 1;
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
//Now stores all the mods preferences into an array into preferences
|
|
|
|
$preferences->mods[$modname]->userinfo = $$var;
|
|
|
|
//And the name of the mod
|
|
|
|
$preferences->mods[$modname]->name = $modname;
|
2003-05-04 21:29:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Check other parameters
|
|
|
|
if (!isset($backup_users)) {
|
|
|
|
$backup_users = 1;
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
$preferences->backup_users = $backup_users;
|
2003-05-04 21:29:27 +00:00
|
|
|
|
|
|
|
if (!isset($backup_logs)) {
|
2003-07-15 18:12:41 +00:00
|
|
|
$backup_logs = 0;
|
2003-05-04 21:29:27 +00:00
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
$preferences->backup_logs = $backup_logs;
|
2003-05-04 21:29:27 +00:00
|
|
|
|
|
|
|
if (!isset($backup_user_files)) {
|
|
|
|
$backup_user_files = 1;
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
$preferences->backup_user_files = $backup_user_files;
|
2003-05-04 21:29:27 +00:00
|
|
|
|
|
|
|
if (!isset($backup_course_files)) {
|
|
|
|
$backup_course_files = 2;
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
$preferences->backup_course_files = $backup_course_files;
|
2003-05-04 21:29:27 +00:00
|
|
|
|
2003-05-04 23:24:48 +00:00
|
|
|
if (!isset($id)) {
|
|
|
|
error ("Course not specified");
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
$preferences->backup_course = $id;
|
2003-05-04 23:24:48 +00:00
|
|
|
|
|
|
|
if (!isset($backup_name)) {
|
|
|
|
error ("Backup name not specified");
|
|
|
|
}
|
2004-12-19 16:18:10 +00:00
|
|
|
//We clean it again (to prevent diacritics entered manually)
|
|
|
|
$preferences->backup_name = clean_filename($backup_name);
|
2003-05-04 23:24:48 +00:00
|
|
|
|
|
|
|
if (!isset($backup_unique_code)) {
|
|
|
|
error ("Backup unique code not specified");
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
$preferences->backup_unique_code = $backup_unique_code;
|
|
|
|
|
|
|
|
//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
|
|
|
|
echo "<table cellpadding=5>";
|
|
|
|
|
|
|
|
//Now print the Backup Name tr
|
|
|
|
echo "<tr>";
|
|
|
|
echo "<td align=\"right\"><p><b>";
|
|
|
|
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
|
2003-07-27 21:30:24 +00:00
|
|
|
echo "<li>".get_string("creatingtemporarystructures");
|
2003-05-04 23:24:48 +00:00
|
|
|
$status = check_and_create_backup_dir($backup_unique_code);
|
|
|
|
//Empty dir
|
|
|
|
if ($status) {
|
|
|
|
$status = clear_backup_dir($backup_unique_code);
|
|
|
|
}
|
2003-05-06 22:48:25 +00:00
|
|
|
|
2003-05-16 17:36:47 +00:00
|
|
|
//Delete old_entries from backup tables
|
2003-07-27 21:30:24 +00:00
|
|
|
echo "<li>".get_string("deletingolddata");
|
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>";
|
2003-07-27 21:30:24 +00:00
|
|
|
echo "<li>".get_string("writingheader");
|
2003-05-06 22:48:25 +00:00
|
|
|
//Obtain the xml file (create and open) and print prolog information
|
|
|
|
$backup_file = backup_open_xml($backup_unique_code);
|
2003-07-27 21:30:24 +00:00
|
|
|
echo "<li>".get_string("writinggeneralinfo");;
|
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>";
|
|
|
|
|
2003-07-27 21:30:24 +00:00
|
|
|
echo "<li>".get_string("courseinfo");
|
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
|
|
|
}
|
2004-10-29 17:07:11 +00:00
|
|
|
echo "<li>".get_string("blocks");
|
|
|
|
//Blocks information
|
|
|
|
if ($status) {
|
|
|
|
if (!$status = backup_course_blocks($backup_file,$preferences)) {
|
|
|
|
notify("An error occurred while backing up course blocks");
|
|
|
|
}
|
|
|
|
}
|
2003-07-27 21:30:24 +00:00
|
|
|
echo "<li>".get_string("sections");
|
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)
|
|
|
|
echo "</ul>";
|
2003-05-07 22:15:14 +00:00
|
|
|
|
|
|
|
//User info
|
2005-01-27 02:35:10 +00:00
|
|
|
if ($status && $preferences->backup_users) {
|
|
|
|
echo "<li>".get_string("writinguserinfo");
|
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
|
|
|
|
|
|
|
//If we have selected to backup quizzes, backup categories and
|
|
|
|
//questions structure (step 1). See notes on mod/quiz/backuplib.php
|
2003-07-27 21:30:24 +00:00
|
|
|
if ($status and $preferences->mods['quiz']->backup) {
|
|
|
|
echo "<li>".get_string("writingcategoriesandquestions");
|
2003-10-07 13:59:15 +00:00
|
|
|
if (!$status = quiz_backup_question_categories($backup_file,$preferences)) {
|
|
|
|
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) {
|
2003-07-27 21:30:24 +00:00
|
|
|
echo "<li>".get_string("writingloginfo");
|
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) {
|
|
|
|
echo "<li>".get_string("writingscalesinfo");
|
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) {
|
|
|
|
echo "<li>".get_string("writinggroupsinfo");
|
|
|
|
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) {
|
|
|
|
echo "<li>".get_string("writingeventsinfo");
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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) {
|
2003-07-27 21:30:24 +00:00
|
|
|
echo "<li>".get_string("modulenameplural",$module->name);
|
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
|
|
|
|
echo "</ul>";
|
|
|
|
//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)
|
|
|
|
echo "</ul>";
|
|
|
|
}
|
2003-05-10 17:44:08 +00:00
|
|
|
|
|
|
|
//Now, if selected, copy user files
|
|
|
|
if ($status) {
|
|
|
|
if ($preferences->backup_user_files) {
|
2003-07-27 21:30:24 +00:00
|
|
|
echo "<li>".get_string("copyinguserfiles");
|
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) {
|
2003-07-27 21:30:24 +00:00
|
|
|
echo "<li>".get_string("copyingcoursefiles");
|
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) {
|
2003-07-27 21:30:24 +00:00
|
|
|
echo "<li>".get_string("zippingbackup");
|
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) {
|
2003-07-27 21:30:24 +00:00
|
|
|
echo "<li>".get_string("copyingzipfile");
|
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) {
|
2003-07-27 21:30:24 +00:00
|
|
|
echo "<li>".get_string("cleaningtempdata");
|
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");
|
|
|
|
print_continue("$CFG->wwwroot/files/index.php?id=".$preferences->backup_course."&wdir=/backupdata");
|
|
|
|
} 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;
|
|
|
|
print_continue($CFG->wwwroot.'/course/import.php?id='.$to.'&fromcourse='.$id.'&filename='.$filename);
|
|
|
|
}
|
2003-05-04 21:29:27 +00:00
|
|
|
?>
|