More MySQL purging
More MySQL purging

file:a/about.php -> file:b/about.php
--- a/about.php
+++ b/about.php
@@ -1,25 +1,24 @@
 <?php

-

-

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

 include_header("Map");

 ?>

 

 <div class="msg_list">

-<p class="msg_head">Header-1 </p>

-<div class="msg_body">

-orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit

+    <p class="msg_head">Header-1 </p>

+    <div class="msg_body">

+        orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit

+    </div>

+    <p class="msg_head">Header-2</p>

+    <div class="msg_body">

+        orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit

+    </div>

+    <p class="msg_head">Header-3</p>

+    <div class="msg_body">

+        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>

-<div class="msg_body">

-orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit

-</div>

-<p class="msg_head">Header-3</p>

-<div class="msg_body">

-orem ipsum dolor sit amet, consectetuer adipiscing elit orem ipsum dolor sit amet, consectetuer adipiscing elit

-</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

 ?>

 

@@ -35,29 +34,25 @@
 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();

-	if (!$query) {

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

-	}

+$query->execute();

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

 echo "<div>";

 $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 

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

-	if (!$query) {

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

-	}

+$query->execute();

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

 echo "<div>";

-$stats =  $query->fetch(PDO::FETCH_ASSOC);

-echo $stats["count"] . " updated records in period " . $stats["start"] . "  to " . $stats["end"] ."<br>";

+$stats = $query->fetch(PDO::FETCH_ASSOC);

+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 */

 

 


--- a/admin/linkAmendments.php
+++ b/admin/linkAmendments.php
@@ -5,9 +5,7 @@
 c."parentCN" > 0 AND p."childCN" IS NULL ';
 $query = $conn->prepare($query);
 	$query->execute();
