<% include( 'edit.html', 'menubar' => [], 'error_callback' => sub { my( $cgi, $svc_x, $fields, $opt ) = @_; #$svcnum = $svc_x->svcnum; $pkgnum = $cgi->param('pkgnum'); $svcpart = $cgi->param('svcpart'); $part_svc = qsearchs( 'part_svc', { svcpart=>$svcpart }); die "No part_svc entry!" unless $part_svc; label_fixup($part_svc, $opt); $svc_x->setfield('svcpart', $svcpart); if ( my $cb = $opt{'svc_error_callback'} ) { my $cust_pkg = $pkgnum ? qsearchs('cust_pkg', {pkgnum=>$pkgnum}) : ''; #? &{ $cb }( $cgi,$svc_x, $part_svc,$cust_pkg, $fields,$opt); } }, 'edit_callback' => sub { my( $cgi, $svc_x, $fields, $opt ) = @_; #$svcnum = $svc_x->svcnum; my $cust_svc = $svc_x->cust_svc 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; label_fixup($part_svc, $opt); if ( my $cb = $opt{'svc_edit_callback'} ) { my $cust_pkg = $pkgnum ? qsearchs('cust_pkg', {pkgnum=>$pkgnum}) : ''; #? &{ $cb }( $cgi,$svc_x, $part_svc,$cust_pkg, $fields,$opt); } }, 'new_hashref_callback' => sub { #my( $cgi, $svc_x ) = @_; { pkgnum => $pkgnum, svcpart => $svcpart, }; }, 'new_callback' => sub { my( $cgi, $svc_x, $fields, $opt ) = @_; $part_svc = qsearchs( 'part_svc', { svcpart=>$svcpart }); die "No part_svc entry!" unless $part_svc; label_fixup($part_svc, $opt); #$svcnum=''; if ( my $cb = $opt{'svc_new_callback'} ) { my $cust_pkg = $pkgnum ? qsearchs('cust_pkg', {pkgnum=>$pkgnum}) : ''; #? &{ $cb }( $cgi,$svc_x, $part_svc,$cust_pkg, $fields,$opt); } $svc_x->set_default_and_fixed; }, 'field_callback' => sub { my ($cgi, $object, $f) = @_; my $columndef = $part_svc->part_svc_column($f->{'field'}); my $flag = $columndef->columnflag; if ( $flag eq 'F' ) { $f->{'type'} = length($columndef->columnvalue) ? 'fixed' : 'hidden'; $f->{'value'} = $columndef->columnvalue; } elsif ( $flag eq 'A' ) { $f->{'type'} = 'hidden'; } elsif ( $flag eq 'M' ) { $f->{'empty_label'} = 'Select inventory item'; $f->{'type'} = 'select-table'; $f->{'table'} = 'inventory_item'; $f->{'name_col'} = 'item'; $f->{'value_col'} = 'item'; $f->{'agent_virt'} = 1; $f->{'agent_null'} = 1; $f->{'hashref'} = { 'classnum'=>$columndef->columnvalue, #'svcnum' => '', }; $f->{'extra_sql'} = 'AND ( svcnum IS NULL '; $f->{'extra_sql'} .= ' OR svcnum = '. $object->svcnum if $object->svcnum; $f->{'extra_sql'} .= ' ) '; $f->{'disable_empty'} = $object->svcnum ? 1 : 0, } elsif ( $flag eq 'H' ) { $f->{'type'} = 'select-hardware_type'; $f->{'hashref'} = { 'classnum'=>$columndef->columnvalue }; $f->{'empty_label'} = 'Select hardware type'; } if ( $f->{'type'} eq 'select-svc_pbx' || $f->{'type'} eq 'select-svc-domain' ) { $f->{'include_opt_callback'} = sub { ( 'pkgnum' => $pkgnum, 'svcpart' => $svcpart, ); }; } if ( $f->{'field'} eq 'custnum' && $pkgnum ) { my $cust_pkg = qsearchs('cust_pkg', {'pkgnum' => $pkgnum}); $object->set('custnum', $cust_pkg->custnum); } }, 'html_init' => sub { my $cust_main; if ( $pkgnum ) { my $cust_pkg = qsearchs('cust_pkg', {'pkgnum' => $pkgnum}); $cust_main = $cust_pkg->cust_main if $cust_pkg; } $cust_main ? include( '/elements/small_custview.html', $cust_main, '', 1, popurl(2). "view/cust_main.cgi" ). '
' : ''; }, 'html_table_bottom' => sub { my $svc_x = shift; my $html = ''; foreach my $field ($svc_x->virtual_fields) { if ($part_svc->part_svc_column($field)->columnflag ne 'F'){ # If the flag is X, it won't even show up # in $svc_acct->virtual_fields. $html .= $svc_x->pvf($field)->widget( 'HTML', 'edit', $svc_x->getfield($field) ); } } $html; }, 'html_bottom' => sub { qq!!. qq!!; }, %opt #pass through/override params ) %> <%once> sub label_fixup { my( $part_svc, $opt ) = @_; $opt->{'name'} ||= $part_svc->svc; my $svcdb = $part_svc->svcdb; require "FS/$svcdb.pm"; if ( UNIVERSAL::can("FS::$svcdb", 'table_info') ) { #$opt->{'name'} ||= "FS::$svcdb"->table_info->{'name'}; my $fields = "FS::$svcdb"->table_info->{'fields'}; $opt->{'fields'} ||= [ grep { $_ ne 'svcnum' } keys %$fields ]; $opt->{labels} ||= { map { $_ => ( ref($fields->{$_}) ? $fields->{$_}{'label'} : $fields->{$_} ); } keys %$fields }; } #false laziness w/view/svc_Common.html #override default labels with service-definition labels if applicable my $labels = $opt->{labels}; # with -> here foreach my $field ( keys %{ $opt->{labels} } ) { my $col = $part_svc->part_svc_column($field); $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\s*$/; } } <%init> my %opt = @_; #my( $svcnum, $pkgnum, $svcpart, $part_svc ); my( $pkgnum, $svcpart, $part_svc ); #get & untaint pkgnum & svcpart if ( ! $cgi->param('error') && $cgi->param('pkgnum') && $cgi->param('svcpart') ) { $cgi->param('pkgnum') =~ /^(\d+)$/ or die 'unparsable pkgnum'; $pkgnum = $1; $cgi->param('svcpart') =~ /^(\d+)$/ or die 'unparsable svcpart'; $svcpart = $1; #$cgi->delete_all(); #so edit.html treats this correctly as new?? }