Add openid security
[contractdashboard.git] / admin / import.php
blob:a/admin/import.php -> blob:b/admin/import.php
--- a/admin/import.php
+++ b/admin/import.php
@@ -2,7 +2,7 @@
 if (php_sapi_name() != "cli") {
     
 include_once ("../lib/common.inc.php");
-auth();
+//auth();
 $contractNoticeFields = array(
     "importFile",
     "agencyName",
@@ -44,18 +44,20 @@
 }
 $contractNoticeInsertQ.= ");";
 $contractNoticeInsertQ = $conn->prepare($contractNoticeInsertQ);
-
 function processFile($fpath) {
     global $conn, $contractNoticeFields, $contractNoticeInsertQ;
+    $success = 0;
     $row = 1;
     $handle = fopen($fpath, "r");
     //"t" mode string translates windows line breaks to unix
+//On the 15 April 2014 AusTender Contract Notice functionality changed to improve transparency. Two new fields have been introduced to capture the ‘Amendment Value’ and the ‘Amendment Start Date’. Where applicable, these fields will display on amendment records published after this date.
     $datamapping0712 = array(
         "Agency" => "agencyName",
         "Parent CN ID" => "parentCN",
         "CN ID" => "CNID",
         "Publish Date" => "publishDate",
         "Amendment Date" => "amendDate",
+        "Amendment Publish Date" => "amendDate",
         "Status" => "",
         "StartDate" => "contractStart",
         "EndDate" => "contractEnd",
@@ -86,10 +88,9 @@
         "Agency Postcode" => "contactPostcode",
         "" => ""
     );
-    
-    $headers;
-
-    while (($data = fgetcsv($handle, 1000, "\t")) !== false) {
+
+
+    while (($data = fgetcsv($handle, 1200, "\t")) !== false) {
         $num = count($data);
         if ($row == 3) {
             $headers = $data;
@@ -108,13 +109,13 @@
                 if (in_array(($datamapping0712[$headers[$c]]), $contractNoticeFields)) {
                     if (($datamapping0712[$headers[$c]]) == "parentCN" || ($datamapping0712[$headers[$c]]) == "CNID") {
                         $data[$c] = substr($data[$c], 2); // take off the "CN" prefix
-                        if ($data[$c] > 0 && $data[$c] != '0') {
+                        if ($data[$c] > 0 && $data[$c] != '0' && $data[$c] != '') {
                             $contractNoticeInsert[] = $data[$c];
                         } else {
                             $contractNoticeInsert[] = null;
                         }
-                    } elseif (($datamapping0712[$headers[$c]]) == "supplierABN") {
-                        if ($data[$c] > 0 && $data[$c] != '0') {
+                    } elseif (($datamapping0712[$headers[$c]]) == "supplierABN" || ($datamapping0712[$headers[$c]]) == "SONID") {
+                        if ($data[$c] > 0 && $data[$c] != '0' && $data[$c] != '') {
                             $contractNoticeInsert[] = $data[$c];
                         } else {
                             $contractNoticeInsert[] = null;
@@ -136,8 +137,9 @@
             $errors = $conn->errorInfo();
             if ($errors[1] == 7 && strpos($errors[2], "duplicate key")) {
                 
-            } elseif ($errors[1] == 0) {
-                $success++;
+            } elseif ($errors[1] <= 0) {
+//print_r($errors);
+                $success = 1;
             } else {
                 foreach ($contractNoticeFields as $key => $cnf) {
                     echo var_dump($contractNoticeInsert[$key]) . $cnf . "<br>";
@@ -186,11 +188,16 @@
 
     flush();
     // run post import data processing
-// cn
+    // 
+    if ($success > 0) {
+$conn->exec("update datasets set \"lastUpdated\" = NOW() where title = 'Contract Notices'");
     echo "link amend<br>";
     include ("linkAmendments.php");
     echo "update UNSPSC<br>";
     include ("updateUNSPSC.php");
+    }
+// cn
+
 // agency
 //include ("setAgencyStatus.php");
 //include ("setAgencyURLABN.php");