-	if (!$query) {
 		databaseError($conn->errorInfo());
-	}
 foreach ($query->fetchAll() as $row) {
   $conn->exec('UPDATE contractnotice SET "childCN" = \'' .
 			 $row['CNID'] . '\' where "CNID" = \'' .
@@ -36,9 +34,7 @@
 GROUP BY "parentCN" having count(*) > 1';
 $query = $conn->prepare($query);
 	$query->execute();
-	if (!$query) {
 		databaseError($conn->errorInfo());
-	}
 foreach ($query->fetchAll() as $row) {
 	$cnids = explode(",",str_replace(Array("{","}"),"",$row['array_agg']));
 	$last_cnid = array_pop($cnids);

--- a/admin/updateReport.php
+++ b/admin/updateReport.php
@@ -1,30 +1,24 @@
 <?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 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>";

+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" 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 = $conn->query($query);

+    $stats = $result->fetch();

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

-echo $stats["count"] . " updated 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" 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 = $conn->query($query);

+    $stats = $result->fetch();

+echo $stats['count'] . ' updated records in period ' . $stats['start'] . '  to ' . $stats['end'] .'<br>';

 

-$query = "SELECT count(*) as count FROM `agency` WHERE `abn` = '0'";

-$result = mysql_query($query);

-$stats = mysql_fetch_array($result, MYSQL_BOTH);

-echo $stats["count"] . " agencies with no ABN<br>";

+$query = 'SELECT count(*) as count FROM agency WHERE abn = \'0\'';

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

+    $stats = $result->fetch();

+echo $stats['count'] . ' agencies with no ABN<br>';

 

-/*$query = "SELECT count(*) as count FROM `supplierdetails` WHERE `supplierABN` = '0' and supplierCountry LIKE 'Australia'";

-$result = mysql_query($query);

-$stats = mysql_fetch_array($result, MYSQL_BOTH);

-echo $stats["count"] . " Australian suppliers with no ABN<br>";*/

-

-

-echo "Last updated: ". $stats["importdate"]."<br>";

+echo 'Last updated: '. $stats['importdate'].'<br>';

 ?>

 

--- a/displayAgency.php
+++ b/displayAgency.php
@@ -1,42 +1,41 @@
 <?php

+

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

 if ($_REQUEST['agency']) {

-    

-include_header("Agency");

-  $agency = htmlentities(strip_tags($_REQUEST['agency']));

-  MethodCountGraph($agency);

-  CnCGraph($agency);

-  MethodValueGraph($agency);

-  /*biggest contracts

-  spending by year

-  spending by industry/category

-  spending by supplier

-  

-  spread procurement methods (stacked bar graph)

-  + percent consultancies + percent confidential (bar graph)

 

- Average value by procurement type

-  

-  --- info

-  website, procurement plan, annual reports

-  Breakdown of divisions/branches

-  Breakdown percentage,number,value by procurement type

-  Histograph, overlaying number value reported per week over X years

-  Compliance statistics: amendments, delay in reporting average and number completely late*/

-  

+    include_header("Agency");

+    $agency = htmlentities(strip_tags($_REQUEST['agency']));

+    MethodCountGraph($agency);

+    CnCGraph($agency);

+    MethodValueGraph($agency);

+    /* biggest contracts

+      spending by year

+      spending by industry/category

+      spending by supplier

+

+      spread procurement methods (stacked bar graph)

+      + percent consultancies + percent confidential (bar graph)

+

+      Average value by procurement type

+

+      --- info

+      website, procurement plan, annual reports

+      Breakdown of divisions/branches

+      Breakdown percentage,number,value by procurement type

+      Histograph, overlaying number value reported per week over X years

+      Compliance statistics: amendments, delay in reporting average and number completely late */

+

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

     "contractStart", "supplierName"

     FROM contractnotice

     WHERE "agencyName" = :agency

     ORDER BY "value" DESC';

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

-$query->bindParam(":agency", $agency);

-	$query->execute();

-	if (!$query) {

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

-	}

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

+    $query->bindParam(":agency", $agency);

+    $query->execute();

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

 

-  echo "<table>  <thead>

+    echo "<table>  <thead>

     <tr>

       <th>Contract Notice Number</th>

       <th>Contract Description</th>

@@ -46,46 +45,44 @@
       <th>Supplier</th>

     </tr>

   </thead>";

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

-    setlocale(LC_MONETARY, 'en_US');

-    $value = number_format(doubleval($row['value']) , 2);

-    echo ("<tr>

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

+        setlocale(LC_MONETARY, 'en_US');

+        $value = number_format(doubleval($row['value']), 2);

+        echo ("<tr>

     <td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td>

     <td><b>{$row['description']}</b></a></td>

     <td>\$$value</td><td>{$row['agencyName']}</td>

     <td>{$row['contractStart']}</td>

     <td>{$row['supplierName']}</td>

     </tr>");

-  }

-  echo "</table>";

+    }

+    echo "</table>";

 } else {

     /*

-     split by portfolio

-    */

-include_header("Agencies");

-agenciesGraph();

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

+      split by portfolio

+     */

+    include_header("Agencies");

+    agenciesGraph();

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

 FROM contractnotice

 WHERE "childCN" is null 

 GROUP BY "agencyName" ';

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

-	$query->execute();

-	if (!$query) {

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

-	}

-  echo "<table>  <thead>

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

+    $query->execute();

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

+    echo "<table>  <thead>

     <tr>

       <th>Agency</th>

       <th>Total Contracts Value</th>

     </tr>

   </thead>";

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

-    setlocale(LC_MONETARY, 'en_US');

-    $value = number_format(doubleval($row[0]) , 2);

-    $agency = stripslashes($row[1]);

-    echo ("<tr><td><b><a href=\"displayAgency.php?agency={$agency}\">{$agency}</a></b></td><td>\$$value</td></tr>\n");

-  }

-  echo "</table>";

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

+        setlocale(LC_MONETARY, 'en_US');

+        $value = number_format(doubleval($row[0]), 2);

+        $agency = stripslashes($row[1]);

+        echo ("<tr><td><b><a href=\"displayAgency.php?agency={$agency}\">{$agency}</a></b></td><td>\$$value</td></tr>\n");

+    }

+    echo "</table>";

 }

 include_footer();

 ?>


--- a/displayAmendments.php
+++ b/displayAmendments.php
@@ -1,10 +1,14 @@
 <?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 is not null) a".

-" where ".$agencyQ.$yearQ."CNID = ccn AND (value - pvalue) <> 0 order by diff DESC";

-$result = mysql_query($query);

-  echo "<table>  <thead>

+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" is not null) a' .

