Change references to numeric child/parent IDs which can now be text
Change references to numeric child/parent IDs which can now be text

file:a/about.php -> file:b/about.php
<?php <?php
include('./lib/common.inc.php'); include('./lib/common.inc.php');
include_header("Map"); include_header("Map");
?> ?>
<div class="msg_list"> <div class="msg_list">
<p class="msg_head">Header-1 </p> <p class="msg_head">Header-1 </p>
<div class="msg_body"> <div class="msg_body">
orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit
</div> </div>
<p class="msg_head">Header-2</p> <p class="msg_head">Header-2</p>
<div class="msg_body"> <div class="msg_body">
orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit
</div> </div>
<p class="msg_head">Header-3</p> <p class="msg_head">Header-3</p>
<div class="msg_body"> <div class="msg_body">
orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit
</div> </div>
</div> </div>
<?php CNDistributionGraph(); <?php CNDistributionGraph();
// select distinct cnid, "publishDate" from (select ("CNID" - MOD("CNID",100)) as cnid from contractnotice where "CNID" < 999999) as a, contractnotice where a.cnid = contractNotice."CNID" order by cnid // select distinct cnid, "publishDate" from (select ("CNID" - MOD("CNID",100)) as cnid from contractnotice where "CNID" < 999999) as a, contractnotice where a.cnid = contractNotice."CNID" order by cnid
?> ?>
sourced from austender sourced from austender
Government Agency Information (2009-07-10): National Archives of Australia, http://www.naa.gov.au under Creative Commons - Attribution 2.5 Australia (CC-BY) Government Agency Information (2009-07-10): National Archives of Australia, http://www.naa.gov.au under Creative Commons - Attribution 2.5 Australia (CC-BY)
ABR ABR
<?php <?php
include_once("./lib/common.inc.php"); include_once("./lib/common.inc.php");
$query = 'SELECT DATE("importDate") as importday, count(*) as count, min("publishDate") as start, max("publishDate") as end $query = 'SELECT DATE("importDate") as importday, count(*) as count, min("publishDate") as start, max("publishDate") as end
FROM contractnotice WHERE "childCN" = 0 AND "parentCN" = 0 AND DATE("importDate") = (select * from (SELECT DATE("importDate") FROM contractnotice WHERE "childCN" is null AND "parentCN" is null AND DATE("importDate") = (select * from (SELECT DATE("importDate")
FROM contractnotice ORDER BY "importDate" DESC limit 1) alias) GROUP BY DATE("importDate")'; FROM contractnotice ORDER BY "importDate" DESC limit 1) alias) GROUP BY DATE("importDate")';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
} }
echo "<div>"; echo "<div>";
$stats = $query->fetch(PDO::FETCH_ASSOC); $stats = $query->fetch(PDO::FETCH_ASSOC);
echo $stats["count"] . " new records in period " . $stats["start"] . " to " . $stats["end"] ."<br>"; echo $stats["count"] . " new records in period " . $stats["start"] . " to " . $stats["end"] ."<br>";
$query = 'SELECT DATE("importDate") as importday, count(*) as count, min("publishDate") as start, max("publishDate") as end $query = 'SELECT DATE("importDate") as importday, count(*) as count, min("publishDate") as start, max("publishDate") as end
FROM contractnotice WHERE ("childCN" != 0 OR "parentCN" != 0) AND DATE("importDate") = (select * from (SELECT DATE("importDate") FROM contractnotice WHERE ("childCN" is not null OR "parentCN" is not null) AND DATE("importDate") = (select * from (SELECT DATE("importDate")
FROM contractnotice ORDER BY "importDate" DESC limit 1) alias) GROUP BY DATE("importDate")'; FROM contractnotice ORDER BY "importDate" DESC limit 1) alias) GROUP BY DATE("importDate")';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
} }
echo "<div>"; echo "<div>";
$stats = $query->fetch(PDO::FETCH_ASSOC); $stats = $query->fetch(PDO::FETCH_ASSOC);
echo $stats["count"] . " updated records in period " . $stats["start"] . " to " . $stats["end"] ."<br>"; echo $stats["count"] . " updated records in period " . $stats["start"] . " to " . $stats["end"] ."<br>";
echo "Last updated: ". $stats["importday"]."<br>"; echo "Last updated: ". $stats["importday"]."<br>";
/* Check for null Procurement method and 0 ABN when not ABN exempt */ /* Check for null Procurement method and 0 ABN when not ABN exempt */
include_footer(); include_footer();
?> ?>
   
<?php <?php
include_once("../lib/common.inc.php"); include_once("../lib/common.inc.php");
$query = "SELECT DATE(importDate) as importday, count(*) as count, min(publishDate) as start, max(publishDate) as end $query = "SELECT DATE(importDate) as importday, count(*) as count, min(publishDate) as start, max(publishDate) as end
FROM `contractnotice` WHERE childCN = 0 AND parentCN = 0 AND DATE(importDate) in (select * from (SELECT DATE(importDate) FROM `contractnotice` WHERE childCN is null AND parentCN is null AND DATE(importDate) in (select * from (SELECT DATE(importDate)
FROM `contractnotice` ORDER BY `importDate` DESC limit 1) alias)"; FROM `contractnotice` ORDER BY `importDate` DESC limit 1) alias)";
$result = mysql_query($query); $result = mysql_query($query);
$stats = mysql_fetch_array($result, MYSQL_BOTH); $stats = mysql_fetch_array($result, MYSQL_BOTH);
echo $stats["count"] . " new records in period " . $stats["start"] . " to " . $stats["end"] ."<br>"; echo $stats["count"] . " new records in period " . $stats["start"] . " to " . $stats["end"] ."<br>";
$query = "SELECT DATE(importDate) as importday, count(*) as count, min(publishDate) as start, max(publishDate) as end $query = "SELECT DATE(importDate) as importday, count(*) as count, min(publishDate) as start, max(publishDate) as end
FROM `contractnotice` WHERE (childCN != 0 OR parentCN != 0) AND DATE(importDate) in (select * from (SELECT DATE(importDate) FROM `contractnotice` WHERE (childCN is not null OR parentCN is not null) AND DATE(importDate) in (select * from (SELECT DATE(importDate)
FROM `contractnotice` ORDER BY `importDate` DESC limit 1) alias)"; FROM `contractnotice` ORDER BY `importDate` DESC limit 1) alias)";
$result = mysql_query($query); $result = mysql_query($query);
$stats = mysql_fetch_array($result, MYSQL_BOTH); $stats = mysql_fetch_array($result, MYSQL_BOTH);
echo $stats["count"] . " updated records in period " . $stats["start"] . " to " . $stats["end"] ."<br>"; echo $stats["count"] . " updated records in period " . $stats["start"] . " to " . $stats["end"] ."<br>";
$query = "SELECT count(*) as count FROM `agency` WHERE `abn` = '0'"; $query = "SELECT count(*) as count FROM `agency` WHERE `abn` = '0'";
$result = mysql_query($query); $result = mysql_query($query);
$stats = mysql_fetch_array($result, MYSQL_BOTH); $stats = mysql_fetch_array($result, MYSQL_BOTH);
echo $stats["count"] . " agencies with no ABN<br>"; echo $stats["count"] . " agencies with no ABN<br>";
/*$query = "SELECT count(*) as count FROM `supplierdetails` WHERE `supplierABN` = '0' and supplierCountry LIKE 'Australia'"; /*$query = "SELECT count(*) as count FROM `supplierdetails` WHERE `supplierABN` = '0' and supplierCountry LIKE 'Australia'";
$result = mysql_query($query); $result = mysql_query($query);
$stats = mysql_fetch_array($result, MYSQL_BOTH); $stats = mysql_fetch_array($result, MYSQL_BOTH);
echo $stats["count"] . " Australian suppliers with no ABN<br>";*/ echo $stats["count"] . " Australian suppliers with no ABN<br>";*/
echo "Last updated: ". $stats["importdate"]."<br>"; echo "Last updated: ". $stats["importdate"]."<br>";
?> ?>
   
<?php <?php
include_once ("./lib/common.inc.php"); include_once ("./lib/common.inc.php");
if ($_REQUEST['agency']) { if ($_REQUEST['agency']) {
include_header("Agency"); include_header("Agency");
$agency = htmlentities(strip_tags($_REQUEST['agency'])); $agency = htmlentities(strip_tags($_REQUEST['agency']));
MethodCountGraph($agency); MethodCountGraph($agency);
CnCGraph($agency); CnCGraph($agency);
MethodValueGraph($agency); MethodValueGraph($agency);
/*biggest contracts /*biggest contracts
spending by year spending by year
spending by industry/category spending by industry/category
spending by supplier spending by supplier
spread procurement methods (stacked bar graph) spread procurement methods (stacked bar graph)
+ percent consultancies + percent confidential (bar graph) + percent consultancies + percent confidential (bar graph)
Average value by procurement type Average value by procurement type
--- info --- info
website, procurement plan, annual reports website, procurement plan, annual reports
Breakdown of divisions/branches Breakdown of divisions/branches
Breakdown percentage,number,value by procurement type Breakdown percentage,number,value by procurement type
Histograph, overlaying number value reported per week over X years Histograph, overlaying number value reported per week over X years
Compliance statistics: amendments, delay in reporting average and number completely late*/ Compliance statistics: amendments, delay in reporting average and number completely late*/
$query = 'SELECT "CNID", "description", "value", "agencyName", "category", $query = 'SELECT "CNID", "description", "value", "agencyName", "category",
"contractStart", "supplierName" "contractStart", "supplierName"
FROM contractnotice FROM contractnotice
WHERE "agencyName" = :agency WHERE "agencyName" = :agency
ORDER BY "value" DESC'; ORDER BY "value" DESC';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->bindParam(":agency", $agency); $query->bindParam(":agency", $agency);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
} }
echo "<table> <thead> echo "<table> <thead>
<tr> <tr>
<th>Contract Notice Number</th> <th>Contract Notice Number</th>
<th>Contract Description</th> <th>Contract Description</th>
<th>Total Contract Value</th> <th>Total Contract Value</th>
<th>Agency</th> <th>Agency</th>
<th>Contract Start Date</th> <th>Contract Start Date</th>
<th>Supplier</th> <th>Supplier</th>
</tr> </tr>
</thead>"; </thead>";
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row['value']) , 2); $value = number_format(doubleval($row['value']) , 2);
echo ("<tr> echo ("<tr>
<td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td> <td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td>
<td><b>{$row['description']}</b></a></td> <td><b>{$row['description']}</b></a></td>
<td>\$$value</td><td>{$row['agencyName']}</td> <td>\$$value</td><td>{$row['agencyName']}</td>
<td>{$row['contractStart']}</td> <td>{$row['contractStart']}</td>
<td>{$row['supplierName']}</td> <td>{$row['supplierName']}</td>
</tr>"); </tr>");
} }
echo "</table>"; echo "</table>";
} else { } else {
/* /*
split by portfolio split by portfolio
*/ */
include_header("Agencies"); include_header("Agencies");
agenciesGraph(); agenciesGraph();
$query = 'SELECT SUM("value"), "agencyName" $query = 'SELECT SUM("value"), "agencyName"
FROM contractnotice FROM contractnotice
WHERE "childCN" = 0 WHERE "childCN" is null
GROUP BY "agencyName" '; GROUP BY "agencyName" ';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
} }
echo "<table> <thead> echo "<table> <thead>
<tr> <tr>
<th>Agency</th> <th>Agency</th>
<th>Total Contracts Value</th> <th>Total Contracts Value</th>
</tr> </tr>
</thead>"; </thead>";
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row[0]) , 2); $value = number_format(doubleval($row[0]) , 2);
$agency = stripslashes($row[1]); $agency = stripslashes($row[1]);
echo ("<tr><td><b><a href=\"displayAgency.php?agency={$agency}\">{$agency}</a></b></td><td>\$$value</td></tr>\n"); echo ("<tr><td><b><a href=\"displayAgency.php?agency={$agency}\">{$agency}</a></b></td><td>\$$value</td></tr>\n");
} }
echo "</table>"; echo "</table>";
} }
include_footer(); include_footer();
?> ?>
   
