From 214fd0fbd1fb00e9d20efb22c80c9662820fb347 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 9 Mar 2012 10:05:38 +0100 Subject: [PATCH] Bug 5357: Adds a new page for searching subscriptions Test plan: - go on the serial module - click on the 'Advanced search' link (right of subscriptions search in the header) - Search subscriptions (by ISSN, title, EAN, Publisher, Supplier and/or Branch) - Check results are correct Signed-off-by: Corinne HAYET Signed-off-by: Katrin Fischer Signed-off-by: Paul Poulain --- C4/Serials.pm | 69 +++++++ .../prog/en/includes/biblio-view-menu.inc | 2 +- .../prog/en/includes/serials-search.inc | 60 +++--- .../prog/en/modules/serials/serial-issues.tt | 2 +- .../prog/en/modules/serials/serials-home.tt | 165 +--------------- .../prog/en/modules/serials/serials-search.tt | 183 ++++++++++++++++++ serials/serials-home.pl | 71 +------ serials/serials-search.pl | 110 +++++++++++ 8 files changed, 411 insertions(+), 251 deletions(-) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt create mode 100755 serials/serials-search.pl diff --git a/C4/Serials.pm b/C4/Serials.pm index e31d5dfb82..eb620cc719 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -36,6 +36,7 @@ BEGIN { @EXPORT = qw( &NewSubscription &ModSubscription &DelSubscription &GetSubscriptions &GetSubscription &CountSubscriptionFromBiblionumber &GetSubscriptionsFromBiblionumber + &SearchSubscriptions &GetFullSubscriptionsFromBiblionumber &GetFullSubscription &ModSubscriptionHistory &HasSubscriptionStrictlyExpired &HasSubscriptionExpired &GetExpirationDate &abouttoexpire @@ -631,6 +632,74 @@ sub GetSubscriptions { return @results; } +=head2 SearchSubscriptions + +@results = SearchSubscriptions($args); +$args is a hashref. Its keys can be contained: title, issn, ean, publisher, bookseller and branchcode + +this function gets all subscriptions which have title like $title, ISSN like $issn, EAN like $ean, publisher like $publisher, bookseller like $bookseller AND branchcode eq $branch. + +return: +a table of hashref. Each hash containt the subscription. + +=cut + +sub SearchSubscriptions { + my ( $args ) = @_; + + my $query = qq{ + SELECT subscription.*, subscriptionhistory.*, biblio.*, biblioitems.issn + FROM subscription + LEFT JOIN subscriptionhistory USING(subscriptionid) + LEFT JOIN biblio ON biblio.biblionumber = subscription.biblionumber + LEFT JOIN biblioitems ON biblioitems.biblionumber = subscription.biblionumber + LEFT JOIN aqbooksellers ON subscription.aqbooksellerid = aqbooksellers.id + }; + my @where_strs; + my @where_args; + if( $args->{biblionumber} ) { + push @where_strs, "biblio.biblionumber = ?"; + push @where_args, $args->{biblionumber}; + } + if( $args->{title} ){ + push @where_strs, "biblio.title LIKE ?"; + push @where_args, "%$args->{title}%"; + } + if( $args->{issn} ){ + push @where_strs, "biblioitems.issn LIKE ?"; + push @where_args, "%$args->{issn}%"; + } + if( $args->{ean} ){ + push @where_strs, "biblioitems.ean LIKE ?"; + push @where_args, "%$args->{ean}%"; + } + if( $args->{publisher} ){ + push @where_strs, "biblioitems.publishercode LIKE ?"; + push @where_args, "%$args->{publisher}%"; + } + if( $args->{bookseller} ){ + push @where_strs, "aqbooksellers.name LIKE ?"; + push @where_args, "%$args->{bookseller}%"; + } + if( $args->{branch} ){ + push @where_strs, "subscription.branchcode = ?"; + push @where_args, "$args->{branch}"; + } + + if(@where_strs){ + $query .= " WHERE " . join(" AND ", @where_strs); + } + + my $dbh = C4::Context->dbh; + my $sth = $dbh->prepare($query); + $sth->execute(@where_args); + my $results = $sth->fetchall_arrayref( {} ); + $sth->finish; + + return @$results; +} + + =head2 GetSerials ($totalissues,@serials) = GetSerials($subscriptionid); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc index 903cf3a758..b2edbe6ef0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc @@ -25,7 +25,7 @@ [% END %] [% IF ( EasyAnalyticalRecords ) %][% IF ( analyze ) %]
  • [% ELSE %]
  • [% END %]Analytics
  • [% END %] - [% IF ( subscriptionsnumber ) %]
  • Subscription(s)
  • [% END %] + [% IF ( subscriptionsnumber ) %]
  • Subscription(s)
  • [% END %]
      [% IF ( issuehistoryview ) %]
    • [% ELSE %]
    • [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-search.inc index dfb908fc33..beb309c5fe 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-search.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-search.inc @@ -1,35 +1,37 @@
      -

      [% LibraryName %]

      -
      diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serial-issues.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serial-issues.tt index a22b97b47c..7bc9feb763 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serial-issues.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serial-issues.tt @@ -16,7 +16,7 @@

      Subscription information for [% bibliotitle %]

      diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-home.tt index a0cd35efdd..eaafc944f7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-home.tt @@ -1,168 +1,23 @@ [% INCLUDE 'doc-head-open.inc' %] [% USE KohaDates %] Koha › Serials [% biblionumber %] - [% INCLUDE 'doc-head-close.inc' %] - -[% INCLUDE 'datatables-strings.inc' %] - - [% INCLUDE 'header.inc' %] [% INCLUDE 'serials-search.inc' %] - +
      - -
      -
      -
      - [% INCLUDE 'serials-toolbar.inc' %] - -[% IF ( information ) %] -Serials updated : - - - - - - - - -[% FOREACH informatio IN information %] - - - - - - - -[% END %] -
      - Serialseq - - Status - - Published date - - Planned date - - Notes -
      - [% informatio.serialseq %] - - [% informatio.status %] - - [% informatio.publisheddate %] - - [% informatio.planneddate %] - - [% informatio.notes %] -
      -[% END %] - [% IF ( done_searched ) %] -

      Serials subscriptions

      - - - - - - - - - - - [% IF ( routing && CAN_user_serials_routing ) %] - - [% END %] - - - - - - - - - - - - - [% IF ( routing && CAN_user_serials_routing ) %][% END %] - - - - - - [% FOREACH subscription IN subscriptions %] - - - - - - - - [% IF ( routing && CAN_user_serials_routing ) %] - - [% END %] - - - - [% END %] - -
      ISSNTitle Notes LibraryCall numberExpiration dateRouting list  
      - [% IF ( subscription.issn ) %][% subscription.issn %] - [% END %] - [% subscription.title |html %] - [% IF ( subscription.notes ) %][% subscription.notes %][% END %] - [% IF ( subscription.internalnotes ) %]([% subscription.internalnotes %])[% END %] - - [% IF ( subscription.branchname ) %][% subscription.branchname %][% END %] - - [% IF ( subscription.callnumber ) %][% subscription.callnumber %][% END %] - - [% IF ( subscription.enddate ) %][% subscription.enddate | $KohaDates %][% END %] - - [% IF ( subscription.cannotedit ) %] -   - [% ELSE %] - [% IF ( subscription.routingedit ) %] - Edit - ([% subscription.routingedit %]) - [% ELSE %] - New - [% END %] - [% END %] - Issue history - - [% IF ( subscription.cannotedit ) %] -   - [% ELSE %] - [% IF ( CAN_user_serials_receive_serials ) %]Serial receive[% END %] - [% END %] -
      - - [% END %] - -
      -
      - -
      -[% INCLUDE 'serials-menu.inc' %] -
      +
      +
      +
      + [% INCLUDE 'serials-toolbar.inc' %] +
      +
      +
      + [% INCLUDE 'serials-menu.inc' %] +
      [% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt new file mode 100644 index 0000000000..a8b83995e2 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt @@ -0,0 +1,183 @@ +[% INCLUDE 'doc-head-open.inc' %] +[% USE KohaDates %] +Koha › Serials [% biblionumber %] + +[% INCLUDE 'doc-head-close.inc' %] + +[% INCLUDE 'datatables-strings.inc' %] + + + + +[% INCLUDE 'header.inc' %] +[% INCLUDE 'serials-search.inc' %] + + + +
      +
      +
      +
      + [% INCLUDE 'serials-toolbar.inc' %] + +

      Serials subscriptions

      + +
      +
      +
      + [% IF ( done_searched ) %] + +
      +
      +
      + + [% IF ( done_searched ) %] + [% IF ( subscriptions ) %] + + + + + + + + + + [% IF ( routing && CAN_user_serials_routing ) %] + + [% END %] + + + + + + + + + + + + + [% IF ( routing && CAN_user_serials_routing ) %][% END %] + + + + + + [% FOREACH subscription IN subscriptions %] + + + + + + + + [% IF ( routing && CAN_user_serials_routing ) %] + + [% END %] + + + + [% END %] + +
      ISSNTitle Notes LibraryCall numberExpiration dateRouting list  
      + [% IF ( subscription.issn ) %][% subscription.issn %] + [% END %] + [% subscription.title |html %] + [% IF ( subscription.notes ) %][% subscription.notes %][% END %] + [% IF ( subscription.internalnotes ) %]([% subscription.internalnotes %])[% END %] + + [% IF ( subscription.branchname ) %][% subscription.branchname %][% END %] + + [% IF ( subscription.callnumber ) %][% subscription.callnumber %][% END %] + + [% IF ( subscription.enddate ) %][% subscription.enddate | $KohaDates %][% END %] + + [% IF ( subscription.cannotedit ) %] +   + [% ELSE %] + [% IF ( subscription.routingedit ) %] + Edit + ([% subscription.routingedit %]) + [% ELSE %] + New + [% END %] + [% END %] + Issue history + + [% IF ( subscription.cannotedit ) %] +   + [% ELSE %] + [% IF ( CAN_user_serials_receive_serials ) %]Serial receive[% END %] + [% END %] +
      + [% ELSE %] + There is no subscription for your search. + [% END %] + [% END %] +
      +
      + +
      + [% INCLUDE 'serials-menu.inc' %] +
      +
      +[% INCLUDE 'intranet-bottom.inc' %] diff --git a/serials/serials-home.pl b/serials/serials-home.pl index 21b76e0513..9ec03364ae 100755 --- a/serials/serials-home.pl +++ b/serials/serials-home.pl @@ -26,42 +26,18 @@ serials-home.pl this script is the main page for serials/ -=head1 PARAMETERS - -=over 4 - -=item title - -=item ISSN - -=item biblionumber - -=back - =cut -use strict; -use warnings; +use Modern::Perl; use CGI; use C4::Auth; -use C4::Serials; -use C4::Output; -use C4::Context; use C4::Branch; +use C4::Context; +use C4::Output; +use C4::Serials; -my $query = new CGI; -my $title = $query->param('title_filter'); -my $ISSN = $query->param('ISSN_filter'); -my $EAN = $query->param('EAN_filter'); -my $routing = $query->param('routing') || C4::Context->preference("RoutingSerials"); -my $searched = $query->param('searched'); -my $biblionumber = $query->param('biblionumber'); - -my @serialseqs = $query->param('serialseq'); -my @planneddates = $query->param('planneddate'); -my @publisheddates = $query->param('publisheddate'); -my @status = $query->param('status'); -my @notes = $query->param('notes'); +my $query = new CGI; +my $routing = $query->param('routing') || C4::Context->preference("RoutingSerials"); my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { @@ -74,42 +50,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -if (@serialseqs){ - my @information; - my $index; - foreach my $seq (@serialseqs){ - if ($seq){ - ### FIXME This limitation that a serial must be given a title may not be very efficient for some library who do not update serials titles. - push @information, - { serialseq=>$seq, - publisheddate=>$publisheddates[$index], - planneddate=>$planneddates[$index], - notes=>$notes[$index], - status=>$status[$index] - } - } - $index++; - } - $template->param('information'=>\@information); -} -my @subscriptions; -if ($searched) { - @subscriptions = GetSubscriptions( $title, $ISSN, $EAN, $biblionumber ); -} - -# to toggle between create or edit routing list options -if ($routing) { - for my $subscription ( @subscriptions) { - $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} ); - $subscription->{branchname} = GetBranchName ( $subscription->{branchcode} ); - } -} - $template->param( - subscriptions => \@subscriptions, - title_filter => $title, - ISSN_filter => $ISSN, - done_searched => $searched, routing => $routing, (uc(C4::Context->preference("marcflavour"))) => 1 ); diff --git a/serials/serials-search.pl b/serials/serials-search.pl new file mode 100755 index 0000000000..0da19d0f1c --- /dev/null +++ b/serials/serials-search.pl @@ -0,0 +1,110 @@ +#!/usr/bin/perl + +# Copyright 2012 Koha Team +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with Koha; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +=head1 NAME + +serials-search.pl + +=head1 DESCRIPTION + +this script is the search page for serials + +=cut + +use Modern::Perl; +use CGI; +use C4::Auth; +use C4::Branch; +use C4::Context; +use C4::Output; +use C4::Serials; + +my $query = new CGI; +my $title = $query->param('title_filter') || ''; +my $ISSN = $query->param('ISSN_filter') || ''; +my $EAN = $query->param('EAN_filter') || ''; +my $publisher = $query->param('publisher_filter') || ''; +my $bookseller = $query->param('bookseller_filter') || ''; +my $biblionumber = $query->param('biblionumber') || ''; +my $branch = $query->param('branch_filter') || ''; +my $routing = $query->param('routing') || C4::Context->preference("RoutingSerials"); +my $searched = $query->param('searched') || 0; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "serials/serials-search.tmpl", + query => $query, + type => "intranet", + authnotrequired => 0, + flagsrequired => { serials => '*' }, + debug => 1, + } +); + +my @subscriptions; +if ($searched){ + @subscriptions = SearchSubscriptions( + { + biblionumber => $biblionumber, + title => $title, + issn => $ISSN, + ean => $EAN, + publisher => $publisher, + bookseller => $bookseller, + branch => $branch, + } + ); +} + +# to toggle between create or edit routing list options +if ($routing) { + for my $subscription ( @subscriptions) { + $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} ); + $subscription->{branchname} = GetBranchName ( $subscription->{branchcode} ); + } +} + +my $branches = GetBranches(); +my @branches_loop; +foreach (sort keys %$branches){ + my $selected = 0; + $selected = 1 if( $branch eq $_ ); + push @branches_loop, { + branchcode => $_, + branchname => $branches->{$_}->{'branchname'}, + selected => $selected, + }; +} + +$template->param( + subscriptions => \@subscriptions, + title_filter => $title, + ISSN_filter => $ISSN, + EAN_filter => $EAN, + publisher_filter => $publisher, + bookseller_filter => $bookseller, + branch_filter => $branch, + branches_loop => \@branches_loop, + done_searched => $searched, + routing => $routing, + (uc(C4::Context->preference("marcflavour"))) => 1 +); + +output_html_with_http_headers $query, $cookie, $template->output; -- 2.20.1