- else # advanced search looking in surname, firstname and othernames
- {
- @data = split( ' ', $searchstring );
- $count = @data;
- $query .= " WHERE ";
- if (C4::Context->preference("IndependantBranches") && !$showallbranches){
- if (C4::Context->userenv && C4::Context->userenv->{flags} % 2 !=1 && C4::Context->userenv->{'branch'}){
- $query.=" borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'})." AND " unless (C4::Context->userenv->{'branch'} eq "insecure");
- }
- }
- $query.="((surname LIKE ? OR surname LIKE ?
- OR firstname LIKE ? OR firstname LIKE ?
- OR othernames LIKE ? OR othernames LIKE ?)
- " .
- ($category_type?" AND category_type = ".$dbh->quote($category_type):"");
- @bind = (
- "$data[0]%", "% $data[0]%", "$data[0]%", "% $data[0]%",
- "$data[0]%", "% $data[0]%"
- );
- for ( my $i = 1 ; $i < $count ; $i++ ) {
- $query = $query . " AND (" . " surname LIKE ? OR surname LIKE ?
- OR firstname LIKE ? OR firstname LIKE ?
- OR othernames LIKE ? OR othernames LIKE ?)";
- push( @bind,
- "$data[$i]%", "% $data[$i]%", "$data[$i]%",
- "% $data[$i]%", "$data[$i]%", "% $data[$i]%" );
-
- # FIXME - .= <<EOT;
- }
- $query = $query . ") OR cardnumber LIKE ? ";
- push( @bind, $searchstring );
- $query .= "order by $orderby";