2 //This script is used to configure and execute the restore proccess.
4 //Define some globals for all the script
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");
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 //Get and check course
27 if (! $course = get_record("course", "id", $id)) {
28 error("Course ID was incorrect (can't find it)");
30 // To some reasons, course_startdateoffset value was lost during restoring
32 if (!empty($course->startdate
) && !empty($SESSION->course_header
->course_startdate
)) {
33 $SESSION->restore
->course_startdateoffset
= $course->startdate
- $SESSION->course_header
->course_startdate
;
35 $SESSION->restore
->course_startdateoffset
= 0;
41 /// With method=manual, we come from the FileManager so we delete all the backup/restore/import session structures
42 if ($method == 'manual') {
43 if (isset($SESSION->course_header
)) {
44 unset ($SESSION->course_header
);
46 if (isset($SESSION->info
)) {
47 unset ($SESSION->info
);
49 if (isset($SESSION->backupprefs
)) {
50 unset ($SESSION->backupprefs
);
52 if (isset($SESSION->restore
)) {
53 unset ($SESSION->restore
);
55 if (isset($SESSION->import_preferences
)) {
56 unset ($SESSION->import_preferences
);
60 if (!$to && isset($SESSION->restore
->restoreto
) && isset($SESSION->restore
->importing
) && isset($SESSION->restore
->course_id
)) {
61 $to = $SESSION->restore
->course_id
;
66 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE
, $id))) {
68 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
70 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE
, $to))
71 && !has_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE
, $to))) {
72 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
77 if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM
))) {
78 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
83 if (!$site = get_site()) {
84 error("Site not found!");
87 //Check necessary functions exists. Thanks to gregb@crowncollege.edu
88 backup_required_functions();
90 //Check backup_version
92 $linkto = "restore.php?id=".$id."&file=".$file;
94 $linkto = "restore.php";
96 upgrade_backup_db($linkto);
100 $strcourserestore = get_string("courserestore");
102 $strcourserestore = get_string("importdata");
104 $stradministration = get_string("administration");
106 //If no file has been selected from the FileManager, inform and end
108 $navlinks[] = array('name' => $stradministration, 'link' => "$CFG->wwwroot/$CFG->admin/index.php", 'type' => 'misc');
109 $navlinks[] = array('name' => $strcourserestore, 'link' => null, 'type' => 'misc');
110 $navigation = build_navigation($navlinks);
113 print_header("$site->shortname: $strcourserestore", $site->fullname
, $navigation);
114 print_heading(get_string("nofilesselected"));
115 print_continue("$CFG->wwwroot/$CFG->admin/index.php");
120 //If cancel has been selected, inform and end
122 print_header("$site->shortname: $strcourserestore", $site->fullname
, $navigation);
123 print_heading(get_string("restorecancelled"));
124 print_continue("$CFG->wwwroot/course/view.php?id=".$id);
129 //We are here, so me have a file.
132 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
))) {
133 $navlinks[] = array('name' => basename($file), 'link' => null, 'type' => 'misc');
134 $navigation = build_navigation($navlinks);
136 print_header("$site->shortname: $strcourserestore", $site->fullname
, $navigation);
139 $navlinks[] = array('name' => $course->shortname
, 'link' => "$CFG->wwwroot/course/view.php?id=$course->id", 'type' => 'misc');
140 $navlinks[] = array('name' => $strcourserestore, 'link' => null, 'type' => 'misc');
141 $navigation = build_navigation($navlinks);
142 print_header("$course->shortname: $strcourserestore", $course->fullname
, $navigation);
145 print_heading("$strcourserestore".((empty($to) ?
': '.basename($file) : '')));
146 print_simple_box_start('center');
148 //Adjust some php variables to the execution of this script
149 @ini_set
("max_execution_time","3000");
150 raise_memory_limit("192M");
152 //Call the form, depending the step we are
155 include_once("restore_precheck.html");
156 } else if ($launch == "form") {
157 if (!empty($SESSION->restore
->importing
)) {
158 // set up all the config stuff and skip asking the user about it.
159 restore_setup_for_check($SESSION->restore
,$backup_unique_code);
160 include_once("restore_execute.html");
162 include_once("restore_form.html");
164 } else if ($launch == "check") {
165 include_once("restore_check.html");
166 //To avoid multiple restore executions...
167 $SESSION->cancontinue
= true;
168 } else if ($launch == "execute") {
169 //Prevent multiple restore executions...
170 if (empty($SESSION->cancontinue
)) {
171 error("Multiple restore execution not allowed!");
173 //Unset this for the future
174 unset($SESSION->cancontinue
);
175 include_once("restore_execute.html");
177 print_simple_box_end();