Merge branch 'bug_9647' into 3.12-master
[koha.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 my $ISSN          = $query->param('ISSN_filter') || '';
42 my $EAN           = $query->param('EAN_filter') || '';
43 my $publisher     = $query->param('publisher_filter') || '';
44 my $bookseller    = $query->param('bookseller_filter') || '';
45 my $biblionumber  = $query->param('biblionumber') || '';
46 my $branch        = $query->param('branch_filter') || '';
47 my $routing       = $query->param('routing') || C4::Context->preference("RoutingSerials");
48 my $searched      = $query->param('searched') || 0;
49 my @subscriptionids = $query ->param('subscriptionid');
50 my $op            = $query->param('op');
51
52 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
53     {
54         template_name   => "serials/serials-search.tmpl",
55         query           => $query,
56         type            => "intranet",
57         authnotrequired => 0,
58         flagsrequired   => { serials => '*' },
59         debug           => 1,
60     }
61 );
62
63 if ( $op and $op eq "close" ) {
64     for my $subscriptionid ( @subscriptionids ) {
65         C4::Serials::CloseSubscription( $subscriptionid );
66     }
67 } elsif ( $op and $op eq "reopen" ) {
68     for my $subscriptionid ( @subscriptionids ) {
69         C4::Serials::ReopenSubscription( $subscriptionid );
70     }
71 }
72
73 my @subscriptions;
74 if ($searched){
75     @subscriptions = SearchSubscriptions(
76         {
77             biblionumber => $biblionumber,
78             title        => $title,
79             issn         => $ISSN,
80             ean          => $EAN,
81             publisher    => $publisher,
82             bookseller   => $bookseller,
83             branch       => $branch,
84         }
85     );
86 }
87
88 # to toggle between create or edit routing list options
89 if ($routing) {
90     for my $subscription ( @subscriptions) {
91         $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} );
92         $subscription->{branchname} = GetBranchName ( $subscription->{branchcode} );
93     }
94 }
95
96 my (@openedsubscriptions, @closedsubscriptions);
97 for my $sub ( @subscriptions ) {
98     unless ( $sub->{closed} ) {
99         push @openedsubscriptions, $sub;
100     } else {
101         push @closedsubscriptions, $sub;
102     }
103 }
104
105 my $branches = GetBranches();
106 my @branches_loop;
107 foreach (sort keys %$branches){
108     my $selected = 0;
109     $selected = 1 if( $branch eq $_ );
110     push @branches_loop, {
111         branchcode  => $_,
112         branchname  => $branches->{$_}->{'branchname'},
113         selected    => $selected,
114     };
115 }
116
117 $template->param(
118     openedsubscriptions => \@openedsubscriptions,
119     closedsubscriptions => \@closedsubscriptions,
120     total         => @openedsubscriptions + @closedsubscriptions,
121     title_filter  => $title,
122     ISSN_filter   => $ISSN,
123     EAN_filter    => $EAN,
124     publisher_filter => $publisher,
125     bookseller_filter  => $bookseller,
126     branch_filter => $branch,
127     branches_loop => \@branches_loop,
128     done_searched => $searched,
129     routing       => $routing,
130     marcflavour   => (uc(C4::Context->preference("marcflavour")))
131 );
132
133 output_html_with_http_headers $query, $cookie, $template->output;