21150ef6750770bab92aa3b7cc6f427fafb7f684
[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 my $error;
32 if ( $exportnum ) {
33   #warn $old;
34   #warn $exportnum;
35   #warn $new->machine;
36   $error = $new->replace($old,\%options);
37 } else {
38   $error = $new->insert(\%options);
39 #  $exportnum = $new->exportnum;
40 }
41
42 my $info = FS::part_export::export_info()->{$new->exporttype};
43 if ( $info->{nas} ) {
44   my @nasnums = map { /^nasnum(\d+)$/ ? $1 : () } keys %{ $cgi->Vars };
45   $error ||= $new->process_m2m(
46     link_table    => 'export_nas',
47     target_table  => 'nas',
48     params        => \@nasnums
49   );
50 }
51
52 </%init>