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" );
17 $id = optional_param( 'id' );
18 $file = optional_param( 'file' );;
19 $cancel = optional_param( 'cancel' );
20 $launch = optional_param( 'launch' );
21 $to = optional_param( 'to' );
26 if (!$to && isset($SESSION->restore
->restoreto
) && isset($SESSION->restore
->importing
) && isset($SESSION->restore
->course_id
)) {
27 $to = $SESSION->restore
->course_id
;
31 if (!isteacheredit($id)) {
33 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
35 if (!isteacheredit($to)) {
36 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
42 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
47 if (!$site = get_site()) {
48 error("Site not found!");
51 //Check necessary functions exists. Thanks to gregb@crowncollege.edu
52 backup_required_functions();
54 //Check backup_version
56 $linkto = "restore.php?id=".$id."&file=".$file;
58 $linkto = "restore.php";
60 upgrade_backup_db($linkto);
64 $strcourserestore = get_string("courserestore");
66 $strcourserestore = get_string("importdata");
68 $stradministration = get_string("administration");
70 //If no file has been selected from the FileManager, inform and end
72 print_header("$site->shortname: $strcourserestore", $site->fullname
,
73 "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> $strcourserestore");
74 print_heading(get_string("nofilesselected"));
75 print_continue("$CFG->wwwroot/$CFG->admin/index.php");
80 //If cancel has been selected, inform and end
82 print_header("$site->shortname: $strcourserestore", $site->fullname
,
83 "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> $strcourserestore");
84 print_heading(get_string("restorecancelled"));
85 print_continue("$CFG->wwwroot/$CFG->admin/index.php");
90 //We are here, so me have a file.
92 //Get and check course
93 if (! $course = get_record("course", "id", $id)) {
94 error("Course ID was incorrect (can't find it)");
97 check_for_restricted_user($USER->username
, "$CFG->wwwroot/course/view.php?id=$course->id");
101 print_header("$site->shortname: $strcourserestore", $site->fullname
,
102 "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> ->
103 $strcourserestore -> ".basename($file));
105 print_header("$course->shortname: $strcourserestore", $course->fullname
,
106 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
110 print_heading("$strcourserestore".((empty($to) ?
': '.basename($file) : '')));
111 print_simple_box_start('center');
113 //Adjust some php variables to the execution of this script
114 @ini_set
("max_execution_time","3000");
115 raise_memory_limit("memory_limit","128M");
117 //Call the form, depending the step we are
121 include_once("restore_precheck.html");
122 } else if ($launch == "form") {
123 if ($SESSION->restore
->importing
) {
124 // set up all the config stuff and skip asking the user about it.
125 restore_setup_for_check($SESSION->restore
,$backup_unique_code);
126 include_once("restore_execute.html");
128 include_once("restore_form.html");
130 } else if ($launch == "check") {
131 include_once("restore_check.html");
132 //To avoid multiple restore executions...
133 $SESSION->cancontinue
= true;
134 } else if ($launch == "execute") {
135 //Prevent multiple restore executions...
136 if (empty($SESSION->cancontinue
)) {
137 error("Multiple restore execution not allowed!");
139 //Unset this for the future
140 unset($SESSION->cancontinue
);
141 include_once("restore_execute.html");
143 print_simple_box_end();