Bug 11810: Input fields in OPAC suggestion form are a bit short (Bootstrap)
[koha.git] / catalogue / moredetail.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2003 Katipo Communications
4 # parts copyright 2010 BibLibre
5 #
6 # This file is part of Koha.
7 #
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.
12 #
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.
16 #
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.
20
21
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;
40
41 my $query=new CGI;
42
43 # FIXME  subject is not exported to the template?
44 my $subject=$query->param('subject');
45
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     });
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 my $hidepatronname = C4::Context->preference("HidePatronName");
67
68 # get variables
69
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');
78
79 #coping with subscriptions
80 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
81
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;
92
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}));
101 }
102
103 my $record=GetMarcBiblio($biblionumber);
104
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);
111 }
112
113 my $subtitle = GetRecordValue('subtitle', $record, $fw);
114
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
121
122 my $ccodes= GetKohaAuthorisedValues('items.ccode',$fw);
123 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$fw);
124 my $itemtypes = GetItemTypes;
125
126 $data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'description'};
127 $data->{'rentalcharge'} = sprintf( "%.2f", $data->{'rentalcharge'} );
128 foreach ( keys %{$data} ) {
129     $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
130 }
131
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'} }
143         }
144         else {
145             $item->{'copyvol'} = $item->{'copynumber'};
146         }
147     }
148
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};
153     }
154
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'};
163     }
164     $item->{'invoiceid'}               = $order->{'invoiceid'};
165     if($item->{invoiceid}) {
166         my $invoice = GetInvoice($item->{invoiceid});
167         $item->{invoicenumber} = $invoice->{invoicenumber} if $invoice;
168     }
169     $item->{'datereceived'}            = $order->{'datereceived'};
170
171     if ($item->{notforloantext} or $item->{itemlost} or $item->{damaged} or $item->{withdrawn}) {
172         $item->{status_advisory} = 1;
173     }
174
175     if (C4::Context->preference("IndependentBranches")) {
176         #verifying rights
177         my $userenv = C4::Context->userenv();
178         unless (C4::Context->IsSuperLibrarian() or ($userenv->{'branch'} eq $item->{'homebranch'})) {
179                 $item->{'nomod'}=1;
180         }
181     }
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;
188     }
189
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'};
195         }
196     }
197
198 }
199 $template->param(count => $data->{'count'},
200         subscriptionsnumber => $subscriptionsnumber,
201     subscriptiontitle   => $data->{title},
202         C4::Search::enabled_staff_search_views,
203 );
204
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,
215 );
216 $template->param(ONLY_ONE => 1) if ( $itemnumber && $showncount != @items );
217 $template->{'VARS'}->{'searchid'} = $query->param('searchid');
218
219 my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber);
220 my @deletedorders_using_biblio;
221 my @orders_using_biblio;
222 my @baskets_orders;
223 my @baskets_deletedorders;
224
225 foreach my $myorder (@allorders_using_biblio) {
226     my $basket = $myorder->{'basketno'};
227     if ((defined $myorder->{'datecancellationprinted'}) and  ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
228         push @deletedorders_using_biblio, $myorder;
229         unless (grep(/^$basket$/, @baskets_deletedorders)){
230             push @baskets_deletedorders,$myorder->{'basketno'};
231         }
232     }
233     else {
234         push @orders_using_biblio, $myorder;
235         unless (grep(/^$basket$/, @baskets_orders)){
236             push @baskets_orders,$myorder->{'basketno'};
237             }
238     }
239 }
240
241 my $count_orders_using_biblio = scalar @orders_using_biblio ;
242 $template->param (countorders => $count_orders_using_biblio);
243
244 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
245 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
246
247 my $holds = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
248 my $holdcount = scalar( @$holds );
249 $template->param( holdcount => scalar ( @$holds ) );
250
251 output_html_with_http_headers $query, $cookie, $template->output;
252