fix date input again
fix date input again

--- a/displayCalendar.php
+++ b/displayCalendar.php
@@ -5,9 +5,9 @@
 

 

 if ($_REQUEST['month']) {

-    $monthParts = explode("-", str_replace(Array("'","/","\\",'-'), "",$_REQUEST['month']));

-    $year = $monthParts[1];

-    $month = $monthParts[0];

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

+    $year = str_replace('-', '',$monthParts[1]);

+    $month = str_replace('-', '',$monthParts[0]);

     $monthName = date("F Y",  mktime(0,0,0,$month,1,$year));

             

     include_header($monthName);

@@ -81,7 +81,7 @@
         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 ('<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>";

 }


--- a/sitemap.xml.php
+++ b/sitemap.xml.php
@@ -1,14 +1,68 @@
 <?php
 include ('lib/common.inc.php');
-$last_updated = date('Y-m-d',@filemtime('cbrfeed.zip'));
+$last_updated['page'] = date('Y-m-d',@filemtime('index.php'));
+$sections = Array(
+    "agency",
+    "category",
+    "supplier",
+    "page"
+);
 header("Content-Type: text/xml");
 echo "<?xml version='1.0' encoding='UTF-8'?>";
-  echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
+$result = $conn->query('SELECT title, to_char("lastUpdated",\'YYYY-MM-DD\') as "lastUpdated" from datasets');
+foreach ($result->fetchAll() as $row) {
+    if ($row['title'] == "Contract Notices") {
+        $last_updated['agency'] = $row['lastUpdated'];
+        $last_updated['supplier'] = $row['lastUpdated'];
+        $last_updated['category'] = $row['lastUpdated'];
+    }
+}
+if (isset($_REQUEST['section']) == false) {
+    echo '<sitemapindex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd"
+         xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
+    foreach ($sections as $section) {
+        echo "<sitemap>
+      <loc>" . local_url() . "sitemap.xml.php?section=$section</loc>
+      <lastmod>" . $last_updated[$section] . '</lastmod></sitemap>';
+    }
+    echo '</sitemapindex>';
+} else {
+   echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n";
+    if ($_REQUEST['section'] == "page") {
       echo " <url><loc>".local_url()."index.php</loc><priority>1.0</priority></url>\n";
 foreach (scandir("./") as $file) {
       if (strpos($file,".php") !== false && $file != "index.php" && $file != "sitemap.xml.php") echo " <url><loc>".local_url()."$file</loc><priority>0.3</priority></url>\n";
 }
+    }
+        if ($_REQUEST['section'] == "agency") {
+       $result = $conn->query('SELECT DISTINCT "agencyName" from contractnotice');
+       foreach ($result->fetchAll() as $row) {
+            echo " <url><loc>" . local_url() . "displayAgency.php?agency=" . urlencode($row['agencyName']) . "</loc>
+      <lastmod>" . $last_updated['agency'] . "</lastmod></url>\n";
+        }
+    }
+    if ($_REQUEST['section'] == "supplier") {
+       $result = $conn->query('SELECT DISTINCT on ("supplierID") (
+ case when "supplierABN" != 0 THEN "supplierABN"::text ELSE "supplierName" END) as "supplierID", "supplierABN", "supplierName"  from contractnotice');
+       
+       foreach ($result->fetchAll() as $row) {
+           
+           $supplier = urlencode(stripslashes($row['supplierABN'] . '-' . $row['supplierName']));
+            echo " <url><loc>" . local_url() . "displaySupplier.php?supplier=$supplier</loc>
+      <lastmod>" . $last_updated['supplier'] . "</lastmod></url>\n";
+        }
+    }
+    if ($_REQUEST['section'] == "category") {
+       $result = $conn->query('SELECT distinct category FROM contractnotice;');
+       foreach ($result->fetchAll() as $row) {
+           
+            echo " <url><loc>" . local_url() . "displayCategory.php?category=".urlencode($row['category'])."</loc>
+      <lastmod>" . $last_updated['category'] . "</lastmod></url>\n";
+           
+        }
+    }
   echo '</urlset>';
-
+}
 ?>