$col) { if (isset($idx[$col])) error_system("column name \"$col\" appears more than once"); $idx[$col] = $i; } print_r($idx); $lichting_idx = check_and_extract($idx, 'Lichting'); $leerjaar_idx = check_and_extract($idx, 'Leerjaar'); $periode_idx = check_and_extract($idx, 'Periode'); $vak_idx = check_and_extract($idx, 'Vak afkorting'); $id_idx = check_and_extract($idx, 'Toets id'); $code_idx = check_and_extract($idx, 'Toetscode'); $longdesc_idx = check_and_extract($idx, 'Toetsomschrijving'); $htype_idx = check_and_extract($idx, 'Herkansingtype'); $no = 1; $year_id_compare = NULL; while (!feof($csv)) { $no++; if (!($row = fgetcsv($csv))) { if (feof($csv)) break; else error_system("unable to read line $no of $filename.csv"); } mdb2_exec($db, "UPDATE pto_import_files SET pto_import_scanned = pto_import_scanned + 1 WHERE pto_import_file_id = $pto_import_file_id"); print_r($row); if (!preg_match('/^(.*) (\d) (\d\d\d\d)-(\d\d\d\d)$/', $row[$lichting_idx], $matches)) error_system("unable to match value of Lichting: {$row[$lichting_idx]}"); $pto_target = $matches[1]; $pto_leerjr = $matches[2]; $year_long = $matches[3].'/'.$matches[4]; echo("year_long = $year_long\n"); if (!($year_id = mdb2_single_val($db, "SELECT year_id FROM $kldv.years WHERE year_long = '%q'", $year_long))) error_system("schooljaar $year_long undefined in database $kldv"); if (!$year_id_compare) $year_id_compare = $year_id; else if ($year_id_compare != $year_id) error_system("toetsen uit meerdere schooljaren in PTO import, kan niet"); echo("year_id=$year_id\n"); if ($pto_leerjr != $row[$leerjaar_idx]) error_system("Mismatch of leerjr between {$row[$lichting_idx]} and specified Leerjaar {$row[$leerjaar_idx]}"); if (!($subj_id = mdb2_single_val($db, "SELECT subj_id FROM $kldv.subj WHERE subj_abbrev = '%q'", $row[$vak_idx]))) error_system("subj {$row[$vak_idx]} not found in database $kldv"); echo("subj_id=$subj_id\n"); if (mdb2_exec_native_errors($db, array(1062), <<