+        ' where ' . $agencyQ . $yearQ . ' "CNID" = ccn AND (value - pvalue) <> 0 order by diff DESC';

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

+$query->execute();

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

+echo "<table>  <thead>

     <tr>

       <th>Contract</th>

       <th>Original Value</th>

@@ -12,21 +16,17 @@
     <th>Difference</th>

     </tr>

   </thead>";

-if ($result) {

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

-  setlocale(LC_MONETARY, 'en_US');

-  $value = number_format(doubleval($row['value']) , 2);

-  $pvalue = number_format(doubleval($row['pvalue']) , 2);

-  $diff = number_format(doubleval($row['diff']) , 2);

-  echo ("<tr>");

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

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

+    setlocale(LC_MONETARY, 'en_US');

+    $value = number_format(doubleval($row['value']), 2);

+    $pvalue = number_format(doubleval($row['pvalue']), 2);

+    $diff = number_format(doubleval($row['diff']), 2);

+    echo ("<tr>");

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

 }

-} else {

-echo mysql_error();

-}

+

 echo "</table>";

-mysql_free_result($result);

 include_footer();

 ?>

 

--- a/displayCalendar.php
+++ b/displayCalendar.php
@@ -1,30 +1,29 @@
 <?php

+

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

 

 include_header("Months and Years");

 

 if ($_REQUEST['month']) {

-    echo "<center><h1>".$_REQUEST['month']."</h1></center>";

-$monthParts = explode("-",$_REQUEST['month']);

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

+    echo "<center><h1>" . $_REQUEST['month'] . "</h1></center>";

+    $monthParts = explode("-", $_REQUEST['month']);

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

     FROM contractnotice

     WHERE "childCN" is null

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

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

     ORDER BY value DESC';

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

-$query->bindParam(":month",  $monthParts[0]);

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

+    $query->bindParam(":month", $monthParts[0]);

 

-$query->bindParam(":year",  $monthParts[1]);

-  $query->execute();

-  if (!$query) {

+    $query->bindParam(":year", $monthParts[1]);

+    $query->execute();

     databaseError($conn->errorInfo());

-  }

 

-MethodCountGraph($supplier);

-CnCGraph($supplier);

+    MethodCountGraph($supplier);

+    CnCGraph($supplier);

 

-  echo "<table>  <thead>

+    echo "<table>  <thead>

     <tr>

       <th>Contract Notice Number</th>

       <th>Contract Description</th>

@@ -34,55 +33,51 @@
       <th>Supplier</th>

     </tr>

   </thead>";

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

-    setlocale(LC_MONETARY, 'en_US');

-    $value = number_format(doubleval($row['value']) , 2);

-    echo ("<tr>

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

+        setlocale(LC_MONETARY, 'en_US');

+        $value = number_format(doubleval($row['value']), 2);

+        echo ("<tr>

     <td><a href=\"displayContract.php?CNID={$row['CNID']}\">{$row['CNID']}</a></td>

     <td><b>{$row['description']}</b></a></td>

     <td>\$$value</td><td>{$row['agencyName']}</td>

     <td>{$row['contractStart']}</td>

     <td>{$row['supplierName']}</td>

     </tr>");

-  }

-  echo "</table>";

-  mysql_free_result($result);

+    }

+    echo "</table>";

 } else {

-/*

-     split by year

-todo:

-Year/Month drilldown - largest contracts, agencies, suppliers

-count per month

-big picture graphs?*/

+    /*

+      split by year

+      todo:

+      Year/Month drilldown - largest contracts, agencies, suppliers

+      count per month

+      big picture graphs? */

 

 

-echo '<img src="graphs/displayContractStartingGraph.php">';

-echo '<img src="graphs/displayContractPublishedGraph.php">';

+    echo '<img src="graphs/displayContractStartingGraph.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" 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) {

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

+    $query->execute();

     databaseError($conn->errorInfo());

-  }

 

-  echo "<table>  <thead>

+    echo "<table>  <thead>

     <tr>

       <th>Month/Year</th>

       <th>Total Contracts Value</th>

       <th>Number of Contracts</th>

     </tr>

   </thead>";

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

-setlocale(LC_MONETARY, 'en_US');

-$value = number_format(doubleval($row["val"]),2);

