Bug 10261: Link to patron files missing from circ-menu.tt
[koha.git] / catalogue / moredetail.pl
blob55e827320ff7f018e6cfae1d178f4266041290b8
1 #!/usr/bin/perl
3 # Copyright 2000-2003 Katipo Communications
4 # parts copyright 2010 BibLibre
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 use strict;
23 #use warnings; FIXME - Bug 2505
24 use C4::Koha;
25 use CGI;
26 use C4::Biblio;
27 use C4::Items;
28 use C4::Branch;
29 use C4::Acquisition;
30 use C4::Bookseller qw(GetBookSellerFromId);
31 use C4::Output;
32 use C4::Auth;
33 use C4::Serials;
34 use C4::Circulation; # to use itemissues
35 use C4::Members; # to use GetMember
36 use C4::Search; # enabled_staff_search_views
37 use C4::Members qw/GetHideLostItemsPreference/;
38 use C4::Reserves qw(GetReservesFromBiblionumber);
39 use Koha::DateUtils;
41 my $query=new CGI;
43 # FIXME subject is not exported to the template?
44 my $subject=$query->param('subject');
46 # if its a subject we need to use the subject.tmpl
47 my ($template, $loggedinuser, $cookie) = get_template_and_user({
48 template_name => ($subject? 'catalogue/subject.tmpl':
49 'catalogue/moredetail.tmpl'),
50 query => $query,
51 type => "intranet",
52 authnotrequired => 0,
53 flagsrequired => {catalogue => 1},
54 });
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'},
66 my $hidepatronname = C4::Context->preference("HidePatronName");
68 # get variables
70 my $biblionumber=$query->param('biblionumber');
71 my $title=$query->param('title');
72 my $bi=$query->param('bi');
73 $bi = $biblionumber unless $bi;
74 my $itemnumber = $query->param('itemnumber');
75 my $data = &GetBiblioData($biblionumber);
76 my $dewey = $data->{'dewey'};
77 my $showallitems = $query->param('showallitems');
79 #coping with subscriptions
80 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
82 # FIXME Dewey is a string, not a number, & we should use a function
83 # $dewey =~ s/0+$//;
84 # if ($dewey eq "000.") { $dewey = "";};
85 # if ($dewey < 10){$dewey='00'.$dewey;}
86 # if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
87 # if ($dewey <= 0){
88 # $dewey='';
89 # }
90 # $dewey=~ s/\.$//;
91 # $data->{'dewey'}=$dewey;
93 my $fw = GetFrameworkCode($biblionumber);
94 my @all_items= GetItemsInfo($biblionumber);
95 my @items;
96 for my $itm (@all_items) {
97 push @items, $itm unless ( $itm->{itemlost} &&
98 GetHideLostItemsPreference($loggedinuser) &&
99 !$showallitems &&
100 ($itemnumber != $itm->{itemnumber}));
103 my $record=GetMarcBiblio($biblionumber);
105 my $hostrecords;
106 # adding items linked via host biblios
107 my @hostitems = GetHostItemsInfo($record);
108 if (@hostitems){
109 $hostrecords =1;
110 push (@items,@hostitems);
113 my $subtitle = GetRecordValue('subtitle', $record, $fw);
115 my $totalcount=@all_items;
116 my $showncount=@items;
117 my $hiddencount = $totalcount - $showncount;
118 $data->{'count'}=$totalcount;
119 $data->{'showncount'}=$showncount;
120 $data->{'hiddencount'}=$hiddencount; # can be zero
122 my $ccodes= GetKohaAuthorisedValues('items.ccode',$fw);
123 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$fw);
124 my $itemtypes = GetItemTypes;
126 $data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'description'};
127 $data->{'rentalcharge'} = sprintf( "%.2f", $data->{'rentalcharge'} );
128 foreach ( keys %{$data} ) {
129 $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
132 ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items);
133 foreach my $item (@items){
134 $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
135 $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
136 $item->{'collection'} = $ccodes->{ $item->{ccode} } if ($ccodes);
137 $item->{'itype'} = $itemtypes->{ $item->{'itype'} }->{'description'};
138 $item->{'replacementprice'} = sprintf( "%.2f", $item->{'replacementprice'} );
139 if ( defined $item->{'copynumber'} ) {
140 $item->{'displaycopy'} = 1;
141 if ( defined $copynumbers->{ $item->{'copynumber'} } ) {
142 $item->{'copyvol'} = $copynumbers->{ $item->{'copynumber'} }
144 else {
145 $item->{'copyvol'} = $item->{'copynumber'};
149 # item has a host number if its biblio number does not match the current bib
150 if ($item->{biblionumber} ne $biblionumber){
151 $item->{hostbiblionumber} = $item->{biblionumber};
152 $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
155 my $order = GetOrderFromItemnumber( $item->{'itemnumber'} );
156 $item->{'ordernumber'} = $order->{'ordernumber'};
157 $item->{'basketno'} = $order->{'basketno'};
158 $item->{'orderdate'} = $order->{'entrydate'};
159 if ($item->{'basketno'}){
160 my $basket = GetBasket($item->{'basketno'});
161 my $bookseller = GetBookSellerFromId($basket->{'booksellerid'});
162 $item->{'vendor'} = $bookseller->{'name'};
164 $item->{'invoiceid'} = $order->{'invoiceid'};
165 if($item->{invoiceid}) {
166 my $invoice = GetInvoice($item->{invoiceid});
167 $item->{invoicenumber} = $invoice->{invoicenumber} if $invoice;
169 $item->{'datereceived'} = $order->{'datereceived'};
171 if ($item->{notforloantext} or $item->{itemlost} or $item->{damaged} or $item->{wthdrawn}) {
172 $item->{status_advisory} = 1;
175 if (C4::Context->preference("IndependantBranches")) {
176 #verifying rights
177 my $userenv = C4::Context->userenv();
178 unless (($userenv->{'flags'} == 1) or ($userenv->{'branch'} eq $item->{'homebranch'})) {
179 $item->{'nomod'}=1;
182 $item->{'homebranchname'} = GetBranchName($item->{'homebranch'});
183 $item->{'holdingbranchname'} = GetBranchName($item->{'holdingbranch'});
184 if ($item->{'datedue'}) {
185 $item->{'issue'}= 1;
186 } else {
187 $item->{'issue'}= 0;
190 unless ($hidepatronname) {
191 if ( $item->{'borrowernumber'} ) {
192 my $curr_borrower = GetMember('borrowernumber' => $item->{'borrowernumber'} );
193 $item->{borrowerfirstname} = $curr_borrower->{'firstname'};
194 $item->{borrowersurname} = $curr_borrower->{'surname'};
199 $template->param(count => $data->{'count'},
200 subscriptionsnumber => $subscriptionsnumber,
201 subscriptiontitle => $data->{title},
202 C4::Search::enabled_staff_search_views,
205 $template->param(
206 ITEM_DATA => \@items,
207 moredetailview => 1,
208 loggedinuser => $loggedinuser,
209 biblionumber => $biblionumber,
210 biblioitemnumber => $bi,
211 itemnumber => $itemnumber,
212 z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
213 subtitle => $subtitle,
214 hidepatronname => $hidepatronname,
216 $template->param(ONLY_ONE => 1) if ( $itemnumber && $showncount != @items );
219 my ( $holdcount, $holds ) = GetReservesFromBiblionumber($biblionumber,1);
220 $template->param( holdcount => $holdcount, holds => $holds );
222 output_html_with_http_headers $query, $cookie, $template->output;