|
Lines 20-53
sub search {
Link Here
|
| 20 |
$searchmember = $dt_params->{sSearch} // ''; |
20 |
$searchmember = $dt_params->{sSearch} // ''; |
| 21 |
} |
21 |
} |
| 22 |
|
22 |
|
| 23 |
my ($sth, $query, $iTotalRecords, $iTotalDisplayRecords); |
23 |
# If branches are independent and user is not superlibrarian |
|
|
24 |
# The search has to be only on the user branch |
| 25 |
my $userenv = C4::Context->userenv; |
| 26 |
my @restricted_branchcodes; |
| 27 |
if (C4::Context::only_my_library) { |
| 28 |
push @restricted_branchcodes, $userenv->{branch}; |
| 29 |
} |
| 30 |
else { |
| 31 |
my $logged_in_user = Koha::Patrons->find( $userenv->{number} ); |
| 32 |
unless ( |
| 33 |
$logged_in_user->can( |
| 34 |
{ borrowers => 'view_borrower_infos_from_any_libraries' } |
| 35 |
) |
| 36 |
) |
| 37 |
{ |
| 38 |
if ( my $library_groups = $logged_in_user->library->library_groups ) |
| 39 |
{ |
| 40 |
while ( my $library_group = $library_groups->next ) { |
| 41 |
push @restricted_branchcodes, |
| 42 |
$library_group->parent->children->get_column('branchcode'); |
| 43 |
} |
| 44 |
} |
| 45 |
else { |
| 46 |
push @restricted_branchcodes, $userenv->{branch}; |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
my ($sth, $query, $iTotalQuery, $iTotalRecords, $iTotalDisplayRecords); |
| 24 |
my $dbh = C4::Context->dbh; |
52 |
my $dbh = C4::Context->dbh; |
| 25 |
# Get the iTotalRecords DataTable variable |
53 |
# Get the iTotalRecords DataTable variable |
| 26 |
$query = "SELECT COUNT(borrowers.borrowernumber) FROM borrowers"; |
54 |
$query = $iTotalQuery = "SELECT COUNT(borrowers.borrowernumber) FROM borrowers"; |
| 27 |
$sth = $dbh->prepare($query); |
55 |
if ( @restricted_branchcodes ) { |
| 28 |
$sth->execute; |
56 |
$iTotalQuery .= " WHERE borrowers.branchcode IN (" . join( ',', ('?') x @restricted_branchcodes ) . ")"; |
| 29 |
($iTotalRecords) = $sth->fetchrow_array; |
57 |
} |
|
|
58 |
($iTotalRecords) = $dbh->selectrow_array( $iTotalQuery, undef, @restricted_branchcodes ); |
| 59 |
|
| 60 |
# Do that after iTotalQuery! |
| 61 |
if ( defined $branchcode and $branchcode ) { |
| 62 |
@restricted_branchcodes = @restricted_branchcodes |
| 63 |
? grep { /^$branchcode$/ } @restricted_branchcodes |
| 64 |
? ($branchcode) |
| 65 |
: (undef) # Do not return any results |
| 66 |
: ($branchcode); |
| 67 |
} |
| 30 |
|
68 |
|
| 31 |
if ( $searchfieldstype eq 'dateofbirth' ) { |
69 |
if ( $searchfieldstype eq 'dateofbirth' ) { |
| 32 |
# Return an empty list if the date of birth is not correctly formatted |
70 |
# Return an empty list if the date of birth is not correctly formatted |
| 33 |
$searchmember = eval { output_pref( { str => $searchmember, dateformat => 'iso', dateonly => 1 } ); }; |
71 |
$searchmember = eval { output_pref( { str => $searchmember, dateformat => 'iso', dateonly => 1 } ); }; |
| 34 |
if ( $@ or not $searchmember ) { |
72 |
if ( $@ or not $searchmember ) { |
| 35 |
return { |
73 |
return { |
| 36 |
iTotalRecords => 0, |
74 |
iTotalRecords => $iTotalRecords, |
| 37 |
iTotalDisplayRecords => 0, |
75 |
iTotalDisplayRecords => 0, |
| 38 |
patrons => [], |
76 |
patrons => [], |
| 39 |
}; |
77 |
}; |
| 40 |
} |
78 |
} |
| 41 |
} |
79 |
} |
| 42 |
|
80 |
|
| 43 |
# If branches are independent and user is not superlibrarian |
|
|
| 44 |
# The search has to be only on the user branch |
| 45 |
if ( C4::Context::only_my_library ) { |
| 46 |
my $userenv = C4::Context->userenv; |
| 47 |
$branchcode = $userenv->{'branch'}; |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
my $select = "SELECT |
81 |
my $select = "SELECT |
| 52 |
borrowers.borrowernumber, borrowers.surname, borrowers.firstname, |
82 |
borrowers.borrowernumber, borrowers.surname, borrowers.firstname, |
| 53 |
borrowers.streetnumber, borrowers.streettype, borrowers.address, |
83 |
borrowers.streetnumber, borrowers.streettype, borrowers.address, |
|
Lines 70-78
sub search {
Link Here
|
| 70 |
push @where_strs, "borrowers.categorycode = ?"; |
100 |
push @where_strs, "borrowers.categorycode = ?"; |
| 71 |
push @where_args, $categorycode; |
101 |
push @where_args, $categorycode; |
| 72 |
} |
102 |
} |
| 73 |
if(defined $branchcode and $branchcode ne '') { |
103 |
if(@restricted_branchcodes ) { |
| 74 |
push @where_strs, "borrowers.branchcode = ?"; |
104 |
push @where_strs, "borrowers.branchcode IN (" . join( ',', ('?') x @restricted_branchcodes ) . ")"; |
| 75 |
push @where_args, $branchcode; |
105 |
push @where_args, @restricted_branchcodes; |
| 76 |
} |
106 |
} |
| 77 |
|
107 |
|
| 78 |
my $searchfields = { |
108 |
my $searchfields = { |
| 79 |
- |
|
|