-$month_name = date( 'F', mktime(0, 0, 0, $row[1]) );

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

-mysql_free_result($result);

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

+        setlocale(LC_MONETARY, 'en_US');

+        $value = number_format(doubleval($row["val"]), 2);

+        $month_name = date('F', mktime(0, 0, 0, $row[1]));

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

 }

 include_footer();

 ?>


--- a/displayCategory.php
+++ b/displayCategory.php
@@ -3,12 +3,16 @@
 if ($_REQUEST['category']) {

     include_header("Category");

     echo "<center><h1>".$_REQUEST['category']."</h1></center>";

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

-    FROM `contractnotice`

-    WHERE childCN is null 

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

-    ORDER BY value DESC";

-  $result = mysql_query($query);

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

+    FROM contractnotice

+    WHERE "childCN" is null 

+    AND category = :category

+    ORDER BY value DESC';

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

+$query->bindParam(":category", $_REQUEST['category']);

+	$query->execute();

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

+	

     echo "<table>  <thead>

     <tr>

       <th>Contract Notice Number</th>

@@ -19,7 +23,7 @@
       <th>Supplier</th>

     </tr>

   </thead>";

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

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

     setlocale(LC_MONETARY, 'en_US');

     $value = number_format(doubleval($row['value']) , 2);

     echo ("<tr>

@@ -31,30 +35,30 @@
     </tr>");

   }

   echo "</table>";

-  mysql_free_result($result);

 } else {

     /*

      split by main categories

     */

     include_header("Categories");

-$query = "SELECT sum(value), category

-FROM `contractnotice`

-WHERE childCN is null

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

-$result = mysql_query($query);

+$query = 'SELECT sum(value), category

+FROM contractnotice

+WHERE "childCN" is null

+GROUP BY category ORDER BY sum(value) DESC ';

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

+	$query->execute();

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

   echo "<table>  <thead>

     <tr>

       <th>Category</th>

       <th>Total Contracts Value</th>

     </tr>

   </thead>";

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

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

   setlocale(LC_MONETARY, 'en_US');

   $value = number_format(doubleval($row[0]) , 2);

   echo ("<tr><td><A href=\"displayCategory.php?category={$row[1]}\"><b>{$row[1]}</b></a></td><td>\$$value</td></tr>");

 }

 echo "</table>";

-mysql_free_result($result);

 }

 include_footer();

 ?>

--- a/displayConfidentialities.php
+++ b/displayConfidentialities.php
@@ -14,16 +14,17 @@
 FROM `contractnotice`
 GROUP BY procurementMethod ";
 
-$result = mysql_query($query);
+    $query = $conn->prepare($query);
+    $query->execute();
+    databaseError($conn->errorInfo());
 
 echo "<table>";
-while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
+    foreach ($query->fetchAll() as $row) {
 setlocale(LC_MONETARY, 'en_US');
 $value = number_format(doubleval($row[0]),2);
     echo ("<tr><td><b>{$row[1]}</b></td><td>\$$value</td></tr>");
 }
 echo "</table>";
-mysql_free_result($result);
 include_footer();
 ?>
 

--- a/displayConsultancies.php
+++ b/displayConsultancies.php
@@ -14,16 +14,18 @@
 FROM `contractnotice`
 GROUP BY procurementMethod ";
 
-$result = mysql_query($query);
+
+    $query = $conn->prepare($query);
+    $query->execute();
+    databaseError($conn->errorInfo());
 
 echo "<table>";
-while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
+    foreach ($query->fetchAll() as $row) {
 setlocale(LC_MONETARY, 'en_US');
 $value = number_format(doubleval($row[0]),2);
     echo ("<tr><td><b>{$row[1]}</b></td><td>\$$value</td></tr>");
 }
 echo "</table>";
-mysql_free_result($result);
 include_footer();
 ?>
 

--- a/displayContract.php
+++ b/displayContract.php
@@ -8,44 +8,40 @@
 

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

 $query->bindParam(":CNID", $_REQUEST['CNID']);

-  $query->execute();

-  if (!$query) {

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

-  }

