'); } return $herinfo; } class regime { public $short; public $rules; public $getpossibilities; public $checkvalid; } $regimes = array( new regime(), new regime(), new regime(), new regime(), new regime(), new regime(), new regime(), new regime(), new regime() ); function get_buiten_beschouwing($db, $period_id) { global $kldv; return mdb2_all_assoc_rekey($db, <<fetchRow(MDB2_FETCHMODE_ASSOC))) { // if (!isset($ret[$row['group']])) $ret[$row['group']] = array(); // $ret[$row['group']][] = $row['toets']; // } // // return $ret; //} */ // maak een lijst van alle toetsen van dit schooljaar, met de groeperingen van deze periode, // zonder de buiten beschouwing gelaten toetsen function get_toetsnames_index($db, $period_id) { global $kldv; return mdb2_all_assoc_rekey($db, <<fetchRow(MDB2_FETCHMODE_ASSOC))) { if (!isset($ret[$row['group']])) $ret[$row['group']] = array(); $ret[$row['group']][] = $row['toets']; } return $ret; } function get_stamklas($db, $ppl_id, $herinfo) { global $kldv; $stamklas = mdb2_single_val($db, << {$herinfo['period_deadline']} EOQ ); if (!$stamklas) fatal_error("leerling $ppl_id heeft geen stamklas?!?!?"); return $stamklas; } function get_exception($db, $ppl_id, $herinfo) { return mdb2_single_val($db, <<$no. Examenlln mogen ST's kiezen uit TP1 en TP2, overige lln mogen alleen ST's kiezen uit TP2."; } function regime3_getpossibilities($db, $ppl_id, $herinfo, $include = 0) { global $kldv, $concat_begin, $concat_cont, $concat_end, $as_varchar; $results = array(); $stamklas = get_stamklas($db, $ppl_id, $herinfo); $exception = get_exception($db, $ppl_id, $herinfo); $jaar = substr($stamklas, 0, 1); $schooltype = substr($stamklas, 1, 1); $pta_period = ($jaar - 4)*3 + $herinfo['period_num']; $pta_period_minus_one = $pta_period - 1; $no = 1; $examenklas = 0; if (($schooltype == 'V' && $jaar == 6) || ($schooltype == 'H' && $jaar == 5)) $examenklas = 1; if ($examenklas) $no += 2; else $no += 1; $no += $exception; $total_weight = mdb2_single_val($db, "SELECT SUM(weight) FROM rex WHERE ppl_id = $ppl_id AND period_id = {$herinfo['period_id']}"); $al_herkanst = mdb2_col($db, 0, <<'); print_r($al_herkanst); echo('');*/ //echo("here! total_weight=$total_weight, no=$no\n"); # als de leerling het maximale aantal herkansingen heeft -> bail out if ($total_weight >= $no && (!in_array($include, $al_herkanst) || !$include)) return array(); //echo("here!\n"); if ($herinfo['period_num'] != 2) fatal_error("impossibru!"); if (!$_SESSION['admin']) { //$restrict = ' AND ( stdher = 1 OR ( stvt = \'VT\' AND stdher = 0 AND inhaalregime = 0 ) )'; $restrict = ' AND ( stdher = 1 )'; if ($examenklas && true) $restrict2 = " AND ( ptas.pta_period = $pta_period OR ptas.pta_period = $pta_period_minus_one ) -- %i"; else $restrict2 = ' AND ptas.pta_period = %i'; } else { $restrict = ''; $restrict2 = ' -- %i'; } $herkansbaar = mdb2_query($db, << {$herinfo['period_deadline']} AND ppl_id = $ppl_id ORDER BY pta_abbrev EOQ , $pta_period, $schooltype); //mdb2_res_table($herkansbaar); while (($row = $herkansbaar->fetchrow(MDB2_FETCHMODE_ASSOC))) { //print_r($row); if (!in_array($row['pta_id'], $al_herkanst) || $row['pta_id'] == $include) { $results[] = $row; } } return $results; } function regime3_checkvalid($db, $ppl_id, $herinfo, $pta_id) { $toegestaan = regime3_getpossibilities($db, $ppl_id, $herinfo, $pta_id); $stamklas = get_stamklas($db, $ppl_id, $herinfo); $exception = get_exception($db, $ppl_id, $herinfo); $schooltype = substr($stamklas, 1, 1); $jaar = substr($stamklas, 0, 1); $ok = 0; foreach ($toegestaan as $check) { if ($pta_id == $check['pta_id']) { $ok = 1; break; } } if (!$ok) { //echo("NIET IN TOEGESTANE LIJST?"); //exit; return false; } // count rex's by weight, so that we // can introduce free rexes /*SELECT COUNT(*) FROM rex WHERE ppl_id = $ppl_id AND period_id = {$herinfo['period_id']}*/ $total = mdb2_single_val($db, << $no) { //echo("total $total > $no, WTF!"); //exit; return false; } return true; //return false; } function regime0_rules($db, $ppl_id, $herinfo) { $exception = get_exception($db, $ppl_id, $herinfo); $stamklas = get_stamklas($db, $ppl_id, $herinfo); $jaar = substr($stamklas, 0, 1); $schooltype = substr($stamklas, 1, 1); if (($jaar == 5 && $schooltype == 'H') || ($jaar == 6 && $schooltype == 'V')) $no = 2; else $no = 1; //if ($exception) $no++; $no += $exception; return "Het aantal herkansingen dat je mag opgeven is $no. Je mag alleen toetsen herkansen uit TP{$herinfo['period_num']}."; } function regime4_rules($db, $ppl_id, $herinfo) { $stamklas = get_stamklas($db, $ppl_id, $herinfo); $jaar = substr($stamklas, 0, 1); $schooltype = substr($stamklas, 1, 1); if ($herinfo['period_num'] != 1) fatal_error("impossibru!"); $exception = get_exception($db, $ppl_id, $herinfo); $no = 2 + $exception; if (($jaar == 5 && $schooltype == 'H') || ($jaar == 6 && $schooltype == 'V')) $no++; return "Het aantal herkansingen dat je mag opgeven is $no. Je mag kiezen uit de herkansbare ST's en VT's uit TP0/TP3* en TP1."; } function regime4_getpossibilities($db, $ppl_id, $herinfo, $include = 0) { global $kldv, $concat_begin, $concat_cont, $concat_end, $as_varchar; if ($herinfo['period_num'] != 1) fatal_error("impossibru!"); $results = array(); $stamklas = get_stamklas($db, $ppl_id, $herinfo); $jaar = substr($stamklas, 0, 1); $schooltype = substr($stamklas, 1, 1); $exception = get_exception($db, $ppl_id, $herinfo); $no = 2 + $exception; if (($jaar == 5 && $schooltype == 'H') || ($jaar == 6 && $schooltype == 'V')) $no++; $pta_period = ($jaar - 4)*3 + $herinfo['period_num']; $total_weight = mdb2_single_val($db, "SELECT SUM(weight) FROM rex WHERE ppl_id = $ppl_id AND period_id = {$herinfo['period_id']}"); $al_herkanst = mdb2_col($db, 0, << bail out if ($total_weight >= $no && (!in_array($include, $al_herkanst) || !$include)) return array(); if (!$_SESSION['admin']) { $restrict = ' AND stdher = 1'; $restrict2 = ' AND ( ptas.pta_period = %i OR ptas.pta_period + 1 = %i )'; } else { $restrict = ''; $restrict2 = '-- %i %i'; } $herkansbaar = mdb2_query($db, << {$herinfo['period_deadline']} AND ppl_id = $ppl_id ORDER BY pta_abbrev EOQ , $pta_period, $pta_period, $pta_period, $pta_period, $schooltype); while (($row = $herkansbaar->fetchrow(MDB2_FETCHMODE_ASSOC))) { //print_r($row); if (!in_array($row['pta_id'], $al_herkanst) || $row['pta_id'] == $include) { $results[] = $row; } } return $results; } function regime0_getpossibilities($db, $ppl_id, $herinfo, $include = 0) { global $kldv, $concat_begin, $concat_cont, $concat_end, $as_varchar; $results = array(); $stamklas = get_stamklas($db, $ppl_id, $herinfo); $exception = get_exception($db, $ppl_id, $herinfo); $jaar = substr($stamklas, 0, 1); $schooltype = substr($stamklas, 1, 1); $pta_period = ($jaar - 4)*3 + $herinfo['period_num']; $no = 1; //if ($exception) $no++; $no += $exception; if ($schooltype == 'V' && $jaar == 6) $no++; else if ($schooltype == 'H' && $jaar == 5) $no++; $total_weight = mdb2_single_val($db, "SELECT SUM(weight) FROM rex WHERE ppl_id = $ppl_id AND period_id = {$herinfo['period_id']}"); $al_herkanst = mdb2_col($db, 0, <<'); //print_r($al_herkanst); //echo(''); # als de leerling het maximale aantal herkansingen heeft -> bail out if ($total_weight >= $no && (!in_array($include, $al_herkanst) || !$include)) return array(); if (!$_SESSION['admin']) { $restrict = ' AND stdher = 1'; $restrict2 = ' AND ptas.pta_leerjr = %i AND ptas.pta_tp = %i'; } else { $restrict = ''; $restrict2 = ' -- %i %i'; } $herkansbaar = mdb2_query($db, << {$herinfo['period_deadline']} AND ppl_id = $ppl_id ORDER BY pta_abbrev EOQ , $jaar, $herinfo['period_num'], $schooltype); while (($row = $herkansbaar->fetchrow(MDB2_FETCHMODE_ASSOC))) { //print_r($row); if (!in_array($row['pta_id'], $al_herkanst) || $row['pta_id'] == $include) { $results[] = $row; } } return $results; } function regime4_checkvalid($db, $ppl_id, $herinfo, $pta_id) { if ($herinfo['period_num'] != 1) fatal_error("impossibru!"); $toegestaan = regime4_getpossibilities($db, $ppl_id, $herinfo, $pta_id); $exception = get_exception($db, $ppl_id, $herinfo); $ok = 0; foreach ($toegestaan as $check) { if ($pta_id == $check['pta_id']) { $ok = 1; break; } } if (!$ok) { //echo("NIET IN TOEGESTANE LIJST?"); //exit; return false; } $total = mdb2_single_val($db, << $no) { //echo("total $total > $no, WTF!"); //exit; return false; } return true; //return false; } function regime0_checkvalid($db, $ppl_id, $herinfo, $pta_id) { $toegestaan = regime0_getpossibilities($db, $ppl_id, $herinfo, $pta_id); $stamklas = get_stamklas($db, $ppl_id, $herinfo); $exception = get_exception($db, $ppl_id, $herinfo); $schooltype = substr($stamklas, 1, 1); $jaar = substr($stamklas, 0, 1); $ok = 0; foreach ($toegestaan as $check) { if ($pta_id == $check['pta_id']) { $ok = 1; break; } } if (!$ok) { //echo("NIET IN TOEGESTANE LIJST?"); //exit; return false; } // count rex's by weight, so that we // can introduce free rexes /*SELECT COUNT(*) FROM rex WHERE ppl_id = $ppl_id AND period_id = {$herinfo['period_id']}*/ $total = mdb2_single_val($db, << $no) { //echo("total $total > $no, WTF!"); //exit; return false; } return true; //return false; } function regime2_rules($db, $ppl_id, $herinfo) { $stamklas = get_stamklas($db, $ppl_id, $herinfo); $exception = get_exception($db, $ppl_id, $herinfo); $jaar = substr($stamklas, 0, 1); $schooltype = substr($stamklas, 1, 1); $no = 2; //if ($exception) $no++; $no += $exception; return "Het aantal herkansingen dat je mag opgeven is $no. Je mag maximaal 1 ST uit TP1 of TP2 herkansen. De andere herkansing(en) moet(en) uit TP3 komen."; //return "Het aantal herkansingen dat je mag opgeven is $no. Je mag maximaal 1 ST uit TP1 of TP2 herkansen (dit moet dan een ST zijn dat je niet eerder hebt herkanst). De andere herkansing(en) moet(en) uit TP3 komen."; } function regime2_getpossibilities($db, $ppl_id, $herinfo, $include = 0) { global $kldv, $concat_begin, $concat_cont, $concat_end, $as_varchar; $results = array(); $stamklas = get_stamklas($db, $ppl_id, $herinfo); $exception = get_exception($db, $ppl_id, $herinfo); $jaar = substr($stamklas, 0, 1); $schooltype = substr($stamklas, 1, 1); $pta_period = ($jaar - 4)*3 + $herinfo['period_num']; $no = 2; $no += $exception; //if ($exception) $no++; if ($schooltype == 'V' && $jaar == 6) $no++; else if ($schooltype == 'H' && $jaar == 5) $no++; $total_weight = mdb2_single_val($db, "SELECT SUM(weight) FROM rex WHERE ppl_id = $ppl_id AND period_id = {$herinfo['period_id']}"); $al_herkanst2 = mdb2_query($db, <<fetchrow(MDB2_FETCHMODE_ASSOC))) { $count++; if ($row['pta_period'] < $pta_period && $include != $row['pta_id']) $pocket = 1; $al_herkanst[] = $row['pta_id']; } //echo('
');
	//print_r($al_herkanst);
	//echo('pocketherkansing '.($pocket?'wel':'niet').' gebruikt');
	//echo('
