From 6addb511875324241cb002b2fe96225c066d0ddc Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 11 Dec 2002 00:12:22 +0000 Subject: [PATCH] beginning of web-based data importer --- httemplate/misc/meta-import.cgi | 52 ++++++++++++ httemplate/misc/process/meta-import.cgi | 145 ++++++++++++++++++++++++++++++++ 2 files changed, 197 insertions(+) create mode 100644 httemplate/misc/meta-import.cgi create mode 100644 httemplate/misc/process/meta-import.cgi diff --git a/httemplate/misc/meta-import.cgi b/httemplate/misc/meta-import.cgi new file mode 100644 index 000000000..ebd2a7e2f --- /dev/null +++ b/httemplate/misc/meta-import.cgi @@ -0,0 +1,52 @@ + +<%= header('Import') %> +
+Import a CSV file containing customer records (zip tar etc).

+ +##no##Default file format is CSV, with the following field order: cust_pkg.setup, dayphone, first, last, address1, address2, city, state, zip, comments

+ +<% + #false laziness with edit/cust_main.cgi + my @agents = qsearch( 'agent', {} ); + die "No agents created!" unless @agents; + my $agentnum = $agents[0]->agentnum; #default to first + + if ( scalar(@agents) == 1 ) { +%> + +<% } else { %> +

Agent

+<% } %> + +<% + my @referrals = qsearch('part_referral',{}); + die "No advertising sources created!" unless @referrals; + my $refnum = $referrals[0]->refnum; #default to first + + if ( scalar(@referrals) == 1 ) { +%> + +<% } else { %> +

Advertising source

+<% } %> + + First package:

+ + CSV (zip, tar etc) Filename:

+ +
+ + + diff --git a/httemplate/misc/process/meta-import.cgi b/httemplate/misc/process/meta-import.cgi new file mode 100644 index 000000000..d42d6d466 --- /dev/null +++ b/httemplate/misc/process/meta-import.cgi @@ -0,0 +1,145 @@ + +<%= header('Map tables') %> + +<% + #one + unless ( $cgi->param('magic') ) { + + #oops, silly + #my $fh = $cgi->upload('csvfile'); + ##warn $cgi; + ##warn $fh; + # + #use Archive::Tar; + #$tar = Archive::Tar->new(); + #$tar->create_archive($fh); #or die $tar->error; + + #haha for now + my @files = qw( +authserv credtype dunprev invoice pmtdet product taxplan +ccdet customer genlog ledger pops pubvars +cchist discplan glacct origco prodcat recur users +credcode dundet invline payment prodclas repforms webserv + ); + + %> +
+ + <%= hashmaker('schema', \@files, [ grep { ! /^h_/ } dbdef->tables ] ) %> +
+
+ + + <% + + } elsif ( $cgi->param('magic') eq 'process' ) { + + %> +
+ + <% + + my $schema_string = $cgi->param('schema'); + my %schema = map { /^\s*(\w+)\s*=>\s*(\w+)\s*$/ + or die "guru meditation #420: $_"; + ( $1 => $2 ); + } + split( /\n/, $schema_string ); + + #*** should be in global.asa/handler.pl like the rest + eval 'use Text::CSV_XS;'; + + foreach my $table ( keys %schema ) { + + my $csv = Text::CSV_XS->new({ 'binary'=>1 }); + open(FILE,"); + close FILE; + $csv->parse($header) or die; + my @from_columns = $csv->fields; + + my @fs_columns = dbdef->table($schema{$table})->columns; + + %> + <%= hashmaker($table, \@from_columns, \@fs_columns, $table, $schema{$table} ) %> +


+ <% + + } + + %> +
+
+ + + <% + + } elsif ( $cgi->param('magic') eq 'process' ) { + + %> + print results!! + <% + } + + #hashmaker widget + sub hashmaker { + my($name, $from, $to, $labelfrom, $labelto) = @_; + $fromsize = scalar(@$from); + $tosize = scalar(@$to); + "'. + '
$labelfrom$labelto
". + qq!\n". + ''. + qq!\n". + '
'. + qq!!. + '
'. + qq!!. + '
'. + "". + ''; + } + +%> -- 2.11.0