1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | <?php include_once('../include/common.inc.php'); include_header(); $db = $server->get_db('disclosr-agencies'); $docs = Array(); try { $rows = $db->get_view("app", "byABN")->rows; //print_r($rows); foreach ($rows as $row) { $docs["a" . $row->key] = $row->value; } } catch (SetteeRestClientException $e) { setteErrorHandler($e); } //print_r($docs); $row = 1; if (($handle = fopen("cacfma.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $row++; echo $data[0] . " " . str_replace("?", "", $data[1]) . "<br />\n"; $name = $data[0]; $abn = trim(str_replace("?", "", $data[1])); $aabn = "a".$abn; if (isset($docs[$aabn])) { echo "Existing agency ABN detected<br>"; if (!in_array($name, object_to_array($docs[$aabn]->otherNames)) && $name != $docs[$aabn]->name) { $docs[$aabn]->otherNames[] = $name; try { $docs[$aabn] = $db->save($docs[$aabn]); //print_r($doc); echo $abn . " additional names imported \n<br>"; } catch (SetteeRestClientException $e) { setteErrorHandler($e); } } } else { echo "New agency ABN detected<br>"; $agency['_id'] = md5($aabn); $agency['name'] = $name; $agency["abn"] = $abn; try { $doc = $db->save($agency); print_r($doc); echo $abn . " imported \n<br>"; } catch (SetteeRestClientException $e) { setteErrorHandler($e); } } echo "<hr>"; } fclose($handle); } include_footer(); ?> |