"; //echo "Hmmm: " . $_SERVER['REMOTE_ADDR'] . "
"; $page_size = 30; $current_season = getCurrentSeason(); switch ($action) { Case "deleteScore": $scoreID = $_POST['scoreID']; if($scoreID > 0) { deleteScore($scoreID); } break; Case "editScoreForm": $scoreID = $_GET['scoreID']; showEditScoreForm($scoreID); break; Case "updateScore": if(isset($_POST['scorePlayerID']) AND isset($_POST['scoreMachineID']) AND isset($_POST['scoreScore']) AND isset($_POST['scoreCreatedDT']) AND isset($_POST['scoreID'])) { $playerID = $_POST['scorePlayerID']; $machineID = $_POST['scoreMachineID']; $score = $_POST['scoreScore']; $createdDT = $_POST['scoreCreatedDT']; $scoreID = $_POST['scoreID']; updateScore($playerID, $machineID, $createdDT, $score, $scoreID); } else { echo "Missing information. Please go back and complete the form."; } break; Case "addScoreForm": if(isset($_POST['scorePlayerID'])) { $playerID = $_POST['scorePlayerID']; } else {$playerID = "";} if(isset($_POST['scoreMachineID'])) { $machineID = $_POST['scoreMachineID']; } else {$machineID = "";} if(isset($_POST['scoreCreatedDT'])) { $createdDT = $_POST['scoreCreatedDT']; } else {$createdDT = "";} showAddScoreForm($playerID,$machineID,$createdDT); break; Case "multipleScoreSetupForm": showMultipleScoreSetupForm(); break; Case "setSetupDetails": setSetupDetails(); break; Case "addMultipleScoresForm": showAddMultipleScoresForm(); break; Case "addMultipleScores": $playerID = $_POST['scorePlayerID']; $createdDT = $_POST['scoreCreatedDT']; echo "
"; echo ""; echo ""; echo "
"; foreach ($_POST as $key => $value) { echo $key; echo " - "; echo $value; echo "
"; } $i = 1; While ($i < 9) { if( isset($_POST['scoreMachineID'.$i])) { $machineID = $_POST['scoreMachineID'.$i]; $score = $_POST['scoreScore'.$i]; if ($score != "") { addScore($playerID, $machineID, $createdDT, $score, $current_season); } } $i = $i + 1; } break; Case "multipleClipScoreSetupForm": showMultipleClipScoreSetupForm(); break; Case "setSetupClipDetails": setSetupClipDetails(); break; Case "addMultipleClipScoresForm": showAddMultipleClipScoresForm(); break; Case "addMultipleClipScores": $createdDT = $_POST['scoreCreatedDT']; $machineID = $_POST['scoreMachineID']; echo "
"; echo ""; echo ""; echo "
"; # foreach ($_POST as $key => $value) { # echo $key." - ".$value."
"; # } echo "machine: ".$machineID."
"; echo "created: ".$createdDT."
"; echo "season: ".$current_season."
"; $i = 1; While ($i < 60) { if( isset($_POST['scorePlayerID'.$i])) { $playerID = $_POST['scorePlayerID'.$i]; $score = $_POST['scoreScore'.$i]; if ($score != "") { addScore($playerID, $machineID, $createdDT, $score, $current_season); # echo "player: ".$playerID."
"; # echo "score: ".$score."
"; } } $i = $i + 1; } break; Case "addScore": if(isset($_POST['scorePlayerID']) AND isset($_POST['scoreMachineID']) AND isset($_POST['scoreScore']) AND isset($_POST['scoreCreatedDT'])) { $playerID = $_POST['scorePlayerID']; $machineID = $_POST['scoreMachineID']; $score = $_POST['scoreScore']; $createdDT = $_POST['scoreCreatedDT']; if(isset($_POST['scoreScore2'])) { $score2 = $_POST['scoreScore2']; } else {$score2 = "";} foreach ($_POST as $key => $value) { echo $key; echo " - "; echo $value; echo "
"; } addScore($playerID, $machineID, $createdDT, $score, $current_season); echo "
"; echo "SAME DAY, SAME PLAYER, SAME MACHINE
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
"; echo "
"; echo "
"; echo "SAME DAY, SAME PLAYER
"; echo ""; echo ""; echo ""; echo ""; echo "
"; echo "
"; echo "
"; echo "SAME DAY
"; echo ""; echo ""; echo ""; echo "
"; echo "
"; } else { echo "Missing data."; } break; Case "viewScores": $date = ""; $page = 0; $which = "ALL"; //ALL, BEST, HIGH $machineID = ""; $playerID = ""; $season = $current_season; If (isset($_GET['season'])) { $season = $_GET['season']; } If (isset($_GET['playerID'])) { $playerID = $_GET['playerID']; } If (isset($_GET['date'])) { if(isDate($_GET['date'])) { $date = date('Y-m-d', strtotime( $_GET['date'] )); } } If (isset($_GET['which'])) { $which = $_GET['which']; } If (isset($_GET['machineID'])) { $machineID = $_GET['machineID']; } If (isset($_GET['page'])) { $page = $_GET['page']; If ($page < 0 || $page > 100) { $page = 0; } } showScores($date,$playerID,$page,$which,$machineID,$page_size,$season); break; case "viewRanking": $date = ""; $page = 0; $machineID = ""; $playerID = ""; $season = $current_season; If (isset($_GET['season'])) { $season = $_GET['season']; } If (isset($_GET['playerID'])) { $playerID = $_GET['playerID']; } If (isset($_GET['date'])) { if(isDate($_GET['date'])) { $date = date('Y-m-d', strtotime( $_GET['date'] )); } } If (isset($_GET['machineID'])) { $machineID = $_GET['machineID']; } If (isset($_GET['page'])) { $page = $_GET['page']; If ($page < 0 || $page > 100) { $page = 0; } } showRankings($date,$playerID,$page,$machineID,$page_size,$season); break; case "viewStanding": $date = ""; $page = 0; $season = $current_season; If (isset($_GET['season'])) { $season = $_GET['season']; } If (isset($_GET['playerID'])) { $playerID = $_GET['playerID']; } If (isset($_GET['date'])) { if(isDate($_GET['date'])) { $date = date('Y-m-d', strtotime( $_GET['date'] )); } } If (isset($_GET['page'])) { $page = $_GET['page']; If ($page < 0 || $page > 100) { $page = 0; } } showStandings($date,$page,$page_size,$season); break; case "viewRankingValues": $season = $current_season; If (isset($_GET['season'])) { $season = $_GET['season']; } showRankingValues($season); break; case "updateRankingForSeason": $season = $current_season; If (isset($_GET['season'])) { $season = $_GET['season']; } updateRankingForSeason($season); break; case "updateRankings": $season = $current_season; If (isset($_GET['season'])) { $season = $_GET['season']; } $date = ""; If (isset($_GET['date'])) { if(isDate($_GET['date'])) { $date = $_GET['date']; } } if($date != "") { echo "Updating rankings for $date
"; updateRankingForDate($date); echo "Done
"; } else { echo "Please select a date:
"; $sql = "SELECT DISTINCT createdDT FROM P_scores WHERE season = '$season' ORDER BY createdDT"; $retval = mysql_query( $sql); if(mysql_num_rows($retval)) { while ($row = mysql_fetch_assoc($retval)) { $createdDT = date('Y-m-d', strtotime ($row['createdDT'])); echo "".$createdDT."
"; } } else { die('No dates found in P_scores' . mysql_error()); } echo "Dates From Ranks:
"; $sql = "SELECT DISTINCT date as createdDT FROM P_ranks WHERE season = '$season' ORDER BY createdDT"; $retval = mysql_query( $sql); if(mysql_num_rows($retval)) { while ($row = mysql_fetch_assoc($retval)) { $createdDT = date('Y-m-d', strtotime ($row['createdDT'])); echo "".$createdDT."
"; } } else { echo "No dates found in P_ranks"; } } break; Case Null: Default: echo "

