diff options
Diffstat (limited to 'httemplate/misc')
-rw-r--r-- | httemplate/misc/cust_main-import.cgi | 67 | ||||
-rw-r--r-- | httemplate/misc/file-upload.html | 10 | ||||
-rw-r--r-- | httemplate/misc/process/cust_main-import.cgi | 37 |
3 files changed, 55 insertions, 59 deletions
diff --git a/httemplate/misc/cust_main-import.cgi b/httemplate/misc/cust_main-import.cgi index 8e170c3c6..bbeaa5187 100644 --- a/httemplate/misc/cust_main-import.cgi +++ b/httemplate/misc/cust_main-import.cgi @@ -3,32 +3,45 @@ 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', - #'curr_value' => '', #$agentnum, - 'label' => "<B>Agent</B>", - 'empty_label' => 'Select agent', - ) -%> + <% include( '/elements/tr-select-agent.html', + #'curr_value' => '', #$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') % @@ -49,7 +62,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> @@ -109,4 +130,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 index 9649d3663..469274c69 100644 --- a/httemplate/misc/file-upload.html +++ b/httemplate/misc/file-upload.html @@ -2,7 +2,7 @@ % if ($error) { Error: <% $error %> % }else{ -Freeside File Upload Successful <% join(',', @filenames) %>; +File Upload Successful <% join(',', @filenames) %>; % } <% include('/elements/footer.html') %> <%init> @@ -17,7 +17,7 @@ $cgi->param('upload_fields') =~ /^([,\w]+)$/ or $error = "invalid upload_fields"; my $fields = $1; -my $dir = $FS::UID::conf_dir. "/cache.". $FS::UID::datasrc; +my $dir = $FS::UID::cache_dir. "/cache.". $FS::UID::datasrc; foreach my $field (split /,/, $fields) { next if $error; @@ -25,7 +25,13 @@ foreach my $field (split /,/, $fields) { 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, ) 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> |