- if ( $type eq "simple" ) # simple search for one letter only
- {
- $query .= ($category_type ? " AND category_type = ".$dbh->quote($category_type) : "");
- $query .= " WHERE (surname LIKE ? OR cardnumber like ?) ";
- if (C4::Context->preference("IndependantBranches") && !$showallbranches){
- if (C4::Context->userenv && C4::Context->userenv->{flags} % 2 !=1 && C4::Context->userenv->{'branch'}){
- $query.=" AND borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'}) unless (C4::Context->userenv->{'branch'} eq "insecure");
- }
- }
- $query.=" ORDER BY $orderby";
- @bind = ("$searchstring%","$searchstring");
- }
- 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 ? AND surname REGEXP ?)
- OR firstname LIKE ? OR (firstname LIKE ? AND firstname REGEXP ?)
- OR othernames LIKE ? OR (othernames LIKE ? AND othernames REGEXP ?))
- " .
- ($category_type?" AND category_type = ".$dbh->quote($category_type):"");
- my $regex = '[[:punct:][:space:]]'.$data[0];
- @bind = (
- "$data[0]%", "%$data[0]%", $regex,
- "$data[0]%", "%$data[0]%", $regex,
- "$data[0]%", "%$data[0]%", $regex
- );
- for ( my $i = 1 ; $i < $count ; $i++ ) {
- $query = $query . " AND (" . " surname LIKE ? OR (surname LIKE ? AND surname REGEXP ?)
- OR firstname LIKE ? OR (firstname LIKE ? AND firstname REGEXP ?)
- OR othernames LIKE ? OR (othernames LIKE ? AND othernames REGEXP ?))";
- $regex = '[[:punct:][:space:]]'.$data[$i];
- push( @bind,
- "$data[$i]%", "%$data[$i]%", $regex,
- "$data[$i]%", "%$data[$i]%", $regex,
- "$data[$i]%", "%$data[$i]%", $regex
- );
-
-
- # FIXME - .= <<EOT;
- }
- $query = $query . ") OR cardnumber LIKE ? ";
- push( @bind, $searchstring );
- $query .= "order by $orderby";
-
- # FIXME - .= <<EOT;