MDL-11515:
[moodle-linuxchix.git] / backup / restore.php
blob47f20c94efa421cf2afe0bd55910350d6676c334
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 require_login($id);
54 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
55 if (empty($to)) {
56 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
57 } else {
58 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))) {
59 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
63 } else {
64 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
65 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
69 //Check site
70 if (!$site = get_site()) {
71 error("Site not found!");
74 //Check necessary functions exists. Thanks to gregb@crowncollege.edu
75 backup_required_functions();
77 //Check backup_version
78 if ($file) {
79 $linkto = "restore.php?id=".$id."&amp;file=".$file;
80 } else {
81 $linkto = "restore.php";
83 upgrade_backup_db($linkto);
85 //Get strings
86 if (empty($to)) {
87 $strcourserestore = get_string("courserestore");
88 } else {
89 $strcourserestore = get_string("importdata");
91 $stradministration = get_string("administration");
93 //If no file has been selected from the FileManager, inform and end
94 $navlinks = array();
95 $navlinks[] = array('name' => $stradministration, 'link' => "$CFG->wwwroot/$CFG->admin/index.php", 'type' => 'misc');
96 $navlinks[] = array('name' => $strcourserestore, 'link' => null, 'type' => 'misc');
97 $navigation = build_navigation($navlinks);
99 if (!$file) {
100 print_header("$site->shortname: $strcourserestore", $site->fullname, $navigation);
101 print_heading(get_string("nofilesselected"));
102 print_continue("$CFG->wwwroot/$CFG->admin/index.php");
103 print_footer();
104 exit;
107 //If cancel has been selected, inform and end
108 if ($cancel) {
109 print_header("$site->shortname: $strcourserestore", $site->fullname, $navigation);
110 print_heading(get_string("restorecancelled"));
111 print_continue("$CFG->wwwroot/$CFG->admin/index.php");
112 print_footer();
113 exit;
116 //We are here, so me have a file.
118 //Get and check course
119 if (! $course = get_record("course", "id", $id)) {
120 error("Course ID was incorrect (can't find it)");
123 //Print header
124 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
125 $navlinks[] = array('name' => basename($file), 'link' => null, 'type' => 'misc');
126 $navigation = build_navigation($navlinks);
128 print_header("$site->shortname: $strcourserestore", $site->fullname, $navigation);
129 } else {
130 $navlinks = array();
131 $navlinks[] = array('name' => $course->shortname, 'link' => "$CFG->wwwroot/course/view.php?id=$course->id", 'type' => 'misc');
132 $navlinks[] = array('name' => $strcourserestore, 'link' => null, 'type' => 'misc');
133 $navigation = build_navigation($navlinks);
134 print_header("$course->shortname: $strcourserestore", $course->fullname, $navigation);
136 //Print form
137 print_heading("$strcourserestore".((empty($to) ? ': '.basename($file) : '')));
138 print_simple_box_start('center');
140 //Adjust some php variables to the execution of this script
141 @ini_set("max_execution_time","3000");
142 raise_memory_limit("192M");
144 //Call the form, depending the step we are
146 if (!$launch) {
147 include_once("restore_precheck.html");
148 } else if ($launch == "form") {
149 if (!empty($SESSION->restore->importing)) {
150 // set up all the config stuff and skip asking the user about it.
151 restore_setup_for_check($SESSION->restore,$backup_unique_code);
152 include_once("restore_execute.html");
153 } else {
154 include_once("restore_form.html");
156 } else if ($launch == "check") {
157 include_once("restore_check.html");
158 //To avoid multiple restore executions...
159 $SESSION->cancontinue = true;
160 } else if ($launch == "execute") {
161 //Prevent multiple restore executions...
162 if (empty($SESSION->cancontinue)) {
163 error("Multiple restore execution not allowed!");
165 //Unset this for the future
166 unset($SESSION->cancontinue);
167 include_once("restore_execute.html");
169 print_simple_box_end();
171 //Print footer
172 print_footer();