summaryrefslogtreecommitdiff
path: root/httemplate/misc
diff options
context:
space:
mode:
authorivan <ivan>2008-08-14 11:56:12 +0000
committerivan <ivan>2008-08-14 11:56:12 +0000
commita9d755c3cee7542d3ca552174af0b7b71693ae58 (patch)
tree30554127a48140e35d59aa015bbf3dd3d4f1ab18 /httemplate/misc
parentb4544738ea893d0e2504d36bc1cd3d0bd369b31e (diff)
customer import: add progress bar & redirect to a search of the imported customers, #3475
Diffstat (limited to 'httemplate/misc')
-rw-r--r--httemplate/misc/cust_main-import.cgi65
-rw-r--r--httemplate/misc/file-upload.html53
-rw-r--r--httemplate/misc/process/cust_main-import.cgi37
3 files changed, 99 insertions, 56 deletions
diff --git a/httemplate/misc/cust_main-import.cgi b/httemplate/misc/cust_main-import.cgi
index e1580e5a1..31bf1ee62 100644
--- a/httemplate/misc/cust_main-import.cgi
+++ b/httemplate/misc/cust_main-import.cgi
@@ -3,31 +3,44 @@
Import a file containing customer records.
<BR><BR>
-<FORM ACTION="process/cust_main-import.cgi" METHOD="post" ENCTYPE="multipart/form-data">
+<% include( '/elements/form-file_upload.html',
+ 'name' => 'CustomerImportForm',
+ 'action' => 'process/cust_main-import.cgi',
+ 'num_files' => 1,
+ 'fields' => [ 'agentnum', 'custbatch', 'format' ],
+ 'message' => 'Customer import successful',
+ 'url' => $p."search/cust_main.html?custbatch=$custbatch",
+ )
+%>
<% &ntable("#cccccc", 2) %>
-<% include('/elements/tr-select-agent.html', '', #$agentnum,
- 'label' => "<B>Agent</B>",
- 'empty_label' => 'Select agent',
- )
-%>
+ <% include('/elements/tr-select-agent.html', '', #$agentnum,
+ 'label' => "<B>Agent</B>",
+ 'empty_label' => 'Select agent',
+ )
+ %>
+
+ <INPUT TYPE="hidden" NAME="custbatch" VALUE="<% $custbatch %>"%>
+
+ <TR>
+ <TH ALIGN="right">Format</TH>
+ <TD>
+ <SELECT NAME="format">
+ <!-- <OPTION VALUE="simple">Simple -->
+ <OPTION VALUE="extended" SELECTED>Extended
+ <OPTION VALUE="extended-plus_company">Extended plus company
+ </SELECT>
+ </TD>
+ </TR>
+
+ <% include( '/elements/file-upload.html',
+ 'field' => 'file',
+ 'label' => 'Filename',
+ )
+ %>
-<TR>
- <TH ALIGN="right">Format</TH>
- <TD>
- <SELECT NAME="format">
-<!-- <OPTION VALUE="simple">Simple -->
- <OPTION VALUE="extended" SELECTED>Extended
- <OPTION VALUE="extended-plus_company">Extended plus company
- </SELECT>
- </TD>
-</TR>
-<TR>
- <TH ALIGN="right">Filename</TH>
- <TD><INPUT TYPE="file" NAME="file"></TD>
-</TR>
% #include('/elements/tr-select-part_referral.html')
%
@@ -48,7 +61,15 @@ Import a file containing customer records.
</TR>
-->
-<TR><TD COLSPAN=2 ALIGN="center" STYLE="padding-top:6px"><INPUT TYPE="submit" VALUE="Import file"></TD></TR>
+ <TR>
+ <TD COLSPAN=2 ALIGN="center" STYLE="padding-top:6px">
+ <INPUT TYPE = "submit"
+ ID = "submit"
+ VALUE = "Import file"
+ onClick = "document.CustomerImportForm.submit.disabled=true;"
+ >
+ </TD>
+ </TR>
</TABLE>
@@ -108,4 +129,6 @@ my $req = qq!<font color="#ff0000">*</font>!;
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Import');
+my $custbatch = time2str('webimport-%Y/%m/%d-%T'. "-$$-". rand() * 2**32, time);
+
</%init>
diff --git a/httemplate/misc/file-upload.html b/httemplate/misc/file-upload.html
new file mode 100644
index 000000000..469274c69
--- /dev/null
+++ b/httemplate/misc/file-upload.html
@@ -0,0 +1,53 @@
+<% include('/elements/header-minimal.html', 'File Upload') %>
+% if ($error) {
+Error: <% $error %>
+% }else{
+File Upload Successful <% join(',', @filenames) %>;
+% }
+<% include('/elements/footer.html') %>
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Import'); #?
+
+my @filenames = ();
+my $error = ''; # could be extended to the access control
+
+$cgi->param('upload_fields') =~ /^([,\w]+)$/
+ or $error = "invalid upload_fields";
+my $fields = $1;
+
+my $dir = $FS::UID::cache_dir. "/cache.". $FS::UID::datasrc;
+
+foreach my $field (split /,/, $fields) {
+ next if $error;
+
+ my $fh = $cgi->upload($field)
+ or $error = "No valid file was provided.";
+
+ my $suffix = '';
+ if ( $cgi->param($field) =~ /(\.\w+)$/i ) {
+ $suffix = lc($1);
+ }
+
+ my $sh = new File::Temp( TEMPLATE => 'upload.XXXXXXXX',
+ SUFFIX => $suffix,
+ DIR => $dir,
+ UNLINK => 0,
+ )
+ or $error ||= "can't open temporary file to store upload: $!\n";
+
+ unless ($error) {
+ while(<$fh>) {
+ print $sh $_;
+ }
+ $sh->filename =~ m!.*/([.\w]+)$!;
+ push @filenames, "$field:$1";
+ close $sh
+ }
+
+}
+
+$error = "No files" unless scalar(@filenames);
+
+</%init>
diff --git a/httemplate/misc/process/cust_main-import.cgi b/httemplate/misc/process/cust_main-import.cgi
index 2568d1c7b..df61eb632 100644
--- a/httemplate/misc/process/cust_main-import.cgi
+++ b/httemplate/misc/process/cust_main-import.cgi
@@ -1,42 +1,9 @@
-% if ( $error ) {
-% errorpage($error);
-% } else {
- <% include('/elements/header.html','Import successful') %>
- <% include('/elements/footer.html') %>
-% }
+<% $server->process %>
<%init>
die "access denied"
unless $FS::CurrentUser::CurrentUser->access_right('Import');
-my $fh = $cgi->upload('file');
-my $error = '';
-if ( defined($fh) ) {
-
- my $type;
- if ( $cgi->param('file') =~ /\.(\w+)$/i ) {
- $type = lc($1);
- } else {
- #or error out???
- warn "can't parse file type from filename ". $cgi->param('file').
- '; defaulting to CSV';
- $type = 'csv';
- }
-
- $error =
- FS::cust_main::batch_import( {
- filehandle => $fh,
- type => $type,
- agentnum => scalar($cgi->param('agentnum')),
- refnum => scalar($cgi->param('refnum')),
- pkgpart => scalar($cgi->param('pkgpart')),
- #'fields' => [qw( cust_pkg.setup dayphone first last address1 address2
- # city state zip comments )],
- 'format' => scalar($cgi->param('format')),
- } );
-
-} else {
- $error = 'No file';
-}
+my $server = new FS::UI::Web::JSRPC 'FS::cust_main::process_batch_import', $cgi;
</%init>