+ my ($sth, $query, $iTotalQuery, $iTotalRecords, $iTotalDisplayRecords);
+ my $dbh = C4::Context->dbh;
+ # Get the iTotalRecords DataTable variable
+ $query = $iTotalQuery = "SELECT COUNT(borrowers.borrowernumber) FROM borrowers";
+ if ( @restricted_branchcodes ) {
+ $iTotalQuery .= " WHERE borrowers.branchcode IN (" . join( ',', ('?') x @restricted_branchcodes ) . ")";
+ }
+ ($iTotalRecords) = $dbh->selectrow_array( $iTotalQuery, undef, @restricted_branchcodes );
+
+ # Do that after iTotalQuery!
+ if ( defined $branchcode and $branchcode ) {
+ @restricted_branchcodes = @restricted_branchcodes
+ ? grep { $_ eq $branchcode } @restricted_branchcodes
+ ? ($branchcode)
+ : (undef) # Do not return any results
+ : ($branchcode);
+ }
+
+ if ( $searchfieldstype eq 'dateofbirth' ) {
+ # Return an empty list if the date of birth is not correctly formatted
+ $searchmember = eval { output_pref( { str => $searchmember, dateformat => 'iso', dateonly => 1 } ); };
+ if ( $@ or not $searchmember ) {
+ return {
+ iTotalRecords => $iTotalRecords,
+ iTotalDisplayRecords => 0,
+ patrons => [],
+ };
+ }