Changeset 365 for trunk/npemap.org.uk
- Timestamp:
- Nov 12, 2006, 5:09:10 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/npemap.org.uk/cgi/geocoder.fcgi
r364 r365 65 65 my $inward; 66 66 if(defined $cgi->param("postcode")) { 67 $postcode = $cgi->param("postcode");68 ($outward,$inward) = ($postcode =~ /^( \w+\d+\w?)\s*(\d\w\w)$/);67 $postcode = uc($cgi->param("postcode")); 68 ($outward,$inward) = ($postcode =~ /^([A-Z]+\d+[A-Z]?)\s*(\d[A-Z][A-Z])$/); 69 69 unless($outward && $inward) { 70 70 print_err ("Invalid postcode '$postcode' supplied"); … … 90 90 } 91 91 unless($matched) { 92 my ($mpart) = ($outward =~ /^( \w+)\d/);92 my ($mpart) = ($outward =~ /^([A-Z]+)\d/); 93 93 my $mlen = length($mpart); 94 94 95 95 ($easting,$northing,$matched,$pc) = 96 execute($area_matcher,$mlen,$mlen,$mpart,$mlen); 96 execute($area_matcher,$mpart,$mlen,$mlen,$mpart,$mlen); 97 98 unless($matched) { 99 print_err "Postcode area '$mpart' not found, postcode probably invalid"; 100 next REQUEST; 101 } 97 102 } 98 103 99 print "$easting $northing $matched $pc\n"; 100 104 # Render 105 if($output eq "xml") { 106 print header("text/xml"); 107 print "<?xml version='1.0'?>\n"; 108 print "<geocoder>\n"; 109 print " <request>\n"; 110 print " <postcode>$postcode</postcode>\n"; 111 print " <outward>$outward</outward>\n"; 112 print " <inward>$inward</inward>\n"; 113 print " </request>\n\n"; 114 print " <easting>".int($easting)."</easting>\n"; 115 print " <northing>".int($northing)."</northing>\n"; 116 print " <postcode>$pc</postcode>\n"; 117 print "</geocoder>\n"; 118 } else { 119 print header("text/plain"); 120 print "# Easting,Northing,Matched Postcode\n"; 121 print int($easting).",".int($northing).",'$pc'\n"; 122 } 101 123 } 102 124 … … 137 159 my $outer_sql = $base_sql_a . " outward || ' ###'". $base_sql_b . 138 160 "AND outward = ? GROUP BY outward"; 139 my $area_sql = $base_sql_a . " substr( outward,1,?) " . $base_sql_b .161 my $area_sql = $base_sql_a . " substr(?,1,?) " . $base_sql_b . 140 162 "AND substr(outward,1,?) = ? ". 141 163 "GROUP BY substr(outward,1,?)"; 142 print $area_sql."\n";143 164 144 165 my $full_matcher = $dbh->prepare($full_sql);
Note: See TracChangeset
for help on using the changeset viewer.