<?php <?php
include_once ("./lib/common.inc.php"); include_once ("./lib/common.inc.php");
include_header("Amendments"); include_header("Amendments");
$query = "select CNID, description, value, pvalue, (value - pvalue) as diff from contractnotice, (SELECT CNID as cn, childCN as ccn, value as pvalue FROM contractnotice where childCN > 0) a". $query = "select CNID, description, value, pvalue, (value - pvalue) as diff from contractnotice, (SELECT CNID as cn, childCN as ccn, value as pvalue FROM contractnotice where childCN is not null) a".
" where ".$agencyQ.$yearQ."CNID = ccn AND (value - pvalue) <> 0 order by diff DESC"; " where ".$agencyQ.$yearQ."CNID = ccn AND (value - pvalue) <> 0 order by diff DESC";
$result = mysql_query($query); $result = mysql_query($query);
echo "<table> <thead> echo "<table> <thead>
<tr> <tr>
<th>Contract</th> <th>Contract</th>
<th>Original Value</th> <th>Original Value</th>
<th>Amended Value</th> <th>Amended Value</th>
<th>Difference</th> <th>Difference</th>
</tr> </tr>
</thead>"; </thead>";
if ($result) { if ($result) {
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row['value']) , 2); $value = number_format(doubleval($row['value']) , 2);
$pvalue = number_format(doubleval($row['pvalue']) , 2); $pvalue = number_format(doubleval($row['pvalue']) , 2);
$diff = number_format(doubleval($row['diff']) , 2); $diff = number_format(doubleval($row['diff']) , 2);
echo ("<tr>"); echo ("<tr>");
echo "<td><A href=\"displayContract.php?CNID={$row['CNID']}\"><b>{$row['description']}</b></a></td>"; echo "<td><A href=\"displayContract.php?CNID={$row['CNID']}\"><b>{$row['description']}</b></a></td>";
echo "<td>\$$pvalue</td><td>\$$value</td><td>\$$diff</td></tr>"; echo "<td>\$$pvalue</td><td>\$$value</td><td>\$$diff</td></tr>";
} }
} else { } else {
echo mysql_error(); echo mysql_error();
} }
echo "</table>"; echo "</table>";
mysql_free_result($result); mysql_free_result($result);
include_footer(); include_footer();
?> ?>
   
   
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<meta charset="UTF-8"/> <meta charset="UTF-8"/>
<title>Minimal BubbleTree Demo</title> <title>Minimal BubbleTree Demo</title>
<script type="text/javascript" src="lib/bubbletree/lib/jquery-1.5.2.min.js"></script> <script type="text/javascript" src="lib/bubbletree/lib/jquery-1.5.2.min.js"></script>
<script type="text/javascript" src="lib/bubbletree/lib/jquery.history.js"></script> <script type="text/javascript" src="lib/bubbletree/lib/jquery.history.js"></script>
<script type="text/javascript" src="lib/bubbletree/lib/raphael.js"></script> <script type="text/javascript" src="lib/bubbletree/lib/raphael.js"></script>
<script type="text/javascript" src="lib/bubbletree/lib/vis4.js"></script> <script type="text/javascript" src="lib/bubbletree/lib/vis4.js"></script>
<script type="text/javascript" src="lib/bubbletree/lib/Tween.js"></script> <script type="text/javascript" src="lib/bubbletree/lib/Tween.js"></script>
<script type="text/javascript" src="lib/bubbletree/build/bubbletree.js"></script> <script type="text/javascript" src="lib/bubbletree/build/bubbletree.js"></script>
<link rel="stylesheet" type="text/css" href="lib/bubbletree/build/bubbletree.css" /> <link rel="stylesheet" type="text/css" href="lib/bubbletree/build/bubbletree.css" />
<script type="text/javascript" src="lib/bubbletree/styles/cofog.js"></script> <script type="text/javascript" src="lib/bubbletree/styles/cofog.js"></script>
<script type="text/javascript"> <script type="text/javascript">
$(function() { $(function() {
<?php <?php
include_once ("lib/common.inc.php"); include_once ("lib/common.inc.php");
   
include("lib/Color.php"); include("lib/Color.php");
$color = new Lux_Color(); $color = new Lux_Color();
   
   
$unspscresult= $conn->prepare('select * from "UNSPSCcategories";'); $unspscresult= $conn->prepare('select * from "UNSPSCcategories";');
$unspscresult->execute(); $unspscresult->execute();
foreach ($unspscresult->fetchAll() as $row) { foreach ($unspscresult->fetchAll() as $row) {
$unspsc[$row['UNSPSC']] = $row['Title']; $unspsc[$row['UNSPSC']] = $row['Title'];
   
} }
$total = 0; $total = 0;
   
$catsresult = $conn->prepare('SELECT distinct substr( "categoryUNSPSC"::text, 0, 2 ) as cat $catsresult = $conn->prepare('SELECT distinct substr( "categoryUNSPSC"::text, 0, 2 ) as cat
FROM contractnotice WHERE "categoryUNSPSC" IS NOT NULL group by "categoryUNSPSC";;'); FROM contractnotice WHERE "categoryUNSPSC" IS NOT NULL group by "categoryUNSPSC";;');
$catsresult->execute(); $catsresult->execute();
foreach ($catsresult->fetchAll() as $row) { foreach ($catsresult->fetchAll() as $row) {
$cats[] = $row['cat']; $cats[] = $row['cat'];
} }
$cattwosresult = $conn->prepare('SELECT distinct substr( "categoryUNSPSC"::text, 0, 3 ) as cat $cattwosresult = $conn->prepare('SELECT distinct substr( "categoryUNSPSC"::text, 0, 3 ) as cat
FROM contractnotice FROM contractnotice
WHERE "categoryUNSPSC" IS NOT NULL WHERE "categoryUNSPSC" IS NOT NULL
GROUP BY "categoryUNSPSC" order by cat ;'); GROUP BY "categoryUNSPSC" order by cat ;');
$cattwosresult->execute(); $cattwosresult->execute();
foreach ($cattwosresult->fetchAll() as $tworow) { foreach ($cattwosresult->fetchAll() as $tworow) {
$cattwos[substr($tworow['cat'],0,1)][] = $tworow['cat']; $cattwos[substr($tworow['cat'],0,1)][] = $tworow['cat'];
} }
   
$catthreesresult = $conn->prepare('SELECT substr( "categoryUNSPSC"::text, 0, 4 ) as cat , SUM( "value" ) as value $catthreesresult = $conn->prepare('SELECT substr( "categoryUNSPSC"::text, 0, 4 ) as cat , SUM( "value" ) as value
FROM contractnotice FROM contractnotice
WHERE "childCN" = 0 and "categoryUNSPSC" IS NOT NULL WHERE "childCN" is null and "categoryUNSPSC" IS NOT NULL
GROUP BY cat order by cat ;'); GROUP BY cat order by cat ;');
$catthreesresult->execute(); $catthreesresult->execute();
foreach ($catthreesresult->fetchAll() as $threerow) { foreach ($catthreesresult->fetchAll() as $threerow) {
$catthrees[substr($threerow['cat'],0,2)][] = $threerow; $catthrees[substr($threerow['cat'],0,2)][] = $threerow;
} }
$nodes = Array(); $nodes = Array();
foreach ($cats as $catNum) { foreach ($cats as $catNum) {
$catColor = $color->hsv2hex(Array($catNum/10, .7, abs(($catNum*(1/10))-.5) + .5)); $catColor = $color->hsv2hex(Array($catNum/10, .7, abs(($catNum*(1/10))-.5) + .5));
$catName = $unspsc[$catNum . "0000000"] . $catNum; $catName = $unspsc[$catNum . "0000000"] . $catNum;
$subnodes = Array(); $subnodes = Array();
$catValue = 0; $catValue = 0;
foreach ($cattwos[$catNum] as $twoCatNum) { foreach ($cattwos[$catNum] as $twoCatNum) {
$subcatName = $unspsc[$twoCatNum. "000000"] .$twoCatNum; $subcatName = $unspsc[$twoCatNum. "000000"] .$twoCatNum;
$subsubnodes = Array(); $subsubnodes = Array();
$subCatValue = 0; $subCatValue = 0;
$subCatColor = $color->hsv2hex(Array($catNum/10, rand(1,10)/10, abs(($catNum*(1/10))-.5) + .5)); $subCatColor = $color->hsv2hex(Array($catNum/10, rand(1,10)/10, abs(($catNum*(1/10))-.5) + .5));
foreach ($catthrees[$twoCatNum] as $threerow) { foreach ($catthrees[$twoCatNum] as $threerow) {
$subsubcatName = $unspsc[$threerow['cat'] . "00000"] . $threerow['cat']; $subsubcatName = $unspsc[$threerow['cat'] . "00000"] . $threerow['cat'];
$subsubnodes[] = Array( $subsubnodes[] = Array(
"label" => $subsubcatName, "label" => $subsubcatName,
"amount" => $threerow['value'], "amount" => $threerow['value'],
//"color" => "#".$subCatColor //"color" => "#".$subCatColor
); );
$subCatValue += $threerow['value']; $subCatValue += $threerow['value'];
} }
$subnodes[] = Array( $subnodes[] = Array(
"label" => $subcatName, "label" => $subcatName,
"amount" => $subCatValue, "amount" => $subCatValue,
"color" => "#".$subCatColor, "color" => "#".$subCatColor,
"children" => $subsubnodes "children" => $subsubnodes
); );
$catValue += $subCatValue; $catValue += $subCatValue;
} }
$nodes[] = Array( $nodes[] = Array(
"label" => $catName, "label" => $catName,
"amount" => $catValue, "amount" => $catValue,
"color" => "#".$catColor, "color" => "#".$catColor,
"children" => $subnodes "children" => $subnodes
); );
$total += $catValue; $total += $catValue;
} }
$data = Array( $data = Array(
"label" => "Australian Federal Government Contract Spending", "label" => "Australian Federal Government Contract Spending",
"amount" => $total, "amount" => $total,
"color" => "#000000", "color" => "#000000",
"children" => $nodes "children" => $nodes
); );
echo "var data =eval('('+'" . json_encode($data) . "'+')');"; echo "var data =eval('('+'" . json_encode($data) . "'+')');";
?> ?>
   
new BubbleTree({ new BubbleTree({
data: data, data: data,
container: '.bubbletree' container: '.bubbletree'
}); });
}); });
</script> </script>
</head> </head>
<body> <body>
<div class="bubbletree-wrapper"> <div class="bubbletree-wrapper">
<div class="bubbletree"></div> <div class="bubbletree"></div>
</div> </div>
</body> </body>
</html> </html>
   
