Bug 12061 - tmpl_process3.pl - Include/exclude file by name
[koha.git] / catalogue / moredetail.pl
blobeed1f68cd5a4c51ae3cb52e49e8a8bfd9796174d
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.tt
47 my ($template, $loggedinuser, $cookie) = get_template_and_user(
49 template_name => ( $subject
50 ? 'catalogue/subject.tt'
51 : 'catalogue/moredetail.tt'),
52 query => $query,
53 type => "intranet",
54 authnotrequired => 0,
55 flagsrequired => { catalogue => 1 },
59 if($query->cookie("holdfor")){
60 my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
61 $template->param(
62 holdfor => $query->cookie("holdfor"),
63 holdfor_surname => $holdfor_patron->{'surname'},
64 holdfor_firstname => $holdfor_patron->{'firstname'},
65 holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
69 my $hidepatronname = C4::Context->preference("HidePatronName");
71 # get variables
73 my $biblionumber=$query->param('biblionumber');
74 my $title=$query->param('title');
75 my $bi=$query->param('bi');
76 $bi = $biblionumber unless $bi;
77 my $itemnumber = $query->param('itemnumber');
78 my $data = &GetBiblioData($biblionumber);
79 my $dewey = $data->{'dewey'};
80 my $showallitems = $query->param('showallitems');
82 #coping with subscriptions
83 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
85 # FIXME Dewey is a string, not a number, & we should use a function
86 # $dewey =~ s/0+$//;
87 # if ($dewey eq "000.") { $dewey = "";};
88 # if ($dewey < 10){$dewey='00'.$dewey;}
89 # if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
90 # if ($dewey <= 0){
91 # $dewey='';
92 # }
93 # $dewey=~ s/\.$//;
94 # $data->{'dewey'}=$dewey;
96 my $fw = GetFrameworkCode($biblionumber);
97 my @all_items= GetItemsInfo($biblionumber);
98 my @items;
99 for my $itm (@all_items) {
100 push @items, $itm unless ( $itm->{itemlost} &&
101 GetHideLostItemsPreference($loggedinuser) &&
102 !$showallitems &&
103 ($itemnumber != $itm->{itemnumber}));
106 my $record=GetMarcBiblio($biblionumber);
108 my $hostrecords;
109 # adding items linked via host biblios
110 my @hostitems = GetHostItemsInfo($record);
111 if (@hostitems){
112 $hostrecords =1;
113 push (@items,@hostitems);
116 my $subtitle = GetRecordValue('subtitle', $record, $fw);
118 my $totalcount=@all_items;
119 my $showncount=@items;
120 my $hiddencount = $totalcount - $showncount;
121 $data->{'count'}=$totalcount;
122 $data->{'showncount'}=$showncount;
123 $data->{'hiddencount'}=$hiddencount; # can be zero
125 my $ccodes= GetKohaAuthorisedValues('items.ccode',$fw);
126 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$fw);
127 my $itemtypes = GetItemTypes;
129 $data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'description'};
130 $data->{'rentalcharge'} = sprintf( "%.2f", $data->{'rentalcharge'} );
131 foreach ( keys %{$data} ) {
132 $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
135 ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items);
136 foreach my $item (@items){
137 $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
138 $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
139 $item->{'collection'} = $ccodes->{ $item->{ccode} } if ($ccodes);
140 $item->{'itype'} = $itemtypes->{ $item->{'itype'} }->{'description'};
141 $item->{'replacementprice'} = sprintf( "%.2f", $item->{'replacementprice'} );
142 if ( defined $item->{'copynumber'} ) {
143 $item->{'displaycopy'} = 1;
144 if ( defined $copynumbers->{ $item->{'copynumber'} } ) {
145 $item->{'copyvol'} = $copynumbers->{ $item->{'copynumber'} }
147 else {
148 $item->{'copyvol'} = $item->{'copynumber'};
152 # item has a host number if its biblio number does not match the current bib
153 if ($item->{biblionumber} ne $biblionumber){
154 $item->{hostbiblionumber} = $item->{biblionumber};
155 $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
158 my $order = GetOrderFromItemnumber( $item->{'itemnumber'} );
159 $item->{'ordernumber'} = $order->{'ordernumber'};
160 $item->{'basketno'} = $order->{'basketno'};
161 $item->{'orderdate'} = $order->{'entrydate'};
162 if ($item->{'basketno'}){
163 my $basket = GetBasket($item->{'basketno'});
164 my $bookseller = GetBookSellerFromId($basket->{'booksellerid'});
165 $item->{'vendor'} = $bookseller->{'name'};
167 $item->{'invoiceid'} = $order->{'invoiceid'};
168 if($item->{invoiceid}) {
169 my $invoice = GetInvoice($item->{invoiceid});
170 $item->{invoicenumber} = $invoice->{invoicenumber} if $invoice;
172 $item->{'datereceived'} = $order->{'datereceived'};
174 if ($item->{notforloantext} or $item->{itemlost} or $item->{damaged} or $item->{withdrawn}) {
175 $item->{status_advisory} = 1;
178 if (C4::Context->preference("IndependentBranches")) {
179 #verifying rights
180 my $userenv = C4::Context->userenv();
181 unless (C4::Context->IsSuperLibrarian() or ($userenv->{'branch'} eq $item->{'homebranch'})) {
182 $item->{'nomod'}=1;
185 $item->{'homebranchname'} = GetBranchName($item->{'homebranch'});
186 $item->{'holdingbranchname'} = GetBranchName($item->{'holdingbranch'});
187 if ($item->{'datedue'}) {
188 $item->{'issue'}= 1;
189 } else {
190 $item->{'issue'}= 0;
193 unless ($hidepatronname) {
194 if ( $item->{'borrowernumber'} ) {
195 my $curr_borrower = GetMember('borrowernumber' => $item->{'borrowernumber'} );
196 $item->{borrowerfirstname} = $curr_borrower->{'firstname'};
197 $item->{borrowersurname} = $curr_borrower->{'surname'};
202 $template->param(count => $data->{'count'},
203 subscriptionsnumber => $subscriptionsnumber,
204 subscriptiontitle => $data->{title},
205 C4::Search::enabled_staff_search_views,
208 $template->param(
209 ITEM_DATA => \@items,
210 moredetailview => 1,
211 loggedinuser => $loggedinuser,
212 biblionumber => $biblionumber,
213 biblioitemnumber => $bi,
214 itemnumber => $itemnumber,
215 z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
216 subtitle => $subtitle,
217 hidepatronname => $hidepatronname,
219 $template->param(ONLY_ONE => 1) if ( $itemnumber && $showncount != @items );
220 $template->{'VARS'}->{'searchid'} = $query->param('searchid');
222 my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber);
223 my @deletedorders_using_biblio;
224 my @orders_using_biblio;
225 my @baskets_orders;
226 my @baskets_deletedorders;
228 foreach my $myorder (@allorders_using_biblio) {
229 my $basket = $myorder->{'basketno'};
230 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
231 push @deletedorders_using_biblio, $myorder;
232 unless (grep(/^$basket$/, @baskets_deletedorders)){
233 push @baskets_deletedorders,$myorder->{'basketno'};
236 else {
237 push @orders_using_biblio, $myorder;
238 unless (grep(/^$basket$/, @baskets_orders)){
239 push @baskets_orders,$myorder->{'basketno'};
244 my $count_orders_using_biblio = scalar @orders_using_biblio ;
245 $template->param (countorders => $count_orders_using_biblio);
247 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
248 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
250 my $holds = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
251 my $holdcount = scalar( @$holds );
252 $template->param( holdcount => scalar ( @$holds ) );
254 output_html_with_http_headers $query, $cookie, $template->output;