From ec64f1fcd8b6fc4a4a5c158e339ff8a3860c31cd Mon Sep 17 00:00:00 2001 From: tipaul Date: Mon, 10 May 2004 09:24:14 +0000 Subject: [PATCH] Marc search ported to OPAC. seems to work fine --- C4/SearchMarc.pm | 55 +++- koha-tmpl/opac-tmpl/css/en/opac-main.tmpl | 9 +- koha-tmpl/opac-tmpl/css/en/opac-search.tmpl | 158 +++++++++--- .../opac-tmpl/css/en/opac-searchresults.tmpl | 236 +++++++++--------- opac/opac-detail.pl | 1 - opac/opac-main.pl | 1 - opac/opac-search.pl | 167 ++++++++++++- 7 files changed, 449 insertions(+), 178 deletions(-) diff --git a/C4/SearchMarc.pm b/C4/SearchMarc.pm index 566f419466..4721601d3c 100644 --- a/C4/SearchMarc.pm +++ b/C4/SearchMarc.pm @@ -219,19 +219,58 @@ sub catalogsearch { # we have bibid list. Now, loads title and author from [offset] to [offset]+[length] my $counter = $offset; - $sth = $dbh->prepare("select author,title from biblio,marc_biblio where biblio.biblionumber=marc_biblio.biblionumber and bibid=?"); + $sth = $dbh->prepare("SELECT biblio.biblionumber,author, title, items.holdingbranch, items.itemcallnumber, bibid + FROM biblio, marc_biblio left join items on items.biblionumber = biblio.biblionumber + WHERE biblio.biblionumber = marc_biblio.biblionumber AND bibid = ? + GROUP BY items.biblionumber, items.holdingbranch, items.itemcallnumber"); my @finalresult = (); + my @CNresults=(); + my $oldbiblionumber=0; + my $totalitems=0; + my ($biblionumber,$author,$title,$holdingbranch, $itemcallnumber, $bibid); + my ($oldbibid, $oldauthor, $oldtitle,$oldbiblionumber); while (($counter <= $#result) && ($counter <= ($offset + $length))) { $sth->execute($result[$counter]); - my ($author,$title) = $sth->fetchrow; - my %line; - $line{bibid}=$result[$counter]; - $line{author}=$author; - $line{title}=$title; - push @finalresult, \%line; + while (($biblionumber,$author,$title,$holdingbranch, $itemcallnumber, $bibid) = $sth->fetchrow) { +# warn "bibid : $oldbiblionumber ($biblionumber,$author,$title,$holdingbranch, $itemcallnumber, $bibid)"; + # parse the result, putting holdingbranch & itemcallnumber in separate array + # then author, title & 1st array in main array + if ($oldbiblionumber && ($oldbiblionumber ne $biblionumber)) { + my %line; + $line{bibid}=$oldbibid; + $line{author}=$oldauthor; + $line{title}=$oldtitle; + $line{totitem} = $totalitems; + $line{biblionumber} = $oldbiblionumber; + my @CNresults2= @CNresults; + $line{CN} = \@CNresults2; + @CNresults = (); + push @finalresult, \%line; + $totalitems=0; + } + $oldbibid = $bibid; + $oldauthor = $author; + $oldtitle = $title; + $oldbiblionumber = $biblionumber; + $totalitems++ if ($holdingbranch); + my %lineCN; + $lineCN{holdingbranch} = $holdingbranch; + $lineCN{itemcallnumber} = $itemcallnumber; + push @CNresults,\%lineCN; + } $counter++; } - +# add the last line, that is not reached byt the loop / if ($oldbiblionumber...) + my %line; + $line{bibid}=$oldbibid; + $line{author}=$oldauthor; + $line{title}=$oldtitle; + $line{totitem} = $totalitems; + $line{biblionumber} = $oldbiblionumber; + my @CNresults2= @CNresults; + $line{CN} = \@CNresults2; + @CNresults = (); + push @finalresult, \%line; my $nbresults = $#result + 1; return (\@finalresult, $nbresults); } diff --git a/koha-tmpl/opac-tmpl/css/en/opac-main.tmpl b/koha-tmpl/opac-tmpl/css/en/opac-main.tmpl index a24810945a..8f1584bd2f 100644 --- a/koha-tmpl/opac-tmpl/css/en/opac-main.tmpl +++ b/koha-tmpl/opac-tmpl/css/en/opac-main.tmpl @@ -15,10 +15,15 @@

Search the catalogue

-
+

+ -
+ + + + +

Advanced Search, More Options diff --git a/koha-tmpl/opac-tmpl/css/en/opac-search.tmpl b/koha-tmpl/opac-tmpl/css/en/opac-search.tmpl index e984080100..a9ea5edf22 100644 --- a/koha-tmpl/opac-tmpl/css/en/opac-search.tmpl +++ b/koha-tmpl/opac-tmpl/css/en/opac-search.tmpl @@ -1,35 +1,129 @@ - - +

-

Advanced search

- -
    -
  • -
-

OR :

-
    -
  • -
-

OR one or more from :

-
    -
  • -
  • -
  • -
  • - + "> +
    +

    Search on

    +

    + + + + + + +

    +

    + + + + + + +

    +

    + + + + + +

    +

    + + + + + + +

    +

    + + + + + + +

    +

    + + + + + +

    +

    + + + + + +

    +

    + + + + + + +

    + +
    +
    +

    Results per page : + + Ordered by + -

  • -
  • -
-

using Normal or Exact search

- -

- - -

-

Note that if you enter a value in Keyword and a value somewhere else, only keyword will be used

- +

+

+ +

+
+ + +
- + diff --git a/koha-tmpl/opac-tmpl/css/en/opac-searchresults.tmpl b/koha-tmpl/opac-tmpl/css/en/opac-searchresults.tmpl index 9367a61b42..0bfd0769d2 100644 --- a/koha-tmpl/opac-tmpl/css/en/opac-searchresults.tmpl +++ b/koha-tmpl/opac-tmpl/css/en/opac-searchresults.tmpl @@ -4,143 +4,131 @@

You searched on

-

acquired in the last days

+

acquired in the last days

-

You did not specify any search criteria

+

You did not specify any search criteria

-

results found

-

- - - << - -   - - - -   - - &=" class="smallnumber"> - -   - - - - &=">>> - -   - -

-

 

- - - - - - /images/background-opac.gif"> - - - - - - +

results found

+
+

+ + &=&resultsperpage=&type=intranet&op=do_search> + + + + + + + + &=&resultsperpage=&type=intranet&op=do_search> + -

/images/background-opac.gif"> - + + + + +
Subject
-   + + &=&&resultsperpage=&type=intranet&op=do_search> + +

+

+ +  Results to of

+ +   No results found.
+ +

+ + + + + + + + + + + + + + + + + + + + + -
TitleAuthor©Item CountLocation 
class="hilighted"> + "> + class="hilighted"> + "> + class="hilighted"> + + class="hilighted"> + + class="hilighted"> + + () + + class="hilighted"> + + ">Request + + Not Reservable +
+ +
+ + &="><<< Previous + +   + +   + + &=">Next >>> + +   + +
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
TitleAuthor©Item CountLocation 
class="hilighted"> - "> - class="hilighted"> - "> - class="hilighted"> - - class="hilighted"> - - class="hilighted"> - - class="hilighted"> - - ">Request - - Not Reservable - -
- - &="><<< Previous - -   +

+ Results through of records. +

+ +
  - - &=">Next >>> + + + + + &=&resultsperpage=&type=intranet&op=do_search> + + + + &=&&resultsperpage=&type=intranet&op=do_search> + +

+

+ +  Results to of

-   +   No results found.
-

- - -

- Results through of records. -

- -

- - - << - -   - - - -   - - &="> - -   - - - - &=">>> - -   - -

+

+ -

Sorry, there were no results

+

Sorry, there were no results

diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index eda7ddf6ad..1fbd46e6ec 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -53,7 +53,6 @@ $template->param(BIBLIO_RESULTS => $resultsarray); $template->param(ITEM_RESULTS => $itemsarray); $template->param(WEB_RESULTS => $webarray); $template->param(SITE_RESULTS => $sitearray, - LibraryName => C4::Context->preference("LibraryName"), ); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/opac/opac-main.pl b/opac/opac-main.pl index c6a16cc33c..202a54e8b2 100755 --- a/opac/opac-main.pl +++ b/opac/opac-main.pl @@ -35,6 +35,5 @@ my ($template, $borrowernumber, $cookie) }); $template->param(CGIitemtype => $CGIitemtype, - LibraryName => C4::Context->preference("LibraryName"), ); output_html_with_http_headers $input, $cookie, $template->output; diff --git a/opac/opac-search.pl b/opac/opac-search.pl index 297761cdb0..3a8345472b 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -8,6 +8,9 @@ use C4::Context; use CGI; use C4::Database; use HTML::Template; +use C4::SearchMarc; +use C4::Catalogue; +use C4::Biblio; my $classlist=''; @@ -20,18 +23,162 @@ while (my ($description,$itemtype) = $sth->fetchrow) { my $query = new CGI; +my $op = $query->param("op"); +my $type=$query->param('type'); -my ($template, $borrowernumber, $cookie) - = get_template_and_user({template_name => "opac-search.tmpl", - query => $query, - type => "opac", - authnotrequired => 1, - flagsrequired => {borrow => 1}, - }); +my $startfrom=$query->param('startfrom'); +$startfrom=0 if(!defined $startfrom); +my ($template, $loggedinuser, $cookie); +my $resultsperpage; +if ($op eq "do_search") { + my @marclist = $query->param('marclist'); + my @and_or = $query->param('and_or'); + my @excluding = $query->param('excluding'); + my @operator = $query->param('operator'); + my @value = $query->param('value'); -$template->param(classlist => $classlist, - LibraryName => C4::Context->preference("LibraryName"), -); + $resultsperpage= $query->param('resultsperpage'); + $resultsperpage = 19 if(!defined $resultsperpage); + my $orderby = $query->param('orderby'); + + # builds tag and subfield arrays + my @tags; + + foreach my $marc (@marclist) { + if ($marc) { + my ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,$marc); + if ($tag) { + push @tags,$dbh->quote("$tag$subfield"); + } else { + push @tags, $dbh->quote(substr($marc,0,4)); + } + } else { + push @tags, ""; + } + } + findseealso($dbh,\@tags); + warn "IN THERE"; + my ($results,$total) = catalogsearch($dbh, \@tags,\@and_or, + \@excluding, \@operator, \@value, + $startfrom*$resultsperpage, $resultsperpage,$orderby); + + ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "opac-searchresults.tmpl", + query => $query, + type => 'opac', + authnotrequired => 1, + debug => 1, + }); + + # multi page display gestion + my $displaynext=0; + my $displayprev=$startfrom; + if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){ + $displaynext = 1; + } + + my @field_data = (); + + + for(my $i = 0 ; $i <= $#marclist ; $i++) + { + push @field_data, { term => "marclist", val=>$marclist[$i] }; + push @field_data, { term => "and_or", val=>$and_or[$i] }; + push @field_data, { term => "excluding", val=>$excluding[$i] }; + push @field_data, { term => "operator", val=>$operator[$i] }; + push @field_data, { term => "value", val=>$value[$i] }; + } + + my @numbers = (); + + if ($total>$resultsperpage) + { + for (my $i=1; $i<$total/$resultsperpage+1; $i++) + { + if ($i<16) + { + my $highlight=0; + ($startfrom==($i-1)) && ($highlight=1); + push @numbers, { number => $i, + highlight => $highlight , + searchdata=> \@field_data, + startfrom => ($i-1)}; + } + } + } + + my $from = $startfrom*$resultsperpage+1; + my $to; + + if($total < (($startfrom+1)*$resultsperpage)) + { + $to = $total; + } else { + $to = (($startfrom+1)*$resultsperpage); + } + $template->param(results => $results, + startfrom=> $startfrom, + displaynext=> $displaynext, + displayprev=> $displayprev, + resultsperpage => $resultsperpage, + startfromnext => $startfrom+1, + startfromprev => $startfrom-1, + searchdata=>\@field_data, + total=>$total, + from=>$from, + to=>$to, + numbers=>\@numbers, + ); + +} else { + ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "opac-search.tmpl", + query => $query, + type => "opac", + authnotrequired => 1, + }); + + + $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description"); + $sth->execute; + my @itemtype; + my %itemtypes; + push @itemtype, ""; + $itemtypes{''} = ""; + while (my ($value,$lib) = $sth->fetchrow_array) { + push @itemtype, $value; + $itemtypes{$value}=$lib; + } + + my $CGIitemtype=CGI::scrolling_list( -name => 'value', + -values => \@itemtype, + -labels => \%itemtypes, + -size => 1, + -multiple => 0 ); + $sth->finish; + + my @branches; + my @select_branch; + my %select_branches; + my ($count2,@branches)=branches(); + push @select_branch, ""; + $select_branches{''} = ""; + for (my $i=0;$i<$count2;$i++){ + push @select_branch, $branches[$i]->{'branchcode'};# + $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'}; + } + my $CGIbranch=CGI::scrolling_list( -name => 'value', + -values => \@select_branch, + -labels => \%select_branches, + -size => 1, + -multiple => 0 ); + $sth->finish; + + $template->param(classlist => $classlist, + CGIitemtype => $CGIitemtype, + CGIbranch => $CGIbranch, + ); +} output_html_with_http_headers $query, $cookie, $template->output; -- 2.39.5