[Koha-cvs] koha/C4 Search.pm [rel_3_0]
Antoine Farnault
antoine at koha-fr.org
Mon Nov 20 11:18:42 CET 2006
CVSROOT: /sources/koha
Module name: koha
Branch: rel_3_0
Changes by: Antoine Farnault <toins> 06/11/20 10:18:41
Modified files:
C4 : Search.pm
Log message:
* removing 3 unused function : itemcount,itemcount2 and ItemTypes
* perltidy
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Search.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.120.2.28&r2=1.120.2.29
Patches:
Index: Search.pm
===================================================================
RCS file: /sources/koha/koha/C4/Search.pm,v
retrieving revision 1.120.2.28
retrieving revision 1.120.2.29
diff -u -b -r1.120.2.28 -r1.120.2.29
--- Search.pm 17 Nov 2006 14:57:21 -0000 1.120.2.28
+++ Search.pm 20 Nov 2006 10:18:41 -0000 1.120.2.29
@@ -32,15 +32,16 @@
use Lingua::Stem;
- # FIXME - C4::Search uses C4::Reserves2, which uses C4::Search.
- # So Perl complains that all of the functions here get redefined.
+# FIXME - C4::Search uses C4::Reserves2, which uses C4::Search.
+# So Perl complains that all of the functions here get redefined.
#use C4::Date;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
# set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.120.2.28 $' =~ /\d+/g;
- shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
+$VERSION = do { my @v = '$Revision: 1.120.2.29 $' =~ /\d+/g;
+ shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v );
+};
=head1 NAME
@@ -63,30 +64,22 @@
@ISA = qw(Exporter);
@EXPORT = qw(
+ &CatSearch
+ &SimpleSearch
+ &BornameSearch &ItemInfo &KeywordSearch
+ &subsearch
+ &itemdata &bibdata
+ &GetItems &borrdata &itemnodata
+ &NewBorrowerNumber &borrissues
+ &getboracctrecord &ItemType &itemissues &subject &subtitle
+ &addauthor &bibitems &barcodes &findguarantees &allissues
+ &findseealso &findguarantor
+ &getwebsites &getwebbiblioitems &FindDuplicate
+ &isbnsearch &getborrowercategory &getborrowercategoryinfo
+ &searchResults &getRecords &buildQuery &catalogsearch
+ &getMARCnotes &getMARCsubjects &getMARCurls
+);
-&CatSearch
-
-&SimpleSearch
-
-&BornameSearch &ItemInfo &KeywordSearch
-
-&subsearch
-
-&itemdata &bibdata
-
-&GetItems &borrdata &itemnodata &itemcount &itemcount2
-
-&NewBorrowerNumber &borrissues
-&getboracctrecord &ItemType &itemissues &subject &subtitle
-&addauthor &bibitems &barcodes &findguarantees &allissues
-&findseealso &findguarantor
-
-&getwebsites &getwebbiblioitems &FindDuplicate
-&isbnsearch &getborrowercategory &getborrowercategoryinfo
-
-&searchResults &getRecords &buildQuery &catalogsearch
-
-&getMARCnotes &getMARCsubjects &getMARCurls);
# make all your functions, whether exported or not;
=item findseealso($dbh,$fields);
@@ -103,12 +96,13 @@
=cut
sub findseealso {
- my ($dbh, $fields) = @_;
- my $tagslib = MARCgettagslib ($dbh,1);
- for (my $i=0;$i<=$#{$fields};$i++) {
- my ($tag) =substr(@$fields[$i],1,3);
- my ($subfield) =substr(@$fields[$i],4,1);
- @$fields[$i].=','.$tagslib->{$tag}->{$subfield}->{seealso} if ($tagslib->{$tag}->{$subfield}->{seealso});
+ my ( $dbh, $fields ) = @_;
+ my $tagslib = MARCgettagslib( $dbh, 1 );
+ for ( my $i = 0 ; $i <= $#{$fields} ; $i++ ) {
+ my ($tag) = substr( @$fields[$i], 1, 3 );
+ my ($subfield) = substr( @$fields[$i], 4, 1 );
+ @$fields[$i] .= ',' . $tagslib->{$tag}->{$subfield}->{seealso}
+ if ( $tagslib->{$tag}->{$subfield}->{seealso} );
}
}
@@ -129,19 +123,21 @@
=cut
#'
-sub findguarantees{
- my ($borrowernumber)=@_;
+sub findguarantees {
+ my ($borrowernumber) = @_;
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("select cardnumber,borrowernumber, firstname, surname from borrowers where guarantor=?");
+ my $sth =
+ $dbh->prepare(
+"select cardnumber,borrowernumber, firstname, surname from borrowers where guarantor=?"
+ );
$sth->execute($borrowernumber);
my @dat;
- while (my $data = $sth->fetchrow_hashref)
- {
+ while ( my $data = $sth->fetchrow_hashref ) {
push @dat, $data;
}
$sth->finish;
- return (scalar(@dat), \@dat);
+ return ( scalar(@dat), \@dat );
}
=item findguarantor
@@ -161,18 +157,19 @@
=cut
#'
-sub findguarantor{
- my ($borrowernumber)=@_;
+sub findguarantor {
+ my ($borrowernumber) = @_;
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("select guarantor from borrowers where borrowernumber=?");
+ my $sth =
+ $dbh->prepare("select guarantor from borrowers where borrowernumber=?");
$sth->execute($borrowernumber);
- my $data=$sth->fetchrow_hashref;
+ my $data = $sth->fetchrow_hashref;
$sth->finish;
- $sth=$dbh->prepare("Select * from borrowers where borrowernumber=?");
- $sth->execute($data->{'guarantor'});
- $data=$sth->fetchrow_hashref;
+ $sth = $dbh->prepare("Select * from borrowers where borrowernumber=?");
+ $sth->execute( $data->{'guarantor'} );
+ $data = $sth->fetchrow_hashref;
$sth->finish;
- return($data);
+ return ($data);
}
=item NewBorrowerNumber
@@ -189,12 +186,12 @@
# doesn't belong in C4::Search.
sub NewBorrowerNumber {
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("Select max(borrowernumber) from borrowers");
+ my $sth = $dbh->prepare("Select max(borrowernumber) from borrowers");
$sth->execute;
- my $data=$sth->fetchrow_hashref;
+ my $data = $sth->fetchrow_hashref;
$sth->finish;
$data->{'max(borrowernumber)'}++;
- return($data->{'max(borrowernumber)'});
+ return ( $data->{'max(borrowernumber)'} );
}
=item catalogsearch
@@ -239,20 +236,25 @@
#'
sub catalogsearch {
- my ($dbh, $tags, $and_or, $excluding, $operator, $value, $offset,$length,$orderby,$desc_or_asc) = @_;
+ my (
+ $dbh, $tags, $and_or, $excluding, $operator,
+ $value, $offset, $length, $orderby, $desc_or_asc
+ ) = @_;
# used for the new API
- my ($search_or_scan,$type,$query,$num,$startfrom,$then_sort_by);
+ my ( $search_or_scan, $type, $query, $num, $startfrom, $then_sort_by );
$search_or_scan = 'search';
$then_sort_by = '';
my $number_of_results = $length; # num of results to return
$startfrom = $offset; # offset
my $ccl_query;
- for (my $i = 0 ; $i <= $#{$value} ; $i++) {
- $ccl_query.= @$value[$i];
+ for ( my $i = 0 ; $i <= $#{$value} ; $i++ ) {
+ $ccl_query .= @$value[$i];
}
- my ($error,$count,$facets, at results) = searchZOOM('search','ccl',$ccl_query,$number_of_results,$startfrom,$then_sort_by);
+ my ( $error, $count, $facets, @results ) =
+ searchZOOM( 'search', 'ccl', $ccl_query, $number_of_results, $startfrom,
+ $then_sort_by );
my @result = ();
my $subtitle; # Added by JF for Subtitles
@@ -261,67 +263,90 @@
#put them in @result
foreach my $rec (@results) {
my $record = MARC::Record->new_from_usmarc($rec);
+
#warn "record :=".$record->as_formatted;
- my $oldbiblio = MARCmarc2koha($dbh,$record,'');
+ my $oldbiblio = MARCmarc2koha( $dbh, $record, '' );
push @result, $oldbiblio->{'biblionumber'};
}
- # we have biblionumber list. Now, loads title and author from [offset] to [offset]+[length]
+
+# we have biblionumber list. Now, loads title and author from [offset] to [offset]+[length]
my $counter = $offset;
- # HINT : biblionumber as bn is important. The hash is fills biblionumber with items.biblionumber.
- # so if you dont' has an item, you get a not nice empty value.
- my $sth = $dbh->prepare("SELECT biblio.biblionumber as bn,biblioitems.*,biblio.*, itemtypes.notforloan,itemtypes.description
+
+# HINT : biblionumber as bn is important. The hash is fills biblionumber with items.biblionumber.
+# so if you dont' has an item, you get a not nice empty value.
+ my $sth = $dbh->prepare(
+"SELECT biblio.biblionumber as bn,biblioitems.*,biblio.*, itemtypes.notforloan,itemtypes.description
FROM biblio
LEFT JOIN biblioitems on biblio.biblionumber = biblioitems.biblionumber
LEFT JOIN itemtypes on itemtypes.itemtype=biblioitems.itemtype
- WHERE biblio.biblionumber = ?");
- my $sth_subtitle = $dbh->prepare("SELECT subtitle FROM bibliosubtitle WHERE biblionumber=?"); # Added BY JF for Subtitles
+ WHERE biblio.biblionumber = ?"
+ );
+ my $sth_subtitle =
+ $dbh->prepare("SELECT subtitle FROM bibliosubtitle WHERE biblionumber=?")
+ ; # Added BY JF for Subtitles
my @finalresult = ();
- my @CNresults=();
- my $totalitems=0;
+ my @CNresults = ();
+ my $totalitems = 0;
my $oldline;
my $sth_itemCN;
- if (C4::Context->preference('hidelostitems')) {
- $sth_itemCN = $dbh->prepare("select items.* from items where biblionumber=? and (itemlost = 0 or itemlost is NULL) order by homebranch");
- } else {
- $sth_itemCN = $dbh->prepare("select items.* from items where biblionumber=? order by homebranch");
+ if ( C4::Context->preference('hidelostitems') ) {
+ $sth_itemCN =
+ $dbh->prepare(
+"select items.* from items where biblionumber=? and (itemlost = 0 or itemlost is NULL) order by homebranch"
+ );
+ }
+ else {
+ $sth_itemCN =
+ $dbh->prepare(
+ "select items.* from items where biblionumber=? order by homebranch"
+ );
}
- my $sth_issue = $dbh->prepare("select date_due,returndate from issues where itemnumber=?");
- # parse all biblios between start & end.
- #while (($counter <= $#result) && ($counter <= ($offset + $length))) { #FIXME, do all of them
- while ($counter <= $#result) {
+ my $sth_issue =
+ $dbh->prepare(
+ "select date_due,returndate from issues where itemnumber=?");
+
+# parse all biblios between start & end.
+#while (($counter <= $#result) && ($counter <= ($offset + $length))) { #FIXME, do all of them
+ while ( $counter <= $#result ) {
+
# search & parse all items & note itemcallnumber
#warn $result[$counter];
- $sth->execute($result[$counter]);
- my $continue=1;
+ $sth->execute( $result[$counter] );
+ my $continue = 1;
my $line = $sth->fetchrow_hashref;
- my $biblionumber=$line->{bn};
+ my $biblionumber = $line->{bn};
+
# Return subtitles first ADDED BY JF
$sth_subtitle->execute($biblionumber);
- my $subtitle_here.= $sth_subtitle->fetchrow." ";
+ my $subtitle_here .= $sth_subtitle->fetchrow . " ";
chop $subtitle_here;
$subtitle = $subtitle_here;
-# warn "Here's the Biblionumber ".$biblionumber;
-# warn "and here's the subtitle: ".$subtitle_here;
+
+ # warn "Here's the Biblionumber ".$biblionumber;
+ # warn "and here's the subtitle: ".$subtitle_here;
# /ADDED BY JF
-# $continue=0 unless $line->{bn};
-# my $lastitemnumber;
+ # $continue=0 unless $line->{bn};
+ # my $lastitemnumber;
$sth_itemCN->execute($biblionumber);
my @CNresults = ();
- my $notforloan=1; # to see if there is at least 1 item that can be issued
- while (my $item = $sth_itemCN->fetchrow_hashref) {
+ my $notforloan =
+ 1; # to see if there is at least 1 item that can be issued
+ while ( my $item = $sth_itemCN->fetchrow_hashref ) {
+
# parse the result, putting holdingbranch & itemcallnumber in separate array
# then all other fields in the main array
# search if item is on loan
my $date_due;
- $sth_issue->execute($item->{itemnumber});
- while (my $loan = $sth_issue->fetchrow_hashref) {
- if ($loan->{date_due} and !$loan->{returndate}) {
+ $sth_issue->execute( $item->{itemnumber} );
+ while ( my $loan = $sth_issue->fetchrow_hashref ) {
+ if ( $loan->{date_due} and !$loan->{returndate} ) {
$date_due = $loan->{date_due};
}
}
+
# store this item
my %lineCN;
$lineCN{holdingbranch} = $item->{holdingbranch};
@@ -330,96 +355,128 @@
$lineCN{date_due} = $date_due; #format_date($date_due);
#$lineCN{notforloan} = $notforloanstatus{$line->{notforloan}} if ($line->{notforloan}); # setting not forloan if itemtype is not for loan
#$lineCN{notforloan} = $notforloanstatus{$item->{notforloan}} if ($item->{notforloan}); # setting not forloan it this item is not for loan
- $notforloan=0 unless ($item->{notforloan} or $item->{wthdrawn} or $item->{itemlost});
- push @CNresults,\%lineCN;
+ $notforloan = 0
+ unless ( $item->{notforloan}
+ or $item->{wthdrawn}
+ or $item->{itemlost} );
+ push @CNresults, \%lineCN;
$totalitems++;
}
+
# save the biblio in the final array, with item and item issue status
my %newline;
%newline = %$line;
$newline{totitem} = $totalitems;
+
# if $totalitems == 0, check if it's being ordered.
- if ($totalitems == 0) {
- my $sth = $dbh->prepare("select count(*) from aqorders where biblionumber=? and datecancellationprinted is NULL");
+ if ( $totalitems == 0 ) {
+ my $sth =
+ $dbh->prepare(
+"select count(*) from aqorders where biblionumber=? and datecancellationprinted is NULL"
+ );
$sth->execute($biblionumber);
my ($ordered) = $sth->fetchrow;
$newline{onorder} = 1 if $ordered;
}
$newline{biblionumber} = $biblionumber;
$newline{norequests} = 0;
- $newline{norequests} = 1 if ($line->{notforloan}); # itemtype not issuable
- $newline{norequests} = 1 if (!$line->{notforloan} && $notforloan); # itemtype issuable but all items not issuable for instance
+ $newline{norequests} = 1
+ if ( $line->{notforloan} ); # itemtype not issuable
+ $newline{norequests} = 1
+ if ( !$line->{notforloan} && $notforloan )
+ ; # itemtype issuable but all items not issuable for instance
$newline{subtitle} = $subtitle; # put the subtitle in ADDED BY JF
- my @CNresults2= @CNresults;
+ my @CNresults2 = @CNresults;
$newline{CN} = \@CNresults2;
$newline{'even'} = 1 if $#finalresult % 2 == 0;
$newline{'odd'} = 1 if $#finalresult % 2 == 1;
+
#$newline{'timestamp'} = format_date($newline{timestamp});
@CNresults = ();
push @finalresult, \%newline;
- $totalitems=0;
+ $totalitems = 0;
$counter++;
}
- my $nbresults = $#result+1;
- return (\@finalresult, $nbresults);
+ my $nbresults = $#result + 1;
+ return ( \@finalresult, $nbresults );
}
-
sub add_html_bold_fields {
- my ($type, $data, $search) = @_;
+ my ( $type, $data, $search ) = @_;
- my %reference = ('additionalauthors' => 'author',
+ my %reference = (
+ 'additionalauthors' => 'author',
'publishercode' => 'publisher',
'subtitle' => 'title'
);
- foreach my $key ('title', 'author', 'additionalauthors', 'publishercode', 'publicationyear', 'subject', 'subtitle') {
+ foreach my $key (
+ 'title', 'author',
+ 'additionalauthors', 'publishercode',
+ 'publicationyear', 'subject',
+ 'subtitle'
+ )
+ {
my $new_key;
- if ($key eq 'additionalauthors') {
+ if ( $key eq 'additionalauthors' ) {
$new_key = 'additionalauthors';
- } else {
+ }
+ else {
$new_key = 'bold_' . $key;
$data->{$new_key} = $data->{$key};
}
my $key1;
- if ($reference{$key}) {
+ if ( $reference{$key} ) {
$key1 = $reference{$key};
- } else {
+ }
+ else {
$key1 = $key;
}
my @keys;
my $i = 1;
- if ($type eq 'keyword') {
- my $newkey=$search->{'keyword'};
- $newkey=~s /\++//g;
+ if ( $type eq 'keyword' ) {
+ my $newkey = $search->{'keyword'};
+ $newkey =~ s /\++//g;
@keys = split " ", $newkey;
- } else {
- while ($search->{"field_value$i"}) {
- my $newkey=$search->{"field_value$i"};
- $newkey=~s /\++//g;
+ }
+ else {
+ while ( $search->{"field_value$i"} ) {
+ my $newkey = $search->{"field_value$i"};
+ $newkey =~ s /\++//g;
push @keys, $newkey;
$i++;
}
}
my $count = @keys;
- for ($i = 0; $i < $count ; $i++) {
- if ($key eq 'additionalauthors') {
+ for ( $i = 0 ; $i < $count ; $i++ ) {
+ if ( $key eq 'additionalauthors' ) {
my $j = 0;
- foreach (@{$data->{$new_key}}) {
- if (!$data->{$new_key}->[$j]->{'bold_value'}) {
- $data->{$new_key}->[$j]->{'bold_value'} = $data->{$new_key}->[$j]->{'value'};
- }
- if ( ($data->{$new_key}->[$j]->{'value'} =~ /($keys[$i])/i) && (lc($keys[$i]) ne 'b') ) {
+ foreach ( @{ $data->{$new_key} } ) {
+ if ( !$data->{$new_key}->[$j]->{'bold_value'} ) {
+ $data->{$new_key}->[$j]->{'bold_value'} =
+ $data->{$new_key}->[$j]->{'value'};
+ }
+ if (
+ (
+ $data->{$new_key}->[$j]->{'value'} =~ /($keys[$i])/i
+ )
+ && ( lc( $keys[$i] ) ne 'b' )
+ )
+ {
my $word = $1;
- $data->{$new_key}->[$j]->{'bold_value'} =~ s/$word/<b>$word<\/b>/;
+ $data->{$new_key}->[$j]->{'bold_value'} =~
+ s/$word/<b>$word<\/b>/;
}
$j++;
}
- } else {
- if (($data->{$new_key} =~ /($keys[$i])/i) && (lc($keys[$i]) ne 'b') ) {
+ }
+ else {
+ if ( ( $data->{$new_key} =~ /($keys[$i])/i )
+ && ( lc( $keys[$i] ) ne 'b' ) )
+ {
my $word = $1;
$data->{$new_key} =~ s/$word/<b>$word<\/b>/;
}
@@ -427,35 +484,41 @@
}
}
-
}
sub FindDuplicate {
- my ($record)=@_;
-my $dbh=C4::Context->dbh;
- my $result = MARCmarc2koha($dbh,$record,'');
+ my ($record) = @_;
+ my $dbh = C4::Context->dbh;
+ my $result = MARCmarc2koha( $dbh, $record, '' );
my $sth;
my $query;
my $search;
my $type;
- my ($biblionumber,$title);
+ my ( $biblionumber, $title );
+
# search duplicate on ISBN, easy and fast..
#$search->{'avoidquerylog'}=1;
- if ($result->{isbn}) {
+ if ( $result->{isbn} ) {
$query = "isbn=$result->{isbn}";
- }else{
-$result->{title}=~s /\\//g;
-$result->{title}=~s /\"//g;
+ }
+ else {
+ $result->{title} =~ s /\\//g;
+ $result->{title} =~ s /\"//g;
$query = "ti,ext=$result->{title}";
}
- my ($possible_duplicate_record)=C4::Biblio::getRecord("biblioserver",$query,"usmarc");
+ my ($possible_duplicate_record) =
+ C4::Biblio::getRecord( "biblioserver", $query, "usmarc" );
if ($possible_duplicate_record) {
- my $marcrecord = MARC::Record->new_from_usmarc($possible_duplicate_record);
- my $result = MARCmarc2koha($dbh,$marcrecord,'');
- return $result->{'biblionumber'}, $result->{'biblionumber'},$result->{'title'} if $result;
+ my $marcrecord =
+ MARC::Record->new_from_usmarc($possible_duplicate_record);
+ my $result = MARCmarc2koha( $dbh, $marcrecord, '' );
+ return $result->{'biblionumber'}, $result->{'biblionumber'},
+ $result->{'title'}
+ if $result;
}
}
+
=item KeywordSearch
$search = { "keyword" => "One or more keywords",
@@ -496,15 +559,16 @@
#'
sub KeywordSearch {
- my ($env,$type,$search,$num,$offset)=@_;
+ my ( $env, $type, $search, $num, $offset ) = @_;
my $dbh = C4::Context->dbh;
- $search->{'keyword'}=~ s/ +$//;
- my @key=split(' ',$search->{'keyword'});
+ $search->{'keyword'} =~ s/ +$//;
+ my @key = split( ' ', $search->{'keyword'} );
+
# FIXME - Naive users might enter comma-separated
# words, e.g., "training, animal". Ought to cope with
# this.
- my $count=@key;
- my $i=1;
+ my $count = @key;
+ my $i = 1;
my %biblionumbers; # Set of biblionumbers returned by the
# various searches.
@@ -535,36 +599,34 @@
FROM biblio
WHERE
EOT
- foreach my $keyword (@key)
- {
+ foreach my $keyword (@key) {
my @subclauses = (); # Subclauses, one for each field we're
# searching on
# For each field we're searching on, create a subclause that'll
# match the current keyword in the current field.
- foreach my $field (qw(title notes seriestitle author))
- {
- push @subclauses,
- "$field LIKE ? OR $field LIKE ?";
- push(@bind,"\Q$keyword\E%","% \Q$keyword\E%");
+ foreach my $field (qw(title notes seriestitle author)) {
+ push @subclauses, "$field LIKE ? OR $field LIKE ?";
+ push( @bind, "\Q$keyword\E%", "% \Q$keyword\E%" );
}
+
# (Yes, this could have been done as
# @subclauses = map {...} qw(field1 field2 ...)
# )but I think this way is more readable.
# Construct the current clause by joining the subclauses.
- push @clauses, "(" . join(")\n\tOR (", @subclauses) . ")";
+ push @clauses, "(" . join( ")\n\tOR (", @subclauses ) . ")";
}
+
# Now join all of the clauses together and append to the query.
- $query .= "(" . join(")\nAND (", @clauses) . ")";
+ $query .= "(" . join( ")\nAND (", @clauses ) . ")";
# FIXME - Perhaps use $sth->bind_columns() ? Documented as the most
# efficient way to fetch data.
- my $sth=$dbh->prepare($query);
+ my $sth = $dbh->prepare($query);
$sth->execute(@bind);
- while (my @res = $sth->fetchrow_array) {
- for (@res)
- {
+ while ( my @res = $sth->fetchrow_array ) {
+ for (@res) {
$biblionumbers{$_} = 1; # Add these results to the set
}
}
@@ -576,19 +638,16 @@
@clauses = ();
@bind = ();
$query = "SELECT biblionumber FROM bibliosubtitle WHERE ";
- foreach my $keyword (@key)
- {
- push @clauses,
- "subtitle LIKE ? OR subtitle like ?";
- push(@bind,"\Q$keyword\E%","% \Q$keyword\E%");
+ foreach my $keyword (@key) {
+ push @clauses, "subtitle LIKE ? OR subtitle like ?";
+ push( @bind, "\Q$keyword\E%", "% \Q$keyword\E%" );
}
- $query .= "(" . join(") AND (", @clauses) . ")";
+ $query .= "(" . join( ") AND (", @clauses ) . ")";
- $sth=$dbh->prepare($query);
+ $sth = $dbh->prepare($query);
$sth->execute(@bind);
- while (my @res = $sth->fetchrow_array) {
- for (@res)
- {
+ while ( my @res = $sth->fetchrow_array ) {
+ for (@res) {
$biblionumbers{$_} = 1; # Add these results to the set
}
}
@@ -601,19 +660,16 @@
@clauses = ();
@bind = ();
$query = "SELECT biblionumber FROM biblioitems WHERE ";
- foreach my $keyword (@key)
- {
- push @clauses,
- "notes LIKE ? OR notes like ?";
- push(@bind,"\Q$keyword\E%","% \Q$keyword\E%");
+ foreach my $keyword (@key) {
+ push @clauses, "notes LIKE ? OR notes like ?";
+ push( @bind, "\Q$keyword\E%", "% \Q$keyword\E%" );
}
- $query .= "(" . join(") AND (", @clauses) . ")";
+ $query .= "(" . join( ") AND (", @clauses ) . ")";
- $sth=$dbh->prepare($query);
+ $sth = $dbh->prepare($query);
$sth->execute(@bind);
- while (my @res = $sth->fetchrow_array) {
- for (@res)
- {
+ while ( my @res = $sth->fetchrow_array ) {
+ for (@res) {
$biblionumbers{$_} = 1; # Add these results to the set
}
}
@@ -633,51 +689,55 @@
# If this isn't the desired effect, see the previous searches for
# how to do it.
- $sth=$dbh->prepare("Select biblionumber from bibliosubject where subject
- like ? group by biblionumber");
+ $sth = $dbh->prepare(
+ "Select biblionumber from bibliosubject where subject
+ like ? group by biblionumber"
+ );
$sth->execute("%$search->{'keyword'}%");
- while (my @res = $sth->fetchrow_array) {
- for (@res)
- {
+ while ( my @res = $sth->fetchrow_array ) {
+ for (@res) {
$biblionumbers{$_} = 1; # Add these results to the set
}
}
$sth->finish;
- my $i2=0;
- my $i3=0;
- my $i4=0;
+ my $i2 = 0;
+ my $i3 = 0;
+ my $i4 = 0;
my @res2;
my @res = keys %biblionumbers;
- $count=@res;
+ $count = @res;
- $i=0;
-# print "count $count";
- if ($search->{'class'} ne ''){
- while ($i2 <$count){
- my $query="select * from biblio,biblioitems where
+ $i = 0;
+
+ # print "count $count";
+ if ( $search->{'class'} ne '' ) {
+ while ( $i2 < $count ) {
+ my $query = "select * from biblio,biblioitems where
biblio.biblionumber=? and
biblio.biblionumber=biblioitems.biblionumber ";
- my @bind = ($res[$i2]);
- if ($search->{'class'} ne ''){ # FIXME - Redundant
- my @temp=split(/\|/,$search->{'class'});
- my $count=@temp;
- $query.= "and ( itemtype=?";
- push(@bind,$temp[0]);
- for (my $i=1;$i<$count;$i++){
- $query.=" or itemtype=?";
- push(@bind,$temp[$i]);
+ my @bind = ( $res[$i2] );
+ if ( $search->{'class'} ne '' ) { # FIXME - Redundant
+ my @temp = split( /\|/, $search->{'class'} );
+ my $count = @temp;
+ $query .= "and ( itemtype=?";
+ push( @bind, $temp[0] );
+ for ( my $i = 1 ; $i < $count ; $i++ ) {
+ $query .= " or itemtype=?";
+ push( @bind, $temp[$i] );
}
- $query.=")";
+ $query .= ")";
}
- my $sth=$dbh->prepare($query);
+ my $sth = $dbh->prepare($query);
+
# print $query;
$sth->execute(@bind);
- if (my $data2=$sth->fetchrow_hashref){
- my $dewey= $data2->{'dewey'};
- my $subclass=$data2->{'subclass'};
+ if ( my $data2 = $sth->fetchrow_hashref ) {
+ my $dewey = $data2->{'dewey'};
+ my $subclass = $data2->{'subclass'};
+
# FIXME - This next bit is bogus, because it assumes that the
# Dewey code is a floating-point number. It isn't. It's
# actually a string that mainly consists of numbers. In
@@ -689,33 +749,39 @@
# science") and should not be interpreted to mean "this
# database entry does not have a Dewey code". That's what
# NULL is for.
- $dewey=~s/\.*0*$//;
- ($dewey == 0) && ($dewey='');
- ($dewey) && ($dewey.=" $subclass") ;
+ $dewey =~ s/\.*0*$//;
+ ( $dewey == 0 ) && ( $dewey = '' );
+ ($dewey) && ( $dewey .= " $subclass" );
$sth->finish;
- my $end=$offset +$num;
- if ($i4 <= $offset){
+ my $end = $offset + $num;
+ if ( $i4 <= $offset ) {
$i4++;
}
-# print $i4;
- if ($i4 <=$end && $i4 > $offset){
- $data2->{'dewey'}=$dewey;
- $res2[$i3]=$data2;
+
+ # print $i4;
+ if ( $i4 <= $end && $i4 > $offset ) {
+ $data2->{'dewey'} = $dewey;
+ $res2[$i3] = $data2;
# $res2[$i3]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data2->{'copyrightdate'}\t$dewey";
$i3++;
$i4++;
-# print "in here $i3<br>";
- } else {
-# print $end;
+
+ # print "in here $i3<br>";
+ }
+ else {
+
+ # print $end;
}
$i++;
}
$i2++;
}
- $count=$i;
+ $count = $i;
+
+ }
+ else {
- } else {
# $search->{'class'} was not specified
# FIXME - This is bogus: it makes a separate query for each
@@ -725,30 +791,32 @@
# big query select all of the desired fields, instead of just
# 'biblionumber'.
- while ($i2 < $num && $i2 < $count){
- my $query="select * from biblio,biblioitems where
+ while ( $i2 < $num && $i2 < $count ) {
+ my $query = "select * from biblio,biblioitems where
biblio.biblionumber=? and
biblio.biblionumber=biblioitems.biblionumber ";
- my @bind=($res[$i2+$offset]);
+ my @bind = ( $res[ $i2 + $offset ] );
- if ($search->{'dewey'} ne ''){
- $query.= "and (dewey like ?)";
- push(@bind,"$search->{'dewey'}%");
+ if ( $search->{'dewey'} ne '' ) {
+ $query .= "and (dewey like ?)";
+ push( @bind, "$search->{'dewey'}%" );
}
- my $sth=$dbh->prepare($query);
-# print $query;
+ my $sth = $dbh->prepare($query);
+
+ # print $query;
$sth->execute(@bind);
- if (my $data2=$sth->fetchrow_hashref){
- my $dewey= $data2->{'dewey'};
- my $subclass=$data2->{'subclass'};
- $dewey=~s/\.*0*$//;
- ($dewey == 0) && ($dewey='');
- ($dewey) && ($dewey.=" $subclass") ;
+ if ( my $data2 = $sth->fetchrow_hashref ) {
+ my $dewey = $data2->{'dewey'};
+ my $subclass = $data2->{'subclass'};
+ $dewey =~ s/\.*0*$//;
+ ( $dewey == 0 ) && ( $dewey = '' );
+ ($dewey) && ( $dewey .= " $subclass" );
$sth->finish;
- $data2->{'dewey'}=$dewey;
+ $data2->{'dewey'} = $dewey;
+
+ $res2[$i] = $data2;
- $res2[$i]=$data2;
# $res2[$i]="$data2->{'author'}\t$data2->{'title'}\t$data2->{'biblionumber'}\t$data2->{'copyrightdate'}\t$dewey";
$i++;
}
@@ -758,8 +826,9 @@
}
#$count=$i;
- return($count, at res2);
+ return ( $count, @res2 );
}
+
=item CatSearch
($count, @results) = &CatSearch($env, $type, $search, $num, $offset);
@@ -917,20 +986,20 @@
#'
sub CatSearch {
- my ($env,$type,$search,$num,$offset)=@_;
+ my ( $env, $type, $search, $num, $offset ) = @_;
my $dbh = C4::Context->dbh;
my $query = '';
my @bind = ();
my @results;
- my $title = lc($search->{'title'});
+ my $title = lc( $search->{'title'} );
- if ($type eq 'loose') {
- if ($search->{'author'} ne ''){
- my @key=split(' ',$search->{'author'});
- my $count=@key;
- my $i=1;
- $query="select *,biblio.author,biblio.biblionumber from
+ if ( $type eq 'loose' ) {
+ if ( $search->{'author'} ne '' ) {
+ my @key = split( ' ', $search->{'author'} );
+ my $count = @key;
+ my $i = 1;
+ $query = "select *,biblio.author,biblio.biblionumber from
biblio
left join additionalauthors
on (additionalauthors.biblionumber =biblio.biblionumber)
@@ -939,54 +1008,56 @@
additionalauthors.author like ? or additionalauthors.author
like ?
)";
- @bind=("$key[0]%","% $key[0]%","$key[0]%","% $key[0]%");
- while ($i < $count){
+ @bind = ( "$key[0]%", "% $key[0]%", "$key[0]%", "% $key[0]%" );
+ while ( $i < $count ) {
$query .= " and (
biblio.author like ? or biblio.author like ? or
additionalauthors.author like ? or additionalauthors.author like ?
)";
- push(@bind,"$key[$i]%","% $key[$i]%","$key[$i]%","% $key[$i]%");
+ push( @bind,
+ "$key[$i]%", "% $key[$i]%", "$key[$i]%", "% $key[$i]%" );
$i++;
}
$query .= ")";
- if ($search->{'title'} ne ''){
- my @key=split(' ',$search->{'title'});
- my $count=@key;
- my $i=0;
- $query.= " and (((title like ? or title like ?)";
- push(@bind,"$key[0]%","% $key[0]%");
- while ($i<$count){
+ if ( $search->{'title'} ne '' ) {
+ my @key = split( ' ', $search->{'title'} );
+ my $count = @key;
+ my $i = 0;
+ $query .= " and (((title like ? or title like ?)";
+ push( @bind, "$key[0]%", "% $key[0]%" );
+ while ( $i < $count ) {
$query .= " and (title like ? or title like ?)";
- push(@bind,"$key[$i]%","% $key[$i]%");
+ push( @bind, "$key[$i]%", "% $key[$i]%" );
$i++;
}
- $query.=") or ((seriestitle like ? or seriestitle like ?)";
- push(@bind,"$key[0]%","% $key[0]%");
- for ($i=1;$i<$count;$i++){
- $query.=" and (seriestitle like ? or seriestitle like ?)";
- push(@bind,"$key[$i]%","% $key[$i]%");
- }
- $query.=") or ((unititle like ? or unititle like ?)";
- push(@bind,"$key[0]%","% $key[0]%");
- for ($i=1;$i<$count;$i++){
- $query.=" and (unititle like ? or unititle like ?)";
- push(@bind,"$key[$i]%","% $key[$i]%");
+ $query .= ") or ((seriestitle like ? or seriestitle like ?)";
+ push( @bind, "$key[0]%", "% $key[0]%" );
+ for ( $i = 1 ; $i < $count ; $i++ ) {
+ $query .= " and (seriestitle like ? or seriestitle like ?)";
+ push( @bind, "$key[$i]%", "% $key[$i]%" );
+ }
+ $query .= ") or ((unititle like ? or unititle like ?)";
+ push( @bind, "$key[0]%", "% $key[0]%" );
+ for ( $i = 1 ; $i < $count ; $i++ ) {
+ $query .= " and (unititle like ? or unititle like ?)";
+ push( @bind, "$key[$i]%", "% $key[$i]%" );
}
$query .= "))";
}
- if ($search->{'abstract'} ne ''){
- $query.= " and (abstract like ?)";
- push(@bind,"%$search->{'abstract'}%");
- }
- if ($search->{'date-before'} ne ''){
- $query.= " and (copyrightdate like ?)";
- push(@bind,"%$search->{'date-before'}%");
+ if ( $search->{'abstract'} ne '' ) {
+ $query .= " and (abstract like ?)";
+ push( @bind, "%$search->{'abstract'}%" );
+ }
+ if ( $search->{'date-before'} ne '' ) {
+ $query .= " and (copyrightdate like ?)";
+ push( @bind, "%$search->{'date-before'}%" );
}
- $query.=" group by biblio.biblionumber";
- } else {
- if ($search->{'title'} ne '') {
- if ($search->{'ttype'} eq 'exact'){
- $query="select * from biblio
+ $query .= " group by biblio.biblionumber";
+ }
+ else {
+ if ( $search->{'title'} ne '' ) {
+ if ( $search->{'ttype'} eq 'exact' ) {
+ $query = "select * from biblio
where
(biblio.title=? or (biblio.unititle = ?
or biblio.unititle like ? or
@@ -997,94 +1068,118 @@
biblio.seriestitle like ? or
biblio.seriestitle like ?)
)";
- @bind=($search->{'title'},$search->{'title'},"$search->{'title'} |%","%| $search->{'title'} |%","%| $search->{'title'}",$search->{'title'},"$search->{'title'} |%","%| $search->{'title'} |%","%| $search->{'title'}");
- } else {
- my @key=split(' ',$search->{'title'});
- my $count=@key;
- my $i=1;
- $query="select biblio.biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp,subtitle from biblio
+ @bind = (
+ $search->{'title'},
+ $search->{'title'},
+ "$search->{'title'} |%",
+ "%| $search->{'title'} |%",
+ "%| $search->{'title'}",
+ $search->{'title'},
+ "$search->{'title'} |%",
+ "%| $search->{'title'} |%",
+ "%| $search->{'title'}"
+ );
+ }
+ else {
+ my @key = split( ' ', $search->{'title'} );
+ my $count = @key;
+ my $i = 1;
+ $query =
+"select biblio.biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp,subtitle from biblio
left join bibliosubtitle on
(biblio.biblionumber=bibliosubtitle.biblionumber)
where
(((title like ? or title like ?)";
- @bind=("$key[0]%","% $key[0]%");
- while ($i<$count){
+ @bind = ( "$key[0]%", "% $key[0]%" );
+ while ( $i < $count ) {
$query .= " and (title like ? or title like ?)";
- push(@bind,"$key[$i]%","% $key[$i]%");
+ push( @bind, "$key[$i]%", "% $key[$i]%" );
$i++;
}
- $query.=") or ((subtitle like ? or subtitle like ?)";
- push(@bind,"$key[0]%","% $key[0]%");
- for ($i=1;$i<$count;$i++){
- $query.=" and (subtitle like ? or subtitle like ?)";
- push(@bind,"$key[$i]%","% $key[$i]%");
- }
- $query.=") or ((seriestitle like ? or seriestitle like ?)";
- push(@bind,"$key[0]%","% $key[0]%");
- for ($i=1;$i<$count;$i++){
- $query.=" and (seriestitle like ? or seriestitle like ?)";
- push(@bind,"$key[$i]%","% $key[$i]%");
- }
- $query.=") or ((unititle like ? or unititle like ?)";
- push(@bind,"$key[0]%","% $key[0]%");
- for ($i=1;$i<$count;$i++){
- $query.=" and (unititle like ? or unititle like ?)";
- push(@bind,"$key[$i]%","% $key[$i]%");
+ $query .= ") or ((subtitle like ? or subtitle like ?)";
+ push( @bind, "$key[0]%", "% $key[0]%" );
+ for ( $i = 1 ; $i < $count ; $i++ ) {
+ $query .= " and (subtitle like ? or subtitle like ?)";
+ push( @bind, "$key[$i]%", "% $key[$i]%" );
+ }
+ $query .=
+ ") or ((seriestitle like ? or seriestitle like ?)";
+ push( @bind, "$key[0]%", "% $key[0]%" );
+ for ( $i = 1 ; $i < $count ; $i++ ) {
+ $query .=
+ " and (seriestitle like ? or seriestitle like ?)";
+ push( @bind, "$key[$i]%", "% $key[$i]%" );
+ }
+ $query .= ") or ((unititle like ? or unititle like ?)";
+ push( @bind, "$key[0]%", "% $key[0]%" );
+ for ( $i = 1 ; $i < $count ; $i++ ) {
+ $query .= " and (unititle like ? or unititle like ?)";
+ push( @bind, "$key[$i]%", "% $key[$i]%" );
}
$query .= "))";
}
- if ($search->{'abstract'} ne ''){
- $query.= " and (abstract like ?)";
- push(@bind,"%$search->{'abstract'}%");
+ if ( $search->{'abstract'} ne '' ) {
+ $query .= " and (abstract like ?)";
+ push( @bind, "%$search->{'abstract'}%" );
}
- if ($search->{'date-before'} ne ''){
- $query.= " and (copyrightdate like ?)";
- push(@bind,"%$search->{'date-before'}%");
+ if ( $search->{'date-before'} ne '' ) {
+ $query .= " and (copyrightdate like ?)";
+ push( @bind, "%$search->{'date-before'}%" );
}
- } elsif ($search->{'dewey'} ne ''){
- $query="select * from biblioitems,biblio
+ }
+ elsif ( $search->{'dewey'} ne '' ) {
+ $query = "select * from biblioitems,biblio
where biblio.biblionumber=biblioitems.biblionumber
and biblioitems.dewey like ?";
- @bind=("$search->{'dewey'}%");
- } elsif ($search->{'illustrator'} ne '') {
- $query="select * from biblioitems,biblio
+ @bind = ("$search->{'dewey'}%");
+ }
+ elsif ( $search->{'illustrator'} ne '' ) {
+ $query = "select * from biblioitems,biblio
where biblio.biblionumber=biblioitems.biblionumber
and biblioitems.illus like ?";
- @bind=("%".$search->{'illustrator'}."%");
- } elsif ($search->{'publisher'} ne ''){
- $query = "Select * from biblio,biblioitems where biblio.biblionumber
+ @bind = ( "%" . $search->{'illustrator'} . "%" );
+ }
+ elsif ( $search->{'publisher'} ne '' ) {
+ $query =
+ "Select * from biblio,biblioitems where biblio.biblionumber
=biblioitems.biblionumber and (publishercode like ?)";
- @bind=("%$search->{'publisher'}%");
- } elsif ($search->{'abstract'} ne ''){
+ @bind = ("%$search->{'publisher'}%");
+ }
+ elsif ( $search->{'abstract'} ne '' ) {
$query = "Select * from biblio where abstract like ?";
- @bind=("%$search->{'abstract'}%");
- } elsif ($search->{'date-before'} ne ''){
+ @bind = ("%$search->{'abstract'}%");
+ }
+ elsif ( $search->{'date-before'} ne '' ) {
$query = "Select * from biblio where copyrightdate like ?";
- @bind=("%$search->{'date-before'}%");
- }elsif ($search->{'branch'} ne ''){
+ @bind = ("%$search->{'date-before'}%");
+ }
+ elsif ( $search->{'branch'} ne '' ) {
$query = "Select * from biblio,items where biblio.biblionumber
=items.biblionumber and holdingbranch like ?";
- @bind=("$search->{'branch'}");
- }elsif ($search->{'class'} ne ''){
- $query="select * from biblioitems,biblio where biblio.biblionumber=biblioitems.biblionumber";
+ @bind = ("$search->{'branch'}");
+ }
+ elsif ( $search->{'class'} ne '' ) {
+ $query =
+"select * from biblioitems,biblio where biblio.biblionumber=biblioitems.biblionumber";
- $query.= " where itemtype= ?";
- @bind=("$search->{'class'}");
+ $query .= " where itemtype= ?";
+ @bind = ("$search->{'class'}");
}
- $query .=" group by biblio.biblionumber";
+ $query .= " group by biblio.biblionumber";
}
}
- if ($type eq 'subject'){
- my @key=split(' ',$search->{'subject'});
- my $count=@key;
- my $i=1;
- $query="select * from bibliosubject, biblioitems where
+ if ( $type eq 'subject' ) {
+ my @key = split( ' ', $search->{'subject'} );
+ my $count = @key;
+ my $i = 1;
+ $query = "select * from bibliosubject, biblioitems where
(bibliosubject.biblionumber = biblioitems.biblionumber) and ( subject like ? or subject like ? or subject like ?)";
- @bind=("$key[0]%","% $key[0]%","%($key[0])%");
- while ($i<$count){
- $query.=" and (subject like ? or subject like ? or subject like ?)";
- push(@bind,"$key[$i]%","% $key[$i]%","%($key[$i])%");
+ @bind = ( "$key[0]%", "% $key[0]%", "%($key[0])%" );
+ while ( $i < $count ) {
+ $query .=
+ " and (subject like ? or subject like ? or subject like ?)";
+ push( @bind, "$key[$i]%", "% $key[$i]%", "%($key[$i])%" );
$i++;
}
@@ -1096,100 +1191,112 @@
# "New Zealand", "SF" a synonym for both "Science fiction" and
# "Fantastic fiction", etc.
- if (lc($search->{'subject'}) eq 'nz'){
- $query.= " or (subject like 'NEW ZEALAND %' or subject like '% NEW ZEALAND %'
+ if ( lc( $search->{'subject'} ) eq 'nz' ) {
+ $query .=
+" or (subject like 'NEW ZEALAND %' or subject like '% NEW ZEALAND %'
or subject like '% NEW ZEALAND' or subject like '%(NEW ZEALAND)%' ) ";
- } elsif ( $search->{'subject'} =~ /^nz /i || $search->{'subject'} =~ / nz /i || $search->{'subject'} =~ / nz$/i){
- $query=~ s/ nz/ NEW ZEALAND/ig;
- $query=~ s/nz /NEW ZEALAND /ig;
- $query=~ s/\(nz\)/\(NEW ZEALAND\)/gi;
}
+ elsif ($search->{'subject'} =~ /^nz /i
+ || $search->{'subject'} =~ / nz /i
+ || $search->{'subject'} =~ / nz$/i )
+ {
+ $query =~ s/ nz/ NEW ZEALAND/ig;
+ $query =~ s/nz /NEW ZEALAND /ig;
+ $query =~ s/\(nz\)/\(NEW ZEALAND\)/gi;
}
- if ($type eq 'precise'){
- if ($search->{'itemnumber'} ne ''){
- $query="select * from items,biblio ";
- my $search2=uc $search->{'itemnumber'};
- $query=$query." where
+ }
+ if ( $type eq 'precise' ) {
+ if ( $search->{'itemnumber'} ne '' ) {
+ $query = "select * from items,biblio ";
+ my $search2 = uc $search->{'itemnumber'};
+ $query = $query . " where
items.biblionumber=biblio.biblionumber
and barcode=?";
- @bind=($search2);
+ @bind = ($search2);
+
# FIXME - .= <<EOT;
}
- if ($search->{'isbn'} ne ''){
+ if ( $search->{'isbn'} ne '' ) {
$query = "Select * from biblio,biblioitems where biblio.biblionumber
=biblioitems.biblionumber and (isbn like ?)";
- @bind=("$search->{'isbn'}%");
+ @bind = ("$search->{'isbn'}%");
}
}
- if ($type ne 'precise' && $type ne 'subject'){
- if ($search->{'author'} ne ''){
+ if ( $type ne 'precise' && $type ne 'subject' ) {
+ if ( $search->{'author'} ne '' ) {
$query .= " order by biblio.author,title";
- } else {
+ }
+ else {
$query .= " order by title";
}
- } else {
- if ($type eq 'subject'){
+ }
+ else {
+ if ( $type eq 'subject' ) {
$query .= " group by subject ";
}
}
- my $sth=$dbh->prepare($query);
+ my $sth = $dbh->prepare($query);
$sth->execute(@bind);
- my $count=1;
- my $i=0;
- my $limit= $num+$offset;
- while (my $data=$sth->fetchrow_hashref){
- my $query="select classification,dewey,subclass,publishercode from biblioitems where biblionumber=?";
- my @bind=($data->{'biblionumber'});
- if ($search->{'class'} ne ''){
- my @temp=split(/\|/,$search->{'class'});
- my $count=@temp;
- $query.= " and ( itemtype= ?";
- push(@bind,$temp[0]);
- for (my $i=1;$i<$count;$i++){
- $query.=" or itemtype=?";
- push(@bind,$temp[$i]);
- }
- $query.=")";
- }
- if ($search->{'dewey'} ne ''){
- $query.=" and dewey=? ";
- push(@bind,$search->{'dewey'});
- }
- if ($search->{'illustrator'} ne ''){
- $query.=" and illus like ?";
- push(@bind,"%$search->{'illustrator'}%");
- }
- if ($search->{'publisher'} ne ''){
- $query.= " and (publishercode like ?)";
- push(@bind,"%$search->{'publisher'}%");
+ my $count = 1;
+ my $i = 0;
+ my $limit = $num + $offset;
+ while ( my $data = $sth->fetchrow_hashref ) {
+ my $query =
+"select classification,dewey,subclass,publishercode from biblioitems where biblionumber=?";
+ my @bind = ( $data->{'biblionumber'} );
+ if ( $search->{'class'} ne '' ) {
+ my @temp = split( /\|/, $search->{'class'} );
+ my $count = @temp;
+ $query .= " and ( itemtype= ?";
+ push( @bind, $temp[0] );
+ for ( my $i = 1 ; $i < $count ; $i++ ) {
+ $query .= " or itemtype=?";
+ push( @bind, $temp[$i] );
+ }
+ $query .= ")";
}
- my $sti=$dbh->prepare($query);
+ if ( $search->{'dewey'} ne '' ) {
+ $query .= " and dewey=? ";
+ push( @bind, $search->{'dewey'} );
+ }
+ if ( $search->{'illustrator'} ne '' ) {
+ $query .= " and illus like ?";
+ push( @bind, "%$search->{'illustrator'}%" );
+ }
+ if ( $search->{'publisher'} ne '' ) {
+ $query .= " and (publishercode like ?)";
+ push( @bind, "%$search->{'publisher'}%" );
+ }
+ my $sti = $dbh->prepare($query);
$sti->execute(@bind);
my $classification;
my $dewey;
my $subclass;
- my $true=0;
+ my $true = 0;
my $publishercode;
my $bibitemdata;
- if ($bibitemdata = $sti->fetchrow_hashref()){
- $true=1;
- $classification=$bibitemdata->{'classification'};
- $dewey=$bibitemdata->{'dewey'};
- $subclass=$bibitemdata->{'subclass'};
- $publishercode=$bibitemdata->{'publishercode'};
+
+ if ( $bibitemdata = $sti->fetchrow_hashref() ) {
+ $true = 1;
+ $classification = $bibitemdata->{'classification'};
+ $dewey = $bibitemdata->{'dewey'};
+ $subclass = $bibitemdata->{'subclass'};
+ $publishercode = $bibitemdata->{'publishercode'};
}
+
# print STDERR "$dewey $subclass $publishercode\n";
# FIXME - The Dewey code is a string, not a number.
- $dewey=~s/\.*0*$//;
- ($dewey == 0) && ($dewey='');
- ($dewey) && ($dewey.=" $subclass");
- $data->{'classification'}=$classification;
- $data->{'dewey'}=$dewey;
- $data->{'publishercode'}=$publishercode;
+ $dewey =~ s/\.*0*$//;
+ ( $dewey == 0 ) && ( $dewey = '' );
+ ($dewey) && ( $dewey .= " $subclass" );
+ $data->{'classification'} = $classification;
+ $data->{'dewey'} = $dewey;
+ $data->{'publishercode'} = $publishercode;
$sti->finish;
- if ($true == 1){
- if ($count > $offset && $count <= $limit){
- $results[$i]=$data;
+
+ if ( $true == 1 ) {
+ if ( $count > $offset && $count <= $limit ) {
+ $results[$i] = $data;
$i++;
}
$count++;
@@ -1197,7 +1304,7 @@
}
$sth->finish;
$count--;
- return($count, at results);
+ return ( $count, @results );
}
=item ItemInfo
@@ -1250,77 +1357,101 @@
#'
sub ItemInfo {
- my ($env,$biblionumber,$type) = @_;
+ my ( $env, $biblionumber, $type ) = @_;
my $dbh = C4::Context->dbh;
- my $query = "SELECT *,items.notforloan as itemnotforloan FROM items, biblio, biblioitems
+ my $query =
+"SELECT *,items.notforloan as itemnotforloan FROM items, biblio, biblioitems
left join itemtypes on (biblioitems.itemtype = itemtypes.itemtype)
WHERE items.biblionumber = ?
AND biblioitems.biblioitemnumber = items.biblioitemnumber
AND biblio.biblionumber = items.biblionumber";
$query .= " order by items.dateaccessioned desc";
- my $sth=$dbh->prepare($query);
+ my $sth = $dbh->prepare($query);
$sth->execute($biblionumber);
- my $i=0;
+ my $i = 0;
my @results;
- my ($date_due, $count_reserves);
- while (my $data=$sth->fetchrow_hashref){
+ my ( $date_due, $count_reserves );
+
+ while ( my $data = $sth->fetchrow_hashref ) {
my $datedue = '';
- my $isth=$dbh->prepare("Select issues.*,borrowers.cardnumber from issues,borrowers where itemnumber = ? and returndate is null and issues.borrowernumber=borrowers.borrowernumber");
- $isth->execute($data->{'itemnumber'});
- if (my $idata=$isth->fetchrow_hashref){
+ my $isth =
+ $dbh->prepare(
+"Select issues.*,borrowers.cardnumber from issues,borrowers where itemnumber = ? and returndate is null and issues.borrowernumber=borrowers.borrowernumber"
+ );
+ $isth->execute( $data->{'itemnumber'} );
+ if ( my $idata = $isth->fetchrow_hashref ) {
$data->{borrowernumber} = $idata->{borrowernumber};
$data->{cardnumber} = $idata->{cardnumber};
$datedue = $idata->{'date_due'}; #format_date($idata->{'date_due'});
}
- if ($datedue eq ''){
+ if ( $datedue eq '' ) {
+
# $datedue="Available";
- my ($restype,$reserves)=C4::Reserves2::CheckReserves($data->{'itemnumber'});
+ my ( $restype, $reserves ) =
+ C4::Reserves2::CheckReserves( $data->{'itemnumber'} );
if ($restype) {
-# $datedue=$restype;
+
+ # $datedue=$restype;
$count_reserves = $restype;
}
}
$isth->finish;
+
#get branch information.....
- my $bsth=$dbh->prepare("SELECT * FROM branches WHERE branchcode = ?");
- $bsth->execute($data->{'holdingbranch'});
- if (my $bdata=$bsth->fetchrow_hashref){
+ my $bsth = $dbh->prepare("SELECT * FROM branches WHERE branchcode = ?");
+ $bsth->execute( $data->{'holdingbranch'} );
+ if ( my $bdata = $bsth->fetchrow_hashref ) {
$data->{'branchname'} = $bdata->{'branchname'};
}
- my $date=$data->{'datelastseen'}; #format_date($data->{'datelastseen'});
- $data->{'datelastseen'}=$date;
- $data->{'datedue'}=$datedue;
+ my $date =
+ $data->{'datelastseen'}; #format_date($data->{'datelastseen'});
+ $data->{'datelastseen'} = $date;
+ $data->{'datedue'} = $datedue;
$data->{'count_reserves'} = $count_reserves;
+
# get notforloan complete status if applicable
- my $sthnflstatus = $dbh->prepare('select authorised_value from marc_subfield_structure where kohafield="items.notforloan"');
+ my $sthnflstatus =
+ $dbh->prepare(
+'select authorised_value from marc_subfield_structure where kohafield="items.notforloan"'
+ );
$sthnflstatus->execute;
my ($authorised_valuecode) = $sthnflstatus->fetchrow;
if ($authorised_valuecode) {
- $sthnflstatus = $dbh->prepare("select lib from authorised_values where category=? and authorised_value=?");
- $sthnflstatus->execute($authorised_valuecode,$data->{itemnotforloan});
+ $sthnflstatus =
+ $dbh->prepare(
+"select lib from authorised_values where category=? and authorised_value=?"
+ );
+ $sthnflstatus->execute( $authorised_valuecode,
+ $data->{itemnotforloan} );
my ($lib) = $sthnflstatus->fetchrow;
$data->{notforloan} = $lib;
}
-# my stack procedures
+ # my stack procedures
- my $stackstatus = $dbh->prepare('select authorised_value from marc_subfield_structure where kohafield="items.stack"');
+ my $stackstatus =
+ $dbh->prepare(
+'select authorised_value from marc_subfield_structure where kohafield="items.stack"'
+ );
$stackstatus->execute;
($authorised_valuecode) = $stackstatus->fetchrow;
if ($authorised_valuecode) {
- $stackstatus = $dbh->prepare("select lib from authorised_values where category=? and authorised_value=?");
- $stackstatus->execute($authorised_valuecode,$data->{stack});
+ $stackstatus =
+ $dbh->prepare(
+"select lib from authorised_values where category=? and authorised_value=?"
+ );
+ $stackstatus->execute( $authorised_valuecode, $data->{stack} );
my ($lib) = $stackstatus->fetchrow;
$data->{stack} = $lib;
}
- $results[$i]=$data;
+ $results[$i] = $data;
$i++;
}
$sth->finish;
- return(@results);
+ return (@results);
}
=item GetItems
@@ -1345,33 +1476,37 @@
#'
sub GetItems {
- my ($env,$biblionumber)=@_;
+ my ( $env, $biblionumber ) = @_;
+
#debug_msg($env,"GetItems");
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("Select * from biblioitems where (biblionumber = ?)");
+ my $sth =
+ $dbh->prepare("Select * from biblioitems where (biblionumber = ?)");
$sth->execute($biblionumber);
+
#debug_msg($env,"executed query");
- my $i=0;
+ my $i = 0;
my @results;
- while (my $data=$sth->fetchrow_hashref) {
- print ($env,$data->{'biblioitemnumber'});
+ while ( my $data = $sth->fetchrow_hashref ) {
+ print( $env, $data->{'biblioitemnumber'} );
my $dewey = $data->{'dewey'};
$dewey =~ s/0+$//;
- my $isbn= $data->{'isbn'};
+ my $isbn = $data->{'isbn'};
-
- my $line = $data->{'biblioitemnumber'}."\t".$data->{'itemtype'};
+ my $line = $data->{'biblioitemnumber'} . "\t" . $data->{'itemtype'};
$line .= "\t$data->{'classification'}\t$dewey";
$line .= "\t$data->{'subclass'}\t$data->{'isbn'}";
$line .= "\t$data->{'volume'}\t$data->{number}";
- my $isth= $dbh->prepare("select * from items where biblioitemnumber = ?");
- $isth->execute($data->{'biblioitemnumber'});
- while (my $idata = $isth->fetchrow_hashref) {
- my $iline = $idata->{'barcode'}."[".$idata->{'holdingbranch'}."[";
- if ($idata->{'notforloan'} == 1) {
+ my $isth =
+ $dbh->prepare("select * from items where biblioitemnumber = ?");
+ $isth->execute( $data->{'biblioitemnumber'} );
+ while ( my $idata = $isth->fetchrow_hashref ) {
+ my $iline =
+ $idata->{'barcode'} . "[" . $idata->{'holdingbranch'} . "[";
+ if ( $idata->{'notforloan'} == 1 ) {
$iline .= "NFL ";
}
- if ($idata->{'itemlost'} == 1) {
+ if ( $idata->{'itemlost'} == 1 ) {
$iline .= "LOST ";
}
$line .= "\t$iline";
@@ -1381,7 +1516,7 @@
$i++;
}
$sth->finish;
- return(@results);
+ return (@results);
}
=item itemdata
@@ -1397,14 +1532,16 @@
#'
sub itemdata {
- my ($barcode)=@_;
+ my ($barcode) = @_;
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("Select * from items,biblioitems where barcode=?
- and items.biblioitemnumber=biblioitems.biblioitemnumber");
+ my $sth = $dbh->prepare(
+ "Select * from items,biblioitems where barcode=?
+ and items.biblioitemnumber=biblioitems.biblioitemnumber"
+ );
$sth->execute($barcode);
- my $data=$sth->fetchrow_hashref;
+ my $data = $sth->fetchrow_hashref;
$sth->finish;
- return($data);
+ return ($data);
}
=item bibdata
@@ -1429,7 +1566,7 @@
#'
sub bibdata {
- my ($bibnum, $type) = @_;
+ my ( $bibnum, $type ) = @_;
my $dbh = C4::Context->dbh;
my $query = "
@@ -1446,11 +1583,12 @@
my $data;
$data = $sth->fetchrow_hashref;
$sth->finish;
+
# handle management of repeated subtitle
$sth = $dbh->prepare("Select * from bibliosubtitle where biblionumber = ?");
$sth->execute($bibnum);
my @subtitles;
- while (my $dat = $sth->fetchrow_hashref){
+ while ( my $dat = $sth->fetchrow_hashref ) {
my %line;
$line{subtitle} = $dat->{subtitle};
push @subtitles, \%line;
@@ -1460,23 +1598,24 @@
$sth = $dbh->prepare("Select * from bibliosubject where biblionumber = ?");
$sth->execute($bibnum);
my @subjects;
- while (my $dat = $sth->fetchrow_hashref){
+ while ( my $dat = $sth->fetchrow_hashref ) {
my %line;
$line{subject} = $dat->{'subject'};
push @subjects, \%line;
} # while
$data->{subjects} = \@subjects;
$sth->finish;
- $sth = $dbh->prepare("Select * from additionalauthors where biblionumber = ?");
+ $sth =
+ $dbh->prepare("Select * from additionalauthors where biblionumber = ?");
$sth->execute($bibnum);
- while (my $dat = $sth->fetchrow_hashref){
+ while ( my $dat = $sth->fetchrow_hashref ) {
$data->{'additionalauthors'} .= "$dat->{'author'} - ";
} # while
chop $data->{'additionalauthors'};
chop $data->{'additionalauthors'};
chop $data->{'additionalauthors'};
$sth->finish;
- return($data);
+ return ($data);
} # sub bibdata
=item subject
@@ -1492,18 +1631,18 @@
#'
sub subject {
- my ($bibnum)=@_;
+ my ($bibnum) = @_;
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("Select * from bibliosubject where biblionumber=?");
+ my $sth = $dbh->prepare("Select * from bibliosubject where biblionumber=?");
$sth->execute($bibnum);
my @results;
- my $i=0;
- while (my $data=$sth->fetchrow_hashref){
- $results[$i]=$data;
+ my $i = 0;
+ while ( my $data = $sth->fetchrow_hashref ) {
+ $results[$i] = $data;
$i++;
}
$sth->finish;
- return($i,\@results);
+ return ( $i, \@results );
}
=item addauthor
@@ -1521,18 +1660,19 @@
#'
sub addauthor {
- my ($bibnum)=@_;
+ my ($bibnum) = @_;
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("Select * from additionalauthors where biblionumber=?");
+ my $sth =
+ $dbh->prepare("Select * from additionalauthors where biblionumber=?");
$sth->execute($bibnum);
my @results;
- my $i=0;
- while (my $data=$sth->fetchrow_hashref){
- $results[$i]=$data;
+ my $i = 0;
+ while ( my $data = $sth->fetchrow_hashref ) {
+ $results[$i] = $data;
$i++;
}
$sth->finish;
- return($i,\@results);
+ return ( $i, \@results );
}
=item subtitle
@@ -1549,18 +1689,19 @@
#'
sub subtitle {
- my ($bibnum)=@_;
+ my ($bibnum) = @_;
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("Select * from bibliosubtitle where biblionumber=?");
+ my $sth =
+ $dbh->prepare("Select * from bibliosubtitle where biblionumber=?");
$sth->execute($bibnum);
my @results;
- my $i=0;
- while (my $data=$sth->fetchrow_hashref){
- $results[$i]=$data;
+ my $i = 0;
+ while ( my $data = $sth->fetchrow_hashref ) {
+ $results[$i] = $data;
$i++;
}
$sth->finish;
- return($i,\@results);
+ return ( $i, \@results );
}
=item itemissues
@@ -1609,20 +1750,24 @@
#'
sub itemissues {
- my ($bibitem, $biblio)=@_;
+ my ( $bibitem, $biblio ) = @_;
my $dbh = C4::Context->dbh;
+
# FIXME - If this function die()s, the script will abort, and the
# user won't get anything; depending on how far the script has
# gotten, the user might get a blank page. It would be much better
# to at least print an error message. The easiest way to do this
# is to set $SIG{__DIE__}.
- my $sth = $dbh->prepare("Select * from items where items.biblioitemnumber = ?") || die $dbh->errstr;
+ my $sth =
+ $dbh->prepare("Select * from items where items.biblioitemnumber = ?")
+ || die $dbh->errstr;
my $i = 0;
my @results;
$sth->execute($bibitem) || die $sth->errstr;
- while (my $data = $sth->fetchrow_hashref) {
+ while ( my $data = $sth->fetchrow_hashref ) {
+
# Find out who currently has this item.
# FIXME - Wouldn't it be better to do this as a left join of
# some sort? Currently, this code assumes that if
@@ -1630,20 +1775,24 @@
# fetchrow_hashref() can fail for any number of reasons (e.g.,
# database server crash), not just because no items match the
# search criteria.
- my $sth2 = $dbh->prepare("select * from issues,borrowers
+ my $sth2 = $dbh->prepare(
+ "select * from issues,borrowers
where itemnumber = ?
and returndate is NULL
-and issues.borrowernumber = borrowers.borrowernumber");
+and issues.borrowernumber = borrowers.borrowernumber"
+ );
- $sth2->execute($data->{'itemnumber'});
- if (my $data2 = $sth2->fetchrow_hashref) {
+ $sth2->execute( $data->{'itemnumber'} );
+ if ( my $data2 = $sth2->fetchrow_hashref ) {
$data->{'date_due'} = $data2->{'date_due'};
$data->{'card'} = $data2->{'cardnumber'};
$data->{'borrower'} = $data2->{'borrowernumber'};
- } else {
- if ($data->{'wthdrawn'} eq '1') {
+ }
+ else {
+ if ( $data->{'wthdrawn'} eq '1' ) {
$data->{'date_due'} = 'Cancelled';
- } else {
+ }
+ else {
$data->{'date_due'} = 'Available';
} # else
} # else
@@ -1651,14 +1800,27 @@
$sth2->finish;
# Find the last 3 people who borrowed this item.
- $sth2 = $dbh->prepare("select * from issues, borrowers
+ $sth2 = $dbh->prepare(
+ "select * from issues, borrowers
where itemnumber = ?
and issues.borrowernumber = borrowers.borrowernumber
and returndate is not NULL
- order by returndate desc,timestamp desc") ;
- $sth2->execute($data->{'itemnumber'}) ;
- for (my $i2 = 0; $i2 < 2; $i2++) { # FIXME : error if there is less than 3 pple borrowing this item
- if (my $data2 = $sth2->fetchrow_hashref) {
+ order by returndate desc,timestamp desc"
+ );
+
+# $sth2 = $dbh->prepare("
+# SELECT *
+# FROM issues
+# LEFT JOIN borrowers ON issues.borrowernumber = borrowers.borrowernumber
+# WHERE itemnumber = ?
+# AND returndate is not NULL
+# ORDER BY returndate DESC,timestamp DESC
+# ");
+
+ $sth2->execute( $data->{'itemnumber'} );
+ for ( my $i2 = 0 ; $i2 < 2 ; $i2++ )
+ { # FIXME : error if there is less than 3 pple borrowing this item
+ if ( my $data2 = $sth2->fetchrow_hashref ) {
$data->{"timestamp$i2"} = $data2->{'timestamp'};
$data->{"card$i2"} = $data2->{'cardnumber'};
$data->{"borrower$i2"} = $data2->{'borrowernumber'};
@@ -1671,7 +1833,7 @@
}
$sth->finish;
- return(@results);
+ return (@results);
}
=item itemnodata
@@ -1690,17 +1852,20 @@
#'
sub itemnodata {
- my ($env,$dbh,$itemnumber) = @_;
+ my ( $env, $dbh, $itemnumber ) = @_;
$dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("Select * from biblio,items,biblioitems
+ my $sth = $dbh->prepare(
+ "Select * from biblio,items,biblioitems
where items.itemnumber = ?
and biblio.biblionumber = items.biblionumber
- and biblioitems.biblioitemnumber = items.biblioitemnumber");
-# print $query;
+ and biblioitems.biblioitemnumber = items.biblioitemnumber"
+ );
+
+ # print $query;
$sth->execute($itemnumber);
- my $data=$sth->fetchrow_hashref;
+ my $data = $sth->fetchrow_hashref;
$sth->finish;
- return($data);
+ return ($data);
}
=item BornameSearch
@@ -1730,48 +1895,57 @@
#used by member enquiries from the intranet
#called by member.pl
sub BornameSearch {
- my ($env,$searchstring,$orderby,$type)=@_;
+ my ( $env, $searchstring, $orderby, $type ) = @_;
my $dbh = C4::Context->dbh;
- my $query = ""; my $count; my @data;
- my @bind=();
+ my $query = "";
+ my $count;
+ my @data;
+ my @bind = ();
- if($type eq "simple") # simple search for one letter only
+ if ( $type eq "simple" ) # simple search for one letter only
{
- $query="Select * from borrowers where surname like '$searchstring%' order by $orderby";
-# @bind=("$searchstring%");
+ $query =
+"Select * from borrowers where surname like '$searchstring%' order by $orderby";
+
+ # @bind=("$searchstring%");
}
else # advanced search looking in surname, firstname and othernames
{
### Try to determine whether numeric like cardnumber
- if ($searchstring+1>1) {
- $query="Select * from borrowers where cardnumber like '$searchstring%' ";
+ if ( $searchstring + 1 > 1 ) {
+ $query =
+"Select * from borrowers where cardnumber like '$searchstring%' ";
- }else{
+ }
+ else {
- my @words=split / /,$searchstring;
- foreach my $word(@words){
- $word="+".$word;
+ my @words = split / /, $searchstring;
+ foreach my $word (@words) {
+ $word = "+" . $word;
}
- $searchstring=join " ", at words;
+ $searchstring = join " ", @words;
- $query="Select * from borrowers where MATCH(surname,firstname,othernames) AGAINST('$searchstring' in boolean mode)";
+ $query =
+"Select * from borrowers where MATCH(surname,firstname,othernames) AGAINST('$searchstring' in boolean mode)";
}
- $query=$query." order by $orderby";
+ $query = $query . " order by $orderby";
}
- my $sth=$dbh->prepare($query);
-# warn "Q $orderby : $query";
+ my $sth = $dbh->prepare($query);
+
+ # warn "Q $orderby : $query";
$sth->execute();
my @results;
- my $cnt=$sth->rows;
- while (my $data=$sth->fetchrow_hashref){
- push(@results,$data);
+ my $cnt = $sth->rows;
+ while ( my $data = $sth->fetchrow_hashref ) {
+ push( @results, $data );
}
+
# $sth->execute;
$sth->finish;
- return ($cnt,\@results);
+ return ( $cnt, \@results );
}
=item getboracctrecord
@@ -1794,297 +1968,36 @@
#'
sub getboracctrecord {
- my ($env,$params) = @_;
+ my ( $env, $params ) = @_;
my $dbh = C4::Context->dbh;
my @acctlines;
- my $numlines=0;
- my $sth=$dbh->prepare("Select * from accountlines where
-borrowernumber=? order by date desc,timestamp desc");
-# print $query;
- $sth->execute($params->{'borrowernumber'});
- my $total=0;
- while (my $data=$sth->fetchrow_hashref){
+ my $numlines = 0;
+ my $sth = $dbh->prepare(
+ "Select * from accountlines where
+borrowernumber=? order by date desc,timestamp desc"
+ );
+
+ # print $query;
+ $sth->execute( $params->{'borrowernumber'} );
+ my $total = 0;
+ while ( my $data = $sth->fetchrow_hashref ) {
+
#FIXME before reinstating: insecure?
-# if ($data->{'itemnumber'} ne ''){
-# $query="Select * from items,biblio where items.itemnumber=
-# '$data->{'itemnumber'}' and biblio.biblionumber=items.biblionumber";
-# my $sth2=$dbh->prepare($query);
-# $sth2->execute;
-# my $data2=$sth2->fetchrow_hashref;
-# $sth2->finish;
-# $data=$data2;
+ # if ($data->{'itemnumber'} ne ''){
+ # $query="Select * from items,biblio where items.itemnumber=
+ # '$data->{'itemnumber'}' and biblio.biblionumber=items.biblionumber";
+ # my $sth2=$dbh->prepare($query);
+ # $sth2->execute;
+ # my $data2=$sth2->fetchrow_hashref;
+ # $sth2->finish;
+ # $data=$data2;
# }
$acctlines[$numlines] = $data;
$numlines++;
$total += $data->{'amountoutstanding'};
}
$sth->finish;
- return ($numlines,\@acctlines,$total);
-}
-
-=item itemcount
-
- ($count, $lcount, $nacount, $fcount, $scount, $lostcount,
- $mending, $transit,$ocount) =
- &itemcount($env, $biblionumber, $type);
-
-Counts the number of items with the given biblionumber, broken down by
-category.
-
-C<$env> is ignored.
-
-If C<$type> is not set to C<intra>, lost, very overdue, and withdrawn
-items will not be counted.
-
-C<&itemcount> returns a nine-element list:
-
-C<$count> is the total number of items with the given biblionumber.
-
-C<$lcount> is the number of items at the Levin branch.
-
-C<$nacount> is the number of items that are neither borrowed, lost,
-nor withdrawn (and are therefore presumably on a shelf somewhere).
-
-C<$fcount> is the number of items at the Foxton branch.
-
-C<$scount> is the number of items at the Shannon branch.
-
-C<$lostcount> is the number of lost and very overdue items.
-
-C<$mending> is the number of items at the Mending branch (being
-mended?).
-
-C<$transit> is the number of items at the Transit branch (in transit
-between branches?).
-
-C<$ocount> is the number of items that haven't arrived yet
-(aqorders.quantity - aqorders.quantityreceived).
-
-=cut
-
-#'
-
-# FIXME - There's also a &C4::Biblio::itemcount.
-# Since they're all exported, acqui/acquire.pl doesn't compile with -w.
-sub itemcount {
- my ($env,$bibnum,$type)=@_;
- my $dbh = C4::Context->dbh;
- my $query="Select * from items where
- biblionumber=? ";
- if ($type ne 'intra'){
- $query.=" and ((itemlost <>1 and itemlost <> 2) or itemlost is NULL) and
- (wthdrawn <> 1 or wthdrawn is NULL)";
- }
- my $sth=$dbh->prepare($query);
- # print $query;
- $sth->execute($bibnum);
- my $count=0;
- my $lcount=0;
- my $nacount=0;
- my $fcount=0;
- my $scount=0;
- my $lostcount=0;
- my $mending=0;
- my $transit=0;
- my $ocount=0;
- while (my $data=$sth->fetchrow_hashref){
- $count++;
-
- my $sth2=$dbh->prepare("select * from issues,items where issues.itemnumber=
- ? and returndate is NULL
- and items.itemnumber=issues.itemnumber and ((items.itemlost <>1 and
- items.itemlost <> 2) or items.itemlost is NULL)
- and (wthdrawn <> 1 or wthdrawn is NULL)");
- $sth2->execute($data->{'itemnumber'});
- if (my $data2=$sth2->fetchrow_hashref){
- $nacount++;
- } else {
- if ($data->{'holdingbranch'} eq 'C' || $data->{'holdingbranch'} eq 'LT'){
- $lcount++;
- }
- if ($data->{'holdingbranch'} eq 'F' || $data->{'holdingbranch'} eq 'FP'){
- $fcount++;
- }
- if ($data->{'holdingbranch'} eq 'S' || $data->{'holdingbranch'} eq 'SP'){
- $scount++;
- }
- if ($data->{'itemlost'} eq '1'){
- $lostcount++;
- }
- if ($data->{'itemlost'} eq '2'){
- $lostcount++;
- }
- if ($data->{'holdingbranch'} eq 'FM'){
- $mending++;
- }
- if ($data->{'holdingbranch'} eq 'TR'){
- $transit++;
- }
- }
- $sth2->finish;
- }
-# if ($count == 0){
- my $sth2=$dbh->prepare("Select * from aqorders where biblionumber=?");
- $sth2->execute($bibnum);
- if (my $data=$sth2->fetchrow_hashref){
- $ocount=$data->{'quantity'} - $data->{'quantityreceived'};
- }
-# $count+=$ocount;
- $sth2->finish;
- $sth->finish;
- return ($count,$lcount,$nacount,$fcount,$scount,$lostcount,$mending,$transit,$ocount);
-}
-
-=item itemcount2
-
- $counts = &itemcount2($env, $biblionumber, $type);
-
-Counts the number of items with the given biblionumber, broken down by
-category.
-
-C<$env> is ignored.
-
-C<$type> may be either C<intra> or anything else. If it is not set to
-C<intra>, then the search will exclude lost, very overdue, and
-withdrawn items.
-
-C<$&itemcount2> returns a reference-to-hash, with the following fields:
-
-=over 4
-
-=item C<total>
-
-The total number of items with this biblionumber.
-
-=item C<order>
-
-The number of items on order (aqorders.quantity -
-aqorders.quantityreceived).
-
-=item I<branchname>
-
-For each branch that has at least one copy of the book, C<$counts>
-will have a key with the branch name, giving the number of copies at
-that branch.
-
-=back
-
-=cut
-
-#'
-sub itemcount2 {
- my ($env,$bibnum,$type)=@_;
- my $dbh = C4::Context->dbh;
- my $query="Select * from items,branches where
- biblionumber=? and items.holdingbranch=branches.branchcode";
- if ($type ne 'intra'){
- $query.=" and ((itemlost <>1 and itemlost <> 2) or itemlost is NULL) and
- (wthdrawn <> 1 or wthdrawn is NULL)";
- }
- my $sth=$dbh->prepare($query);
- # print $query;
- $sth->execute($bibnum);
- my %counts;
- $counts{'total'}=0;
- while (my $data=$sth->fetchrow_hashref){
- $counts{'total'}++;
- my $status;
- for my $test (
- [
- 'Item Lost',
- 'select * from items
- where itemnumber=?
- and not ((items.itemlost <>1 and items.itemlost <> 2)
- or items.itemlost is NULL)'
- ], [
- 'Withdrawn',
- 'select * from items
- where itemnumber=? and not (wthdrawn <> 1 or wthdrawn is NULL)'
- ], [
- 'On Loan', "select * from issues,items
- where issues.itemnumber=? and returndate is NULL
- and items.itemnumber=issues.itemnumber"
- ],
- ) {
- my($testlabel, $query2) = @$test;
-
- my $sth2=$dbh->prepare($query2);
- $sth2->execute($data->{'itemnumber'});
-
- # FIXME - fetchrow_hashref() can fail for any number of reasons
- # (e.g., a database server crash). Perhaps use a left join of some
- # sort for this?
- $status = $testlabel if $sth2->fetchrow_hashref;
- $sth2->finish;
- last if defined $status;
- }
-## find the shelving name from stack
-my $stackstatus = $dbh->prepare('select authorised_value from marc_subfield_structure where kohafield="items.stack"');
- $stackstatus->execute;
-
- my ($authorised_valuecode) = $stackstatus->fetchrow;
- if ($authorised_valuecode) {
- $stackstatus = $dbh->prepare("select lib from authorised_values where category=? and authorised_value=?");
- $stackstatus->execute($authorised_valuecode,$data->{stack});
-
- my ($lib) = $stackstatus->fetchrow;
- $data->{stack} = $lib;
- }
-
-
- $status = $data->{'branchname'}."[".$data->{'stack'}."]" unless defined $status;
- $counts{$status}++;
-
- }
- my $sth2=$dbh->prepare("Select * from aqorders where biblionumber=? and
- datecancellationprinted is NULL and quantity > quantityreceived");
- $sth2->execute($bibnum);
- if (my $data=$sth2->fetchrow_hashref){
- $counts{'order'}=$data->{'quantity'} - $data->{'quantityreceived'};
- }
- $sth2->finish;
- $sth->finish;
- return (\%counts);
-}
-
-=item ItemType
-
- $description = &ItemType($itemtype);
-
-Given an item type code, returns the description for that type.
-
-=cut
-
-#'
-
-# FIXME - I'm pretty sure that after the initial setup, the list of
-# item types doesn't change very often. Hence, it seems slow and
-# inefficient to make yet another database call to look up information
-# that'll only change every few months or years.
-#
-# Much better, I think, to automatically build a Perl file that can be
-# included in those scripts that require it, e.g.:
-# @itemtypes = qw( ART BCD CAS CD F ... );
-# %itemtypedesc = (
-# ART => "Art Prints",
-# BCD => "CD-ROM from book",
-# CD => "Compact disc (WN)",
-# F => "Free Fiction",
-# ...
-# );
-# The web server can then run a cron job to rebuild this file from the
-# database every hour or so.
-#
-# The same thing goes for branches, book funds, book sellers, currency
-# rates, printers, stopwords, and perhaps others.
-sub ItemType {
- my ($type)=@_;
- my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("select description from itemtypes where itemtype=?");
- $sth->execute($type);
- my $dat=$sth->fetchrow_hashref;
- $sth->finish;
- return ($dat->{'description'});
+ return ( $numlines, \@acctlines, $total );
}
=item bibitems
@@ -2109,7 +2022,8 @@
sub bibitems {
my ($bibnum) = @_;
my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("SELECT biblioitems.*,
+ my $sth = $dbh->prepare(
+ "SELECT biblioitems.*,
itemtypes.*,
MIN(items.itemlost) as itemlost,
MIN(items.dateaccessioned) as dateaccessioned
@@ -2117,16 +2031,17 @@
WHERE biblioitems.biblionumber = ?
AND biblioitems.itemtype = itemtypes.itemtype
AND biblioitems.biblioitemnumber = items.biblioitemnumber
- GROUP BY items.biblioitemnumber");
+ GROUP BY items.biblioitemnumber"
+ );
my $count = 0;
my @results;
$sth->execute($bibnum);
- while (my $data = $sth->fetchrow_hashref) {
+ while ( my $data = $sth->fetchrow_hashref ) {
$results[$count] = $data;
$count++;
} # while
$sth->finish;
- return($count, @results);
+ return ( $count, @results );
} # sub bibitems
=item barcodes
@@ -2143,22 +2058,25 @@
=cut
#'
-sub barcodes{
+sub barcodes {
+
#called from request.pl
- my ($biblioitemnumber)=@_;
+ my ($biblioitemnumber) = @_;
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("SELECT barcode, itemlost, homebranch, holdingbranch,itemnumber FROM items
+ my $sth = $dbh->prepare(
+"SELECT barcode, itemlost, homebranch, holdingbranch,itemnumber FROM items
WHERE biblioitemnumber = ?
- AND (wthdrawn <> 1 OR wthdrawn IS NULL)");
+ AND (wthdrawn <> 1 OR wthdrawn IS NULL)"
+ );
$sth->execute($biblioitemnumber);
my @barcodes;
- my $i=0;
- while (my $data=$sth->fetchrow_hashref){
- $barcodes[$i]=$data;
+ my $i = 0;
+ while ( my $data = $sth->fetchrow_hashref ) {
+ $barcodes[$i] = $data;
$i++;
}
$sth->finish;
- return(@barcodes);
+ return (@barcodes);
}
=item getwebsites
@@ -2184,7 +2102,8 @@
my @results;
$sth->execute($biblionumber);
- while (my $data = $sth->fetchrow_hashref) {
+ while ( my $data = $sth->fetchrow_hashref ) {
+
# FIXME - The URL scheme shouldn't be stripped off, at least
# not here, since it's part of the URL, and will be useful in
# constructing a link to the site. If you don't want the user
@@ -2197,7 +2116,7 @@
} # while
$sth->finish;
- return($count, @results);
+ return ( $count, @results );
} # sub getwebsites
=item getwebbiblioitems
@@ -2217,24 +2136,24 @@
sub getwebbiblioitems {
my ($biblionumber) = @_;
my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("Select * from biblioitems where biblionumber = ?
-and itemtype = 'WEB'");
+ my $sth = $dbh->prepare(
+ "Select * from biblioitems where biblionumber = ?
+and itemtype = 'WEB'"
+ );
my $count = 0;
my @results;
$sth->execute($biblionumber);
- while (my $data = $sth->fetchrow_hashref) {
+ while ( my $data = $sth->fetchrow_hashref ) {
$data->{'url'} =~ s/^http:\/\///;
$results[$count] = $data;
$count++;
} # while
$sth->finish;
- return($count, @results);
+ return ( $count, @results );
} # sub getwebbiblioitems
-
-
=item isbnsearch
($count, @results) = &isbnsearch($isbn,$title);
@@ -2249,34 +2168,35 @@
=cut
sub isbnsearch {
- my ($isbn,$title) = @_;
+ my ( $isbn, $title ) = @_;
my $dbh = C4::Context->dbh;
my $count = 0;
- my ($query, at bind);
+ my ( $query, @bind );
my $sth;
my @results;
- $query = "Select distinct biblio.*, biblioitems.classification from biblio, biblioitems where
+ $query =
+"Select distinct biblio.*, biblioitems.classification from biblio, biblioitems where
biblio.biblionumber = biblioitems.biblionumber";
- @bind=();
+ @bind = ();
if ($isbn) {
$query .= " and isbn like ?";
- @bind=(uc($isbn)."%");
+ @bind = ( uc($isbn) . "%" );
}
if ($title) {
$query .= " and title like ?";
- @bind=($title."%");
+ @bind = ( $title . "%" );
}
$sth = $dbh->prepare($query);
$sth->execute(@bind);
- while (my $data = $sth->fetchrow_hashref) {
+ while ( my $data = $sth->fetchrow_hashref ) {
$results[$count] = $data;
$count++;
} # while
$sth->finish;
- return($count, @results);
+ return ( $count, @results );
} # sub isbnsearch
=item getborrowercategory
@@ -2288,19 +2208,19 @@
=cut
-sub getborrowercategory
-{
+sub getborrowercategory {
my ($catcode) = @_;
my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare("SELECT description FROM categories WHERE categorycode = ?");
+ my $sth =
+ $dbh->prepare(
+ "SELECT description FROM categories WHERE categorycode = ?");
$sth->execute($catcode);
my $description = $sth->fetchrow();
$sth->finish();
return $description;
} # sub getborrowercategory
-sub getborrowercategoryinfo
-{
+sub getborrowercategoryinfo {
my ($catcode) = @_;
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare("SELECT * FROM categories WHERE categorycode = ?");
@@ -2311,116 +2231,125 @@
} # sub getborrowercategoryinfo
sub getMARCnotes {
- my ($dbh, $biblionumber, $marcflavour) = @_;
+ my ( $dbh, $biblionumber, $marcflavour ) = @_;
my $scope;
- if ($marcflavour eq "MARC21") {
- $scope='5..';
- } else { # assume unimarc if not marc21
- $scope='3..';
+ if ( $marcflavour eq "MARC21" ) {
+ $scope = '5..';
+ }
+ else { # assume unimarc if not marc21
+ $scope = '3..';
}
- my $record=MARCgetbiblio($dbh,$biblionumber);
+ my $record = MARCgetbiblio( $dbh, $biblionumber );
my @marcnotes;
my $note = "";
my $tag = "";
my $marcnote;
- foreach my $field ($record->field($scope)) {
+ foreach my $field ( $record->field($scope) ) {
my $value = $field->as_string();
- if ( $note ne "") {
- $marcnote = {marcnote => $note,};
+ if ( $note ne "" ) {
+ $marcnote = { marcnote => $note, };
push @marcnotes, $marcnote;
- $note=$value;
+ $note = $value;
}
- if ($note ne $value) {
- $note = $note." ".$value;
+ if ( $note ne $value ) {
+ $note = $note . " " . $value;
}
}
if ($note) {
- $marcnote = {marcnote => $note};
+ $marcnote = { marcnote => $note };
push @marcnotes, $marcnote; #load last tag into array
}
-
-
- my $marcnotesarray=\@marcnotes;
+ my $marcnotesarray = \@marcnotes;
return $marcnotesarray;
} # end getMARCnotes
-
sub getMARCsubjects {
- my ($dbh, $biblionumber, $marcflavour) = @_;
- my ($mintag, $maxtag);
- if ($marcflavour eq "MARC21") {
+ my ( $dbh, $biblionumber, $marcflavour ) = @_;
+ my ( $mintag, $maxtag );
+ if ( $marcflavour eq "MARC21" ) {
$mintag = "600";
$maxtag = "699";
- } else { # assume unimarc if not marc21
+ }
+ else { # assume unimarc if not marc21
$mintag = "600";
$maxtag = "619";
}
- my $record=MARCgetbiblio($dbh,$biblionumber);
+ my $record = MARCgetbiblio( $dbh, $biblionumber );
my @marcsubjcts;
my $subjct = "";
my $subfield = "";
my $marcsubjct;
- foreach my $field ($record->fields) {
- next unless $field->tag() >=$mintag && $field->tag() <=$maxtag;
+ foreach my $field ( $record->fields ) {
+ next unless $field->tag() >= $mintag && $field->tag() <= $maxtag;
my @subfields_loop;
+
#my $value = $field->subfield('a');
#$marcsubjct = {MARCSUBJCT => $value,};
my @subfields = $field->subfields();
+
#warn "subfields:".join " ", @$subfields;
my $counter = 0;
my @link_loop;
- for my $subject_subfield (@subfields ) {
+ for my $subject_subfield (@subfields) {
my $code = $subject_subfield->[0];
my $value = $subject_subfield->[1];
my $linkvalue = $value;
$linkvalue =~ s/(\(|\))//g;
- my $operator = " and " unless $counter==0;
- push @link_loop, {link => $linkvalue, operator => $operator };
- my $separator = C4::Context->preference("authoritysep") unless $counter==0;
- push @subfields_loop, {code => $code, value => $value, link_loop => \@link_loop, separator => $separator};
+ my $operator = " and " unless $counter == 0;
+ push @link_loop, { link => $linkvalue, operator => $operator };
+ my $separator = C4::Context->preference("authoritysep")
+ unless $counter == 0;
+ push @subfields_loop,
+ {
+ code => $code,
+ value => $value,
+ link_loop => \@link_loop,
+ separator => $separator
+ };
$counter++;
}
push @marcsubjcts, { MARCSUBJECT_SUBFIELDS_LOOP => \@subfields_loop };
+
#$marcsubjct = {MARCSUBJCT => $field->as_string(),};
#push @marcsubjcts, $marcsubjct;
#$subjct = $value;
}
- my $marcsubjctsarray=\@marcsubjcts;
+ my $marcsubjctsarray = \@marcsubjcts;
return $marcsubjctsarray;
} #end getMARCsubjects
-
sub getMARCurls {
- my ($dbh, $biblionumber, $marcflavour) = @_;
- my ($mintag, $maxtag);
- if ($marcflavour eq "MARC21") {
+ my ( $dbh, $biblionumber, $marcflavour ) = @_;
+ my ( $mintag, $maxtag );
+ if ( $marcflavour eq "MARC21" ) {
$mintag = "856";
$maxtag = "856";
- } else { # assume unimarc if not marc21
+ }
+ else { # assume unimarc if not marc21
$mintag = "600";
$maxtag = "619";
}
-my $record=MARCgetbiblio($dbh,$biblionumber);
+ my $record = MARCgetbiblio( $dbh, $biblionumber );
my @marcurls;
my $url = "";
my $subfil = "";
my $marcurl;
- foreach my $field ($record->field('856')) {
+ foreach my $field ( $record->field('856') ) {
my $value = $field->subfield('u');
- if ( $value ne $url) {
- $marcurl = {MARCURL => $value,};
+ if ( $value ne $url ) {
+ $marcurl = { MARCURL => $value, };
push @marcurls, $marcurl;
$url = $value;
}
}
- my $marcurlsarray=\@marcurls;
+ my $marcurlsarray = \@marcurls;
return $marcurlsarray;
} #end getMARCurls
@@ -2640,49 +2569,63 @@
my @results;
my @tmpresults;
my @zconns;
- return ("No query entered",undef) unless $query;
+ return ( "No query entered", undef ) unless $query;
#@servers = (C4::Context->config("biblioserver")) unless @servers;
- @servers = ("biblioserver"); # FIXME hardcoded value. See catalog/search.pl & opac-search.pl too.
+ @servers =
+ ("biblioserver")
+ ; # FIXME hardcoded value. See catalog/search.pl & opac-search.pl too.
# Connect & Search
- for (my $i = 0; $i < @servers; $i++) {
- $zconns[$i] = C4::Context->Zconn($servers[$i],1);
- $tmpresults[$i] = $zconns[$i]->search(new ZOOM::Query::CCL2RPN($query,$zconns[$i]));
+ for ( my $i = 0 ; $i < @servers ; $i++ ) {
+ $zconns[$i] = C4::Context->Zconn( $servers[$i], 1 );
+ $tmpresults[$i] =
+ $zconns[$i]
+ ->search( new ZOOM::Query::CCL2RPN( $query, $zconns[$i] ) );
# getting error message if one occured.
- my $error = $zconns[$i]->errmsg()." (".$zconns[$i]->errcode().") ".$zconns[$i]->addinfo()." ".$zconns[$i]->diagset();
+ my $error =
+ $zconns[$i]->errmsg() . " ("
+ . $zconns[$i]->errcode() . ") "
+ . $zconns[$i]->addinfo() . " "
+ . $zconns[$i]->diagset();
- return ($error,undef) if $zconns[$i]->errcode();
+ return ( $error, undef ) if $zconns[$i]->errcode();
}
my $hits;
my $ev;
- while ((my $i = ZOOM::event(\@zconns)) != 0) {
- $ev = $zconns[$i-1]->last_event();
- if ($ev == ZOOM::Event::ZEND) {
- $hits = $tmpresults[$i-1]->size();
- }
- if($hits > 0){
- for(my $j=0;$j<$hits;$j++){
- my $record = $tmpresults[$i-1]->record($j)->raw();
+ while ( ( my $i = ZOOM::event( \@zconns ) ) != 0 ) {
+ $ev = $zconns[ $i - 1 ]->last_event();
+ if ( $ev == ZOOM::Event::ZEND ) {
+ $hits = $tmpresults[ $i - 1 ]->size();
+ }
+ if ( $hits > 0 ) {
+ for ( my $j = 0 ; $j < $hits ; $j++ ) {
+ my $record = $tmpresults[ $i - 1 ]->record($j)->raw();
push @results, $record;
}
}
}
- return (undef,\@results);
+ return ( undef, \@results );
}
# performs the search
sub getRecords {
- my ($koha_query,$federated_query,$sort_by_ref,$servers_ref,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan) = @_;
+ my (
+ $koha_query, $federated_query, $sort_by_ref,
+ $servers_ref, $results_per_page, $offset,
+ $expanded_facet, $branches, $query_type,
+ $scan
+ ) = @_;
my @servers = @$servers_ref;
my @sort_by = @$sort_by_ref;
+
# create the zoom connection and query object
my $zconn;
my @zconns;
my @results;
- my $results_hashref =();
+ my $results_hashref = ();
### FACETED RESULTS
my $facets_counter = ();
@@ -2691,155 +2634,220 @@
#### INITIALIZE SOME VARS USED CREATE THE FACETED RESULTS
my @facets_loop; # stores the ref to array of hashes for template
- for (my $i = 0; $i < @servers; $i++) {
- $zconns[$i] = C4::Context->Zconn($servers[$i],1);
+ for ( my $i = 0 ; $i < @servers ; $i++ ) {
+ $zconns[$i] = C4::Context->Zconn( $servers[$i], 1 );
- # perform the search, create the results objects
- # if this is a local search, use the $koha-query, if it's a federated one, use the federated-query
+# perform the search, create the results objects
+# if this is a local search, use the $koha-query, if it's a federated one, use the federated-query
my $query_to_use;
- if ($servers[$i] =~ /biblioserver/) {
+ if ( $servers[$i] =~ /biblioserver/ ) {
$query_to_use = $koha_query;
}
else {
$query_to_use = $federated_query;
}
-# warn "HERE : $query_type => $query_to_use";
+
+ # warn "HERE : $query_type => $query_to_use";
# check if we've got a query_type defined
eval {
- if ($query_type) {
- if ($query_type =~/^ccl/) {
- $query_to_use =~ s/\:/\=/g; # change : to = last minute (FIXME)
-# warn "CCL : $query_to_use";
- $results[$i] = $zconns[$i]->search(new ZOOM::Query::CCL2RPN($query_to_use,$zconns[$i]));
- }
- elsif ($query_type =~/^cql/) {
-# warn "CQL : $query_to_use";
- $results[$i] = $zconns[$i]->search(new ZOOM::Query::CQL($query_to_use,$zconns[$i]));
- }
- elsif ($query_type =~/^pqf/) {
-# warn "PQF : $query_to_use";
- $results[$i] = $zconns[$i]->search(new ZOOM::Query::PQF($query_to_use,$zconns[$i]));
+ if ($query_type)
+ {
+ if ( $query_type =~ /^ccl/ ) {
+ $query_to_use =~
+ s/\:/\=/g; # change : to = last minute (FIXME)
+
+ # warn "CCL : $query_to_use";
+ $results[$i] =
+ $zconns[$i]->search(
+ new ZOOM::Query::CCL2RPN( $query_to_use, $zconns[$i] )
+ );
+ }
+ elsif ( $query_type =~ /^cql/ ) {
+
+ # warn "CQL : $query_to_use";
+ $results[$i] =
+ $zconns[$i]->search(
+ new ZOOM::Query::CQL( $query_to_use, $zconns[$i] ) );
+ }
+ elsif ( $query_type =~ /^pqf/ ) {
+
+ # warn "PQF : $query_to_use";
+ $results[$i] =
+ $zconns[$i]->search(
+ new ZOOM::Query::PQF( $query_to_use, $zconns[$i] ) );
}
}
else {
if ($scan) {
-# warn "preparing to scan";
- $results[$i] = $zconns[$i]->scan(new ZOOM::Query::CCL2RPN($query_to_use,$zconns[$i]));
- } else {
-# warn "LAST : $query_to_use";
- $results[$i] = $zconns[$i]->search(new ZOOM::Query::CCL2RPN($query_to_use,$zconns[$i]));
+
+ # warn "preparing to scan";
+ $results[$i] =
+ $zconns[$i]->scan(
+ new ZOOM::Query::CCL2RPN( $query_to_use, $zconns[$i] )
+ );
+ }
+ else {
+
+ # warn "LAST : $query_to_use";
+ $results[$i] =
+ $zconns[$i]->search(
+ new ZOOM::Query::CCL2RPN( $query_to_use, $zconns[$i] )
+ );
}
}
};
if ($@) {
- warn "prob with query $query_to_use ".$@;
+ warn "prob with query $query_to_use " . $@;
}
+
# concatenate the sort_by limits and pass them to the results object
my $sort_by;
foreach my $sort (@sort_by) {
- $sort_by.=$sort." "; # used to be $sort,
+ $sort_by .= $sort . " "; # used to be $sort,
}
- $results[$i]->sort("yaz", $sort_by) if $sort_by;
+ $results[$i]->sort( "yaz", $sort_by ) if $sort_by;
}
- while ((my $i = ZOOM::event(\@zconns)) != 0) {
- my $ev = $zconns[$i-1]->last_event();
- if ($ev == ZOOM::Event::ZEND) {
- my $size = $results[$i-1]->size();
- if ($size > 0) {
+ while ( ( my $i = ZOOM::event( \@zconns ) ) != 0 ) {
+ my $ev = $zconns[ $i - 1 ]->last_event();
+ if ( $ev == ZOOM::Event::ZEND ) {
+ my $size = $results[ $i - 1 ]->size();
+ if ( $size > 0 ) {
my $results_hash;
+
#$results_hash->{'server'} = $servers[$i-1];
# loop through the results
$results_hash->{'hits'} = $size;
my $times;
- if ($offset+$results_per_page<=$size) {
- $times= $offset+$results_per_page;
- } else {
+ if ( $offset + $results_per_page <= $size ) {
+ $times = $offset + $results_per_page;
+ }
+ else {
$times = $size;
}
- for ( my $j=$offset; $j<$times;$j++){ #(($offset+$count<=$size) ? ($offset+$count):$size) ; $j++){
+ for ( my $j = $offset ; $j < $times ; $j++ )
+ { #(($offset+$count<=$size) ? ($offset+$count):$size) ; $j++){
my $records_hash;
my $record;
my $facet_record;
## This is just an index scan
if ($scan) {
- my ($term,$occ) = $results[$i-1]->term($j);
+ my ( $term, $occ ) = $results[ $i - 1 ]->term($j);
+
# here we create a minimal MARC record and hand it off to the
# template just like a normal result ... perhaps not ideal, but
# it works for now
my $tmprecord = MARC::Record->new();
$tmprecord->encoding('UTF-8');
my $tmptitle;
+
# srote the minimal record in author/title (depending on MARC flavour)
- if (C4::Context->preference("marcflavour") eq "UNIMARC") {
- $tmptitle = MARC::Field->new( '200',' ',' ',
+ if ( C4::Context->preference("marcflavour") eq
+ "UNIMARC" )
+ {
+ $tmptitle = MARC::Field->new(
+ '200', ' ', ' ',
a => $term,
- f => $occ);
- } else {
- $tmptitle = MARC::Field->new( '245',' ',' ',
+ f => $occ
+ );
+ }
+ else {
+ $tmptitle = MARC::Field->new(
+ '245', ' ', ' ',
a => $term,
- b => $occ);
+ b => $occ
+ );
}
$tmprecord->append_fields($tmptitle);
- $results_hash->{'RECORDS'}[$j] = $tmprecord->as_usmarc();
+ $results_hash->{'RECORDS'}[$j] =
+ $tmprecord->as_usmarc();
}
else {
- $record = $results[$i-1]->record($j)->raw();
+ $record = $results[ $i - 1 ]->record($j)->raw();
+
#warn "RECORD $j:".$record;
- $results_hash->{'RECORDS'}[$j] = $record; # making a reference to a hash
+ $results_hash->{'RECORDS'}[$j] =
+ $record; # making a reference to a hash
# Fill the facets while we're looping
$facet_record = MARC::Record->new_from_usmarc($record);
+
#warn $servers[$i-1].$facet_record->title();
- for (my $k=0;$k<=@$facets;$k++) {
- if ($facets->[$k]) {
+ for ( my $k = 0 ; $k <= @$facets ; $k++ ) {
+ if ( $facets->[$k] ) {
my @fields;
- for my $tag (@{$facets->[$k]->{'tags'}}) {
+ for my $tag ( @{ $facets->[$k]->{'tags'} } ) {
push @fields, $facet_record->field($tag);
}
for my $field (@fields) {
my @subfields = $field->subfields();
for my $subfield (@subfields) {
- my ($code,$data) = @$subfield;
- if ($code eq $facets->[$k]->{'subfield'}) {
- $facets_counter->{ $facets->[$k]->{'link_value'} }->{ $data }++;
+ my ( $code, $data ) = @$subfield;
+ if ( $code eq
+ $facets->[$k]->{'subfield'} )
+ {
+ $facets_counter->{ $facets->[$k]
+ ->{'link_value'} }->{$data}++;
}
}
}
- $facets_info->{ $facets->[$k]->{'link_value'} }->{ 'label_value' } = $facets->[$k]->{'label_value'};
- $facets_info->{ $facets->[$k]->{'link_value'} }->{ 'expanded' } = $facets->[$k]->{'expanded'};
+ $facets_info->{ $facets->[$k]->{'link_value'} }
+ ->{'label_value'} =
+ $facets->[$k]->{'label_value'};
+ $facets_info->{ $facets->[$k]->{'link_value'} }
+ ->{'expanded'} = $facets->[$k]->{'expanded'};
}
}
}
}
- $results_hashref->{$servers[$i-1]} = $results_hash;
+ $results_hashref->{ $servers[ $i - 1 ] } = $results_hash;
}
+
#print "connection ", $i-1, ": $size hits";
#print $results[$i-1]->record(0)->render() if $size > 0;
# BUILD FACETS
- for my $link_value ( sort { $facets_counter->{$b} <=> $facets_counter->{$a} } keys %$facets_counter) {
+ for my $link_value (
+ sort { $facets_counter->{$b} <=> $facets_counter->{$a} }
+ keys %$facets_counter )
+ {
my $expandable;
my $number_of_facets;
my @this_facets_array;
- for my $one_facet (sort { $facets_counter->{ $link_value }->{$b} <=> $facets_counter->{ $link_value }->{$a} } keys %{$facets_counter->{ $link_value }} ) {
+ for my $one_facet (
+ sort {
+ $facets_counter->{$link_value}
+ ->{$b} <=> $facets_counter->{$link_value}->{$a}
+ } keys %{ $facets_counter->{$link_value} }
+ )
+ {
$number_of_facets++;
- if (($number_of_facets < 6) || ($expanded_facet eq $link_value) || ($facets_info->{ $link_value }->{ 'expanded'})) {
+ if ( ( $number_of_facets < 6 )
+ || ( $expanded_facet eq $link_value )
+ || ( $facets_info->{$link_value}->{'expanded'} ) )
+ {
+
# sanitize the link value ), ( will cause errors with CCL
my $facet_link_value = $one_facet;
$facet_link_value =~ s/(\(|\))/ /g;
# fix the length that will display in the label
my $facet_label_value = $one_facet;
- $facet_label_value = substr($one_facet,0,20)."..." unless length($facet_label_value)<=20;
+ $facet_label_value = substr( $one_facet, 0, 20 ) . "..."
+ unless length($facet_label_value) <= 20;
+
# well, if it's a branch, label by the name, not the code
- if ($link_value =~/branch/) {
- $facet_label_value = $branches->{$one_facet}->{'branchname'};
+ if ( $link_value =~ /branch/ ) {
+ $facet_label_value =
+ $branches->{$one_facet}->{'branchname'};
}
# but we're down with the whole label being in the link's title
my $facet_title_value = $one_facet;
- push @this_facets_array ,
- ( { facet_count => $facets_counter->{ $link_value }->{ $one_facet },
+ push @this_facets_array,
+ (
+ {
+ facet_count =>
+ $facets_counter->{$link_value}->{$one_facet},
facet_label_value => $facet_label_value,
facet_title_value => $facet_title_value,
facet_link_value => $facet_link_value,
@@ -2848,13 +2856,18 @@
);
}
}
- unless ($facets_info->{ $link_value }->{ 'expanded'}) {
- $expandable=1 if (($number_of_facets > 6) && ($expanded_facet ne $link_value));
+ unless ( $facets_info->{$link_value}->{'expanded'} ) {
+ $expandable = 1
+ if ( ( $number_of_facets > 6 )
+ && ( $expanded_facet ne $link_value ) );
}
push @facets_loop,
- ( { type_link_value => $link_value,
- type_id => $link_value."_id",
- type_label => $facets_info->{ $link_value }->{ 'label_value' },
+ (
+ {
+ type_link_value => $link_value,
+ type_id => $link_value . "_id",
+ type_label =>
+ $facets_info->{$link_value}->{'label_value'},
facets => \@this_facets_array,
expandable => $expandable,
expand => $link_value,
@@ -2863,17 +2876,17 @@
}
}
}
- return (undef, $results_hashref, \@facets_loop);
+ return ( undef, $results_hashref, \@facets_loop );
}
# build the query itself
sub buildQuery {
- my ($query,$operators,$operands,$indexes,$limits,$sort_by) = @_;
- warn "OPERATORS : ".Data::Dumper::Dumper($operators);
- warn "OPERANDS : ".Data::Dumper::Dumper($operands);
- warn "INDEXES : ".Data::Dumper::Dumper($indexes);
- warn "LIMITS : ".Data::Dumper::Dumper($limits);
- warn "SORT BY : ".Data::Dumper::Dumper($sort_by);
+ my ( $query, $operators, $operands, $indexes, $limits, $sort_by ) = @_;
+ warn "OPERATORS : " . Data::Dumper::Dumper($operators);
+ warn "OPERANDS : " . Data::Dumper::Dumper($operands);
+ warn "INDEXES : " . Data::Dumper::Dumper($indexes);
+ warn "LIMITS : " . Data::Dumper::Dumper($limits);
+ warn "SORT BY : " . Data::Dumper::Dumper($sort_by);
my @operators = @$operators if $operators;
my @indexes = @$indexes if $indexes;
my @operands = @$operands if $operands;
@@ -2883,94 +2896,120 @@
my $human_search_desc; # a human-readable query
my $machine_search_desc; #a machine-readable query
# FIXME: the locale should be set based on the syspref
- my $stemmer = Lingua::Stem->new(-locale => 'EN-US');
- # FIXME: these should be stored in the db so the librarian can modify the behavior
- $stemmer->add_exceptions({ 'and' => 'and',
+ my $stemmer = Lingua::Stem->new( -locale => 'EN-US' );
+
+# FIXME: these should be stored in the db so the librarian can modify the behavior
+ $stemmer->add_exceptions(
+ {
+ 'and' => 'and',
'or' => 'or',
- 'not' => 'not',});
+ 'not' => 'not',
+ }
+ );
- # STEP I: determine if this is a form-based / simple query or if it's complex (if complex,
- # we can't handle field weighting, stemming until a formal query parser is written
- # I'll work on this soon -- JF
- #if (!$query) { # form-based
- # check if this is a known query language query, if it is, return immediately:
- if ($query =~/^ccl=/) {
- return (undef,$',$',$','ccl');
- }
- if ($query =~/^cql=/) {
- return (undef,$',$',$','cql');
- }
- if ($query =~/^pqf=/) {
- return (undef,$',$',$','pqf');
- }
- if ($query =~/(\(|\))/ ) { # sorry, too complex
- return (undef,$query,$query,$query,'ccl');
- }
- # form-based queries are limited to non-nested a specific depth, so we can easily
- # modify the incoming query operands and indexes to do stemming and field weighting
- # Once we do so, we'll end up with a value in $query, just like if we had an
- # incoming $query from the user
+# STEP I: determine if this is a form-based / simple query or if it's complex (if complex,
+# we can't handle field weighting, stemming until a formal query parser is written
+# I'll work on this soon -- JF
+#if (!$query) { # form-based
+# check if this is a known query language query, if it is, return immediately:
+ if ( $query =~ /^ccl=/ ) {
+ return ( undef, $', $', $', 'ccl' );
+ }
+ if ( $query =~ /^cql=/ ) {
+ return ( undef, $', $', $', 'cql' );
+ }
+ if ( $query =~ /^pqf=/ ) {
+ return ( undef, $', $', $', 'pqf' );
+ }
+ if ( $query =~ /(\(|\))/ ) { # sorry, too complex
+ return ( undef, $query, $query, $query, 'ccl' );
+ }
+
+# form-based queries are limited to non-nested a specific depth, so we can easily
+# modify the incoming query operands and indexes to do stemming and field weighting
+# Once we do so, we'll end up with a value in $query, just like if we had an
+# incoming $query from the user
else {
- $query = ""; # clear it out so we can populate properly with field-weighted stemmed query
- my $previous_operand; # a flag used to keep track if there was a previous query
+ $query = ""
+ ; # clear it out so we can populate properly with field-weighted stemmed query
+ my $previous_operand
+ ; # a flag used to keep track if there was a previous query
# if there was, we can apply the current operator
- for (my $i=0; $i<=@operands; $i++) {
+ for ( my $i = 0 ; $i <= @operands ; $i++ ) {
my $operand = $operands[$i];
my $index = $indexes[$i];
my $stemmed_operand;
- my $stemming = C4::Context->parameters("Stemming") ||0;
+ my $stemming = C4::Context->parameters("Stemming") || 0;
my $weight_fields = C4::Context->parameters("WeightFields") || 0;
- if ($operands[$i]) {
+ if ( $operands[$i] ) {
- # STEMMING FIXME: need to refine the field weighting so stemmed operands don't disrupt the query ranking
+# STEMMING FIXME: need to refine the field weighting so stemmed operands don't disrupt the query ranking
if ($stemming) {
- my @words = split (/ /, $operands[$i]);
+ my @words = split( / /, $operands[$i] );
my $stems = $stemmer->stem(@words);
- foreach my $stem(@$stems) {
- $stemmed_operand.="$stem";
- $stemmed_operand.="?" unless ($stem =~/(and$|or$|not$)/) || (length($stem<3));
- $stemmed_operand.=" ";
+ foreach my $stem (@$stems) {
+ $stemmed_operand .= "$stem";
+ $stemmed_operand .= "?"
+ unless ( $stem =~ /(and$|or$|not$)/ )
+ || ( length( $stem < 3 ) );
+ $stemmed_operand .= " ";
+
#warn "STEM: $stemmed_operand";
}
+
#$operand = $stemmed_operand;
}
- # FIELD WEIGHTING - This is largely experimental stuff. What I'm committing works
- # pretty well but will work much better when we have an actual query parser
+# FIELD WEIGHTING - This is largely experimental stuff. What I'm committing works
+# pretty well but will work much better when we have an actual query parser
my $weighted_query;
if ($weight_fields) {
- $weighted_query.= " rk=("; # Specifies that we're applying rank
+ $weighted_query .=
+ " rk=("; # Specifies that we're applying rank
# keyword has different weight properties
- if (($index =~ /kw/) || (!$index)) { # FIXME: do I need to add right-truncation in the case of stemming?
+ if ( ( $index =~ /kw/ ) || ( !$index ) )
+ { # FIXME: do I need to add right-truncation in the case of stemming?
# a simple way to find out if this query uses an index
- if ($operand =~ /(\=|\:)/) {
+ if ( $operand =~ /(\=|\:)/ ) {
$weighted_query .= " $operand";
}
else {
- $weighted_query .= " Title-cover,ext,r1=\"$operand\""; # index label as exact
- $weighted_query .= " or ti,ext,r2=$operand"; # index as exact
+ $weighted_query .=
+ " Title-cover,ext,r1=\"$operand\""
+ ; # index label as exact
+ $weighted_query .=
+ " or ti,ext,r2=$operand"; # index as exact
#$weighted_query .= " or ti,phr,r3=$operand"; # index as phrase
#$weighted_query .= " or any,ext,r4=$operand"; # index as exact
- $weighted_query .= " or kw,wrdl,r5=$operand"; # index as exact
+ $weighted_query .=
+ " or kw,wrdl,r5=$operand"; # index as exact
$weighted_query .= " or wrd,fuzzy,r9=$operand";
- $weighted_query .= " or wrd=$stemmed_operand" if $stemming;
+ $weighted_query .= " or wrd=$stemmed_operand"
+ if $stemming;
}
}
- elsif ($index =~ /au/) {
- $weighted_query .= " $index,ext,r1=$operand"; # index label as exact
+ elsif ( $index =~ /au/ ) {
+ $weighted_query .=
+ " $index,ext,r1=$operand"; # index label as exact
#$weighted_query .= " or (title-sort-az=0 or $index,startswithnt,st-word,r3=$operand #)";
- $weighted_query .= " or $index,phr,r3=$operand"; # index as phrase
+ $weighted_query .=
+ " or $index,phr,r3=$operand"; # index as phrase
$weighted_query .= " or $index,rt,wrd,r3=$operand";
}
- elsif ($index =~ /ti/) {
- $weighted_query .= " Title-cover,ext,r1=$operand"; # index label as exact
+ elsif ( $index =~ /ti/ ) {
+ $weighted_query .=
+ " Title-cover,ext,r1=$operand"; # index label as exact
$weighted_query .= " or Title-series,ext,r2=$operand";
+
#$weighted_query .= " or ti,ext,r2=$operand";
#$weighted_query .= " or ti,phr,r3=$operand";
#$weighted_query .= " or ti,wrd,r3=$operand";
- $weighted_query .= " or (title-sort-az=0 or Title-cover,startswithnt,st-word,r3=$operand #)";
- $weighted_query .= " or (title-sort-az=0 or Title-cover,phr,r6=$operand)";
+ $weighted_query .=
+" or (title-sort-az=0 or Title-cover,startswithnt,st-word,r3=$operand #)";
+ $weighted_query .=
+" or (title-sort-az=0 or Title-cover,phr,r6=$operand)";
+
#$weighted_query .= " or Title-cover,wrd,r5=$operand";
#$weighted_query .= " or ti,ext,r6=$operand";
#$weighted_query .= " or ti,startswith,phr,r7=$operand";
@@ -2983,41 +3022,49 @@
#$weighted_query .= " or kw,wrd,r5=$operand"; # index as exact
}
else {
- $weighted_query .= " $index,ext,r1=$operand"; # index label as exact
+ $weighted_query .=
+ " $index,ext,r1=$operand"; # index label as exact
#$weighted_query .= " or $index,ext,r2=$operand"; # index as exact
- $weighted_query .= " or $index,phr,r3=$operand"; # index as phrase
+ $weighted_query .=
+ " or $index,phr,r3=$operand"; # index as phrase
$weighted_query .= " or $index,rt,wrd,r3=$operand";
- $weighted_query .= " or $index,wrd,r5=$operand"; # index as word right-truncated
+ $weighted_query .=
+ " or $index,wrd,r5=$operand"
+ ; # index as word right-truncated
$weighted_query .= " or $index,wrd,fuzzy,r8=$operand";
}
- $weighted_query.=")"; # close rank specification
+ $weighted_query .= ")"; # close rank specification
$operand = $weighted_query;
}
+
# only add an operator if there is a previous operand
if ($previous_operand) {
- if ($operators[$i-1]) {
- $query.=" $operators[$i-1] $index: $operand";
- if (!$index) {
- $human_search_desc.=" $operators[$i-1] $operands[$i]";
+ if ( $operators[ $i - 1 ] ) {
+ $query .= " $operators[$i-1] $index: $operand";
+ if ( !$index ) {
+ $human_search_desc .=
+ " $operators[$i-1] $operands[$i]";
}
else {
- $human_search_desc.=" $operators[$i-1] $index: $operands[$i]";
+ $human_search_desc .=
+ " $operators[$i-1] $index: $operands[$i]";
}
}
+
# the default operator is and
else {
- $query.=" and $index: $operand";
- $human_search_desc.=" and $index: $operands[$i]";
+ $query .= " and $index: $operand";
+ $human_search_desc .= " and $index: $operands[$i]";
}
}
else {
- if (!$index) {
- $query.=" $operand";
- $human_search_desc.=" $operands[$i]";
+ if ( !$index ) {
+ $query .= " $operand";
+ $human_search_desc .= " $operands[$i]";
}
else {
- $query.=" $index: $operand";
- $human_search_desc.=" $index: $operands[$i]";
+ $query .= " $index: $operand";
+ $human_search_desc .= " $index: $operands[$i]";
}
$previous_operand = 1;
}
@@ -3029,51 +3076,71 @@
my $limit_query;
my $limit_search_desc;
foreach my $limit (@limits) {
+
# FIXME: not quite right yet ... will work on this soon -- JF
- my $type=$1 if $limit=~m/([^:]+):([^:]*)/;
- if ($limit =~ /available/) {
- $limit_query.=" (($query and datedue=0000-00-00) or ($query and datedue=0000-00-00 not lost=1) or ($query and datedue=0000-00-00 not lost=2))";
+ my $type = $1 if $limit =~ m/([^:]+):([^:]*)/;
+ if ( $limit =~ /available/ ) {
+ $limit_query .=
+" (($query and datedue=0000-00-00) or ($query and datedue=0000-00-00 not lost=1) or ($query and datedue=0000-00-00 not lost=2))";
+
#$limit_search_desc.=" and available";
}
- elsif (($limit_query) && (index($limit_query,$type,0)>0)) {
- if ($limit_query!~/\(/){
- $limit_query= substr($limit_query,0,index($limit_query,$type,0))."(".substr($limit_query,index($limit_query,$type,0))." or $limit )" if $limit;
- $limit_search_desc= substr($limit_search_desc,0,index($limit_search_desc,$type,0))."(".substr($limit_search_desc,index($limit_search_desc,$type,0))." or $limit )" if $limit;
- } else {
+ elsif ( ($limit_query) && ( index( $limit_query, $type, 0 ) > 0 ) ) {
+ if ( $limit_query !~ /\(/ ) {
+ $limit_query =
+ substr( $limit_query, 0, index( $limit_query, $type, 0 ) )
+ . "("
+ . substr( $limit_query, index( $limit_query, $type, 0 ) )
+ . " or $limit )"
+ if $limit;
+ $limit_search_desc =
+ substr( $limit_search_desc, 0,
+ index( $limit_search_desc, $type, 0 ) )
+ . "("
+ . substr( $limit_search_desc,
+ index( $limit_search_desc, $type, 0 ) )
+ . " or $limit )"
+ if $limit;
+ }
+ else {
chop $limit_query;
chop $limit_search_desc;
- $limit_query.=" or $limit )" if $limit;
- $limit_search_desc.=" or $limit )" if $limit;
+ $limit_query .= " or $limit )" if $limit;
+ $limit_search_desc .= " or $limit )" if $limit;
}
}
- elsif (($limit_query) && ($limit =~/mc/)) {
- $limit_query.=" or $limit" if $limit;
- $limit_search_desc.=" or $limit" if $limit;
+ elsif ( ($limit_query) && ( $limit =~ /mc/ ) ) {
+ $limit_query .= " or $limit" if $limit;
+ $limit_search_desc .= " or $limit" if $limit;
}
+
# these are treated as AND
elsif ($limit_query) {
- $limit_query.=" and $limit" if $limit;
- $limit_search_desc.=" and $limit" if $limit;
+ $limit_query .= " and $limit" if $limit;
+ $limit_search_desc .= " and $limit" if $limit;
}
+
# otherwise, there is nothing but the limit
else {
- $limit_query.="$limit" if $limit;
- $limit_search_desc.="$limit" if $limit;
+ $limit_query .= "$limit" if $limit;
+ $limit_search_desc .= "$limit" if $limit;
}
}
+
# if there's also a query, we need to AND the limits to it
- if (($limit_query) && ($query)) {
- $limit_query=" and (".$limit_query.")";
- $limit_search_desc=" and ($limit_search_desc)" if $limit_search_desc;
+ if ( ($limit_query) && ($query) ) {
+ $limit_query = " and (" . $limit_query . ")";
+ $limit_search_desc = " and ($limit_search_desc)" if $limit_search_desc;
}
$query .= $limit_query;
$human_search_desc .= $limit_search_desc;
+
# now normalize the strings
$query =~ s/ / /g; # remove extra spaces
$query =~ s/^ //g; # remove any beginning spaces
- $query =~s/:/=/g; # causes probs for server
- $query =~s/==/=/g; # remove double == from query
+ $query =~ s/:/=/g; # causes probs for server
+ $query =~ s/==/=/g; # remove double == from query
my $federated_query = $human_search_desc;
$federated_query =~ s/ / /g;
@@ -3081,95 +3148,118 @@
$federated_query =~ s/:/=/g;
$human_search_desc =~ s/ / /g;
- $human_search_desc =~s/^ //g;
+ $human_search_desc =~ s/^ //g;
my $koha_query = $query;
+
#warn "QUERY:".$koha_query;
#warn "SEARCHDESC:".$human_search_desc;
#warn "FEDERATED QUERY:".$federated_query;
- return (undef,$human_search_desc,$koha_query,$federated_query);
+ return ( undef, $human_search_desc, $koha_query, $federated_query );
}
# IMO this subroutine is pretty messy still -- it's responsible for
# building the HTML output for the template
sub searchResults {
- my ($searchdesc,$hits,$results_per_page,$offset, at marcresults)=@_;
+ my ( $searchdesc, $hits, $results_per_page, $offset, @marcresults ) = @_;
- my $dbh= C4::Context->dbh;
+ my $dbh = C4::Context->dbh;
my $toggle;
- my $even=1;
+ my $even = 1;
my @newresults;
my $span_terms_hashref;
- for my $span_term (split (/ /, $searchdesc)) {
- $span_term =~s/(.*=|\)|\(|\+|\.)//g;
+ for my $span_term ( split( / /, $searchdesc ) ) {
+ $span_term =~ s/(.*=|\)|\(|\+|\.)//g;
$span_terms_hashref->{$span_term}++;
}
+
#Build brancnames hash
#find branchname
#get branch information.....
my %branches;
- my $bsth=$dbh->prepare("SELECT branchcode,branchname FROM branches"); # FIXME : use C4::Koha::GetBranches
+ my $bsth =
+ $dbh->prepare("SELECT branchcode,branchname FROM branches")
+ ; # FIXME : use C4::Koha::GetBranches
$bsth->execute();
- while (my $bdata=$bsth->fetchrow_hashref){
- $branches{$bdata->{'branchcode'}}= $bdata->{'branchname'};
+ while ( my $bdata = $bsth->fetchrow_hashref ) {
+ $branches{ $bdata->{'branchcode'} } = $bdata->{'branchname'};
}
#Build itemtype hash
#find itemtype & itemtype image
my %itemtypes;
- my $bsth=$dbh->prepare("SELECT itemtype,description,imageurl FROM itemtypes");
+ $bsth =
+ $dbh->prepare("SELECT itemtype,description,imageurl FROM itemtypes");
$bsth->execute();
- while (my $bdata=$bsth->fetchrow_hashref){
- $itemtypes{$bdata->{'itemtype'}}->{description}= $bdata->{'description'};
- $itemtypes{$bdata->{'itemtype'}}->{imageurl} = $bdata->{'imageurl'};
+ while ( my $bdata = $bsth->fetchrow_hashref ) {
+ $itemtypes{ $bdata->{'itemtype'} }->{description} =
+ $bdata->{'description'};
+ $itemtypes{ $bdata->{'itemtype'} }->{imageurl} = $bdata->{'imageurl'};
}
#search item field code
- my $sth = $dbh->prepare(
- "select tagfield from marc_subfield_structure where kohafield like 'items.itemnumber'"
+ my $sth =
+ $dbh->prepare(
+"select tagfield from marc_subfield_structure where kohafield like 'items.itemnumber'"
);
$sth->execute;
my ($itemtag) = $sth->fetchrow;
## find column names of items related to MARC
- my $sth2=$dbh->prepare("SHOW COLUMNS from items");
+ my $sth2 = $dbh->prepare("SHOW COLUMNS from items");
$sth2->execute;
my %subfieldstosearch;
- while ((my $column)=$sth2->fetchrow){
- my ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,"items.".$column,"");
- $subfieldstosearch{$column}=$tagsubfield;
+ while ( ( my $column ) = $sth2->fetchrow ) {
+ my ( $tagfield, $tagsubfield ) =
+ &MARCfind_marc_from_kohafield( $dbh, "items." . $column, "" );
+ $subfieldstosearch{$column} = $tagsubfield;
}
my $times;
- if ($offset+$results_per_page<=$hits) {
- $times= $offset+$results_per_page;
- } else {
+ if ( $offset + $results_per_page <= $hits ) {
+ $times = $offset + $results_per_page;
+ }
+ else {
$times = $hits;
}
- for ( my $i=$offset; $i<$times; $i++){
+ for ( my $i = $offset ; $i < $times ; $i++ ) {
my $marcrecord;
- $marcrecord = MARC::File::USMARC::decode($marcresults[$i]);
+ $marcrecord = MARC::File::USMARC::decode( $marcresults[$i] );
+
+ my $oldbiblio = MARCmarc2koha( $dbh, $marcrecord, '' );
- my $oldbiblio = MARCmarc2koha($dbh,$marcrecord,'');
# add image url if there is one
- if ($itemtypes{$oldbiblio->{itemtype}}->{imageurl} =~ /^http:/) {
- $oldbiblio->{imageurl} = $itemtypes{$oldbiblio->{itemtype}}->{imageurl};
- $oldbiblio->{description} = $itemtypes{$oldbiblio->{itemtype}}->{description};
- } else {
- $oldbiblio->{imageurl} = getitemtypeimagesrc()."/".$itemtypes{$oldbiblio->{itemtype}}->{imageurl} if ($itemtypes{$oldbiblio->{itemtype}}->{imageurl});
- $oldbiblio->{description} = $itemtypes{$oldbiblio->{itemtype}}->{description};
+ if ( $itemtypes{ $oldbiblio->{itemtype} }->{imageurl} =~ /^http:/ ) {
+ $oldbiblio->{imageurl} =
+ $itemtypes{ $oldbiblio->{itemtype} }->{imageurl};
+ $oldbiblio->{description} =
+ $itemtypes{ $oldbiblio->{itemtype} }->{description};
}
+ else {
+ $oldbiblio->{imageurl} =
+ getitemtypeimagesrc() . "/"
+ . $itemtypes{ $oldbiblio->{itemtype} }->{imageurl}
+ if ( $itemtypes{ $oldbiblio->{itemtype} }->{imageurl} );
+ $oldbiblio->{description} =
+ $itemtypes{ $oldbiblio->{itemtype} }->{description};
+ }
+
# add spans to search term in results
- foreach my $term (keys %$span_terms_hashref) {
+ foreach my $term ( keys %$span_terms_hashref ) {
+
#warn "term: $term";
my $old_term = $term;
- if (length($term) > 3) {
+ if ( length($term) > 3 ) {
$term =~ s/(.*=|\)|\(|\+|\.)//g;
+
#FIXME: is there a better way to do this?
$oldbiblio->{'title'} =~ s/$term/<span class=term>$&<\/span>/gi;
- $oldbiblio->{'subtitle'} =~ s/$term/<span class=term>$&<\/span>/gi;
- #$oldbiblio->{'author'} =~ s/$term/<span class=term>$&<\/span>/gi; #FIXME: add back later
- $oldbiblio->{'publishercode'} =~ s/$term/<span class=term>$&<\/span>/gi;
+ $oldbiblio->{'subtitle'} =~
+ s/$term/<span class=term>$&<\/span>/gi;
+
+#$oldbiblio->{'author'} =~ s/$term/<span class=term>$&<\/span>/gi; #FIXME: add back later
+ $oldbiblio->{'publishercode'} =~
+ s/$term/<span class=term>$&<\/span>/gi;
$oldbiblio->{'place'} =~ s/$term/<span class=term>$&<\/span>/gi;
$oldbiblio->{'pages'} =~ s/$term/<span class=term>$&<\/span>/gi;
$oldbiblio->{'notes'} =~ s/$term/<span class=term>$&<\/span>/gi;
@@ -3177,12 +3267,13 @@
}
}
- if ($i % 2) {
- $toggle="#ffffcc";
- } else {
- $toggle="white";
+ if ( $i % 2 ) {
+ $toggle = "#ffffcc";
+ }
+ else {
+ $toggle = "white";
}
- $oldbiblio->{'toggle'}=$toggle;
+ $oldbiblio->{'toggle'} = $toggle;
my @fields = $marcrecord->field($itemtag);
my @items_loop;
my $items;
@@ -3192,43 +3283,53 @@
my $itemlost_count = 0;
my $itembinding_count = 0;
my $norequests = 1;
+
foreach my $field (@fields) {
my $item;
foreach my $code ( keys %subfieldstosearch ) {
- $item->{$code}=$field->subfield($subfieldstosearch{$code});
+ $item->{$code} = $field->subfield( $subfieldstosearch{$code} );
}
- if ($item->{wthdrawn}) {
+ if ( $item->{wthdrawn} ) {
$wthdrawn_count++;
}
- elsif ($item->{notforloan} == -1) {
+ elsif ( $item->{notforloan} == -1 ) {
$ordered_count++;
$norequests = 0;
}
- elsif ($item->{itemlost}) {
+ elsif ( $item->{itemlost} ) {
$itemlost_count++;
}
- elsif ($item->{binding}) {
+ elsif ( $item->{binding} ) {
$itembinding_count++;
}
- elsif (($item->{onloan}) && ($item->{onloan} != '0000-00-00')) {
+ elsif ( ( $item->{onloan} ) && ( $item->{onloan} != '0000-00-00' ) )
+ {
$onloan_count++;
$norequests = 0;
}
else {
$norequests = 0;
- if ($item->{'homebranch'}) {
- $items->{$item->{'homebranch'}}->{count}++;
+ if ( $item->{'homebranch'} ) {
+ $items->{ $item->{'homebranch'} }->{count}++;
}
+
# Last resort
- elsif ($item->{'holdingbranch'}) {
- $items->{$item->{'homebranch'}}->{count}++;
+ elsif ( $item->{'holdingbranch'} ) {
+ $items->{ $item->{'homebranch'} }->{count}++;
}
- $items->{$item->{homebranch}}->{itemcallnumber}= $item->{itemcallnumber};
+ $items->{ $item->{homebranch} }->{itemcallnumber} =
+ $item->{itemcallnumber};
}
} # notforloan, item level and biblioitem level
- for my $key (keys %$items) {
+ for my $key ( keys %$items ) {
+
#warn "key: $key";
- my $this_item = { branchname => $branches{$key}, branchcode => $key, count => $items->{$key}->{count}, itemcallnumber => $items->{$key}->{itemcallnumber} };
+ my $this_item = {
+ branchname => $branches{$key},
+ branchcode => $key,
+ count => $items->{$key}->{count},
+ itemcallnumber => $items->{$key}->{itemcallnumber}
+ };
push @items_loop, $this_item;
}
$oldbiblio->{norequests} = $norequests;
@@ -3296,12 +3397,11 @@
=cut
- push (@newresults, $oldbiblio);
+ push( @newresults, $oldbiblio );
}
return @newresults;
}
-
END { } # module clean-up code here (global destructor)
1;
More information about the Koha-cvs
mailing list