LOPL Scores and Ranking

\n"; echo ""; break; } mysql_close(); echo ""; include 'footer.php'; #update this number to current season number function getCurrentSeason() { return 13; } function IsDate($string) { $t = strtotime($string); $m = date('m',$t); $d = date('d',$t); $y = date('Y',$t); return checkdate ($m, $d, $y); } Function addScore($playerID, $machineID, $createdDT, $score, $season) { $sql = "INSERT INTO P_scores " ."(playerID,machineID,createdDT,score,season) " ."VALUES ( '$playerID' ,'$machineID','$createdDT','$score','$season')"; $retval = mysql_query( $sql); if(! $retval ) { die('Could not enter data: ' . mysql_error()); } } Function deleteScore($scoreID) { $sql = "DELETE FROM P_scores WHERE scoreID=$scoreID"; $retval = mysql_query( $sql); if(! $retval ) { die('Could not delete data: ' . mysql_error()); } echo "Data deleted successfully\n"; } Function updateScore($playerID, $machineID, $createdDT, $score, $scoreID) { foreach ($_POST as $key => $value) { echo $key; echo " - "; echo $value; echo "
"; } echo "
"; $sql = "UPDATE P_scores " ." SET playerID= $playerID, machineID = $machineID, createdDT='$createdDT', score=$score " ."WHERE scoreID=$scoreID"; $retval = mysql_query( $sql); if(! $retval ) { die('Could not update data: ' . mysql_error()); } echo "Updated data successfully\n"; } Function setSetupClipDetails() { # foreach ($_POST as $key => $value) { # echo $key; # echo " - "; # echo $value; # echo "
"; # } # echo "
"; $i = 1; While ($i < 60) { if( isset($_POST['scorePlayerID'.$i])) { $playerID = $_POST['scorePlayerID'.$i]; $_SESSION['scorePlayerID'.$i]=$playerID; } $i = $i + 1; } $i = 1; While ($i < 9) { if( isset($_POST['scoreMachineID'.$i])) { $machineID = $_POST['scoreMachineID'.$i]; $_SESSION['scoreMachineID'.$i]=$machineID; } $i = $i + 1; } $_SESSION['scoreCreatedDT'] = $_POST['scoreCreatedDT']; showAddMultipleClipScoresForm(); } Function showMultipleClipScoreSetupForm() { echo "

Add New Scores Setup

"; echo "
"; echo ""; echo "\n"; $sql = "SELECT * FROM P_machines pm JOIN P_players pp ON pp.playerID = pm.ownerID WHERE pm.isActive=1 ORDER BY pm.name"; $machinelist = mysql_query($sql); $Max=mysql_numrows($machinelist); $m = 1; while($m < 9) { echo "\n"; $m = $m + 1; } $sql = "SELECT * FROM P_players pp WHERE pp.isActive=1 ORDER BY pp.FName"; $playerlist = mysql_query($sql); $Max=mysql_numrows($playerlist); $m = 1; while($m < 60) { echo "\n"; $m = $m + 1; } echo "
Date (YYYY-MM-DD)
Machine $m
Player $m
"; echo ""; echo ""; echo "
"; } Function showAddMultipleClipScoresForm() { $createdDT = ""; if (isset($_SESSION['scoreCreatedDT'])) { $createdDT = $_SESSION['scoreCreatedDT']; } echo "

Add New Scores

