1 <% include( 'edit.html',
5 'error_callback' => sub {
6 my( $cgi, $svc_x, $fields, $opt ) = @_;
7 #$svcnum = $svc_x->svcnum;
8 $pkgnum = $cgi->param('pkgnum');
9 $svcpart = $cgi->param('svcpart');
11 $part_svc = qsearchs( 'part_svc', { svcpart=>$svcpart });
12 die "No part_svc entry!" unless $part_svc;
14 label_fixup($part_svc, $opt);
16 $svc_x->setfield('svcpart', $svcpart);
18 if ( my $cb = $opt{'svc_error_callback'} ) {
19 my $cust_pkg = $pkgnum
20 ? qsearchs('cust_pkg', {pkgnum=>$pkgnum})
22 &{ $cb }( $cgi,$svc_x, $part_svc,$cust_pkg, $fields,$opt);
27 'edit_callback' => sub {
28 my( $cgi, $svc_x, $fields, $opt ) = @_;
29 #$svcnum = $svc_x->svcnum;
30 my $cust_svc = $svc_x->cust_svc
31 or die "Unknown (cust_svc) svcnum!";
33 $pkgnum = $cust_svc->pkgnum;
34 $svcpart = $cust_svc->svcpart;
36 $part_svc = qsearchs ('part_svc', { svcpart=>$svcpart });
37 die "No part_svc entry!" unless $part_svc;
39 label_fixup($part_svc, $opt);
41 if ( my $cb = $opt{'svc_edit_callback'} ) {
42 my $cust_pkg = $pkgnum
43 ? qsearchs('cust_pkg', {pkgnum=>$pkgnum})
45 &{ $cb }( $cgi,$svc_x, $part_svc,$cust_pkg, $fields,$opt);
48 if ( $part_svc->has_router ) {
49 my $router = qsearchs('router', {svcnum => $svc_x->svcnum});
51 $svc_x->set("router_$_", $router->get($_))
52 foreach ('routername', 'routernum');
53 my ($block) = $router->addr_block; # one-to-one for now
55 $svc_x->set('router_blocknum', $block->blocknum);
56 # silly, but necessary...make the currently
57 # assigned block appear on the list
58 my ($field) = grep {ref($_) and
59 $_->{field} eq 'router_blocknum'}
62 ' OR routernum = '.$router->routernum;
63 $field->{curr_value} = $block->blocknum;
70 'new_hashref_callback' => sub {
71 #my( $cgi, $svc_x ) = @_;
79 'new_callback' => sub {
80 my( $cgi, $svc_x, $fields, $opt ) = @_;
82 $part_svc = qsearchs( 'part_svc', { svcpart=>$svcpart });
83 die "No part_svc entry!" unless $part_svc;
85 label_fixup($part_svc, $opt);
89 if ( my $cb = $opt{'svc_new_callback'} ) {
90 my $cust_pkg = $pkgnum
91 ? qsearchs('cust_pkg', {pkgnum=>$pkgnum})
93 &{ $cb }( $cgi,$svc_x, $part_svc,$cust_pkg, $fields,$opt);
96 $svc_x->set_default_and_fixed;
99 'field_callback' => sub {
100 my ($cgi, $object, $f) = @_;
102 my $columndef = $part_svc->part_svc_column($f->{'field'});
103 my $flag = $columndef->columnflag;
106 if $columndef->required;
108 if ( $flag eq 'F' ) { #fixed
109 $f->{'value'} = $columndef->columnvalue;
110 if (length($columndef->columnvalue)) {
112 if ( $f->{'type'} =~ /^select-?(.*)/ ) {
113 # try to display this in a user-friendly manner
114 if ( $f->{'table'} ) { # find matching records
115 $f->{'value_col'} ||=
116 dbdef->table($f->{'table'})->primary_key;
118 my @values = split(',', $f->{'value'});
121 push @recs, qsearchs( $f->{'table'},
122 { $f->{'value_col'} => $_ }
126 my $method = $f->{'name_col'};
127 if ( $f->{'multiple'} ) {
128 $f->{'formatted_value'} = [
129 map { $_->method } @recs
131 } else { # there shouldn't be more than one...
132 $f->{'formatted_value'} = $recs[0]->$method;
134 } # if not, then just let tr-fixed display the
137 } # other select types probably don't matter
140 $f->{'type'} = 'fixed';
142 } else { # fixed, null
143 $f->{'type'} = 'hidden';
146 } elsif ( $flag eq 'A' ) { #auto assign from inventory
147 $f->{'type'} = 'hidden';
149 } elsif ( $flag eq 'M' ) { #manually assign from inventory
150 $f->{'type'} = 'select-inventory_item';
151 $f->{'empty_label'} = 'Select inventory item';
152 $f->{'extra_sql'} = 'WHERE ( svcnum IS NULL ' .
153 ($object->svcnum && ' OR svcnum = '.$object->svcnum) .
155 $f->{'classnum'} = $columndef->columnvalue;
156 $f->{'disable_empty'} = $object->svcnum ? 1 : 0;
158 } elsif ( $flag eq 'H' ) { #hardware
159 $f->{'type'} = 'select-hardware_type';
161 'classnum'=>$columndef->columnvalue
164 } elsif ( $flag eq 'S' #selectable choice
165 && $f->{type} !~ /^select-svc/ ) {
166 $f->{type} = 'select';
167 $f->{options} = [ split( /\s*,\s*/,
168 $columndef->columnvalue)
170 } # shouldn't this be enforced for all 'S' fields?
172 if ( $f->{'type'} =~ /^select-svc/ )
174 $f->{'include_opt_callback'} =
175 sub { ( 'pkgnum' => $pkgnum,
176 'svcpart' => $svcpart,
181 if ( $f->{'field'} eq 'custnum' && $pkgnum ) {
182 my $cust_pkg = qsearchs('cust_pkg', {'pkgnum' => $pkgnum});
183 $object->set('custnum', $cust_pkg->custnum);
186 if ( my $cb = $opt{'svc_field_callback'} ) {
187 &{ $cb }( $cgi, $object, $f);
196 my $cust_pkg = qsearchs('cust_pkg', {'pkgnum' => $pkgnum});
197 $cust_main = $cust_pkg->cust_main if $cust_pkg;
199 $html = include( '/elements/small_custview.html',
203 popurl(2). "view/cust_main.cgi"
210 'html_table_bottom' => sub {
213 foreach my $field ($svc_x->virtual_fields) {
214 if ($part_svc->part_svc_column($field)->columnflag ne 'F'){
215 # If the flag is X, it won't even show up
216 # in $svc_acct->virtual_fields.
218 $svc_x->pvf($field)->widget( 'HTML',
220 $svc_x->getfield($field)
227 'html_bottom' => sub {
228 qq!<INPUT TYPE="hidden" NAME="pkgnum" VALUE="$pkgnum">!.
229 qq!<INPUT TYPE="hidden" NAME="svcpart" VALUE="$svcpart">!;
232 %opt #pass through/override params
238 my( $part_svc, $opt ) = @_;
240 $opt->{'name'} ||= $part_svc->svc;
242 my $svcdb = $part_svc->svcdb;
243 require "FS/$svcdb.pm";
245 if ( UNIVERSAL::can("FS::$svcdb", 'table_info') ) {
246 #$opt->{'name'} ||= "FS::$svcdb"->table_info->{'name'};
248 my $fields = "FS::$svcdb"->table_info->{'fields'};
249 $opt->{'fields'} ||= [ grep { $_ ne 'svcnum' } keys %$fields ];
252 map { $_ => ( ref($fields->{$_})
253 ? $fields->{$_}{'label'}
261 #false laziness w/view/svc_Common.html
262 #override default labels with service-definition labels if applicable
263 my $labels = $opt->{labels}; # with -> here
264 foreach my $field ( keys %{ $opt->{labels} } ) {
265 my $col = $part_svc->part_svc_column($field);
266 $labels->{$field} = $col->columnlabel if $col->columnlabel !~ /^\s*$/;
269 if ( $part_svc->has_router ) {
270 # these will be set up as pseudo-fields in the new_ and edit_ callbacks
271 push @{ $opt->{'fields'} }, (
272 { field => 'router_routernum', type => 'hidden' },
273 { field => 'router_routername', type => 'text', size => 32 },
274 # router address block selection
275 # (one-to-one for now)
276 { field => 'router_blocknum',
277 type => 'select-table',
278 table => 'addr_block',
279 hashref => { 'routernum' => '0' },
283 order_by => 'ORDER BY ip_gateway, ip_netmask',
284 empty_label => '(none)',
288 $labels->{router_routername} = 'Attached router name';
289 $labels->{router_blocknum} = 'Attached address block';
298 #my( $svcnum, $pkgnum, $svcpart, $part_svc );
299 my( $pkgnum, $svcpart, $part_svc );
301 #get & untaint pkgnum & svcpart
302 if ( ! $cgi->param('error')
303 && $cgi->param('pkgnum') && $cgi->param('svcpart')
306 $cgi->param('pkgnum') =~ /^(\d+)$/ or die 'unparsable pkgnum';
308 $cgi->param('svcpart') =~ /^(\d+)$/ or die 'unparsable svcpart';
310 #$cgi->delete_all(); #so edit.html treats this correctly as new??