MDL-26353 Database activity module: display help icon with the new help strings
[moodle.git] / mod / data / export_form.php
blob3bd234e87416f1e81fdb74fd38f3c6a218eca46b
1 <?php
3 if (!defined('MOODLE_INTERNAL')) {
4 die('Direct access to this script is forbidden!');
6 require_once($CFG->libdir . '/formslib.php');
7 require_once($CFG->libdir . '/csvlib.class.php');
9 class mod_data_export_form extends moodleform {
10 var $_datafields = array();
11 var $_cm;
13 // @param string $url: the url to post to
14 // @param array $datafields: objects in this database
15 function mod_data_export_form($url, $datafields, $cm) {
16 $this->_datafields = $datafields;
17 $this->_cm = $cm;
18 parent::moodleform($url);
21 function definition() {
22 global $CFG;
23 $mform =& $this->_form;
24 $mform->addElement('header', 'notice', get_string('chooseexportformat', 'data'));
25 $choices = csv_import_reader::get_delimiter_list();
26 $key = array_search(';', $choices);
27 if (! $key === FALSE) {
28 // array $choices contains the semicolon -> drop it (because its encrypted form also contains a semicolon):
29 unset($choices[$key]);
31 $typesarray = array();
32 $typesarray[] = &MoodleQuickForm::createElement('radio', 'exporttype', null, get_string('csvwithselecteddelimiter', 'data') . '&nbsp;', 'csv');
33 $typesarray[] = &MoodleQuickForm::createElement('select', 'delimiter_name', null, $choices);
34 $typesarray[] = &MoodleQuickForm::createElement('radio', 'exporttype', null, get_string('excel', 'data'), 'xls');
35 $typesarray[] = &MoodleQuickForm::createElement('radio', 'exporttype', null, get_string('ods', 'data'), 'ods');
36 $mform->addGroup($typesarray, 'exportar', '', array(''), false);
37 $mform->addRule('exportar', null, 'required');
38 $mform->setDefault('exporttype', 'csv');
39 if (array_key_exists('cfg', $choices)) {
40 $mform->setDefault('delimiter_name', 'cfg');
41 } else if (get_string('listsep', 'langconfig') == ';') {
42 $mform->setDefault('delimiter_name', 'semicolon');
43 } else {
44 $mform->setDefault('delimiter_name', 'comma');
46 $mform->addElement('header', 'notice', get_string('chooseexportfields', 'data'));
47 foreach($this->_datafields as $field) {
48 if($field->text_export_supported()) {
49 $mform->addElement('advcheckbox', 'field_'.$field->field->id, '<div title="' . s($field->field->description) . '">' . $field->field->name . '</div>', ' (' . $field->name() . ')', array('group'=>1));
50 $mform->setDefault('field_'.$field->field->id, 1);
51 } else {
52 $a = new stdClass();
53 $a->fieldtype = $field->name();
54 $mform->addElement('static', 'unsupported'.$field->field->id, $field->field->name, get_string('unsupportedexport', 'data', $a));
57 $this->add_checkbox_controller(1, null, null, 1);
58 $this->add_action_buttons(true, get_string('exportentries', 'data'));