209419f0b029fe6da101fe8f44ce3ed5c31225da
[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 </%init>