diff options
Diffstat (limited to 'pkle2009.php')
-rw-r--r-- | pkle2009.php | 582 |
1 files changed, 582 insertions, 0 deletions
diff --git a/pkle2009.php b/pkle2009.php new file mode 100644 index 0000000..ddd1135 --- /dev/null +++ b/pkle2009.php @@ -0,0 +1,582 @@ +<?php +$tabpkl = array(); +$typ = 0; +$rng = 0; +$xrng = 0; +$iuc = 0; +$izw = 0; +$swk = 0; +$tab = 0; +$minpkl = 0; +$min1 = 300; +$min2 = 200; +$min3 = 100; +$min4 = 50; +$min5 = 0; +$min6 = 50; +$mind = 0; +$min7 = 0; +$min8 = 0; +$min9 = 0; + +// regulamin +$progu0 = 0; +$progp0 = 100; + +$progu1 = 2; // dla pierwszych progu1% uczestników +$progp1 = 90; // ostatni dostaje progp1% maximum punktów + +$progu2 = 20; // dla kolejnych (progu2-progu1)% uczestników +$progp2 = 20; // ostatni dostaje 10*progp2% maximum punktów + +$progu3 = 50; // dla kolejnych (progu3-progu2)% uczestników +$progp3 = 0; // ostatni dostaje 10*progp3% maximum punktów + + +$rgg = 15; // OTP**** +$rgp = 12; // OTP*** +$rot = 10; // OTP** +$rok = 7; // OTP +$r40 = 5; // OTP krótki +$rtp = 5; // RTP* +$rtd = 5; // RTP 40+ +$rtr = 3; // RTP +$rto = 2; // okregowy +$rtk = 1; // klubowy + +$xrgg = 20; // OTP**** +$xrgp = 16; // OTP*** +$xrot = 12; // OTP** +$xrok = 9; // OTP +$xr40 = 8; // OTP krótki +$xrtp = 7; // RTP* +$xrtd = 6; // RTP 40+ +$xrtr = 5; // RTP +$xrto = 3; // okregowy +$xrtk = 2; // klubowy + +$zaw = 0.05; +$dajp = 0; + +if( $_SERVER['REQUEST_METHOD'] == 'GET' ){ +// ?typtur=[1,2,4]&uczest=IU&sumawk=SWK&ranga=[1..9] +// I P T GP..KLUB + $l = 0; + if( isset($_GET['typtur']) ){ + $typ = $_GET['typtur']; + $l = 1; + } + if( isset($_GET['uczest']) ){ + $iuc = $_GET['uczest']; + $l = $l + 1; + } + if( isset($_GET['sumawk']) ){ + $swk = $_GET['sumawk']; + $l = $l + 1; + } + if( isset($_GET['ranga']) ){ + $rng = $_GET['ranga']; + switch( $rng ){ + case 1: + $rng = $rgg; + $xrng = $xrgg; + $minpkl = $min1; + break; + case 2: + $rng = $rgp; + $xrng = $xrgp; + $minpkl = $min2; + break; + case 3: + $rng = $rot; + $xrng = $xrot; + $minpkl = $min3; + break; + case 4: + $rng = $rok; + $xrng = $xrok; + $minpkl = $min4; + break; + case 5: + $rng = $r40; + $xrng = $xr40; + $minpkl = $min5; + break; + case 6: + $rng = $rtp; + $xrng = $xrtp; + $minpkl = $min6; + break; + case 7: + $rng = $rtd; + $xrng = $xrtd; + $minpkl = $mind; + break; + case 8: + $rng = $rtr; + $xrng = $xrtr; + $minpkl = $min7; + break; + case 9: + $rng = $rto; + $xrng = $xrto; + $minpkl = $min8; + break; + case 10: + $rng = $rtk; + $xrng = $xrtk; + $minpkl = $min9; + break; + } + if( $rng ) $l = $l + 1; + } + if( $typ>2 ) $typ = 4; + $izw = $typ*$iuc; + if( $izw > 99 ){ + $dajp = 1; + } + if( $l > 3 ) $tab = 1; +} +elseif( $_SERVER['REQUEST_METHOD'] == 'POST' ){ + $progu1 = $_POST['pru1']; // dla pierwszych progu1% uczestników + $progp1 = $_POST['prp1']; // ostatni dostaje progp1% maximum punktów + $progu2 = $_POST['pru2']; // dla kolejnych (progu2-progu1)% uczestników + $progp2 = $_POST['prp2']; // ostatni dostaje 10*progp2% maximum punktów + $progu3 = $_POST['pru3']; // dla kolejnych (progu3-progu2)% uczestników + $rgg = $_POST['rgg']; + $rgp = $_POST['rgp']; + $rot = $_POST['rot']; + $rok = $_POST['rok']; + $r40 = $_POST['r40']; + $rtp = $_POST['rtp']; + $rtd = $_POST['rtd']; + $rtr = $_POST['rtr']; + $rto = $_POST['rto']; + $rtk = $_POST['rtk']; + + $typ = $_POST['typ']; + $rng = $_POST['rng']; + $zaw = $_POST['zaw']; + $min1 = $_POST['min1']; + $min2 = $_POST['min2']; + $min3 = $_POST['min3']; + $min4 = $_POST['min4']; + $min5 = $_POST['min5']; + $min6 = $_POST['min6']; + $min7 = $_POST['min7']; + $min8 = $_POST['min8']; + $min9 = $_POST['min9']; + switch( $rng ){ + case 20: + $rng = $rgg; + $xrng = $xrgg; + $minpkl = $min1; + break; + case 16: + $rng = $rgp; + $xrng = $xrgp; + $minpkl = $min2; + break; + case 12: + $rng = $rot; + $xrng = $xrot; + $minpkl = $min3; + break; + case 9: + $rng = $rok; + $xrng = $xrok; + $minpkl = $min4; + break; + case 8: + $rng = $r40; + $xrng = $xr40; + $minpkl = $min5; + break; + case 7: + $rng = $rtp; + $xrng = $xrtp; + $minpkl = $min6; + break; + case 6: + $rng = $rtd; + $xrng = $xrtd; + $minpkl = $mind; + break; + case 5: + $rng = $rtr; + $xrng = $xrtr; + $minpkl = $min7; + break; + case 3: + $rng = $rto; + $xrng = $xrto; + $minpkl = $min8; + break; + case 2: + $rng = $rtk; + $xrng = $xrtk; + $minpkl = $min9; + break; + } + $iuc = $_POST['iuc']; + if( $typ>2 ) $typ = 4; + $izw = $typ*$iuc; + if( $izw > 99 ){ + $dajp = 1; + } + $swk = $_POST['swk']; + $tab = 1; +} +?> +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<head> +<meta http-equiv="pragma" content="no-cache"> +<meta http-equiv="cache-control" content="no-cache"> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> +<title>Kargulator PKLi</title> +<link rel="stylesheet" href="style.css" type="text/css"> +<link rel="icon" href="images/favicon.ico" type="image/x-icon"> +<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon"> +<script type="text/javascript"> +<!-- +function valiuc(x,y){ + if( !(x.value==null || x.value=='') ){ + if( isFinite(x.value)){ + if( y==1 ){ + if( document.getElementsByName("typ")[0].checked ){ + document.getElementById("izw").value = x.value; + } else { + if( document.getElementsByName("typ")[1].checked ){ + document.getElementById("izw").value = 2 * x.value; + } else { + if( document.getElementsByName("typ")[2].checked ){ + document.getElementById("izw").value = 4 * x.value; + } + } + } + } + if( y==3 ){ + var z = document.getElementById('izw'); + if( valiuc(z,2) ){ + document.getElementById('srd').value = x.value/z.value; + } + } + return true; + } else { + alert(x.value+' to nie liczba!'); + x.select(); + x.focus(); + return false; + } + } +} + +function typtur(x){ + var t = document.getElementById("iuc"); + var z = document.getElementById("izw"); + if( t.value!=null && t.value!='' && isFinite(t.value) ){ + z.value = x * t.value; + } +} + +function submitit(){ + if( document.getElementsByName("typ")[0].checked || + document.getElementsByName("typ")[1].checked || + document.getElementsByName("typ")[2].checked ){ + if( document.getElementsByName("rng")[0].checked || + document.getElementsByName("rng")[1].checked || + document.getElementsByName("rng")[2].checked || + document.getElementsByName("rng")[3].checked || + document.getElementsByName("rng")[4].checked || + document.getElementsByName("rng")[5].checked || + document.getElementsByName("rng")[6].checked || + document.getElementsByName("rng")[7].checked || + document.getElementsByName("rng")[8].checked || + document.getElementsByName("rng")[9].checked ){ + var t = document.getElementById("iuc") + if( t.value!=null && t.value!='' && isFinite(t.value) ){ + t = document.getElementById("izw"); + if( t.value!=null && t.value!='' && isFinite(t.value) ){ + t = document.getElementById("swk"); + if( t.value!=null && t.value!='' && isFinite(t.value) ){ + + document.getElementById("pkl").submit(); + + } else { + alert('Brak sumy WK!'); + t.select(); + } + } else { + alert('Brak liczby zawodników!'); + t.select(); + } + } else { + alert('Brak liczby uczestników!'); + t.select(); + } + } else { + alert('Wybierz rangę turnieju'); + document.getElementsByName("rng")[0].select(); + } + } else { + alert('Wybierz typ turnieju'); + document.getElementsByName("typ")[0].select(); + } +} +--> +</script> +</head> +<body> +<form id="pkl" method="post" action="pkle2009.php"> +<table border="0" cellspacing="0" cellpadding="0"> + <tr> + <td><img src="images/logo_pzbs.gif"></td> + <td colspan="3" align="center"><h3>KALKULATOR PKLI W TURNIEJACH PZBS<br> + zgodny ze <span style="color:#d00">starym regulaminem (01.10.2009 - 31.03.2014)</span></h3> + Przejdź do <a href="pkle2014.php"><b>kalkulatora zgodnego z nowym regulaminem</b></a>! + <br><br> + Możesz eksperymentować ze wszystkimi (prawie) parametrami.<br> + Dla przywrócenia stanu regulaminowego otwórz ponownie stronę.</td> + <td><img src="images/logo_pzbs.gif"></td> + </tr> + <tr><td colspan="5"> </td></tr> + <tr> + <td align="right">WAGA<br>turnieju</td><td align="left">MINIMUM<br>za 1sze miejsce</td><td align="left" colspan="3">WSP:</td> + </tr> + <tr> + <td align="right" rowspan="3"> + OTP<sup>∗∗∗∗</sup>: <input type="text" id="rgg" name="rgg" maxlength="3" style="width:30px" value=<?php echo '"'.$rgg.'"'; ?>><br /> + OTP<sup>∗∗∗</sup>: <input type="text" id="rgp" name="rgp" maxlength="3" style="width:30px" value=<?php echo '"'.$rgp.'"'; ?>><br /> + OTP<sup>∗∗</sup>: <input type="text" id="rot" name="rot" maxlength="3" style="width:30px" value=<?php echo '"'.$rot.'"'; ?>><br /> + OTP: <input type="text" id="rok" name="rok" maxlength="3" style="width:30px" value=<?php echo '"'.$rok.'"'; ?>><br /> + OTP krótki: <input type="text" id="r40" name="r40" maxlength="3" style="width:30px" value=<?php echo '"'.$r40.'"'; ?>><br /> + Regionalny<sup>∗</sup>: <input type="text" id="rtp" name="rtp" maxlength="3" style="width:30px" value=<?php echo '"'.$rtp.'"'; ?>><br /> + Regionalny+40r: <input type="text" id="rtd" name="rtd" maxlength="3" style="width:30px" value=<?php echo '"'.$rtd.'"'; ?>><br /> + Regionalny: <input type="text" id="rtr" name="rtr" maxlength="3" style="width:30px" value=<?php echo '"'.$rtr.'"'; ?>><br /> + Okręgowy: <input type="text" id="rto" name="rto" maxlength="3" style="width:30px" value=<?php echo '"'.$rto.'"'; ?>><br /> + Klubowy: <input type="text" id="rtk" name="rtk" maxlength="3" style="width:30px" value=<?php echo '"'.$rtk.'"'; ?>></td> + <td align="left" rowspan="3"> + <input type="text" id="min1" name="min1" maxlength="3" style="width:30px" value=<?php echo '"'.$min1.'"'; ?>><br /> + <input type="text" id="min2" name="min2" maxlength="3" style="width:30px" value=<?php echo '"'.$min2.'"'; ?>><br /> + <input type="text" id="min3" name="min3" maxlength="3" style="width:30px" value=<?php echo '"'.$min3.'"'; ?>><br /> + <input type="text" id="min4" name="min4" maxlength="3" style="width:30px" value=<?php echo '"'.$min4.'"'; ?>><br /> + <input type="text" id="min5" name="min5" maxlength="3" style="width:30px" value=<?php echo '"'.$min5.'"'; ?>><br /> + <input type="text" id="min6" name="min6" maxlength="3" style="width:30px" value=<?php echo '"'.$min6.'"'; ?>><br /> + <input type="text" id="mind" name="minD" maxlength="3" style="width:30px" value=<?php echo '"'.$mind.'"'; ?>><br /> + <input type="text" id="min7" name="min7" maxlength="3" style="width:30px" value=<?php echo '"'.$min7.'"'; ?>><br /> + <input type="text" id="min8" name="min8" maxlength="3" style="width:30px" value=<?php echo '"'.$min8.'"'; ?>><br /> + <input type="text" id="min9" name="min9" maxlength="3" style="width:30px" value=<?php echo '"'.$min9.'"'; ?>></td> + <td align="left" valign="top"><input type="text" id="zaw" name="zaw" maxlength="5" style="width:30px" value=<?php echo '"'.$zaw.'"'; ?>></td> + <td valign="top" colspan="2">PKL za 1 m = <b>śr.WK×WAGA + il.zaw×WSP</b></td> + </tr> + <tr> + <td align="right" valign="top"><br /><br /><br /><br /><input type="text" id="prp1" name="prp1" style="width:18px" value=<?php echo '"'.$progp1.'"'; ?>>%<br /><input type="text" id="prp2" name="prp2" style="width:18px" value=<?php echo '"'.$progp2.'"'; ?>>%</td> + <td colspan="2" align="left"><img src="images/pkle.png"></td> + </tr> + <tr> + <td> </td> + <td colspan="2"><table cellspacing="0" cellpadding="0"><tr><td align="right" style="width:50px"><input type="text" id="pru1" name="pru1" style="width:18px" value=<?php echo '"'.$progu1.'"'; ?>>%</td><td align="right" style="width:25px"><input type="text" id="pru2" name="pru2" style="width:18px" value=<?php echo '"'.$progu2.'"'; ?>>%</td><td align="right" style="width:55px"><input type="text" id="pru3" name="pru3" style="width:18px" value=<?php echo '"'.$progu3.'"'; ?>>%</td></tr></table></td> + </tr> + + <tr><td colspan="5"> </td></tr> + <tr> + <td valign=top rowspan="2">TYP ZAWODÓW<br /> + <input type="radio" name="typ" id="tp1" value="1" onclick="typtur(1)"<?php if( $typ==1 ){ echo ' checked="checked"';}?>><label for="tp1"> Indywiduel</label><br /> + <input type="radio" name="typ" id="tp2" value="2" onclick="typtur(2)"<?php if( $typ==2 ){ echo ' checked="checked"';}?>><label for="tp2"> Pary</label><br /> + <input type="radio" name="typ" id="tp3" value="4" onclick="typtur(4)"<?php if( $typ==4 ){ echo ' checked="checked"';}?>><label for="tp3"> Teamy</label></td> + <td valign=top rowspan="2">RANGA ZAWODÓW<br /> + <input type="radio" name="rng" id="rg1" value="20"<?php if( $xrng==$xrgg ){echo ' checked="checked"';}?>><label for="rg1"> OTP<sup>∗∗∗∗</sup></label><br /> + <input type="radio" name="rng" id="rg2" value="16"<?php if( $xrng==$xrgp ){echo ' checked="checked"';}?>><label for="rg2"> OTP<sup>∗∗∗</sup></label><br /> + <input type="radio" name="rng" id="rg3" value="12"<?php if( $xrng==$xrot ){echo ' checked="checked"';}?>><label for="rg3"> OTP<sup>∗∗</sup></label><br /> + <input type="radio" name="rng" id="rg4" value="9"<?php if( $xrng==$xrok ){echo ' checked="checked"';}?>><label for="rg4"> OTP</label><br /> + <input type="radio" name="rng" id="rg5" value="8"<?php if( $xrng==$xr40 ){echo ' checked="checked"';}?>><label for="rg5"> OTP krótki</label><br /> + <input type="radio" name="rng" id="rg6" value="7"<?php if( $xrng==$xrtp ){echo ' checked="checked"';}?>><label for="rg6"> Regionalny<sup>∗</sup></label><br /> + <input type="radio" name="rng" id="rgD" value="6"<?php if( $xrng==$xrtd ){echo ' checked="checked"';}?>><label for="rgD"> Regionalny+40</label><br /> + <input type="radio" name="rng" id="rg7" value="5"<?php if( $xrng==$xrtr ){echo ' checked="checked"';}?>><label for="rg7"> Regionalny</label><br /> + <input type="radio" name="rng" id="rg8" value="3"<?php if( $xrng==$xrto ){echo ' checked="checked"';}?>><label for="rg8"> Okręgowy</label><br /> + <input type="radio" name="rng" id="rg9" value="2"<?php if( $xrng==$xrtk ){echo ' checked="checked"';}?>><label for="rg9"> Klubowy</label></td> + <td align="CENTER" valign=top>UCZESTNIKÓW<br /> + <input type="text" id="iuc" name="iuc" maxlength="3" style="width:50px" onblur="valiuc(this,1)"<?php if( $iuc>0 ){echo ' value="'.$iuc.'"';}?>><br /> + <small>W zależności od typu<br />ilość indywidualistów,<br />par lub teamów</small></td> + <td align="CENTER" valign=top>ZAWODNIKÓW<br /> + <input type="text" id="izw" name="izw" readonly="readonly" maxlength="4" style="width:50px" onblur="valiuc(this,2)"<?php if( $izw>0 ){echo ' value="'.$izw.'"';}?>><br /> + <small>To pole jest wyliczane<br />automatycznie.</small></td> + <td align="CENTER" valign=top>SUMA WK<br /> + <input type="text" id="swk" name="swk" maxlength="7" style="width:70px" onblur="valiuc(this,3)"<?php if( $swk>0 ){echo ' value="'.$swk.'"';}?>><br /> + <small>Suma WK wszystkich<br />zawodników.</small></td> + </tr> + <tr> + <td align="CENTER" colspan="3">Średnie WK zawodnika w turnieju: + <input type="text" id="srd" name="srd" readonly="readonly"<?php if( $izw>0 ){echo ' value="'.$swk/$izw.'"';}?>><br /> + </td> + </tr> + <tr><td colspan="5"> </td></tr> + <tr> + <td align="CENTER" colspan="2"> + <input type="button" value="Policz PKLe" onclick="submitit()"></td> + <td colspan="3"> +<?php +if( $tab>0 ){ + echo '<input type="button" value="SQL dla Pary" onclick="document.getElementById(\'outsql\').style.display=(document.getElementById(\'outsql\').style.display==\'none\') ? \'block\' : \'none\';"> + <input type="button" value="SQL dla Teamów" onclick="document.getElementById(\'outsql2\').style.display=(document.getElementById(\'outsql2\').style.display==\'none\') ? \'block\' : \'none\';">'; +} else { + echo ' '; +} +?> + </td> + </tr> + <tr><td colspan="2" align="center"> +<?php +if( $tab>0 ){ + unset( $tabpkl ); + $lasti = 0; + echo '<table><tr><td class="t">Miejsce</td><td class="t"> PKL </td>'; + echo '<td class="s">dotychczas</td></tr>'; + $max = ceil(($swk/$izw)*$rng + $izw*$zaw); + if( $max<$minpkl ) $max = $minpkl; + $prem = 0; + switch( $rng ){ + case $rgg: + case $rgp: + $prcold = 0.1; + break; + case $rot: + $prcold = 0.1; + break; + case $rok: + case $r40: + $prcold = 0.06; + break; + case $rtp: + case $rtr: + $prcold = 0.06; + if( $dajp ){ + $prem = 3; + } + break; + case $rto: + $prcold = 0.05; + break; + case $rtk: + $prcold = 0.04; + break; + } + $zni = 1; + switch( $typ ){ + case 2: + $zni = 2; + break; + case 4: + $zni = 4; + break; + } + if( $prem>0 ){ + $d = 2; + } else { + $d = 0; + } + $maxold = ceil($prcold*$izw + 0.05*$swk); + $progu1 = $progu1*$iuc*0.01+1; + $progu2 = $progu2*$iuc*0.01+1; + $progu3 = $progu3*$iuc*0.01+1; // 0 pkl za ostatnie punktowane+1 + $progp1 = $max*$progp1*0.01; + $progp2 = $max*$progp2*0.01; + $sumn = 0 ; + $sumo = 0; + $i = 0; + $dok = 1 - 1e-15; // unikamy błędu ceil(2)=3; + do{ + $i++; + if( $i<=$progu1 ){ + $p = $progp1+($max-$progp1)*($progu1-$i)/($progu1-1); + } + elseif( $i<=$progu2 ){ + $p = $progp2+($progp1-$progp2)*($progu2-$i)/($progu2-$progu1); + } + elseif( $i<$progu3 ){ + $p = $progp3+($progp2-$progp3)*($progu3-$i)/($progu3-$progu2); + } + else $p=0; + if( ($p>0) || ($maxold>0) ){ + echo '<tr><td class="t">'.$i.'</td>'; + if( $p>0 ){ + $pkl_temp = ceil($p); + if (($pkl_temp - $p) < $dok){ + $p = $pkl_temp; + } else { + $p = round($p); + } + $tabkl[$i] = $p; + $lasti = $i; + echo '<td class="t">'.$p.'</td>'; + $sumn = $sumn + $p; + } else { + echo '<td class="p"> </td>'; + } + if( $maxold>0 ){ + echo '<td class="s">'; + if( $i>($iuc/2) ){ + echo '<del> '; + } else { + $sumo = $sumo + $maxold + $d; + } + echo ($maxold + $d); + if( $i>($iuc/2) ){ + echo ' </del>'; + } + echo '</td>'; + if( $maxold<10 ){ + switch( $typ ){ + case 4: + $zni = 2; + break; + case 2: + $zni = 1; + break; + } + } + $maxold = $maxold - $zni; + if( $prem>0 ){ + if( $prem==3 ){ + $d = 1; + } else { + if( $prem==1 ){ + $d = 0; + } + } + $prem = $prem - 1; + } + } else { + echo '<td class="p"> </td>'; + } + echo '</tr>'; + } + } while( (($p>0) || ($maxold>0)) && ($i<$iuc) ); + echo '<tr><td class="p">SUMA PKL</td><td class="t">'.$typ*$sumn.'</td><td class="s">'.$typ*$sumo.'</td></tr>'; + echo '</table>'; +} else { + echo ' '; +} +?> +</td><td colspan="3" valign="top"><span id="outsql" style="display: none"> +<?php +echo "UPDATE `dodatki` SET `pkl`=0;<br />\r\n"; +for( $i=1; $i<=$lasti; $i++){ + echo "UPDATE `dodatki` SET `pkl`=".$tabkl[$i]." WHERE `miejsce`=".$i.";<br />\r\n"; +} +?> +</span></td> +<td colspan="3" valign="top"><span id="outsql2" style="display: none"> +<?php +echo "UPDATE `addons` SET `mastr`=0;<br />\r\n"; +for( $i=1; $i<=$lasti; $i++){ + echo "UPDATE `addons` SET `mastr`=".$tabkl[$i]." WHERE `place`=".$i.";<br />\r\n"; +} +?> +</span></td></tr> +<tr><td colspan="5" class="copyright">©'2009, Jan Romański dla PZBS</td></tr> +</table> +</form> +</body> +</html> |