"; echo "
"; echo ""; echo "\n"; echo "\n"; $prcnt = $prcnt + 1; } } $i = $i + 1; } echo "
Date (YYYY-MM-DD)
Machine
".$i." ".$player_list_array[$playerID]."
"; if(($mrcnt > 0) and ($prcnt > 0)) { echo ""; echo ""; } else { echo "Please go back and select some machines and players before proceeding."; } echo "
"; } Function old_setSetupDetails() { foreach ($_POST as $key => $value) { echo $key; echo " - "; echo $value; echo "
"; } echo "
"; $i = 1; While ($i < 9) { if( isset($_POST['scoreMachineID'.$i])) { $machineID = $_POST['scoreMachineID'.$i]; $_SESSION['scoreMachineID'.$i]=$machineID; } $i = $i + 1; } $_SESSION['scoreCreatedDT'] = $_POST['scoreCreatedDT']; showAddMultipleScoresForm(); } Function old_showMultipleScoreSetupForm() { echo "

Add New Scores Setup

"; echo "
"; echo ""; echo "\n"; $sql = "SELECT * FROM P_machines pm JOIN P_players pp ON pp.playerID = pm.ownerID WHERE pm.isActive=1 ORDER BY pm.name"; $machinelist = mysql_query($sql); $Max=mysql_numrows($machinelist); $m = 1; while($m < 9) { echo "\n"; $m = $m + 1; } echo "
Date (YYYY-MM-DD)
Machine $m
"; echo ""; echo ""; echo "
"; } Function old_showAddMultipleScoresForm() { /* foreach ($_SESSION as $key => $value) { echo $key; echo " - "; echo $value; echo "
"; } */ $createdDT = ""; if (isset($_SESSION['scoreCreatedDT'])) { $createdDT = $_SESSION['scoreCreatedDT']; } echo "

Add New Scores

"; echo "
"; echo ""; echo "\n"; echo "\n"; $sql = "SELECT * FROM P_machines pm JOIN P_players pp ON pp.playerID = pm.ownerID WHERE pm.isActive=1 ORDER BY pm.name"; $machinelist = mysql_query($sql); $Max=mysql_numrows($machinelist); $machine_list_array = array(); $i=0; while ($i < $Max) { $machineID = mysql_result($machinelist, $i, 'machineID'); $machine_list_array[$machineID] = mysql_result($machinelist, $i, 'pm.name')." (".mysql_result($machinelist, $i, 'acronym'). ") (".mysql_result($machinelist, $i, 'pp.FName')." ".mysql_result($machinelist, $i, 'pp.LName').")"; $i = $i + 1; } $i = 1; $rcnt = 0; While ($i < 9) { if (isset($_SESSION['scoreMachineID'.$i])) { if($_SESSION['scoreMachineID'.$i] != "") { $machineID = $_SESSION['scoreMachineID'.$i]; echo "\n"; $rcnt = $rcnt + 1; } } $i = $i + 1; } echo "
Date (YYYY-MM-DD)
Player
Score for $machine_list_array[$machineID]
"; if($rcnt > 0) { echo ""; echo ""; } else { echo "Please go back and select some machines before proceeding."; } echo "
"; } Function showAddScoreForm($playerID,$machineID,$createdDT) { echo "

Add New Score

"; echo "
"; echo ""; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
Date (YYYY-MM-DD)
Player
Machine
Score
"; echo ""; echo ""; echo "
"; } Function showEditScoreForm($scoreID) { $sql = "SELECT * FROM P_scores WHERE scoreID=$scoreID"; $response = mysql_query($sql); if(mysql_numrows($response) == 0) { echo "

Can't edit: Score not found.

"; } else { echo "

Edit Score

"; echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo "
Date (YYYY-MM-DD)
Player
Machine
Score
"; echo ""; echo ""; echo ""; echo "
"; echo "

