|
Lines 26-31
use C4::Utils::DataTables qw( dt_get_params );
Link Here
|
| 26 |
use C4::Utils::DataTables::Members qw( search ); |
26 |
use C4::Utils::DataTables::Members qw( search ); |
| 27 |
use Koha::DateUtils qw( output_pref dt_from_string ); |
27 |
use Koha::DateUtils qw( output_pref dt_from_string ); |
| 28 |
use Koha::Patrons; |
28 |
use Koha::Patrons; |
|
|
29 |
use Data::Dumper; |
| 30 |
use Time::Piece; |
| 31 |
use JSON::XS qw( ); |
| 32 |
use HTML::Entities qw( encode_entities ); |
| 33 |
use List::Slice 'head'; |
| 29 |
|
34 |
|
| 30 |
my $input = new CGI; |
35 |
my $input = new CGI; |
| 31 |
|
36 |
|
|
Lines 39-44
my ($template, $user, $cookie) = get_template_and_user({
Link Here
|
| 39 |
flagsrequired => { borrowers => 'edit_borrowers' } |
44 |
flagsrequired => { borrowers => 'edit_borrowers' } |
| 40 |
}); |
45 |
}); |
| 41 |
|
46 |
|
|
|
47 |
my $first_query = $input->param('first_query'); |
| 42 |
my $searchmember = $input->param('searchmember'); |
48 |
my $searchmember = $input->param('searchmember'); |
| 43 |
my $firstletter = $input->param('firstletter'); |
49 |
my $firstletter = $input->param('firstletter'); |
| 44 |
my $categorycode = $input->param('categorycode'); |
50 |
my $categorycode = $input->param('categorycode'); |
|
Lines 50-57
my $selection_type = $input->param('selection_type');
Link Here
|
| 50 |
|
56 |
|
| 51 |
# variable information for DataTables (id) |
57 |
# variable information for DataTables (id) |
| 52 |
my $sEcho = $input->param('sEcho'); |
58 |
my $sEcho = $input->param('sEcho'); |
| 53 |
|
|
|
| 54 |
my %dt_params = dt_get_params($input); |
59 |
my %dt_params = dt_get_params($input); |
|
|
60 |
|
| 55 |
foreach (grep {$_ =~ /^mDataProp/} keys %dt_params) { |
61 |
foreach (grep {$_ =~ /^mDataProp/} keys %dt_params) { |
| 56 |
$dt_params{$_} =~ s/^dt_//; |
62 |
$dt_params{$_} =~ s/^dt_//; |
| 57 |
} |
63 |
} |
|
Lines 72-115
if ( $searchmember
Link Here
|
| 72 |
} if $member; |
78 |
} if $member; |
| 73 |
} |
79 |
} |
| 74 |
|
80 |
|
| 75 |
# Perform the patrons search |
81 |
my $filterable_results; |
| 76 |
$results = C4::Utils::DataTables::Members::search( |
82 |
if ($searchmember ne $first_query) { |
| 77 |
{ |
83 |
# Perform the patrons search |
| 78 |
searchmember => $searchmember, |
84 |
$results = C4::Utils::DataTables::Members::search( |
| 79 |
firstletter => $firstletter, |
|
|
| 80 |
categorycode => $categorycode, |
| 81 |
branchcode => $branchcode, |
| 82 |
searchtype => $searchtype, |
| 83 |
searchfieldstype => $searchfieldstype, |
| 84 |
dt_params => \%dt_params, |
| 85 |
} |
| 86 |
) unless $results; |
| 87 |
|
| 88 |
# It is not recommanded to use the has_permission param if you use the pagination |
| 89 |
# The filter is done AFTER requested the data |
| 90 |
if ($has_permission) { |
| 91 |
my ( $permission, $subpermission ) = split /\./, $has_permission; |
| 92 |
my @patrons_with_permission; |
| 93 |
for my $patron ( @{ $results->{patrons} } ) { |
| 94 |
my $perms = haspermission( $patron->{userid} ); |
| 95 |
if ( $perms->{superlibrarian} == 1 |
| 96 |
or $perms->{$permission} == 1 ) |
| 97 |
{ |
85 |
{ |
| 98 |
push @patrons_with_permission, $patron; |
86 |
searchmember => $first_query, |
| 99 |
next; |
87 |
firstletter => $firstletter, |
|
|
88 |
categorycode => $categorycode, |
| 89 |
branchcode => $branchcode, |
| 90 |
searchtype => $searchtype, |
| 91 |
searchfieldstype => $searchfieldstype, |
| 92 |
dt_params => \%dt_params, |
| 100 |
} |
93 |
} |
|
|
94 |
) unless $results; |
| 101 |
|
95 |
|
| 102 |
if ($subpermission) { |
96 |
my $value_to_display = $dt_params{'iDisplayLength'}; |
| 103 |
my $subperms = get_user_subpermissions( $patron->{userid} ); |
97 |
$dt_params{'iDisplayLength'} = -1; |
| 104 |
push @patrons_with_permission, $patron |
98 |
|
| 105 |
if $subperms->{$permission}->{$subpermission}; |
99 |
# Retreive all patrons matching the $first_query value. These will be filtered |
|
|
100 |
$filterable_results = C4::Utils::DataTables::Members::search( |
| 101 |
{ |
| 102 |
searchmember => $first_query, |
| 103 |
firstletter => $firstletter, |
| 104 |
categorycode => $categorycode, |
| 105 |
branchcode => $branchcode, |
| 106 |
searchtype => $searchtype, |
| 107 |
searchfieldstype => $searchfieldstype, |
| 108 |
dt_params => \%dt_params, |
| 106 |
} |
109 |
} |
| 107 |
} |
110 |
) unless $filterable_results; |
| 108 |
$results->{patrons} = \@patrons_with_permission; |
111 |
} else { |
| 109 |
$results->{iTotalDisplayRecords} = scalar( @patrons_with_permission ); |
112 |
# Perform the patrons search |
|
|
113 |
$results = C4::Utils::DataTables::Members::search( |
| 114 |
{ |
| 115 |
searchmember => $first_query, |
| 116 |
firstletter => $firstletter, |
| 117 |
categorycode => $categorycode, |
| 118 |
branchcode => $branchcode, |
| 119 |
searchtype => $searchtype, |
| 120 |
searchfieldstype => $searchfieldstype, |
| 121 |
dt_params => \%dt_params, |
| 122 |
} |
| 123 |
) unless $results; |
| 110 |
} |
124 |
} |
| 111 |
|
125 |
|
|
|
126 |
# It is not recommanded to use the has_permission param if you use the pagination |
| 127 |
# The filter is done AFTER requested the data |
| 128 |
if ($has_permission) { |
| 129 |
my ( $permission, $subpermission ) = split /\./, $has_permission; |
| 130 |
my @patrons_with_permission; |
| 131 |
for my $patron ( @{ $results->{patrons} } ) { |
| 132 |
my $perms = haspermission( $patron->{userid} ); |
| 133 |
if ( $perms->{superlibrarian} == 1 |
| 134 |
or $perms->{$permission} == 1 ) |
| 135 |
{ |
| 136 |
push @patrons_with_permission, $patron; |
| 137 |
next; |
| 138 |
} |
| 139 |
|
| 140 |
if ($subpermission) { |
| 141 |
my $subperms = get_user_subpermissions( $patron->{userid} ); |
| 142 |
push @patrons_with_permission, $patron |
| 143 |
if $subperms->{$permission}->{$subpermission}; |
| 144 |
} |
| 145 |
} |
| 146 |
$results->{patrons} = \@patrons_with_permission; |
| 147 |
$results->{iTotalDisplayRecords} = scalar( @patrons_with_permission ); |
| 148 |
} |
| 149 |
my $date_format = C4::Context->preference("dateformat"); |
| 150 |
|
| 151 |
my $count; |
| 152 |
if ($searchmember ne $first_query) { |
| 153 |
my @filtered_patron_list; |
| 154 |
for my $patron ( @{ $filterable_results->{patrons} } ) { |
| 155 |
my $match; |
| 156 |
for my $value (values $patron) { |
| 157 |
my $lc_patron_value = lc $value; |
| 158 |
my $lc_searchmember = lc $searchmember; |
| 159 |
|
| 160 |
#Reformat the date value |
| 161 |
if ($lc_patron_value =~ /^\d{4}-\d\d-\d\d$/) { |
| 162 |
if ($date_format eq "us" ) { |
| 163 |
$lc_patron_value = Time::Piece->strptime($lc_patron_value, '%Y-%m-%d')->strftime('%m/%d/%Y'); |
| 164 |
} elsif ($date_format eq "metric" ) { |
| 165 |
$lc_patron_value = Time::Piece->strptime($lc_patron_value, '%Y-%m-%d')->strftime('%d/%m/%Y'); |
| 166 |
} elsif ($date_format eq "iso" ) { |
| 167 |
$lc_patron_value = Time::Piece->strptime($lc_patron_value, '%Y-%m-%d')->strftime('%Y-%m-%d'); |
| 168 |
} elsif ($date_format eq "dmydot" ) { |
| 169 |
$lc_patron_value = Time::Piece->strptime($lc_patron_value, '%Y-%m-%d')->strftime('%d.%m.%Y'); |
| 170 |
|
| 171 |
} |
| 172 |
} |
| 173 |
if ($searchtype eq "start_with") { |
| 174 |
#Find a match starting with the start of a value in the patron record |
| 175 |
if (index($lc_patron_value, $lc_searchmember) == 0) { |
| 176 |
$match = 1; |
| 177 |
} |
| 178 |
} else { |
| 179 |
if (($lc_patron_value) =~ /($lc_searchmember)/) { |
| 180 |
$match = 1; |
| 181 |
} |
| 182 |
} |
| 183 |
} |
| 184 |
if ($match) { |
| 185 |
$count++; |
| 186 |
push @filtered_patron_list, $patron; |
| 187 |
next; |
| 188 |
} |
| 189 |
} |
| 190 |
$results->{patrons} = \@filtered_patron_list; |
| 191 |
if ($searchmember ne $first_query) { |
| 192 |
$results->{iTotalDisplayRecords} = scalar @{$results->{patrons}}; |
| 193 |
} |
| 194 |
} |
| 195 |
$date_format = C4::Context->preference("dateformat"); |
| 196 |
my $json = JSON::XS->new->allow_nonref; |
| 197 |
$date_format = $json->encode($date_format); |
| 198 |
$date_format = encode_entities($date_format); |
| 199 |
|
| 112 |
$template->param( |
200 |
$template->param( |
|
|
201 |
dateformat => $date_format, |
| 113 |
sEcho => $sEcho, |
202 |
sEcho => $sEcho, |
| 114 |
iTotalRecords => $results->{iTotalRecords}, |
203 |
iTotalRecords => $results->{iTotalRecords}, |
| 115 |
iTotalDisplayRecords => $results->{iTotalDisplayRecords}, |
204 |
iTotalDisplayRecords => $results->{iTotalDisplayRecords}, |
| 116 |
- |
|
|