Location: PHPKode > projects > GolfstatsPHP > golfstatsphp_3.0/tournament2.php
<?
include("dbasecon.inc.php");
include("session.inc.php");
include ("header.php");
include ("statscoursefunctions.inc.php");

if ((!$HTTP_POST_VARS['addmsg']) && (!$HTTP_POST_VARS['deletemsg'])) {

$tourneyid=$HTTP_GET_VARS['tourney_id'];
//get list of tourneys
} else {
}

if ($tourneyid) {

$usersql="select userid as tourney_userid from games where gameid='$tourneyid' and tournament=1";
$userquery=mysql_query($usersql);
$userrow=mysql_fetch_array($userquery);
$userexist=mysql_numrows($userquery); //check to see if actually exist

$tourneysql="select *, date_format(date,'%d/%m/%Y') as real_date from tourney where tourneyid='$tourneyid'";
				$tourneyquery=mysql_query($tourneysql);
				$tourneyrow=mysql_fetch_array($tourneyquery);
				$tourneyexist=mysql_numrows($tourneyquery);
if ($tourneyexist) {
extract($tourneyrow);
} else {
echo "Application error.";
exit();
}

//now get the tourney venue details
$coursechecksql="select * from courses where courseid='$tourneyvenue'";
				$coursecheckquery=mysql_query($coursechecksql);
				$coursecheckrow=mysql_fetch_array($coursecheckquery);
				$coursecheckexist=mysql_numrows($coursecheckquery);

if ($coursecheckexist) {				
extract($coursecheckrow);
} else {
echo "Application error.";
exit();
}

//now get the champion details
$champsql="select *, userid as champ_id from users_tour where userid='$championid'";
				$champquery=mysql_query($champsql);
				$champrow=mysql_fetch_array($champquery);
				$champexist=mysql_numrows($champquery);

if ($champexist) {				
extract($champrow);
} else {
echo "Application error.";
exit();
}
		
		
//get the leaderboard!
//now get the leaderion details
$leadersql="select *, userid as leader_id from games where gameid='$tourneyid' and tournament=1 
						order by stableford DESC, net_score ASC, gross_score ASC";
				$leaderquery=mysql_query($leadersql);
				$leaderrow=mysql_fetch_array($leaderquery);
				$leaderexist=mysql_numrows($leaderquery);		
		
		
		
		//get the leader's purse		
		$moneysql="select *, userid as leader_id from games where gameid='$tourneyid' and userid='$champ_id'
						order by stableford DESC, handicap ASC, net_score ASC, gross_score ASC";
				$moneyquery=mysql_query($moneysql);
				$moneyrow=mysql_fetch_array($moneyquery);
				$moneyexist=mysql_numrows($moneyquery);		
				
				$winnermoney=$moneyrow['money'];
				
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<? showheader("Tournament::$tourneyname"); ?>
<table border=0 width=100%>
<tr>


<td align="center" width=50%>
<table border=1 width=90%>
<tr class="bg2">
<td align="center"><? echo "<b>$tourneyname";?></td></tr>
<tr class="bg2">
<td ALIGN="center"><? 
echo "$coursename, $coursestate <br>";
echo "$real_date <br>";
echo "$tourneytype <br>";
?></td></tr>

<tr class="bg2">
<td align="center">
<table border=0>
<tr class="bg2">
<td>
<?
$mugshot="mug_"."$champ_id".".jpg";
//$mugshot="mug_"."$pic".".jpg";
?>
<img src="images/<?echo $mugshot;?>" align="right" border="1">
</td>
<td>
<? 
echo "<b>Champion</b>: $name $surname <br>";
echo "<b>Winning Score</b>: $championscore <br>";
echo "<b>Winners Purse</b>: \$$winnermoney <br>";
?>
</td></tr>
</table>

</td></tr>

</table>

<p>

<?
//ok, now report back what has been done
$tourneystatsql2="select * from tourney_stat where tourneyid='$tourneyid'";
				$tourneystatquery2=mysql_query($tourneystatsql2);
				$tourneystatrow2=mysql_fetch_array($tourneystatquery2);
				$tourneystatexist2=mysql_numrows($tourneystatquery2);

extract($tourneystatrow2);


?>
<table border=1 width=90%>
<tr class="bg0">
<td colspan="4">
<b>Tournament Statistics
</td>
</tr>
<tr class="bg1"><td>Category</td><td>Gross</td><td>Net</td></tr>
<tr class=bg4><td class="bg2">Top Score</td><td><?echo "$top_gross_score";?></td><td><?echo "$top_net_score";?></td></tr>
<tr class=bg4><td class="bg2">Most Eagles</td><td><?echo "$top_gross_eagles";?></td><td><?echo "$top_net_eagles";?></td></tr>
<tr class=bg4><td class="bg2">Most Birdies</td><td><?echo "$top_gross_birdies";?></td><td><?echo "$top_net_birdies";?></td></tr>
<tr class=bg4><td class="bg2">Most Pars</td><td><?echo "$top_gross_pars";?></td><td><?echo "$top_net_pars";?></td></tr>
<tr class=bg4><td class="bg2">Most Bogeys</td><td><?echo "$top_gross_bogeys";?></td><td><?echo "$top_net_bogeys";?></td></tr>
<tr class=bg4><td class="bg2">Total Eagles</td><td><?echo "$total_gross_eagles";?></td><td><?echo "$total_net_eagles";?></td></tr>
<tr class=bg4><td class="bg2">Total Birdies</td><td><?echo "$total_gross_birdies";?></td><td><?echo "$total_net_birdies";?></td></tr>
<tr class=bg4><td class="bg2">Total Pars</td><td><?echo "$total_gross_pars";?></td><td><?echo "$total_net_pars";?></td></tr>
<tr class=bg4><td class="bg2">Total Bogeys</td><td><?echo "$total_gross_bogeys";?></td><td><?echo "$total_net_bogeys";?></td></tr>
<tr class=bg4><td class="bg2">Total Others</td><td><?echo "$total_gross_others";?></td><td><?echo "$total_net_others";?></td></tr>
<tr class=bg4><td class="bg2">Average Par 3 Scores</td><td><?echo "$par3avg_gross";?></td><td><?echo "$par3avg_net";?></td></tr>
<tr class=bg4><td class="bg2">Average Par 4 Scores</td><td><?echo "$par4avg_gross";?></td><td><?echo "$par4avg_net";?></td></tr>
<tr class=bg4><td class="bg2">Average Par 5 Scores</td><td><?echo "$par5avg_gross";?></td><td><?echo "$par5avg_net";?></td></tr>

<tr class="bg1"><td>Category</td><td colspan="2">Stat</td></tr>
<tr class=bg4><td class="bg2">Longest Drive</td><td colspan=2><?echo "$top_drive";?></td></tr>
<tr class=bg4><td class="bg2">Top GIR</td><td colspan=2><?echo "$top_gir";?></td></tr>
<tr class=bg4><td class="bg2">Top Sand Save</td><td colspan=2><?echo "$top_sandsave";?></td></tr>
<tr class=bg4><td class="bg2">Top Driving Accuracy</td><td colspan=2><?echo "$top_fairway_hit";?></td></tr>
<tr class=bg4><td class="bg2">Top Putts per Round</td><td colspan=2><?echo "$top_putts";?></td></tr>


</table>

<p class=bg0>
<b>Gallery</b>
</p>
<img src="images/<?echo $tourneyid.'a.jpg';?>" height="320" width="400"><p>

</td>
<td width=50%>

<table border=1 width=100%>
<tr class="bg0">
<td colspan="7">
<b>Full Leaderboard
</td>
</tr>
<tr class="bg2">
<td>&nbsp;</td><td>Player Name</td><td>Handicap</td><td>Gross Score</td><td>Net Score</td><td>Points</td><td>Card</td>
</tr>
<?
$playerposition=0;
if ($leaderexist) {				

do {
extract($leaderrow);
$playerposition++;		
//now get the player details
$leaderusersql="select name as leader_name, surname as leader_surname, userid as leaderboard_id from users_tour where userid='$leader_id'";
				$leaderuserquery=mysql_query($leaderusersql);
				$leaderuserrow=mysql_fetch_array($leaderuserquery);
				$leaderuserexist=mysql_numrows($leaderuserquery);


extract($leaderuserrow);

//ok, lets count to coursepar
$gross_par=$gross_score-$coursepar;
$net_par=$net_score-$coursepar;

if ($gross_par > 0) {
$gross_par="+"."$gross_par";
} elseif ($gross_par==0) {
$gross_par="E";
}

if ($net_par > 0) {
$net_par="+"."$net_par";
} elseif ($net_par==0) {
$net_par="E";
}

echo "<tr class='bg4'><td>$playerposition</td><td><a href='players2.php?userid=$leaderboard_id&action=details&fullname=$leader_name $leader_surname'>$leader_name $leader_surname</a>
</td><td>$handicap</td><td>$gross_score [$gross_par]</td><td>$net_score [$net_par]</td><td>$stableford</td>
<td><a href='#' title=\"$tourneyid\" onClick=\"window.open('players3.php?userid=$leaderboard_id&gameid=$tourneyid','$tourneyid','left=100,top=0,height=730,width=620,scrollbars=yes');return false;\">[+]</a></td>
</tr>";



//lets keep track of the total for each column so we can divide it later for average
//1.handicap
$total_handicap=$total_handicap+$handicap;
//2.gross
$total_gross_score=$total_gross_score+$gross_score;
$total_gross_par=$total_gross_par+$gross_par;

//2.net
$total_net_score=$total_net_score+$net_score;
$total_net_par=$total_net_par+$net_par;

//4.stableford
$total_stableford=$total_stableford+$stableford;



} while ($leaderrow=mysql_fetch_array($leaderquery));


//get the average

$avg_handicap=round($total_handicap/$userexist,2);
$avg_gross=round($total_gross_score/$userexist,2);
$avg_net=round($total_net_score/$userexist,2);
$avg_gross_par=round($total_gross_par/$userexist,2);
$avg_net_par=round($total_net_par/$userexist,2);
$avg_stableford=round($total_stableford/$userexist,2);

if ($avg_gross_par > 0) {
$avg_gross_par="+"."$avg_gross_par";
} elseif ($avg_gross_par==0) {
$avg_gross_par="E";
}

if ($avg_net_par > 0) {
$avg_net_par="+"."$avg_net_par";
} elseif ($avg_net_par==0) {
$avg_net_par="E";
}


echo "<tr class='bg4'><td colspan=2><b>Average Stats</td><td>$avg_handicap</td><td>$avg_gross [$avg_gross_par]</td><td>$avg_net [$avg_net_par]</td><td>$avg_stableford</td>
<td>&nbsp;</a></td>
</tr>";



} else {
echo "Application error.";
exit();
}

?>


</table>

<p>

<?
##########################MESSAGE PORTION###################################


//format date
$today=date("Y-m-d");                           
$time=date("H:i:s");                           


if ($HTTP_POST_VARS['addmsg']) {
$insertsql="INSERT INTO tourney_board (tourneyid,userid,msgtype,msgdate,msgtime,msgbody) VALUES 
('$tourneyid','$login_id','$msgtype','$today','$time', '$reqmsg')";
$insertquery=mysql_query($insertsql);

}//endif addmessage

if ($HTTP_POST_VARS['deletemsg']) {
$delsql= "Delete From tourney_board where (Id='$msgid')";
	$delresult=mysql_query($delsql);
$error="Message Deleted.";
}//endif deletemessage

//query for any message
$messagesql="select *, userid as msguserid from tourney_board where tourneyid='$tourneyid'
						order by msgdate DESC, msgtime DESC";
				$messagequery=mysql_query($messagesql);
				$messagerow=mysql_fetch_array($messagequery);
				$messageexist=mysql_numrows($messagequery);
				
?>

<form method="post" onSubmit="return msgcheckrequired(this)" action="<?=$PHP_SELF?>">

<?echo $error."<p>";
?>
<table border=1 width=60%>
<tr class="bg0">
<td colspan="7">
<b>Tournament Report
</td>
</tr>
<tr class="bg2">
<td width=5%>&nbsp;</td><td>
<td><TEXTAREA name="reqmsg" ROWS="8" COLS="40"></textarea></td>
<td>
<input type="Hidden" name="msguserid" value="<?echo $login_id;?>">
<input type="Hidden" name="tourneyid" value="<?echo $tourneyid;?>">
<input type="Hidden" name="msgtype" value='POTD'>
<input type="Hidden" name="action" value="<?=$action;?>">

<input type="Submit" name="addmsg" value="Submit">

</td>

</tr>

</form>
<?
if ($messageexist) {
$position=0;
do {

echo "<form method='post' action='$PHP_SELF'>";
$position++;
extract($messagerow);
echo "<input type='Hidden' name='msgid' value='$Id'>";
echo "<tr class=bg2><td>$position<td><td>$msgbody <br> -- <i>Submitted by $msguserid on $msgtime $msgdate</td><td>";
if ($msguserid==$login_id) {
echo "<input type='Submit' name='deletemsg' value='Delete'>";
}
echo "</td></tr>";
echo "<input type='Hidden' name='msguserid' value='$login_id'>";
echo "<input type='Hidden' name='tourneyid' value='$tourneyid'>";

echo "</form>";
}while ($messagerow=mysql_fetch_array($messagequery));
}
?>





</table>


</td>
</tr>
</table>



<table border=1 width=80%>
<tr class=bg0>
<td align='center'><b>Tournament Correspondence</td></tr>
<tr><td>
<?
$textfilename="files/"."$tourneyid"."a".".txt";

if (file_exists($textfilename)) {

$lines = file($textfilename);

foreach ($lines as $line_num => $line) {
    echo htmlspecialchars($line) . "<br />\n";
		
}//endfor

}//endif fileexist


?>
</td></tr>
</table>


<? 

} else {

echo "Application error.";

}//endif tourneyid

 ?>
<? showfooter(); ?>
Return current item: GolfstatsPHP