<%doc> Display a text version of information, easy to select and copy. Formats accepted: js, csv, csv2 % % % <%args> $object => undef $total => undef $sid => undef $osid => undef $format => "js"; % <%attr> title => 'View' % <%init> my $js = 0; my $csv = 0; my $csv2 = 0; my @orderbrief; my $session; my $osession; my %objindex; my $table; my $page; my $content; $m->clear_buffer; if ($format eq "js") { $js = 1; } elsif ($format eq "csv") { $csv = 1; } elsif ($format eq "csv2") { $csv2 = 1; } if ($csv && $osid) { $osession = $ui->get_session($osid); $object = $osession->{object}; } if ($csv && $sid) { $session = $ui->get_session($sid); %objindex = %{ $session->{objindex} }; $table = $session->{table}; @orderbrief = @{ $session->{orderbrief} }; $total = $session->{total}; } if ($csv2 && $sid) { $session = $ui->get_session($sid); # %objindex = %{ $session->{objindex} }; # $table = $session->{table}; @orderbrief = @{ $session->{orderbrief} }; # $total = $session->{total}; $page = $session->{page}; } % $m->clear_buffer; % #csv format % if ($csv) { % my @outlist; % my $outstring; % #headers % foreach my $c (@orderbrief) { % my $tag = $table->meta_data->get_column($c)->tag; % if( defined($tag) ) { % $outstring = $tag; % }else{ % $outstring = $c; % } % $outstring =~ s/,/ /g; % $outstring =~ s/"/'/g; % push(@outlist, $outstring); % } % print join(',',@outlist); % @outlist = ();
% #data % my $pos = 0; % while ($pos < $total) { % my $o = $objindex{$pos}; % $pos++; % foreach my $c ( @orderbrief ) { % my $ftable = $table->meta_data->get_column($c)->links_to; % if (defined $ftable) { % if (int(my $fo = $o->$c) != 0 ) { % $outstring = $fo->get_label; #$lbl % }else{ % $outstring = ""; % } % }else{ % $outstring = $o->$c; % } % $outstring =~ s/,/ /g; % $outstring =~ s/"/'/g; % push(@outlist, $outstring); % } % print join(',',@outlist); % @outlist = ();
% } % } % #csv2 format: pass @orderbrief for headers and $page for cell_data % #without using other variables, such as $table, $objindex, $total. % if ( $csv2 ){ % my @outlist; % my $outstring; % #headers % foreach my $c ( @orderbrief ) { % $outstring = $c; % $outstring =~ s/,/ /g; % $outstring =~ s/"/'/g; % push( @outlist, $outstring ); % } % print join( ',' , @outlist ); % @outlist = ();
% #data % foreach my $c (@$page){ % foreach my $cc (@$c) { % $outstring = $cc; % $outstring =~ s/,/ /g; % $outstring =~ s/"/'/g; % push(@outlist,$outstring); % } % print join(',',@outlist); % @outlist = ();
% } % } % if($js){ % } % $m->abort;