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
--- a/about.php
+++ b/about.php
@@ -32,7 +32,7 @@
 <?php

 include_once("./lib/common.inc.php");

 $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")';

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

 	$query->execute();

@@ -45,7 +45,7 @@
 

 

 $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")';

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

 	$query->execute();


--- a/admin/updateReport.php
+++ b/admin/updateReport.php
@@ -1,14 +1,14 @@
 <?php

 include_once("../lib/common.inc.php");

 $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)";

 $result = mysql_query($query);

 $stats = mysql_fetch_array($result, MYSQL_BOTH);

 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 

-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)";

 $result = mysql_query($query);

 $stats = mysql_fetch_array($result, MYSQL_BOTH);


--- a/displayAgency.php
+++ b/displayAgency.php
@@ -66,7 +66,7 @@
 agenciesGraph();

   $query = 'SELECT SUM("value"), "agencyName"

 FROM contractnotice

-WHERE "childCN" = 0

+WHERE "childCN" is null 

 GROUP BY "agencyName" ';

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

 	$query->execute();


--- a/displayAmendments.php
+++ b/displayAmendments.php
@@ -1,7 +1,7 @@
 <?php

 include_once ("./lib/common.inc.php");

     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";

 $result = mysql_query($query);

   echo "<table>  <thead>


