Bug 35453: Fix wrong 'Laserdisc)' string on 007 builder (MARC21)
[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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
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 qw( get_template_and_user );
34 use C4::Context;
35 use C4::Output qw( output_html_with_http_headers );
36 use C4::Serials qw( CloseSubscription ReopenSubscription SearchSubscriptions check_routing );
37 use Koha::AdditionalFields;
38
39 use Koha::DateUtils qw( dt_from_string );
40 use Koha::SharedContent;
41
42 my $query         = CGI->new;
43 my $title         = $query->param('title_filter') || '';
44 my $ISSN          = $query->param('ISSN_filter') || '';
45 my $EAN           = $query->param('EAN_filter') || '';
46 my $callnumber    = $query->param('callnumber_filter') || '';
47 my $publisher     = $query->param('publisher_filter') || '';
48 my $bookseller    = $query->param('bookseller_filter') || '';
49 my $biblionumber  = $query->param('biblionumber') || '';
50 my $branch        = $query->param('branch_filter') || '';
51 my $location      = $query->param('location_filter') || '';
52 my $expiration_date = $query->param('expiration_date_filter') || '';
53 my $routing       = $query->param('routing') || C4::Context->preference("RoutingSerials");
54 my $searched      = $query->param('searched') || 0;
55 my $mana      = $query->param('mana') || 0;
56 my @subscriptionids = $query->multi_param('subscriptionid');
57 my $op            = $query->param('op');
58
59 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
60     {
61         template_name   => "serials/serials-search.tt",
62         query           => $query,
63         type            => "intranet",
64         flagsrequired   => { serials => '*' },
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
79 my @additional_fields = Koha::AdditionalFields->search( { tablename => 'subscription', searchable => 1 } )->as_list;
80 my @additional_field_filters;
81 for my $field ( @additional_fields ) {
82     my $value = $query->param( 'additional_field_' . $field->id );
83     if ( defined $value and $value ne '' ) {
84         push @additional_field_filters, {
85             id => $field->id,
86             value => $value,
87         };
88     }
89 }
90
91 my @subscriptions;
92 my $mana_statuscode;
93 if ($searched){
94     if ($mana) {
95         my $result = Koha::SharedContent::search_entities("subscription",{
96             title        => $title,
97             issn         => $ISSN,
98             ean          => $EAN,
99             publisher    => $publisher
100         });
101         $mana_statuscode = $result->{code};
102         @subscriptions = @{ $result->{data} };
103     }
104     else {
105         @subscriptions = SearchSubscriptions(
106         {
107             biblionumber => $biblionumber,
108             title        => $title,
109             issn         => $ISSN,
110             ean          => $EAN,
111             callnumber   => $callnumber,
112             publisher    => $publisher,
113             bookseller   => $bookseller,
114             branch       => $branch,
115             additional_fields => \@additional_field_filters,
116             location     => $location,
117             expiration_date => $expiration_date,
118         });
119     }
120 }
121
122 if ($mana) {
123     $template->param(
124         subscriptions => \@subscriptions,
125         statuscode    => $mana_statuscode,
126         total         => scalar @subscriptions,
127         title_filter  => $title,
128         ISSN_filter   => $ISSN,
129         EAN_filter    => $EAN,
130         callnumber_filter => $callnumber,
131         publisher_filter => $publisher,
132         bookseller_filter  => $bookseller,
133         branch_filter => $branch,
134         location_filter => $location,
135         expiration_date_filter => $expiration_date,
136         done_searched => $searched,
137         routing       => $routing,
138         additional_field_filters => \@additional_field_filters,
139         additional_fields_for_subscription => \@additional_fields,
140         marcflavour   => (uc(C4::Context->preference("marcflavour"))),
141         mana => $mana,
142         search_only => 1
143     );
144 }
145 else
146 {
147     # to toggle between create or edit routing list options
148     if ($routing) {
149         for my $subscription ( @subscriptions) {
150             $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} );
151         }
152     }
153
154     my (@openedsubscriptions, @closedsubscriptions);
155     for my $sub ( @subscriptions ) {
156         unless ( $sub->{closed} ) {
157             push @openedsubscriptions, $sub
158                 unless $sub->{cannotdisplay};
159         } else {
160             push @closedsubscriptions, $sub
161                 unless $sub->{cannotdisplay};
162         }
163     }
164
165     my @branches = Koha::Libraries->search( {}, { order_by => ['branchcode'] } )->as_list;
166     my @branches_loop;
167     foreach my $b ( @branches ) {
168         my $selected = 0;
169         $selected = 1 if( defined $branch and $branch eq $b->branchcode );
170         push @branches_loop, {
171             branchcode  => $b->branchcode,
172             branchname  => $b->branchname,
173             selected    => $selected,
174         };
175     }
176
177     $template->param(
178         openedsubscriptions => \@openedsubscriptions,
179         closedsubscriptions => \@closedsubscriptions,
180         total         => @openedsubscriptions + @closedsubscriptions,
181         title_filter  => $title,
182         ISSN_filter   => $ISSN,
183         EAN_filter    => $EAN,
184         callnumber_filter => $callnumber,
185         publisher_filter => $publisher,
186         bookseller_filter  => $bookseller,
187         branch_filter => $branch,
188         location_filter => $location,
189         expiration_date_filter => $expiration_date,
190         branches_loop => \@branches_loop,
191         done_searched => $searched,
192         routing       => $routing,
193         additional_field_filters => { map { $_->{id} => $_->{value} } @additional_field_filters },
194         additional_fields_for_subscription => \@additional_fields,
195         marcflavour   => (uc(C4::Context->preference("marcflavour"))),
196         mana => $mana
197     );
198 }
199 output_html_with_http_headers $query, $cookie, $template->output;