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
36 use C4::Koha qw( GetAuthorisedValues );
39 use Koha::AdditionalField;
44 my $title = $query->param('title_filter') || '';
45 my $ISSN = $query->param('ISSN_filter') || '';
46 my $EAN = $query->param('EAN_filter') || '';
47 my $callnumber = $query->param('callnumber_filter') || '';
48 my $publisher = $query->param('publisher_filter') || '';
49 my $bookseller = $query->param('bookseller_filter') || '';
50 my $biblionumber = $query->param('biblionumber') || '';
51 my $branch = $query->param('branch_filter') || '';
52 my $location = $query->param('location_filter') || '';
53 my $expiration_date = $query->param('expiration_date_filter') || '';
54 my $routing = $query->param('routing') || C4::Context->preference("RoutingSerials");
55 my $searched = $query->param('searched') || 0;
56 my @subscriptionids = $query ->param('subscriptionid');
57 my $op = $query->param('op');
59 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
61 template_name => "serials/serials-search.tt",
65 flagsrequired => { serials => '*' },
70 if ( $op and $op eq "close" ) {
71 for my $subscriptionid ( @subscriptionids ) {
72 C4::Serials::CloseSubscription( $subscriptionid );
74 } elsif ( $op and $op eq "reopen" ) {
75 for my $subscriptionid ( @subscriptionids ) {
76 C4::Serials::ReopenSubscription( $subscriptionid );
81 my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription', searchable => 1 } );
82 my $additional_field_filters;
83 for my $field ( @$additional_fields ) {
84 my $filter_value = $query->param('additional_field_' . $field->{id} . '_filter');
85 if ( defined ( $filter_value ) ) {
86 $additional_field_filters->{ $field->{name} } = $filter_value;
88 if ( $field->{authorised_value_category} ) {
89 $field->{authorised_value_choices} = GetAuthorisedValues( $field->{authorised_value_category} );
93 my $expiration_date_dt = $expiration_date ? dt_from_string( $expiration_date ) : undef;
96 @subscriptions = SearchSubscriptions(
98 biblionumber => $biblionumber,
102 callnumber => $callnumber,
103 publisher => $publisher,
104 bookseller => $bookseller,
106 additional_fields => [ map{ { name => $_, value => $additional_field_filters->{$_}} } keys %$additional_field_filters ],
107 location => $location,
108 expiration_date => $expiration_date_dt,
113 # to toggle between create or edit routing list options
115 for my $subscription ( @subscriptions) {
116 $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} );
120 my (@openedsubscriptions, @closedsubscriptions);
121 for my $sub ( @subscriptions ) {
122 unless ( $sub->{closed} ) {
123 push @openedsubscriptions, $sub
124 unless $sub->{cannotdisplay};
126 push @closedsubscriptions, $sub
127 unless $sub->{cannotdisplay};
131 my $branches = GetBranches();
133 foreach (sort keys %$branches){
135 $selected = 1 if( defined $branch and $branch eq $_ );
136 push @branches_loop, {
138 branchname => $branches->{$_}->{'branchname'},
139 selected => $selected,
145 openedsubscriptions => \@openedsubscriptions,
146 closedsubscriptions => \@closedsubscriptions,
147 total => @openedsubscriptions + @closedsubscriptions,
148 title_filter => $title,
149 ISSN_filter => $ISSN,
151 callnumber_filter => $callnumber,
152 publisher_filter => $publisher,
153 bookseller_filter => $bookseller,
154 branch_filter => $branch,
155 locations => C4::Koha::GetAuthorisedValues('LOC', $location),
156 expiration_date_filter => $expiration_date_dt,
157 branches_loop => \@branches_loop,
158 done_searched => $searched,
160 additional_field_filters => $additional_field_filters,
161 additional_fields_for_subscription => $additional_fields,
162 marcflavour => (uc(C4::Context->preference("marcflavour")))
165 output_html_with_http_headers $query, $cookie, $template->output;