Beginnings of Heuristics work
[contractdashboard.git] / sitemap.xml.php
blob:a/sitemap.xml.php -> blob:b/sitemap.xml.php
<?php <?php
include ('include/common.inc.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",
  "SON",
  "page"
  );
header("Content-Type: text/xml"); header("Content-Type: text/xml");
echo "<?xml version='1.0' encoding='UTF-8'?>"; 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');
echo " <url><loc>".curPageURL()."index.php</loc><priority>1.0</priority></url>\n"; foreach ($result->fetchAll() as $row) {
foreach (scandir("./") as $file) { if ($row['title'] == "Contract Notices") {
if (strpos($file,".php") !== false && $file != "index.php" && $file != "sitemap.xml.php") echo " <url><loc>".curPageURL()."$file</loc><priority>0.3</priority></url>\n"; $last_updated['agency'] = $row['lastUpdated'];
  $last_updated['supplier'] = $row['lastUpdated'];
  $last_updated['category'] = $row['lastUpdated'];
  $last_updated['SON'] = $row['lastUpdated'];
  }
} }
foreach (getStops() as $stop) { if (isset($_REQUEST['section']) == false) {
echo " <url><loc>".curPageURL()."stop.php?stopid=".htmlspecialchars ($stop["stop_id"])."</loc>"; echo '<sitemapindex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
echo "<lastmod>" . $last_updated . "</lastmod>"; xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd"
echo "<changefreq>monthly</changefreq>"; xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
echo "<priority>0.9</priority>"; foreach ($sections as $section) {
echo "</url>\n"; $pages = 0;
} $i = 0;
foreach (getRoutes() as $route) { if ($section == 'supplier') $pages = 1;
echo " <url><loc>".curPageURL()."trip.php?routeid=".htmlspecialchars ($route["route_id"])."</loc>"; do {
echo "<lastmod>" . $last_updated . "</lastmod>"; echo "<sitemap>
echo "<changefreq>monthly</changefreq>"; <loc>" . local_url() . "sitemap.xml.php?section=$section&amp;page=$i</loc>
echo "<priority>0.9</priority>"; <lastmod>" . $last_updated[$section] . '</lastmod></sitemap>';
echo "</url>\n"; $i++;
} } while ($i <= $pages);
echo '</urlset>'; }
  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") {
  $start = $_REQUEST['page'] * 40000;
  $result = $conn->prepare('SELECT DISTINCT ON ("supplierID") (
  CASE WHEN "supplierABN" != 0 THEN "supplierABN"::TEXT ELSE lower("supplierName") END) AS "supplierID", "supplierABN", "supplierName"
  FROM contractnotice
  order by "supplierID"
  LIMIT 40000 OFFSET :start
  ');
  $result->execute(array(':start' => $start));
  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";
   
  }
  }
  if ($_REQUEST['section'] == "SON") {
  $result = $conn->query('SELECT DISTINCT "SONID" FROM contractnotice;');
  foreach ($result->fetchAll() as $row) {
   
  echo " <url><loc>" . local_url() . "displaySON.php?SONID=" . urlencode($row['SONID']) . "</loc>
  <lastmod>" . $last_updated['SON'] . "</lastmod></url>\n";
   
  }
  }
  echo '</urlset>';
  }
?> ?>