Bug 25567: Prevent patron category type's categorycode to be created with ""
[koha.git] / catalogue / labeledMARCdetail.pl
blob446a679fba6dc6110be6bd64d4467d3103408bb2
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') // GetFrameworkCode( $biblionumber );
42 my $popup =
43 $query->param('popup')
44 ; # if set to 1, then don't insert links, it's just to show the biblio
46 # open template
47 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
49 template_name => "catalogue/labeledMARCdetail.tt",
50 query => $query,
51 type => "intranet",
52 authnotrequired => 0,
53 flagsrequired => { catalogue => 1 },
54 debug => 1,
58 my $record = GetMarcBiblio({ biblionumber => $biblionumber });
59 if ( not defined $record ) {
60 # biblionumber invalid -> report and exit
61 $template->param( unknownbiblionumber => 1,
62 biblionumber => $biblionumber
64 output_html_with_http_headers $query, $cookie, $template->output;
65 exit;
68 my $biblio_object = Koha::Biblios->find( $biblionumber ); # FIXME Should replace $biblio
69 my $tagslib = GetMarcStructure(1,$frameworkcode);
70 my $biblio = GetBiblioData($biblionumber);
72 if($query->cookie("holdfor")){
73 my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
74 $template->param(
75 holdfor => $query->cookie("holdfor"),
76 holdfor_surname => $holdfor_patron->surname,
77 holdfor_firstname => $holdfor_patron->firstname,
78 holdfor_cardnumber => $holdfor_patron->cardnumber,
82 if( $query->cookie("searchToOrder") ){
83 my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
84 $template->param(
85 searchtoorder_basketno => $basketno,
86 searchtoorder_vendorid => $vendorid
90 #count of item linked
91 my $itemcount = $biblio_object->items->count;
92 $template->param( count => $itemcount,
93 bibliotitle => $biblio->{title}, );
95 my $frameworks = Koha::BiblioFrameworks->search({}, { order_by => ['frameworktext'] });
96 $template->param(
97 frameworks => $frameworks,
98 frameworkcode => $frameworkcode,
101 my @marc_data;
102 my $prevlabel = '';
103 for my $field ($record->fields)
105 my $tag = $field->tag;
106 next if ! exists $tagslib->{$tag}->{lib};
107 my $label = $tagslib->{$tag}->{lib};
108 if ($label eq $prevlabel)
110 $label = '';
112 else
114 $prevlabel = $label;
116 my $value = $tag < 10
117 ? $field->data
118 : join ' ', map { $_->[1] } $field->subfields;
119 push @marc_data, {
120 label => $label,
121 value => $value,
125 $template->param (
126 marc_data => \@marc_data,
127 biblionumber => $biblionumber,
128 popup => $popup,
129 labeledmarcview => 1,
130 z3950_search_params => C4::Search::z3950_search_args($biblio),
131 C4::Search::enabled_staff_search_views,
132 subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber),
133 searchid => scalar $query->param('searchid'),
136 my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber);
137 my @deletedorders_using_biblio;
138 my @orders_using_biblio;
139 my @baskets_orders;
140 my @baskets_deletedorders;
142 foreach my $myorder (@allorders_using_biblio) {
143 my $basket = $myorder->{'basketno'};
144 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
145 push @deletedorders_using_biblio, $myorder;
146 unless (grep { $_ eq $basket } @baskets_deletedorders){
147 push @baskets_deletedorders,$myorder->{'basketno'};
150 else {
151 push @orders_using_biblio, $myorder;
152 unless (grep{ $_ eq $basket } @baskets_orders){
153 push @baskets_orders,$myorder->{'basketno'};
158 my $count_orders_using_biblio = scalar @orders_using_biblio ;
159 $template->param (countorders => $count_orders_using_biblio);
161 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
162 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
164 $biblio = Koha::Biblios->find( $biblionumber );
165 my $holds = $biblio->holds;
166 $template->param( holdcount => $holds->count );
168 output_html_with_http_headers $query, $cookie, $template->output;