<?
require('chart/jpgraph.php');
require('chart/jpgraph_pie.php');
require('chart/jpgraph_pie3d.php');
header("Location: holestats.php?courseid=$courseid&hole=$hole&rankhole=$rankhole");
require('chart/jpgraph_line.php');
require('chart/jpgraph_bar.php');
require('dbasecon.inc.php');
//first check see if course already exist
$parhole="parhole".$hole;
$indexhole="indexhole".$hole;
$lengthhole="lengthhole".$hole;
$holeid="hole".$hole;
//ok, first check if stats for this user exist
//1.check number of times user has played
$holesql="select * from $holeid where courseid='$courseid' AND userid='$login_id'";
$holequery=mysql_query($holesql);
$holecheckrow=mysql_fetch_array($holequery);
$holecheckexist=mysql_numrows($holequery);
if ($holecheckexist) {
//1.start getting the stats
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' AND userid='$login_id' and (gross_name='Double Eagle' or gross_name='Hole In One')";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$usergrossDeagle=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' AND userid='$login_id' and gross_name='Eagle'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$usergrossEagle=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' AND userid='$login_id' and gross_name='Birdie'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$usergrossBirdie=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' AND userid='$login_id' and gross_name='Par'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$usergrossPar=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' AND userid='$login_id' and gross_name='Bogey'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$usergrossBogey=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid where courseid='$courseid' AND userid='$login_id' and gross_name != 'Par'
and gross_name != 'Bogey' and gross_name !='Birdie' and gross_name !='Eagle' and gross_name !='Double Eagle'
and gross_name != 'Hole in one'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$usergrossOthers=$userscoresarray['score'];
//start with user-gross-score
$usergrossdata = array($usergrossDeagle,$usergrossEagle,$usergrossBirdie,$usergrossPar,$usergrossBogey,$usergrossOthers);
// Create the Pie Graph.
$graph = new PieGraph(400,200,"auto");
$graph->SetShadow();
// Set A title for the plot
$graph->title->Set("Player Gross Score");
//$graph->title->SetFont(FF_VERDANA,FS_BOLD,12);
$graph->title->SetColor("darkblue");
$graph->legend->Pos(0.025,0.2);
// Create 3D pie plot
$p1 = new PiePlot3d($usergrossdata);
$p1->SetTheme("golf");
$p1->SetCenter(0.3);
$p1->SetSize(80);
// Adjust projection angle
$p1->SetAngle(45);
// Adjsut angle for first slice
$p1->SetStartAngle(45);
// Display the slice values
//$p1->value->SetFont(FF_ARIAL,FS_BOLD,9);
$p1->value->SetColor("navy");
// Add colored edges to the 3D pie
// NOTE: You can't have exploded slices with edges!
$p1->SetEdge("navy");
$p1->SetLegends(array("Db.Eagle/Hole in 1","Eagle","Birdie","Par","Bogey","Others"));
$graph->Add($p1);
$graph->Stroke("tempcharts/gross$login_id.jpg");
//$graph->Stroke();
} //endif holecheckexist
//now for the gross global!
//1.start getting the stats
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' and (gross_name='Double Eagle' or gross_name='Hole In One')";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$globgrossDeagle=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' and gross_name='Eagle'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$globgrossEagle=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' and gross_name='Birdie'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$globgrossBirdie=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' and gross_name='Par'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$globgrossPar=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' and gross_name='Bogey'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$globgrossBogey=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid where courseid='$courseid' and gross_name != 'Par'
and gross_name != 'Bogey' and gross_name !='Birdie' and gross_name !='Eagle' and gross_name !='Double Eagle'
and gross_name != 'Hole in one'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$globgrossOthers=$userscoresarray['score'];
//start with user-gross-score
$globgrossdata = array($globgrossDeagle,$globgrossEagle,$globgrossBirdie,$globgrossPar,$globgrossBogey,$globgrossOthers);
// Create the Pie Graph.
$graph = new PieGraph(400,200,"auto");
$graph->SetShadow();
// Set A title for the plot
$graph->title->Set("Global Gross Score");
//$graph->title->SetFont(FF_VERDANA,FS_BOLD,12);
$graph->title->SetColor("darkblue");
$graph->legend->Pos(0.025,0.2);
// Create 3D pie plot
$p1 = new PiePlot3d($globgrossdata);
$p1->SetTheme("golf");
$p1->SetCenter(0.3);
$p1->SetSize(80);
// Adjust projection angle
$p1->SetAngle(45);
// Adjsut angle for first slice
$p1->SetStartAngle(45);
// Display the slice values
//$p1->value->SetFont(FF_ARIAL,FS_BOLD,9);
$p1->value->SetColor("navy");
// Add colored edges to the 3D pie
// NOTE: You can't have exploded slices with edges!
$p1->SetEdge("navy");
$p1->SetLegends(array("Db.Eagle/Hole in 1","Eagle","Birdie","Par","Bogey","Others"));
$graph->Add($p1);
$graph->Stroke("tempcharts/grossglobal.jpg");
//$graph->Stroke();
if ($holecheckexist) {
###################################Now for user-net-score#################################
//1.start getting the stats
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' AND userid='$login_id' and (net_name='Double Eagle' or net_name='Hole In One')";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$usernetDeagle=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' AND userid='$login_id' and net_name='Eagle'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$usernetEagle=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' AND userid='$login_id' and net_name='Birdie'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$usernetBirdie=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' AND userid='$login_id' and net_name='Par'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$usernetPar=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' AND userid='$login_id' and net_name='Bogey'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$usernetBogey=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid where courseid='$courseid' AND userid='$login_id' and net_name != 'Par'
and net_name != 'Bogey' and net_name !='Birdie' and net_name !='Eagle' and net_name !='Double Eagle'
and net_name != 'Hole in one'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$usernetOthers=$userscoresarray['score'];
//start with user-net-score
$usernetdata = array($usernetDeagle,$usernetEagle,$usernetBirdie,$usernetPar,$usernetBogey,$usernetOthers);
// Create the Pie Graph.
$graph = new PieGraph(400,200,"auto");
$graph->SetShadow();
// Set A title for the plot
$graph->title->Set("Player Net Score");
//$graph->title->SetFont(FF_VERDANA,FS_BOLD,12);
$graph->title->SetColor("darkblue");
$graph->legend->Pos(0.025,0.2);
// Create 3D pie plot
$p1 = new PiePlot3d($usernetdata);
$p1->SetTheme("golf");
$p1->SetCenter(0.3);
$p1->SetSize(80);
// Adjust projection angle
$p1->SetAngle(45);
// Adjsut angle for first slice
$p1->SetStartAngle(45);
// Display the slice values
//$p1->value->SetFont(FF_ARIAL,FS_BOLD,9);
$p1->value->SetColor("navy");
// Add colored edges to the 3D pie
// NOTE: You can't have exploded slices with edges!
$p1->SetEdge("navy");
$p1->SetLegends(array("Db.Eagle/Hole in 1","Eagle","Birdie","Par","Bogey","Others"));
$graph->Add($p1);
$graph->Stroke("tempcharts/net$login_id.jpg");
//$graph->Stroke();
} //endif holecheckexist
##############################Now for global net score#####################################
//now for the net global!
//1.start getting the stats
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' and (net_name='Double Eagle' or net_name='Hole In One')";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$globnetDeagle=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' and net_name='Eagle'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$globnetEagle=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' and net_name='Birdie'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$globnetBirdie=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' and net_name='Par'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$globnetPar=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid
where courseid='$courseid' and net_name='Bogey'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$globnetBogey=$userscoresarray['score'];
$userscores="Select count(*) as score from $holeid where courseid='$courseid' and net_name != 'Par'
and net_name != 'Bogey' and net_name !='Birdie' and net_name !='Eagle' and net_name !='Double Eagle'
and net_name != 'Hole in one'";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$globnetOthers=$userscoresarray['score'];
//start with user-net-score
$globnetdata = array($globnetDeagle,$globnetEagle,$globnetBirdie,$globnetPar,$globnetBogey,$globnetOthers);
// Create the Pie Graph.
$graph = new PieGraph(400,200,"auto");
$graph->SetShadow();
// Set A title for the plot
$graph->title->Set("Global Net Score");
//$graph->title->SetFont(FF_VERDANA,FS_BOLD,12);
$graph->title->SetColor("darkblue");
$graph->legend->Pos(0.025,0.2);
// Create 3D pie plot
$p1 = new PiePlot3d($globnetdata);
$p1->SetTheme("golf");
$p1->SetCenter(0.3);
$p1->SetSize(80);
// Adjust projection angle
$p1->SetAngle(45);
// Adjsut angle for first slice
$p1->SetStartAngle(45);
// Display the slice values
//$p1->value->SetFont(FF_ARIAL,FS_BOLD,9);
$p1->value->SetColor("navy");
// Add colored edges to the 3D pie
// NOTE: You can't have exploded slices with edges!
$p1->SetEdge("navy");
$p1->SetLegends(array("Db.Eagle/Hole in 1","Eagle","Birdie","Par","Bogey","Others"));
$graph->Add($p1);
$graph->Stroke("tempcharts/netglobal.jpg");
//$graph->Stroke();
//ok, now 3 more bar charts to go.
#####First bar chart, gross and Net################
$datay=array($myavggross,$myavgnet,$myavgputt);
$datay2=array($allavggross,$allavgnet,$allavgputt);
$datax=array("Gross","Net","Putts");
$datazero=array(0,0);
// Create the graph.
$graph = new Graph(400,200,"auto");
$graph->title->Set('Average Scores');
$graph->img->SetMargin(60,90,20,50);
$graph->SetScale("textlin");
$graph->SetMarginColor("silver");
$graph->SetShadow();
// Show 0 label on Y-axis (default is not to show)
$graph->yscale->ticks->SupressZeroLabel(true);
$graph->SetScale("textlin");
//$graph->SetY2Scale("lin");
$graph->yaxis->scale->SetGrace(30);
//$graph->y2axis->scale->SetGrace(30);
// Setup X-axis labels
$graph->xaxis->SetTickLabels($datax);
$graph->ygrid->Show(true,true);
$graph->ygrid->SetColor('gray','hide@address.com');
// Setup graph colors
//$graph->SetMarginColor('white');
//$graph->y2axis->SetColor('darkred');
// Set X-axis at the minimum value of Y-axis (default will be at 0)
$graph->xaxis->SetPos("min"); // "min" will position the x-axis at the minimum value of the Y-axis
// Create the "dummy" 0 bplot
$bplotzero = new BarPlot($datazero);
// Create the "Y" axis group
$ybplot1 = new BarPlot($datay);
$ybplot1->value->SetFormat('%01.2f');
$ybplot1->SetLegend("Player","blue");
$ybplot1->SetShadow();
$ybplot1->value->Show();
// Setup color for gradient fill style
$ybplot1->SetFillGradient("navy","steelblue",GRAD_MIDVER);
$ybplot = new GroupBarPlot(array($ybplot1,$bplotzero));
// Create the "Y2" axis group
$ybplot2 = new BarPlot($datay2);
$ybplot2->value->SetFormat('%01.2f');
$ybplot2->SetLegend("Global","darkred");
$ybplot2->SetShadow();
$ybplot2->value->Show();
$ybplot2->value->SetColor('darkred');
$ybplot2->SetFillColor('darkred');
// Setup color for gradient fill style
$ybplot2->SetFillGradient("darkred","violetred",GRAD_MIDVER);
$y2bplot = new GroupBarPlot(array($bplotzero,$ybplot2));
// Add the grouped bar plots to the graph
$graph->Add($ybplot);
$graph->Add($y2bplot);
$graph->xaxis->title->Set("Scoring Type");
$graph->yaxis->title->Set("Average");
// .. and finally stroke the image back to browser
$graph->Stroke("tempcharts/averagebar$login_id.jpg");
unset($datay);
unset($datay2);
unset($datax);
unset($datazero);
#####Finally Percentage of FH and GIR################
$datay=array($mygirpct,$myfwaypct);
$datay2=array($allgirpct,$allfwaypct);
$datax=array("GIR","Fairway");
$datazero=array(0,0);
// Create the graph.
$graph = new Graph(400,200,"auto");
$graph->title->Set('Average Percentage');
$graph->img->SetMargin(40,90,20,50);
$graph->SetScale("textlin");
$graph->SetMarginColor("silver");
$graph->SetShadow();
// Setup Y and Y2 scales with some "grace"
//$graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,9);
//$graph->yaxis->SetFont(FF_VERDANA,FS_NORMAL,9);
// Show 0 label on Y-axis (default is not to show)
$graph->yscale->ticks->SupressZeroLabel(true);
$graph->SetScale("textlin");
//$graph->SetY2Scale("lin");
$graph->yaxis->scale->SetGrace(10);
//$graph->y2axis->scale->SetGrace(30);
// Setup X-axis labels
$graph->xaxis->SetTickLabels($datax);
$graph->ygrid->Show(true,true);
$graph->ygrid->SetColor('gray','hide@address.com');
// Setup graph colors
//$graph->SetMarginColor('white');
//$graph->y2axis->SetColor('darkred');
// Set X-axis at the minimum value of Y-axis (default will be at 0)
$graph->xaxis->SetPos("min"); // "min" will position the x-axis at the minimum value of the Y-axis
// Create the "dummy" 0 bplot
$bplotzero = new BarPlot($datazero);
// Create the "Y" axis group
$ybplot1 = new BarPlot($datay);
$ybplot1->value->SetFormat('%01.2f');
$ybplot1->SetLegend("Player","blue");
$ybplot1->SetShadow();
$ybplot1->value->Show();
// Setup color for gradient fill style
$ybplot1->SetFillGradient("navy","steelblue",GRAD_MIDVER);
$ybplot = new GroupBarPlot(array($ybplot1,$bplotzero));
// Create the "Y2" axis group
$ybplot2 = new BarPlot($datay2);
$ybplot2->value->SetFormat('%01.2f');
$ybplot2->SetLegend("Global","darkred");
$ybplot2->SetShadow();
$ybplot2->value->Show();
$ybplot2->value->SetColor('darkred');
$ybplot2->SetFillColor('darkred');
// Setup color for gradient fill style
$ybplot2->SetFillGradient("darkred","violetred",GRAD_MIDVER);
$y2bplot = new GroupBarPlot(array($bplotzero,$ybplot2));
// Add the grouped bar plots to the graph
$graph->Add($ybplot);
$graph->Add($y2bplot);
$graph->xaxis->title->Set("Statistic");
$graph->yaxis->title->Set("Average %");
// .. and finally stroke the image back to browser
$graph->Stroke("tempcharts/averagebar2$login_id.jpg");
unset($datay);
unset($datay2);
unset($datax);
unset($datazero);
//ok the final graph is the graph for the last 10 scores for this hole. First lets do it
//we
$userscores="Select gross,gross_name, net, net_name,gameid from $holeid
where courseid='$courseid' AND userid='$login_id' order by gameid desc limit 10";
$userscoresquery=mysql_query($userscores);
$userscoresarray=mysql_fetch_array($userscoresquery);
$userscoresexist=mysql_numrows($userscoresquery);
if ($userscoresexist>1) {
$grossscoreline=array();
$netscoreline=array();
$datadate=array();
do {
$gameid=$userscoresarray[gameid];
//get year
$gameyr=substr($gameid,2,2);
$gamemonth=substr($gameid,4,2);
//get the day
$gameday=substr($gameid,6,2);
//now together!
$gamedate=$gameday.'/'.$gamemonth.'/'.$gameyr;
$gross=$userscoresarray[gross];
$gross_name=$userscoresarray[gross_name];
$net=$userscoresarray[net];
$net_name=$userscoresarray[net_name];
//start pushing
array_push ($grossscoreline, $gross);
array_push ($netscoreline, $net);
array_push ($datadate, "$gamedate");
} while ($userscoresarray=mysql_fetch_array($userscoresquery));
//now reverse it!
$grossscoreline = array_reverse ($grossscoreline);
$netscoreline = array_reverse ($netscoreline);
$datadate = array_reverse ($datadate);
/*--------------------BEGIN GRAPH DRAWING!!!!----------------------*/
//$gJpgBrandTiming=true;
// Create the graph. These two calls are always required
$graph = new Graph(750,400,"auto");
$graph->SetScale("textlin",0,10);
$graph->img->SetMargin(60,150,30,50);
$graph->legend->Pos(0.05,0.5,"right","center");
$graph->yaxis->title->Set("Score");
$lineplot1=new LinePlot($grossscoreline);
$lineplot1->mark->SetType(MARK_UTRIANGLE);
$lineplot1->value->show();
$lineplot1->value->SetColor('darkred');
//$lineplot1->value->SetFont(FF_FONT1,FS_BOLD);
$lineplot1->value->SetFormat('%d');
$graph->Add($lineplot1);
$lineplot1->SetColor("red");
$lineplot1->SetWeight(2);
$lineplot1->SetLegend("Gross","red");
$lineplot2=new LinePlot($netscoreline);
$lineplot2->mark->SetType(MARK_CIRCLE);
$lineplot2->value->show();
$lineplot2->value->SetColor('darkblue');
//$lineplot2->value->SetFont(FF_FONT1,FS_BOLD);
$lineplot2->value->SetFormat('%d');
$graph->Add($lineplot2);
$lineplot2->SetColor("blue");
$lineplot2->SetWeight(2);
$lineplot2->SetLegend("Net","blue");
// Add the plot to the graph
$graph->title->Set("Most recent scores for $courseid $holeid");
$graph->xaxis->title->Set("Date");
//$graph->yaxis->title->Set("Percentage");
//$graph->title->SetFont(FF_FONT1,FS_BOLD);
//$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
//$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
//some grace for yaxis and xaxis
$graph->yaxis->scale->SetGrace(30);
// Setup X-axis labels
$graph->xaxis->SetTickLabels($datadate);
$graph->yaxis->SetColor("red");
$graph->yaxis->SetWeight(2);
$graph->SetShadow();
// Display the graph
$graphname="scoreline".$login_id.$courseid;
$graph->Stroke("tempcharts/$graphname.jpg");
//$graph->Stroke();
} else {
} //endif userscoresexist > 1
?>