Changeset 40


Ignore:
Timestamp:
Oct 15, 2006, 12:22:44 PM (13 years ago)
Author:
Dominic Hargreaves
Message:

Add a return link feature as per trac ticket #10

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/cgi/submit.fcgi

    r38 r40  
    2121
    2222my @fields = qw(easting northing postcode);
     23my $returnBaseURL = 'http://www.npemap.org.uk';
    2324
    2425my $cgi;
     
    2627REQUEST: while ($cgi = new CGI::Fast) {
    2728
     29    # If we're given return URL parameters, basic sanity check to stop
     30    # funny business
     31    my $returnlink = '<a href="'. $returnBaseURL . '/">Go back to the start</a>';   
     32
     33    if (defined $cgi->param('returnX') and ($cgi->param('returnX') =~ /\d+/) and
     34        defined $cgi->param('returnY') and ($cgi->param('returnY') =~ /\d+/) and
     35        defined $cgi->param('returnZoom') and ($cgi->param('returnZoom') =~ /\d+/)) {
     36        $returnlink = '<a href="' . $returnBaseURL . '/tiles/map.html?' . $cgi->param('returnX') . ',' . $cgi->param('returnY') . ',' . $cgi->param('returnZoom') . '">Go back to the map</a>';
     37    }
     38
     39
    2840    # In case the database went away, make sure we have a connection
    2941    unless (setup_dbh()) {
    30         print_err('Error setting up database connection');
     42        print_err('Error setting up database connection', $returnlink);
    3143        next REQUEST;
    3244    }
     
    3749    foreach my $field (@fields) {
    3850        unless (defined $cgi->param($field)) {
    39             print_err ("Parameter '$field' missing");
     51            print_err ("Parameter '$field' missing", $returnlink);
    4052            next REQUEST;
    4153        }
     
    4557    if (($cgi->param('easting') > 700000) or
    4658        ($cgi->param('easting') < 0)) {
    47         print_err ("Parameter 'easting' must be an integer between 0 and 700,000");
     59        print_err ("Parameter 'easting' must be an integer between 0 and 700,000", $returnlink);
    4860        next REQUEST;
    4961    } else {
     
    5466    if (($cgi->param('northing') > 1300000) or
    5567        ($cgi->param('northing') < 0)) {
    56         print_err("Parameter 'northing' must be an integer between 0 and 1,300,000");
     68        print_err("Parameter 'northing' must be an integer between 0 and 1,300,000", $returnlink);
    5769        next REQUEST;
    5870    } else {
     
    8092        $inward .= $fourth if $fourth;
    8193    } else {
    82         print_err("The postcode format is not valid");
     94        print_err("The postcode format is not valid", $returnlink);
    8395        next REQUEST;
    8496    }
     
    90102    $sth = $dbh->prepare('SELECT raw_postcode FROM postcodes WHERE raw_postcode = ? AND easting = ? AND northing = ? AND ip = ?');
    91103    unless ($sth->execute($raw_postcode, $easting, $northing, $ENV{'REMOTE_ADDR'})) {
    92         print_err('Database error when checking for duplicate data :(');
     104        print_err('Database error when checking for duplicate data :(', $returnlink);
    93105        next REQUEST;
    94106    }
    95107
    96108    if ($sth->rows) {
    97         print_err('You, or someone with the same IP address, have already submitted this postcode with these co-ordinates.');
     109        print_err('You, or someone with the same IP address, have already submitted this postcode with these co-ordinates.', $returnlink);
    98110        next REQUEST;
    99111    }
     
    103115        print "Content-type: text/html\n\n";
    104116        print "<html><head><title>Thank you</title></head>\n";
    105         print "<body>Thank you for telling us where your post code is!\n";
     117        print "<body><p>Thank you for telling us where your post code is!</p>\n";
     118        print "<p>$returnlink</p>\n";
    106119        print "</body></html>";
    107120        next REQUEST;
    108121    } else {
    109122        print STDERR "DB error: " . $dbh->errstr . "\n";
    110         print_err("Database error when adding your data :(");
     123        print_err("Database error when adding your data :(", $returnlink);
    111124        next REQUEST;
    112125    }
     
    117130
    118131# Helper routines
    119 sub print_err($) {
     132sub print_err($$) {
    120133    my $err = shift;
     134    my $returnlink = shift;
    121135    print "Content-type: text/html\n\n";
    122136    print "<html><head><title>Error submitting</title></head>\n";
     
    128142        print "<li>$field: " . $param . "</li>\n";
    129143    }
    130     print "</ul></body></html>\n";
     144    print "</ul>\n";
     145    print "<p>$returnlink</p>\n";
     146    print "</body></html>\n";
    131147}
    132148
Note: See TracChangeset for help on using the changeset viewer.