[freeside-commits] freeside/httemplate/misc file-upload.html, NONE, 1.1 tax-import.cgi, 1.2, 1.3
Jeff Finucane,420,,
jeff at wavetail.420.am
Tue Apr 15 13:48:00 PDT 2008
Update of /home/cvs/cvsroot/freeside/httemplate/misc
In directory wavetail.420.am:/tmp/cvs-serv11472/httemplate/misc
Modified Files:
tax-import.cgi
Added Files:
file-upload.html
Log Message:
(finally) wrap up new tax rate engine (for now)
Index: tax-import.cgi
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/misc/tax-import.cgi,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- tax-import.cgi 9 Apr 2008 21:54:30 -0000 1.2
+++ tax-import.cgi 15 Apr 2008 20:47:58 -0000 1.3
@@ -3,41 +3,63 @@
Import a CSV file set containing tax rate records.
<BR><BR>
-<FORM ACTION="process/tax-import.cgi" METHOD="post" ENCTYPE="multipart/form-data">
+<% include( '/elements/progress-init.html',
+ 'TaxRateUpload',
+ [ 'format', 'uploaded_files' ],
+ 'process/tax-import.cgi',
+ { 'message' => 'Tax rates imported' },
+ )
+%>
-<% &ntable("#cccccc", 2) %>
+<SCRIPT>
+
+ function gotLoaded(success, message) {
+ var uploaded = document.getElementById('uploaded_files');
+ var a = uploaded.value.split(',');
+ if (uploaded.value.split(',').length == 4){
+ process();
+ }else{
+ var p = document.getElementById('uploadError');
+ p.innerHTML='<FONT SIZE="+1" COLOR="#ff0000">Error: '+message+'</FONT><BR><BR>';
+ p.style='display:visible';
+ return false;
+ }
+
+ }
+
+</SCRIPT>
+
+<div style="display:none:" id="uploadError"></div>
+<FORM NAME="TaxRateUpload" ACTION="<% $fsurl %>misc/file-upload.html" METHOD="post" ENCTYPE="multipart/form-data" onsubmit="return doUpload(this, gotLoaded )">
+
+<% &ntable("#cccccc", 2) %>
<TR>
<TH ALIGN="right">Format</TH>
<TD>
<SELECT NAME="format">
- <OPTION VALUE="cch" SELECTED>CCH
+ <OPTION VALUE="cch-update" SELECTED>CCH update
+ <OPTION VALUE="cch">CCH initial import
</SELECT>
</TD>
</TR>
-<TR>
- <TH ALIGN="right">code CSV filename</TH>
- <TD><INPUT TYPE="file" NAME="codefile"></TD>
-</TR>
-
-<TR>
- <TH ALIGN="right">plus4 CSV filename</TH>
- <TD><INPUT TYPE="file" NAME="plus4file"></TD>
-</TR>
-
-<TR>
- <TH ALIGN="right">txmatrix CSV filename</TH>
- <TD><INPUT TYPE="file" NAME="txmatrix"></TD>
-</TR>
-
-<TR>
- <TH ALIGN="right">detail CSV filename</TH>
- <TD><INPUT TYPE="file" NAME="detail"></TD>
-</TR>
-
+<% include('/elements/file-upload.html', 'field' => [ 'codefile',
+ 'plus4file',
+ 'txmatrix',
+ 'detail',
+ ],
+ 'label' => [ 'code CSV filename',
+ 'plus4 CSV filename',
+ 'txmatrix CSV filename',
+ 'detail CSV filename',
+ ],
+ 'callback' => 'gotLoaded',
+ 'debug' => 0,
+ )
+%>
-<TR><TD COLSPAN=2 ALIGN="center" STYLE="padding-top:6px"><INPUT TYPE="submit" VALUE="Import CSV files"></TD></TR>
+<TR><TD COLSPAN=2 ALIGN="center" STYLE="padding-top:6px"><INPUT TYPE="submit" VALUE="Import CSV files" onClick="document.TaxRateUpload.submit.disabled=true;"></TD></TR>
</TABLE>
--- NEW FILE: file-upload.html ---
<% include('/elements/header-minimal.html', 'File Upload') %>
% if ($error) {
Error: <% $error %>
% }else{
Freeside 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::conf_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 $sh = new File::Temp( TEMPLATE => 'upload.XXXXXXXX',
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>
More information about the freeside-commits
mailing list