Changeset 512 for trunk


Ignore:
Timestamp:
Mar 26, 2007, 6:44:57 PM (13 years ago)
Author:
Nick Burch
Message:

Support getting gb and ie postcodes, with the optional parameter ie

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/cgi/get-postcodes.fcgi

    r300 r512  
    2626my $max_distance = 50000; # in metres
    2727
     28my %grid_max = (
     29        easting  => { 'gb' => 700000, 'ie' => 400000 },
     30        northing => { 'gb' => 1300000, 'ie' => 500000 },
     31);
     32
    2833my $cgi;
    2934# Process incoming requests
     
    3540        next REQUEST;
    3641    }
     42
     43        # Did they request the irish grid?
     44        my $grid = 'gb';
     45        my $ie = 0;
     46        if(defined $cgi->param('ie')) {
     47                $grid = 'ie';
     48                $ie = 1;
     49        }
    3750
    3851    # Input validation
     
    4659    # Are the Eastings in a valid range?
    4760    foreach (qw(mineasting maxeasting)) {
    48         if (($cgi->param($_) > 700000) or
     61        if (($cgi->param($_) > $grid_max{'easting'}->{$grid}) or
    4962            ($cgi->param($_) < 0)) {
    50             print_err ("Parameter '$_' must be an integer between 0 and 700,000");
     63            print_err ("Parameter '$_' must be an integer between 0 and ".($grid_max{'easting'}->{$grid}/1000).",000");
    5164            next REQUEST;
    5265        }
     
    5568    # Are the Northings in a valid range?
    5669    foreach (qw(minnorthing maxnorthing)) {
    57         if (($cgi->param($_) > 1300000) or
     70        if (($cgi->param($_) > $grid_max{'northing'}->{$grid}) or
    5871            ($cgi->param($_) < 0)) {
    59             print_err("Parameter '$_' must be an integer between 0 and 1,300,000");
     72            print_err("Parameter '$_' must be an integer between 0 and ".($grid_max{'northing'}->{$grid}/1000).",000");
    6073            next REQUEST;
    6174        }
     
    6881    }
    6982
    70     my $sth = $dbh->prepare("SELECT outward || ' ' || inward AS postcode, easting, northing,id,source FROM postcodes WHERE easting BETWEEN ? AND ? AND northing BETWEEN ? AND ? AND NOT deleted");
     83        my ($e,$n) = ("easting","northing");
     84        if($ie) { ($e,$n) = ("ie_easting","ie_northing"); }
     85    my $sth = $dbh->prepare("SELECT outward || ' ' || inward AS postcode, $e, $n,id,source FROM postcodes WHERE $e BETWEEN ? AND ? AND $n BETWEEN ? AND ? AND NOT deleted");
    7186   
    7287    if ($sth->execute($cgi->param('mineasting'), $cgi->param('maxeasting'), $cgi->param('minnorthing'), $cgi->param('maxnorthing'))) {
Note: See TracChangeset for help on using the changeset viewer.