-  foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row) {

-setlocale(LC_MONETARY, 'en_US');

-foreach (array_filter($row) as $key => $value) {

-	echo "<b>$key</b>&nbsp;";

-switch ($key) {

-case "supplierName":

-case "supplierABN":

-	echo '<a href="displaySupplier.php?supplier='.$row['supplierABN'].'-'.urlencode($row['supplierName']).'">'.$value."</a>";

-	break;

-case "agencyName":

-	echo '<a href="displayAgency.php?agency='.urlencode($value).'">'.$value."</a>";

-	break;

-case "value":

-	echo "$".number_format(doubleval($value),2);

-	break;

-default:

-	echo str_replace("  ","<br>",$value);

+$query->execute();

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

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

+    setlocale(LC_MONETARY, 'en_US');

+    foreach (array_filter($row) as $key => $value) {

+        echo "<b>$key</b>&nbsp;";

+        switch ($key) {

+            case "supplierName":

+            case "supplierABN":

+                echo '<a href="displaySupplier.php?supplier=' . $row['supplierABN'] . '-' . urlencode($row['supplierName']) . '">' . $value . "</a>";

+                break;

+            case "agencyName":

+                echo '<a href="displayAgency.php?agency=' . urlencode($value) . '">' . $value . "</a>";

+                break;

+            case "value":

+                echo "$" . number_format(doubleval($value), 2);

+                break;

+            default:

+                echo str_replace("  ", "<br>", $value);

+        }

+        echo "<br>";

+    }

 }

-echo "<br>";

-}

-}

-echo '<br><a href="https://www.tenders.gov.au/?event=public.advancedsearch.keyword&keyword=CN'.$_REQUEST['CNID'].'"> View original record @ tenders.gov.au</a><br>';

+echo '<br><a href="https://www.tenders.gov.au/?event=public.advancedsearch.keyword&keyword=CN' . $_REQUEST['CNID'] . '"> View original record @ tenders.gov.au</a><br>';

 

 

 $query = 'SELECT * FROM `heuristic_results` where "CNID" = :CNID';

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

-$agencyName = $input.'%';

+$agencyName = $input . '%';

 $query->bindParam(":CNID", $_REQUEST['CNID']);

-  $query->execute();

-  if (!$query) {

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

-  }

-  foreach ($query->fetchAll() as $r) {

-	echo "<b>{$r['heuristic_name']}</b>: {$r['heuristic_value']} (raw value: {$r['raw_value']}, mean: {$r['mean']}, stddev: {$r['stddev']})<br>";

+$query->execute();

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

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

+    echo "<b>{$r['heuristic_name']}</b>: {$r['heuristic_value']} (raw value: {$r['raw_value']}, mean: {$r['mean']}, stddev: {$r['stddev']})<br>";

 }

 

 include_footer();


--- a/displayHeatmap.php
+++ b/displayHeatmap.php
@@ -1,5 +1,4 @@
 <?php

-

 

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

 

@@ -28,72 +27,70 @@
 

 $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) {

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

-   }

+$query->execute();

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

 

 

 $left = "FFFF50";

-$right= "EF0050";

-$leftR = hexdec(substr($left,0,2));

-$leftG = hexdec(substr($left,2,2));

-$leftB = hexdec(substr($left,4,2));

-$rightR = hexdec(substr($right,0,2));

-$rightG = hexdec(substr($right,2,2));

-$rightB = hexdec(substr($right,4,2));

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

+$right = "EF0050";

+$leftR = hexdec(substr($left, 0, 2));

+$leftG = hexdec(substr($left, 2, 2));

+$leftB = hexdec(substr($left, 4, 2));

+$rightR = hexdec(substr($right, 0, 2));

+$rightG = hexdec(substr($right, 2, 2));

+$rightB = hexdec(substr($right, 4, 2));

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

 }

 

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

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

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

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

-   @$pagevalues[$xpage][$ypage] += $row['value'];

-   //echo $ypage." ".$xpage."<br>";

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

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

+    if ($row['lat'] < -40.25)

+        $row['lat']-= 0.75;

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

+    @$pagevalues[$xpage][$ypage] += $row['value'];

+    //echo $ypage." ".$xpage."<br>";

 }

 

 $max = 0;

 $min = 0;

-for ($i = 0;$i < $xdivs; $i++ ) {

-   for ($j