示例#1
0
    $formdata = new stdClass();
    $formdata->d = $data->id;
    $form->set_data($formdata);
    $form->display();
    echo $OUTPUT->box_end();
    echo $OUTPUT->footer();
    die;
} else {
    // 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);
    $iid = csv_import_reader::get_new_iid('moddata');
    $cir = new csv_import_reader($iid, 'moddata');
    $readcount = $cir->load_csv_content($form->get_file_content('recordsfile'), $formdata->encoding, $formdata->fielddelimiter);
    if (empty($readcount)) {
        print_error('csvfailed', 'data', "{$CFG->wwwroot}/mod/data/edit.php?d={$data->id}");
    } else {
        if (!($fieldnames = $cir->get_columns())) {
            print_error('cannotreadtmpfile', 'error');
        }
        // check the fieldnames are valid
        $fields = $DB->get_records('data_fields', array('dataid' => $data->id), '', 'name, id, type');
        $errorfield = '';
        foreach ($fieldnames as $name) {
            if (!isset($fields[$name])) {
                $errorfield .= "'{$name}' ";
            }
        }
        if (!empty($errorfield)) {
示例#2
0
文件: import.php 项目: evltuma/moodle
    $formdata = new stdClass();
    $formdata->d = $data->id;
    $form->set_data($formdata);
    $form->display();
    echo $OUTPUT->box_end();
    echo $OUTPUT->footer();
    die;
} else {
    // 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.
    core_php_time_limit::raise();
    raise_memory_limit(MEMORY_EXTRA);
    $iid = csv_import_reader::get_new_iid('moddata');
    $cir = new csv_import_reader($iid, 'moddata');
    $filecontent = $form->get_file_content('recordsfile');
    $readcount = $cir->load_csv_content($filecontent, $formdata->encoding, $formdata->fielddelimiter);
    unset($filecontent);
    if (empty($readcount)) {
        print_error('csvfailed', 'data', "{$CFG->wwwroot}/mod/data/edit.php?d={$data->id}");
    } else {
        if (!($fieldnames = $cir->get_columns())) {
            print_error('cannotreadtmpfile', 'error');
        }
        $fieldnames = array_flip($fieldnames);
        // check the fieldnames are valid
        $rawfields = $DB->get_records('data_fields', array('dataid' => $data->id), '', 'name, id, type');
        $fields = array();
        $errorfield = '';
        foreach ($fieldnames as $name => $id) {
            if (!isset($rawfields[$name])) {