MDL-10364 Added the showcalculations preference and re-factored preferences_form...
[moodle-pu.git] / backup / restore.php
blobdf9b64cfd3e2293a32b755f6abcd69419f979c4f
1 <?php //$Id$
2 //This script is used to configure and execute the restore proccess.
4 //Define some globals for all the script
6 //Units used
7 require_once("../config.php");
8 require_once("../lib/xmlize.php");
9 require_once("../course/lib.php");
10 require_once("lib.php");
11 require_once("restorelib.php");
12 require_once("bb/restore_bb.php");
13 require_once("$CFG->libdir/blocklib.php");
14 require_once("$CFG->libdir/wiki_to_markdown.php" );
15 require_once("$CFG->libdir/adminlib.php");
17 //Optional
18 $id = optional_param( 'id' );
19 $file = optional_param( 'file' );
20 $cancel = optional_param( 'cancel' );
21 $launch = optional_param( 'launch' );
22 $to = optional_param( 'to' );
23 $method = optional_param( 'method' );
24 $backup_unique_code = optional_param('backup_unique_code',0,PARAM_INT);
26 //Check login
27 require_login();
29 /// With method=manual, we come from the FileManager so we delete all the backup/restore/import session structures
30 if ($method == 'manual') {
31 if (isset($SESSION->course_header)) {
32 unset ($SESSION->course_header);
34 if (isset($SESSION->info)) {
35 unset ($SESSION->info);
37 if (isset($SESSION->backupprefs)) {
38 unset ($SESSION->backupprefs);
40 if (isset($SESSION->restore)) {
41 unset ($SESSION->restore);
43 if (isset($SESSION->import_preferences)) {
44 unset ($SESSION->import_preferences);
48 if (!$to && isset($SESSION->restore->restoreto) && isset($SESSION->restore->importing) && isset($SESSION->restore->course_id)) {
49 $to = $SESSION->restore->course_id;
52 if (!empty($id)) {
53 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
54 if (empty($to)) {
55 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
56 } else {
57 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))) {
58 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
62 } else {
63 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
64 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
68 //Check site
69 if (!$site = get_site()) {
70 error("Site not found!");
73 //Check necessary functions exists. Thanks to gregb@crowncollege.edu
74 backup_required_functions();
76 //Check backup_version
77 if ($file) {
78 $linkto = "restore.php?id=".$id."&amp;file=".$file;
79 } else {
80 $linkto = "restore.php";
82 upgrade_backup_db($linkto);
84 //Get strings
85 if (empty($to)) {
86 $strcourserestore = get_string("courserestore");
87 } else {
88 $strcourserestore = get_string("importdata");
90 $stradministration = get_string("administration");
92 //If no file has been selected from the FileManager, inform and end
93 if (!$file) {
94 print_header("$site->shortname: $strcourserestore", $site->fullname,
95 "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> $strcourserestore");
96 print_heading(get_string("nofilesselected"));
97 print_continue("$CFG->wwwroot/$CFG->admin/index.php");
98 print_footer();
99 exit;
102 //If cancel has been selected, inform and end
103 if ($cancel) {
104 print_header("$site->shortname: $strcourserestore", $site->fullname,
105 "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> $strcourserestore");
106 print_heading(get_string("restorecancelled"));
107 print_continue("$CFG->wwwroot/$CFG->admin/index.php");
108 print_footer();
109 exit;
112 //We are here, so me have a file.
114 //Get and check course
115 if (! $course = get_record("course", "id", $id)) {
116 error("Course ID was incorrect (can't find it)");
119 //Print header
120 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
121 print_header("$site->shortname: $strcourserestore", $site->fullname,
122 "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> ->
123 $strcourserestore -> ".basename($file));
124 } else {
125 print_header("$course->shortname: $strcourserestore", $course->fullname,
126 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
127 $strcourserestore");
129 //Print form
130 print_heading("$strcourserestore".((empty($to) ? ': '.basename($file) : '')));
131 print_simple_box_start('center');
133 //Adjust some php variables to the execution of this script
134 @ini_set("max_execution_time","3000");
135 raise_memory_limit("192M");
137 //Call the form, depending the step we are
139 if (!$launch) {
140 include_once("restore_precheck.html");
141 } else if ($launch == "form") {
142 if (!empty($SESSION->restore->importing)) {
143 // set up all the config stuff and skip asking the user about it.
144 restore_setup_for_check($SESSION->restore,$backup_unique_code);
145 include_once("restore_execute.html");
146 } else {
147 include_once("restore_form.html");
149 } else if ($launch == "check") {
150 include_once("restore_check.html");
151 //To avoid multiple restore executions...
152 $SESSION->cancontinue = true;
153 } else if ($launch == "execute") {
154 //Prevent multiple restore executions...
155 if (empty($SESSION->cancontinue)) {
156 error("Multiple restore execution not allowed!");
158 //Unset this for the future
159 unset($SESSION->cancontinue);
160 include_once("restore_execute.html");
162 print_simple_box_end();
164 //Print footer
165 print_footer();