From 6addb511875324241cb002b2fe96225c066d0ddc Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 11 Dec 2002 00:12:22 +0000 Subject: beginning of web-based data importer --- httemplate/misc/process/meta-import.cgi | 145 ++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 httemplate/misc/process/meta-import.cgi (limited to 'httemplate/misc/process/meta-import.cgi') 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!!. + '
'. + "". + ''; + } + +%> -- cgit v1.2.1 From 64d21fc13eddf275f614f54ff9e17eca74dcd858 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 13 Dec 2002 00:31:32 +0000 Subject: taxclass fix (?) --- httemplate/misc/process/meta-import.cgi | 50 +++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 12 deletions(-) (limited to 'httemplate/misc/process/meta-import.cgi') diff --git a/httemplate/misc/process/meta-import.cgi b/httemplate/misc/process/meta-import.cgi index d42d6d466..4c3c7d665 100644 --- a/httemplate/misc/process/meta-import.cgi +++ b/httemplate/misc/process/meta-import.cgi @@ -19,6 +19,7 @@ function SafeOnsubmit() { gSafeOnsubmit[i](); } +
<% #one unless ( $cgi->param('magic') ) { @@ -41,23 +42,19 @@ 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 ); @@ -88,18 +85,47 @@ credcode dundet invline payment prodclas repforms webserv %>
-
- - <% - } elsif ( $cgi->param('magic') eq 'process' ) { + } elsif ( $cgi->param('magic') eq 'process2' ) { - %> - print results!! - <% + print "
\n";
+    #false laziness with above
+    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 );
+    foreach my $table ( keys %schema ) {
+      ( my $spaces = $table ) =~ s/./ /g;
+      print "'$table' => { 'table' => '$schema{$table}',\n".
+            #(length($table) x ' '). "         'map'   => {\n";
+            "$spaces        'map'   => {\n";
+      my %map = map { /^\s*(\w+)\s*=>\s*(\w+)\s*$/
+                         or die "guru meditation #420: $_";
+                       ( $1 => $2 );
+                     }
+                 split( /\n/, $cgi->param($table) );
+      foreach ( keys %map ) {
+        print "$spaces                     '$_' => '$map{$_}',\n";
+      }
+      print "$spaces                   },\n";
+      print "$spaces      },\n";
+
+    }
+    print "\n
"; + + } else { + warn "unrecognized magic: ". $cgi->param('magic'); } + %> + + + + + <% #hashmaker widget sub hashmaker { my($name, $from, $to, $labelfrom, $labelto) = @_; -- cgit v1.2.1 From c174642d32c139d1233597e3fa6a467586207023 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 11 Mar 2003 11:36:51 +0000 Subject: minor meta import webUI updates --- httemplate/misc/process/meta-import.cgi | 82 +++++++++++++-------------------- 1 file changed, 32 insertions(+), 50 deletions(-) (limited to 'httemplate/misc/process/meta-import.cgi') diff --git a/httemplate/misc/process/meta-import.cgi b/httemplate/misc/process/meta-import.cgi index 4c3c7d665..9e374b508 100644 --- a/httemplate/misc/process/meta-import.cgi +++ b/httemplate/misc/process/meta-import.cgi @@ -1,5 +1,6 @@ <%= 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 - ); + #use DBIx::DBSchema; + my $schema = new_native DBIx::DBSchema + map { $cgi->param($_) } qw( data_source username password ); + foreach my $field (qw( data_source username password )) { %> + VALUE="<%= $cgi->param($field) %>"> + <% } + + my %schema = (); + if ( $cgi->param('schema') ) { + my $schema_string = $cgi->param('schema'); + %> <% + %schema = map { /^\s*(\w+)\s*=>\s*(\w+)\s*$/ + or die "guru meditation #420: $_"; + ( $1 => $2 ); + } + split( /\n/, $schema_string ); + } + + #first page + unless ( $cgi->param('magic') ) { %> - %> - <%= hashmaker('schema', \@files, [ grep { ! /^h_/ } dbdef->tables ] ) %> + <%= hashmaker('schema', [ $schema->tables ], + [ grep !/^h_/, dbdef->tables ], ) %>
<% - } elsif ( $cgi->param('magic') eq 'process' ) { + #second page + } 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 @from_columns = $schema->table($table)->columns; my @fs_columns = dbdef->table($schema{$table})->columns; %> - <%= hashmaker($table, \@from_columns, \@fs_columns, $table, $schema{$table} ) %> + <%= hashmaker($table, \@from_columns => \@fs_columns, + $table => $schema{$table}, ) %>


<% @@ -87,16 +74,11 @@ credcode dundet invline payment prodclas repforms webserv
<% + #third (results) } elsif ( $cgi->param('magic') eq 'process2' ) { print "
\n";
-    #false laziness with above
-    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 );
+
     foreach my $table ( keys %schema ) {
       ( my $spaces = $table ) =~ s/./ /g;
       print "'$table' => { 'table' => '$schema{$table}',\n".
-- 
cgit v1.2.1


From 856a62ca215f921ef3e9ddf4080626565727532a Mon Sep 17 00:00:00 2001
From: ivan 
Date: Wed, 2 Apr 2003 09:46:50 +0000
Subject: updated meta-import web UI to allow duplicate import tables

---
 httemplate/misc/process/meta-import.cgi | 37 +++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)