<?php <?php
include_once("./lib/common.inc.php"); include_once("./lib/common.inc.php");
include_header("Months and Years"); include_header("Months and Years");
if ($_REQUEST['month']) { if ($_REQUEST['month']) {
echo "<center><h1>".$_REQUEST['month']."</h1></center>"; echo "<center><h1>".$_REQUEST['month']."</h1></center>";
$monthParts = explode("-",$_REQUEST['month']); $monthParts = explode("-",$_REQUEST['month']);
$query = 'SELECT "CNID", "description", "value", "agencyName", "category", "contractStart", "supplierName" $query = 'SELECT "CNID", "description", "value", "agencyName", "category", "contractStart", "supplierName"
FROM contractnotice FROM contractnotice
WHERE "childCN" = 0 WHERE "childCN" is null
AND extract(year from "contractStart") = :year AND extract(year from "contractStart") = :year
AND extract(month from "contractStart") = :month AND extract(month from "contractStart") = :month
ORDER BY value DESC'; ORDER BY value DESC';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->bindParam(":month", $monthParts[0]); $query->bindParam(":month", $monthParts[0]);
$query->bindParam(":year", $monthParts[1]); $query->bindParam(":year", $monthParts[1]);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
} }
MethodCountGraph($supplier); MethodCountGraph($supplier);
CnCGraph($supplier); CnCGraph($supplier);
echo "<table> <thead> echo "<table> <thead>
<tr> <tr>
<th>Contract Notice Number</th> <th>Contract Notice Number</th>
<th>Contract Description</th> <th>Contract Description</th>
<th>Total Contract Value</th> <th>Total Contract Value</th>
<th>Agency</th> <th>Agency</th>
<th>Contract Start Date</th> <th>Contract Start Date</th>
<th>Supplier</th> <th>Supplier</th>
</tr> </tr>
</thead>"; </thead>";
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row['value']) , 2); $value = number_format(doubleval($row['value']) , 2);
echo ("<tr> echo ("<tr>
<td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td> <td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td>
<td><b>{$row['description']}</b></a></td> <td><b>{$row['description']}</b></a></td>
<td>\$$value</td><td>{$row['agencyName']}</td> <td>\$$value</td><td>{$row['agencyName']}</td>
<td>{$row['contractStart']}</td> <td>{$row['contractStart']}</td>
<td>{$row['supplierName']}</td> <td>{$row['supplierName']}</td>
</tr>"); </tr>");
} }
echo "</table>"; echo "</table>";
mysql_free_result($result); mysql_free_result($result);
} else { } else {
/* /*
split by year split by year
todo: todo:
Year/Month drilldown - largest contracts, agencies, suppliers Year/Month drilldown - largest contracts, agencies, suppliers
count per month count per month
big picture graphs?*/ big picture graphs?*/
echo '<img src="graphs/displayContractStartingGraph.php">'; echo '<img src="graphs/displayContractStartingGraph.php">';
echo '<img src="graphs/displayContractPublishedGraph.php">'; echo '<img src="graphs/displayContractPublishedGraph.php">';
$query = 'SELECT extract(year from "contractStart"), extract(month from "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") '; SUM(value) as val, count(1) as count FROM contractnotice WHERE "childCN" is null 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 = $conn->prepare($query);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
} }
echo "<table> <thead> echo "<table> <thead>
<tr> <tr>
<th>Month/Year</th> <th>Month/Year</th>
<th>Total Contracts Value</th> <th>Total Contracts Value</th>
<th>Number of Contracts</th> <th>Number of Contracts</th>
</tr> </tr>
</thead>"; </thead>";
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row["val"]),2); $value = number_format(doubleval($row["val"]),2);
$month_name = date( 'F', mktime(0, 0, 0, $row[1]) ); $month_name = date( 'F', mktime(0, 0, 0, $row[1]) );
echo ("<tr><td><b><a href=\"?month=$row[1]-$row[0]\">$month_name {$row[0]}</a></b></td><td>\$$value</td><td>({$row['count']} contracts)</td></tr>"); echo ("<tr><td><b><a href=\"?month=$row[1]-$row[0]\">$month_name {$row[0]}</a></b></td><td>\$$value</td><td>({$row['count']} contracts)</td></tr>");
} }
echo "</table>"; echo "</table>";
mysql_free_result($result); mysql_free_result($result);
} }
include_footer(); include_footer();
?> ?>
   
<?php <?php
include_once ("./lib/common.inc.php"); include_once ("./lib/common.inc.php");
if ($_REQUEST['category']) { if ($_REQUEST['category']) {
include_header("Category"); include_header("Category");
echo "<center><h1>".$_REQUEST['category']."</h1></center>"; echo "<center><h1>".$_REQUEST['category']."</h1></center>";
$query = "SELECT CNID, description, value, agencyName, category, contractStart, supplierName $query = "SELECT CNID, description, value, agencyName, category, contractStart, supplierName
FROM `contractnotice` FROM `contractnotice`
WHERE childCN = 0 WHERE childCN is null
AND category = '" . $_REQUEST['category'] . "' AND category = '" . $_REQUEST['category'] . "'
ORDER BY value DESC"; ORDER BY value DESC";
$result = mysql_query($query); $result = mysql_query($query);
echo "<table> <thead> echo "<table> <thead>
<tr> <tr>
<th>Contract Notice Number</th> <th>Contract Notice Number</th>
<th>Contract Description</th> <th>Contract Description</th>
<th>Total Contract Value</th> <th>Total Contract Value</th>
<th>Agency</th> <th>Agency</th>
<th>Contract Start Date</th> <th>Contract Start Date</th>
<th>Supplier</th> <th>Supplier</th>
</tr> </tr>
</thead>"; </thead>";
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row['value']) , 2); $value = number_format(doubleval($row['value']) , 2);
echo ("<tr> echo ("<tr>
<td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td> <td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td>
<td><b>{$row['description']}</b></a></td> <td><b>{$row['description']}</b></a></td>
<td>\$$value</td><td>{$row['agencyName']}</td> <td>\$$value</td><td>{$row['agencyName']}</td>
<td>{$row['contractStart']}</td> <td>{$row['contractStart']}</td>
<td>{$row['supplierName']}</td> <td>{$row['supplierName']}</td>
</tr>"); </tr>");
} }
echo "</table>"; echo "</table>";
mysql_free_result($result); mysql_free_result($result);
} else { } else {
/* /*
split by main categories split by main categories
*/ */
include_header("Categories"); include_header("Categories");
$query = "SELECT sum(value), category $query = "SELECT sum(value), category
FROM `contractnotice` FROM `contractnotice`
WHERE childCN = 0 WHERE childCN is null
GROUP BY category ORDER BY sum(value) DESC "; GROUP BY category ORDER BY sum(value) DESC ";
$result = mysql_query($query); $result = mysql_query($query);
echo "<table> <thead> echo "<table> <thead>
<tr> <tr>
<th>Category</th> <th>Category</th>
<th>Total Contracts Value</th> <th>Total Contracts Value</th>
</tr> </tr>
</thead>"; </thead>";
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row[0]) , 2); $value = number_format(doubleval($row[0]) , 2);
echo ("<tr><td><A href=\"displayCategory.php?category={$row[1]}\"><b>{$row[1]}</b></a></td><td>\$$value</td></tr>"); echo ("<tr><td><A href=\"displayCategory.php?category={$row[1]}\"><b>{$row[1]}</b></a></td><td>\$$value</td></tr>");
} }
echo "</table>"; echo "</table>";
mysql_free_result($result); mysql_free_result($result);
} }
include_footer(); include_footer();
?> ?>
<?php <?php
include('lib/common.inc.php'); include('lib/common.inc.php');
$year = 2006; $year = 2006;
$ZeroX = 112.5; $ZeroX = 112.5;
$MaxX = 157; $MaxX = 157;
$ZeroY = -9; $ZeroY = -9;
$MaxY = -45; $MaxY = -45;
$XRange = $MaxX - $ZeroX; $XRange = $MaxX - $ZeroX;
$YRange = abs($MaxY) - abs($ZeroY); $YRange = abs($MaxY) - abs($ZeroY);
$xdivs = 250; $xdivs = 250;
$xdivlength = $XRange / $xdivs; $xdivlength = $XRange / $xdivs;
$ydivs = 250; $ydivs = 250;
$ydivheight = $YRange / $ydivs; $ydivheight = $YRange / $ydivs;
$borderLeft = 100; $borderLeft = 100;
$borderTop = 35; $borderTop = 35;
$width = 497; $width = 497;
$height = 457; $height = 457;
//echo "http://dev.openstreetmap.org/~pafciu17/?module=map&bbox=".$ZeroX.",".$ZeroY.",".$MaxX.",".$MaxY."&width=".$width."&height=".$height; //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 = ImageCreate ($width, $height) or die ("Cannot Create image");
$handle = imagecreatefrompng('images/australia.png'); $handle = imagecreatefrompng('images/australia.png');
$white = imagecolorallocate($handle, 0, 0, 0); $white = imagecolorallocate($handle, 0, 0, 0);
imagecolortransparent($handle, $white); imagecolortransparent($handle, $white);
$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 = '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" is null AND "supplierCountry" = \'Australia\' GROUP BY "supplierPostcode"';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
} }
$left = "FFFF50"; $left = "FFFF50";
$right= "EF0050"; $right= "EF0050";
$leftR = hexdec(substr($left,0,2)); $leftR = hexdec(substr($left,0,2));
$leftG = hexdec(substr($left,2,2)); $leftG = hexdec(substr($left,2,2));
$leftB = hexdec(substr($left,4,2)); $leftB = hexdec(substr($left,4,2));
$rightR = hexdec(substr($right,0,2)); $rightR = hexdec(substr($right,0,2));
$rightG = hexdec(substr($right,2,2)); $rightG = hexdec(substr($right,2,2));
$rightB = hexdec(substr($right,4,2)); $rightB = hexdec(substr($right,4,2));
for($i=0;$i<250;$i++) { for($i=0;$i<250;$i++) {
$colorset[$i] = imagecolorallocatealpha($handle, $leftR + ($i*(($rightR-$leftR)/250)), $leftG + ($i*(($rightG-$leftG)/250)), $leftB + ($i*(($rightB-$leftB)/250)),117 - ($i/250)*40); $colorset[$i] = imagecolorallocatealpha($handle, $leftR + ($i*(($rightR-$leftR)/250)), $leftG + ($i*(($rightG-$leftG)/250)), $leftB + ($i*(($rightB-$leftB)/250)),117 - ($i/250)*40);
} }
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
$xpage = round((($XRange - ($MaxX - $row['lon'])) / $xdivlength)); $xpage = round((($XRange - ($MaxX - $row['lon'])) / $xdivlength));
if ($row['lat'] < -40.25) $row['lat']-= 0.75; if ($row['lat'] < -40.25) $row['lat']-= 0.75;
$ypage = round(($YRange - (abs($MaxY) - abs($row['lat']))) / $ydivheight); $ypage = round(($YRange - (abs($MaxY) - abs($row['lat']))) / $ydivheight);
@$pagevalues[$xpage][$ypage] += $row['value']; @$pagevalues[$xpage][$ypage] += $row['value'];
//echo $ypage." ".$xpage."<br>"; //echo $ypage." ".$xpage."<br>";
} }
$max = 0; $max = 0;
$min = 0; $min = 0;
for ($i = 0;$i < $xdivs; $i++ ) { for ($i = 0;$i < $xdivs; $i++ ) {
for ($j = 0;$j < $ydivs; $j++ ) { for ($j = 0;$j < $ydivs; $j++ ) {
if (@$pagevalues[$i][$j]) if (@$pagevalues[$i][$j])
{ {
if (@$pagevalues[$i][$j] > $max) $max = @$pagevalues[$i][$j]; if (@$pagevalues[$i][$j] > $max) $max = @$pagevalues[$i][$j];
if ($min == 0 || @$pagevalues[$i][$j] < $min) $min = @$pagevalues[$i][$j]; if ($min == 0 || @$pagevalues[$i][$j] < $min) $min = @$pagevalues[$i][$j];
} else { } else {
@$pagevalues[$i][$j] = ((@$pagevalues[$i][$j] + (@$pagevalues[$i+1][$j] + @$pagevalues[$i][$j+1] @$pagevalues[$i][$j] = ((@$pagevalues[$i][$j] + (@$pagevalues[$i+1][$j] + @$pagevalues[$i][$j+1]
+ @$pagevalues[$i-1][$j] + @$pagevalues[$i][$j-1])/4) /2)-9; + @$pagevalues[$i-1][$j] + @$pagevalues[$i][$j-1])/4) /2)-9;
@$pagevalues[$i-1][$j] = ((@$pagevalues[$i-1][$j] + (@$pagevalues[$i][$j] + @$pagevalues[$i-1][$j+1] @$pagevalues[$i-1][$j] = ((@$pagevalues[$i-1][$j] + (@$pagevalues[$i][$j] + @$pagevalues[$i-1][$j+1]
+ @$pagevalues[$i-2][$j] + @$pagevalues[$i-1][$j-1])/4) /2)-9; + @$pagevalues[$i-2][$j] + @$pagevalues[$i-1][$j-1])/4) /2)-9;
@$pagevalues[$i][$j-1] = ((@$pagevalues[$i][$j-1] + (@$pagevalues[$i+1][$j-1] + @$pagevalues[$i][$j] @$pagevalues[$i][$j-1] = ((@$pagevalues[$i][$j-1] + (@$pagevalues[$i+1][$j-1] + @$pagevalues[$i][$j]
+ @$pagevalues[$i-1][$j-1] + @$pagevalues[$i][$j-2])/4) /2)-9; + @$pagevalues[$i-1][$j-1] + @$pagevalues[$i][$j-2])/4) /2)-9;
} }
} }
} }
//echo $max." ".$min; //echo $max." ".$min;
//echo "<table width='100%'>"; //echo "<table width='100%'>";
for ($i = 0;$i < $xdivs; $i++ ) { for ($i = 0;$i < $xdivs; $i++ ) {
// echo "<tr>"; // echo "<tr>";
for ($j = 0; $j < $ydivs; $j++ ) { for ($j = 0; $j < $ydivs; $j++ ) {
// echo ("<td>". log10(@$pagevalues[$i][$j])/log10($max) ."</td>"); // echo ("<td>". log10(@$pagevalues[$i][$j])/log10($max) ."</td>");
if ((@$pagevalues[$i][$j]) > $min) { if ((@$pagevalues[$i][$j]) > $min) {
$x = $i*($width/$xdivs); $x = $i*($width/$xdivs);
$x1 = $borderLeft + $x -($width/$xdivs); $x1 = $borderLeft + $x -($width/$xdivs);
$x2 = $borderLeft + $x +($width/$xdivs); $x2 = $borderLeft + $x +($width/$xdivs);
$y = $j*($height/$ydivs); $y = $j*($height/$ydivs);
$y1 = $borderTop + $y - ($height/$ydivs); $y1 = $borderTop + $y - ($height/$ydivs);
$y2 = $borderTop + $y + ($height/$ydivs); $y2 = $borderTop + $y + ($height/$ydivs);
imagefilledrectangle ($handle, $x1, $y1, $x2, $y2, $colorset[(int)((log10(@$pagevalues[$i][$j])/log10($max))*249)]); imagefilledrectangle ($handle, $x1, $y1, $x2, $y2, $colorset[(int)((log10(@$pagevalues[$i][$j])/log10($max))*249)]);
} }
} }
//echo "</tr>"; //echo "</tr>";
} }
//echo "</table>" //echo "</table>"
header ("Content-type: image/png"); header ("Content-type: image/png");
ImagePng ($handle); ImagePng ($handle);
?> ?>
<?php <?php
include_once("./lib/common.inc.php"); include_once("./lib/common.inc.php");
/* /*
biggest suppliers in each method biggest suppliers in each method
biggest agencies in each method (weighted for size? percentage of total expenditure) biggest agencies in each method (weighted for size? percentage of total expenditure)
largest Average value by procurement type? largest Average value by procurement type?
*/ */
include_header("Procurement Methods"); include_header("Procurement Methods");
$query = "SELECT SUM(value) as value, procurementMethod $query = "SELECT SUM(value) as value, procurementMethod
FROM `contractnotice` FROM `contractnotice`
WHERE childCN = 0 WHERE childCN is null
GROUP BY procurementMethod "; GROUP BY procurementMethod ";
$result = mysql_query($query); $result = mysql_query($query);
echo "<table>"; echo "<table>";
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row[0]),2); $value = number_format(doubleval($row[0]),2);
echo ("<tr><td><b>{$row[1]}</b></td><td>\$$value</td></tr>"); echo ("<tr><td><b>{$row[1]}</b></td><td>\$$value</td></tr>");
} }
echo "</table>"; echo "</table>";
mysql_free_result($result); mysql_free_result($result);
include_footer(); include_footer();
?> ?>
   
