<?php
// graph.php: generates player charts
//
// This file is part of the SportsPHool application
// Copyright (C) 2000, 2001 Barry Scott Will <hide@address.com>
// See /license and /gpl.txt for licensing information
//
$page="charts";
$pagetitle="Score Charts";
require("./shared.php");
// Make sure a valid player is accessing the page
if(!$HTTP_SESSION_VARS["userID"]) {
header("Location: " . $SYS["base_href"] . "/signon.php?&message=4&" . SID);
exit;
}
include($SYS["includes"] . "/phplot/phplot.php");
$chart=$HTTP_GET_VARS["chart"];
if(!$chart) $chart=1;
$graph=new PHPlot();
$graph->x_label_ttffont = $SYS["assets"] . "/benjamingothic.ttf";
$graph->y_label_ttffont = $SYS["assets"] . "/benjamingothic.ttf";
$gametbl = $SYS["prefix"] . $phool . "Games";
$picktbl = $SYS["prefix"] . $phool . "Picks";
$weektbl = $SYS["prefix"] . $phool . "Weeks";
if($chart==1) {
$leader=$HTTP_GET_VARS["leader"];
$qry="SELECT W.weekID, W.weekname, COUNT(G.gameID) as score, P.profileID, R.profilename FROM $weektbl W, $gametbl G, $picktbl P, $profiletbl R WHERE G.gameID=P.gameID AND (G.winner=P.pick OR G.winner='-1') AND G.weekID=W.weekID AND P.profileID=R.profileID AND (P.profileID=$profile OR P.profileID=$leader) GROUP BY W.weekID, P.profileID ORDER BY W.weekID, P.profileID";
if($rs=&$conn->Execute($qry)===FALSE) {
echo "<p><strong>Could not access Games database. Please inform the site administrator of this error:<br/>\n" . $conn->ErrorNo() . ": " . $conn->ErrorMsg() . "</strong></p>\n";
exit;
}
if($rs->EOF) {
echo "<p>There are no scores to display.</p>";
include($footer);
exit;
}
$scores=$rs->GetRows();
$week=0; $i=-1;
$data=""; $legend="";
foreach($scores as $score) {
if($week!=$score["weekID"]) {
$i++;
$week=$score["weekID"];
$data[$i][0]=$score["weekname"];
$j=1;
}
$data[$i][$j]=$score["score"];
$legend[$j-1]=$score["profilename"];
$j++;
}
$graph->SetDataType("text-data");
$graph->SetDataValues($data);
$graph->SetLegend($legend);
$graph->SetVertTickIncrement(2);
$graph->SetTitle("Weekly score history");
$graph->SetXLabel("Week");
$graph->SetYLabel("Score");
$graph->DrawGraph();
} elseif($chart==2) {
$qry1="SELECT COUNT(gameID) FROM $gametbl WHERE visscore>'-1' AND homescore>'-1'";
$rs1=&$conn->Execute($qry1);
$total=$rs1->fields[0];
$qry2="SELECT COUNT(gameID) FROM $gametbl WHERE winner=visitor";
$rs2=&$conn->Execute($qry2);
$visitor=$rs2->fields[0];
$qry3="SELECT COUNT(gameID) FROM $gametbl WHERE winner=home";
$rs3=&$conn->Execute($qry3);
$home=$rs3->fields[0];
$ties=$total-$visitor-$home;
if($ties==0) {
$data=array(array('',$home,$visitor),array('',$home,$visitor));
$legend=array("Home wins", "Visitor wins");
} else {
$data=array(array('',$home,$visitor,$ties),array('',$home,$visitor,$ties));
$legend=array("Home wins", "Visitor wins", "Ties");
}
$graph->SetPlotType("pie");
$graph->SetDataValues($data);
$graph->SetLegend($legend);
$graph->DrawGraph();
}
?>