lotta updates
[contractdashboard.git] / admin / importSON.php
blob:a/admin/importSON.php -> blob:b/admin/importSON.php
--- a/admin/importSON.php
+++ b/admin/importSON.php
@@ -3,7 +3,7 @@
 function fetchSON($SONID)
 {
     global $conn;
-    echo $SONID;
+    echo $SONID."\n";
 
 # Create a search parser object
     $search = new DOMDocument();
@@ -18,14 +18,19 @@
     foreach ($search->getElementsByTagName('a') as $link) {
         # Show the <a href>
         if (strpos($link->getAttribute('href'), 'UUID')) {
-            echo $link->getAttribute('href');
+            echo $link->getAttribute('href')."\n";
             @$doc->loadHTML(file_get_contents("https://www.tenders.gov.au".$link->getAttribute('href')));
+	   break;
         }
     }
 
-    //TODO update title from $x("//p[@class='lead']/text()")
-
-
+    //update title from $x("//p[@class='lead']/text()")
+$xpath = new DOMXpath($doc);
+$elements = $xpath->query("//p[@class='lead']/text()");
+echo ($elements[0]->wholeText)."\n";
+if ($title[0]->wholeText != "") {
+$conn->exec('insert into standingoffers ("SONID",title) values (\''.$SONID."','".$title[0]->wholeText."') ON CONFLICT DO UPDATE;");
+}
     $sql='insert into standingoffer_suppliers("SONID",name,abn,state,postcode) values(?,?,?,?,?)';
     $q=$conn->prepare($sql);
 
@@ -47,4 +52,16 @@
 }
 if ($_REQUEST['SONID']) {
     fetchSON($_REQUEST['SONID']);
+} else {
+
+$sons = Array(
+"SON1200402",
+"SON1209932",
+"SON98624");
+
+foreach ($sons as $son) {
+fetchSON($son);
+
 }
+}
+