"; echo "
"; echo ""; echo ""; echo ""; echo "
"; } } Function showScores($date,$playerID,$page,$which,$machineID,$page_size,$season) { if($which == "HIGH") { $sql = "SELECT createdDT, score, ps.scoreID, season, " ."p.FName, p.LName, p.initials, p.playerID, " ."m.acronym, m.name " ."FROM P_scores ps " ."INNER JOIN( " ." SELECT machineID, scoreID, max(score) maxscore " ." FROM P_scores " ." WHERE 1=1 "; if($date) { $sql = $sql." AND createdDT = '$date' "; } if($season != 0) { $sql = $sql. "AND season = '$season' "; } if($playerID) { $sql = $sql."AND playerID = '$playerID' "; } if($machineID) { $sql = $sql." AND machineID = '$machineID' "; } $sql = $sql." GROUP BY machineID " ." ) ss on ps.machineID = ss.machineID AND ps.score = ss.maxscore " ." JOIN P_players p " ." ON p.playerID = ps.playerID " ." JOIN P_machines m " ." ON m.machineID = ps.machineID"; $sql = $sql." ORDER BY createdDT ASC"; } elseif($which == "HIGH2") { /*$date ="";*/ $sql = "select s.*, p.* , m.* " . "from P_scores as s " . "left outer join P_scores as xx on xx.machineID = s.machineID " . "and xx.score > s.score "; $sql = $sql."INNER JOIN P_players p ON p.playerID = s.playerID "; $sql = $sql."INNER JOIN P_machines m ON m.machineID = s.machineID WHERE 1=1 "; $sql = $sql. "AND xx.score is null "; //highscore for date doesn't make sense - that's like best if($date) { $sql = $sql." AND s.createdDT='$date' "; } if($playerID) { $sql = $sql."AND s.playerID=$playerID "; } if($machineID) { $sql = $sql." AND s.machineID = '$machineID' "; } if($season != 0) $sql = $sql. "AND s.season = '$season' "; $sql = $sql." ORDER BY createdDT ASC"; /* LIMIT " .$page*$page_size .",$page_size";*/ } else { if($which == "BEST") { $sql = "SELECT p.*, m.*, score, createdDT, scoreID " ." FROM P_scores as T JOIN P_players as p ON p.playerID = T.playerID JOIN P_machines m ON T.machineID = m.machineID" ." WHERE 1=1 "; $sql = $sql. "AND T.season = '$season' "; if($date) { $sql = $sql." AND T.createdDT = '$date' "; } if($playerID) { $sql = $sql." AND T.playerID = $playerID "; } if($machineID) { $sql = $sql." AND T.machineID = '$machineID' "; } $sql = $sql." AND score" ." = ( select max(score)" ." from P_scores" ." WHERE playerID = T.playerID" ." AND machineID = T.machineID" ." AND createdDT = T.createdDT ) "; if($machineID) { $sql = $sql." ORDER BY score DESC "; } else { if($playerID) { $sql = $sql." ORDER BY p.FName, m.name "; } else { $sql = $sql." ORDER BY m.name, score DESC "; } } /*$sql = $sql." LIMIT " .$page*$page_size .",$page_size";*/ } else { $sql = "SELECT p.*, m.*, s.* "; if($which == "BEST") { $sql = $sql.", MAX(score) AS score "; } else { $sql = $sql.", score "; } $sql = $sql."FROM P_players p JOIN P_scores s ON p.playerID = s.playerID JOIN P_machines m " ."ON s.machineID = m.machineID WHERE 1=1 "; $sql = $sql. "AND s.season = '$season' "; if($playerID) { $sql = $sql."AND p.playerID=$playerID "; } if($date) { $sql = $sql." AND s.createdDT = '$date' "; } if($machineID) { $sql = $sql." AND s.machineID = '$machineID' "; } if($which == "BEST") {$sql = $sql."GROUP BY p.playerID, s.machineID,s.createdDT"; } $sql = $sql." ORDER BY m.name, score DESC "; /*$sql = $sql." LIMIT " .$page*$page_size .",$page_size";*/ } } //echo $sql; $response = mysql_query($sql); if(! $response ) { die('Could not get data: ' . mysql_error()); } echo "Season "; $i = 1; while ($i <= getCurrentSeason() ) { if ($season == $i) { echo $i." / "; } else { echo " ".$i." / "; } $i = $i+1; } echo "
"; If ($response != "") { $numdates = 0; $sql = "SELECT DISTINCT createdDT FROM P_scores WHERE season = '$season' ORDER BY createdDT"; $retval = mysql_query( $sql); $numdates = mysql_num_rows($retval); if($numdates > 0) { $datelist = array(); while ($row = mysql_fetch_array($retval)) { $datelist[] = $row['createdDT']; } echo "Dates: "; for ($i = 0; $i < $numdates; $i++) { $createdDT = date('Y-m-d', strtotime ($datelist[$i])); if ($createdDT != $date) { echo "".$createdDT." / "; } else { echo $createdDT." / "; } } if($date) { echo "ALL"; } else { echo "ALL"; } } echo "
"; $Max=mysql_numrows($response); /* if($date <> '') { echo "Page "; $i = 0; while ($i < 10) { if ($page == $i) { echo ($i+1)." "; //($i*$page_size+1)."-".(($i+1)*$page_size)." "; } else { echo "".($i*$page_size+1)."-".(($i+1)*$page_size)." "; echo "&page=" . $i . "\">".($i+1)." "; } $i = $i + 1; } } */ if($playerID) { echo "(SHOW ALL PLAYERS)"; } if($machineID) { echo "(SHOW ALL MACHINES)"; } if($date) { echo "(SHOW ALL DATES)"; } if($which == "BEST") { echo "(ALL)"; echo "(HIGH)"; } elseif($which == "ALL") { echo "(BEST)"; echo "(HIGH)"; } else { echo "(ALL)"; echo "(BEST)"; } $i=0; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; if (isset($_SESSION['loggedinadmin'])) { echo ""; } echo "\n"; echo "\n"; echo "\n"; $evenodd = 0; While ($i < $Max) { if($evenodd==0) { echo ""; } else { echo ""; } $evenodd = 1-$evenodd; echo ""; echo ""; echo ""; echo ""; if (isset($_SESSION['loggedinadmin'])) { echo ""; } echo "\n"; $i = $i + 1; } echo "\n"; echo "
Player Name
"; echo "
Machine
"; echo "
Date
"; echo "
Score
"; echo "
ADMIN OPTION
"; if($playerID) { //link to player info echo "". mysql_result($response, $i, "p.FName")." ".mysql_result($response, $i, "p.LName")." (".mysql_result($response, $i, "p.initials").")"; } else { echo "\">".mysql_result($response, $i, "p.initials").""; } } else { //link to score for this player echo "". mysql_result($response, $i, "p.FName")." ".mysql_result($response, $i, "p.LName")." (".mysql_result($response, $i, "p.initials").")"; } else { echo "\">".mysql_result($response, $i, "p.initials").""; } } echo ""; if($machineID) { echo mysql_result($response, $i, "m.name"); } else { //link to scores for this machine echo "". mysql_result($response, $i, "m.name").""; } if (isset($_SESSION['loggedin'])) { echo "(INFO)"; } echo ""; if($date OR $which == "HIGH") { echo date('Y-m-d', strtotime (mysql_result($response, $i, "createdDT"))); } else { //link to score for this date echo "".date('Y-m-d', strtotime (mysql_result($response, $i, "createdDT"))).""; } echo "" . number_format(mysql_result($response, $i, "score")) ."
"; } else { echo "No results."; } echo ""; } function showRankingValues($season) { if($season < 3) { $sql = "SELECT * FROM `P_rankvalues` LIMIT 0, 25 "; $result = mysql_query($sql); if(! $result ) { die('Could not get data: ' . mysql_error()); } echo "

Point Scaling

"; echo "

On a given night, based on the number of machines played and the rank of your best score on a machine, you are awarded raw points.
"; echo "Eg. With 16 people playing on 4 machines you could earn 30 points for a 1st ranked score or 25 points for 2nd place, etc.
"; echo "In total for any night that we play, you have a chance at receiving a max of 120 raw points (eg. 4 machines * 30 points).

"; echo "

On a night with 12 or fewer participants, that raw score is scaled down by a certain factor.
"; echo "With only 8 players, if you were to get top score on all 4 machines that night you'd end up with 20 points (120 pts / 6)

"; echo "

On nights with more than 20 participants we play on more than 4 machines.
"; echo "The top score of 30 is for 4 machines so we scale it down by a factor of 4/5 or 4/6 to 4/7 or 4/8 giving you 24, 20, 17 or 15 points respectively.
"; echo "If you were to get top score on all machines for that night you'd still end up with 120 raw points (4*30, 5*24, 6*20, 7*17 or 6*20 pts)

"; echo "

Ideally we want at least 12 people playing on 4 machines to make the scoring system as balanced as possible."; echo "Fewer players means fewer points.

"; echo ""; echo ""; echo "
"; echo "

Ranking Table - Raw Pts

"; echo ""; echo ""; echo ''; echo ''; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $i = 0; while ($i < 25) { echo ""; echo ""; echo ""; $fraction = intval(mysql_result($result, $i, 'value')*4/5); if($fraction < 1) $fraction = 1; echo ""; $fraction = intval(mysql_result($result, $i, 'value')*4/6); if($fraction < 1) $fraction = 1; echo ""; $fraction = intval(mysql_result($result, $i, 'value')*4/7); if($fraction < 1) $fraction = 1; echo ""; $fraction = intval(mysql_result($result, $i, 'value')*4/8); if($fraction < 1) $fraction = 1; echo ""; echo ""; $i = $i+1; } echo "
RankMachines
45678
".($i+1)."".mysql_result($result, $i, 'value')."".$fraction."".$fraction."".$fraction."".$fraction."
"; echo "
"; echo "

Scaling Table - Points

"; echo ""; echo ""; echo ''; echo ''; echo ''; echo ''; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $i = 0; while ($i < 25) { echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $i = $i+1; } echo "
PlayersRawScale
Factor
Scaled
MaxMinMaxMin
".($i+1)."".(mysql_result($result, 0, 'value')*4)."".(mysql_result($result, $i, 'value')*4)."".mysql_result($result, $i, 'scale')."".intval(mysql_result($result, 0, 'value')*4/mysql_result($result, $i, 'scale'))."".intval(mysql_result($result, $i, 'value')*4/mysql_result($result, $i, 'scale'))."
"; echo "
"; } else { echo "

Percentage Scoring

"; echo "

Your scores from each league night will be entered into the database.
"; echo "Based on your placement against all players who played that machine that night "; echo "you will be awarded a percentage score.

"; echo "

For each machine:
"; echo "( (Number_of_players + 1) - (Your_position) ) / (Number_of_players) X 100
"; echo "
"; echo "eg.
"; echo "On a night with 40 players you get 3rd best score on game A.
"; echo "Your points would be ((40+1)-3)/40 X 100 = 38/40 = 95%
"; echo "1st gets 100%, 2nd gets 97.5%, last place gets 2.5%
"; echo "
"; echo "We then average out the totals for all machines that night.

"; echo "

You must attend at least 4 league nights to qualify for playoffs.
"; echo "Your ranking scores from your best 8 nights determine your standings.

"; } } function showStandings($date,$page,$page_size,$season) { $usepage = 0; //build query $sql = "SELECT season, date, p.playerID, FName, LName, Initials, GROUP_CONCAT(points ORDER BY date ASC) AS points, AVG(points) AS total FROM P_standings r JOIN P_players p on r.playerID = p.playerID "; if($date) { //show points for this date $sql = $sql." AND r.date = '$date' "; $sql = $sql. "AND season = '$season' "; $sql = $sql." GROUP BY date, r.playerID ORDER BY total DESC "; } else { //show cummulative points $sql = $sql. "AND season = '$season' "; $sql = $sql." GROUP BY r.playerID ORDER BY total DESC "; } if($usepage) { $sql = $sql." LIMIT " .$page*$page_size .",$page_size"; } // Perform Query $result = mysql_query($sql); if(! $result ) { die('Could not get data: ' . mysql_error()); } echo "Season "; $i = 1; while ($i <= getCurrentSeason() ) { if ($season == $i) { echo $i." / "; } else { echo " ".$i." / "; } $i = $i+1; } echo "
"; $numdates = 0; $sql = "SELECT DISTINCT createdDT FROM P_scores WHERE season = '$season' ORDER BY createdDT "; $retval = mysql_query( $sql); $numdates = mysql_num_rows($retval); if($numdates > 0) { $datelist = array(); while ($row = mysql_fetch_array($retval)) { $datelist[] = $row['createdDT']; } echo "Dates: "; for ($i = 0; $i < $numdates; $i++) { $createdDT = date('Y-m-d', strtotime ($datelist[$i])); if ($createdDT != $date) { echo "".$createdDT." / "; } else { echo $createdDT." / "; } } if($date) { echo "ALL"; } else { echo "ALL"; } } echo "
"; if($date) { echo "

Points Earned on $date

"; } else { echo "

Cummulative Points

"; } echo ""; echo ""; echo ""; echo ""; $numBest = $numdates; if ($numBest < 1) $numBest = 1; if ($season < 4) { if ($numBest > 8) $numBest = 8; $qualify_number = 4; } elseif ($season < 6) { if ($numBest > 5) $numBest = 5; $qualify_number = 5; } else { if ($numBest > 4) $numBest = 4; if ($season > 9) { if ($season > 10) { if ($numBest > 2) $numBest = 2; } $qualify_number = 2; } else { $qualify_number = 4; } } if( ! $date) { for ($i = 0; $i < $numdates; $i++) { echo ""; } echo ""; # echo ""; echo ""; echo ""; # echo ""; echo ""; } else { echo ""; } echo "\n"; echo "\n"; $i= 1; $evenodd = 0; while ($row = mysql_fetch_assoc($result)) { if($row['total'] > 0) { if($evenodd==0) { echo ""; } else { echo ""; } $evenodd = 1-$evenodd; echo ""; echo ""; if(! $date) { $myArray = explode(',', $row['points']); for ($j = 0; $j < $numdates; $j++) { echo ""; } //get the total $sum = 0; $numNonZero = 0; for ($j = 0; $j < $numdates; $j++) { $sum = $sum + $myArray[$j]; if($myArray[$j] <> 0) { $numNonZero = $numNonZero+1; } } $avg1 = 0; $avg2 = 0; if($numNonZero > 0) { $avg1 = number_format((float) ($sum / $numdates), 2, '.', ''); $avg2 = number_format((float) ($sum / $numNonZero), 2, '.', ''); } # echo ""; echo ""; echo ""; //get the total, dropping the lowest ones rsort($myArray, SORT_NUMERIC); $sumBest = 0; for ($j = 0; $j < $numBest; $j++) { $sumBest = $sumBest + $myArray[$j]; } $avg = number_format((float) ($sumBest/ $numBest), 2, '.', ''); # echo ""; echo ""; if ($numNonZero >= $qualify_number) { echo ""; } else { echo ""; } } else { echo ""; } echo "\n"; $i = $i + 1; } } echo ""; echo "
PLACE
PLAYER
".date('M-d', strtotime ($datelist[$i]))."
SEASON AVG
AVG
PLAY AVG
BEST ".($numBest)."
BEST AVG
ELIGIBLE
POINTS
$i"; //link to score for this player echo "".$row['FName']." ".$row['LName']." (".$row['Initials'].")"; } else { echo "\">".$row['Initials'].""; } echo "".$myArray[$j]."".$row['total']."".$avg1."".$avg2."".$sumBest.""; /* for ($j = 0; $j < $numBest; $j++) { echo $myArray[$j]."+"; } */ echo $avg."YesNo ($numNonZero)".$row['total']."
"; if($usepage) { echo "Page "; $Max=mysql_numrows($result); $i = 0; while ($i < 10) { if ($page == $i) { echo ($i+1)." "; //($i*$page_size+1)."-".(($i+1)*$page_size)." "; } else { echo "".($i*$page_size+1)."-".(($i+1)*$page_size)." "; echo "&page=" . $i . "\">".($i+1)." "; } $i = $i + 1; } } echo "