<?php <?php
include_once ("./lib/common.inc.php"); include_once ("./lib/common.inc.php");
if ($_REQUEST['supplier']) { if ($_REQUEST['supplier']) {
include_header("Supplier"); include_header("Supplier");
$supplierS = htmlentities(strip_tags($_REQUEST['supplier'])); $supplierS = htmlentities(strip_tags($_REQUEST['supplier']));
MethodCountGraph($supplierS); MethodCountGraph($supplierS);
CnCGraph($supplierS); CnCGraph($supplierS);
MethodValueGraph($supplierS); MethodValueGraph($supplierS);
/*lobbyist ties /*lobbyist ties
links to ABR/ASIC/Google News/ASX/Court records links to ABR/ASIC/Google News/ASX/Court records
total value to various agencies (bar graph) total value to various agencies (bar graph)
spread procurement methods + percent consultancies + percent confidential (bar graph) spread procurement methods + percent consultancies + percent confidential (bar graph)
spread of contract values spread of contract values
spread of industries (textual?)*/ spread of industries (textual?)*/
$query = 'SELECT "CNID", "description", "value", "agencyName", "category", $query = 'SELECT "CNID", "description", "value", "agencyName", "category",
"contractStart", "supplierName" "contractStart", "supplierName"
FROM contractnotice WHERE '. FROM contractnotice WHERE '.
$supplierQ.' '.$standardQ $supplierQ.' '.$standardQ
.' ORDER BY value DESC'; .' ORDER BY value DESC';
echo $query; echo $query;
$query = $conn->prepare($query); $query = $conn->prepare($query);
   
//$query->bindParam(":supplierName", $supplierName); //$query->bindParam(":supplierName", $supplierName);
$query->bindParam(":supplierABN", $supplierABN); $query->bindParam(":supplierABN", $supplierABN);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
} }
echo '<img src="graphs/displayMethodCountGraph.php?month=' . stripslashes($supplier) . '">'; echo '<img src="graphs/displayMethodCountGraph.php?month=' . stripslashes($supplier) . '">';
echo '<img src="graphs/displayCnCGraph.php?month=' . stripslashes($supplier) . '">'; echo '<img src="graphs/displayCnCGraph.php?month=' . stripslashes($supplier) . '">';
   
echo "<table> <thead> echo "<table> <thead>
<tr> <tr>
<th>Contract Notice Number</th> <th>Contract Notice Number</th>
<th>Contract Description</th> <th>Contract Description</th>
<th>Total Contract Value</th> <th>Total Contract Value</th>
<th>Agency</th> <th>Agency</th>
<th>Contract Start Date</th> <th>Contract Start Date</th>
<th>Supplier</th> <th>Supplier</th>
</tr> </tr>
</thead>"; </thead>";
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row['value']) , 2); $value = number_format(doubleval($row['value']) , 2);
echo ("<tr> echo ("<tr>
<td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td> <td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td>
<td><b>{$row['description']}</b></a></td> <td><b>{$row['description']}</b></a></td>
<td>\$$value</td><td>{$row['agencyName']}</td> <td>\$$value</td><td>{$row['agencyName']}</td>
<td>{$row['contractStart']}</td> <td>{$row['contractStart']}</td>
<td>{$row['supplierName']}</td> <td>{$row['supplierName']}</td>
</tr>"); </tr>");
} }
echo "</table>"; echo "</table>";
} else { } else {
/* /*
histograph of supplier size/value histograph of supplier size/value
*/ */
include_header("Suppliers"); include_header("Suppliers");
suppliersGraph(); suppliersGraph();
$query = 'SELECT SUM("value") as val, MAX("supplierName") as supplierName, "supplierABN",( $query = 'SELECT SUM("value") as val, MAX("supplierName") as supplierName, "supplierABN",(
case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as supplierID case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as supplierID
FROM contractnotice FROM contractnotice
WHERE "childCN" = 0 WHERE "childCN" is null
GROUP BY supplierID,"supplierABN" GROUP BY supplierID,"supplierABN"
ORDER BY val DESC ORDER BY val DESC
LIMIT 100'; LIMIT 100';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
} }
echo "<table> <thead> echo "<table> <thead>
<tr> <tr>
<th>Position</th> <th>Position</th>
<th>Supplier</th> <th>Supplier</th>
<th>Total Contract Value</th> <th>Total Contract Value</th>
</tr> </tr>
</thead>"; </thead>";
$i = 1; $i = 1;
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row['val']) , 2); $value = number_format(doubleval($row['val']) , 2);
$supplier = stripslashes($row['supplierABN'].'-'.$row['suppliername']); $supplier = stripslashes($row['supplierABN'].'-'.$row['suppliername']);
echo ("<tr><td>$i</td><td><b><a href=\"displaySupplier.php?supplier={$supplier}\">".ucsmart($row['suppliername'])."</a></b></td><td>\$$value</td></tr>\n"); echo ("<tr><td>$i</td><td><b><a href=\"displaySupplier.php?supplier={$supplier}\">".ucsmart($row['suppliername'])."</a></b></td><td>\$$value</td></tr>\n");
$i++; $i++;
} }
echo "</table>"; echo "</table>";
} }
include_footer(); include_footer();
?> ?>
   
<?php <?php
   
