Bug 6554: Followup for serial search
[koha-equinox.git] / serials / serials-search.pl
1 #!/usr/bin/perl
2
3 # Copyright 2012 Koha Team
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
21 =head1 NAME
22
23 serials-search.pl
24
25 =head1 DESCRIPTION
26
27 this script is the search page for serials
28
29 =cut
30
31 use Modern::Perl;
32 use CGI;
33 use C4::Auth;
34 use C4::Branch;
35 use C4::Context;
36 use C4::Output;
37 use C4::Serials;
38
39 my $query         = new CGI;
40 my $title         = $query->param('title_filter') || '';
41 utf8::decode($title);
42 my $ISSN          = $query->param('ISSN_filter') || '';
43 my $EAN           = $query->param('EAN_filter') || '';
44 my $publisher     = $query->param('publisher_filter') || '';
45 utf8::decode($publisher);
46 my $bookseller    = $query->param('bookseller_filter') || '';
47 utf8::decode($bookseller);
48 my $biblionumber  = $query->param('biblionumber') || '';
49 my $branch        = $query->param('branch_filter') || '';
50 my $routing       = $query->param('routing') || C4::Context->preference("RoutingSerials");
51 my $searched      = $query->param('searched') || 0;
52 my @subscriptionids = $query ->param('subscriptionid');
53 my $op            = $query->param('op');
54
55 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
56     {
57         template_name   => "serials/serials-search.tmpl",
58         query           => $query,
59         type            => "intranet",
60         authnotrequired => 0,
61         flagsrequired   => { serials => '*' },
62         debug           => 1,
63     }
64 );
65
66 if ( $op and $op eq "close" ) {
67     for my $subscriptionid ( @subscriptionids ) {
68         C4::Serials::CloseSubscription( $subscriptionid );
69     }
70 } elsif ( $op and $op eq "reopen" ) {
71     for my $subscriptionid ( @subscriptionids ) {
72         C4::Serials::ReopenSubscription( $subscriptionid );
73     }
74 }
75
76 my @subscriptions;
77 if ($searched){
78     @subscriptions = SearchSubscriptions(
79         {
80             biblionumber => $biblionumber,
81             title        => $title,
82             issn         => $ISSN,
83             ean          => $EAN,
84             publisher    => $publisher,
85             bookseller   => $bookseller,
86             branch       => $branch,
87         }
88     );
89 }
90
91 # to toggle between create or edit routing list options
92 if ($routing) {
93     for my $subscription ( @subscriptions) {
94         $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} );
95         $subscription->{branchname} = GetBranchName ( $subscription->{branchcode} );
96     }
97 }
98
99 my (@openedsubscriptions, @closedsubscriptions);
100 for my $sub ( @subscriptions ) {
101     unless ( $sub->{closed} ) {
102         push @openedsubscriptions, $sub;
103     } else {
104         push @closedsubscriptions, $sub;
105     }
106 }
107
108 my $branches = GetBranches();
109 my @branches_loop;
110 foreach (sort keys %$branches){
111     my $selected = 0;
112     $selected = 1 if( defined $branch and $branch eq $_ );
113     push @branches_loop, {
114         branchcode  => $_,
115         branchname  => $branches->{$_}->{'branchname'},
116         selected    => $selected,
117     };
118 }
119
120 $template->param(
121     openedsubscriptions => \@openedsubscriptions,
122     closedsubscriptions => \@closedsubscriptions,
123     total         => @openedsubscriptions + @closedsubscriptions,
124     title_filter  => $title,
125     ISSN_filter   => $ISSN,
126     EAN_filter    => $EAN,
127     publisher_filter => $publisher,
128     bookseller_filter  => $bookseller,
129     branch_filter => $branch,
130     branches_loop => \@branches_loop,
131     done_searched => $searched,
132     routing       => $routing,
133     marcflavour   => (uc(C4::Context->preference("marcflavour")))
134 );
135
136 output_html_with_http_headers $query, $cookie, $template->output;