From ff606c3eb18ce3a1975c140fce56fad34b220f72 Mon Sep 17 00:00:00 2001 From: Chris Nighswonger Date: Thu, 30 Jul 2009 00:14:58 -0400 Subject: [PATCH] [16/40] Improvements to label management interface code. --- C4/Labels/Lib.pm | 3 ++- labels/label-manage.pl | 55 ++---------------------------------------- 2 files changed, 4 insertions(+), 54 deletions(-) diff --git a/C4/Labels/Lib.pm b/C4/Labels/Lib.pm index ead58fcfeb..f7c2241fe8 100644 --- a/C4/Labels/Lib.pm +++ b/C4/Labels/Lib.pm @@ -460,7 +460,8 @@ sub html_table { elsif ($db_column =~ m/^_((.*)_(.*$))/) { # this a special case my $table_name = get_table_names($2); my $record_set = _SELECT($1, @$table_name[0], $2 . "_id = " . $db_row->{$2 . "_id"}); - $db_row->{$db_column} = $$record_set[0]{$1}; + $$fields[$col_index] = {select_field => 0, field_name => ($db_column . "_tbl"), field_value => $$record_set[0]{$1}}; + $col_index++; next POPULATE_ROW; } elsif ($db_column eq 'select' ) { diff --git a/labels/label-manage.pl b/labels/label-manage.pl index 00e3795b97..9bf270103c 100755 --- a/labels/label-manage.pl +++ b/labels/label-manage.pl @@ -33,7 +33,7 @@ use C4::Output; use C4::Context; use autouse 'C4::Branch' => qw(get_branch_code_from_name); use C4::Debug; -use C4::Labels::Lib 1.000000 qw(get_all_templates get_all_layouts get_all_profiles get_batch_summary get_barcode_types get_label_types get_column_names get_table_names SELECT); +use C4::Labels::Lib 1.000000 qw(get_all_templates get_all_layouts get_all_profiles get_batch_summary html_table); use C4::Labels::Layout 1.000000; use C4::Labels::Template 1.000000; use C4::Labels::Profile 1.000000; @@ -83,57 +83,6 @@ my $op = $cgi->param('op') || $ARGV[1] || ''; my $element_id = $cgi->param('element_id') || $ARGV[2] || ''; my $branch_code = ($label_element eq 'batch' ? get_branch_code_from_name($template->param('LoginBranchname')) : ''); -sub _build_table { - my $headers = shift; - my $data = shift; - my $table = []; - my $fields = []; - my @db_columns = (); - my ($row_index, $col_index) = (0,0); - my $cols = 0; # number of columns to wrap on - my $field_count = 0; - POPULATE_HEADER: - foreach my $db_column (@$headers) { - my @key = keys %$db_column; - push (@db_columns, $key[0]); - $$fields[$col_index] = {select_field => 0, field_name => ($key[0]), field_label => $db_column->{$key[0]}}; - $field_count++; - $col_index++; - } - $$table[$row_index] = {header_fields => $fields}; - $cols = $col_index; - $field_count *= scalar(@$data); # total fields to be displayed in the table - $col_index = 0; - $row_index++; - $fields = []; - POPULATE_TABLE: - foreach my $db_row (@$data) { - my $element_id = 0; - POPULATE_ROW: - foreach my $db_column (@db_columns) { - if (grep {$db_column eq $_} keys %$db_row) { - $element_id = $db_row->{$db_column} if $db_column =~ m/id/; - $$fields[$col_index] = {select_field => 0, field_name => ($db_column . "_tbl"), field_value => $db_row->{$db_column}}; - $col_index++; - next POPULATE_ROW; - } - elsif ($db_column =~ m/^_((.*)_(.*$))/) { # this a special case - my $table_name = get_table_names($2); - my $record_set = SELECT($1, @$table_name[0], $2 . "_id = " . $db_row->{$2 . "_id"}); - $$fields[$col_index] = {select_field => 0, field_name => ($db_column . "_tbl"), field_value => $$record_set[0]{$1}}; - $col_index++; - next POPULATE_ROW; - } - } - $$fields[$col_index] = {select_field => 1, field_name => 'select', field_value => $element_id}; - $$table[$row_index] = {text_fields => $fields}; - $col_index = 0; - $row_index++; - $fields = []; - } - return $table; -} - if ($op eq 'delete') { given ($label_element) { when 'layout' {$error = C4::Labels::Layout::delete(layout_id => $element_id); last;} @@ -155,7 +104,7 @@ given ($label_element) { default {} # FIXME: Some error trapping code } -my $table = _build_table($display_columns->{$label_element}, $db_rows); +my $table = html_table($display_columns->{$label_element}, $db_rows); $template->param(error => $error) if ($error ne 0); $template->param(print => 1) if ($label_element eq 'batch'); -- 2.39.5