include_once("./lib/common.inc.php"); include_once("./lib/common.inc.php");
setlocale(LC_CTYPE, 'C'); setlocale(LC_CTYPE, 'C');
// source: http://stackoverflow.com/questions/81934/easy-way-to-export-a-sql-table-without-access-to-the-server-or-phpmyadmin#81951 // source: http://stackoverflow.com/questions/81934/easy-way-to-export-a-sql-table-without-access-to-the-server-or-phpmyadmin#81951
$query = $conn->prepare(' $query = $conn->prepare('
SELECT "CNID",contractnotice."agencyName",agency.abn as "agencyABN",EXTRACT(EPOCH FROM "publishDate") as "publishDate",EXTRACT(EPOCH FROM "contractStart") as "contractStart",EXTRACT(EPOCH FROM "contractEnd") as "contractEnd",value,description,"procurementMethod",category,"categoryUNSPSC", SELECT "CNID",contractnotice."agencyName",agency.abn as "agencyABN",EXTRACT(EPOCH FROM "publishDate") as "publishDate",EXTRACT(EPOCH FROM "contractStart") as "contractStart",EXTRACT(EPOCH FROM "contractEnd") as "contractEnd",value,description,"procurementMethod",category,"categoryUNSPSC",
"supplierABN","supplierName", "supplierABN","supplierName",
( (
case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as supplierID, case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as supplierID,
(\'https://www.tenders.gov.au/?event=public.advancedsearch.keyword&keyword=CN\'::text || "CNID"::text) as sourceURL (\'https://www.tenders.gov.au/?event=public.advancedsearch.keyword&keyword=CN\'::text || "CNID"::text) as sourceURL
FROM contractnotice join agency on contractnotice."agencyName"=agency."agencyName" where "childCN" = 0' FROM contractnotice join agency on contractnotice."agencyName"=agency."agencyName" where "childCN" is null'
, array(PDO::ATTR_CURSOR => PDO::FETCH_ORI_NEXT)); , array(PDO::ATTR_CURSOR => PDO::FETCH_ORI_NEXT));
// "supplierCity","supplierPostcode","supplierCountry","contactPostcode", // "supplierCity","supplierPostcode","supplierCountry","contactPostcode",
// (substr( "categoryUNSPSC"::text, 0, 2 ) || \'0000000\'::text) as "categoryUNSPSClv1", "categoryUNSPSC", (substr( "categoryUNSPSC"::text, 0, 3 ) || \'000000\'::text) as "categoryUNSPSClv2" "categoryUNSPSC", (substr( "categoryUNSPSC"::text, 0, 4 ) || \'00000\'::text as "categoryUNSPSClv3") // (substr( "categoryUNSPSC"::text, 0, 2 ) || \'0000000\'::text) as "categoryUNSPSClv1", "categoryUNSPSC", (substr( "categoryUNSPSC"::text, 0, 3 ) || \'000000\'::text) as "categoryUNSPSClv2" "categoryUNSPSC", (substr( "categoryUNSPSC"::text, 0, 4 ) || \'00000\'::text as "categoryUNSPSClv3")
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
die('Couldn\'t fetch records'); die('Couldn\'t fetch records');
} }
   
$num_fields = $query->columnCount(); $num_fields = $query->columnCount();
$headers = array(); $headers = array();
for ($i = 0; $i < $num_fields; $i++) { for ($i = 0; $i < $num_fields; $i++) {
$meta = $query->getColumnMeta($i); $meta = $query->getColumnMeta($i);
$headers[] = $meta['name']; $headers[] = $meta['name'];
} }
$fp = fopen('php://output', 'w'); $fp = fopen('php://output', 'w');
if ($fp && $query) { if ($fp && $query) {
header('Content-Type: text/csv'); header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="export.'.date("c").'.csv"'); header('Content-Disposition: attachment; filename="export.'.date("c").'.csv"');
header('Pragma: no-cache'); header('Pragma: no-cache');
header('Expires: 0'); header('Expires: 0');
fputcsv($fp, $headers); fputcsv($fp, $headers);
while ($row = $query->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) { while ($row = $query->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) {
foreach ($row as $key => &$colvalue) { foreach ($row as $key => &$colvalue) {
$colvalue = preg_replace( '/[^[:print:]]/', '', $colvalue = preg_replace( '/[^[:print:]]/', '',
utf8_encode($colvalue)); utf8_encode($colvalue));
if ($headers[$key] == "publishDate" || $headers[$key] == "contractStart" if ($headers[$key] == "publishDate" || $headers[$key] == "contractStart"
|| $headers[$key] == "contractEnd") { || $headers[$key] == "contractEnd") {
$colvalue = date("Y-m-d",$colvalue); $colvalue = date("Y-m-d",$colvalue);
} }
} }
fputcsv($fp, array_values($row)); fputcsv($fp, array_values($row));
} }
die; die;
} }
?> ?>
   
<?php <?php
date_default_timezone_set("Australia/ACT"); date_default_timezone_set("Australia/ACT");
error_reporting(E_ALL ^ E_NOTICE); error_reporting(E_ALL ^ E_NOTICE);
$conn = new PDO("pgsql:dbname=contractDashboard;user=postgres;password=snmc;host=localhost"); $conn = new PDO("pgsql:dbname=contractDashboard;user=postgres;password=snmc;host=localhost");
if (!$conn) { if (!$conn) {
die("A database error occurred.\n"); die("A database error occurred.\n");
} }
// $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
function databaseError($errMsg) function databaseError($errMsg)
{ {
die($errMsg); die(print_r($errMsg,true));
} }
function ucsmart($str) { function ucsmart($str) {
$shortWords = Array("The","Pty","Ltd","Inc","Red","Oil","A","An","And","At","For","In" $shortWords = Array("The","Pty","Ltd","Inc","Red","Oil","A","An","And","At","For","In"
,"Of","On","Or","The","To","With"); ,"Of","On","Or","The","To","With");
$strArray = explode(" ",preg_replace("/(?<=(?<!:|’s)\W) $strArray = explode(" ",preg_replace("/(?<=(?<!:|’s)\W)
(A|An|And|At|For|In|Of|On|Or|The|To|With) (A|An|And|At|For|In|Of|On|Or|The|To|With)
(?=\W)/e", 'strtolower("$1")', ucwords(strtolower($str)))); (?=\W)/e", 'strtolower("$1")', ucwords(strtolower($str))));
foreach($strArray as &$word) { foreach($strArray as &$word) {
if (strlen($word) <= 4 && !in_array($word,$shortWords)) $word = strtoupper($word); if (strlen($word) <= 4 && !in_array($word,$shortWords)) $word = strtoupper($word);
} }
return implode(" ",$strArray); return implode(" ",$strArray);
} }
function percent($num_amount, $num_total) { function percent($num_amount, $num_total) {
$count1 = $num_amount / $num_total; $count1 = $num_amount / $num_total;
$count2 = $count1 * 100; $count2 = $count1 * 100;
$count = number_format($count2, 2); $count = number_format($count2, 2);
return $count; return $count;
} }
function array_sum_all($a) { function array_sum_all($a) {
if(!is_array($a)) return $a; if(!is_array($a)) return $a;
foreach($a as $key=>$value) foreach($a as $key=>$value)
$totale += array_sum_all($value); $totale += array_sum_all($value);
return $totale; return $totale;
} }
// magic query modifiers // magic query modifiers
$agency = filter_var($_REQUEST['agency'], FILTER_SANITIZE_STRING); $agency = filter_var($_REQUEST['agency'], FILTER_SANITIZE_STRING);
if ($agency != "") $agencyQ = "agencyName = '" . $agency . "' AND "; if ($agency != "") $agencyQ = "agencyName = '" . $agency . "' AND ";
$supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING); $supplier = filter_var($_REQUEST['supplier'], FILTER_SANITIZE_STRING);
if ($supplier != "") { if ($supplier != "") {
$supplierParts = explode("-", $supplier); $supplierParts = explode("-", $supplier);
$supplierName = "%".$supplierParts[1]."%"; $supplierName = "%".$supplierParts[1]."%";
$supplierABN = $supplierParts[0]; $supplierABN = $supplierParts[0];
if ($supplierParts[0] > 0) $supplierQ = ' "supplierABN" = :supplierABN AND '; if ($supplierParts[0] > 0) $supplierQ = ' "supplierABN" = :supplierABN AND ';
else $supplierQ = ' "supplierName" LIKE :supplierName AND '; else $supplierQ = ' "supplierName" LIKE :supplierName AND ';
} }
$startYear = 2007; $startYear = 2007;
$year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT); $year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT);
if ($year != "") $yearQ = "YEAR(publishDate) = " . $year . " AND "; if ($year != "") $yearQ = "YEAR(publishDate) = " . $year . " AND ";
$standardQ = ' "childCN" = 0 '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010'; $standardQ = ' "childCN" is null '; // AND YEAR(contractStart) >= 2007 AND YEAR(contractStart) <= 2010';
$start =0.0; $start =0.0;
function include_header($title) { function include_header($title) {
global $start; global $start;
?> ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"> "http://www.w3.org/TR/html4/strict.dtd">
<html> <html>
<head> <head>
<title>Contract Dashboard - <?php echo $title; ?></title> <title>Contract Dashboard - <?php echo $title; ?></title>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.0r4/build/reset-fonts-grids/reset-fonts-grids.css"> <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.0r4/build/reset-fonts-grids/reset-fonts-grids.css">
<script type="text/javascript" src="lib/bsn.AutoSuggest_2.1.3_comp.js" charset="utf-8"></script> <script type="text/javascript" src="lib/bsn.AutoSuggest_2.1.3_comp.js" charset="utf-8"></script>
<link rel="stylesheet" href="autosuggest_inquisitor.css" type="text/css" media="screen" charset="utf-8" /> <link rel="stylesheet" href="autosuggest_inquisitor.css" type="text/css" media="screen" charset="utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() $(document).ready(function()
{ {
//hide the all of the element with class msg_body //hide the all of the element with class msg_body
$(".msg_body").hide(); $(".msg_body").hide();
//toggle the componenet with class msg_body //toggle the componenet with class msg_body
$(".msg_head").click(function() $(".msg_head").click(function()
{ {
$(this).next(".msg_body").slideToggle(600); $(this).next(".msg_body").slideToggle(600);
}); });
}); });
</script> </script>
<style type="text/css" title="currentStyle"> <style type="text/css" title="currentStyle">
@import "media/css/demo_table.css"; @import "media/css/demo_table.css";
</style> </style>
<script type="text/javascript" language="javascript" src="media/js/jquery.dataTables.js"></script> <script type="text/javascript" language="javascript" src="media/js/jquery.dataTables.js"></script>
<script type="text/javascript" charset="utf-8"> <script type="text/javascript" charset="utf-8">
jQuery.fn.dataTableExt.aTypes.unshift( jQuery.fn.dataTableExt.aTypes.unshift(
function ( sData ) function ( sData )
{ {
var sValidChars = "0123456789.-,"; var sValidChars = "0123456789.-,";
var Char; var Char;
/* Check the numeric part */ /* Check the numeric part */
for ( i=1 ; i<sData.length ; i++ ) for ( i=1 ; i<sData.length ; i++ )
{ {
Char = sData.charAt(i); Char = sData.charAt(i);
if (sValidChars.indexOf(Char) == -1) if (sValidChars.indexOf(Char) == -1)
{ {
return null; return null;
} }
} }
/* Check prefixed by currency */ /* Check prefixed by currency */
if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' ) if ( sData.charAt(0) == '$' || sData.charAt(0) == '£' )
{ {
return 'currency'; return 'currency';
} }
return null; return null;
} }
); );
jQuery.fn.dataTableExt.oSort['currency-asc'] = function(a,b) { jQuery.fn.dataTableExt.oSort['currency-asc'] = function(a,b) {
/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */ /* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
var x = a == "-" ? 0 : a.replace( /,/g, "" ); var x = a == "-" ? 0 : a.replace( /,/g, "" );
var y = b == "-" ? 0 : b.replace( /,/g, "" ); var y = b == "-" ? 0 : b.replace( /,/g, "" );
/* Remove the currency sign */ /* Remove the currency sign */
x = x.substring( 1 ); x = x.substring( 1 );
y = y.substring( 1 ); y = y.substring( 1 );
/* Parse and return */ /* Parse and return */
x = parseFloat( x ); x = parseFloat( x );
y = parseFloat( y ); y = parseFloat( y );
return x - y; return x - y;
}; };
jQuery.fn.dataTableExt.oSort['currency-desc'] = function(a,b) { jQuery.fn.dataTableExt.oSort['currency-desc'] = function(a,b) {
/* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */ /* Remove any commas (assumes that if present all strings will have a fixed number of d.p) */
var x = a == "-" ? 0 : a.replace( /,/g, "" ); var x = a == "-" ? 0 : a.replace( /,/g, "" );
var y = b == "-" ? 0 : b.replace( /,/g, "" ); var y = b == "-" ? 0 : b.replace( /,/g, "" );
/* Remove the currency sign */ /* Remove the currency sign */
x = x.substring( 1 ); x = x.substring( 1 );
y = y.substring( 1 ); y = y.substring( 1 );
/* Parse and return */ /* Parse and return */
x = parseFloat( x ); x = parseFloat( x );
y = parseFloat( y ); y = parseFloat( y );
return y - x; return y - x;
}; };
$(document).ready(function() { $(document).ready(function() {
$('table').dataTable(); $('table').dataTable();
} ); } );
</script> </script>
<link type="text/css" rel="stylesheet" href="style.css"> <link type="text/css" rel="stylesheet" href="style.css">
</head> </head>
<body><div id="doc3" class="yui-t4"> <body><div id="doc3" class="yui-t4">
<div id="hd"> <div id="hd">
<h1> contract dashboard</h1> <h1> contract dashboard</h1>
</div> </div>
<div id="sitenav"> <div id="sitenav">
<a href="displayAgency.php">agencies</a> <a href="displayAgency.php">agencies</a>
<a href="displaySupplier.php">suppliers</a> <a href="displaySupplier.php">suppliers</a>
<a href="displayCategory.php">product/service categories</a> <a href="displayCategory.php">product/service categories</a>
<a href="displayCalendar.php">time periods</a> <a href="displayCalendar.php">time periods</a>
| metrics | | metrics |
<a href="displayProcurementMethod.php">procurement method</a> <a href="displayProcurementMethod.php">procurement method</a>
<a href="displayConfidentialities.php">contractual confidentiality</a> <a href="displayConfidentialities.php">contractual confidentiality</a>
<a href="displayConsultancies.php">consultancies</a> <a href="displayConsultancies.php">consultancies</a>
<a href="displayAmendments.php">amendments</a> <a href="displayAmendments.php">amendments</a>
<a href="displayMap.php">postcodes</a> <a href="displayMap.php">postcodes</a>
<div id="search"><form method="post" action="search.php" class="asholder"> <div id="search"><form method="post" action="search.php" class="asholder">
<label for="searchKeyword">search</label> <label for="searchKeyword">search</label>
<input type="text" id="searchKeyword" name="searchKeyword" value="" style="width:150px" /> <input type="text" id="searchKeyword" name="searchKeyword" value="" style="width:150px" />
<input type="hidden" id="searchID" name="searchID" value=""/><input type="submit" value="submit" /> <input type="hidden" id="searchID" name="searchID" value=""/><input type="submit" value="submit" />
</form></div> </form></div>
<script type="text/javascript"> <script type="text/javascript">
var options_xml = { var options_xml = {
script: function (input) { return "search_autosuggest.php?input="+input; }, script: function (input) { return "search_autosuggest.php?input="+input; },
varname:"input", varname:"input",
callback: function (obj) { document.getElementById('searchID').value = obj.id; } callback: function (obj) { document.getElementById('searchID').value = obj.id; }
}; };
var as_xml = new bsn.AutoSuggest('searchKeyword', options_xml); var as_xml = new bsn.AutoSuggest('searchKeyword', options_xml);
</script> </script>
</div> </div>
<div id="bd" role="main"> <div id="bd" role="main">
<div id="yui-main"> <div id="yui-main">
<div class="yui-b"><div class="yui-g"> <div class="yui-b"><div class="yui-g">
<?php <?php
$start = (float) array_sum(explode(' ',microtime())); $start = (float) array_sum(explode(' ',microtime()));
} }
function include_footer() { function include_footer() {
global $start; global $start;
$end = (float) array_sum(explode(' ',microtime())); $end = (float) array_sum(explode(' ',microtime()));
?> ?>
</div> </div>
</div> </div>
</div> </div>
<div class="yui-b"> <div class="yui-b">
Filter by:<ul> Filter by:<ul>
<li>year <li>year
<ul><li>2008</li> <ul><li>2008</li>
</ul> </ul>
</li> </li>
</ul> <br> </div> </div> </ul> <br> </div> </div>
<?php <?php
echo '<div id="ft"><p>'."Processing time: ". sprintf("%.4f", ($end-$start))." seconds".'</p></div>'; echo '<div id="ft"><p>'."Processing time: ". sprintf("%.4f", ($end-$start))." seconds".'</p></div>';
echo '</div> </body> </html>'; echo '</div> </body> </html>';
} }
include ("graphs.inc.php"); include ("graphs.inc.php");
?> ?>
   
