$value) { if (preg_match('/weging-(per1|per2|per3)-(\d+)-(\d+)/', $key, $matches)) { if (!isset($per_translate[$matches[1]])) error_system("period {$matches[1]} is unknown"); if (!isset($subjs[$matches[3]])) error_system("subj {$matches[3]} is unknown"); if (!isset($toetsen[$matches[2]])) { $toetsen[$matches[2]] = mdb2_single_assoc($db, "SELECT * FROM toets WHERE toets_id = %i", $matches[2]); if (!is_array($toetsen[$matches[2]])) error_system("toets {$matches[2]} is unknown"); if ($toetsen[$matches[2]]['year_id'] != $year_id) error_system("toets {$matches[2]} komt uit het verkeerde jaar"); } $link = mdb2_single_val($db, "SELECT toets2subj_id FROM toets2subj WHERE toets_id = %i AND subj_id = %i", $matches[2], $matches[3]); if (!$link) error_system("toets {$matches[2]} is niet gekoppeld aan subj {$matches[3]}"); if (strlen($value) > 24) error_system("wegingsfactor langer dan 24 tekens"); $work[] = array ( 'type' => 'weging', 'toets_id' => $matches[2], 'period_id' => $per_translate[$matches[1]], 'subj_id' => $matches[3], 'weging' => $value ); } else if (preg_match('/stofoms-(\d+)-(\d+)/', $key, $matches)) { if (!isset($subjs[$matches[2]])) error_system("subj {$matches[3]} is unknown"); if (!isset($toetsen[$matches[1]])) { $toetsen[$matches[1]] = mdb2_single_assoc($db, "SELECT * FROM toets WHERE toets_id = %i", $matches[1]); if (!is_array($toetsen[$matches[1]])) error_system("toets {$matches[1]} is unknown"); if ($toetsen[$matches[1]]['year_id'] != $year_id) error_system("toets {$matches[1]} komt uit het verkeerde jaar"); } $link = mdb2_single_val($db, "SELECT toets2subj_id FROM toets2subj WHERE toets_id = %i AND subj_id = %i", $matches[1], $matches[2]); if (!$link) error_system("toets {$matches[1]} is niet gekoppeld aan subj {$matches[2]}"); $work[] = array ( 'type' => 'stof', 'toets_id' => $matches[1], 'subj_id' => $matches[2], 'text' => $value ); } } //print_r($work); $count = 0; $affected = 0; $error_gemachtigd = 0; $error_geaccordeerd = 0; foreach ($work as $info) { if (!isset($gemachtigd[$info['subj_id']])) { $error_gemachtigd++; continue; } if (!isset($geaccordeerd[$info['subj_id']])) { $error_geaccordeerd++; continue; } $count++; //echo("inserting"); print_r($info); if ($info['type'] == 'weging') $affected += (mdb2_exec($db, "INSERT INTO rweging ( period_id, subj_id, toets_id, rweging_factor ) VALUES ( %i, %i, %i, '%q' ) ON DUPLICATE KEY UPDATE rweging_factor = '%q'", $info['period_id'], $info['subj_id'], $info['toets_id'], $info['weging'], $info['weging']) > 0); else if ($info['type'] == 'stof') $affected += (mdb2_exec($db, "INSERT INTO rstof ( subj_id, toets_id, text ) VALUES ( %i, %i, '%q' ) ON DUPLICATE KEY UPDATE text = '%q'", $info['subj_id'], $info['toets_id'], $info['text'], $info['text']) > 0); } $diff = $count - $affected; if ($affected) notice_user("Succes", "$affected item(s) opgeslagen, $diff item(s) ongewijzigd, $error_gemachtigd konden niet worden opgeslagen omdat u niet gemachtigd bent en $error_geaccordeerd konden niet worden opgeslagen omdat het betreffende vak al was geaccordeeerd", 'wegingen.php'); header("Location: wegingen.php");