export host selection per service, RT#17914
[freeside.git] / httemplate / edit / process / part_export.cgi
1 %if ( $error ) {
2 %  $cgi->param('error', $error );
3 <% $cgi->redirect(popurl(2). "part_export.cgi?". $cgi->query_string ) %>
4 %} else {
5 <% $cgi->redirect(popurl(3). "browse/part_export.cgi") %>
6 %}
7 <%init>
8
9 die "access denied"
10   unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
11
12 my $exportnum = $cgi->param('exportnum');
13
14 my $old = qsearchs('part_export', { 'exportnum'=>$exportnum } ) if $exportnum;
15
16 #fixup options
17 #warn join('-', split(',',$cgi->param('options')));
18 my %options = map {
19   my @values = $cgi->param($_);
20   my $value = scalar(@values) > 1 ? join (' ', @values) : $values[0];
21   $value =~ s/\r\n/\n/g; #browsers? (textarea)
22   $_ => $value;
23 } split(',', $cgi->param('options'));
24
25 my $new = new FS::part_export ( {
26   map {
27     $_, scalar($cgi->param($_));
28   } fields('part_export')
29 } );
30
31 if ( $cgi->param('svc_machine') eq 'Y' ) {
32   $new->machine('_SVC_MACHINE');
33   $new->part_export_machine_textarea( $cgi->param('part_export_machine') );
34 }
35
36 my $error;
37 if ( $exportnum ) {
38   #warn $old;
39   #warn $exportnum;
40   #warn $new->machine;
41   $error = $new->replace($old,\%options);
42 } else {
43   $error = $new->insert(\%options);
44 #  $exportnum = $new->exportnum;
45 }
46
47 my $info = FS::part_export::export_info()->{$new->exporttype};
48 if ( $info->{nas} ) {
49   my @nasnums = map { /^nasnum(\d+)$/ ? $1 : () } keys %{ $cgi->Vars };
50   $error ||= $new->process_m2m(
51     link_table    => 'export_nas',
52     target_table  => 'nas',
53     params        => \@nasnums
54   );
55 }
56
57 </%init>