X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fedit%2Fsvc_broadband.cgi;h=bcf55fe11a73cd9a1e37f32d8f016634846b885a;hp=c2fb58ddad5e38eb3fe523d02d3645f30d914f87;hb=b71b1576c68bc40ad26592b354feace37a029f0e;hpb=0930d22ffc440f80c1b222b2e750cadbabd9e8f6 diff --git a/httemplate/edit/svc_broadband.cgi b/httemplate/edit/svc_broadband.cgi index c2fb58dda..bcf55fe11 100644 --- a/httemplate/edit/svc_broadband.cgi +++ b/httemplate/edit/svc_broadband.cgi @@ -1,167 +1,16 @@ -<% include('/elements/header.html', "Broadband Service $action") %> - -<% include('/elements/error.html') %> - -Service #<%$svcnum ? $svcnum : "(NEW)"%>

- -
- - - - - <%&ntable("#cccccc",2)%> - - Description - -% if ( $part_svc->part_svc_column('description')->columnflag eq 'F' ) { - - <%$description%> -% } else { - - -% } - - - - - IP Address - -% if ( $part_svc->part_svc_column('ip_addr')->columnflag eq 'F' ) { - - <%$ip_addr%> -% } else { - - -% } - - - - - Download speed - -% if ( $part_svc->part_svc_column('speed_down')->columnflag eq 'F' ) { - - <%$speed_down%>Kbps -% } else { - - Kbps -% } - - - - - Upload speed - -% if ( $part_svc->part_svc_column('speed_up')->columnflag eq 'F' ) { - - <%$speed_up%>Kbps -% } else { - - Kbps -% } - - - -% if ($action eq 'Add') { - - - Router/Block - - - - -% } else { - - - - Router/Block - - <%$svc_broadband->addr_block->router->routername%>:<%$svc_broadband->addr_block->NetAddr%> - - - -% } - - MAC Address - - - - - - Latitude - - - - - - Longitude - - - - - - Altitude - - - - - - VLAN Profile - -% if ( $part_svc->part_svc_column('vlan_profile')->columnflag eq 'F' ) { - - <%$vlan_profile%> -% } else { - - -% } - - - - - Authentication Key - -% if ( $part_svc->part_svc_column('auth_key')->columnflag eq 'F' ) { - - <%$auth_key%> -% } else { - - -% } - - - -% -%foreach my $field ($svc_broadband->virtual_fields) { -% if ( $part_svc->part_svc_column($field)->columnflag ne 'F' && -% $part_svc->part_svc_column($field)->columnflag ne 'X') { -% print $svc_broadband->pvf($field)->widget('HTML', 'edit', -% $svc_broadband->getfield($field)); -% } -%} - - -
- -
- -<% include('/elements/footer.html') %> - +<& elements/svc_Common.html, + 'post_url' => popurl(1). 'process/svc_broadband.cgi', + 'name' => 'broadband service', + 'table' => 'svc_broadband', + 'fields' => \@fields, + 'svc_field_callback' => $svc_field_callback, + 'svc_new_callback' => $svc_edit_callback, + 'svc_edit_callback' => $svc_edit_callback, + 'svc_error_callback' => $svc_edit_callback, + 'dummy' => $cgi->query_string, + 'onsubmit' => 'validate_coords', + 'html_foot' => $js, +&> <%init> die "access denied" @@ -170,85 +19,170 @@ die "access denied" # If it's stupid but it works, it's still stupid. # -Kristian -use HTML::Widgets::SelectLayers; -use Tie::IxHash; - -my( $svcnum, $pkgnum, $svcpart, $part_svc, $svc_broadband ); -if ( $cgi->param('error') ) { - - $svc_broadband = new FS::svc_broadband ( { - map { $_, scalar($cgi->param($_)) } fields('svc_broadband'), qw(svcpart) - } ); - $svcnum = $svc_broadband->svcnum; - $pkgnum = $cgi->param('pkgnum'); - $svcpart = $svc_broadband->svcpart; - $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart}); - die "No part_svc entry!" unless $part_svc; - -} elsif ( $cgi->param('pkgnum') && $cgi->param('svcpart') ) { #adding - - $cgi->param('pkgnum') =~ /^(\d+)$/ or die 'unparsable pkgnum'; - $pkgnum = $1; - $cgi->param('svcpart') =~ /^(\d+)$/ or die 'unparsable svcpart'; - $svcpart = $1; - - $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart}); - die "No part_svc entry!" unless $part_svc; - - $svc_broadband = new FS::svc_broadband({ svcpart => $svcpart }); - - $svcnum=''; - - $svc_broadband->set_default_and_fixed; - -} else { #editing - - my($query) = $cgi->keywords; - $query =~ /^(\d+)$/ or die "unparsable svcnum"; - $svcnum=$1; - $svc_broadband=qsearchs('svc_broadband',{'svcnum'=>$svcnum}) - or die "Unknown (svc_broadband) svcnum!"; - - my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum}) - or die "Unknown (cust_svc) svcnum!"; - - $pkgnum=$cust_svc->pkgnum; - $svcpart=$cust_svc->svcpart; - - $part_svc=qsearchs('part_svc',{'svcpart'=>$svcpart}); - die "No part_svc entry!" unless $part_svc; - +my $conf = new FS::Conf; + +my $js = < + function validate_coords(f){ +END +; +if ( $conf->exists('svc_broadband-require-nw-coordinates') ) { +$js .= < 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 +; } -my $action = $svc_broadband->svcnum ? 'Edit' : 'Add'; - -if ($pkgnum) { - - #Nothing? - -} elsif ( $action eq 'Edit' ) { - - #Nothing? - -} else { - die "\$action eq Add, but \$pkgnum is null!\n"; +$js .= < +END +; + +my @fields = ( + qw( description speed_down speed_up speed_test_down speed_test_up speed_test_latency), + { field=>'sectornum', type=>'select-tower_sector', }, + { field=>'routernum', type=>'select-router_block_ip', + include_opt_callback => sub { + my $svc_broadband = shift; + my $part_svc = $svc_broadband->part_svc; + return () unless $part_svc; #sanity check + my $col = $part_svc->part_svc_column('ip_addr'); + return () unless $col; #sanity check + return ('ip_addr_required' => $col->required); + }, + }, + { field=>'mac_addr' , type=>'input-mac_addr' }, + qw( + latitude longitude altitude + radio_serialnum radio_location poe_location rssi suid + ), + { field=>'shared_svcnum', type=>'search-svc_broadband', }, + qw( vlan_profile performance_profile authkey plan_id ), +); + +if ( $conf->exists('svc_broadband-radius') ) { + push @fields, + { field => 'usergroup', + type => 'select-radius_group', + multiple => 1, + } } -my $p1 = popurl(1); - -my ($ip_addr, $speed_up, $speed_down, $blocknum, $mac_addr, - $latitude, $longitude, $altitude, $vlan_profile, $auth_key, - $description) = - ($svc_broadband->ip_addr, - $svc_broadband->speed_up, - $svc_broadband->speed_down, - $svc_broadband->blocknum, - $svc_broadband->mac_addr, - $svc_broadband->latitude, - $svc_broadband->longitude, - $svc_broadband->altitude, - $svc_broadband->vlan_profile, - $svc_broadband->auth_key, - $svc_broadband->description, - ); +my $part_svc; + +my $svc_edit_callback = sub { + my ($cgi, $svc_x, $part_svc_x, $cust_pkg, $fields, $opt) = @_; + + $part_svc = $part_svc_x; #for field_callback to use + + my ($nas_export) = $part_svc->part_export('broadband_nas'); + #can we assume there's only one of these per part_svc? + if ( $nas_export ) { + my $nas; + if ( $svc_x->svcnum ) { + $nas = qsearchs('nas', { 'svcnum' => $svc_x->svcnum }); + } + $nas ||= $nas_export->default_nas; + $svc_x->set($_, $nas->$_) foreach fields('nas'); + + # duplicates the fields in httemplate/edit/nas.html (mostly) + push @$fields, + { type => 'tablebreak-tr-title', + #value => 'Attached NAS', + value => $nas_export->exportname, + colspan => 2, + }, + { field=>'nasnum', type=>'hidden', }, + { field=>'shortname', size=>16, maxlength=>32 }, + { field=>'secret', size=>40, maxlength=>60, required=>1 }, + { field=>'type', type=>'select', + options=>[qw( cisco computone livingston max40xx multitech netserver + pathras patton portslave tc usrhiper other )], + }, + { field=>'ports', size=>5 }, + { field=>'server', size=>40, maxlength=>64 }, + { field=>'community', size=>40, maxlength=>50 }, + ; + + $opt->{'labels'}{'shortname'} = 'Short name'; + $opt->{'labels'}{'secret'} = 'Shared secret'; + $opt->{'labels'}{'type'} = 'Type'; + $opt->{'labels'}{'ports'} = 'Ports'; + $opt->{'labels'}{'server'} = 'Server'; + $opt->{'labels'}{'community'} = 'Community'; + } +}; + +my $svc_field_callback = sub { + my ($cgi, $object, $fieldref) = @_; + + my $columndef = $part_svc->part_svc_column($fieldref->{'field'}); + if ($fieldref->{field} eq 'usergroup' && $columndef->columnflag eq 'F') { + $fieldref->{'formatted_value'} = + [ $object->radius_groups('long_description') ]; + } + +};