<?php <?php
$includedFlot = false; $includedFlot = false;
function includeFlot() { function includeFlot() {
if (!$includedFlot) { if (!$includedFlot) {
echo ' <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="lib/flot/excanvas.min.js"></script><![endif]--> echo ' <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="lib/flot/excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.js"></script> <script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.pie.js"></script> <script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.pie.js"></script>
<script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.selection.js"></script> <script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.selection.js"></script>
<script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.stack.js"></script> <script language="javascript" type="text/javascript" src="lib/flot/jquery.flot.stack.js"></script>
   
'; ';
$includedFlot = true; $includedFlot = true;
} }
} }
   
function CNDistributionGraph() { function CNDistributionGraph() {
global $conn; global $conn;
includeFlot(); includeFlot();
?> ?>
<center><div id="cndist" style="width:900px;height:550px"></div></center> <center><div id="cndist" style="width:900px;height:550px"></div></center>
<script type="text/javascript"> <script type="text/javascript">
var placeholder = $("#cndist"); var placeholder = $("#cndist");
$(function () { $(function () {
   
var d1 = []; var d1 = [];
var d2 = []; var d2 = [];
<?php <?php
$query = 'select cnid, count(*) from (select ("CNID" - MOD("CNID",100)) as cnid from contractnotice where "CNID" < 999999 and "parentCN" is null) as a group by cnid order by cnid'; $query = 'select cnid, count(*) from (select ("CNID" - MOD("CNID",100)) as cnid from contractnotice where "CNID" < 999999 and "parentCN" is null) as a group by cnid order by cnid';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
return Array(); return Array();
} }
   
foreach ($query->fetchAll() as $delta) { foreach ($query->fetchAll() as $delta) {
   
echo "d1.push([ ".intval($delta['cnid']).", ".intval($delta['count'])."]); \n"; echo "d1.push([ ".intval($delta['cnid']).", ".intval($delta['count'])."]); \n";
}; };
$query = 'select cnid, count(*) from (select ("CNID" - MOD("CNID",100)) as cnid from contractnotice where "CNID" < 999999 and "parentCN" is not null) as a group by cnid order by cnid'; $query = 'select cnid, count(*) from (select ("CNID" - MOD("CNID",100)) as cnid from contractnotice where "CNID" < 999999 and "parentCN" is not null) as a group by cnid order by cnid';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
return Array(); return Array();
} }
   
foreach ($query->fetchAll() as $delta) { foreach ($query->fetchAll() as $delta) {
   
echo "d2.push([ ".intval($delta['cnid']).", ".intval($delta['count'])."]); \n"; echo "d2.push([ ".intval($delta['cnid']).", ".intval($delta['count'])."]); \n";
}; };
?> ?>
   
var data = [ var data = [
{ {
data: d1, data: d1,
series: { series: {
lines: { show: true }, lines: { show: true },
points: { show: true } points: { show: true }
}, },
bars: { show: true } bars: { show: true }
}, },
{ {
data: d2, data: d2,
series: { series: {
lines: { show: true }, lines: { show: true },
points: { show: true } points: { show: true }
}, },
bars: { show: true } bars: { show: true }
}, },
]; ];
var options = var options =
{ {
series: { series: {
stack: true, stack: true,
}, },
grid: { hoverable: true, clickable: true, labelMargin: 17 }, grid: { hoverable: true, clickable: true, labelMargin: 17 },
selection: { mode: "x" } selection: { mode: "x" }
}; };
   
placeholder.bind("plotselected", function (event, ranges) { placeholder.bind("plotselected", function (event, ranges) {
plot = $.plot(placeholder, data, plot = $.plot(placeholder, data,
$.extend(true, {}, options, { $.extend(true, {}, options, {
xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to } xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to }
})); }));
}); });
var previousPoint = null; var previousPoint = null;
placeholder.bind("plothover", function (event, pos, item) { placeholder.bind("plothover", function (event, pos, item) {
$("#x").text(pos.x.toFixed(2)); $("#x").text(pos.x.toFixed(2));
$("#y").text(pos.y.toFixed(2)); $("#y").text(pos.y.toFixed(2));
if (item) { if (item) {
if (previousPoint != item.dataIndex) { if (previousPoint != item.dataIndex) {
previousPoint = item.dataIndex; previousPoint = item.dataIndex;
$("#tooltip").remove(); $("#tooltip").remove();
var x = item.datapoint[0].toFixed(2), var x = item.datapoint[0].toFixed(2),
y = item.datapoint[1].toFixed(2); y = item.datapoint[1].toFixed(2);
showTooltip(item.pageX, item.pageY, showTooltip(item.pageX, item.pageY,
item.series.label + " of " + x + " = " + y); item.series.label + " of " + x + " = " + y);
} }
} }
else { else {
$("#tooltip").remove(); $("#tooltip").remove();
previousPoint = null; previousPoint = null;
} }
}); });
   
var plot = $.plot(placeholder, data, var plot = $.plot(placeholder, data,
options); options);
}); });
   
function showTooltip(x, y, contents) { function showTooltip(x, y, contents) {
$('<div id="tooltip">' + contents + '</div>').css( { $('<div id="tooltip">' + contents + '</div>').css( {
position: 'absolute', position: 'absolute',
display: 'none', display: 'none',
top: y + 5, top: y + 5,
left: x + 5, left: x + 5,
border: '1px solid #fdd', border: '1px solid #fdd',
padding: '2px', padding: '2px',
'background-color': '#fee', 'background-color': '#fee',
opacity: 0.80 opacity: 0.80
}).appendTo("body").fadeIn(200); }).appendTo("body").fadeIn(200);
} }
</script> </script>
<?php <?php
} }
   
