Bug 7736 amend edi_cron.pl to use new style call to Context
[koha.git] / catalogue / moredetail.pl
blobaa23799d350f55d871ca5408db28412d15e009aa
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
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use strict;
23 #use warnings; FIXME - Bug 2505
24 use C4::Koha;
25 use CGI qw ( -utf8 );
26 use C4::Biblio;
27 use C4::Items;
28 use C4::Branch;
29 use C4::Acquisition;
30 use C4::Output;
31 use C4::Auth;
32 use C4::Serials;
33 use C4::Circulation; # to use itemissues
34 use C4::Members; # to use GetMember
35 use C4::Search; # enabled_staff_search_views
36 use C4::Members qw/GetHideLostItemsPreference/;
37 use C4::Reserves qw(GetReservesFromBiblionumber);
39 use Koha::Acquisition::Bookseller;
40 use Koha::DateUtils;
41 use Koha::Items;
43 my $query=new CGI;
45 # FIXME subject is not exported to the template?
46 my $subject=$query->param('subject');
48 # if its a subject we need to use the subject.tt
49 my ($template, $loggedinuser, $cookie) = get_template_and_user(
51 template_name => ( $subject
52 ? 'catalogue/subject.tt'
53 : 'catalogue/moredetail.tt'),
54 query => $query,
55 type => "intranet",
56 authnotrequired => 0,
57 flagsrequired => { catalogue => 1 },
61 if($query->cookie("holdfor")){
62 my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
63 $template->param(
64 holdfor => $query->cookie("holdfor"),
65 holdfor_surname => $holdfor_patron->{'surname'},
66 holdfor_firstname => $holdfor_patron->{'firstname'},
67 holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
71 my $hidepatronname = C4::Context->preference("HidePatronName");
73 # get variables
75 my $biblionumber=$query->param('biblionumber');
76 my $title=$query->param('title');
77 my $bi=$query->param('bi');
78 $bi = $biblionumber unless $bi;
79 my $itemnumber = $query->param('itemnumber');
80 my $data = &GetBiblioData($biblionumber);
81 my $dewey = $data->{'dewey'};
82 my $showallitems = $query->param('showallitems');
84 #coping with subscriptions
85 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
87 # FIXME Dewey is a string, not a number, & we should use a function
88 # $dewey =~ s/0+$//;
89 # if ($dewey eq "000.") { $dewey = "";};
90 # if ($dewey < 10){$dewey='00'.$dewey;}
91 # if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
92 # if ($dewey <= 0){
93 # $dewey='';
94 # }
95 # $dewey=~ s/\.$//;
96 # $data->{'dewey'}=$dewey;
98 my $fw = GetFrameworkCode($biblionumber);
99 my @all_items= GetItemsInfo($biblionumber);
100 my @items;
101 for my $itm (@all_items) {
102 push @items, $itm unless ( $itm->{itemlost} &&
103 GetHideLostItemsPreference($loggedinuser) &&
104 !$showallitems &&
105 ($itemnumber != $itm->{itemnumber}));
108 my $record=GetMarcBiblio($biblionumber);
110 my $hostrecords;
111 # adding items linked via host biblios
112 my @hostitems = GetHostItemsInfo($record);
113 if (@hostitems){
114 $hostrecords =1;
115 push (@items,@hostitems);
118 my $subtitle = GetRecordValue('subtitle', $record, $fw);
120 my $totalcount=@all_items;
121 my $showncount=@items;
122 my $hiddencount = $totalcount - $showncount;
123 $data->{'count'}=$totalcount;
124 $data->{'showncount'}=$showncount;
125 $data->{'hiddencount'}=$hiddencount; # can be zero
127 my $ccodes= GetKohaAuthorisedValues('items.ccode',$fw);
128 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$fw);
129 my $itemtypes = GetItemTypes;
131 $data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'translated_description'};
132 $data->{'rentalcharge'} = sprintf( "%.2f", $data->{'rentalcharge'} );
133 foreach ( keys %{$data} ) {
134 $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
137 ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items);
138 foreach my $item (@items){
139 $item->{object} = Koha::Items->find( $item->{itemnumber} );
140 $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
141 $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
142 $item->{itemwithdrawnloop}= GetAuthorisedValues(GetAuthValCode('items.withdrawn',$fw),$item->{withdrawn}) if GetAuthValCode('items.withdrawn',$fw);
143 $item->{'collection'} = $ccodes->{ $item->{ccode} } if ($ccodes);
144 $item->{'itype'} = $itemtypes->{ $item->{'itype'} }->{'translated_description'};
145 $item->{'replacementprice'} = sprintf( "%.2f", $item->{'replacementprice'} );
146 if ( defined $item->{'copynumber'} ) {
147 $item->{'displaycopy'} = 1;
148 if ( defined $copynumbers->{ $item->{'copynumber'} } ) {
149 $item->{'copyvol'} = $copynumbers->{ $item->{'copynumber'} }
151 else {
152 $item->{'copyvol'} = $item->{'copynumber'};
156 # item has a host number if its biblio number does not match the current bib
157 if ($item->{biblionumber} ne $biblionumber){
158 $item->{hostbiblionumber} = $item->{biblionumber};
159 $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
162 my $order = GetOrderFromItemnumber( $item->{'itemnumber'} );
163 $item->{'ordernumber'} = $order->{'ordernumber'};
164 $item->{'basketno'} = $order->{'basketno'};
165 $item->{'orderdate'} = $order->{'entrydate'};
166 if ($item->{'basketno'}){
167 my $basket = GetBasket($item->{'basketno'});
168 my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $basket->{booksellerid} });
169 $item->{'vendor'} = $bookseller->{'name'};
171 $item->{'invoiceid'} = $order->{'invoiceid'};
172 if($item->{invoiceid}) {
173 my $invoice = GetInvoice($item->{invoiceid});
174 $item->{invoicenumber} = $invoice->{invoicenumber} if $invoice;
176 $item->{'datereceived'} = $order->{'datereceived'};
178 if ($item->{notforloantext} or $item->{itemlost} or $item->{damaged} or $item->{withdrawn}) {
179 $item->{status_advisory} = 1;
182 if (C4::Context->preference("IndependentBranches")) {
183 #verifying rights
184 my $userenv = C4::Context->userenv();
185 unless (C4::Context->IsSuperLibrarian() or ($userenv->{'branch'} eq $item->{'homebranch'})) {
186 $item->{'nomod'}=1;
189 $item->{'homebranchname'} = GetBranchName($item->{'homebranch'});
190 $item->{'holdingbranchname'} = GetBranchName($item->{'holdingbranch'});
191 if ($item->{'datedue'}) {
192 $item->{'issue'}= 1;
193 } else {
194 $item->{'issue'}= 0;
197 unless ($hidepatronname) {
198 if ( $item->{'borrowernumber'} ) {
199 my $curr_borrower = GetMember('borrowernumber' => $item->{'borrowernumber'} );
200 $item->{borrowerfirstname} = $curr_borrower->{'firstname'};
201 $item->{borrowersurname} = $curr_borrower->{'surname'};
206 $template->param(count => $data->{'count'},
207 subscriptionsnumber => $subscriptionsnumber,
208 subscriptiontitle => $data->{title},
209 C4::Search::enabled_staff_search_views,
212 $template->param(
213 ITEM_DATA => \@items,
214 moredetailview => 1,
215 loggedinuser => $loggedinuser,
216 biblionumber => $biblionumber,
217 biblioitemnumber => $bi,
218 itemnumber => $itemnumber,
219 z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
220 subtitle => $subtitle,
221 hidepatronname => $hidepatronname,
223 $template->param(ONLY_ONE => 1) if ( $itemnumber && $showncount != @items );
224 $template->{'VARS'}->{'searchid'} = $query->param('searchid');
226 my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber);
227 my @deletedorders_using_biblio;
228 my @orders_using_biblio;
229 my @baskets_orders;
230 my @baskets_deletedorders;
232 foreach my $myorder (@allorders_using_biblio) {
233 my $basket = $myorder->{'basketno'};
234 if ((defined $myorder->{'datecancellationprinted'}) and ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
235 push @deletedorders_using_biblio, $myorder;
236 unless (grep(/^$basket$/, @baskets_deletedorders)){
237 push @baskets_deletedorders,$myorder->{'basketno'};
240 else {
241 push @orders_using_biblio, $myorder;
242 unless (grep(/^$basket$/, @baskets_orders)){
243 push @baskets_orders,$myorder->{'basketno'};
248 my $count_orders_using_biblio = scalar @orders_using_biblio ;
249 $template->param (countorders => $count_orders_using_biblio);
251 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
252 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
254 my $holds = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
255 my $holdcount = scalar( @$holds );
256 $template->param( holdcount => scalar ( @$holds ) );
258 output_html_with_http_headers $query, $cookie, $template->output;