weekly release 3.10.1+
[moodle.git] / group / import_form.php
CommitLineData
aa6c1ced 1<?php
4d8e2417
AG
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * A form for group import.
19 *
20 * @package core_group
21 * @copyright 2010 Toyomoyo (http://moodle.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
447ca67d 24
bfebaf64
MD
25if (!defined('MOODLE_INTERNAL')) {
26 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
27}
28
447ca67d 29require_once($CFG->libdir.'/formslib.php');
776b4a85 30require_once($CFG->libdir . '/csvlib.class.php');
447ca67d 31
4d8e2417
AG
32/**
33 * Groups import form class
34 *
35 * @package core_group
36 * @copyright 2010 Toyomoyo (http://moodle.com)
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 */
81ed4632 39class groups_import_form extends moodleform {
447ca67d 40
4d8e2417
AG
41 /**
42 * Form definition
43 */
e73457e4 44 function definition() {
9bed73fa 45 $mform =& $this->_form;
81ed4632 46 $data = $this->_customdata;
1d284fbd 47
9bed73fa 48 //fill in the data depending on page params
e73457e4 49 //later using set_data
5995717e 50 $mform->addElement('header', 'general', get_string('general'));
1d284fbd 51
9bed73fa
DC
52 $filepickeroptions = array();
53 $filepickeroptions['filetypes'] = '*';
81ed4632 54 $filepickeroptions['maxbytes'] = get_max_upload_file_size();
9bed73fa 55 $mform->addElement('filepicker', 'userfile', get_string('import'), null, $filepickeroptions);
1d284fbd 56
81ed4632 57 $mform->addElement('hidden', 'id');
35626ff4 58 $mform->setType('id', PARAM_INT);
81ed4632 59
776b4a85
SL
60 $choices = csv_import_reader::get_delimiter_list();
61 $mform->addElement('select', 'delimiter_name', get_string('csvdelimiter', 'group'), $choices);
62 if (array_key_exists('cfg', $choices)) {
63 $mform->setDefault('delimiter_name', 'cfg');
64 } else if (get_string('listsep', 'langconfig') == ';') {
65 $mform->setDefault('delimiter_name', 'semicolon');
66 } else {
67 $mform->setDefault('delimiter_name', 'comma');
68 }
69
70 $choices = core_text::get_encodings();
71 $mform->addElement('select', 'encoding', get_string('encoding', 'group'), $choices);
72 $mform->setDefault('encoding', 'UTF-8');
b74ceb3f 73 $this->add_action_buttons(true, get_string('importgroups', 'core_group'));
81ed4632
PS
74
75 $this->set_data($data);
e73457e4 76 }
447ca67d 77}
aa6c1ced 78