Skip to content
Commits on Source (3)
......@@ -15,8 +15,7 @@ if (isset($_GET['key'])){
}
break;
case "postcode":
$postcode=implode("", explode(" ", $_GET['value']));
echo json_encode(lookup_postcode($postcode));
echo lookup_postcode($_GET['value']);
break;
case "username":
$username = $_GET['value'];
......
......@@ -21,21 +21,34 @@ function validate(){
}
function processPostcode(){
// lookup postcode
$.getJSON("/signup/ajax",{key: "postcode",value: $('input#postcode').val().replace(/ /g,'')}, function(j){
$.getJSON("signup/ajax",{key: "postcode",value: $('input#postcode').val()}, function(j){
//populate dropdown
var options = '';
if (j.length > 1) {
if (j.addresses.length > 1) {
// make dropdown visible
$('div#addseldiv').removeAttr("style");
for (var i = 0; i < j.length; i++) {
options += '<option>' + j[i] + '</option>';
for (var i = 0; i < (j.addresses.length); i++) {
options += '<option>';
if (j.addresses[i].flat != null) {
options += j.addresses[i].flat + "\n";
}
if (j.addresses[i].house != null) {
options += j.addresses[i].house + "\n";
}
if (j.addresses[i].road != null) {
options += j.addresses[i].road + "\n";
}
if (j.addresses[i].city != null) {
options += j.addresses[i].city + "\n";
}
options += '</option>';
}
$("select#addsel").html(options);
$('select#addsel option:first').attr('selected', 'selected');
}
if (j.length == 1) {
if (j.addresses.length == 1) {
$('div#addseldiv').attr("style","display:none");
$("textarea#address").val(j[0].replace(/, /g,'\n'))
$("textarea#address")
$('div#addressmessage').attr("style","color:green; float:right; clear:right;");
$('div#addressmessage').html("OK");
validation["address"]=true;
......
......@@ -12,29 +12,15 @@ function lookupSID($sid) {
}
// lookup addresses from postcodes useing the univeritys website
function lookup_postcode($postcode = "")
{
$url = "https://intranet.swan.ac.uk/common/postcodeLookup.asp?pCode=".$postcode;
$referer = "https://intranet.swan.ac.uk/common/postcodeaddresslookup.asp";
function lookup_postcode($postcode) {
include_once "../paf-key.php";
$url = "http://paf.sucs.org/?apikey=$apikey&postcode=".rawurlencode($postcode);
$req = curl_init($url);
curl_setopt($req, CURLOPT_HEADER, false);
curl_setopt($req, CURLOPT_REFERER, $referer);
curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
curl_setopt($req, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($req, CURLOPT_SSLVERSION, 3);
$page = curl_exec($req);
curl_close($req);
$scrape = explode("returnAddress(\"", $page);
$addresses = array();
for ($i = 1; $i < count($scrape); $i++) {
if (preg_match("/^[^,\"].+?\"/", $scrape[$i], $address)) {
$addr = str_replace("<BR>\"", "", $address[0]);
array_push($addresses, str_replace("<BR>", ", ", $addr));
}
}
return $addresses;
}
?>