3 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
19 * This file contains the generic moodleform bridge for the backup user interface
20 * as well as the individual forms that relate to the different stages the user
21 * interface can exist within.
24 * @copyright 2010 Sam Hemelryk
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') || die();
31 * Backup moodleform bridge
33 * Ahhh the mighty moodleform bridge! Strong enough to take the weight of 682 full
34 * grown african swallows all of whom have been carring coconuts for several days.
35 * EWWWWW!!!!!!!!!!!!!!!!!!!!!!!!
37 * @copyright 2010 Sam Hemelryk
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 abstract class backup_moodleform extends base_moodleform {
44 * @param backup_ui_stage $uistage
45 * @param moodle_url|string $action
46 * @param mixed $customdata
47 * @param string $method get|post
48 * @param string $target
49 * @param array $attributes
50 * @param bool $editable
52 public function __construct(backup_ui_stage $uistage, $action = null, $customdata = null, $method = 'post', $target = '', $attributes = null, $editable = true) {
53 parent::__construct($uistage, $action, $customdata, $method, $target, $attributes, $editable);
57 * Initial backup user interface stage moodleform.
59 class backup_initial_form extends backup_moodleform {
62 * We override the initial form to offer a one click backup option.
64 public function definition() {
65 $mform = $this->_form;
67 $mform->addElement('header', 'backupheading', get_string('backup'));
68 $mform->addElement('html', html_writer::tag('p', get_string('performoneclickbackup_desc', 'backup')));
69 $mform->addElement('submit', 'oneclickbackup', get_string('performoneclickbackup', 'backup'));
73 $mform->setDisableShortforms(false);
77 * Schema backup user interface stage moodleform.
79 * Nothing to override we only need it defined so that moodleform doesn't get confused
82 class backup_schema_form extends backup_moodleform {}
84 * Confirmation backup user interface stage moodleform.
86 * Nothing to override we only need it defined so that moodleform doesn't get confused
89 class backup_confirmation_form extends backup_moodleform {
91 public function definition_after_data() {
92 parent::definition_after_data();
93 $this->_form->addRule('setting_root_filename', get_string('errorfilenamerequired', 'backup'), 'required');
94 $this->_form->setType('setting_root_filename', PARAM_FILE);
97 public function validation($data, $files) {
98 $errors = parent::validation($data, $files);
100 if (!array_key_exists('setting_root_filename', $errors)) {
101 if (trim($data['setting_root_filename']) == '') {
102 $errors['setting_root_filename'] = get_string('errorfilenamerequired', 'backup');
103 } else if (!preg_match('#\.mbz$#i', $data['setting_root_filename'])) {
104 $errors['setting_root_filename'] = get_string('errorfilenamemustbezip', 'backup');