From 61c3153168587796ad38b88381a8ba9f182c5bdb 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 --- C4/Serials.pm | 65 +++++++ .../prog/en/includes/serials-search.inc | 60 ++++---- .../prog/en/modules/serials/serials-home.tt | 176 ++++---------------- .../prog/en/modules/serials/serials-search.tt | 172 +++++++++++++++++++ serials/serials-home.pl | 44 ++++-- serials/serials-search.pl | 114 +++++++++++++ 6 files changed, 446 insertions(+), 185 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 58b6078..9508166 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 @@ -630,6 +631,70 @@ 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->{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}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/serials-search.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-search.inc index dfb908f..beb309c 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/serials-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-home.tt index 1fdf693..973fcc9 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,24 +1,6 @@ [% INCLUDE 'doc-head-open.inc' %] Koha › Serials [% biblionumber %] - [% INCLUDE 'doc-head-close.inc' %] - -[% INCLUDE 'datatables-strings.inc' %] - - [% INCLUDE 'header.inc' %] @@ -27,133 +9,39 @@
- -
-
-
- [% 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 %] +
+
+
+ [% INCLUDE 'serials-toolbar.inc' %] + [% IF ( information ) %] + Serials updated : +
ISSNTitle Notes - Library (callnumber) - Routing list  
+ - - - - - [% IF ( routing && CAN_user_serials_routing ) %] - - [% END %] - - + + + + + - [% END %] - -
- [% 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.cannotedit ) %] -   - [% ELSE %] - [% IF ( subscription.routingedit ) %] - Edit - [% ELSE %] - New - [% END %] - [% END %] - Issue history - - [% IF ( subscription.cannotedit ) %] -   - [% ELSE %] - [% IF ( CAN_user_serials_receive_serials ) %]Serial receive[% END %] - [% END %] - SerialseqStatusPublished datePlanned dateNotes
- - [% END %] - -
-
- -
-[% INCLUDE 'serials-menu.inc' %] -
+ + + [% FOREACH informatio IN information %] + + [% informatio.serialseq %] + [% informatio.status %] + [% informatio.publisheddate %] + [% informatio.planneddate %] + [% informatio.notes %] + + [% END %] + + + [% END %] +
+
+
+ [% 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 0000000..4f8dfce --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt @@ -0,0 +1,172 @@ +[% INCLUDE 'doc-head-open.inc' %] +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 ) %] + Advanced search +
+
+
+ + [% 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 + Library (callnumber) + Routing 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.cannotedit ) %] +   + [% ELSE %] + [% IF ( subscription.routingedit ) %] + Edit + [% 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 21b76e0..1eaf469 100755 --- a/serials/serials-home.pl +++ b/serials/serials-home.pl @@ -44,18 +44,21 @@ use strict; use warnings; 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 $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 $supplier = $query->param('supplier_filter'); +my $branch = $query->param('branch_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'); @@ -93,8 +96,8 @@ if (@serialseqs){ $template->param('information'=>\@information); } my @subscriptions; -if ($searched) { - @subscriptions = GetSubscriptions( $title, $ISSN, $EAN, $biblionumber ); +if ($searched){ + @subscriptions = SearchSubscriptions( $title, $ISSN, $EAN, $publisher, $supplier, $branch ); } # to toggle between create or edit routing list options @@ -105,10 +108,27 @@ if ($routing) { } } +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, + supplier_filter => $supplier, + branch_filter => $branch, + branches_loop => \@branches_loop, 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 0000000..098c380 --- /dev/null +++ b/serials/serials-search.pl @@ -0,0 +1,114 @@ +#!/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 $branch = $query->param('branch_filter') || ''; +my $routing = $query->param('routing') || C4::Context->preference("RoutingSerials"); +my $searched = $query->param('searched') || 0; + +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 ( $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( + { + title =>$title, + isbn => $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; -- 1.7.7.3