Location: PHPKode > projects > SportsPHool > sportsphool/graph.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
$pagetitle="Score Charts";

// Make sure a valid player is accessing the page
if(!$HTTP_SESSION_VARS["userID"]) {
  header("Location: " . $SYS["base_href"] . "/signon.php?&message=4&" . SID);

include($SYS["includes"] . "/phplot/phplot.php");
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) {
  $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";
  if($rs->EOF) {
    echo "<p>There are no scores to display.</p>";


  $week=0; $i=-1;
  $data=""; $legend="";
  foreach($scores as $score) {
    if($week!=$score["weekID"]) {

  $graph->SetTitle("Weekly score history");
} elseif($chart==2) {
  $qry1="SELECT COUNT(gameID) FROM $gametbl WHERE visscore>'-1' AND homescore>'-1'";
  $qry2="SELECT COUNT(gameID) FROM $gametbl WHERE winner=visitor";
  $qry3="SELECT COUNT(gameID) FROM $gametbl WHERE winner=home";
  if($ties==0) {
    $legend=array("Home wins", "Visitor wins");
  } else {
    $legend=array("Home wins", "Visitor wins", "Ties");
Return current item: SportsPHool