-sub findguarantor {
- my ($borrowernumber) = @_;
- my $dbh = C4::Context->dbh;
- my $sth =
- $dbh->prepare("select guarantorid from borrowers where borrowernumber=?");
- $sth->execute($borrowernumber);
- my $data = $sth->fetchrow_hashref;
- $sth->finish;
- $sth = $dbh->prepare("Select * from borrowers where borrowernumber=?");
- $sth->execute( $data->{'guarantorid'} );
- $data = $sth->fetchrow_hashref;
- $sth->finish;
- return ($data);
-}
-
-=item GuarantornameSearch
-
- ($count, $borrowers) = &GuarantornameSearch($searchstring, $type);
-
-Looks up guarantor by name.
-
-BUGFIX 499: C<$type> is now used to determine type of search.
-if $type is "simple", search is performed on the first letter of the
-surname only.
-
-C<$searchstring> is a space-separated list of search terms. Each term
-must match the beginning a borrower's surname, first name, or other
-name.
-
-C<&GuarantornameSearch> returns a two-element list. C<$borrowers> is a
-reference-to-array; each element is a reference-to-hash, whose keys
-are the fields of the C<borrowers> table in the Koha database.
-C<$count> is the number of elements in C<$borrowers>.
-
-return all info from guarantor =>only category_type A
-
-=cut
-
-#'
-#used by member enquiries from the intranet
-#called by guarantor_search.pl
-sub GuarantornameSearch {
- my ($searchstring, $orderby, $type ) = @_;
- my $dbh = C4::Context->dbh;
- my $query = "";
- my $count;
- my @data;
- my @bind = ();
-
- if ( $type eq "simple" ) # simple search for one letter only
- {
- $query =
-"Select * from borrowers,categories where borrowers.categorycode=categories.categorycode and category_type='A' and surname like ? order by $orderby";
- @bind = ("$searchstring%");
- }
- else # advanced search looking in surname, firstname and othernames
- {
- @data = split( ' ', $searchstring );
- $count = @data;
- $query = "Select * from borrowers,categories
- where ((surname like ? or surname like ?
- or firstname like ? or firstname like ?
- or othernames like ? or othernames like ?) and borrowers.categorycode=categories.categorycode and category_type='A'
- ";
- @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 ?
- order by $orderby";
- push( @bind, $searchstring );
-
- # FIXME - .= <<EOT;
- }