Integrate supplier piechart
--- a/admin/linkAmendments.php
+++ b/admin/linkAmendments.php
@@ -25,4 +25,5 @@
else print_r($errors);
}
+// also need to eliminate CN 100528/100529 - check for double parent CNs with no childCN, latest sequent CN id wins childCN = 0
?>
--- a/displayCalendar.php
+++ b/displayCalendar.php
@@ -6,15 +6,23 @@
if ($_REQUEST['month']) {
echo "<center><h1>".$_REQUEST['month']."</h1></center>";
$monthParts = explode("-",$_REQUEST['month']);
- $query = "SELECT CNID, description, value, agencyName, category, contractStart, supplierName
- FROM `contractnotice`
- WHERE childCN = 0
- AND YEAR(contractStart) = {$monthParts[1]}
- AND MONTH(contractStart) = {$monthParts[0]}
- ORDER BY value DESC";
- $result = mysql_query($query);
-echo '<img src="graphs/displayMethodCountGraph.php?month=' . stripslashes($supplier) . '">';
- echo '<img src="graphs/displayCnCGraph.php?month=' . stripslashes($supplier) . '">';
+ $query = 'SELECT "CNID", "description", "value", "agencyName", "category", "contractStart", "supplierName"
+ FROM contractnotice
+ WHERE "childCN" = 0
+ AND extract(year from "contractStart") = :year
+ AND extract(month from "contractStart") = :month
+ ORDER BY value DESC';
+$query = $conn->prepare($query);
+$query->bindParam(":month", $monthParts[0]);
+
+$query->bindParam(":year", $monthParts[1]);
+ $query->execute();
+ if (!$query) {
+ databaseError($conn->errorInfo());
+ }
+
+MethodCountGraph($supplier);
+CnCGraph($supplier);
echo "<table> <thead>
<tr>
@@ -26,7 +34,7 @@
<th>Supplier</th>
</tr>
</thead>";
- while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
+ foreach ($query->fetchAll() as $row) {
setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row['value']) , 2);
echo ("<tr>
@@ -52,10 +60,14 @@
echo '<img src="graphs/displayContractPublishedGraph.php">';
-$query = "SELECT YEAR(contractStart), MONTH(contractStart),
-SUM(value) as val, count(1) as count FROM `contractnotice` WHERE childCN = 0 GROUP BY MONTH(contractStart), YEAR(contractStart) ORDER BY YEAR(contractStart), MONTH(contractStart) ";
+$query = 'SELECT extract(year from "contractStart"), extract(month from "contractStart"),
+SUM(value) as val, count(1) as count FROM contractnotice WHERE "childCN" = 0 GROUP BY extract(year from "contractStart"), extract(month from "contractStart") ORDER BY extract(year from "contractStart"), extract(month from "contractStart") ';
+$query = $conn->prepare($query);
+ $query->execute();
+ if (!$query) {
+ databaseError($conn->errorInfo());
+ }
-$result = mysql_query($query);
echo "<table> <thead>
<tr>
<th>Month/Year</th>
@@ -63,7 +75,7 @@
<th>Number of Contracts</th>
</tr>
</thead>";
-while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
+ foreach ($query->fetchAll() as $row) {
setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row["val"]),2);
$month_name = date( 'F', mktime(0, 0, 0, $row[1]) );
--- 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);
--- a/displaySupplier.php
+++ b/displaySupplier.php
@@ -4,9 +4,9 @@
include_header("Supplier");
$supplierS = htmlentities(strip_tags($_REQUEST['supplier']));
- echo '<img src="graphs/displayMethodCountGraph.php?supplier=' . stripslashes($supplierS) . '">';
- echo '<img src="graphs/displayCnCGraph.php?supplier=' . stripslashes($supplierS) . '">';
- echo '<img src="graphs/displayMethodValueGraph.php?supplier=' . stripslashes($supplierS) . '">';
+ MethodCountGraph($supplierS);
+ CnCGraph($supplierS);
+ MethodValueGraph($supplierS);
/*lobbyist ties
links to ABR/ASIC/Google News/ASX/Court records
@@ -62,6 +62,7 @@
histograph of supplier size/value
*/
include_header("Suppliers");
+suppliersGraph();
$query = 'SELECT SUM("value") as val, MAX("supplierName") as supplierName, "supplierABN",(
case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as supplierID
FROM contractnotice
--- a/lib/graphs.inc.php
+++ b/lib/graphs.inc.php
@@ -296,40 +296,63 @@
}
function SuppliersGraph() {
+
+ global $conn;
+ includeFlot();
$topX = 10;
-$query = "SELECT value, supplierName
-FROM `contractnotice` WHERE (YEAR(contractStart) >= 2009) AND childCN = 0
-GROUP BY supplierABN ORDER BY value DESC limit $topX";
-$result = mysql_query($query);
$suppliers = Array();
$values = Array();
-while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
+
+
+$query = 'SELECT SUM("value") as value, MAX("supplierName") as supplierName, (
+ case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as supplierID
+FROM contractnotice
+WHERE "childCN" = 0
+GROUP BY supplierID
+ORDER BY value DESC
+LIMIT '.$topX;
+$query = $conn->prepare($query);
+ $query->execute();
+ if (!$query) {
+ databaseError($conn->errorInfo());
+ }
+ foreach ($query->fetchAll() as $row) {
setlocale(LC_MONETARY, 'en_US');
// $value = number_format(doubleval($row["value"]) , 2);
$suppliers[] = ucsmart($row[1]);
$values[] = doubleval($row["value"]);
}
-mysql_free_result($result);
-
-$query = "SELECT sum(a.value) as val, supplierCountry from (SELECT value, supplierName, supplierCountry
-FROM `contractnotice` WHERE (YEAR(contractStart) >= 2009) AND childCN = 0
-GROUP BY supplierName ORDER BY value LIMIT 18446744073709551610 OFFSET $topX) as a group by supplierCountry order by val DESC limit 5 offset 1";
-$result = mysql_query($query);
-while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
- $suppliers[] = "Other suppliers in ".ucsmart($row["supplierCountry"]);
+
+$query = 'SELECT sum(a.svalue) as val, suppliercountry from (SELECT sum("value") as svalue, max("supplierCountry") as suppliercountry
+FROM contractnotice WHERE "childCN" = 0 and "supplierCountry" NOT ILIKE \'Australia\'
+GROUP BY "supplierName" ORDER BY svalue LIMIT 18446744073 OFFSET 10) as a group by suppliercountry order by val DESC limit 10 ';
+$query = $conn->prepare($query);
+ $query->execute();
+ if (!$query) {
+ databaseError($conn->errorInfo());
+ }
+
+ foreach ($query->fetchAll() as $row) {
+ $suppliers[] = "Other suppliers in ".ucsmart($row["suppliercountry"]);
$values[] = doubleval($row[0]);
}
-mysql_free_result($result);
-
-$query = "SELECT sum(a.value) as val, TRUNCATE(supplierPostcode,-2) as postcode from (SELECT value, supplierName, supplierPostcode, supplierCountry
-FROM `contractnotice` WHERE (YEAR(contractStart) >= 2009) AND childCN = 0
-GROUP BY supplierName ORDER BY value LIMIT 18446744073709551610 OFFSET $topX) as a
-WHERE (supplierCountry LIKE 'Australia' OR supplierCountry LIKE 'AUSTRALIA') AND supplierPostcode < 10000
-group by TRUNCATE(supplierPostcode,-2)
-order by val DESC";
-$result = mysql_query($query);
-while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
+
+$query = 'SELECT sum(a.value) as val, substring(
+supplierpostcode from 0 for 2) as postcode from (SELECT sum(value) as value, max("supplierPostcode") as supplierpostcode, max("supplierCountry") as suppliercountry
+FROM contractnotice WHERE "childCN" = 0
+GROUP BY "supplierABN" ORDER BY sum(value) LIMIT 1844674 OFFSET 10) as a
+WHERE (suppliercountry ILIKE \'Australia\')
+group by substring(
+supplierpostcode from 0 for 2)
+order by val DESC;';
+$query = $conn->prepare($query);
+ $query->execute();
+ if (!$query) {
+ databaseError($conn->errorInfo());
+ }
+
+ foreach ($query->fetchAll() as $row) {
if ($row['postcode'][0] == 2 && $row['postcode'][1] == 6) $ACTvalue += $row[0];
else if ($row['postcode'][0] == 2 || $row['postcode'][0] == 1) $NSWvalue += $row[0];
else if ($row['postcode'][0] == 3 || $row['postcode'][0] == 8) $Vicvalue += $row[0];
@@ -339,7 +362,6 @@
else if ($row['postcode'][0] == 7) $Tasvalue += $row[0];
else if ($row['postcode'][0] == 0) $NTvalue += $row[0];
}
-mysql_free_result($result);
$suppliers[] = "Other suppliers in Australia - ACT";
$values[] = doubleval($ACTvalue);
$suppliers[] = "Other suppliers in Australia - NSW";
@@ -356,7 +378,53 @@
$values[] = doubleval($SAvalue);
$suppliers[] = "Other suppliers in Australia - Tasmania";
$values[] = doubleval($Tasvalue);
-
-}
+
?>
+<script type="text/javascript">
+$(function () {
+ // data
+ var data = [
+ <?php
+foreach ($suppliers as $key => $supplier) {
+ echo '{ label: "'.$supplier.'", data: '.doubleval($values[$key]).'},';
+ }
+ ?>
+ ];
+ // GRAPH 7
+ $.plot($("#graph7"), data,
+ {
+ series: {
+ pie: {
+ show: true,
+ radius: 1,
+ tilt: 0.75,
+ label: {
+ show: true,
+ radius: 1,
+ formatter: function(label, series){
+ return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+': '+Math.round(series.percent)+'%</div>';
+ },
+ background: {
+ opacity: 0.5,
+ color: '#000'
+ }
+ },
+ combine: {
+ color: '#999',
+ threshold: 0.012
+ }
+ }
+ },
+ legend: {
+ show: false
+ }
+ });
+});
+</script>
+ <div id="graph7" style="width:900px;height:550px"></div>
+
+<?php
+}
+
+?>