import customer from Excel file too
[freeside.git] / httemplate / misc / process / cust_main-import.cgi
1 % if ( $error ) {
2 %   errorpage($error);
3 %  } else {
4     <% include('/elements/header.html','Import successful') %> 
5     <% include('/elements/footer.html') %> 
6 %  }
7 <%init>
8
9 die "access denied"
10   unless $FS::CurrentUser::CurrentUser->access_right('Import');
11
12 my $fh = $cgi->upload('file');
13 my $error = '';
14 if ( defined($fh) ) {
15
16   my $type;
17   if ( $cgi->param('file') =~ /\.(\w+)$/i ) {
18     $type = lc($1);
19   } else {
20     #or error out???
21     warn "can't parse file type from filename ". $cgi->param('file').
22          '; defaulting to CSV';
23     $type = 'csv';
24   }
25
26   $error =
27     FS::cust_main::batch_import( {
28       filehandle => $fh,
29       type       => $type,
30       agentnum   => scalar($cgi->param('agentnum')),
31       refnum     => scalar($cgi->param('refnum')),
32       pkgpart    => scalar($cgi->param('pkgpart')),
33       #'fields'    => [qw( cust_pkg.setup dayphone first last address1 address2
34       #                    city state zip comments                          )],
35       'format'   => scalar($cgi->param('format')),
36     } );
37
38 } else {
39   $error = 'No file';
40 }
41
42 </%init>