summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlevinse <levinse>2011-06-10 05:16:54 +0000
committerlevinse <levinse>2011-06-10 05:16:54 +0000
commit6361e71971a84c4f798c2f4eef89bbd454a3cb0d (patch)
treecef6785e494f33681b424beb8a32f0c0abc0bc4c
parentc7bf005860b761a55ca075df987fb3b5ade8c242 (diff)
svc_broadband add/edit: configurable require co-ordinates in NW quadrant, RT12925
-rw-r--r--FS/FS/Conf.pm7
-rwxr-xr-xFS/FS/svc_broadband.pm8
-rw-r--r--httemplate/edit/svc_broadband.cgi80
3 files changed, 93 insertions, 2 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index 2499f4e54..1a05aaee9 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -4446,6 +4446,13 @@ and customer address. Include units.',
},
{
+ 'key' => 'svc_broadband-require-nw-coordinates',
+ 'section' => 'UI',
+ 'description' => 'On svc_broadband add/edit, require latitude and longitude in the North Western quadrant',
+ 'type' => 'checkbox',
+ },
+
+ {
'key' => 'cust-email-high-visibility',
'section' => 'UI',
'description' => 'Move the invoicing e-mail address field to the top of the billing address section and highlight it.',
diff --git a/FS/FS/svc_broadband.pm b/FS/FS/svc_broadband.pm
index 2b794aa4b..f1a233b40 100755
--- a/FS/FS/svc_broadband.pm
+++ b/FS/FS/svc_broadband.pm
@@ -334,6 +334,10 @@ sub check {
return $x unless ref($x);
+ my $nw_coords = $conf->exists('svc_broadband-require-nw-coordinates');
+ my $lat_lower = $nw_coords ? 1 : -90;
+ my $lon_upper = $nw_coords ? -1 : 180;
+
my $error =
$self->ut_numbern('svcnum')
|| $self->ut_numbern('blocknum')
@@ -343,8 +347,8 @@ sub check {
|| $self->ut_ipn('ip_addr')
|| $self->ut_hexn('mac_addr')
|| $self->ut_hexn('auth_key')
- || $self->ut_coordn('latitude', -90, 90)
- || $self->ut_coordn('longitude', -180, 180)
+ || $self->ut_coordn('latitude', $lat_lower, 90)
+ || $self->ut_coordn('longitude', -180, $lon_upper)
|| $self->ut_sfloatn('altitude')
|| $self->ut_textn('vlan_profile')
|| $self->ut_textn('plan_id')
diff --git a/httemplate/edit/svc_broadband.cgi b/httemplate/edit/svc_broadband.cgi
index ae7f50fca..a67f6f05a 100644
--- a/httemplate/edit/svc_broadband.cgi
+++ b/httemplate/edit/svc_broadband.cgi
@@ -5,6 +5,8 @@
'fields' => \@fields,
'field_callback' => $callback,
'dummy' => $cgi->query_string,
+ 'onsubmit' => 'validate_coords',
+ 'html_foot' => $js,
)
%>
<%init>
@@ -17,6 +19,84 @@ die "access denied"
my $conf = new FS::Conf;
+my $js = <<END
+ <script type="text/javascript">
+ function validate_coords(f){
+END
+;
+if ( $conf->exists('svc_broadband-require-nw-coordinates') ) {
+$js .= <<END
+ var lon = f.longitude;
+ var lat = f.latitude;
+ if ( lon == null || lat == null ||
+ lon.value.length == 0 || lat.value.length == 0 ) return true;
+
+ return (ut_coord(lat.value,1,90) && ut_coord(lon.value,-180,-1));
+ } // validate_coords
+
+ /* this is a JS re-implementation of FS::Record::ut_coord */
+ function ut_coord(coord,lower,upper) {
+ var neg = /^-/.test(coord);
+ coord = coord.replace(/^-/,'');
+
+ var d = 0;
+ var m = 0;
+ var s = 0;
+
+ var t1 = /^(\\s*\\d{1,3}(?:\\.\\d+)?)\\s*\$/.exec(coord);
+ var t2 = /^(\\s*\\d{1,3})\\s+(\\d{1,2}(?:\\.\\d+))\\s*\$/.exec(coord);
+ var t3 = /^(\\s*\\d{1,3})\\s+(\\d{1,2})\\s+(\\d{1,3})\\s*\$/.exec(coord);
+ if ( t1 != null ) {
+ d = t1[1];
+ } else if ( t2 != null ) {
+ d = t2[1];
+ m = t2[2];
+ } else if ( t3 != null ) {
+ d = t3[1];
+ m = t3[2];
+ s = t3[3];
+ } else {
+ alert('Invalid co-ordinates! Latitude must be positive and longitude must be negative.');
+ return false;
+ }
+
+ var ts = /^\\d{3}\$/.exec(s);
+ if ( ts != null || s > 59 ) {
+ s /= 1000;
+ } else {
+ s /= 60;
+ }
+ s /= 60;
+
+ m /= 60;
+ if ( m > 59 ) {
+ alert('Invalid coordinate with minutes > 59');
+ return false;
+ }
+
+ var tmp = parseInt(d)+parseInt(m)+parseInt(s);
+ tmp = tmp.toFixed(8);
+ coord = (neg ? -1 : 1) * tmp;
+
+ if(coord < lower) {
+ alert('Error: invalid coordinate < '+lower);
+ return false;
+ }
+ if(coord > upper) {
+ alert('Error: invalid coordinate > '+upper);
+ return false;
+ }
+
+ return true;
+END
+;
+}
+$js .= <<END
+ }
+ </script>
+END
+;
+
my @fields = (
qw( description ip_addr speed_down speed_up blocknum ),
{ field=>'block_label', type=>'fixed' },