[if session arg]
[value name="mvc_data_table" set="[data session arg]" scratch=1 hide=1]
[value name="mv_data_table" set="[value mvc_data_table]" hide=1]
[/if]
[if-mm !tables]
[bounce href="[area config/violation]"]
[/if-mm]
[calc] $Config->{NoSearch} = ''; [/calc]
[perl]
$Scratch->{relocate} = '';
return unless $CGI->{row_change};
$CGI->{row_change} =~ /^(insert|append|delete)(\d+)$/
or return;
$function = $1;
$row = $2;
%saved = %$CGI;
for(keys %saved) {
push @del, $_ unless length($saved{$_});
}
for(@del) {
delete $saved{$_};
}
@del = ();
my @change;
my %ignore = qw/
break
sort_order
sort_option
/;
my $key;
my $max = 0;
foreach $key (keys %saved) {
next unless $key =~ /^(\w+\D)(\d+)$/;
my $nm = $1;
my $idx = $2;
next if $ignore{$nm};
$max = $idx if $idx > $max and $key eq "table$idx";
if($function eq 'append') {
next if $idx <= $row;
}
else {
next if $idx < $row;
}
push @change, [$key, $saved{$key}];
push @del, $key;
}
for(@del) {
delete $saved{$_};
}
if($function eq 'insert' or $function eq 'append') {
$max++;
for(@change) {
my ($k, $v) = @{$_};
$k =~ s/(\d+)$/$1 + 1/e;
$saved{$k} = $v;
}
$Scratch->{relocate} = 'config/report';
}
elsif($function eq 'delete') {
$max--;
for(@change) {
my ($k, $v) = @{$_};
$k =~ /(\d+)/;
my $idx = $1;
next if $idx == $row;
$k =~ s/(\d+)$/$1 - 1/e;
$saved{$k} = $v;
}
$Scratch->{relocate} = 'config/report';
}
else {
$Scratch->{relocate} = 'special/failed';
}
$saved{num_columns} = $max > 1 ? $max + 1 : 3;
$Values->{saved_report} = \%saved;
return;
[/perl]
[if scratch relocate]
[bounce href="[area href=`$Scratch->{relocate}`]"]
[/if]
[seti name=tables][list-databases][/seti]
[perl table="[scratch tables]"]
$vals = {};
my $current_table = $Values->{mv_data_table} = $CGI->{report_table};
%saved = %$CGI;
for(keys %saved) {
push @del, $_ unless length($saved{$_});
}
for(@del) {
delete $saved{$_};
}
unless ($current_table) {
$Scratch->{search_string} = "";
$Scratch->{search_page} = "NO CURRENT TABLE |
";
return;
}
for( keys %{$CGI} ) {
next unless /^([A-Za-z_]+)(\d+)$/;
my $item = $1;
my $idx = $2;
$vals->{$item} = []
unless defined $vals->{$item};
$vals->{$item}[$idx] = $CGI->{"$item$idx"};
}
return "No tables/columns selected" unless defined $vals->{table};
if($CGI->{search_field} and $CGI->{search_spec}) {
push @string, "co=1";
push @string, "se=$CGI->{search_spec}";
push @string, "sf=$CGI->{search_field}";
push @string, "op=$CGI->{search_op}";
push @string, "nu=1"
if $CGI->{search_op} =~ /\W/;
}
else {
push @string, "ra=yes";
}
push @string, "st=db";
push @string, "fi=$current_table";
if ($CGI->{matchlimit}) {
push @string, "ml=$CGI->{matchlimit}";
my $page = $CGI->{report_title};
$page =~ s/%/%37/g;
push @string, "sp=config/reports/$page";
}
else {
push @string, "ml=999999";
}
if($vals->{sort_order}) {
for(my $i = 0; $i < scalar @{$vals->{sort_order}}; $i++) {
my $f = $vals->{sort_order}[$i];
last unless $f;
push @string, "tf=$f";
push @string, "to=" . $vals->{sort_option}[$i];
if($vals->{break}[$i]) {
unshift(@breaks, $f);
$hfoot_change{$f} = qq{\n[item-change $i][condition]};
$hfoot_change{$f} .= qq{[item-data $current_table $f]};
$hfoot_change{$f} .= qq{[/condition]\n};
$foot_change{$f} = qq{\n};
$efoot_change{$f} = "[/item-change $i]\n";
}
}
}
my $header = "
\n";
my $page = '';
my $summary_found;
$page .= "
\n" unless $summary_only;
my $end_line = '';
my $total_line = "
\n";
my $count = 0;
for (my $i = 0; $i < 10; $i++) {
last if ! $vals->{table}[$i];
$count++;
}
$saved{num_columns} = $count;
$Values->{saved_report} = \%saved;
for (my $i = 0; $i < $count; $i++) {
my $t = $vals->{table}[$i] or last;
my $c = $vals->{column}[$i];
my $k = $vals->{key}[$i];
my $h = $vals->{heading}[$i] || $c;
my $s = $vals->{summary}[$i];
my $r = $vals->{filter}[$i];
my $e = $vals->{edit}[$i];
my $ek = $vals->{editkey}[$i] || '';
if($r) {
$r =~ s/'/\\'/g;
$r =~ s/[\0 ]+/' '/g if $r;
$r = "'$r'";
}
my $l = "ALIGN=$vals->{align}[$i]";
$header .= "\t$h | \n";
my $data;
if($k) {
$data = "[data table=$t column=$c key='[item-data $current_table $k]']";
}
else {
$data = "[item-data $t $c]";
}
if($e) {
$ek = $ek ? "[item-data $t $ek]" : $data;
}
unless($summary_only) {
$page .= "\t";
$page .= qq{[page href="config/edit_record"
form="
mv_action=return
mv_data_table=$e
mv_arg=$ek
"]} if $e;
$page .= qq{[filter op=|$r| interpolate=1]} if $r;
$page .= $data;
$page .= "[/filter]" if $r;
$page .= qq{} if $e;
}
$total_line .= "\t | ";
$total_line .= "TOTAL" unless $i;
for (@breaks) {
$foot_change{$_} .= "\t | ";
if($_ eq $c) {
$foot_change{$_} .= "[if scratch first_done_$c] [value prev_data_$c] [/if]";
}
elsif($s) {
$foot_change{$_} .= qq{[if scratch first_done_$_]};
$foot_change{$_} .= qq{ };
$foot_change{$_} .= qq{[filter op=|$r| interpolate=1]} if $r;
$foot_change{$_} .= qq{[summary name=subtotal.$t.$c.$_ total=1]};
$foot_change{$_} .= qq{[summary name=subtotal.$t.$c.$_ reset=1]};
$foot_change{$_} .= qq{[/filter]} if $r;
$foot_change{$_} .= qq{ [/if]};
}
$foot_change{$_} .= " | \n";
}
if($s) {
$summary_found = 1;
$page .= qq{[summary name=total.$t.$c hide=1 amount="$data"]};
for(@breaks) {
$page .= qq{[summary name=subtotal.$t.$c.$_ hide=1 amount="$data"]}
}
$total_line .= qq{};
$total_line .= qq{[filter op=|$r| interpolate=1]} if $r;
$total_line .= qq{[summary name=total.$t.$c total=1]\n};
$total_line .= qq{[/filter]} if $r;
$total_line .= qq{};
}
$total_line .= "\n";
$page .= "\n" unless $summary_only;
}
$page .= "
\n" unless $summary_only;
$header .= "\n";
$total_line .= "\n";
$Scratch->{search_string} = join "\n\t\t", '', @string, '';
$Scratch->{search_page} = scalar(@breaks) ? '' : $header;
for (reverse @breaks) {
$Scratch->{search_page} .= "[set first_done_$_][/set]\n";
$foot_change{$_} .= "";
$efoot_change{$_} = "\n$header\n$efoot_change{$_}\n";
$header = '';
}
$Scratch->{search_page} .= "[search-list]\n";
for (@breaks) {
$Scratch->{search_page} .= $hfoot_change{$_};
$Scratch->{search_page} .= $foot_change{$_};
$Scratch->{search_page} .= $efoot_change{$_};
$Scratch->{search_page} .= "\n[set first_done_$_]1[/set]\n";
}
$Scratch->{search_page} .= $page;
for (@breaks) {
$Scratch->{search_page} .= qq{[value name=prev_data_$_ hide=1 set=|};
$Scratch->{search_page} .= qq{[item-data $current_table $_]};
$Scratch->{search_page} .= qq{|]};
}
$Scratch->{search_page} .= "\n[/search-list]\n";
for (@breaks) {
$Scratch->{search_page} .= $foot_change{$_};
}
$Scratch->{search_page} .= $total_line if $summary_found;
if($CGI->{matchlimit}) {
$Scratch->{search_page} .= "
|
";
$count--;
$Scratch->{search_page} .= <
More |
[more] |
[/more-list]
EOF
}
return;
[/perl]
[L]Table[/L] [page href="config/dbedit" arg="[value mv_data_table]"][value mv_data_table]
[comment]
string: [scratch search_string]
page: [scratch search_page]
[/comment]
[title-bar size=2][page index]__COMPANY__[/page][/title-bar]
[title-bar][L]Table[/L] [value mv_data_table] [/title-bar]
[if cgi generate_page]
[set write_report]
success=[perl]
my $data = $CGI->{page};
$data =~ s/[/[/g;
$data =~ s/\r//g;
my $page = $CGI->{report_name};
return 0 unless ($page and $data);
$CGI->{definition} =~ s/\r//g;
$def = '[';
$def .= <{saved_report} = $CGI->{definition};
return;
EOF
$def .= '[';
$def .= '/perl]';
$def .= "[bounce href='[area config/report]']\n";
$page =~ s/([^-\w.])/sprintf '%%%02x', ord($1)/ge;
$Values->{tried_page} = $page;
$Values->{tried_data} = $data;
Log("tried $page");
$status = $Tag->write_relative_file("pages/config/report_def/$page.html", $def);
$status &&= $Tag->write_relative_file("pages/config/reports/$page.html", $data);
delete $CGI->{page};
delete $CGI->{def};
return $status;
[/perl]
[/set]
[else]
[cgi report_title]
[search-region search="[scratch search_string]" interpolate=1]
[scratch search_page]
[/search-region]
[/else]
[/if]
[set search_page][/set]
[set search_string][/set]