3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
27 use C4
::Search qw
/enabled_staff_search_views/;
29 use Koha
::AuthorisedValues
;
31 use Koha
::Acquisition
::Bookseller
;
33 use Date
::Calc qw
/Today Day_of_Year Week_of_Year Add_Delta_Days/;
37 my $op = $query->param('op') || q{};
38 my $issueconfirmed = $query->param('issueconfirmed');
39 my $dbh = C4
::Context
->dbh;
40 my $subscriptionid = $query->param('subscriptionid');
42 if ( $op and $op eq "close" ) {
43 C4
::Serials
::CloseSubscription
( $subscriptionid );
44 } elsif ( $op and $op eq "reopen" ) {
45 C4
::Serials
::ReopenSubscription
( $subscriptionid );
48 # the subscription must be deletable if there is NO issues for a reason or another (should not happend, but...)
50 # Permission needed if it is a deletion (del) : delete_subscription
51 # Permission needed otherwise : *
52 my $permission = ($op eq "del") ?
"delete_subscription" : "*";
54 my ($template, $loggedinuser, $cookie)
55 = get_template_and_user
({template_name
=> "serials/subscription-detail.tt",
59 flagsrequired
=> {serials
=> $permission},
64 my $subs = GetSubscription
($subscriptionid);
65 $subs->{enddate
} ||= GetExpirationDate
($subscriptionid);
67 my ($totalissues,@serialslist) = GetSerials
($subscriptionid);
68 $totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
71 if ($$subs{'cannotedit'}){
72 carp
"Attempt to delete subscription $subscriptionid by ".C4
::Context
->userenv->{'id'}." not allowed";
73 print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
77 # Asking for confirmation if the subscription has not strictly expired yet or if it has linked issues
78 my $strictlyexpired = HasSubscriptionStrictlyExpired
($subscriptionid);
79 my $linkedissues = CountIssues
($subscriptionid);
80 my $countitems = HasItems
($subscriptionid);
81 if ($strictlyexpired == 0 || $linkedissues > 0 || $countitems>0) {
82 $template->param(NEEDSCONFIRMATION
=> 1);
83 if ($strictlyexpired == 0) { $template->param("NOTEXPIRED" => 1); }
84 if ($linkedissues > 0) { $template->param("LINKEDISSUES" => 1); }
85 if ($countitems > 0) { $template->param("LINKEDITEMS" => 1); }
87 $issueconfirmed = "1";
89 # If it's ok to delete the subscription, we do so
90 if ($issueconfirmed eq "1") {
91 &DelSubscription
($subscriptionid);
92 print $query->redirect("/cgi-bin/koha/serials/serials-home.pl");
96 my $hasRouting = check_routing
($subscriptionid);
98 (undef, $cookie, undef, undef)
99 = checkauth
($query, 0, {catalogue
=> 1}, "intranet");
101 # COMMENT hdl : IMHO, we should think about passing more and more data hash to template->param rather than duplicating code a new coding Guideline ?
103 for my $date ( qw(startdate enddate firstacquidate histstartdate histenddate) ) {
104 $subs->{$date} = output_pref
( { str
=> $subs->{$date}, dateonly
=> 1 } )
107 my $av = Koha
::AuthorisedValues
->search({ category
=> 'LOC', authorised_value
=> $subs->{location
} });
108 $subs->{location
} = $av->count ?
$av->next->lib : '';
109 $subs->{abouttoexpire
} = abouttoexpire
($subs->{subscriptionid
});
110 $template->param(%{ $subs });
111 $template->param(biblionumber_for_new_subscription
=> $subs->{bibnum
});
112 my @irregular_issues = split /;/, $subs->{irregularity
};
114 my $frequency = C4
::Serials
::Frequency
::GetSubscriptionFrequency
($subs->{periodicity
});
115 my $numberpattern = C4
::Serials
::Numberpattern
::GetSubscriptionNumberpattern
($subs->{numberpattern
});
117 my $default_bib_view = get_default_view
();
119 my $additional_fields = Koha
::AdditionalField
->all( { tablename
=> 'subscription' } );
120 for my $field ( @
$additional_fields ) {
121 if ( $field->{authorised_value_category
} ) {
122 $field->{authorised_value_choices
} = GetAuthorisedValues
( $field->{authorised_value_category
} );
125 $template->param( additional_fields_for_subscription
=> $additional_fields );
127 # FIXME Do we want to hide canceled orders?
128 my $orders = Koha
::Acquisition
::Orders
->search( { subscriptionid
=> $subscriptionid } );
131 subscriptionid
=> $subscriptionid,
132 serialslist
=> \
@serialslist,
133 hasRouting
=> $hasRouting,
134 routing
=> C4
::Context
->preference("RoutingSerials"),
135 totalissues
=> $totalissues,
136 cannotedit
=> (not C4
::Serials
::can_edit_subscription
( $subs )),
137 frequency
=> $frequency,
138 numberpattern
=> $numberpattern,
139 has_X
=> ($numberpattern->{'numberingmethod'} =~ /{X}/) ?
1 : 0,
140 has_Y
=> ($numberpattern->{'numberingmethod'} =~ /{Y}/) ?
1 : 0,
141 has_Z
=> ($numberpattern->{'numberingmethod'} =~ /{Z}/) ?
1 : 0,
142 intranetstylesheet
=> C4
::Context
->preference('intranetstylesheet'),
143 intranetcolorstylesheet
=> C4
::Context
->preference('intranetcolorstylesheet'),
144 irregular_issues
=> scalar @irregular_issues,
145 default_bib_view
=> $default_bib_view,
147 (uc(C4
::Context
->preference("marcflavour"))) => 1,
150 output_html_with_http_headers
$query, $cookie, $template->output;
152 sub get_default_view
{
153 my $defaultview = C4
::Context
->preference('IntranetBiblioDefaultView');
154 my %views = C4
::Search
::enabled_staff_search_views
();
155 if ( $defaultview eq 'isbd' && $views{can_view_ISBD
} ) {
158 elsif ( $defaultview eq 'marc' && $views{can_view_MARC
} ) {
161 elsif ( $defaultview eq 'labeled_marc' && $views{can_view_labeledMARC
} ) {
162 return 'labeledMARCdetail';