Bug 14391: (QA follow-up) Fix some typos
[koha.git] / catalogue / labeledMARCdetail.pl
blob9b5105103c3c95995bd1c5d43a78a8c510a72693
1 #!/usr/bin/perl
3 # Copyright 2008-2009 LibLime
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>.
20 use Modern::Perl;
21 use CGI qw ( -utf8 );
22 use HTML::Entities;
23 use MARC::Record;
24 use C4::Auth;
25 use C4::Context;
26 use C4::Output;
27 use C4::Biblio;
28 use C4::Items;
29 use C4::Search; # enabled_staff_search_views
30 use C4::Serials;
31 use C4::Acquisition qw(GetOrdersByBiblionumber);
33 use Koha::Biblios;
34 use Koha::BiblioFrameworks;
35 use Koha::Patrons;
37 my $query = new CGI;
38 my $dbh = C4::Context->dbh;
39 my $biblionumber = $query->param('biblionumber');
40 $biblionumber = HTML::Entities::encode($biblionumber);
41 my $frameworkcode = $query->param('frameworkcode');
42 $frameworkcode = GetFrameworkCode( $biblionumber ) unless ($frameworkcode);
43 my $popup =
44 $query->param('popup')
45 ; # if set to 1, then don't insert links, it's just to show the biblio
47 # open template
48 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
50 template_name => "catalogue/labeledMARCdetail.tt",
51 query => $query,
52 type => "intranet",
53 authnotrequired => 0,
54 flagsrequired => { catalogue => 1 },
55 debug => 1,
59 my $record = GetMarcBiblio({ biblionumber => $biblionumber });
60 if ( not defined $record ) {
61 # biblionumber invalid -> report and exit
62 $template->param( unknownbiblionumber => 1,
63 biblionumber => $biblionumber
65 output_html_with_http_headers $query, $cookie, $template->output;
66 exit;
69 my $biblio_object = Koha::Biblios->find( $biblionumber ); # FIXME Should replace $biblio
70 my $tagslib = GetMarcStructure(1,$frameworkcode);
71 my $biblio = GetBiblioData($biblionumber);
73 if($query->cookie("holdfor")){
74 my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
75 $template->param(
76 holdfor => $query->cookie("holdfor"),
77 holdfor_surname => $holdfor_patron->surname,
78 holdfor_firstname => $holdfor_patron->firstname,
79 holdfor_cardnumber => $holdfor_patron->cardnumber,
83 #count of item linked
84 my $itemcount = $biblio_object->items->count;
85 $template->param( count => $itemcount,
86 bibliotitle => $biblio->{title}, );
88 my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
89 $template->param(
90 frameworks => $frameworks,
91 frameworkcode => $frameworkcode,
94 my @marc_data;
95 my $prevlabel = '';
96 for my $field ($record->fields)
98 my $tag = $field->tag;
99 next if ! exists $tagslib->{$tag}->{lib};
100 my $label = $tagslib->{$tag}->{lib};
101 if ($label eq $prevlabel)
103 $label = '';
105 else
107 $prevlabel = $label;
109 my $value = $tag < 10
110 ? $field->data
111 : join ' ', map { $_->[1] } $field->subfields;
112 push @marc_data, {
113 label => $label,
114 value => $value,
118 $template->param (
119 marc_data => \@marc_data,
120 biblionumber => $biblionumber,
121 popup => $popup,
122 labeledmarcview => 1,
123 z3950_search_params => C4::Search::z3950_search_args($biblio),
124 C4::Search::enabled_staff_search_views,
125 subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber),
126 searchid => scalar $query->param('searchid'),
129 my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber);
130 my @deletedorders_using_biblio;
131 my @orders_using_biblio;
132 my @baskets_orders;
133 my @baskets_deletedorders;
135 foreach my $myorder (@allorders_using_biblio) {
136 my $basket = $myorder->{'basketno'};
137 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
138 push @deletedorders_using_biblio, $myorder;
139 unless (grep(/^$basket$/, @baskets_deletedorders)){
140 push @baskets_deletedorders,$myorder->{'basketno'};
143 else {
144 push @orders_using_biblio, $myorder;
145 unless (grep(/^$basket$/, @baskets_orders)){
146 push @baskets_orders,$myorder->{'basketno'};
151 my $count_orders_using_biblio = scalar @orders_using_biblio ;
152 $template->param (countorders => $count_orders_using_biblio);
154 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
155 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
157 $biblio = Koha::Biblios->find( $biblionumber );
158 my $holds = $biblio->holds;
159 $template->param( holdcount => $holds->count );
161 output_html_with_http_headers $query, $cookie, $template->output;