Amendment partial record importer
[contractdashboard.git] / admin / partialdata / importamendments.php
blob:a/admin/partialdata/importamendments.php -> blob:b/admin/partialdata/importamendments.php
--- a/admin/partialdata/importamendments.php
+++ b/admin/partialdata/importamendments.php
@@ -1,6 +1,14 @@
 <?php
-include_once ("../../lib/common.inc.php");
-
+if (php_sapi_name() == "cli") {
+    include_once ("../../lib/common.inc.php");
+/*
+update contractnotice set "supplierABN" = a."supplierABN" 
+from contractnotice as cn inner join (select "supplierABN", 
+"supplierName" from contractnotice where "supplierABN" 
+IS NOT NULL and "supplierABN" != 0) as a on 
+cn."supplierName" = a."supplierName" where 
+cn."CNID"=contractnotice."CNID" and (contractnotice."supplierABN" 
+IS NULL or contractnotice."supplierABN" = 0) */
 // http://www.lastcraft.com/browser_documentation.php
 // http://code.google.com/p/phpquery/
 require('phpQuery-onefile.php');
@@ -10,6 +18,8 @@
 	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 	curl_setopt($ch, CURLOPT_HEADER, 0);
 	curl_setopt($ch, CURLOPT_TIMEOUT, 45);
+curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
 	$page = curl_exec($ch);
 	if (curl_errno($ch)) {
 		echo "<font color=red> Database temporarily unavailable: ";
@@ -111,7 +121,6 @@
 
 function importCN($cnid) {
     global $conn;
-    $CN = str_replace("-A", "00",$cnid);
     // check if already complete
     $query = 'Select "parentCN" from contractnotice
 	where "CNID" = :CNID';
@@ -191,7 +200,6 @@
 							    $fieldValue = trim(getTextFromNode($tr));
 							    }
 							$fieldValue = substr($fieldValue, 2); // take off the "CN" prefix
-							$fieldValue = str_replace("-A", "00", $fieldValue); // make amendments really big numbers
 	} elseif ($fieldName == "description") {
 	   
 							if (is_array($tra['td'])) $fieldValue = print_r($tra['td']['p'],true);
@@ -212,6 +220,10 @@
 	    $cnFields[$fieldName] = $fieldValue;
 	}
 }
+if (isset($cnFields[""])) {
+ $cnFields["description"] .= $cnFields[""];
+ unset($cnFields[""]);
+}
 $cnFields["importFile"] = $url;
 $contractNoticeInsertQ = 'INSERT INTO contractnotice ("' . implode('" , "', array_keys($cnFields)) . '") VALUES ( ';
 		for($key = 0; $key < sizeof($cnFields); $key++) {
@@ -297,8 +309,8 @@
 	if ($dhandle) {
 		// loop through all of the files
 		while (false !== ($fname = readdir($dhandle))) {
-			if (($fname != '.') && ($fname != '..')) {
-				echo "<a href=\"import.php?fname=$fname\">$fname</a>&nbsp;" . filesize($path . $fname) . "&nbsp;" . date("c", filemtime($path . $fname)) . "<br/>";
+			if (($fname != '.') && ($fname != '..') && (strpos($fname,".xls")>0)) {
+				echo "<a href=\"importdatagov.php?fname=$fname\">$fname</a>&nbsp;" . filesize($path . $fname) . "&nbsp;" . date("c", filemtime($path . $fname)) . "<br/>";
 				processFile($path . $fname, "contractnotice");
 			}
 		}
@@ -311,5 +323,6 @@
 	$success+= processFile($path . $fname, "contractnotice");
 
 }
-
+}
 ?>
+