3 if (!defined('MOODLE_INTERNAL')) {
4 die('Direct access to this script is forbidden!');
6 require_once($CFG->libdir
. '/formslib.php');
8 class mod_data_export_form
extends moodleform
{
9 var $_datafields = array();
10 // @param string $url: the url to post to
11 // @param array $datafields: objects in this database
12 function mod_data_export_form($url, $datafields) {
13 $this->_datafields
= $datafields;
14 parent
::moodleform($url);
17 function definition() {
18 $mform =& $this->_form
;
19 $mform->addElement('header', 'notice', get_string('chooseexportformat', 'data'));
20 $choices = csv_import_reader
::get_delimiter_list();
21 $key = array_search(';', $choices);
22 if (! $key === FALSE) {
23 // array $choices contains the semicolon -> drop it (because its encrypted form also contains a semicolon):
24 unset($choices[$key]);
26 $typesarray = array();
27 $typesarray[] = &MoodleQuickForm
::createElement('radio', 'exporttype', null, get_string('csvwithselecteddelimiter', 'data') . ' ', 'csv');
28 $typesarray[] = &MoodleQuickForm
::createElement('select', 'delimiter_name', null, $choices);
29 $typesarray[] = &MoodleQuickForm
::createElement('radio', 'exporttype', null, get_string('excel', 'data'), 'xls');
30 $typesarray[] = &MoodleQuickForm
::createElement('radio', 'exporttype', null, get_string('ods', 'data'), 'ods');
31 $mform->addGroup($typesarray, 'exportar', '', array(''), false);
32 $mform->addRule('exportar', null, 'required');
33 $mform->setDefault('exporttype', 'csv');
34 if (array_key_exists('cfg', $choices)) {
35 $mform->setDefault('delimiter_name', 'cfg');
36 } else if (get_string('listsep') == ';') {
37 $mform->setDefault('delimiter_name', 'semicolon');
39 $mform->setDefault('delimiter_name', 'comma');
41 $mform->addElement('header', 'notice', get_string('chooseexportfields', 'data'));
42 foreach($this->_datafields
as $field) {
43 if($field->text_export_supported()) {
44 $mform->addElement('advcheckbox', 'field_'.$field->field
->id
, '<div title="' . s($field->field
->description
) . '">' . $field->field
->name
. '</div>', ' (' . $field->name() . ')', array('group'=>1));
45 $mform->setDefault('field_'.$field->field
->id
, 1);
48 $a->fieldtype
= $field->name();
49 $mform->addElement('static', 'unsupported'.$field->field
->id
, $field->field
->name
, get_string('unsupportedexport', 'data', $a));
52 $this->add_checkbox_controller(1, null, null, 1);
53 $this->add_action_buttons(true, get_string('exportdatabaserecords', 'data'));