Пример #1
0
$PAGE->navbar->add('CSV');
echo $OUTPUT->header();
if (!has_capability('local/reservasalas:upload', $context)) {
    print_error(get_string('INVALID_ACCESS', 'Reserva_Sala'));
}
if (isset($CFG->local_uai_debug) && $CFG->local_uai_debug == 0) {
    print_error(get_string('INVALID_ACCESS', 'Reserva_Sala'));
}
$mform = new import_form(null, array('includeseparator' => true, 'verbosescales' => true));
/*echo html_writer::start_tag('div', array('class' => 'clearer'));
echo html_writer::end_tag('div');
$mform->display();
*/
if (!$iid) {
    // If the import form has been submitted.
    if ($mform->is_cancelled()) {
        redirect($url);
    } else {
        if ($formdata = $mform->get_data()) {
            // Large files are likely to take their time and memory. Let PHP know
            // that we'll take longer, and that the process should be recycled soon
            // to free up memory.
            @set_time_limit(0);
            raise_memory_limit(MEMORY_EXTRA);
            $text = $mform->get_file_content('userfile');
            $iid = csv_import_reader::get_new_iid('rooms');
            $csvimport = new csv_import_reader($iid, 'rooms');
            $csvimport->load_csv_content($text, $formdata->encoding, $separator);
            // --- get header (field names) ---
            $header = $csvimport->get_columns();
            // Print a preview of the data.