<%= 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 '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";

    }
    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!!. '
'. "". ''; } %>