Bug 11944: use CGI( -utf8 ) everywhere
[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 qw ( -utf8 );
33 use C4::Auth;
34 use C4::Branch;
35 use C4::Context;
36 use C4::Output;
37 use C4::Serials;
38
39 use Koha::DateUtils;
40
41 my $query         = new CGI;
42 my $title         = $query->param('title_filter') || '';
43 my $ISSN          = $query->param('ISSN_filter') || '';
44 my $EAN           = $query->param('EAN_filter') || '';
45 my $callnumber    = $query->param('callnumber_filter') || '';
46 my $publisher     = $query->param('publisher_filter') || '';
47 my $bookseller    = $query->param('bookseller_filter') || '';
48 my $biblionumber  = $query->param('biblionumber') || '';
49 my $branch        = $query->param('branch_filter') || '';
50 my $location      = $query->param('location_filter') || '';
51 my $expiration_date = $query->param('expiration_date_filter') || '';
52 my $routing       = $query->param('routing') || C4::Context->preference("RoutingSerials");
53 my $searched      = $query->param('searched') || 0;
54 my @subscriptionids = $query ->param('subscriptionid');
55 my $op            = $query->param('op');
56
57 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
58     {
59         template_name   => "serials/serials-search.tt",
60         query           => $query,
61         type            => "intranet",
62         authnotrequired => 0,
63         flagsrequired   => { serials => '*' },
64         debug           => 1,
65     }
66 );
67
68 if ( $op and $op eq "close" ) {
69     for my $subscriptionid ( @subscriptionids ) {
70         C4::Serials::CloseSubscription( $subscriptionid );
71     }
72 } elsif ( $op and $op eq "reopen" ) {
73     for my $subscriptionid ( @subscriptionids ) {
74         C4::Serials::ReopenSubscription( $subscriptionid );
75     }
76 }
77
78 my $expiration_date_dt = $expiration_date ? dt_from_string( $expiration_date ) : undef;
79 my @subscriptions;
80 if ($searched){
81     @subscriptions = SearchSubscriptions(
82         {
83             biblionumber => $biblionumber,
84             title        => $title,
85             issn         => $ISSN,
86             ean          => $EAN,
87             callnumber   => $callnumber,
88             publisher    => $publisher,
89             bookseller   => $bookseller,
90             branch       => $branch,
91             location     => $location,
92             expiration_date => $expiration_date_dt,
93         }
94     );
95 }
96
97 # to toggle between create or edit routing list options
98 if ($routing) {
99     for my $subscription ( @subscriptions) {
100         $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} );
101     }
102 }
103
104 my (@openedsubscriptions, @closedsubscriptions);
105 for my $sub ( @subscriptions ) {
106     unless ( $sub->{closed} ) {
107         push @openedsubscriptions, $sub
108             unless $sub->{cannotdisplay};
109     } else {
110         push @closedsubscriptions, $sub
111             unless $sub->{cannotdisplay};
112     }
113 }
114
115 my $branches = GetBranches();
116 my @branches_loop;
117 foreach (sort keys %$branches){
118     my $selected = 0;
119     $selected = 1 if( defined $branch and $branch eq $_ );
120     push @branches_loop, {
121         branchcode  => $_,
122         branchname  => $branches->{$_}->{'branchname'},
123         selected    => $selected,
124     };
125 }
126
127
128 $template->param(
129     openedsubscriptions => \@openedsubscriptions,
130     closedsubscriptions => \@closedsubscriptions,
131     total         => @openedsubscriptions + @closedsubscriptions,
132     title_filter  => $title,
133     ISSN_filter   => $ISSN,
134     EAN_filter    => $EAN,
135     callnumber_filter => $callnumber,
136     publisher_filter => $publisher,
137     bookseller_filter  => $bookseller,
138     branch_filter => $branch,
139     locations     => C4::Koha::GetAuthorisedValues('LOC', $location),
140     expiration_date_filter => $expiration_date_dt,
141     branches_loop => \@branches_loop,
142     done_searched => $searched,
143     routing       => $routing,
144     marcflavour   => (uc(C4::Context->preference("marcflavour")))
145 );
146
147 output_html_with_http_headers $query, $cookie, $template->output;