MDL-22388 Added some checks to kill these scripts dead with an unequivocal notice...
[moodle.git] / admin / dbtransfer / database_transfer_form.php
1 <?php
3 if (!defined('MOODLE_INTERNAL')) {
4     die('Direct access to this script is forbidden.');    ///  It must be included from a Moodle page
5 }
7 require_once $CFG->libdir.'/formslib.php';
9 class database_transfer_form extends moodleform {
11     function definition() {
12         $mform = $this->_form;
14         $mform->addElement('header', 'database', get_string('dbtransfer', 'dbtransfer'));
16         $supported = array (
17             'mysqli/native',
18             'pgsql/native',
19             'mssql/native',
20             'oci/native',
21             'sqlite3/pdo',
22         );
23         $drivers = array();
24         foreach($supported as $driver) {
25             list($dbtype, $dblibrary) = explode('/', $driver);
26             $targetdb = moodle_database::get_driver_instance($dbtype, $dblibrary);
27             if ($targetdb->driver_installed() !== true) {
28                 continue;
29             }
30             $drivers[$driver] = $driver;
31         }
33         $mform->addElement('select', 'driver', get_string('dbtype', 'install'), $drivers);
34         $mform->addElement('text', 'dbhost', get_string('dbhost', 'install'));
35         $mform->addElement('text', 'dbname', get_string('database', 'install'));
36         $mform->addElement('text', 'dbuser', get_string('user'));
37         $mform->addElement('text', 'dbpass', get_string('password'));
38         $mform->addElement('text', 'prefix', get_string('dbprefix', 'install'));
40         $mform->addRule('dbhost', get_string('required'), 'required', null);
41         $mform->addRule('dbname', get_string('required'), 'required', null);
42         $mform->addRule('dbuser', get_string('required'), 'required', null);
43         $mform->addRule('dbpass', get_string('required'), 'required', null);
44         $mform->addRule('prefix', get_string('required'), 'required', null);
46         $this->add_action_buttons(false, get_string('transferdata', 'dbtransfer'));
47     }
48 }