-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 $fixedblock = '';
+
+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
+
+ $opt->{'labels'}{'block_label'} = 'Block';
+
+ 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 $field_callback = sub {
+ my ($cgi, $object, $fieldref) = @_;
+
+ my $columndef = $part_svc->part_svc_column($fieldref->{'field'});
+ if ($columndef->columnflag eq 'F') {
+ $fieldref->{'type'} = length($columndef->columnvalue)
+ ? 'fixed'
+ : 'hidden';
+ $fieldref->{'value'} = $columndef->columnvalue;
+ $fixedblock = $fieldref->{value}
+ if $fieldref->{field} eq 'blocknum';
+
+ if ( $fieldref->{field} eq 'usergroup' ) {
+ $fieldref->{'formatted_value'} =
+ [ $object->radius_groups('long_description') ];
+ }
+ }
+
+ if ($object->svcnum) {
+
+ $fieldref->{type} = 'hidden'
+ if $fieldref->{field} eq 'blocknum';
+
+ $fieldref->{value} = $object->addr_block->label
+ if $fieldref->{field} eq 'block_label' && $object->addr_block;
+
+ } else {
+
+ if ($fieldref->{field} eq 'block_label') {
+ if ($fixedblock && $object->addr_block) {
+ $object->blocknum($fixedblock);
+ $fieldref->{value} = $object->addr_block->label;
+ }else{
+ $fieldref->{type} = 'hidden';
+ }
+ }
+
+ if ($fieldref->{field} eq 'blocknum') {
+ if ( $fixedblock or $conf->exists('auto_router') ) {
+ $fieldref->{type} = 'hidden';
+ $fieldref->{value} = $fixedblock;
+ return;
+ }
+
+ my $cust_pkg = qsearchs( 'cust_pkg', {pkgnum => $cgi->param('pkgnum')} );
+ die "No cust_pkg entry!" unless $cust_pkg;
+
+ $object->svcpart($part_svc->svcpart);
+ my @addr_block =
+ grep { ! $_->agentnum
+ || $cust_pkg->cust_main->agentnum == $_->agentnum
+ && $FS::CurrentUser::CurrentUser->agentnum($_->agentnum)
+ }
+ map { $_->addr_block } $object->allowed_routers;
+ my @options = map { $_->blocknum }
+ sort { $a->label cmp $b->label } @addr_block;
+ my %option_labels = map { ( $_->blocknum => $_->label ) } @addr_block;
+ $fieldref->{type} = 'select';
+ $fieldref->{options} = \@options;
+ $fieldref->{labels} = \%option_labels;
+ }
+
+ }
+};