Add openid security
[contractdashboard.git] / admin / setAgencyURLABN.php
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
<?php
include_once ("../lib/common.inc.php");
// to reset: update agency set abn = 0, website = ''
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "http://contractdashboard.lambdacomplex.org");
$querySel = sprintf("SELECT * FROM `agency` where ABN = 0 OR website = ''");
$resultSel = mysql_query($querySel);
while ($row = mysql_fetch_array($resultSel, MYSQL_ASSOC)) {
  $agency = $row['agencyName'];
  //foreach $agency
  $url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&key=ABQIAAAA95XYXN0cki3Yj_Sb71CFvBSgIPe2k9-DRgEVQvbvQDV8xmTiXRTBpHxrD7bSh5rl2lswY56769CyQQ&rsz=small&filter=1&gl=au&q=" . urlencode($agency) . "%20ABN%20site:.gov.au%20-site:www.abr.business.gov.au";
  curl_setopt($ch, CURLOPT_URL, $url);
  $body = curl_exec($ch);
  $json = json_decode($body);
  echo "<pre>";
  $result = $json->responseData->results[0];
  print_r($result);
  echo "</pre>";
  echo "<b> Agency:</b> $agency";
  echo "<b> URL:</b> http://" . $result->visibleUrl;
  preg_match('/\d{2} \d{3} \d{3} \d{3}/i', $result->content, $abn);
  $abn[0] = str_replace(" ","",$abn[0]);
  echo "<b> ABN:</b> {$abn[0]}";
  if ($abn[0] > 1000) {
  $result = mysql_query("UPDATE agency SET website = 'http://" . $result->visibleUrl . "', abn = '{$abn[0]}' WHERE agencyName = '$agency';");
  if ($result) echo $agency . " set in " . mysql_affected_rows() . " <br>\n";
  } else {
        
        echo "invalid ABN";
        $result = mysql_query("UPDATE agency SET website = 'http://" . $result->visibleUrl . "' WHERE agencyName = '$agency';");
        if ($result) echo $agency . " set in " . mysql_affected_rows() . " <br>\n";
  }
  // fi
  
}
curl_close($ch);
?>