#!/usr/bin/php $l1) { if ($legenda1[$idx] == 'Gemeenschappelijk' && $vak == 'niks') $vak = 'gem'; else if ($legenda1[$idx] == 'Profielvak' && $vak == 'gem') $vak = 'profielvak'; else if ($legenda1[$idx] == 'Keuzevak' && $vak == 'profielvak') $vak = 'keuzevak'; // een leerling heeft in dit jaar een 'Beroepsgericht vak' else if ($year == '2014/2015' && $legenda1[$idx] == 'Beroepsgericht vak' && $vak == 'keuzevak') $vak = 'keuzevak'; else if ($legenda1[$idx] == 'Aantal vakken' && $vak == 'keuzevak') $vak = 'aantallen'; $v = $legenda2[$idx]; // $v is alleen een vak als $vak = gem, profielvak of keuze // sommige vakken negeren we (zie verantwoording in index.php) if ($v == 'Comb VWO') continue; if ($v == 'Comb HAVO') continue; if ($v == 'RT3F') continue; if ($v == 're') continue; if ($v == 'rkt') continue; if ($v == 'kcv') continue; if ($v == 'kualg') continue; if ($v == 'netl') continue; if ($v == 'lo') continue; if ($v == 'maat') continue; if ($v == 'ckv') continue; if ($v == 'anw') continue; if ($vak == 'gem') $gemvakken[$v] = $idx; else if ($vak == 'profielvak') $profielvakken[$v] = $idx; else if ($vak == 'keuzevak') $keuzevakken[$v] = $idx; } if ($vak != 'aantallen') die("onverwachte structuur in input, stuck at: $vak\n"); print_r($gemvakken); print_r($profielvakken); print_r($keuzevakken); while (($row = fgetcsv($fp))) { $vakken = array(); $vakken_simple = array(); $ll = $row[$leerlingnummer]; $jaar = $row[$jaaropl]; if (!preg_match('/^(\w+)-(\w+)$/', $row[$opleiding], $somprofiel)) die("ongeldig format in kolom opl {$row[$opleiding]}\n"); switch ($somprofiel[1]) { case 'HAVO': $short = 'H'; break; case 'ATH': $short = 'A'; break; case 'GYM': $short = 'G'; break; default: die("impossible value for opl;"); } if ($short == 'H') $exjr = $exjr_exklas - $jaar + 5; else if ($short == 'A' || $short == 'G') $exjr = $exjr_exklas - $jaar + 6; else die("impossible\n"); echo('ll='.$ll."\n"); echo("jaar=$jaar\n"); echo("exjr_exklas=$exjr_exklas\n"); echo("exjr=$exjr\n"); echo("opl=".$short."\n"); $exjr_id = db_get_id("exjr_id", "exjr", "exjr", $exjr); echo($somprofiel[2]."\n"); $somprofiel_id = db_get_id("somprofiel_id", "somprofielen", "somprofiel", $somprofiel[2]); if ($jaar != 4 && $jaar != 5 && !(($short == 'A' || $short == 'G') && $jaar == 6)) die("ongeldige data\n"); //echo("somprofiel_id=$somprofiel_id\n"); foreach ($gemvakken as $vak => $idx) { if ($vak == 'gtc') $vak = 'grkc'; if ($vak == 'ltc') $vak = 'lakc'; if ($row[$idx] == 'x') { $vakken[] = 'G-'.$vak; $vakken_simple[] = $vak; } } foreach ($profielvakken as $vak => $idx) { if ($vak == 'gtc') $vak = 'grkc'; if ($vak == 'ltc') $vak = 'lakc'; if ($row[$idx] == 'x') { $vakken[] = 'P-'.$vak; $vakken_simple[] = $vak; } } foreach ($keuzevakken as $vak => $idx) { if ($vak == 'gtc') $vak = 'grkc'; if ($vak == 'ltc') $vak = 'lakc'; if ($row[$idx] == 'x') { $vakken[] = 'K-'.$vak; $vakken_simple[] = $vak; } } // heeft de leerling cen? (cen komt alleen voor als keuzevak) if (($key = array_search('K-cen', $vakken)) !== FALSE) { unset($vakken[$key]); //verwijder K-cen // dan heeft de leerling cen als vervanging voor entl en dus // geen G-entl, maar G-cen (en geen K-cen) if (($key = array_search('G-entl', $vakken)) === FALSE) die("impossible\n"); unset($vakken[$key]); if (($key = array_search('entl', $vakken_simple)) === FALSE) die("impossible\n"); unset($vakken_simple[$key]); // voeg G-cen toe $vakken[] = 'G-cen'; } // heeft de leerling K-grkc (gtl) en ook G-grkc (gtc), // dan schrappen we het keuzevak if (($key = array_search('K-grkc', $vakken)) !== FALSE && array_search('G-grkc', $vakken) !== FALSE) { unset($vakken[$key]); } // heeft de leerling K-lakc (ltc) en ook G-lakc (ltc), // dan schrappen we het keuzevak if (($key = array_search('K-lakc', $vakken)) !== FALSE && array_search('G-lakc', $vakken) !== FALSE) { unset($vakken[$key]); } $pv = array(); $gv = array(); $kv = array(); foreach ($vakken as $idx => $vak) { if (!preg_match('/^(\w)-(\w+)$/', $vak, $matches)) die("impossible\n"); if ($matches[1] == 'G') { $gv[] = $matches[2]; } else if ($matches[1] == 'P') { $pv[] = $matches[2]; } else if ($matches[1] == 'K') { if (array_search('P-'.$matches[2], $vakken)) { echo("dubbel vak gevonden {$matches[2]} {$somprofiel[2]}\n"); unset($vakken[$idx]); } else { $kv[] = $matches[2]; } } } // deze leerling heeft te weinig vakken if (count($pv) == 4 && count($kv) == 0) continue; // sorteer vakken, om pakketten te kunnen vergelijken natcasesort($vakken); natcasesort($gv); natcasesort($pv); natcasesort($kv); // haal dubbelingen uit vakken zonder GPK prefix $vakken_simple_ordered = array_unique($vakken_simple); natcasesort($vakken_simple_ordered); $pakket_simple = implode(',', $vakken_simple_ordered); $pakket = 'G-'.implode('-', $gv).',P-'.implode('-', $pv).((count($kv) > 0)?',K-'.implode('-', $kv):''); //$pakket = implode(',', $vakken); //echo($pakket."\n"); //echo($pakket_simple."\n"); //$llsjn_id = get_llsjn_id($row[0], $sj, $n); //echo($row[0].' '.$sj.' '.$n.' ('.$llsjn_id.')'."\n"); $pakket_simple_id = db_get_id('pakket_simple_id', 'pakket_simple', 'pakket_simple', $pakket_simple); $pakket_id = db_get_id('pakket_id', 'pakketten', 'pakket', $pakket, 'pakket_simple_id', $pakket_simple_id); $lj_id = db_get_id('lj_id', 'lj', 'lj', $jaar); $opl_id = db_get_id('opl_id', 'opl', 'opl', $short); $llsjnpp_id = db_get_id('llsjnpp_id', 'llsjnpp', 'll', $ll, 'year_id', $year_id, 'somprofiel_id', $somprofiel_id, 'pakket_id', $pakket_id, 'lj_id', $lj_id, 'opl_id', $opl_id, 'exjr_id', $exjr_id); $count = db_single_field("SELECT COUNT(*) FROM pakket2subj WHERE pakket_id = ?", $pakket_id); if ($count) continue; // pakket niet gevonden foreach ($vakken as $vak_and_type) { $info = explode('-', $vak_and_type); //print_r($info); $subj_id = db_get_id('subj_id', $kldv.'.subj', 'subj_abbrev', $info[1]); db_exec("INSERT INTO pakket2subj ( pakket_id, subj_id, type ) VALUES ( ?, ?, ? )", $pakket_id, $subj_id, $info[0]); } //break; } fclose($fp); ?>