X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fmisc%2Fprocess%2Fmeta-import.cgi;h=68ae49c60c642a6597b6319fc41b80bab4bb5aaa;hb=833cfe5c9938d33c3e6b97ed610c25a7afa6eb04;hp=4c3c7d665e6c706f8bc924f703ed626408919139;hpb=64d21fc13eddf275f614f54ff9e17eca74dcd858;p=freeside.git diff --git a/httemplate/misc/process/meta-import.cgi b/httemplate/misc/process/meta-import.cgi index 4c3c7d665..68ae49c60 100644 --- a/httemplate/misc/process/meta-import.cgi +++ b/httemplate/misc/process/meta-import.cgi @@ -1,5 +1,5 @@ - -<%= header('Map tables') %> +<% include("/elements/header.html",'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; + +% +% #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; +% use Tie::DxHash; +% tie %schema, 'Tie::DxHash'; +% 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') ) { - #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 ] ) %> + <% hashmaker('schema', [ $schema->tables ], + [ grep !/^h_/, dbdef->tables ], ) %>
- <% +% +% +% #second page +% } elsif ( $cgi->param('magic') eq 'process' ) { - } 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} ) %> +% +% +% my %unique; +% foreach my $table ( keys %schema ) { +% +% my @from_columns = $schema->table($table)->columns; +% my @fs_columns = dbdef->table($schema{$table})->columns; +% +% + + <% hashmaker( $table.'__'.$unique{$table}++, + \@from_columns => \@fs_columns, + $table => $schema{$table}, ) %>


- <% - - } +% +% +% } +% +% - %>
- <% - - } 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".
-            #(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";
+%
+%
+%  #third (results)
+%  } elsif ( $cgi->param('magic') eq 'process2' ) {
+%
+%    print "
\n";
+%
+%    my %unique;
+%    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.'__'.$unique{$table}++) );
+%      foreach ( keys %map ) {
+%        print "$spaces                     '$_' => '$map{$_}',\n";
+%      }
+%      print "$spaces                   },\n";
+%      print "$spaces      },\n";
+%
+%    }
+%    print "\n
"; +% +% } else { +% warn "unrecognized magic: ". $cgi->param('magic'); +% } +% +% - } - print "\n
"; - - } else { - warn "unrecognized magic: ". $cgi->param('magic'); - } - - %>
- - <% - #hashmaker widget - sub hashmaker { - my($name, $from, $to, $labelfrom, $labelto) = @_; - $fromsize = scalar(@$from); - $tosize = scalar(@$to); - "'. - '
$labelfrom$labelto
". - qq!\n". - ''. - qq!\n". - '
'. - qq!!. - '
'. - qq!!. - '
'. - "". - ''; - } - -%> +% +% #hashmaker widget +% sub hashmaker { +% my($name, $from, $to, $labelfrom, $labelto) = @_; +% my $fromsize = scalar(@$from); +% my $tosize = scalar(@$to); +% "'. +% '
$labelfrom$labelto
". +% qq!\n
". +% qq!!. +% '
'. +% qq!\n
". +% qq!!. +% '
'. +% qq!!. +% '
'. +% qq!!. +% '
'. +% "". +% ''; +% } +% +% +<%init> + +#there's no ACL for this... haven't used in ages +#make XSS-safe if this is used for more than just admins to import data.... +die 'meta-import not enabled; remove this if you want to use it'; + +