function agenciesGraph() { function agenciesGraph() {
global $conn; global $conn;
includeFlot(); includeFlot();
$query = 'SELECT SUM("value") as val, MAX(contractnotice."agencyName") as agencyname FROM contractnotice join agency on contractnotice."agencyName"=agency."agencyName" WHERE "childCN" = 0 $query = 'SELECT SUM("value") as val, MAX(contractnotice."agencyName") as agencyname FROM contractnotice join agency on contractnotice."agencyName"=agency."agencyName" WHERE "childCN" is null
GROUP BY abn ORDER BY SUM("value") DESC'; GROUP BY abn ORDER BY SUM("value") DESC';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
return Array(); return Array();
} }
?> ?>
<script type="text/javascript"> <script type="text/javascript">
$(function () { $(function () {
// data // data
var data = [ var data = [
<?php <?php
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
echo '{ label: "'.$row['agencyname'].'", data: '.doubleval($row["val"]).'},'; echo '{ label: "'.$row['agencyname'].'", data: '.doubleval($row["val"]).'},';
} }
?> ?>
]; ];
// GRAPH 7 // GRAPH 7
$.plot($("#graph7"), data, $.plot($("#graph7"), data,
{ {
series: { series: {
pie: { pie: {
show: true, show: true,
radius: 1, radius: 1,
tilt: 0.75, tilt: 0.75,
label: { label: {
show: true, show: true,
radius: 1, radius: 1,
formatter: function(label, series){ formatter: function(label, series){
return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+': '+Math.round(series.percent)+'%</div>'; return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+': '+Math.round(series.percent)+'%</div>';
}, },
background: { background: {
opacity: 0.5, opacity: 0.5,
color: '#000' color: '#000'
} }
}, },
combine: { combine: {
color: '#999', color: '#999',
threshold: 0.012 threshold: 0.012
} }
} }
}, },
legend: { legend: {
show: false show: false
} }
}); });
}); });
</script> </script>
<div id="graph7" style="width:900px;height:550px"></div> <div id="graph7" style="width:900px;height:550px"></div>
   
<?php <?php
}; };
   
function agencySuppliersGraph($agency) { function agencySuppliersGraph($agency) {
$agency = "AusAid"; $agency = "AusAid";
$topX = 15; $topX = 15;
$query = "SELECT SUM(value) as val, supplierName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND childCN = 0 AND agencyName = '$agency' $query = 'SELECT SUM(value) as val, supplierName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND "childCN" is null AND agencyName = \'$agency\'
GROUP BY lower(supplierName) ORDER BY val DESC limit $topX"; GROUP BY lower(supplierName) ORDER BY val DESC limit $topX';
$result = mysql_query($query); $result = mysql_query($query);
$suppliers = Array(); $suppliers = Array();
$values = Array(); $values = Array();
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
$suppliers[] = ucsmart($row['supplierName']); $suppliers[] = ucsmart($row['supplierName']);
$values[] = doubleval($row["val"]); $values[] = doubleval($row["val"]);
} }
mysql_free_result($result); mysql_free_result($result);
   
$query = "SELECT sum(a.val) as value, count(1) as count from (SELECT SUM(value) as val, supplierName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND childCN = 0 and agencyName = '$agency' $query = 'SELECT sum(a.val) as value, count(1) as count from (SELECT SUM(value) as val, supplierName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND "childCN" is null and agencyName = \'$agency\'
GROUP BY lower(supplierName) ORDER BY val DESC LIMIT 18446744073709551610 OFFSET $topX) as a"; GROUP BY lower(supplierName) ORDER BY val DESC LIMIT 18446744073709551610 OFFSET $topX) as a';
$result = mysql_query($query); $result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
if ($row['count'] > 0) { if ($row['count'] > 0) {
$suppliers[] = $row['count'] . " other suppliers"; $suppliers[] = $row['count'] . " other suppliers";
$values[] = doubleval($row[0]); $values[] = doubleval($row[0]);
} }
} }
mysql_free_result($result); mysql_free_result($result);
} }
   
function CnCGraph() { function CnCGraph() {
$query = "select procurementMethod, count(1) as count, SUM(value) as val, MONTH(contractStart) as month, YEAR(contractStart) as year from `contractnotice` $query = "select procurementMethod, count(1) as count, SUM(value) as val, MONTH(contractStart) as month, YEAR(contractStart) as year from `contractnotice`
where $agencyQ $supplierQ $standardQ group by procurementMethod,year,month order by procurementMethod,year,month"; where $agencyQ $supplierQ $standardQ group by procurementMethod,year,month order by procurementMethod,year,month";
$result = mysql_query($query); $result = mysql_query($query);
$methods = Array("Direct","Open","Select"); $methods = Array("Direct","Open","Select");
$dates = Array(); $dates = Array();
$methodCountsP = Array(); $methodCountsP = Array();
$methodCounts = Array(); $methodCounts = Array();
$maxValue = 0; $maxValue = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
if ($row['val'] > $maxValue) $maxValue = $row['val']; if ($row['val'] > $maxValue) $maxValue = $row['val'];
$date = date( 'F ', mktime(0, 0, 0, $row["month"]) ). $row["year"]; $date = date( 'F ', mktime(0, 0, 0, $row["month"]) ). $row["year"];
if (array_search($date,$dates) === false ) { if (array_search($date,$dates) === false ) {
$dates[$row["year"]*100 + $row["month"]] = $date; $dates[$row["year"]*100 + $row["month"]] = $date;
ksort($dates); ksort($dates);
} }
$methodCountsP[$row["procurementMethod"]][$date] = $row["count"]; $methodCountsP[$row["procurementMethod"]][$date] = $row["count"];
   
} }
foreach ($methods as $method) { foreach ($methods as $method) {
foreach($dates as $date) { foreach($dates as $date) {
if ($methodCountsP[$method][$date] > 0) $methodCounts[$method][] = $methodCountsP[$method][$date]; if ($methodCountsP[$method][$date] > 0) $methodCounts[$method][] = $methodCountsP[$method][$date];
else $methodCounts[$method][] = 0; else $methodCounts[$method][] = 0;
} }
} }
$dates = array_values($dates); $dates = array_values($dates);
$totalRecords = array_sum_all($methodCounts); $totalRecords = array_sum_all($methodCounts);
mysql_free_result($result); mysql_free_result($result);
   
   
function formatCallback($aVal) { function formatCallback($aVal) {
global $totalRecords; global $totalRecords;
return percent($aVal, $totalRecords) . "%"; return percent($aVal, $totalRecords) . "%";
} }
$attributes = Array(); $attributes = Array();
$attributeNames = Array( $attributeNames = Array(
"Consultancies", "Consultancies",
"Confidentialities" "Confidentialities"
); );
$query = "SELECT 'consultancy', count(1) FROM `contractnotice` WHERE $agencyQ $supplierQ consultancy='Yes' AND childCN = 0;"; $query = 'SELECT \'consultancy\', count(1) FROM `contractnotice` WHERE $agencyQ $supplierQ consultancy=\'Yes\' AND "childCN" is null;';
$result = mysql_query($query); $result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_BOTH); $row = mysql_fetch_array($result, MYSQL_BOTH);
$attributes[0] = $row[1]; $attributes[0] = $row[1];
$query = "SELECT 'confidentiality', count(1) FROM `contractnotice` WHERE $agencyQ $supplierQ (confidentialityContract='Yes' OR confidentialityOutputs='Yes') AND childCN = 0;"; $query = 'SELECT \'confidentiality\', count(1) FROM `contractnotice` WHERE $agencyQ $supplierQ (confidentialityContract=\'Yes\' OR confidentialityOutputs=\'Yes\') AND "childCN" is null;';
$result = mysql_query($query); $result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_BOTH); $row = mysql_fetch_array($result, MYSQL_BOTH);
$attributes[1] = $row[1]; $attributes[1] = $row[1];
mysql_free_result($result); mysql_free_result($result);
} }
function ContractPublishedGraph() { function ContractPublishedGraph() {
$query = "SELECT YEAR(publishDate), MONTH(publishDate), $query = 'SELECT YEAR(publishDate), MONTH(publishDate),
SUM(value) as val, count(1) as count FROM `contractnotice` SUM(value) as val, count(1) as count FROM `contractnotice`
WHERE (YEAR(publishDate) >= 2008) WHERE (YEAR(publishDate) >= 2008)
AND childCN = 0 AND "childCN" is null
GROUP BY MONTH(publishDate), YEAR(publishDate) GROUP BY MONTH(publishDate), YEAR(publishDate)
ORDER BY YEAR(publishDate), MONTH(publishDate)"; ORDER BY YEAR(publishDate), MONTH(publishDate)';
   
$result = mysql_query($query); $result = mysql_query($query);
$dates = Array(); $dates = Array();
$values = Array(); $values = Array();
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row["val"]),2); $value = number_format(doubleval($row["val"]),2);
$month_name = date( 'F', mktime(0, 0, 0, $row[1]) ); $month_name = date( 'F', mktime(0, 0, 0, $row[1]) );
$dates[] = $month_name." {$row[0]}"; $dates[] = $month_name." {$row[0]}";
$counts[] = doubleval($row["count"]); $counts[] = doubleval($row["count"]);
$values[] = doubleval($row["val"]); $values[] = doubleval($row["val"]);
} }
mysql_free_result($result); mysql_free_result($result);
   
} }
function ContractStartingGraph() { function ContractStartingGraph() {
$query = "SELECT YEAR(contractStart), MONTH(contractStart), $query = 'SELECT YEAR(contractStart), MONTH(contractStart),
SUM(value) as val, count(1) as count FROM `contractnotice` SUM(value) as val, count(1) as count FROM `contractnotice`
WHERE (YEAR(contractStart) >= 2008) WHERE (YEAR(contractStart) >= 2008)
AND childCN = 0 AND "childCN" is null
GROUP BY MONTH(contractStart), YEAR(contractStart) GROUP BY MONTH(contractStart), YEAR(contractStart)
ORDER BY YEAR(contractStart), MONTH(contractStart)"; ORDER BY YEAR(contractStart), MONTH(contractStart)';
   
$result = mysql_query($query); $result = mysql_query($query);
$dates = Array(); $dates = Array();
$values = Array(); $values = Array();
while ($row = mysql_fetch_array($result, MYSQL_BOTH)) { while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
$value = number_format(doubleval($row["val"]),2); $value = number_format(doubleval($row["val"]),2);
$month_name = date( 'F', mktime(0, 0, 0, $row[1]) ); $month_name = date( 'F', mktime(0, 0, 0, $row[1]) );
$dates[] = $month_name." {$row[0]}"; $dates[] = $month_name." {$row[0]}";
$counts[] = doubleval($row["count"]); $counts[] = doubleval($row["count"]);
$values[] = doubleval($row["val"]); $values[] = doubleval($row["val"]);
} }
mysql_free_result($result); mysql_free_result($result);
} }
function MethodCountGraph() { function MethodCountGraph() {
$query = "select procurementMethod, count(1) as count, SUM(value) as value, MONTH(contractStart) as month, YEAR(contractStart) as year from `contractnotice` $query = 'select procurementMethod, count(1) as count, SUM(value) as value, MONTH(contractStart) as month, YEAR(contractStart) as year from `contractnotice`
where $agencyQ $supplierQ $standardQ group by procurementMethod,year,month order by procurementMethod,year,month"; where $agencyQ $supplierQ $standardQ group by procurementMethod,year,month order by procurementMethod,year,month';
$result = mysql_query($query); $result = mysql_query($query);
$methods = Array("Direct","Open","Select"); $methods = Array("Direct","Open","Select");
$dates = Array(); $dates = Array();
$methodCountsP = Array(); $methodCountsP = Array();
$methodCounts = Array(); $methodCounts = Array();
$maxValue = 0; $maxValue = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
if ($row['value'] > $maxValue) $maxValue = $row['value']; if ($row['value'] > $maxValue) $maxValue = $row['value'];
$date = date( 'F ', mktime(0, 0, 0, $row["month"]) ). $row["year"]; $date = date( 'F ', mktime(0, 0, 0, $row["month"]) ). $row["year"];
if (array_search($date,$dates) === false ) { if (array_search($date,$dates) === false ) {
$dates[$row["year"]*100 + $row["month"]] = $date; $dates[$row["year"]*100 + $row["month"]] = $date;
ksort($dates); ksort($dates);
} }
$methodCountsP[$row["procurementMethod"]][$date] = $row["count"]; $methodCountsP[$row["procurementMethod"]][$date] = $row["count"];
   
} }
foreach ($methods as $method) { foreach ($methods as $method) {
foreach($dates as $date) { foreach($dates as $date) {
if ($methodCountsP[$method][$date] > 0) $methodCounts[$method][] = $methodCountsP[$method][$date]; if ($methodCountsP[$method][$date] > 0) $methodCounts[$method][] = $methodCountsP[$method][$date];
else $methodCounts[$method][] = 0; else $methodCounts[$method][] = 0;
} }
} }
$dates = array_values($dates); $dates = array_values($dates);
$totalRecords = array_sum_all($methodCounts); $totalRecords = array_sum_all($methodCounts);
mysql_free_result($result); mysql_free_result($result);
} }
function MethodValueGraph() { function MethodValueGraph() {
$query = "select procurementMethod, SUM(value) as value, MONTH(contractStart) as month, YEAR(contractStart) as year from `contractnotice` $query = "select procurementMethod, SUM(value) as value, MONTH(contractStart) as month, YEAR(contractStart) as year from `contractnotice`
where $agencyQ $supplierQ $standardQ group by procurementMethod,year,month order by procurementMethod,year,month"; where $agencyQ $supplierQ $standardQ group by procurementMethod,year,month order by procurementMethod,year,month";
$result = mysql_query($query); $result = mysql_query($query);
$methods = Array("Direct","Open","Select"); $methods = Array("Direct","Open","Select");
$dates = Array(); $dates = Array();
$methodValuesP = Array(); $methodValuesP = Array();
$methodValues = Array(); $methodValues = Array();
$maxValue = 0; $maxValue = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
if ($row['value'] > $maxValue) $maxValue = $row['value']; if ($row['value'] > $maxValue) $maxValue = $row['value'];
$date = date( 'F ', mktime(0, 0, 0, $row["month"]) ). $row["year"]; $date = date( 'F ', mktime(0, 0, 0, $row["month"]) ). $row["year"];
if (array_search($date,$dates) === false ) { if (array_search($date,$dates) === false ) {
$dates[$row["year"]*100 + $row["month"]] = $date; $dates[$row["year"]*100 + $row["month"]] = $date;
ksort($dates); ksort($dates);
} }
$methodValuesP[$row["procurementMethod"]][$date] = $row["value"]; $methodValuesP[$row["procurementMethod"]][$date] = $row["value"];
   
} }
foreach ($methods as $method) { foreach ($methods as $method) {
foreach($dates as $date) { foreach($dates as $date) {
if ($methodValuesP[$method][$date] > 0) $methodValues[$method][] = $methodValuesP[$method][$date]; if ($methodValuesP[$method][$date] > 0) $methodValues[$method][] = $methodValuesP[$method][$date];
else $methodValues[$method][] = 0; else $methodValues[$method][] = 0;
} }
} }
$dates = array_values($dates); $dates = array_values($dates);
$totalRecords = array_sum_all($methodValues); $totalRecords = array_sum_all($methodValues);
mysql_free_result($result); mysql_free_result($result);
   
} }
function SuppliersGraph() { function SuppliersGraph() {
   
global $conn; global $conn;
includeFlot(); includeFlot();
$topX = 10; $topX = 10;
$suppliers = Array(); $suppliers = Array();
$values = Array(); $values = Array();
   
   
$query = 'SELECT SUM("value") as value, MAX("supplierName") as supplierName, ( $query = 'SELECT SUM("value") as value, MAX("supplierName") as supplierName, (
case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as supplierID case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as supplierID
FROM contractnotice FROM contractnotice
WHERE "childCN" = 0 WHERE "childCN" is null
GROUP BY supplierID GROUP BY supplierID
ORDER BY value DESC ORDER BY value DESC
LIMIT '.$topX; LIMIT '.$topX;
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
} }
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
setlocale(LC_MONETARY, 'en_US'); setlocale(LC_MONETARY, 'en_US');
// $value = number_format(doubleval($row["value"]) , 2); // $value = number_format(doubleval($row["value"]) , 2);
$suppliers[] = ucsmart($row[1]); $suppliers[] = ucsmart($row[1]);
$values[] = doubleval($row["value"]); $values[] = doubleval($row["value"]);
} }
   
