--- a/lib/graphs.inc.php +++ b/lib/graphs.inc.php @@ -136,7 +136,7 @@ global $conn; includeFlot(); - $query = 'SELECT SUM("value") as val, MAX(contractnotice."agencyName") as agencyname FROM contractnotice join agency on contractnotice."agencyName"=agency."agencyName" WHERE "childCN" is null + $query = 'SELECT SUM("value") as val, MAX(contractnotice."agencyName") as agencyname FROM contractnotice join agency_nametoabn on contractnotice."agencyName"=agency_nametoabn."agencyName" WHERE "childCN" is null GROUP BY abn ORDER BY SUM("value") DESC'; $query = $conn->prepare($query); $query->execute(); @@ -195,11 +195,15 @@ ; function agencySuppliersGraph($agency) { + + global $conn; $agency = "AusAid"; $topX = 15; - $query = 'SELECT SUM(value) as val, supplierName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND "childCN" is null AND agencyName = \'$agency\' + $query = 'SELECT SUM(value) as val, "supplierName" FROM contractnotice WHERE (extract ("YEAR" from "contractStart") >= :startYear) AND "childCN" is null AND "agencyName" = :agency GROUP BY lower(supplierName) ORDER BY val DESC limit $topX'; $query = $conn->prepare($query); + $query->bindParam(":startYear",$startYear); + $query->bindParam(":agency",$agency); $query->execute(); databaseError($conn->errorInfo()); $suppliers = Array(); @@ -210,9 +214,11 @@ } - $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'; - $query = $conn->prepare($query); + $query = 'SELECT sum(a.val) as value, count(1) as count from (SELECT SUM(value) as val, "supplierName" FROM contractnotice WHERE (extract ("YEAR" from "contractStart") >= :startYear) AND "childCN" is null and "agencyName" = :agency +GROUP BY lower("supplierName") ORDER BY val DESC LIMIT 18446744073709551610 OFFSET $topX) as a'; + $query = $conn->prepare($query); + $query->bindParam(":startYear",$startYear); + $query->bindParam(":agency",$agency); $query->execute(); databaseError($conn->errorInfo()); foreach ($query->fetchAll() as $row) { @@ -224,8 +230,10 @@ } function CnCGraph() { - $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"; + + global $conn; + $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'; $query = $conn->prepare($query); $query->execute(); databaseError($conn->errorInfo()); @@ -267,19 +275,21 @@ "Consultancies", "Confidentialities" ); - $query = 'SELECT \'consultancy\', count(1) FROM `contractnotice` WHERE $agencyQ $supplierQ consultancy=\'Yes\' AND "childCN" is null;'; + $query = 'SELECT \'consultancy\', count(1) FROM contractnotice WHERE $agencyQ $supplierQ consultancy=\'Yes\' AND "childCN" is null;'; $result = $conn->query($query); $row = $result->fetch(PDO::FETCH_ASSOC); $attributes[0] = $row[1]; - $query = 'SELECT \'confidentiality\', count(1) FROM `contractnotice` WHERE $agencyQ $supplierQ (confidentialityContract=\'Yes\' OR confidentialityOutputs=\'Yes\') AND "childCN" is null;'; + $query = 'SELECT \'confidentiality\', count(1) FROM contractnotice WHERE $agencyQ $supplierQ (confidentialityContract=\'Yes\' OR confidentialityOutputs=\'Yes\') AND "childCN" is null;'; $result = $conn->query($query); $row = $result->fetch(PDO::FETCH_ASSOC); $attributes[1] = $row[1]; } function ContractPublishedGraph() { + + global $conn; $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) AND "childCN" is null GROUP BY MONTH(publishDate), YEAR(publishDate) @@ -302,8 +312,10 @@ } function ContractStartingGraph() { + + global $conn; $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) AND "childCN" is null GROUP BY MONTH(contractStart), YEAR(contractStart) @@ -326,7 +338,9 @@ } function MethodCountGraph() { - $query = 'select procurementMethod, count(1) as count, SUM(value) as value, MONTH(contractStart) as month, YEAR(contractStart) as year from `contractnotice` + + global $conn; + $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'; $methods = Array("Direct", "Open", "Select"); $dates = Array(); @@ -361,7 +375,9 @@ } function MethodValueGraph() { - $query = "select procurementMethod, SUM(value) as value, MONTH(contractStart) as month, YEAR(contractStart) as year from `contractnotice` + + global $conn; + $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"; $methods = Array("Direct", "Open", "Select"); $dates = Array();