Changeset 40
- Timestamp:
- Oct 15, 2006, 12:22:44 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/npemap.org.uk/cgi/submit.fcgi
r38 r40 21 21 22 22 my @fields = qw(easting northing postcode); 23 my $returnBaseURL = 'http://www.npemap.org.uk'; 23 24 24 25 my $cgi; … … 26 27 REQUEST: while ($cgi = new CGI::Fast) { 27 28 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 28 40 # In case the database went away, make sure we have a connection 29 41 unless (setup_dbh()) { 30 print_err('Error setting up database connection' );42 print_err('Error setting up database connection', $returnlink); 31 43 next REQUEST; 32 44 } … … 37 49 foreach my $field (@fields) { 38 50 unless (defined $cgi->param($field)) { 39 print_err ("Parameter '$field' missing" );51 print_err ("Parameter '$field' missing", $returnlink); 40 52 next REQUEST; 41 53 } … … 45 57 if (($cgi->param('easting') > 700000) or 46 58 ($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); 48 60 next REQUEST; 49 61 } else { … … 54 66 if (($cgi->param('northing') > 1300000) or 55 67 ($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); 57 69 next REQUEST; 58 70 } else { … … 80 92 $inward .= $fourth if $fourth; 81 93 } else { 82 print_err("The postcode format is not valid" );94 print_err("The postcode format is not valid", $returnlink); 83 95 next REQUEST; 84 96 } … … 90 102 $sth = $dbh->prepare('SELECT raw_postcode FROM postcodes WHERE raw_postcode = ? AND easting = ? AND northing = ? AND ip = ?'); 91 103 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); 93 105 next REQUEST; 94 106 } 95 107 96 108 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); 98 110 next REQUEST; 99 111 } … … 103 115 print "Content-type: text/html\n\n"; 104 116 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"; 106 119 print "</body></html>"; 107 120 next REQUEST; 108 121 } else { 109 122 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); 111 124 next REQUEST; 112 125 } … … 117 130 118 131 # Helper routines 119 sub print_err($ ) {132 sub print_err($$) { 120 133 my $err = shift; 134 my $returnlink = shift; 121 135 print "Content-type: text/html\n\n"; 122 136 print "<html><head><title>Error submitting</title></head>\n"; … … 128 142 print "<li>$field: " . $param . "</li>\n"; 129 143 } 130 print "</ul></body></html>\n"; 144 print "</ul>\n"; 145 print "<p>$returnlink</p>\n"; 146 print "</body></html>\n"; 131 147 } 132 148
Note: See TracChangeset
for help on using the changeset viewer.