$query = 'SELECT sum(a.svalue) as val, suppliercountry from (SELECT sum("value") as svalue, max("supplierCountry") as 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\' FROM contractnotice WHERE "childCN" is null 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 '; 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 = $conn->prepare($query);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
} }
   
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
$suppliers[] = "Other suppliers in ".ucsmart($row["suppliercountry"]); $suppliers[] = "Other suppliers in ".ucsmart($row["suppliercountry"]);
$values[] = doubleval($row[0]); $values[] = doubleval($row[0]);
} }
   
   
$query = 'SELECT sum(a.value) as val, substring( $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 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 FROM contractnotice WHERE "childCN" is null
GROUP BY "supplierABN" ORDER BY sum(value) LIMIT 1844674 OFFSET 10) as a GROUP BY "supplierABN" ORDER BY sum(value) LIMIT 1844674 OFFSET 10) as a
WHERE (suppliercountry ILIKE \'Australia\') WHERE (suppliercountry ILIKE \'Australia\')
group by substring( group by substring(
supplierpostcode from 0 for 2) supplierpostcode from 0 for 2)
order by val DESC;'; order by val DESC;';
$query = $conn->prepare($query); $query = $conn->prepare($query);
$query->execute(); $query->execute();
if (!$query) { if (!$query) {
databaseError($conn->errorInfo()); databaseError($conn->errorInfo());
} }
   
foreach ($query->fetchAll() as $row) { foreach ($query->fetchAll() as $row) {
if ($row['postcode'][0] == 2 && $row['postcode'][1] == 6) $ACTvalue += $row[0]; 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] == 2 || $row['postcode'][0] == 1) $NSWvalue += $row[0];
else if ($row['postcode'][0] == 3 || $row['postcode'][0] == 8) $Vicvalue += $row[0]; else if ($row['postcode'][0] == 3 || $row['postcode'][0] == 8) $Vicvalue += $row[0];
else if ($row['postcode'][0] == 4 || $row['postcode'][0] == 9) $QLDvalue += $row[0]; else if ($row['postcode'][0] == 4 || $row['postcode'][0] == 9) $QLDvalue += $row[0];
else if ($row['postcode'][0] == 5) $SAvalue += $row[0]; else if ($row['postcode'][0] == 5) $SAvalue += $row[0];
else if ($row['postcode'][0] == 6) $WAvalue += $row[0]; else if ($row['postcode'][0] == 6) $WAvalue += $row[0];
else if ($row['postcode'][0] == 7) $Tasvalue += $row[0]; else if ($row['postcode'][0] == 7) $Tasvalue += $row[0];
else if ($row['postcode'][0] == 0) $NTvalue += $row[0]; else if ($row['postcode'][0] == 0) $NTvalue += $row[0];
} }
$suppliers[] = "Other suppliers in Australia - ACT"; $suppliers[] = "Other suppliers in Australia - ACT";
$values[] = doubleval($ACTvalue); $values[] = doubleval($ACTvalue);
$suppliers[] = "Other suppliers in Australia - NSW"; $suppliers[] = "Other suppliers in Australia - NSW";
$values[] = doubleval($NSWvalue); $values[] = doubleval($NSWvalue);
$suppliers[] = "Other suppliers in Australia - Victoria"; $suppliers[] = "Other suppliers in Australia - Victoria";
$values[] = doubleval($Vicvalue); $values[] = doubleval($Vicvalue);
$suppliers[] = "Other suppliers in Australia - Queensland"; $suppliers[] = "Other suppliers in Australia - Queensland";
$values[] = doubleval($QLDvalue); $values[] = doubleval($QLDvalue);
$suppliers[] = "Other suppliers in Australia - NT"; $suppliers[] = "Other suppliers in Australia - NT";
$values[] = doubleval($NTvalue); $values[] = doubleval($NTvalue);
$suppliers[] = "Other suppliers in Australia - West Australia"; $suppliers[] = "Other suppliers in Australia - West Australia";
$values[] = doubleval($WAvalue); $values[] = doubleval($WAvalue);
$suppliers[] = "Other suppliers in Australia - South Australia"; $suppliers[] = "Other suppliers in Australia - South Australia";
$values[] = doubleval($SAvalue); $values[] = doubleval($SAvalue);
$suppliers[] = "Other suppliers in Australia - Tasmania"; $suppliers[] = "Other suppliers in Australia - Tasmania";
$values[] = doubleval($Tasvalue); $values[] = doubleval($Tasvalue);
   
   
?> ?>
<script type="text/javascript"> <script type="text/javascript">
$(function () { $(function () {
// data // data
var data = [ var data = [
<?php <?php
foreach ($suppliers as $key => $supplier) { foreach ($suppliers as $key => $supplier) {
echo '{ label: "'.$supplier.'", data: '.doubleval($values[$key]).'},'; echo '{ label: "'.$supplier.'", data: '.doubleval($values[$key]).'},';
} }
?> ?>
]; ];
// GRAPH 7 // GRAPH 7
$.plot($("#graph7"), data, $.plot($("#graph7"), data,
{ {
series: { series: {
pie: { pie: {
show: true, show: true,
radius: 1, radius: 1,
tilt: 0.75, tilt: 0.75,
label: { label: {
show: true, show: true,
radius: 1, radius: 1,
formatter: function(label, series){ formatter: function(label, series){
return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+': '+Math.round(series.percent)+'%</div>'; return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+': '+Math.round(series.percent)+'%</div>';
}, },
background: { background: {
opacity: 0.5, opacity: 0.5,
color: '#000' color: '#000'
} }
}, },
combine: { combine: {
color: '#999', color: '#999',
threshold: 0.012 threshold: 0.012
} }
} }
}, },
legend: { legend: {
show: false show: false
} }
}); });
}); });
</script> </script>
<div id="graph7" style="width:900px;height:550px"></div> <div id="graph7" style="width:900px;height:550px"></div>
   
<?php <?php
} }
   
?> ?>