Lines 38-98
my $cgi = CGI->new;
Link Here
|
38 |
my $format = $cgi->param('format'); |
38 |
my $format = $cgi->param('format'); |
39 |
my $template_name = 'catalogue/itemsearch.tt'; |
39 |
my $template_name = 'catalogue/itemsearch.tt'; |
40 |
|
40 |
|
41 |
if (defined $format and $format eq 'json') { |
41 |
if ( defined $format and $format eq 'json' ) { |
42 |
$template_name = 'catalogue/itemsearch_json.tt'; |
42 |
$template_name = 'catalogue/itemsearch_json.tt'; |
43 |
|
43 |
|
44 |
# Map DataTables parameters with 'regular' parameters |
44 |
# Map DataTables parameters with 'regular' parameters |
45 |
$cgi->param('rows', scalar $cgi->param('length')); |
45 |
$cgi->param( 'rows', scalar $cgi->param('length') ); |
46 |
$cgi->param('page', (scalar $cgi->param('start') / scalar $cgi->param('length')) + 1); |
46 |
$cgi->param( 'page', ( scalar $cgi->param('start') / scalar $cgi->param('length') ) + 1 ); |
47 |
my @columns = @{ from_json $cgi->param('columns') }; |
47 |
my @columns = @{ from_json $cgi->param('columns') }; |
48 |
$cgi->param('sortby', $columns[ $cgi->param('order[0][column]') ]->{name}); |
48 |
$cgi->param( 'sortby', $columns[ $cgi->param('order[0][column]') ]->{name} ); |
49 |
$cgi->param('sortorder', scalar $cgi->param('order[0][dir]')); |
49 |
$cgi->param( 'sortorder', scalar $cgi->param('order[0][dir]') ); |
50 |
|
50 |
|
51 |
my @f = $cgi->multi_param('f'); |
51 |
my @f = $cgi->multi_param('f'); |
52 |
my @q = $cgi->multi_param('q'); |
52 |
my @q = $cgi->multi_param('q'); |
53 |
|
53 |
|
54 |
# If index indicates the value is a barcode, we need to preprocess it before searching |
54 |
# If index indicates the value is a barcode, we need to preprocess it before searching |
55 |
for ( my $i = 0; $i < @q; $i++ ) { |
55 |
for ( my $i = 0 ; $i < @q ; $i++ ) { |
56 |
$q[$i] = barcodedecode($q[$i]) if $f[$i] eq 'barcode'; |
56 |
$q[$i] = barcodedecode( $q[$i] ) if $f[$i] eq 'barcode'; |
57 |
} |
57 |
} |
58 |
|
58 |
|
59 |
push @q, '' if @q == 0; |
59 |
push @q, '' if @q == 0; |
60 |
my @op = $cgi->multi_param('op'); |
60 |
my @op = $cgi->multi_param('op'); |
61 |
my @c = $cgi->multi_param('c'); |
61 |
my @c = $cgi->multi_param('c'); |
62 |
for my $column (@columns) { |
62 |
for my $column (@columns) { |
63 |
my $search = $column->{search}->{value}; |
63 |
my $search = $column->{search}->{value}; |
64 |
my $column_name = $column->{name}; |
64 |
my $column_name = $column->{name}; |
65 |
if (defined $search and $search ne '') { |
65 |
if ( defined $search and $search ne '' ) { |
66 |
my @words = split /\s+/, $search; |
66 |
my @words = split /\s+/, $search; |
67 |
foreach my $word (@words) { |
67 |
foreach my $word (@words) { |
68 |
push @f, $column_name; |
68 |
push @f, $column_name; |
69 |
push @c, 'and'; |
69 |
push @c, 'and'; |
70 |
|
70 |
|
71 |
if ( grep { $_ eq $column_name } qw( ccode homebranch holdingbranch location itype notforloan itemlost onloan ) ) { |
71 |
if ( grep { $_ eq $column_name } |
72 |
push @q, "$word"; |
72 |
qw( ccode homebranch holdingbranch location itype notforloan itemlost onloan ) ) |
|
|
73 |
{ |
74 |
push @q, "$word"; |
73 |
push @op, '='; |
75 |
push @op, '='; |
74 |
} else { |
76 |
} else { |
75 |
push @q, "%$word%"; |
77 |
push @q, "%$word%"; |
76 |
push @op, 'like'; |
78 |
push @op, 'like'; |
77 |
} |
79 |
} |
78 |
} |
80 |
} |
79 |
} |
81 |
} |
80 |
} |
82 |
} |
81 |
$cgi->param('f', @f); |
83 |
$cgi->param( 'f', @f ); |
82 |
$cgi->param('q', @q); |
84 |
$cgi->param( 'q', @q ); |
83 |
$cgi->param('op', @op); |
85 |
$cgi->param( 'op', @op ); |
84 |
$cgi->param('c', @c); |
86 |
$cgi->param( 'c', @c ); |
85 |
} elsif (defined $format and $format eq 'csv') { |
87 |
} elsif ( defined $format and $format eq 'csv' ) { |
86 |
$template_name = 'catalogue/itemsearch_csv.tt'; |
88 |
$template_name = 'catalogue/itemsearch_csv.tt'; |
87 |
|
89 |
|
88 |
# Retrieve all results |
90 |
# Retrieve all results |
89 |
$cgi->param('rows', 0); |
91 |
$cgi->param( 'rows', 0 ); |
90 |
} elsif (defined $format and $format eq 'barcodes') { |
92 |
} elsif ( defined $format and $format eq 'barcodes' ) { |
|
|
93 |
|
91 |
# Retrieve all results |
94 |
# Retrieve all results |
92 |
$cgi->param('rows', 0); |
95 |
$cgi->param( 'rows', 0 ); |
93 |
} elsif (defined $format and $format eq 'shareable') { |
96 |
} elsif ( defined $format and $format eq 'shareable' ) { |
|
|
97 |
|
94 |
# get the item search parameters from the url and fill form |
98 |
# get the item search parameters from the url and fill form |
95 |
} elsif (defined $format) { |
99 |
} elsif ( defined $format ) { |
96 |
die "Unsupported format $format"; |
100 |
die "Unsupported format $format"; |
97 |
} |
101 |
} |
98 |
|
102 |
|
99 |
- |
|
|