--- a/admin/partialdata/import.php +++ b/admin/partialdata/import.php @@ -1,12 +1,18 @@ "; + flush(); $row = 1; + $success = 0; + $dupes = 0; $handle = fopen($fpath, "r"); //"t" mode string translates windows line breaks to unix $datamapping0507 = array( + "Agency" => "agencyName", "CN ID" => "CNID", "Publish Date" => "publishDate", @@ -16,7 +22,8 @@ "Title" => "description", "Category" => "category", "ATM ID" => "atmID", - "LastUpdated" => "", + "Supplier Name" => "supplierName", + "LastUpdated" => "amendDate", "" => "" ); $headers; @@ -32,7 +39,7 @@ "value", "atmID", "supplierName", - "LastUpdated" + "amendDate" ); if ($tablename == "contractnotice") { $contractNoticeInsertQ = 'INSERT INTO contractnotice ("' . implode('" , "', $contractNoticeFields) . '") VALUES ( '; @@ -50,7 +57,7 @@ } elseif ($row > 3) { if ($num > count($datamapping0507)) { - die("Error in data import; data mapping fields out of bounds or changed
" . $fname . print_r($data)); + die("Error in data import; data mapping fields out of bounds or changed
" . $fname . "data:" .$num. print_r($data ,true). "mapping:" . count($datamapping0507). print_r($datamapping0507 ,true)); } $contractNoticeInsert = Array(); $contractNoticeInsert[] = $fpath; @@ -62,7 +69,6 @@ if (in_array(($datamapping0507[$headers[$c]]) , $contractNoticeFields)) { if (($datamapping0507[$headers[$c]]) == "parentCN" || ($datamapping0507[$headers[$c]]) == "CNID") { $data[$c] = substr($data[$c], 2); // take off the "CN" prefix - $data[$c] = str_replace("-A", "00", $data[$c]); // make amendments really big numbers if (!is_numeric($data[$c]) && $data[$c] != "") die($data[$c] . " is not numeric"); if ($data[$c] > 0) { $contractNoticeInsert[] = $data[$c]; @@ -98,6 +104,7 @@ $contractNoticeInsertQ->execute($contractNoticeInsert); $errors = $conn->errorInfo(); if ($errors[1] == 7 && strpos($errors[2], "duplicate key")) { + $dupes++; } elseif ($errors[1] == 0) { $success++; @@ -116,6 +123,9 @@ $row++; } fclose($handle); + echo " $dupes duplicate records
"; + echo " $success records successfully created
"; + flush(); return $success; } $path = './'; @@ -127,8 +137,9 @@ if ($dhandle) { // loop through all of the files while (false !== ($fname = readdir($dhandle))) { - if (($fname != '.') && ($fname != '..')) { - echo "$fname " . filesize($path . $fname) . " " . date("c", filemtime($path . $fname)) . "
"; + if (($fname != '.') && ($fname != '..') && (!isset($_REQUEST["filter"]) || strpos($fname,$_REQUEST["filter"]) != false)) { + echo "$fname " . filesize($path . $fname) . " " . date("c", filemtime($path . $fname)) . "
"; + processFile($path . $fname, "contractnotice"); } } } @@ -136,11 +147,10 @@ else { $success = 0; $fname = $_REQUEST["fname"]; - echo " ============== $fname ==============
"; - flush(); + $success+= processFile($path . $fname, "contractnotice"); - echo "
$success records successfully created"; - flush(); + +} } ?>