--- a/displayBubbletree.php
+++ b/displayBubbletree.php
@@ -51,7 +51,7 @@
 
 $catthreesresult = $conn->prepare('SELECT substr( "categoryUNSPSC"::text, 0, 4 ) as cat , SUM( "value" ) as value
 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 ;');
 $catthreesresult->execute();
 		foreach ($catthreesresult->fetchAll() as $threerow) { 

--- a/displayCalendar.php
+++ b/displayCalendar.php
@@ -8,7 +8,7 @@
 $monthParts = explode("-",$_REQUEST['month']);

   $query = 'SELECT "CNID", "description", "value", "agencyName", "category", "contractStart", "supplierName"

     FROM contractnotice

-    WHERE "childCN" = 0 

+    WHERE "childCN" is null

     AND extract(year from "contractStart") = :year

     AND extract(month from "contractStart")  = :month

     ORDER BY value DESC';

@@ -61,7 +61,7 @@
 

 

 $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->execute();

   if (!$query) {


--- a/displayCategory.php
+++ b/displayCategory.php
@@ -5,7 +5,7 @@
     echo "<center><h1>".$_REQUEST['category']."</h1></center>";

   $query = "SELECT CNID, description, value, agencyName, category, contractStart, supplierName

     FROM `contractnotice`

-    WHERE childCN = 0 

+    WHERE childCN is null 

     AND category = '" . $_REQUEST['category'] . "'

     ORDER BY value DESC";

   $result = mysql_query($query);

@@ -39,7 +39,7 @@
     include_header("Categories");

 $query = "SELECT sum(value), category

 FROM `contractnotice`

-WHERE childCN = 0 

+WHERE childCN is null

 GROUP BY category ORDER BY sum(value) DESC ";

 $result = mysql_query($query);

   echo "<table>  <thead>


--- a/displayHeatmap.php
+++ b/displayHeatmap.php
@@ -26,7 +26,7 @@
 $white = imagecolorallocate($handle, 0, 0, 0);

 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->execute();

    if (!$query) {


--- a/displayProcurementMethod.php
+++ b/displayProcurementMethod.php
@@ -12,7 +12,7 @@
 include_header("Procurement Methods");

 $query = "SELECT SUM(value) as value, procurementMethod

 FROM `contractnotice`

-WHERE childCN = 0

+WHERE childCN is null

 GROUP BY procurementMethod ";

 

 $result = mysql_query($query);


--- a/displaySupplier.php
+++ b/displaySupplier.php
@@ -66,7 +66,7 @@
   $query = 'SELECT SUM("value") as val, MAX("supplierName") as supplierName, "supplierABN",(
  case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as supplierID 
 FROM contractnotice
-WHERE "childCN" = 0
+WHERE "childCN" is null
 GROUP BY supplierID,"supplierABN"
 ORDER BY val DESC
 LIMIT 100';

--- a/exportData.csv.php
+++ b/exportData.csv.php
@@ -10,7 +10,7 @@
  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 
-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));
 // "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")

--- a/lib/common.inc.php
+++ b/lib/common.inc.php
@@ -13,7 +13,7 @@
 //    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

 function databaseError($errMsg)

 {

-	die($errMsg);

+	die(print_r($errMsg,true));

 }

 

 function ucsmart($str) {

@@ -57,7 +57,7 @@
 $year = filter_var($_REQUEST['year'], FILTER_SANITIZE_NUMBER_INT);

 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;

 

 function include_header($title) {


--- a/lib/graphs.inc.php
+++ b/lib/graphs.inc.php
@@ -133,7 +133,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" = 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';
 $query = $conn->prepare($query);
 $query->execute();
@@ -191,8 +191,8 @@
 function agencySuppliersGraph($agency) {
 	$agency = "AusAid";
 $topX = 15;
-$query = "SELECT SUM(value) as val, supplierName FROM `contractnotice` WHERE (YEAR(contractStart) >= $startYear) AND childCN = 0 AND agencyName = '$agency'
-GROUP BY lower(supplierName) ORDER BY val DESC limit $topX";
+$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';
 $result = mysql_query($query);
 $suppliers = Array();
 $values = Array();
@@ -202,8 +202,8 @@
 }
 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'
-GROUP BY lower(supplierName) ORDER BY val DESC LIMIT 18446744073709551610 OFFSET $topX) as a";
+$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';
 $result = mysql_query($query);
 while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
 if ($row['count'] > 0) {
@@ -254,11 +254,11 @@
   "Consultancies",
   "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);
 $row = mysql_fetch_array($result, MYSQL_BOTH);
 $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);
 $row = mysql_fetch_array($result, MYSQL_BOTH);
 $attributes[1] = $row[1];
@@ -266,12 +266,12 @@
 	
 }
 function ContractPublishedGraph() {
-	$query = "SELECT YEAR(publishDate), MONTH(publishDate),
+	$query = 'SELECT YEAR(publishDate), MONTH(publishDate),
 SUM(value) as val, count(1) as count FROM `contractnotice`
 WHERE (YEAR(publishDate) >= 2008)
-AND childCN = 0
+AND "childCN" is null
 GROUP BY MONTH(publishDate), YEAR(publishDate) 
-ORDER BY YEAR(publishDate), MONTH(publishDate)";
+ORDER BY YEAR(publishDate), MONTH(publishDate)';
 
 $result = mysql_query($query);
 $dates = Array();
@@ -288,12 +288,12 @@
 
 }
 function ContractStartingGraph() {
-	$query = "SELECT YEAR(contractStart), MONTH(contractStart),
+	$query = 'SELECT YEAR(contractStart), MONTH(contractStart),
 SUM(value) as val, count(1) as count FROM `contractnotice`
 WHERE (YEAR(contractStart) >= 2008)
-AND childCN = 0
+AND "childCN" is null
 GROUP BY MONTH(contractStart), YEAR(contractStart) 
-ORDER BY YEAR(contractStart), MONTH(contractStart)";
+ORDER BY YEAR(contractStart), MONTH(contractStart)';
 
 $result = mysql_query($query);
 $dates = Array();
@@ -309,8 +309,8 @@
 mysql_free_result($result);
 }
 function MethodCountGraph() {
-	$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";
+	$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';
 $result = mysql_query($query);
 $methods = Array("Direct","Open","Select");
 $dates = Array();
@@ -381,7 +381,7 @@
 $query = 'SELECT SUM("value") as value, MAX("supplierName") as supplierName, (
  case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as supplierID 
 FROM contractnotice
-WHERE "childCN" = 0
+WHERE "childCN" is null
 GROUP BY supplierID
 ORDER BY value DESC
 LIMIT '.$topX;
@@ -398,7 +398,7 @@
 }
 
 $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 ';
 $query = $conn->prepare($query);
   $query->execute();
@@ -414,7 +414,7 @@
 
 $query = 'SELECT sum(a.value) as val, substring(
 supplierpostcode from 0 for 2) as postcode from (SELECT sum(value) as value, max("supplierPostcode") as supplierpostcode, max("supplierCountry") as suppliercountry
-FROM contractnotice WHERE "childCN" = 0 
+FROM contractnotice WHERE "childCN" is null 
 GROUP BY "supplierABN" ORDER BY sum(value) LIMIT 1844674 OFFSET 10) as a
 WHERE (suppliercountry ILIKE \'Australia\')
 group by substring(