4 1,"CDR import successful",<% $cdr_batch->cdrbatchnum %>,"<% $cdrbatch %>"
9 unless $FS::CurrentUser::CurrentUser->access_right('Import');
17 my $filename = $cgi->param('cdr_file');
18 unless ( $filename ) {
19 $error = "No cdr_file filename";
23 my $fh = $cgi->upload('cdr_file');
24 unless ( defined($fh) ) {
25 $error = 'No cdr_file file';
29 #i should probably be transactionalized.
31 my $csv = new Text::CSV_XS or die Text::CSV->error_diag;
33 $cdrbatch = time2str('post-%Y/%m/%d-%T'. "-$$-". rand() * 2**32, time);
34 $cdr_batch = new FS::cdr_batch { 'cdrbatch' => $cdrbatch };
35 $error = $cdr_batch->insert and last;
37 chomp(my $hline = scalar(<$fh>));
39 my @header = $csv->fields;
41 #while ( my $row = $csv->getline($fh) ) {
45 my @row = $csv->fields;
47 my $cdr = new FS::cdr { 'cdrbatchnum' => $cdr_batch->cdrbatchnum };
48 $cdr->set( lc($_) => shift(@row) ) foreach @header;
50 $error = $cdr->insert and last;
56 $error =~ s/"/""/g; #CSV