Bug 9118: Do not show option to create exception on range for unique holiday
[koha.git] / serials / serials-search.pl
blob456a6cd4313aaa2f86b8872e2b67b1829c7b1153
1 #!/usr/bin/perl
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>.
21 =head1 NAME
23 serials-search.pl
25 =head1 DESCRIPTION
27 this script is the search page for serials
29 =cut
31 use Modern::Perl;
32 use CGI qw ( -utf8 );
33 use C4::Auth;
34 use C4::Context;
35 use C4::Koha qw( GetAuthorisedValues );
36 use C4::Output;
37 use C4::Serials;
38 use Koha::AdditionalFields;
40 use Koha::DateUtils;
41 use Koha::SharedContent;
43 my $query = new CGI;
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 $mana = $query->param('mana') || 0;
57 my @subscriptionids = $query->multi_param('subscriptionid');
58 my $op = $query->param('op');
60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
62 template_name => "serials/serials-search.tt",
63 query => $query,
64 type => "intranet",
65 flagsrequired => { serials => '*' },
66 debug => 1,
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::AdditionalFields->search( { tablename => 'subscription', searchable => 1 } );
82 my @additional_field_filters;
83 for my $field ( @additional_fields ) {
84 my $value = $query->param( 'additional_field_' . $field->id );
85 if ( defined $value and $value ne '' ) {
86 push @additional_field_filters, {
87 id => $field->id,
88 value => $value,
93 my $expiration_date_dt = $expiration_date ? dt_from_string( $expiration_date ) : undef;
94 my @subscriptions;
95 my $mana_statuscode;
96 if ($searched){
97 if ($mana) {
98 my $result = Koha::SharedContent::search_entities("subscription",{
99 title => $title,
100 issn => $ISSN,
101 ean => $EAN,
102 publisher => $publisher
104 $mana_statuscode = $result->{code};
105 @subscriptions = @{ $result->{data} };
107 else {
108 @subscriptions = SearchSubscriptions(
110 biblionumber => $biblionumber,
111 title => $title,
112 issn => $ISSN,
113 ean => $EAN,
114 callnumber => $callnumber,
115 publisher => $publisher,
116 bookseller => $bookseller,
117 branch => $branch,
118 additional_fields => \@additional_field_filters,
119 location => $location,
120 expiration_date => $expiration_date_dt,
125 if ($mana) {
126 $template->param(
127 subscriptions => \@subscriptions,
128 statuscode => $mana_statuscode,
129 total => scalar @subscriptions,
130 title_filter => $title,
131 ISSN_filter => $ISSN,
132 EAN_filter => $EAN,
133 callnumber_filter => $callnumber,
134 publisher_filter => $publisher,
135 bookseller_filter => $bookseller,
136 branch_filter => $branch,
137 location_filter => $location,
138 expiration_date_filter => $expiration_date_dt,
139 done_searched => $searched,
140 routing => $routing,
141 additional_field_filters => \@additional_field_filters,
142 additional_fields_for_subscription => \@additional_fields,
143 marcflavour => (uc(C4::Context->preference("marcflavour"))),
144 mana => $mana,
145 search_only => 1
148 else
150 # to toggle between create or edit routing list options
151 if ($routing) {
152 for my $subscription ( @subscriptions) {
153 $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} );
157 my (@openedsubscriptions, @closedsubscriptions);
158 for my $sub ( @subscriptions ) {
159 unless ( $sub->{closed} ) {
160 push @openedsubscriptions, $sub
161 unless $sub->{cannotdisplay};
162 } else {
163 push @closedsubscriptions, $sub
164 unless $sub->{cannotdisplay};
168 my @branches = Koha::Libraries->search( {}, { order_by => ['branchcode'] } );
169 my @branches_loop;
170 foreach my $b ( @branches ) {
171 my $selected = 0;
172 $selected = 1 if( defined $branch and $branch eq $b->branchcode );
173 push @branches_loop, {
174 branchcode => $b->branchcode,
175 branchname => $b->branchname,
176 selected => $selected,
180 $template->param(
181 openedsubscriptions => \@openedsubscriptions,
182 closedsubscriptions => \@closedsubscriptions,
183 total => @openedsubscriptions + @closedsubscriptions,
184 title_filter => $title,
185 ISSN_filter => $ISSN,
186 EAN_filter => $EAN,
187 callnumber_filter => $callnumber,
188 publisher_filter => $publisher,
189 bookseller_filter => $bookseller,
190 branch_filter => $branch,
191 location_filter => $location,
192 expiration_date_filter => $expiration_date_dt,
193 branches_loop => \@branches_loop,
194 done_searched => $searched,
195 routing => $routing,
196 additional_field_filters => { map { $_->{id} => $_->{value} } @additional_field_filters },
197 additional_fields_for_subscription => \@additional_fields,
198 marcflavour => (uc(C4::Context->preference("marcflavour"))),
199 mana => $mana
202 output_html_with_http_headers $query, $cookie, $template->output;