summaryrefslogtreecommitdiff
path: root/httemplate
diff options
context:
space:
mode:
authorivan <ivan>2010-06-08 08:24:46 +0000
committerivan <ivan>2010-06-08 08:24:46 +0000
commit3d0320979331ac4b68fc07fd4203d74c1b05aff4 (patch)
tree37b25bdce4d8666a015e97283aa03cc32c078eda /httemplate
parent964843e86eba1171f3e946f021ac450348852e3a (diff)
add programmatic CDR posting, RT#8201
Diffstat (limited to 'httemplate')
-rw-r--r--httemplate/misc/cdr-post.cgi55
-rw-r--r--httemplate/misc/cdr-post.html11
2 files changed, 66 insertions, 0 deletions
diff --git a/httemplate/misc/cdr-post.cgi b/httemplate/misc/cdr-post.cgi
new file mode 100644
index 000000000..d9e42fa99
--- /dev/null
+++ b/httemplate/misc/cdr-post.cgi
@@ -0,0 +1,55 @@
+% if ( $error ) {
+0,"<% $error %>",,
+% } else {
+1,"CDR import successful',<% $cdr_batch->cdrbatchnum %>,"<% $cdrbatch %>"
+% }
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Import');
+
+my $error = '';
+my $cdr_batch;
+
+{
+
+ my $filename = $cgi->param('cdr_file');
+ unless ( $filename ) {
+ $error = "No cdr_file filename";
+ last;
+ }
+
+ my $fh = $cgi->upload('cdr_file');
+ unless ( defined($fh) ) {
+ $error = 'No cdr_file file';
+ last;
+ }
+
+ #i should probably be transactionalized.
+
+ my $csv = new Text::CSV_XS or die Text::CSV->error_diag;
+
+ my $cdrbatch = time2str('post-%Y/%m/%d-%T'. "-$$-". rand() * 2**32, time);
+ $cdr_batch = new FS::cdr_batch { 'cdrbatch' => $cdrbatch };
+ $error = $cdr_batch->insert and last;
+
+ chomp(my $hline = scalar(<$fh>));
+ $csv->parse($hline);
+ my @header = $csv->fields;
+
+ #while ( my $row = $csv->getline($fh) ) {
+ while (<$fh>) {
+
+ $csv->parse($_);
+ my @row = $csv->fields;
+
+ my $cdr = new FS::cdr { 'cdrbatchnum' => $cdr_batch->cdrbatchnum };
+ $cdr->set( lc($_) => shift(@row) ) foreach @header;
+
+ $error = $cdr->insert and last;
+
+ }
+
+}
+
+</%init>
diff --git a/httemplate/misc/cdr-post.html b/httemplate/misc/cdr-post.html
new file mode 100644
index 000000000..5d34272f7
--- /dev/null
+++ b/httemplate/misc/cdr-post.html
@@ -0,0 +1,11 @@
+<% include("/elements/header.html",'Call Detail Record - POST Import') %>
+
+<FORM METHOD="POST" ACTION="cdr-post.cgi" enctype="multipart/form-data">
+
+ cdr_file: <INPUT TYPE="file" NAME="cdr_file"><BR><BR>
+
+ <INPUT TYPE="submit" VALUE="upload">
+
+</FORM>
+
+<% include("/elements/footer.html") %>