3 # Copyright 2012 Koha Team
5 # This file is part of Koha.
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.
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.
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>.
27 this script is the search page for serials
33 use C4::Auth qw( get_template_and_user );
35 use C4::Output qw( output_html_with_http_headers );
36 use C4::Serials qw( CloseSubscription ReopenSubscription SearchSubscriptions check_routing );
37 use Koha::AdditionalFields;
39 use Koha::DateUtils qw( dt_from_string );
40 use Koha::SharedContent;
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');
59 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
61 template_name => "serials/serials-search.tt",
64 flagsrequired => { serials => '*' },
68 if ( $op and $op eq "close" ) {
69 for my $subscriptionid ( @subscriptionids ) {
70 C4::Serials::CloseSubscription( $subscriptionid );
72 } elsif ( $op and $op eq "reopen" ) {
73 for my $subscriptionid ( @subscriptionids ) {
74 C4::Serials::ReopenSubscription( $subscriptionid );
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, {
91 my $expiration_date_dt = $expiration_date ? dt_from_string( $expiration_date ) : undef;
96 my $result = Koha::SharedContent::search_entities("subscription",{
100 publisher => $publisher
102 $mana_statuscode = $result->{code};
103 @subscriptions = @{ $result->{data} };
106 @subscriptions = SearchSubscriptions(
108 biblionumber => $biblionumber,
112 callnumber => $callnumber,
113 publisher => $publisher,
114 bookseller => $bookseller,
116 additional_fields => \@additional_field_filters,
117 location => $location,
118 expiration_date => $expiration_date_dt,
125 subscriptions => \@subscriptions,
126 statuscode => $mana_statuscode,
127 total => scalar @subscriptions,
128 title_filter => $title,
129 ISSN_filter => $ISSN,
131 callnumber_filter => $callnumber,
132 publisher_filter => $publisher,
133 bookseller_filter => $bookseller,
134 branch_filter => $branch,
135 location_filter => $location,
136 expiration_date_filter => $expiration_date_dt,
137 done_searched => $searched,
139 additional_field_filters => \@additional_field_filters,
140 additional_fields_for_subscription => \@additional_fields,
141 marcflavour => (uc(C4::Context->preference("marcflavour"))),
148 # to toggle between create or edit routing list options
150 for my $subscription ( @subscriptions) {
151 $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} );
155 my (@openedsubscriptions, @closedsubscriptions);
156 for my $sub ( @subscriptions ) {
157 unless ( $sub->{closed} ) {
158 push @openedsubscriptions, $sub
159 unless $sub->{cannotdisplay};
161 push @closedsubscriptions, $sub
162 unless $sub->{cannotdisplay};
166 my @branches = Koha::Libraries->search( {}, { order_by => ['branchcode'] } )->as_list;
168 foreach my $b ( @branches ) {
170 $selected = 1 if( defined $branch and $branch eq $b->branchcode );
171 push @branches_loop, {
172 branchcode => $b->branchcode,
173 branchname => $b->branchname,
174 selected => $selected,
179 openedsubscriptions => \@openedsubscriptions,
180 closedsubscriptions => \@closedsubscriptions,
181 total => @openedsubscriptions + @closedsubscriptions,
182 title_filter => $title,
183 ISSN_filter => $ISSN,
185 callnumber_filter => $callnumber,
186 publisher_filter => $publisher,
187 bookseller_filter => $bookseller,
188 branch_filter => $branch,
189 location_filter => $location,
190 expiration_date_filter => $expiration_date_dt,
191 branches_loop => \@branches_loop,
192 done_searched => $searched,
194 additional_field_filters => { map { $_->{id} => $_->{value} } @additional_field_filters },
195 additional_fields_for_subscription => \@additional_fields,
196 marcflavour => (uc(C4::Context->preference("marcflavour"))),
200 output_html_with_http_headers $query, $cookie, $template->output;