Bumping version for 1.8.10 release (note new convention for numbering)
[moodle.git] / backup / backup.php
blob994dc4402b59e37a799152cedb45269d06432d9c
1 <?php //$Id$
2 //This script is used to configure and execute the backup proccess.
4 //Define some globals for all the script
6 require_once ("../config.php");
7 require_once ("lib.php");
8 require_once ("backuplib.php");
9 require_once ("$CFG->libdir/blocklib.php");
10 require_once ("$CFG->libdir/adminlib.php");
12 $id = optional_param( 'id' ); // course id
13 $to = optional_param( 'to' ); // id of course to import into afterwards.
14 $cancel = optional_param( 'cancel' );
15 $launch = optional_param( 'launch' );
18 if (!empty($id)) {
19 require_login($id);
20 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $id))) {
21 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
23 } else {
24 require_login();
25 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
26 error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
30 if (!empty($to)) {
31 if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
32 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
36 //Check site
37 if (!$site = get_site()) {
38 error("Site not found!");
41 //Check necessary functions exists. Thanks to gregb@crowncollege.edu
42 backup_required_functions();
44 //Check backup_version
45 if ($id) {
46 $linkto = "backup.php?id=".$id.((!empty($to)) ? '&to='.$to : '');
47 } else {
48 $linkto = "backup.php";
50 upgrade_backup_db($linkto);
52 //Get strings
53 if (empty($to)) {
54 $strcoursebackup = get_string("coursebackup");
56 else {
57 $strcoursebackup = get_string('importdata');
59 $stradministration = get_string("administration");
61 //If cancel has been selected, go back to course main page (bug 2817)
62 if ($cancel) {
63 if ($id) {
64 $redirecto = $CFG->wwwroot . '/course/view.php?id=' . $id; //Course page
65 } else {
66 $redirecto = $CFG->wwwroot.'/';
68 redirect ($redirecto, get_string('backupcancelled')); //Site page
69 exit;
72 //If no course has been selected, show a list of available courses
74 if (!$id) {
75 print_header("$site->shortname: $strcoursebackup", $site->fullname,
76 "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> -> $strcoursebackup");
78 if ($courses = get_courses('all','c.shortname','c.id,c.shortname,c.fullname')) {
79 print_heading(get_string("choosecourse"));
80 print_simple_box_start("center");
81 foreach ($courses as $course) {
82 echo '<a href="backup.php?id='.$course->id.'">'.format_string($course->fullname).' ('.format_string($course->shortname).')</a><br />'."\n";
84 print_simple_box_end();
85 } else {
86 print_heading(get_string("nocoursesyet"));
87 print_continue("$CFG->wwwroot/$CFG->admin/index.php");
89 print_footer();
90 exit;
93 //Get and check course
94 if (! $course = get_record("course", "id", $id)) {
95 error("Course ID was incorrect (can't find it)");
98 //Print header
99 if (has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
100 print_header("$site->shortname: $strcoursebackup", $site->fullname,
101 "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> ->
102 <a href=\"backup.php\">$strcoursebackup</a> -> $course->fullname ($course->shortname)");
103 } else {
104 print_header("$course->shortname: $strcoursebackup", $course->fullname,
105 "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
106 $strcoursebackup");
109 //Print form
110 print_heading(format_string("$strcoursebackup: $course->fullname ($course->shortname)"));
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("192M");
117 //Call the form, depending the step we are
118 if (!$launch) {
119 // if we're at the start, clear the cache of prefs
120 if (isset($SESSION->backupprefs[$course->id])) {
121 unset($SESSION->backupprefs[$course->id]);
123 include_once("backup_form.html");
124 } else if ($launch == "check") {
125 include_once("backup_check.html");
126 } else if ($launch == "execute") {
127 include_once("backup_execute.html");
129 print_simple_box_end();
131 //Print footer
132 print_footer();