(limited to 'httemplate/misc/process/meta-import.cgi')

diff --git a/httemplate/misc/process/meta-import.cgi b/httemplate/misc/process/meta-import.cgi
index 9e374b508..2939c8fb2 100644
--- a/httemplate/misc/process/meta-import.cgi
+++ b/httemplate/misc/process/meta-import.cgi
@@ -31,7 +31,9 @@ function SafeOnsubmit() {
      VALUE="<%= $cgi->param($field) %>">
   <% }
 
-  my %schema = ();
+  my %schema;
+  use Tie::DxHash;
+  tie %schema, 'Tie::DxHash';
   if ( $cgi->param('schema') ) {
     my $schema_string = $cgi->param('schema');
     %>  <%
@@ -57,14 +59,16 @@ function SafeOnsubmit() {
     
     <%
 
+    my %unique;
     foreach my $table ( keys %schema ) {
 
       my @from_columns = $schema->table($table)->columns;
       my @fs_columns = dbdef->table($schema{$table})->columns;
 
       %>
-      <%= hashmaker($table, \@from_columns => \@fs_columns,
-                            $table         =>  $schema{$table}, ) %>
+      <%= hashmaker( $table.'__'.$unique{$table}++,
+                     \@from_columns => \@fs_columns,
+                     $table         =>  $schema{$table}, ) %>
       


<% @@ -79,6 +83,7 @@ function SafeOnsubmit() { print "
\n";
 
+    my %unique;
     foreach my $table ( keys %schema ) {
       ( my $spaces = $table ) =~ s/./ /g;
       print "'$table' => { 'table' => '$schema{$table}',\n".
@@ -88,7 +93,7 @@ function SafeOnsubmit() {
                          or die "guru meditation #420: $_";
                        ( $1 => $2 );
                      }
-                 split( /\n/, $cgi->param($table) );
+                 split( /\n/, $cgi->param($table.'__'.$unique{$table}++) );
       foreach ( keys %map ) {
         print "$spaces                     '$_' => '$map{$_}',\n";
       }
@@ -116,11 +121,13 @@ function SafeOnsubmit() {
     "'.
       '
$labelfrom$labelto
". qq!\n". + "\n
". + qq!!. '
'. qq!\n". + "\n
". + qq!!. '
'. qq!!. @@ -146,6 +153,24 @@ function SafeOnsubmit() { object.options[index] = null; return value; } + function repack_${name}_from() { + var object = document.OneTrueForm.${name}_from; + object.options.length = 0; + ". join("\n", + map { "addOption_$name(object, '$_');\n" } + ( sort { $a cmp $b } @$from ) ). " + } + function repack_${name}_to() { + var object = document.OneTrueForm.${name}_to; + object.options.length = 0; + ". join("\n", + map { "addOption_$name(object, '$_');\n" } + ( sort { $a cmp $b } @$to ) ). " + } + function addOption_$name(object,value) { + var length = object.length; + object.options[length] = new Option(value, value, false, false); + } ". ''; } -- cgit v1.2.1 From 066c1665efce43307446207a33f876b0baefe1d6 Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 10 Nov 2003 13:54:21 +0000 Subject: hmm forgot to check this in? --- httemplate/misc/process/meta-import.cgi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'httemplate/misc/process/meta-import.cgi') diff --git a/httemplate/misc/process/meta-import.cgi b/httemplate/misc/process/meta-import.cgi index 2939c8fb2..59d236f64 100644 --- a/httemplate/misc/process/meta-import.cgi +++ b/httemplate/misc/process/meta-import.cgi @@ -116,8 +116,8 @@ function SafeOnsubmit() { #hashmaker widget sub hashmaker { my($name, $from, $to, $labelfrom, $labelto) = @_; - $fromsize = scalar(@$from); - $tosize = scalar(@$to); + my $fromsize = scalar(@$from); + my $tosize = scalar(@$to); "
$labelfrom$labelto
". qq!