Initial checkin for import course content functionality (uses backup/restore). Probably needs wording changes and new icon! Please test me *thoroughly*!
This commit is contained in:
+15
-3
@@ -9,6 +9,7 @@
|
||||
require_once ("$CFG->libdir/blocklib.php");
|
||||
|
||||
optional_variable($id); // course id
|
||||
optional_variable($to); // id of course to import into afterwards.
|
||||
optional_variable($cancel);
|
||||
optional_variable($launch);
|
||||
|
||||
@@ -16,7 +17,13 @@
|
||||
|
||||
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");
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!isadmin()) {
|
||||
@@ -34,14 +41,19 @@
|
||||
|
||||
//Check backup_version
|
||||
if ($id) {
|
||||
$linkto = "backup.php?id=".$id;
|
||||
$linkto = "backup.php?id=".$id.((!empty($to)) ? '&to='.$to : '');
|
||||
} else {
|
||||
$linkto = "backup.php";
|
||||
}
|
||||
upgrade_backup_db($linkto);
|
||||
|
||||
//Get strings
|
||||
$strcoursebackup = get_string("coursebackup");
|
||||
if (empty($to)) {
|
||||
$strcoursebackup = get_string("coursebackup");
|
||||
}
|
||||
else {
|
||||
$strcoursebackup = get_string('importdata');
|
||||
}
|
||||
$stradministration = get_string("administration");
|
||||
|
||||
//If no course has been selected or cancel button pressed
|
||||
|
||||
+57
-38
@@ -6,7 +6,13 @@
|
||||
|
||||
if (!empty($course->id)) {
|
||||
if (!isteacheredit($course->id)) {
|
||||
error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!isadmin()) {
|
||||
@@ -77,11 +83,6 @@
|
||||
<table cellpadding="5">
|
||||
<?php
|
||||
|
||||
//Now print the Backup Name tr
|
||||
echo "<tr>";
|
||||
echo "<td align=\"right\"><p><b>";
|
||||
echo get_string("name").":";
|
||||
echo "</b></td><td>";
|
||||
//Calculate the backup string
|
||||
|
||||
//Calculate the backup word
|
||||
@@ -118,22 +119,33 @@
|
||||
//And finally, clean everything
|
||||
$backup_name = clean_filename($backup_name);
|
||||
|
||||
//Add as text field
|
||||
echo "<input type=\"text\" name=\"backup_name\" size=\"40\" value=\"".$backup_name."\">";
|
||||
echo "</td></tr>";
|
||||
|
||||
//Calculate the backup unique code to allow simultaneus backups (to define
|
||||
//the temp-directory name and records in backup temp tables
|
||||
$backup_unique_code = time();
|
||||
//Add as hidden name
|
||||
echo "<input type=\"hidden\" name=\"backup_unique_code\" value=\"".$backup_unique_code."\">";
|
||||
|
||||
//Line
|
||||
echo "<tr><td colspan=\"2\"><hr noshade size=\"1\"></td></tr>";
|
||||
|
||||
//Now print the To Do list
|
||||
echo "<tr>";
|
||||
echo "<td colspan=\"2\" align=\"center\"><p><b>";
|
||||
if (empty($to)) {
|
||||
//Now print the Backup Name tr
|
||||
echo "<tr>";
|
||||
echo "<td align=\"right\"><P><B>";
|
||||
echo get_string("name").":";
|
||||
echo "</B></td><td>";
|
||||
//Add as text field
|
||||
echo "<input type=\"text\" name=\"backup_name\" size=\"40\" value=\"".$backup_name."\">";
|
||||
echo "</td></tr>";
|
||||
|
||||
//Line
|
||||
echo "<tr><td colspan=\"2\"><hr noshade size=\"1\"></td></tr>";
|
||||
|
||||
//Now print the To Do list
|
||||
echo "<tr>";
|
||||
echo "<td colspan=\"2\" align=\"center\"><p><b>";
|
||||
|
||||
} else {
|
||||
echo '<input type="hidden" name="backup_name" value="'.$backup_name.'" />';
|
||||
}
|
||||
|
||||
|
||||
//Here we check if backup_users = None. Then, we switch off every module
|
||||
//user info, user_files, logs and exercises and workshop backups. A Warning is showed to
|
||||
@@ -160,8 +172,10 @@
|
||||
echo "<hr noshade size=\"1\">";
|
||||
}
|
||||
|
||||
echo get_string("backupdetails").":";
|
||||
echo "</td></tr>";
|
||||
if (empty($to)) {
|
||||
echo get_string("backupdetails").":";
|
||||
echo "</td></tr>";
|
||||
}
|
||||
|
||||
//This is tha align to every ingo table
|
||||
$table->align = array ("left","right");
|
||||
@@ -200,25 +214,29 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
//Line
|
||||
echo "<tr><td colspan=\"2\"><hr noshade size=\"1\"></td></tr>";
|
||||
|
||||
//Now print the Users tr
|
||||
echo "<tr>";
|
||||
echo "<td colspan=\"2\"><p><b>";
|
||||
$user_options[0] = get_string("includeallusers");
|
||||
$user_options[1] = get_string("includecourseusers");
|
||||
$user_options[2] = get_string("includenoneusers");
|
||||
echo "<li>".$user_options[$backup_users]."<p>";
|
||||
|
||||
if (empty($to)) {
|
||||
//Line
|
||||
echo "<tr><td colspan=\"2\"><hr noshade size=\"1\"></td></tr>";
|
||||
|
||||
//Now print the Users tr
|
||||
echo "<tr>";
|
||||
echo "<td colspan=\"2\"><p><b>";
|
||||
$user_options[0] = get_string("includeallusers");
|
||||
$user_options[1] = get_string("includecourseusers");
|
||||
$user_options[2] = get_string("includenoneusers");
|
||||
echo "<li>".$user_options[$backup_users]."<p>";
|
||||
//Print info
|
||||
$table->data = user_check_backup($id,$backup_unique_code,$backup_users);
|
||||
print_table($table);
|
||||
echo "</td></tr>";
|
||||
|
||||
}
|
||||
//Add as hidden name
|
||||
echo "<input type=\"hidden\" name=\"backup_users\" value=\"".$backup_users."\">";
|
||||
//Print info
|
||||
$table->data = user_check_backup($id,$backup_unique_code,$backup_users);
|
||||
print_table($table);
|
||||
echo "</td></tr>";
|
||||
|
||||
|
||||
//Now print the Logs tr conditionally
|
||||
if ($backup_logs) {
|
||||
if ($backup_logs && empty($to)) {
|
||||
echo "<tr>";
|
||||
echo "<td colspan=\"2\"><p><b>";
|
||||
echo "<li>".get_string("includelogentries")."<p>";
|
||||
@@ -260,9 +278,10 @@
|
||||
</table>
|
||||
<br />
|
||||
<center>
|
||||
<input type="hidden" name="id" value="<?php p($id) ?>">
|
||||
<input type="hidden" name="launch" value="execute">
|
||||
<input type="submit" value="<?php print_string("continue") ?>">
|
||||
<input type="submit" name="cancel" value="<?php print_string("cancel") ?>">
|
||||
<input type="hidden" name="to" value="<?php p($to) ?>" />
|
||||
<input type="hidden" name="id" value="<?php p($id) ?>" />
|
||||
<input type="hidden" name="launch" value="execute" />
|
||||
<input type="submit" value="<?php print_string("continue") ?>" />
|
||||
<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
|
||||
</center>
|
||||
</form>
|
||||
|
||||
+43
-24
@@ -6,7 +6,13 @@
|
||||
|
||||
if (!empty($course->id)) {
|
||||
if (!isteacheredit($course->id)) {
|
||||
error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!isadmin()) {
|
||||
@@ -106,24 +112,26 @@
|
||||
notice("No backupable modules are installed!");
|
||||
}
|
||||
|
||||
//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>";
|
||||
|
||||
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>";
|
||||
}
|
||||
//Check for temp and backup and backup_unique_code directory
|
||||
//Create them as needed
|
||||
echo "<li>".get_string("creatingtemporarystructures");
|
||||
@@ -185,9 +193,9 @@
|
||||
//End course contents (close ul)
|
||||
echo "</ul>";
|
||||
|
||||
echo "<li>".get_string("writinguserinfo");
|
||||
//User info
|
||||
if ($status) {
|
||||
if ($status && $preferences->backup_users) {
|
||||
echo "<li>".get_string("writinguserinfo");
|
||||
if (!$status = backup_user_info($backup_file,$preferences)) {
|
||||
notify("An error occurred while backing up user info");
|
||||
}
|
||||
@@ -346,8 +354,19 @@
|
||||
"$CFG->wwwroot/course/view.php?id=$course->id");
|
||||
}
|
||||
|
||||
//Print final message
|
||||
print_simple_box(get_string("backupfinished"),"center");
|
||||
print_continue("$CFG->wwwroot/files/index.php?id=".$preferences->backup_course."&wdir=/backupdata");
|
||||
|
||||
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);
|
||||
}
|
||||
?>
|
||||
|
||||
+68
-42
@@ -6,7 +6,13 @@
|
||||
|
||||
if (!empty($course->id)) {
|
||||
if (!isteacheredit($course->id)) {
|
||||
error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!isadmin()) {
|
||||
@@ -92,50 +98,69 @@
|
||||
$backup_options[1] = get_string("yes");
|
||||
$var = "backup_".$modname;
|
||||
choose_from_menu($backup_options, $var, $$var, "");
|
||||
$backup_user_options[0] = get_string("withoutuserdata");
|
||||
$backup_user_options[1] = get_string("withuserdata");
|
||||
$var = "backup_user_info_".$modname;
|
||||
choose_from_menu($backup_user_options, $var, $$var, "");
|
||||
echo "</td></tr>";
|
||||
if (empty($to)) {
|
||||
$backup_user_options[0] = get_string("withoutuserdata");
|
||||
$backup_user_options[1] = get_string("withuserdata");
|
||||
choose_from_menu($backup_user_options, $var, $$var, "");
|
||||
}
|
||||
else {
|
||||
echo '<input type="hidden" name="'.$var.'" value="0" />';
|
||||
}
|
||||
echo "</td></tr>";
|
||||
}
|
||||
}
|
||||
//Line
|
||||
echo "<tr><td colspan=\"2\"><hr noshade size=\"1\"></td></tr>";
|
||||
|
||||
//Now print the Users tr
|
||||
echo "<tr>";
|
||||
echo "<td align=\"right\"><p><b>";
|
||||
echo get_string("users").":";
|
||||
echo "</td><td>";
|
||||
$user_options[0] = get_string("all");
|
||||
$user_options[1] = get_string("course");
|
||||
$user_options[2] = get_string("none");
|
||||
choose_from_menu($user_options, "backup_users", $backup_users, "");
|
||||
echo "</td></tr>";
|
||||
|
||||
//Now print the Logs tr
|
||||
echo "<tr>";
|
||||
echo "<td align=\"right\"><p><b>";
|
||||
echo get_string("logs").":";
|
||||
echo "</td><td>";
|
||||
$log_options[0] = get_string("no");
|
||||
$log_options[1] = get_string("yes");
|
||||
choose_from_menu($log_options, "backup_logs", $backup_logs, "");
|
||||
echo "</td></tr>";
|
||||
|
||||
//Now print the User Files tr
|
||||
echo "<tr>";
|
||||
echo "<td align=\"right\"><p><b>";
|
||||
echo get_string ("userfiles").":";
|
||||
echo "</td><td>";
|
||||
$user_file_options[0] = get_string("no");
|
||||
$user_file_options[1] = get_string("yes");
|
||||
choose_from_menu($user_file_options, "backup_user_files", $backup_user_files, "");
|
||||
echo "</td></tr>";
|
||||
|
||||
|
||||
if (empty($to)) {
|
||||
//Now print the Users tr
|
||||
echo "<tr>";
|
||||
echo "<td align=\"right\"><P><B>";
|
||||
echo get_string("users").":";
|
||||
echo "</td><td>";
|
||||
$user_options[0] = get_string("all");
|
||||
$user_options[1] = get_string("course");
|
||||
$user_options[2] = get_string("none");
|
||||
choose_from_menu($user_options, "backup_users", $backup_users, "");
|
||||
echo "</td></tr>";
|
||||
}
|
||||
else {
|
||||
echo '<input type="hidden" name="backup_users" value="0" />';
|
||||
}
|
||||
|
||||
if (empty($to)) {
|
||||
//Now print the Logs tr
|
||||
echo "<tr>";
|
||||
echo "<td align=\"right\"><P><B>";
|
||||
echo get_string("logs").":";
|
||||
echo "</td><td>";
|
||||
$log_options[0] = get_string("no");
|
||||
$log_options[1] = get_string("yes");
|
||||
choose_from_menu($log_options, "backup_logs", $backup_logs, "");
|
||||
echo "</td></tr>";
|
||||
}
|
||||
else {
|
||||
echo '<input type="hidden" name="backup_logs" value="0" />';
|
||||
}
|
||||
|
||||
if (empty($to)) {
|
||||
//Now print the User Files tr
|
||||
echo "<tr>";
|
||||
echo "<td align=\"right\"><P><B>";
|
||||
echo get_string ("userfiles").":";
|
||||
echo "</td><td>";
|
||||
$user_file_options[0] = get_string("no");
|
||||
$user_file_options[1] = get_string("yes");
|
||||
choose_from_menu($user_file_options, "backup_user_files", $backup_user_files, "");
|
||||
echo "</td></tr>";
|
||||
}
|
||||
else {
|
||||
echo '<input type="hidden" name="backup_user_files" value="0" />';
|
||||
}
|
||||
//Now print the Course Files tr
|
||||
echo "<tr>";
|
||||
echo "<td align=\"right\"><p><b>";
|
||||
echo "<td align=\"right\"><P><B>";
|
||||
echo get_string ("coursefiles").":";
|
||||
echo "</td><td>";
|
||||
$course_file_options[0] = get_string("no");
|
||||
@@ -147,9 +172,10 @@
|
||||
</table>
|
||||
<br />
|
||||
<center>
|
||||
<input type="hidden" name="id" value="<?php p($id) ?>">
|
||||
<input type="hidden" name="launch" value="check">
|
||||
<input type="submit" value="<?php print_string("continue") ?>">
|
||||
<input type="submit" name="cancel" value="<?php print_string("cancel") ?>">
|
||||
<input type="hidden" name="id" value="<?php p($id) ?>" />
|
||||
<input type="hidden" name="to" value="<?php p($to) ?>" />
|
||||
<input type="hidden" name="launch" value="check" />
|
||||
<input type="submit" value="<?php print_string("continue") ?>" />
|
||||
<input type="submit" name="cancel" value="<?php print_string("cancel") ?>" />
|
||||
</center>
|
||||
</form>
|
||||
|
||||
+27
-4
@@ -16,13 +16,24 @@
|
||||
optional_variable($file);
|
||||
optional_variable($cancel);
|
||||
optional_variable($launch);
|
||||
optional_variable($to);
|
||||
|
||||
//Check login
|
||||
require_login();
|
||||
|
||||
if (!$to && isset($SESSION->restore->restoreto) && isset($SESSION->restore->importing) && isset($SESSION->restore->course_id)) {
|
||||
$to = $SESSION->restore->course_id;
|
||||
}
|
||||
|
||||
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");
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!isadmin()) {
|
||||
@@ -47,7 +58,11 @@
|
||||
upgrade_backup_db($linkto);
|
||||
|
||||
//Get strings
|
||||
$strcourserestore = get_string("courserestore");
|
||||
if (empty($to)) {
|
||||
$strcourserestore = get_string("courserestore");
|
||||
} else {
|
||||
$strcourserestore = get_string("importdata");
|
||||
}
|
||||
$stradministration = get_string("administration");
|
||||
|
||||
//If no file has been selected from the FileManager, inform and end
|
||||
@@ -90,7 +105,7 @@
|
||||
$strcourserestore");
|
||||
}
|
||||
//Print form
|
||||
print_heading("$strcourserestore: ".basename($file));
|
||||
print_heading("$strcourserestore".((empty($to) ? ': '.basename($file) : '')));
|
||||
print_simple_box_start("center", "", "$THEME->cellheading");
|
||||
|
||||
//Adjust some php variables to the execution of this script
|
||||
@@ -98,10 +113,18 @@
|
||||
raise_memory_limit("memory_limit","128M");
|
||||
|
||||
//Call the form, depending the step we are
|
||||
|
||||
|
||||
if (!$launch) {
|
||||
include_once("restore_precheck.html");
|
||||
} else if ($launch == "form") {
|
||||
include_once("restore_form.html");
|
||||
if ($SESSION->restore->importing) {
|
||||
// set up all the config stuff and skip asking the user about it.
|
||||
restore_setup_for_check($SESSION->restore,$backup_unique_code);
|
||||
include_once("restore_execute.html");
|
||||
} else {
|
||||
include_once("restore_form.html");
|
||||
}
|
||||
} else if ($launch == "check") {
|
||||
include_once("restore_check.html");
|
||||
} else if ($launch == "execute") {
|
||||
|
||||
@@ -20,7 +20,13 @@
|
||||
//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");
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!isadmin()) {
|
||||
@@ -382,8 +388,14 @@
|
||||
error ("An error has occurred and the restore could not be completed!");
|
||||
}
|
||||
|
||||
//Print final message
|
||||
print_simple_box(get_string("restorefinished"),"center");
|
||||
if (!$restore->importing) {
|
||||
echo $output;
|
||||
//Print final message
|
||||
print_simple_box(get_string("restorefinished"),"CENTER");
|
||||
} else {
|
||||
print_simple_box(get_string("importdatafinished"),"CENTER");
|
||||
unset($SESSION->restore);
|
||||
}
|
||||
print_continue("$CFG->wwwroot/course/view.php?id=".$restore->course_id);
|
||||
|
||||
?>
|
||||
|
||||
+10
-121
@@ -15,7 +15,13 @@
|
||||
//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");
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!isadmin()) {
|
||||
@@ -28,127 +34,10 @@
|
||||
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>";
|
||||
}
|
||||
|
||||
$status = restore_precheck($id,$file,!empty($SESSION->restore->importing));
|
||||
|
||||
if (!$status) {
|
||||
error ("An error has ocurred");
|
||||
error("An error occured");
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -3165,4 +3165,192 @@
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
|
||||
function restore_precheck($id,$file,$silent=false) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
//Prepend dataroot to variable to have the absolute path
|
||||
$file = $CFG->dataroot."/".$file;
|
||||
|
||||
if (empty($silent)) {
|
||||
//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)
|
||||
if (empty($silent)) {
|
||||
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) {
|
||||
if (empty($silent)) {
|
||||
echo "<li>".get_string("deletingolddata");
|
||||
}
|
||||
$status = backup_delete_old_data();
|
||||
}
|
||||
|
||||
//Now copy he zip file to dataroot/temp/backup/backup_unique_code
|
||||
if ($status) {
|
||||
if (empty($silent)) {
|
||||
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) {
|
||||
if (empty($silent)) {
|
||||
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";
|
||||
if (empty($silent)) {
|
||||
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) {
|
||||
if (empty($silent)) {
|
||||
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);
|
||||
}
|
||||
|
||||
if (empty($silent)) {
|
||||
//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) {
|
||||
if (empty($silent)) {
|
||||
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>";
|
||||
}
|
||||
else {
|
||||
redirect($CFG->wwwroot.'/backup/restore.php?backup_unique_code='.$backup_unique_code.'&launch=form&file='.$file.'&id='.$id);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$status) {
|
||||
error ("An error has ocurred");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function restore_setup_for_check(&$restore,$backup_unique_code) {
|
||||
global $SESSION;
|
||||
$restore->backup_unique_code=$backup_unique_code;
|
||||
$restore->users = 2; // yuk
|
||||
if ($allmods = get_records("modules")) {
|
||||
foreach ($allmods as $mod) {
|
||||
$modname = $mod->name;
|
||||
$var = "restore_".$modname;
|
||||
//Now check that we have that module info in the backup file
|
||||
if (isset($SESSION->info->mods[$modname]) && $SESSION->info->mods[$modname]->backup == "true") {
|
||||
$restore->$var = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function backup_to_restore_array($backup,$k=0) {
|
||||
if (is_array($backup) ) {
|
||||
foreach ($backup as $key => $value) {
|
||||
$newkey = str_replace('backup','restore',$key);
|
||||
$restore[$newkey] = backup_to_restore_array($value,$key);
|
||||
}
|
||||
}
|
||||
else if (is_object($backup)) {
|
||||
$tmp = get_object_vars($backup);
|
||||
foreach ($tmp as $key => $value) {
|
||||
$newkey = str_replace('backup','restore',$key);
|
||||
$restore->$newkey = backup_to_restore_array($value,$key);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$newkey = str_replace('backup','restore',$k);
|
||||
$restore = $backup;
|
||||
}
|
||||
return $restore;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -117,6 +117,10 @@ class block_admin extends block_base {
|
||||
|
||||
$this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->instance->pageid.'&wdir=/backupdata">'.get_string('restore').'...</a>';
|
||||
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" height="16" width="16" alt="" />';
|
||||
|
||||
$this->content->items[]='<a href="'.$CFG->wwwroot.'/course/import.php?id='.$this->instance->pageid.'">'.get_string('importdata').'</a>';
|
||||
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" height="16" width="16" alt="" />';
|
||||
|
||||
$this->content->items[]='<a href="scales.php?id='.$this->instance->pageid.'">'.get_string('scales').'...</a>';
|
||||
$this->content->icons[]='<img src="'.$CFG->pixpath.'/i/scales.gif" height="16" width="16" alt="" />';
|
||||
}
|
||||
|
||||
@@ -254,6 +254,8 @@ $string['coursegrades'] = 'Course grades';
|
||||
$string['courseinfo'] = 'Course info';
|
||||
$string['courserestore'] = 'Course restore';
|
||||
$string['courses'] = 'Courses';
|
||||
$string['coursestaught'] = 'Courses I have taught';
|
||||
$string['coursescategory'] = 'Courses in the same category';
|
||||
$string['courseupdates'] = 'Course updates';
|
||||
$string['courseuploadlimit'] = 'Course upload limit';
|
||||
$string['create'] = 'Create';
|
||||
@@ -590,6 +592,10 @@ $string['htmleditordisabledbrowser'] = 'The HTML editor is unavailable because y
|
||||
$string['htmlformat'] = 'Pretty HTML format';
|
||||
$string['icqnumber'] = 'ICQ number';
|
||||
$string['idnumber'] = 'ID number';
|
||||
$string['importdata'] = 'Import course data';
|
||||
$string['importdatafrom'] = 'Find a course to import data from:';
|
||||
$string['importdataexported'] = 'Exported data from \'from\' course successfully.<br /> Continue to import into your \'to\' course.';
|
||||
$string['importdatafinished'] = 'Import complete! Continue to your course';
|
||||
$string['importmetacoursenote'] = 'Use this form to add courses to your meta course (this will import the enrolments)';
|
||||
$string['inactive'] = 'Inactive';
|
||||
$string['include'] = 'Include';
|
||||
@@ -797,6 +803,7 @@ $string['nopotentialadmins'] = 'No potential admins';
|
||||
$string['nopotentialcreators'] = 'No potential course creators';
|
||||
$string['nopotentialstudents'] = 'No potential students';
|
||||
$string['nopotentialteachers'] = 'No potential teachers';
|
||||
$string['noresults'] = 'No results';
|
||||
$string['normal'] = 'Normal';
|
||||
$string['normalfilter'] = 'Normal search';
|
||||
$string['nostudentsfound'] = 'No $a found';
|
||||
@@ -1093,6 +1100,7 @@ $string['userprofilefor'] = 'User profile for $a';
|
||||
$string['users'] = 'Users';
|
||||
$string['usersnew'] = 'New users';
|
||||
$string['userzones'] = 'User zones';
|
||||
$string['usethiscourse'] = 'Use this course';
|
||||
$string['usingexistingcourse'] = 'Using existing course';
|
||||
$string['version'] = 'Version';
|
||||
$string['view'] = 'View';
|
||||
|
||||
Reference in New Issue
Block a user