Bug 21439: Update two-column templates with Bootstrap grid: Rotating collections
[koha.git] / serials / serials-search.pl
blob30bf7db87c18f02960a0ab5a212455eb8b15e93d
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::AdditionalField;
40 use Koha::DateUtils;
42 my $query = new CGI;
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 @subscriptionids = $query->multi_param('subscriptionid');
56 my $op = $query->param('op');
58 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
60 template_name => "serials/serials-search.tt",
61 query => $query,
62 type => "intranet",
63 authnotrequired => 0,
64 flagsrequired => { serials => '*' },
65 debug => 1,
69 if ( $op and $op eq "close" ) {
70 for my $subscriptionid ( @subscriptionids ) {
71 C4::Serials::CloseSubscription( $subscriptionid );
73 } elsif ( $op and $op eq "reopen" ) {
74 for my $subscriptionid ( @subscriptionids ) {
75 C4::Serials::ReopenSubscription( $subscriptionid );
80 my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription', searchable => 1 } );
81 my $additional_field_filters;
82 for my $field ( @$additional_fields ) {
83 my $filter_value = $query->param('additional_field_' . $field->{id} . '_filter');
84 if ( defined $filter_value and $filter_value ne q|| ) {
85 $additional_field_filters->{ $field->{name} } = {
86 value => $filter_value,
87 authorised_value_category => $field->{authorised_value_category},
90 if ( $field->{authorised_value_category} ) {
91 $field->{authorised_value_choices} = GetAuthorisedValues( $field->{authorised_value_category} );
95 my $expiration_date_dt = $expiration_date ? dt_from_string( $expiration_date ) : undef;
96 my @subscriptions;
97 if ($searched){
98 @subscriptions = SearchSubscriptions(
100 biblionumber => $biblionumber,
101 title => $title,
102 issn => $ISSN,
103 ean => $EAN,
104 callnumber => $callnumber,
105 publisher => $publisher,
106 bookseller => $bookseller,
107 branch => $branch,
108 additional_fields => [ map{ { name => $_, value => $additional_field_filters->{$_}{value}, authorised_value_category => $additional_field_filters->{$_}{authorised_value_category} } } keys %$additional_field_filters ],
109 location => $location,
110 expiration_date => $expiration_date_dt,
115 # to toggle between create or edit routing list options
116 if ($routing) {
117 for my $subscription ( @subscriptions) {
118 $subscription->{routingedit} = check_routing( $subscription->{subscriptionid} );
122 my (@openedsubscriptions, @closedsubscriptions);
123 for my $sub ( @subscriptions ) {
124 unless ( $sub->{closed} ) {
125 push @openedsubscriptions, $sub
126 unless $sub->{cannotdisplay};
127 } else {
128 push @closedsubscriptions, $sub
129 unless $sub->{cannotdisplay};
133 $template->param(
134 openedsubscriptions => \@openedsubscriptions,
135 closedsubscriptions => \@closedsubscriptions,
136 total => @openedsubscriptions + @closedsubscriptions,
137 title_filter => $title,
138 ISSN_filter => $ISSN,
139 EAN_filter => $EAN,
140 callnumber_filter => $callnumber,
141 publisher_filter => $publisher,
142 bookseller_filter => $bookseller,
143 branch_filter => $branch,
144 location_filter => $location,
145 expiration_date_filter => $expiration_date_dt,
146 done_searched => $searched,
147 routing => $routing,
148 additional_field_filters => $additional_field_filters,
149 additional_fields_for_subscription => $additional_fields,
150 marcflavour => (uc(C4::Context->preference("marcflavour")))
153 output_html_with_http_headers $query, $cookie, $template->output;