'); if ($pocket) $pocket_start = $pta_period; else $pocket_start = $pta_period - 2; if ($_SESSION['admin']) { $pocket_start = $pta_period - 2; $stvtd = "( stvt = 'ST' OR stvt = 'VT' )"; $stdher = "( stdher = 0 OR stdher = 1 )"; } else { $stvtd = "stvt = 'ST'"; $stdher = "stdher = 1"; } # als de leerling het maximale aantal herkansingen heeft -> bail out if ($total_weight >= $no && (!in_array($include, $al_herkanst) || !$include)) return array(); $herkansbaar = mdb2_query($db, <<= %i AND ptas.pta_target = '%q' AND $stvtd AND pta_leerjr = '$jaar' WHERE year2grp2subj.year_id = {$herinfo['year_id']} AND $stdher AND ppl2grp.ppl_enter <= {$herinfo['period_deadline']} AND ppl2grp.ppl_exit > {$herinfo['period_deadline']} AND ppl_id = $ppl_id ORDER BY pta_abbrev EOQ , $pta_period, $pocket_start, $schooltype); while (($row = $herkansbaar->fetchrow(MDB2_FETCHMODE_ASSOC))) { //print_r($row); if (!in_array($row['pta_id'], $al_herkanst) || $row['pta_id'] == $include) { $results[] = $row; } } return $results; } function regime2_checkvalid($db, $ppl_id, $herinfo, $pta_id) { $toegestaan = regime2_getpossibilities($db, $ppl_id, $herinfo, $pta_id); $stamklas = get_stamklas($db, $ppl_id, $herinfo); $exception = get_exception($db, $ppl_id, $herinfo); $schooltype = substr($stamklas, 1, 1); $jaar = substr($stamklas, 0, 1); $ok = 0; foreach ($toegestaan as $check) { if ($pta_id == $check['pta_id']) { $ok = 1; break; } } if (!$ok) { //echo("NIET IN TOEGESTANE LIJST?"); //exit; return false; } // count rex's by weight, so that we // can introduce free rexes /*SELECT COUNT(*) FROM rex WHERE ppl_id = $ppl_id AND period_id = {$herinfo['period_id']}*/ $total = mdb2_single_val($db, << $no) { //echo("total $total > $no, WTF!"); //exit; return false; } return true; //return false; } function regime6_rules($db, $ppl_id, $herinfo) { $exception = get_exception($db, $ppl_id, $herinfo); $no = 2 + $exception; return "Het aantal RV's dat je mag opgeven is $no."; } function regime7_rules($db, $ppl_id, $herinfo) { $exception = get_exception($db, $ppl_id, $herinfo); $no = 2 + $exception; return "Het aantal toetsen dat je mag opgeven is $no."; } function regime8_rules($db, $ppl_id, $herinfo) { global $kldv; $stamklas = get_stamklas($db, $ppl_id, $herinfo); $jaar = substr($stamklas, 0, 1); $target = mdb2_single_val($db, <<rules.php."; } function regime5_rules($db, $ppl_id, $herinfo) { $stamklas = get_stamklas($db, $ppl_id, $herinfo); $jaar = substr($stamklas, 0, 1); $schooltype = substr($stamklas, 1, 1); if ($herinfo['period_num'] != 1) fatal_error("impossibru!"); $exception = get_exception($db, $ppl_id, $herinfo); $no = 2 + $exception; if (($jaar == 5 && $schooltype == 'H') || ($jaar == 6 && $schooltype == 'V')) $no++; if ($jaar == 3) return "Het aantal herkansingen dat je mag opgeven is $no."; else if ($jaar == 4) return "Het aantal herkansingen dat je mag opgeven is $no. Je mag kiezen uit de herkansbare ST's en VT's uit TP1."; else return "Het aantal herkansingen dat je mag opgeven is $no. Je mag kiezen uit de herkansbare ST's en VT's uit TP0/TP3* en TP1."; } function regime7_getpossibilities($db, $ppl_id, $herinfo, $include = 0) { global $kldv, $concat_begin, $concat_cont, $concat_end, $as_varchar; $results = array(); $stamklas = get_stamklas($db, $ppl_id, $herinfo); $jaar = substr($stamklas, 0, 1); $schooltype = substr($stamklas, 1, 1); if (strlen($stamklas) == 4) $schooltype .= substr($stamklas, 3, 1); $exception = get_exception($db, $ppl_id, $herinfo); $no = 2 + $exception; $pta_tp = $herinfo['period_num']; $total_weight = mdb2_single_val($db, "SELECT SUM(weight) FROM rex WHERE ppl_id = $ppl_id AND period_id = {$herinfo['period_id']}"); $al_herkanst = mdb2_col($db, 0, << bail out if ($total_weight >= $no && (!in_array($include, $al_herkanst) || !$include)) return array(); if (!$_SESSION['admin']) { $restrict = ' AND stdher = 1'; $restrict2 = ' AND ( ptas.pta_tp = \'%q\' OR ptas.pta_tp = \'%q\' ) AND ptas.pta_leerjr = '.$jaar; } else { $restrict = ''; $restrict2 = '-- %q %q'; } $herkansbaar = mdb2_query($db, << {$herinfo['period_deadline']} AND ppl_id = $ppl_id AND stvt = 'HER (of per1)' ORDER BY pta_abbrev EOQ , $pta_tp, $pta_tp, $pta_tp, $pta_tp, $schooltype); while (($row = $herkansbaar->fetchrow(MDB2_FETCHMODE_ASSOC))) { //print_r($row); if (!in_array($row['pta_id'], $al_herkanst) || $row['pta_id'] == $include) { $results[] = $row; } } return $results; } function regime8_getpossibilities($db, $ppl_id, $herinfo, $include = 0) { global $kldv, $concat_begin, $concat_cont, $concat_end, $as_varchar; $results = array(); $stamklas = get_stamklas($db, $ppl_id, $herinfo); $leerjr = substr($stamklas, 0, 1); //$target = substr($stamklas, 1, 1); $target = mdb2_single_val($db, <<fetchRow(MDB2_FETCHMODE_ASSOC))) { //print_r($row); $count['regime'.$row['period2maxflags_id']] = 0; $regimes['regime'.$row['period2maxflags_id']] = array ( 'max' => $row['max'], 'flags' => $row['flags'] ); $select .= ', ( bla.flags & '.$row['flags'].' ) != 0 AS regime'.$row['period2maxflags_id']; $join .= << {$herinfo['period_deadline']} JOIN ( SELECT *, pta_leerjr + ( SELECT SUBSTRING(year_long, 6, 4) FROM kldv.years WHERE year_id = {$herinfo['year_id']} ) - SUBSTRING(year_long, 6, 4) AS eff_leerjr FROM ptas JOIN kldv.years USING (year_id) WHERE $restrict ) AS bla2 USING (subj_id) {$left}JOIN ( SELECT * FROM period2selectable WHERE period_id = {$herinfo['period_id']} AND ( ll = 1 OR ment = 1 ) AND flags != 0 ) AS bla USING ( pta_id ) $join LEFT JOIN ( SELECT * FROM rex WHERE period_id = {$herinfo['period_id']} ) AS bla3 USING ( ppl_id, pta_id ) WHERE year2grp2subj.year_id = {$herinfo['year_id']} AND ppl2grp.ppl_enter <= {$herinfo['period_deadline']} AND ppl2grp.ppl_exit > {$herinfo['period_deadline']} AND ppl_id = $ppl_id ORDER BY pta_leerjr DESC, pta_tp, pta_abbrev EOQ , $target, $leerjr); //print_r($regimes); //mdb2_res_table($herkansbaar); while (($row = $herkansbaar->fetchrow(MDB2_FETCHMODE_ASSOC))) { //print_r($row); if ($row['pta_id'] != $include) { foreach ($regimes as $regime => $info) { if ($row['rex_id']) $count[$regime] += $row['weight']*$row[$regime]; //$results[] = $row; } } } $forbidden = 0; foreach ($regimes as $regime => $info) { if ($count[$regime] >= $info['max'] + $exception) $forbidden |= $info['flags']; } //print_r($count); //echo("forbidden $forbidden\n"); $herkansbaar->seek(); while (($row = $herkansbaar->fetchrow(MDB2_FETCHMODE_ASSOC))) { if ((!$row['rex_id'] || $row['pta_id'] == $include) && !($row['flags']&$forbidden) && ($_SESSION['admin'] == 1 || $row['ll'] == 1)) { $results[] = $row; } } //echo("hoi target=$target, leerjr=$leerjr, period_id={$herinfo['period_id']}\n"); return $results; } function regime6_getpossibilities($db, $ppl_id, $herinfo, $include = 0) { global $kldv, $concat_begin, $concat_cont, $concat_end, $as_varchar; $results = array(); $stamklas = get_stamklas($db, $ppl_id, $herinfo); $jaar = substr($stamklas, 0, 1); $schooltype = substr($stamklas, 1, 1); if (strlen($stamklas) == 4) $schooltype .= substr($stamklas, 3, 1); $exception = get_exception($db, $ppl_id, $herinfo); $no = 2 + $exception; $pta_tp = $herinfo['period_num']; $total_weight = mdb2_single_val($db, "SELECT SUM(weight) FROM rex WHERE ppl_id = $ppl_id AND period_id = {$herinfo['period_id']}"); $al_herkanst = mdb2_col($db, 0, << bail out if ($total_weight >= $no && (!in_array($include, $al_herkanst) || !$include)) return array(); if (!$_SESSION['admin']) { $restrict = ' AND stdher = 1'; $restrict2 = ' AND ( ptas.pta_tp = \'%q\' OR ptas.pta_tp = \'%q\' ) AND ptas.pta_leerjr = '.$jaar; } else { $restrict = ''; $restrict2 = '-- %q %q'; } $herkansbaar = mdb2_query($db, << {$herinfo['period_deadline']} AND ppl_id = $ppl_id AND stvt = 'RV' ORDER BY pta_abbrev EOQ , $pta_tp, $pta_tp, $pta_tp, $pta_tp, $schooltype); while (($row = $herkansbaar->fetchrow(MDB2_FETCHMODE_ASSOC))) { //print_r($row); if (!in_array($row['pta_id'], $al_herkanst) || $row['pta_id'] == $include) { $results[] = $row; } } return $results; } function regime5_getpossibilities($db, $ppl_id, $herinfo, $include = 0) { global $kldv, $concat_begin, $concat_cont, $concat_end, $as_varchar; if ($herinfo['period_num'] != 1) fatal_error("impossibru!"); $results = array(); $stamklas = get_stamklas($db, $ppl_id, $herinfo); $jaar = substr($stamklas, 0, 1); $schooltype = substr($stamklas, 1, 1); $exception = get_exception($db, $ppl_id, $herinfo); $no = 2 + $exception; if (($jaar == 5 && $schooltype == 'H') || ($jaar == 6 && $schooltype == 'V')) $no++; //$pta_period = ($jaar - 4)*3 + $herinfo['period_num']; $pta_tp = $herinfo['period_num']; $total_weight = mdb2_single_val($db, "SELECT SUM(weight) FROM rex WHERE ppl_id = $ppl_id AND period_id = {$herinfo['period_id']}"); $al_herkanst = mdb2_col($db, 0, << bail out if ($total_weight >= $no && (!in_array($include, $al_herkanst) || !$include)) return array(); if (!$_SESSION['admin']) { $restrict = ' AND stdher = 1'; $restrict2 = ' AND ( ptas.pta_tp = \'%q\' OR ptas.pta_tp = \'%q\' ) AND ptas.pta_leerjr = '.$jaar; } else { $restrict = ''; $restrict2 = '-- %q %q'; } $herkansbaar = mdb2_query($db, << {$herinfo['period_deadline']} AND ppl_id = $ppl_id ORDER BY pta_abbrev EOQ , $pta_tp, $pta_tp - 1, $pta_tp, $pta_tp - 1, $schooltype); while (($row = $herkansbaar->fetchrow(MDB2_FETCHMODE_ASSOC))) { //print_r($row); if (!in_array($row['pta_id'], $al_herkanst) || $row['pta_id'] == $include) { $results[] = $row; } } return $results; } function regime8_checkvalid($db, $ppl_id, $herinfo, $pta_id) { $toegestaan = regime8_getpossibilities($db, $ppl_id, $herinfo, $pta_id); $exception = get_exception($db, $ppl_id, $herinfo); $ok = 0; foreach ($toegestaan as $check) { if ($pta_id == $check['pta_id']) { $ok = 1; break; } } if (!$ok) { //echo("NIET IN TOEGESTANE LIJST?"); //exit; return false; } return true; //return false; } function regime7_checkvalid($db, $ppl_id, $herinfo, $pta_id) { $toegestaan = regime7_getpossibilities($db, $ppl_id, $herinfo, $pta_id); $exception = get_exception($db, $ppl_id, $herinfo); $ok = 0; foreach ($toegestaan as $check) { if ($pta_id == $check['pta_id']) { $ok = 1; break; } } if (!$ok) { //echo("NIET IN TOEGESTANE LIJST?"); //exit; return false; } $total = mdb2_single_val($db, << $no) { //echo("total $total > $no, WTF!"); //exit; return false; } return true; //return false; } function regime6_checkvalid($db, $ppl_id, $herinfo, $pta_id) { $toegestaan = regime6_getpossibilities($db, $ppl_id, $herinfo, $pta_id); $exception = get_exception($db, $ppl_id, $herinfo); $ok = 0; foreach ($toegestaan as $check) { if ($pta_id == $check['pta_id']) { $ok = 1; break; } } if (!$ok) { //echo("NIET IN TOEGESTANE LIJST?"); //exit; return false; } $total = mdb2_single_val($db, << $no) { //echo("total $total > $no, WTF!"); //exit; return false; } return true; //return false; } function regime5_checkvalid($db, $ppl_id, $herinfo, $pta_id) { if ($herinfo['period_num'] != 1) fatal_error("impossibru!"); $toegestaan = regime5_getpossibilities($db, $ppl_id, $herinfo, $pta_id); $exception = get_exception($db, $ppl_id, $herinfo); $ok = 0; foreach ($toegestaan as $check) { if ($pta_id == $check['pta_id']) { $ok = 1; break; } } if (!$ok) { //echo("NIET IN TOEGESTANE LIJST?"); //exit; return false; } $total = mdb2_single_val($db, << $no) { //echo("total $total > $no, WTF!"); //exit; return false; } return true; //return false; } $regimes[0]->short = "examenklassen 2 hers, anderen 1 her"; $regimes[0]->rules = 'regime0_rules'; $regimes[0]->getpossibilities = 'regime0_getpossibilities'; $regimes[0]->checkvalid = 'regime0_checkvalid'; $regimes[1]->short = "rekentoets"; $regimes[2]->short = "voorexamenklassen + pocketherkansing"; $regimes[2]->rules = 'regime2_rules'; $regimes[2]->getpossibilities = 'regime2_getpossibilities'; $regimes[2]->checkvalid = 'regime2_checkvalid'; $regimes[3]->short = "examenklassen 3 hers, anderen 2 hers"; $regimes[3]->rules = 'regime3_rules'; $regimes[3]->getpossibilities = 'regime3_getpossibilities'; $regimes[3]->checkvalid = 'regime3_checkvalid'; $regimes[4]->short = "examenklassen 3, anderen 2 hers uit TP1 (en TP0/TP3*)"; $regimes[4]->rules = 'regime4_rules'; $regimes[4]->getpossibilities = 'regime4_getpossibilities'; $regimes[4]->checkvalid = 'regime4_checkvalid'; $regimes[5]->short = "examenklassen 3, anderen 2 hers uit TP1 (en TP0/TP3*) en 3e klassen"; $regimes[5]->rules = 'regime5_rules'; $regimes[5]->getpossibilities = 'regime5_getpossibilities'; $regimes[5]->checkvalid = 'regime5_checkvalid'; $regimes[6]->short = "onderbouw 2 toetsen"; $regimes[6]->rules = 'regime6_rules'; $regimes[6]->getpossibilities = 'regime6_getpossibilities'; $regimes[6]->checkvalid = 'regime6_checkvalid'; $regimes[7]->short = "onderbouw 2 toetsen (of per1)"; $regimes[7]->rules = 'regime7_rules'; $regimes[7]->getpossibilities = 'regime7_getpossibilities'; $regimes[7]->checkvalid = 'regime7_checkvalid'; $regimes[8]->short = "eustomflex"; $regimes[8]->rules = 'regime8_rules'; $regimes[8]->getpossibilities = 'regime8_getpossibilities'; $regimes[8]->checkvalid = 'regime8_checkvalid'; /* function get_toets_name($idx, $legenda, $afdeling) { assert($idx >= 0 && $idx < count($legenda) || $afdeling); return $afdeling.'.'.$legenda[$idx]; } */ function get_toets_proper_name($db, $pta_id, $ignore, $combine) { $toets = mdb2_single_val($db, "SELECT PTA(%i)", $pta_id); if (in_array($toets, $combine)) error_system("naam van combinatietoets is naam van echte toets!?!?"); if (in_array($toets, $ignore)) return NULL; if (isset($combine[$toets])) $toets = $combine[$toets]; return trim($toets); } function build_combine($combine_raw, $ignore) { // build combine from combine_raw and check sanity $combine = array(); foreach ($combine_raw as $new => $list) { $ignored = 0; foreach ($list as $old) { if (in_array($old, $ignore)) { $ignored++; //print_r($ignore); //print_r($list); //error_system("ignored toets $old is to be combined into $new?"); } if (isset($combine[$old])) error_system("toets $old must be combined to $new but is already combined to {$combine['old']}"); $combine[$old] = $new; } if ($ignored > 0 && $ignored != count($list)) error_system("some parts of combined toets are ignored, only none or all are supported"); } return $combine; } function get_conflicts($db, $period_id) { global $kldv; $info = mdb2_all_assoc($db, << TIME_TO_SEC(moments.moment_time_start) + 300 JOIN $kldv.ppl USING (ppl_id) WHERE rex.period_id = %i GROUP BY ppl_id EOQ , $period_id, $period_id); return $info; } function get_simple_conflicts($db, $period_id) { global $kldv; $info = mdb2_all_assoc_rekey($db, << TIME_TO_SEC(moments.moment_time_start) - 300 WHERE moments.period_id = %i GROUP BY moments.moment_id ORDER BY moment_date, moment_time_start EOQ , $period_id, $period_id); return $moments; } function get_duur($momentinfos, $color) { return $momentinfos['data'][$momentinfos['from_color'][$color]]['duur']; } function visit(&$indices, $cur, $max, $duren, &$info ) { if ($cur != $max) { for ($indices[$cur] = 0; $indices[$cur] < 2; $indices[$cur]++) { visit($indices, $cur + 1, $max, $duren, $info); } return; } // analyze and count $count = array_fill_keys($duren, 0); $conflicts = array_fill(0, $max, 0); for ($i = 0; $i < $max; $i++) { if (!$indices[$i]) continue; $duur = $info['data'][$info['from_color'][$i]]['duur']; assert(isset($duren[$duur])); $count[$duur]++; foreach ($info['conflicts'][$i] as $j => $tmp) { $conflicts[$j] |= 1; } } $dindex = implode('-', $count); // reinitialize count to count free moments $count = array_fill_keys($duren, 0); for ($i = 0; $i < $max; $i++) { if ($conflicts[$i]) continue; $duur = $info['data'][$info['from_color'][$i]]['duur']; $count[$duur]++; } foreach ($duren as $duur) { if (!isset($info['worst_case_perduur'][$duur][$dindex]) || $info['worst_case_perduur'][$duur][$dindex] > $count[$duur]) $info['worst_case_perduur'][$duur][$dindex] = $count[$duur]; } //print_r($indices); //print_r($conflicts); //print_r($count); //echo("$i $duur $dindex\n"); } function get_momentinfos($moments) { $idx = 0; $duren = array(); $info = array('to_color' => array(), 'conflicts' => array(), 'from_color' => array(), 'max_colors' => count($moments), 'moments_perduur' => array(), 'max_colors_perduur' => array(), 'worst_case_perduur' => array(), 'data' => $moments, ); foreach ($moments as $moment_id => $moment) { if (!isset($info['max_colors_perduur'][$moment['duur']])) $info['max_colors_perduur'][$moment['duur']] = 1; else $info['max_colors_perduur'][$moment['duur']]++; if (!isset($info['moments_perduur'][$moment['duur']])) { $info['moments_perduur'][$moment['duur']] = array(); $info['worst_case_perduur'][$moment['duur']] = array(); $duren[] = $moment['duur']; } $info['moments_perduur'][$moment['duur']][] = $idx; $info['to_color'][$moment_id] = $idx; $info['from_color'][$idx] = $moment_id; $idx++; } foreach ($moments as $moment_id => $moment) { $info['conflicts'][$info['to_color'][$moment_id]] = array(); foreach (explode(',', $moment['conflict']) as $conflict) { $info['conflicts'][$info['to_color'][$moment_id]][$info['to_color'][$conflict]] = true; } } assert($idx == $info['max_colors']); $indices = array(); visit($indices, 0, $idx, $duren, $info); return $info; } /* function get_rooster($db, $period_id) { global $kldv; // the GROUP BY IFNULL( trick is to not group the NULL values in group_id return mdb2_all_assoc_rekey($db, << $count) { if (isset($indices) && $indices[$neighbor] > $indices[$name]) assert($toetsen[$neighbor]['color'] === NULL); else if ($toetsen[$neighbor]['color'] !== NULL) { // account for conflicting colors of neighboring toetsen foreach ($momentinfos['conflicts'][$toetsen[$neighbor]['color']] as $color => $tmp) { $bad_colors[$color]++; } } else assert(!isset($indices)); } // toetsduur, mark all colors with different toetsduur invalid foreach ($momentinfos['to_color'] as $color) { if ($toetsen[$name]['duur'] != get_duur($momentinfos, $color)) { $bad_colors[$color]++; } } return $bad_colors; } function check_neighbors($toetsen, $neighbors, $color, $momentinfos) { assert($color !== NULL); //global $toetsen; //print_r($neighbors); foreach ($neighbors as $neighbor => $tmp) { //if ($toetsen[$neighbor]['color'] === $color) return false; if (isset($momentinfos['conflicts'][$toetsen[$neighbor]['color']][$color])) return false; } return true; } function clear_colors(&$toetsen) { foreach ($toetsen as $id => $info) { $toetsen[$id]['color'] = NULL; } } function set_graph_id2(&$collections, &$toetsen, &$toets, $id) { assert(!$toets['graph']); $toets['graph'] = $id; foreach ($toets['neighbors'] as $naam => $aantal) { if ($toetsen[$naam]['graph'] === NULL) { $collections[$id]['list'][] = $naam; set_graph_id2($collections, $toetsen, $toetsen[$naam], $id); } } } function make_collections(&$collections, &$toetsen) { $graph_id = 0; foreach ($toetsen as $naam => &$value) { if ($value['graph'] !== NULL) continue; $collections[$graph_id] = array('list' => array($naam)); set_graph_id2($collections, $toetsen, $value, $graph_id++); } } function set_subgraph_id(&$subgraphs, &$toetsen, &$toets, $id) { assert(!$toets['subgraph_id']); $toets['subgraph_id'] = $id; foreach ($toets['neighbors'] as $naam => $aantal) { if ($toetsen[$naam]['alwaysfits'] == 1) continue; if ($toetsen[$naam]['subgraph_id'] !== NULL) continue; $subgraphs[$id]['list'][] = $naam; set_subgraph_id($subgraphs, $toetsen, $toetsen[$naam], $id); } } function make_subgraphs(&$subgraphs, &$list, &$toetsen) { $subgraph_id = 0; foreach ($list as $id) { $toets = $toetsen[$id]; if ($toets['subgraph_id'] !== NULL) continue; if ($toets['alwaysfits'] == 1) { $toetsen[$id]['subgraph_id'] = PHP_INT_MAX; $toetsen[$id]['subgraph_order'] = 0; continue; } $subgraphs[$subgraph_id] = array('list' => array()); $subgraphs[$subgraph_id]['list'][] = $id; set_subgraph_id($subgraphs, $toetsen, $toetsen[$id], $subgraph_id++); } } function set_colors_from_rooster2(&$toetsen, $rooster, $moment_to_color) { foreach ($toetsen as $id => $info) { if (isset($rooster[$id])) { $toetsen[$id]['color'] = $moment_to_color[$rooster[$id]]; } else $toetsen[$id]['color'] = NULL; } } function research(&$toetsen, $array, $collection, $momentinfos) { if (count($array) == 0) return true; $name = array_shift($array); //echo("name=$name"); //print_r($array); $bad_colors = get_bad_colors2($toetsen, $name, $collection['idx'], $momentinfos); //print_r($bad_colors); foreach ($bad_colors as $color => $used) { if ($used) continue; //echo("try color $color\n"); $toetsen[$name]['color'] = $color; if (research($toetsen, $array, $collection, $momentinfos)) return true; } $toetsen[$name]['color'] = NULL; return false; } function static_analysis_toetsen(&$toetsen, $momentinfos) { foreach ($toetsen as $id => $toets) { $count = array_fill_keys(array_keys($momentinfos['worst_case_perduur']), 0); foreach ($toets['neighbors'] as $neighbor => $aantal) { $count[$toetsen[$neighbor]['duur']]++; } $overflow = 0; foreach (array_keys($momentinfos['worst_case_perduur']) as $duur) { if ($count[$duur] > $momentinfos['max_colors_perduur'][$duur]) $overflow = 1; } if (!$overflow) { $dindex = implode('-', $count); $toetsen[$id]['alwaysfits'] = ($momentinfos['worst_case_perduur'][$toets['duur']][$dindex] > 0)?1:0; } else $toetsen[$id]['alwaysfits'] = 0; } } function check_consistent_and($check_solvable = true, &$toetsen, &$collections, $momentinfos) { static_analysis_toetsen($toetsen, $momentinfos); foreach ($collections as $id => $collection) { $collections[$id]['subgraphs'] = array(); usort($collections[$id]['list'], function ($a, $b) use (&$toetsen) { return count($toetsen[$a]['neighbors']) < count($toetsen[$b]['neighbors']); }); make_subgraphs($collections[$id]['subgraphs'], $collections[$id]['list'], $toetsen); foreach ($collections[$id]['subgraphs'] as $subgraph) { calc_optimal_order_of_subgraph($subgraph['list'], $toetsen); } usort($collections[$id]['list'], function ($a, $b) use (&$toetsen, &$momentinfos) { if ($toetsen[$a]['subgraph_id'] == $toetsen{$b}['subgraph_id']) return $toetsen[$a]['subgraph_order'] > $toetsen{$b}['subgraph_order']; return $toetsen[$a]['subgraph_id'] > $toetsen{$b}['subgraph_id']; /* $afdvaka = strstr($a, '.', true); $afdvakb = strstr($b, '.', true); $strcmp = strcmp($afdvaka, $afdvakb); if ($toetsen[$a]['alwaysfits']) { if ($toetsen[$b]['alwaysfits']) { return 0; } else { return 1; } } else if ($toetsen[$b]['alwaysfits']) { return -1; } if ($strcmp == 0) return count($toetsen[$a]['neighbors']) < count($toetsen[$b]['neighbors']); else return $strcmp; */ }); $collections[$id]['used_colors'] = array(); $collections[$id]['to_research'] = array(); // elke toets krijgt een 'idx', deze geeft aan in welke volgorde // de toetsen een kleur krijgen; toetsen met idx = -1 hebben al een kleur $collections[$id]['idx'] = array(); $collections[$id]['no_idx'] = 0; foreach ($collections[$id]['list'] as $name) { $toets = $toetsen[$name]; //print_r($toets); $color = $toets['color']; if ($color === NULL) { $collections[$id]['to_research'][] = $name; $collections[$id]['idx'][$name] = $collections[$id]['no_idx']++; continue; } $collections[$id]['idx'][$name] = -1; $collections[$id]['used_colors'][$color] = true; if (!check_neighbors($toetsen, $toets['neighbors'], $color, $momentinfos)) { return false; } } foreach ($collections[$id]['to_research'] as $name) { uksort($toetsen[$name]['neighbors'], function ($a, $b) use ($collections, $id) { //print_r($collections); return $collections[$id]['idx'][$a] > $collections[$id]['idx'][$b]; }); } //print_r($collections[$id]['used_colors']); if ($check_solvable) { $ret = research($toetsen, $collections[$id]['to_research'], $collections[$id], $momentinfos); if (!$ret) { return false; } } ////print_r($collections[$id]['to_research']); } return true; } function check_sanity($toetsen, $momentinfos) { foreach ($toetsen as $naam => $toets) { if ($toets['color'] === NULL) { echo("$naam is niet ingekleurd terwijl dat wel moet\n"); return false; } if ($toets['color'] < 0 || $toets['color'] >= $momentinfos['max_colors']) { echo("$naam is ingevuld met ongeldige kleur\n"); return false; } if (!check_neighbors($toetsen, $toets['neighbors'], $toets['color'], $momentinfos)) { echo("check neighbors failed for $naam\n"); return false; } if ($toets['duur'] != get_duur($momentinfos, $toets['color'])) { echo("duur van toets $naam niet gelijk aan duur van toetsmoment"); return false; } } return true; } function calc_optimal_order_of_subgraph(&$list, &$toetsen) { $tmplist = array(); foreach ($list as $elt) { $tmplist[$elt] = $toetsen[$elt]['neighbors']; } $wildfire = array(); $wildfire[] = $list[0]; $neighbors = $tmplist[$list[0]]; unset($tmplist[$list[0]]); foreach ($neighbors as $neighbor => $aantal) { if (!isset($tmplist[$neighbor])) { unset($neighbors[$neighbor]); continue; } } expand($wildfire, $tmplist, $neighbors); foreach ($wildfire as $idx => $toets) { $toetsen[$toets]['subgraph_order'] = $idx; } } function expand(&$wildfire, &$tmplist, $neighbors) { //print_r($neighbors); foreach ($neighbors as $neighbor => $aantal) { // echo("n: $neighbor\n"); // remove neighbors we have already visited foreach ($tmplist[$neighbor] as $next_neighbor => $aantal) { if (!isset($tmplist[$next_neighbor])) { unset($tmplist[$neighbor][$next_neighbor]); continue; } // echo("nn: $next_neighbor\n"); } } if (count($neighbors) == 0) return; uksort($neighbors, function ($a, $b) use ($tmplist) { return count($tmplist[$a]) < count($tmplist[$b]); }); // foreach ($neighbors as $neighbor => $aantal) { // echo("$neighbor ".count($tmplist[$neighbor])."\n"); // } $toets_to_merge = array_key_first($neighbors); // echo("selected next: $toets_to_merge\n"); $next_neighbors = $tmplist[$toets_to_merge]; $wildfire[] = $toets_to_merge; unset($neighbors[$toets_to_merge]); unset($tmplist[$toets_to_merge]); //echo("neighbors:\n"); //print_r($neighbors); //echo("to merge with:\n"); //print_r($next_neighbors); foreach ($neighbors as $neighbor => $aantal) { if (isset($next_neighbors[$neighbor])) continue; $next_neighbors[$neighbor] = $aantal; } //echo("merged:\n"); //print_r($next_neighbors); expand($wildfire, $tmplist, $next_neighbors); } function get_toetsen($db, $data, $ignore, $combine_raw) { $toetsen = array(); $combine = build_combine($combine_raw, $ignore); $node_counter = 0; foreach ($data as $llnr => $array) { $lijst = array(); foreach ($array as $pta_id) { if (!($toets = get_toets_proper_name($db, $pta_id, $ignore, $combine))) continue; if (isset($lijst[$toets])) error_system("leerling heeft (gecombineerde) toets $toets dubbel"); else $lijst[$toets] = 1; if (!isset($toetsen[$toets])) $toetsen[$toets] = array( 'id' => $node_counter++, 'aantal' => 1, 'neighbors' => array(), 'graph' => NULL, 'subgraph_id' => NULL, 'subgraph_order' => NULL, 'color' => NULL, 'duur' => mdb2_single_val($db, "SELECT toetsduur FROM ptas WHERE pta_id = %i", $pta_id) ); else $toetsen[$toets]['aantal']++; } foreach ($lijst as $toets1 => $tmp1) { foreach ($lijst as $toets2 => $tmp2) { if ($toets1 == $toets2) continue; if (!isset($toetsen[$toets1]['neighbors'][$toets2])) $toetsen[$toets1]['neighbors'][$toets2] = 1; else $toetsen[$toets1]['neighbors'][$toets2]++; } } } return $toetsen; } // format of parameters // $ignore = array('6V.wisD/TP1', '5H.schk/TP1') // $combine = array('6V.wisAC/TP1' => array('6V.wisA/TP1', '6V.wisC/TP1') function get_toetsen_from_db($db, $period_id = NULL, $ignore = array(), $combine_raw = array(), $limit = NULL) { global $kldv; if (!$period_id) { $herinfo = get_herinfo($db); if (!$herinfo) error_system('geen aankomende herkansingsperiode'); $period_id = $herinfo['period_id']; } if ($limit) { $limit_pta_id = mdb2_single_val($db, "SELECT pta_id FROM ptas WHERE pta_id = %i", $limit); if (!$limit_pta_id) error_system('limit_pta_id niet gevonden'); $join = << &$list) { if ($list == '') $list = array(); else $list = explode(',', $list); } return get_toetsen($db, $data, $ignore, $combine_raw); } function dot($list, $toetsen) { ob_start(); ?> graph herkansingen { size="16x8" ratio=".5" n [id="n",label=""] $count) { if ($toetsen[$neighbor]['id'] < $id) { ?> n -- n [label=""] }