Lines 23-29
use warnings;
Link Here
|
23 |
|
23 |
|
24 |
use CGI; |
24 |
use CGI; |
25 |
use POSIX; |
25 |
use POSIX; |
26 |
use Text::CSV_XS; |
|
|
27 |
|
26 |
|
28 |
use C4::Auth qw(get_template_and_user); |
27 |
use C4::Auth qw(get_template_and_user); |
29 |
use C4::Output qw(output_html_with_http_headers); |
28 |
use C4::Output qw(output_html_with_http_headers); |
Lines 66-105
sub _set_selected {
Link Here
|
66 |
|
65 |
|
67 |
sub _select_format_string { # generate field table based on format_string |
66 |
sub _select_format_string { # generate field table based on format_string |
68 |
my $format_string = shift; |
67 |
my $format_string = shift; |
69 |
$format_string =~ s/(?<=,) (?![A-Z][a-z][0-9])//g; # remove spaces between fields |
68 |
|
70 |
my $table = []; |
69 |
my @text_fields = grep /\w/, split /\s*,\s/, $format_string; |
71 |
my $fields = []; |
70 |
my %tf = map {$_ => 1} @text_fields; |
72 |
my ($row_index, $col_index, $field_index) = (0,0,0); |
71 |
my @missing_fields = grep { !$tf{$_} } @{ C4::Labels::Layout->PRESET_FIELDS }; |
73 |
my $cols = 5; # number of columns to wrap on |
72 |
|
74 |
my $csv = Text::CSV_XS->new({ allow_whitespace => 1 }); |
73 |
my $field_count = scalar(@text_fields) + scalar( @missing_fields); |
75 |
my $status = $csv->parse($format_string); |
74 |
|
76 |
my @text_fields = $csv->fields(); |
75 |
my @fields; |
77 |
warn sprintf('Error parsing format_string. Parser returned: %s', $csv->error_input()) if $csv->error_input(); |
76 |
my $field_index = 1; |
78 |
my $field_count = $#text_fields + 1; |
77 |
foreach my $f (@text_fields) { |
79 |
POPULATE_TABLE: |
78 |
push @fields, {field_name => ($f . "_tbl"), field_label => $f, order => $field_index}; |
80 |
foreach my $text_field (@text_fields) { |
|
|
81 |
$$fields[$col_index] = {field_empty => 0, field_name => ($text_field . "_tbl"), field_label => $text_field, order => [{num => '', selected => 0}]}; |
82 |
for (my $order_i = 1; $order_i <= $field_count; $order_i++) { |
83 |
$$fields[$col_index]{'order'}[$order_i] = {num => $order_i, selected => ($field_index == $order_i-1 ? 1 : 0)}; |
84 |
} |
85 |
$col_index++; |
86 |
$field_index++; |
79 |
$field_index++; |
87 |
if ((($col_index > 0) && !($col_index % $cols)) || ($field_index == $field_count)) { # wrap to new row |
|
|
88 |
if (($field_index == $field_count) && ($row_index > 0)) { # in this case fill out row with empty fields |
89 |
while ($col_index < $cols) { |
90 |
$$fields[$col_index] = {field_empty => 1, field_name => '', field_label => '', order => [{num => '', selected => 0}]}; |
91 |
$col_index++; |
92 |
} |
93 |
$$table[$row_index] = {text_fields => $fields}; |
94 |
last POPULATE_TABLE; |
95 |
} |
96 |
$$table[$row_index] = {text_fields => $fields}; |
97 |
$row_index++; |
98 |
$fields = []; |
99 |
$col_index = 0; |
100 |
} |
101 |
} |
80 |
} |
102 |
return $table; |
81 |
foreach my $f (@missing_fields) { |
|
|
82 |
push @fields, {field_name => ($f . "_tbl"), field_label => $f}; |
83 |
} |
84 |
return (\@fields, $field_count); |
103 |
} |
85 |
} |
104 |
|
86 |
|
105 |
if ($op eq 'edit') { |
87 |
if ($op eq 'edit') { |
Lines 110-124
if ($op eq 'edit') {
Link Here
|
110 |
elsif ($op eq 'save') { |
92 |
elsif ($op eq 'save') { |
111 |
my $format_string = ''; |
93 |
my $format_string = ''; |
112 |
if ($layout_choice eq 'layout_table') { # translate the field table into a format_string |
94 |
if ($layout_choice eq 'layout_table') { # translate the field table into a format_string |
113 |
my @layout_table = (); |
95 |
my %layout_table; |
114 |
foreach my $cgi_param ($cgi->param()) { |
96 |
foreach my $cgi_param ($cgi->param()) { |
115 |
if (($cgi_param =~ m/^(.*)_tbl$/) && ($cgi->param($cgi_param))) { |
97 |
if (($cgi_param =~ m/^(.*)_tbl$/) && ($cgi->param($cgi_param))) { |
116 |
my $value = $cgi->param($cgi_param); |
98 |
my $value = $cgi->param($cgi_param); |
117 |
$layout_table[$value - 1] = $1; |
99 |
$layout_table{$1} = $value; |
118 |
} |
100 |
} |
119 |
} |
101 |
} |
120 |
@layout_table = grep {$_} @layout_table; # this removes numerically 'skipped' fields. ie. user omits a number in sequential order |
102 |
$format_string = join ', ', sort { $layout_table{$a} <=> $layout_table{$b} } keys %layout_table; |
121 |
$format_string = join ', ', @layout_table; |
|
|
122 |
$cgi->param('format_string', $format_string); |
103 |
$cgi->param('format_string', $format_string); |
123 |
} |
104 |
} |
124 |
my @params = ( |
105 |
my @params = ( |
Lines 152-165
my $barcode_types = _set_selected(get_barcode_types(), $layout, 'barcode_type');
Link Here
|
152 |
my $label_types = _set_selected(get_label_types(), $layout, 'printing_type'); |
133 |
my $label_types = _set_selected(get_label_types(), $layout, 'printing_type'); |
153 |
my $font_types = _set_selected(get_font_types(), $layout, 'font'); |
134 |
my $font_types = _set_selected(get_font_types(), $layout, 'font'); |
154 |
my $text_justification_types = _set_selected(get_text_justification_types(), $layout, 'text_justify'); |
135 |
my $text_justification_types = _set_selected(get_text_justification_types(), $layout, 'text_justify'); |
155 |
my $select_text_fields = _select_format_string($layout->get_attr('format_string')); |
136 |
my ($select_text_fields, $select_text_fields_cnt) = _select_format_string($layout->get_attr('format_string')); |
156 |
|
137 |
|
157 |
$template->param( |
138 |
$template->param( |
158 |
barcode_types => $barcode_types, |
139 |
barcode_types => $barcode_types, |
159 |
label_types => $label_types, |
140 |
label_types => $label_types, |
160 |
font_types => $font_types, |
141 |
font_types => $font_types, |
161 |
text_justification_types => $text_justification_types, |
142 |
text_justification_types => $text_justification_types, |
162 |
field_table => $select_text_fields, |
143 |
fields => $select_text_fields, |
|
|
144 |
field_count => $select_text_fields_cnt, |
163 |
layout_id => $layout->get_attr('layout_id') > -1 ? $layout->get_attr('layout_id') : '', |
145 |
layout_id => $layout->get_attr('layout_id') > -1 ? $layout->get_attr('layout_id') : '', |
164 |
layout_name => $layout->get_attr('layout_name'), |
146 |
layout_name => $layout->get_attr('layout_name'), |
165 |
guidebox => $layout->get_attr('guidebox'), |
147 |
guidebox => $layout->get_attr('guidebox'), |
166 |
- |
|
|