Merge remote branch 'kc/new/bug_3670' into kcmaster
[koha.git] / catalogue / labeledMARCdetail.pl
1 #!/usr/bin/perl
2
3 # Copyright 2008-2009 LibLime
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use strict;
21 use warnings;
22 use CGI; 
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::Members; # to use GetMember
30 use C4::Search;         # enabled_staff_search_views
31
32 my $query        = new CGI;
33 my $dbh          = C4::Context->dbh;
34 my $biblionumber = $query->param('biblionumber');
35 my $frameworkcode = $query->param('frameworkcode');
36 $frameworkcode = GetFrameworkCode( $biblionumber ) unless ($frameworkcode);
37 my $popup        =
38   $query->param('popup')
39   ;    # if set to 1, then don't insert links, it's just to show the biblio
40
41 my $tagslib = GetMarcStructure(1,$frameworkcode);
42 my $record = GetMarcBiblio($biblionumber);
43 my $biblio = GetBiblioData($biblionumber);
44 # open template
45 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
46     {
47         template_name   => "catalogue/labeledMARCdetail.tmpl",
48         query           => $query,
49         type            => "intranet",
50         authnotrequired => 0,
51         flagsrequired   => { catalogue => 1 },
52         debug           => 1,
53     }
54 );
55
56 if($query->cookie("holdfor")){ 
57     my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
58     $template->param(
59         holdfor => $query->cookie("holdfor"),
60         holdfor_surname => $holdfor_patron->{'surname'},
61         holdfor_firstname => $holdfor_patron->{'firstname'},
62         holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
63     );
64 }
65
66 #count of item linked
67 my $itemcount = GetItemsCount($biblionumber);
68 $template->param( count => $itemcount,
69                                         bibliotitle => $biblio->{title}, );
70
71 #Getting the list of all frameworks
72 my $queryfwk =
73   $dbh->prepare("select frameworktext, frameworkcode from biblio_framework");
74 $queryfwk->execute;
75 my %select_fwk;
76 my @select_fwk;
77 my $curfwk;
78 push @select_fwk, "Default";
79 $select_fwk{"Default"} = "Default";
80
81 while ( my ( $description, $fwk ) = $queryfwk->fetchrow ) {
82     push @select_fwk, $fwk;
83     $select_fwk{$fwk} = $description;
84 }
85 $curfwk=$frameworkcode;
86 my $framework=CGI::scrolling_list( -name     => 'Frameworks',
87             -id => 'Frameworks',
88             -default => $curfwk,
89             -OnChange => 'Changefwk(this);',
90             -values   => \@select_fwk,
91             -labels   => \%select_fwk,
92             -size     => 1,
93             -multiple => 0 );
94 $template->param(framework => $framework);
95
96 my @marc_data;
97 my $prevlabel = '';
98 for my $field ($record->fields)
99 {
100         my $tag = $field->tag;
101         next if ! exists $tagslib->{$tag}->{lib};
102         my $label = $tagslib->{$tag}->{lib};
103         if ($label eq $prevlabel)
104         {
105                 $label = '';
106         }
107         else
108         {
109                 $prevlabel = $label;
110         }
111         my $value = $tag < 10
112                 ? $field->data
113                 : join ' ', map { $_->[1] } $field->subfields;
114         push @marc_data, {
115                 label => $label,
116                 value => $value,
117         };
118 }
119
120 $template->param (
121         marc_data                               => \@marc_data,
122     biblionumber            => $biblionumber,
123     popup                   => $popup,
124         labeledmarcview => 1,
125         z3950_search_params             => C4::Search::z3950_search_args($biblio),
126         C4::Search::enabled_staff_search_views,
127 );
128
129 output_html_with_http_headers $query, $cookie, $template->output;