Lines 31-37
use DateTime;
Link Here
|
31 |
use DateTime::Format::MySQL; |
31 |
use DateTime::Format::MySQL; |
32 |
|
32 |
|
33 |
my $input = new CGI; |
33 |
my $input = new CGI; |
34 |
my $order = $input->param('order') || ''; |
|
|
35 |
my $showall = $input->param('showall'); |
34 |
my $showall = $input->param('showall'); |
36 |
my $bornamefilter = $input->param('borname') || ''; |
35 |
my $bornamefilter = $input->param('borname') || ''; |
37 |
my $borcatfilter = $input->param('borcat') || ''; |
36 |
my $borcatfilter = $input->param('borcat') || ''; |
Lines 105-124
for my $attrcode (grep { /^patron_attr_filter_/ } $input->multi_param) {
Link Here
|
105 |
my $have_pattr_filter_data = keys(%cgi_attrcode_to_attrvalues) > 0; |
104 |
my $have_pattr_filter_data = keys(%cgi_attrcode_to_attrvalues) > 0; |
106 |
|
105 |
|
107 |
my @patron_attr_filter_loop; # array of [ domid cgivalue ismany isclone ordinal code description repeatable authorised_value_category ] |
106 |
my @patron_attr_filter_loop; # array of [ domid cgivalue ismany isclone ordinal code description repeatable authorised_value_category ] |
108 |
my @patron_attr_order_loop; # array of { label => $patron_attr_label, value => $patron_attr_order } |
|
|
109 |
|
110 |
my @sort_roots = qw(borrower title barcode date_due); |
111 |
push @sort_roots, map {$_ . " desc"} @sort_roots; |
112 |
my @order_loop = ({selected => $order ? 0 : 1}); # initial blank row |
113 |
foreach (@sort_roots) { |
114 |
my $tmpl_name = $_; |
115 |
$tmpl_name =~ s/\s/_/g; |
116 |
push @order_loop, { |
117 |
selected => $order eq $_ ? 1 : 0, |
118 |
ordervalue => $_, |
119 |
'order_' . $tmpl_name => 1, |
120 |
}; |
121 |
} |
122 |
|
107 |
|
123 |
my $sth = $dbh->prepare('SELECT code,description,repeatable,authorised_value_category |
108 |
my $sth = $dbh->prepare('SELECT code,description,repeatable,authorised_value_category |
124 |
FROM borrower_attribute_types |
109 |
FROM borrower_attribute_types |
Lines 139-157
while (my $row = $sth->fetchrow_hashref) {
Link Here
|
139 |
$row->{isclone} = $isclone; |
124 |
$row->{isclone} = $isclone; |
140 |
push @patron_attr_filter_loop, { %$row }; # careful: must store a *deep copy* of the modified row |
125 |
push @patron_attr_filter_loop, { %$row }; # careful: must store a *deep copy* of the modified row |
141 |
} continue { $isclone = 1, ++$serial } |
126 |
} continue { $isclone = 1, ++$serial } |
142 |
foreach my $sortorder ('asc', 'desc') { |
|
|
143 |
my $ordervalue = "patron_attr_${sortorder}_${code}"; |
144 |
push @order_loop, { |
145 |
selected => $order eq $ordervalue ? 1 : 0, |
146 |
ordervalue => $ordervalue, |
147 |
label => $row->{description}, |
148 |
$sortorder => 1, |
149 |
}; |
150 |
} |
151 |
} continue { ++$ordinal } |
127 |
} continue { ++$ordinal } |
152 |
for (@patron_attr_order_loop) { $_->{selected} = 1 if $order eq $_->{value} } |
|
|
153 |
|
154 |
$template->param(ORDER_LOOP => \@order_loop); |
155 |
|
128 |
|
156 |
my %borrowernumber_to_attributes; # hash of { borrowernumber => { attrcode => [ [val,display], [val,display], ... ] } } |
129 |
my %borrowernumber_to_attributes; # hash of { borrowernumber => { attrcode => [ [val,display], [val,display], ... ] } } |
157 |
# i.e. val differs from display when attr is an authorised value |
130 |
# i.e. val differs from display when attr is an authorised value |
Lines 213-219
$template->param(
Link Here
|
213 |
itemtypeloop => \@itemtypeloop, |
186 |
itemtypeloop => \@itemtypeloop, |
214 |
patron_attr_filter_loop => \@patron_attr_filter_loop, |
187 |
patron_attr_filter_loop => \@patron_attr_filter_loop, |
215 |
borname => $bornamefilter, |
188 |
borname => $bornamefilter, |
216 |
order => $order, |
|
|
217 |
showall => $showall, |
189 |
showall => $showall, |
218 |
dateduefrom => $dateduefrom, |
190 |
dateduefrom => $dateduefrom, |
219 |
datedueto => $datedueto, |
191 |
datedueto => $datedueto, |
Lines 300-313
if ($noreport) {
Link Here
|
300 |
my $bnlist = $have_pattr_filter_data ? join(',',keys %borrowernumber_to_attributes) : ''; |
272 |
my $bnlist = $have_pattr_filter_data ? join(',',keys %borrowernumber_to_attributes) : ''; |
301 |
$strsth =~ s/WHERE 1=1/WHERE 1=1 AND borrowers.borrowernumber IN ($bnlist)/ if $bnlist; |
273 |
$strsth =~ s/WHERE 1=1/WHERE 1=1 AND borrowers.borrowernumber IN ($bnlist)/ if $bnlist; |
302 |
$strsth =~ s/WHERE 1=1/WHERE 0=1/ if $have_pattr_filter_data && !$bnlist; # no match if no borrowers matched patron attrs |
274 |
$strsth =~ s/WHERE 1=1/WHERE 0=1/ if $have_pattr_filter_data && !$bnlist; # no match if no borrowers matched patron attrs |
303 |
$strsth.=" ORDER BY " . ( |
275 |
$strsth.=" ORDER BY date_due, surname, firstname"; |
304 |
($order eq "borrower") ? "surname, firstname, date_due" : |
|
|
305 |
($order eq "borrower desc") ? "surname desc, firstname desc, date_due" : |
306 |
($order eq "title" or $order eq "title desc") ? "$order, date_due, surname, firstname" : |
307 |
($order eq "barcode" or $order eq "barcode desc") ? "items.$order, date_due, surname, firstname" : |
308 |
($order eq "date_due desc") ? "date_due DESC, surname, firstname" : |
309 |
"date_due, surname, firstname" # default sort order |
310 |
); |
311 |
$template->param(sql=>$strsth); |
276 |
$template->param(sql=>$strsth); |
312 |
my $sth=$dbh->prepare($strsth); |
277 |
my $sth=$dbh->prepare($strsth); |
313 |
$sth->execute( |
278 |
$sth->execute( |
Lines 363-391
if ($noreport) {
Link Here
|
363 |
}; |
328 |
}; |
364 |
} |
329 |
} |
365 |
|
330 |
|
366 |
my ($attrorder) = $order =~ /patron_attr_(.*)$/; |
|
|
367 |
my $patrorder = ''; |
368 |
my $sortorder = 'asc'; |
369 |
if (defined $attrorder) { |
370 |
($sortorder, $patrorder) = split /_/, $attrorder, 2; |
371 |
} |
372 |
print STDERR ">>> order is $order, patrorder is $patrorder, sortorder is $sortorder\n" if $debug; |
373 |
|
374 |
if (my @attrtype = grep { $_->{'code'} eq $patrorder } @patron_attr_filter_loop) { # sort by patron attrs perhaps? |
375 |
my $ordinal = $attrtype[0]{ordinal}; |
376 |
print STDERR ">>> sort ordinal is $ordinal\n" if $debug; |
377 |
|
378 |
sub patronattr_sorter_asc { |
379 |
lc $a->{patron_attr_value_loop}[$ordinal]{value} |
380 |
cmp |
381 |
lc $b->{patron_attr_value_loop}[$ordinal]{value} } |
382 |
|
383 |
sub patronattr_sorter_des { -patronattr_sorter_asc() } |
384 |
|
385 |
my $sorter = $sortorder eq 'desc' ? \&patronattr_sorter_des : \&patronattr_sorter_asc; |
386 |
@overduedata = sort $sorter @overduedata; |
387 |
} |
388 |
|
389 |
if ($op eq 'csv') { |
331 |
if ($op eq 'csv') { |
390 |
binmode(STDOUT, ":encoding(UTF-8)"); |
332 |
binmode(STDOUT, ":encoding(UTF-8)"); |
391 |
my $csv = build_csv(\@overduedata); |
333 |
my $csv = build_csv(\@overduedata); |