Integrate supplier piechart
[contractdashboard.git] / displayHeatmap.php
blob:a/displayHeatmap.php -> blob:b/displayHeatmap.php
--- a/displayHeatmap.php
+++ b/displayHeatmap.php
@@ -1,7 +1,7 @@
 <?php

 

 

-include('../lib/common.inc.php');

+include('lib/common.inc.php');

 

 $year = 2006;

 $ZeroX = 112.5;

@@ -22,12 +22,17 @@
 $height = 457;

 //echo "http://dev.openstreetmap.org/~pafciu17/?module=map&bbox=".$ZeroX.",".$ZeroY.",".$MaxX.",".$MaxY."&width=".$width."&height=".$height;

 //$handle = ImageCreate ($width, $height) or die ("Cannot Create image");

-$handle = imagecreatefrompng('../images/australia.png');

+$handle = imagecreatefrompng('images/australia.png');

 $white = imagecolorallocate($handle, 0, 0, 0);

 imagecolortransparent($handle, $white);

 

-$query = "SELECT supplierPostcode, sum(value) as value, lat, lon FROM `contractnotice`,`postcodes` where childCN = 0 AND supplierCountry = 'Australia' AND YEAR(contractStart) >= '$year' AND supplierPostcode = postcode GROUP BY supplierPostcode";

-$result = mysql_query($query);

+$query = 'SELECT "supplierPostcode", sum("value") as value, max(lat) as lat, max(lon) as lon FROM contractnotice inner join postcodes on "supplierPostcode" = postcode::text where "childCN" = 0 AND "supplierCountry" = \'Australia\' GROUP BY "supplierPostcode"';

+$query = $conn->prepare($query);

+   $query->execute();

+   if (!$query) {

+      databaseError($conn->errorInfo());

+   }

+

 

 $left = "FFFF50";

 $right= "EF0050";

@@ -41,8 +46,7 @@
     $colorset[$i] = imagecolorallocatealpha($handle, $leftR + ($i*(($rightR-$leftR)/250)), $leftG + ($i*(($rightG-$leftG)/250)), $leftB + ($i*(($rightB-$leftB)/250)),117 - ($i/250)*40);

 }

 

-while ($row = mysql_fetch_array($result, MYSQL_BOTH))

-{

+  foreach ($query->fetchAll() as $row) {

    $xpage = round((($XRange - ($MaxX - $row['lon'])) / $xdivlength));

 	if ($row['lat'] < -40.25) $row['lat']-= 0.75;

    $ypage = round(($YRange - (abs($MaxY) - abs($row['lat']))) / $ydivheight);