1 |
efrain |
1 |
<?php
|
|
|
2 |
if (!defined('MOODLE_INTERNAL')) {
|
|
|
3 |
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
|
|
4 |
}
|
|
|
5 |
|
|
|
6 |
require_once($CFG->libdir.'/formslib.php');
|
|
|
7 |
require_once($CFG->libdir.'/csvlib.class.php');
|
|
|
8 |
|
|
|
9 |
class mod_data_import_form extends moodleform {
|
|
|
10 |
|
|
|
11 |
function definition() {
|
|
|
12 |
$mform =& $this->_form;
|
|
|
13 |
|
|
|
14 |
$dataid = $this->_customdata['dataid'];
|
|
|
15 |
$backtourl = $this->_customdata['backtourl'];
|
|
|
16 |
|
|
|
17 |
$mform->addElement('filepicker', 'recordsfile', get_string('csvfile', 'data'),
|
|
|
18 |
null, ['accepted_types' => ['application/zip', 'text/csv']]);
|
|
|
19 |
|
|
|
20 |
$delimiters = csv_import_reader::get_delimiter_list();
|
|
|
21 |
$mform->addElement('select', 'fielddelimiter', get_string('fielddelimiter', 'data'), $delimiters);
|
|
|
22 |
$mform->setDefault('fielddelimiter', 'comma');
|
|
|
23 |
|
|
|
24 |
$mform->addElement('text', 'fieldenclosure', get_string('fieldenclosure', 'data'));
|
|
|
25 |
$mform->setType('fieldenclosure', PARAM_CLEANHTML);
|
|
|
26 |
|
|
|
27 |
$choices = core_text::get_encodings();
|
|
|
28 |
$mform->addElement('select', 'encoding', get_string('fileencoding', 'mod_data'), $choices);
|
|
|
29 |
$mform->setDefault('encoding', 'UTF-8');
|
|
|
30 |
|
|
|
31 |
// Database activity ID.
|
|
|
32 |
$mform->addElement('hidden', 'd');
|
|
|
33 |
$mform->setType('d', PARAM_INT);
|
|
|
34 |
$mform->setDefault('d', $dataid);
|
|
|
35 |
|
|
|
36 |
// Back to URL.
|
|
|
37 |
$mform->addElement('hidden', 'backto');
|
|
|
38 |
$mform->setType('backto', PARAM_LOCALURL);
|
|
|
39 |
$mform->setDefault('backto', $backtourl);
|
|
|
40 |
|
|
|
41 |
$this->add_action_buttons(true, get_string('submit'));
|
|
|
42 |
}
|
|
|
43 |
}
|