Merge branch 'wip-MDL-35056-stable23' of git://github.com/phalacee/moodle into MOODLE...
[moodle.git] / backup / backup.php
CommitLineData
795b6945 1<?php
3920667e 2
1904e9b3
SH
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18require_once('../config.php');
19require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
20require_once($CFG->dirroot . '/backup/moodle2/backup_plan_builder.class.php');
21
22
23$courseid = required_param('id', PARAM_INT);
24$sectionid = optional_param('section', null, PARAM_INT);
25$cmid = optional_param('cm', null, PARAM_INT);
8c6d7f34
SH
26/**
27 * Part of the forms in stages after initial, is POST never GET
28 */
29$backupid = optional_param('backup', false, PARAM_ALPHANUM);
1904e9b3
SH
30
31$url = new moodle_url('/backup/backup.php', array('id'=>$courseid));
32if ($sectionid !== null) {
33 $url->param('section', $sectionid);
34}
35if ($cmid !== null) {
36 $url->param('cm', $cmid);
37}
38$PAGE->set_url($url);
4886029c 39$PAGE->set_pagelayout('admin');
1904e9b3
SH
40
41$id = $courseid;
42$cm = null;
43$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
44$type = backup::TYPE_1COURSE;
45if (!is_null($sectionid)) {
105f805c 46 $section = $DB->get_record('course_sections', array('course'=>$course->id, 'id'=>$sectionid), '*', MUST_EXIST);
1904e9b3
SH
47 $type = backup::TYPE_1SECTION;
48 $id = $sectionid;
49}
50if (!is_null($cmid)) {
a2190f5c 51 $cm = get_coursemodule_from_id(null, $cmid, $course->id, false, MUST_EXIST);
1904e9b3
SH
52 $type = backup::TYPE_1ACTIVITY;
53 $id = $cmid;
54}
55require_login($course, false, $cm);
56
9c27e9ab
SH
57switch ($type) {
58 case backup::TYPE_1COURSE :
59 require_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_COURSE, $course->id));
105f805c 60 $heading = get_string('backupcourse', 'backup', $course->shortname);
9c27e9ab
SH
61 break;
62 case backup::TYPE_1SECTION :
71e0b3b5
SH
63 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
64 require_capability('moodle/backup:backupsection', $coursecontext);
ff5d6f88 65 if ((string)$section->name !== '') {
71e0b3b5
SH
66 $sectionname = format_string($section->name, true, array('context' => $coursecontext));
67 $heading = get_string('backupsection', 'backup', $sectionname);
68 $PAGE->navbar->add($sectionname);
105f805c
SH
69 } else {
70 $heading = get_string('backupsection', 'backup', $section->section);
71 $PAGE->navbar->add(get_string('section').' '.$section->section);
72 }
9c27e9ab
SH
73 break;
74 case backup::TYPE_1ACTIVITY :
75 require_capability('moodle/backup:backupactivity', get_context_instance(CONTEXT_MODULE, $cm->id));
105f805c 76 $heading = get_string('backupactivity', 'backup', $cm->name);
9c27e9ab
SH
77 break;
78 default :
79 print_error('unknownbackuptype');
1904e9b3
SH
80}
81
8c6d7f34 82if (!($bc = backup_ui::load_controller($backupid))) {
1904e9b3
SH
83 $bc = new backup_controller($type, $id, backup::FORMAT_MOODLE,
84 backup::INTERACTIVE_YES, backup::MODE_GENERAL, $USER->id);
85}
86$backup = new backup_ui($bc);
87$backup->process();
88if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
89 $backup->execute();
90} else {
91 $backup->save_controller();
92}
93
105f805c
SH
94$PAGE->set_title($heading.': '.$backup->get_stage_name());
95$PAGE->set_heading($heading);
105f805c 96$PAGE->navbar->add($backup->get_stage_name());
1904e9b3
SH
97
98$renderer = $PAGE->get_renderer('core','backup');
99echo $OUTPUT->header();
100if ($backup->enforce_changed_dependencies()) {
d4f5439d 101 debugging('Your settings have been altered due to unmet dependencies', DEBUG_DEVELOPER);
1904e9b3
SH
102}
103echo $renderer->progress_bar($backup->get_progress_bar());
748e9651 104echo $backup->display($renderer);
44bb101d
SH
105$backup->destroy();
106unset($backup);
1904e9b3 107echo $OUTPUT->footer();