"; # echo ""; ?> ".$i." / "; } $i = $i+1; } echo "
"; $numdates = 0; $sql = "SELECT DISTINCT createdDT FROM P_scores WHERE season = $season ORDER BY createdDT"; $retval = mysql_query( $sql); $numdates = mysql_num_rows($retval); if($numdates > 0) { $datelist = array(); while ($row = mysql_fetch_array($retval)) { $datelist[] = $row['createdDT']; } echo "Dates: "; for ($i = 0; $i < $numdates; $i++) { $createdDT = date('Y-m-d', strtotime ($datelist[$i])); if ($createdDT != $date) { echo "".$createdDT." / "; } else { echo $createdDT." / "; } } if($date) { echo "ALL"; } else { echo "ALL"; } } echo "
"; $Max=mysql_numrows($result); /*echo "Page "; $i = 0; while ($i < 10) { if ($page == $i) { echo ($i+1)." "; //($i*$page_size+1)."-".(($i+1)*$page_size)." "; } else { echo "".($i*$page_size+1)."-".(($i+1)*$page_size)." "; echo "&page=" . $i . "\">".($i+1)." "; } $i = $i + 1; } */ if($date) { echo "(SHOW ALL DATES)"; } if($playerID) { echo "(SHOW ALL PLAYERS)"; } if($machineID) { echo "(SHOW ALL MACHINES)"; } echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; $total= 0; $evenodd = 0; while ($row = mysql_fetch_assoc($result)) { if($evenodd==0) { echo ""; } else { echo ""; } $evenodd = 1-$evenodd; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "\n"; $total = $total + $row['points']; } if($playerID AND $Max > 1) { #average for the night $avg1 = number_format((float) ($total/$Max), 2, '.', ''); echo ""; echo ""; echo ""; echo "\n"; } echo "
DATE
"; echo "
PLAYER
"; echo "
MACHINE
"; echo "
SCORE
RANK
POINTS
"; if($date) { echo date('Y-m-d', strtotime ($row['date'])); } else { //link to score for this date echo "".date('Y-m-d', strtotime ($row['date'])).""; } echo ""; if($playerID) { //link to player info echo "". $row['FName']." ".$row['LName']." (".$row['Initials'].")"; } else { echo "\">".$row['Initials'].""; } } else { //link to score for this player echo "".$row['FName']." ".$row['LName']." (".$row['Initials'].")"; } else { echo "\">".$row['Initials'].""; } } echo ""; if($machineID) { echo $row['name']; } else { //link to scores for this machine echo "".$row['name'].""; } if (isset($_SESSION['loggedin'])) { echo "(INFO)"; } echo "".number_format($row['score'])."".$row['rank']."".$row['points']."
Average For the Night".$avg1."
\n"; echo ""; } function updateRankingForSeason($season) { echo "Updating rankings for season".$season; $sql = "SELECT DISTINCT date as createdDT FROM P_ranks WHERE season = '$season' ORDER BY createdDT"; $retval = mysql_query( $sql); if(mysql_num_rows($retval)) { while ($row = mysql_fetch_assoc($retval)) { $createdDT = date('Y-m-d', strtotime ($row['createdDT'])); updateRankingForDate($createdDT); } } else { echo "No dates found in P_ranks"; } } function updateRankingForDate($date) { echo "Updating rankings for ".$date; //delete old rankings for this date $sql = "DELETE FROM P_ranks " ." WHERE date = '$date' "; $retval = mysql_query( $sql); if(! $retval ) { die('Could not delete data: ' . mysql_error()); } $sql = "SELECT DISTINCT season FROM P_scores " ." WHERE createdDT = '$date' "; $retval = mysql_query( $sql); while ($row = mysql_fetch_assoc($retval)) { $season = $row['season']; } echo "season ".$season; $sql = "SELECT DISTINCT playerID FROM P_scores " ." WHERE createdDT = '$date' "; $retval = mysql_query( $sql); $num_players = mysql_num_rows($retval); echo "Players ".$num_players; $sql = "SELECT DISTINCT machineID FROM P_scores " ." WHERE createdDT = '$date' "; $retval = mysql_query( $sql); $num_machines = mysql_num_rows($retval); echo "Machines ".$num_machines; $sql = "SELECT DISTINCT machineID FROM P_scores " ." WHERE createdDT = '$date' "; $retval = mysql_query( $sql); if(mysql_num_rows($retval)) { while ($row = mysql_fetch_assoc($retval)) { $machineID = $row['machineID']; updateRankingMachine($date, $machineID, $num_players, $num_machines, $season); } } //delete old standings for this date $sql = "DELETE FROM P_standings " ." WHERE date = '$date' "; $retval = mysql_query( $sql); if(! $retval ) { die('Could not delete data: ' . mysql_error()); } //for all players, update standings for this date $sql = "SELECT playerID FROM P_players " ." WHERE isActive = 1 "; $retval = mysql_query( $sql); $num_players = mysql_num_rows($retval); if($num_players > 0) { while ($row = mysql_fetch_assoc($retval)) { $playerID = $row['playerID']; updatePlayerStandings($playerID, $date, $season); } } } function updateRankingMachine($date, $machineID, $num_players, $num_machines, $season) { if($season < 3) { $sql = "SELECT scale FROM P_rankvalues WHERE ID = ($num_players)"; $result = mysql_query($sql); if(! $result ) { die('Could not get data: ' . mysql_error()); } $row = mysql_fetch_assoc($result); $scalingfactor = $row['scale']; if($num_machines == 5) { $scalingfactor = $scalingfactor*5/4; } if($num_machines == 6) { $scalingfactor = $scalingfactor*6/4; } if($num_machines == 7) { $scalingfactor = $scalingfactor*7/4; } if($num_machines == 8) { $scalingfactor = $scalingfactor*8/4; } if($date != "" AND $machineID != "") { //build query $sql = "SELECT v.*, rank_number, playerID, score, machineID "; $sql .= "FROM ( "; $sql .= " SELECT @rank:=IF(@last_score=score, @rank, @rank+1) AS rank_number, playerID, score, machineID, @last_score:=score AS previous "; $sql .= " FROM ( "; $sql .= " SELECT pl.playerID, pm.machineID, MAX(ps.score) AS score "; $sql .= " FROM P_players pl "; $sql .= " JOIN P_scores ps ON pl.playerID = ps.playerID"; $sql .= " JOIN P_machines pm ON pm.machineID = ps.machineID"; $sql .= " WHERE 1=1 "; // score != 0 "; $sql .= " AND ps.machineID = $machineID "; $sql .= " AND ps.createdDT = '$date' "; $sql .= " GROUP BY pl.playerID "; $sql .= " ORDER BY score DESC"; $sql .= " ) AS rankings, (SELECT @rank:=0) AS r, (SELECT @last_score:=0) AS l "; $sql .= ") AS overall_rankings "; $sql .= " JOIN P_rankvalues v ON rank_number = v.ID "; $result = mysql_query($sql); if(! $result ) { die('Could not get data: ' . mysql_error()); } else { //loop through rankings and insert while ($row = mysql_fetch_assoc($result)) { $rowPlayerID = $row['playerID']; $rowMachineID = $row['machineID']; $rowDate = $date; $rowScore = $row['score']; $rowPoints = $row['value']/$scalingfactor; $rowRank = $row['rank_number']; //0 points for 0 scores - ie missed a league night if($rowScore == 0) { //$rowPoints = 0; } //create row $sql = "INSERT INTO P_ranks (playerID, machineID, date, rank, points, score, season) " ." VALUES ($rowPlayerID, $rowMachineID, '$rowDate', $rowRank, $rowPoints, $rowScore, $season)"; $retval = mysql_query( $sql); if(! $retval ){ die('Could not insert data: ' . mysql_error());} } } } } else { if($date != "" AND $machineID != "") { //build query $sql = "SELECT v.*, rank_number, playerID, score, machineID "; $sql .= "FROM ( "; $sql .= " SELECT @rank:=IF(@last_score=score, @rank, @rank+1) AS rank_number, playerID, score, machineID, @last_score:=score AS previous "; $sql .= " FROM ( "; $sql .= " SELECT pl.playerID, pm.machineID, MAX(ps.score) AS score "; $sql .= " FROM P_players pl "; $sql .= " JOIN P_scores ps ON pl.playerID = ps.playerID"; $sql .= " JOIN P_machines pm ON pm.machineID = ps.machineID"; $sql .= " WHERE 1=1 "; // score != 0 "; $sql .= " AND ps.machineID = $machineID "; $sql .= " AND ps.createdDT = '$date' "; $sql .= " GROUP BY pl.playerID "; $sql .= " ORDER BY score DESC"; $sql .= " ) AS rankings, (SELECT @rank:=0) AS r, (SELECT @last_score:=0) AS l "; $sql .= ") AS overall_rankings "; $sql .= " JOIN P_rankvalues v ON rank_number = v.ID "; $result = mysql_query($sql); if(! $result ) { die('Could not get data: ' . mysql_error()); } else { //loop through rankings and insert while ($row = mysql_fetch_assoc($result)) { $rowPlayerID = $row['playerID']; $rowMachineID = $row['machineID']; $rowDate = $date; $rowScore = $row['score']; $rowRank = $row['rank_number']; $rowPoints = (float) (($num_players+1)-$rowRank)/$num_players*100; //0 points for 0 scores - ie missed a league night if($rowScore == 0) { $rowPoints = 0; } //create row $sql = "INSERT INTO P_ranks (playerID, machineID, date, rank, points, score, season) " ." VALUES ($rowPlayerID, $rowMachineID, '$rowDate', $rowRank, $rowPoints, $rowScore, $season)"; $retval = mysql_query( $sql); if(! $retval ){ die('Could not insert data: ' . mysql_error());} } } } } } function updatePlayerStandings($playerID, $date, $season) { if($date != "" AND $playerID != "") { //get the rank and sum of points (from all machines) for this date $sql = "SELECT * FROM ( SELECT @rownum := @rownum +1 as rank, prequery.total, prequery.playerID "; $sql = $sql."FROM "; $sql = $sql."( SELECT @rownum := 0 ) sqlvars, "; if($season < 3) { $sql = $sql."( SELECT playerID, sum(points) AS total "; } else { $sql = $sql."( SELECT playerID, AVG(points) AS total "; } $sql = $sql."FROM P_ranks "; $sql = $sql."WHERE date = '$date' "; $sql = $sql."GROUP BY playerID, date "; $sql = $sql."ORDER BY sum(points) desc ) prequery ) as cc "; $sql = $sql."WHERE playerID = $playerID "; $result = mysql_query($sql); if(! $result ) { die('Could not get data: ' . mysql_error()); } else { if (mysql_numrows($result) == 0) { //no scores found for this player/date , set rank to 100 and points to 0 $rowPoints = 0; $rowRank = 100; } else { $row = mysql_fetch_assoc($result); $rowPoints = $row['total']; $rowRank = $row['rank']; } //create row $sql = "INSERT INTO P_standings (playerID, date, rank, points, season) " ." VALUES ($playerID, '$date', $rowRank, $rowPoints, $season)"; $retval = mysql_query( $sql); if(! $retval ){ die('Could not insert data: ' . mysql_error()."
".$sql);} } } } function oldshowStandings($date,$page,$page_size) { $usepage = 0; //build query $sql = "SELECT date, p.playerID, FName, LName, Initials, SUM(points) AS total FROM P_ranks r JOIN P_players p on r.playerID = p.playerID "; if($date) { //show points for this date $sql = $sql." AND r.date = '$date' "; $sql = $sql." GROUP BY date, r.playerID ORDER BY total DESC "; } else { //show cummulative points $sql = $sql." GROUP BY r.playerID ORDER BY total DESC "; } if($usepage) { $sql = $sql." LIMIT " .$page*$page_size .",$page_size"; } // Perform Query $result = mysql_query($sql); if(! $result ) { die('Could not get data: ' . mysql_error()); } /* $row = mysql_fetch_assoc($result); foreach ($row as $key => $value) { echo $key; echo " - "; echo $value; echo "
"; } echo "
"; */ $sql = "SELECT DISTINCT createdDT FROM P_scores ORDER BY createdDT "; $retval = mysql_query( $sql); if(mysql_num_rows($retval)) { echo "Dates: "; while ($row = mysql_fetch_assoc($retval)) { $createdDT = date('Y-m-d', strtotime ($row['createdDT'])); if ($createdDT != $date) { echo "".$createdDT." / "; } else { echo $createdDT." / "; } } if($date) { echo "ALL"; } else { echo "ALL"; } } echo "
"; if($date) { echo "

Points Earned on $date

"; } else { echo "

Cummulative Points

"; } echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $i= 1; while ($row = mysql_fetch_assoc($result)) { echo ""; echo ""; echo ""; echo ""; echo ""; $i = $i + 1; } echo "
PLACEPLAYERPOINTS
$i"; //link to score for this player echo "".$row['FName']." ".$row['LName']." (".$row['Initials'].")"; } else { echo "\">".$row['Initials'].""; } echo "".$row['total']."
"; if($usepage) { echo "Page "; $Max=mysql_numrows($result); $i = 0; while ($i < 10) { if ($page == $i) { echo ($i+1)." "; //($i*$page_size+1)."-".(($i+1)*$page_size)." "; } else { echo "".($i*$page_size+1)."-".(($i+1)*$page_size)." "; echo "&page=" . $i . "\">".($i+1)." "; } $i = $i + 1; } } echo "

"; } ?>