<?
include("dbasecon.inc.php");
include("session.inc.php");
include ("header.php");
include ("score_functions.inc.php");
/*There is no edit function. TO edit a scorecard, just create a new one with the same date. it will write it over.
I did attempt to do a score card edit function but its a WIP. Feel free to hack scorecardedit.php if you want and
just put a submit button to link that page on this one.*/
$usersql="Select * from users_tour
where userid = '$login_id' ";
$userquery=mysql_query($usersql);
$userrow=mysql_fetch_array($userquery);
extract($userrow);
if ($HTTP_POST_VARS['delete']) {
//then, lets delete everything from all holes that has this gameid and this userid
$hole=0;
do {
$hole++;
$table="hole$hole";
$holedelsql= "Delete From $table where (gameid='$gameid') and (userid='$login_id')";
//echo $holedelsql."<br>";
$holedelresult=mysql_query($holedelsql);
} while ($hole<18);
//now we delete from games
$gamedelsql= "Delete From games where (gameid='$gameid') and (userid='$login_id')";
$gamedelresult=mysql_query($gamedelsql);
$hole=0;
/*
do {
$hole++;
$table="hole$hole";
//First, the tough part, readjust substat!
//1. get the total drive for this game
$holegetsql= "Select * From $table where (gameid='$gameid' and userid='$login_id')";
$holegetresult=mysql_query($holegetsql);
$holegetrow=mysql_fetch_array($holegetresult);
$holegetexist=mysql_numrows($holegetresult);
extract($holegetrow);
$total_drive_distance=$total_drive_distance+$drive_distance;
//2.get the number of drives
} while ($hole<18);
*/
//mainstats1 is different from mainstats just by the query. Here we only query one game. Not all games.
include("mainstats.inc.php");
include("substats.inc.php");
//first get the current total money and total points
$moneypointssql="Select total_money,total_points from ranking where userid='$login_id'";
$moneypointsquery=mysql_query($moneypointssql);
$moneypointsrow=mysql_fetch_array($moneypointsquery);
$total_mny=$moneypointsrow["total_money"];
$total_pts=$moneypointsrow["total_points"];
$statsdelsql="DELETE FROM ranking where userid='$login_id'";
$statsdelresult=mysql_query($statsdelsql);
$statsaddsql = "INSERT INTO ranking (userid, ddistance, daccuracy, dlongest, girpct, puttavg, puttround, sandsavepct,
totaleagles, totaldoubleeagles, totalholeinone, birdieavg, paravg, avgscore, parbreakers, par3birdies, par4birdies, par5birdies, par3pars,
par4pars, par5pars, par3perf, par4perf, par5perf, scrambling, net_totaleagles, net_totaldoubleeagles, net_totalholeinone, net_birdieavg, net_paravg,
net_avgscore, net_parbreakers, net_par3birdies, net_par4birdies, net_par5birdies, net_par3pars, net_par4pars,
net_par5pars, net_par3perf, net_par4perf, net_par5perf, net_scrambling, total_money, total_points)
VALUES
('$login_id', '$driving_distance', '$pct_fairways_hit', '$longest_drive1', '$pct_gir', '$avg_putt', '$putts_per_round', '$pct_sandsaves',
'$total_eagles', '$total_double_eagles', '$total_holeinone', '$avg_birdie', '$avg_par', '$avg_gross', '$pct_parbreak', '$par3_birdie_pct', '$par4_birdie_pct',
'$par5_birdie_pct', '$par3_par_pct', '$par4_par_pct', '$par5_par_pct', '$par3_avg_score', '$par4_avg_score',
'$par5_avg_score', '$scrambling_pct',
'$net_total_eagles', '$net_total_double_eagles', '$net_total_holeinone', '$net_avg_birdie', '$net_avg_par', '$avg_net', '$net_pct_parbreak', '$net_par3_birdie_pct',
'$net_par4_birdie_pct', '$net_par5_birdie_pct', '$net_par3_par_pct', '$net_par4_par_pct', '$net_par5_par_pct',
'$net_par3_avg_score', '$net_par4_avg_score',
'$net_par5_avg_score', '$net_scrambling_pct', '$total_mny', '$total_pts')";
$statsaddresult=mysql_query($statsaddsql);
//delete from substats
$substatsdelsql="DELETE FROM substats where userid='$login_id'";
$substatsdelresult=mysql_query($substatsdelsql);
//do the substats
$substatsaddsql="INSERT INTO substats (userid, total_drive_distance, total_drive, total_fairways_hit, poss_fairways,
total_gir, total_bunker, total_sandsave,total_holes, total_putts2, total_holes_putt, total_birdies, total_rounds, total_par, total_gross,
total_parbreak, total_putts1, total_putt_rounds, net_total_birdies, net_total_par, total_net, net_total_parbreak,
par3_birdies, par4_birdies, par5_birdies, par3_pars, par4_pars, par5_pars, total_par3, total_par4, total_par5,
total_par3_scores, total_par4_scores, total_par5_scores, scrambled_holes, missed_gir, net_par3_birdies,
net_par4_birdies, net_par5_birdies, net_par3_pars, net_par4_pars, net_par5_pars, net_par3_scores, net_par4_scores,
net_par5_scores, net_scrambled_holes)
VALUES
('$login_id', '$total_drive_distance', '$total_drive', '$total_fairways_hit', '$poss_fairways', '$total_gir', '$total_bunker2', '$total_sandsave',
'$total_holes', '$total_putts2', '$total_holes_putt', '$total_birdies', '$total_rounds', '$total_par', '$total_gross',
'$total_parbreak', '$total_putts1', '$total_putt_rounds', '$net_total_birdies', '$net_total_par', '$total_net', '$net_total_parbreak',
'$par3_birdies','$par4_birdies', '$par5_birdies', '$par3_pars', '$par4_pars', '$par5_pars', '$total_par3', '$total_par4', '$total_par5',
'$total_par3_scores', '$total_par4_scores', '$total_par5_scores', '$scrambled_holes', '$missed_gir', '$net_par3_birdies',
'$net_par4_birdies', '$net_par5_birdies', '$net_par3_pars', '$net_par4_pars', '$net_par5_pars', '$net_par3_scores', '$net_par4_scores',
'$net_par5_scores', '$net_scrambled_holes')";
$substatsaddresult=mysql_query($substatsaddsql);
}//endif delete
$gamesql="select *, date_format(date,'%d/%m/%Y') as real_date from games LEFT JOIN courses
ON games.courseid=courses.courseid
where games.userid = '$login_id'
order by games.date desc";
$gamequery=mysql_query($gamesql);
$gamerow=mysql_fetch_array($gamequery);
$gameexist=mysql_numrows($gamequery);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<? showheader("View Scores"); ?>
<p>
<?
if ($gameexist) {
echo "<b>Click on details for full scorecard.</b><p>";
echo "<b><u>Rounds played : $gameexist</u></b><p>";
?>
<table border=1>
<tr class="menu-bg">
<td>Game ID</td><td>Date</td><td>Course Name</td><td>Handicap</td><td>Gross Score</td><td>Net Score</td><td>Score Cards</td>
</tr>
<?
do {
extract($gamerow);
echo "<FORM method=\"post\" action=\"$PHP_SELF\">";
echo "<tr><td class='menu-bg2'>$gameid</td><td>$real_date</td><td><a href='statscourse2.php?courseid=$courseid&action=view'>$coursename</a></td>";
echo "<td>$handicap</td><td>$gross_score</td><td>$net_score</td>";
echo "<td>
<INPUT type='button' value='Details' onClick=\"window.open('scoreview1.php?gameid=$gameid','ScoreCard','scrollbars=yes,width=800,height=670,left=100,top=0')\">
<INPUT type='submit' name='delete' value='Delete' onclick=\"return confirm('Are you sure you want to delete the scorecard for game $gameid?');\" >
</td>";
echo "</tr>";
echo "<input type=\"Hidden\" name=\"courseid\" value=\"$courseid\">";
echo "<input type=\"Hidden\" name=\"gameid\" value=\"$gameid\">";
echo "</FORM>";
} while ($gamerow=mysql_fetch_array($gamequery)); //endif main loop of games
?>
</table>
<?
} else {
echo "You don't have any scorecards yet. Please enter score cards <a href='statsmain.php'>here</a>.";
} //endif gameexist
?>
<? showfooter(); ?>