Added descriptions of some more of the filters.
[moodle-linuxchix.git] / backup / restore.php
blob65e68416eab7368ab6e5319341b96eb50d78bf9e
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" );
16 //Optional
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' );
23 //Check login
24 require_login();
26 if (!$to && isset($SESSION->restore->restoreto) && isset($SESSION->restore->importing) && isset($SESSION->restore->course_id)) {
27 $to = $SESSION->restore->course_id;
30 if (!empty($id)) {
31 if (!isteacheredit($id)) {
32 if (empty($to)) {
33 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
34 } else {
35 if (!isteacheredit($to)) {
36 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
40 } else {
41 if (!isadmin()) {
42 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
46 //Check site
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
55 if ($file) {
56 $linkto = "restore.php?id=".$id."&amp;file=".$file;
57 } else {
58 $linkto = "restore.php";
60 upgrade_backup_db($linkto);
62 //Get strings
63 if (empty($to)) {
64 $strcourserestore = get_string("courserestore");
65 } else {
66 $strcourserestore = get_string("importdata");
68 $stradministration = get_string("administration");
70 //If no file has been selected from the FileManager, inform and end
71 if (!$file) {
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");
76 print_footer();
77 exit;
80 //If cancel has been selected, inform and end
81 if ($cancel) {
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");
86 print_footer();
87 exit;
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");
99 //Print header
100 if (isadmin()) {
101 print_header("$site->shortname: $strcourserestore", $site->fullname,
102 "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> ->
103 $strcourserestore -> ".basename($file));
104 } else {
105 print_header("$course->shortname: $strcourserestore", $course->fullname,
106 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
107 $strcourserestore");
109 //Print form
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
120 if (!$launch) {
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");
127 } else {
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();
145 //Print footer
146 print_footer();