Bug 8181 [REVISED] Replace DynArch calendar widget with jQueryUI version
[koha.git] / catalogue / moredetail.pl
blob809430cf053fc425f07811d23e9faf051272bf8b
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; # contains gettemplate
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 Koha::DateUtils;
40 my $query=new CGI;
42 # FIXME subject is not exported to the template?
43 my $subject=$query->param('subject');
45 # if its a subject we need to use the subject.tmpl
46 my ($template, $loggedinuser, $cookie) = get_template_and_user({
47 template_name => ($subject? 'catalogue/subject.tmpl':
48 'catalogue/moredetail.tmpl'),
49 query => $query,
50 type => "intranet",
51 authnotrequired => 0,
52 flagsrequired => {catalogue => 1},
53 });
55 if($query->cookie("holdfor")){
56 my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
57 $template->param(
58 holdfor => $query->cookie("holdfor"),
59 holdfor_surname => $holdfor_patron->{'surname'},
60 holdfor_firstname => $holdfor_patron->{'firstname'},
61 holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
65 my $hidepatronname = C4::Context->preference("HidePatronName");
67 # get variables
69 my $biblionumber=$query->param('biblionumber');
70 my $title=$query->param('title');
71 my $bi=$query->param('bi');
72 $bi = $biblionumber unless $bi;
73 my $itemnumber = $query->param('itemnumber');
74 my $data = &GetBiblioData($biblionumber);
75 my $dewey = $data->{'dewey'};
76 my $showallitems = $query->param('showallitems');
78 #coping with subscriptions
79 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
81 # FIXME Dewey is a string, not a number, & we should use a function
82 # $dewey =~ s/0+$//;
83 # if ($dewey eq "000.") { $dewey = "";};
84 # if ($dewey < 10){$dewey='00'.$dewey;}
85 # if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
86 # if ($dewey <= 0){
87 # $dewey='';
88 # }
89 # $dewey=~ s/\.$//;
90 # $data->{'dewey'}=$dewey;
92 my $fw = GetFrameworkCode($biblionumber);
93 my @all_items= GetItemsInfo($biblionumber);
94 my @items;
95 for my $itm (@all_items) {
96 push @items, $itm unless ( $itm->{itemlost} &&
97 GetHideLostItemsPreference($loggedinuser) &&
98 !$showallitems &&
99 ($itemnumber != $itm->{itemnumber}));
102 my $record=GetMarcBiblio($biblionumber);
104 my $hostrecords;
105 # adding items linked via host biblios
106 my @hostitems = GetHostItemsInfo($record);
107 if (@hostitems){
108 $hostrecords =1;
109 push (@items,@hostitems);
112 my $subtitle = GetRecordValue('subtitle', $record, $fw);
114 my $totalcount=@all_items;
115 my $showncount=@items;
116 my $hiddencount = $totalcount - $showncount;
117 $data->{'count'}=$totalcount;
118 $data->{'showncount'}=$showncount;
119 $data->{'hiddencount'}=$hiddencount; # can be zero
121 my $ccodes= GetKohaAuthorisedValues('items.ccode',$fw);
122 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$fw);
123 my $itemtypes = GetItemTypes;
125 $data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'description'};
126 $data->{'rentalcharge'} = sprintf( "%.2f", $data->{'rentalcharge'} );
127 foreach ( keys %{$data} ) {
128 $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
131 ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items);
132 foreach my $item (@items){
133 $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
134 $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
135 $item->{'collection'} = $ccodes->{ $item->{ccode} } if ($ccodes);
136 $item->{'itype'} = $itemtypes->{ $item->{'itype'} }->{'description'};
137 $item->{'replacementprice'} = sprintf( "%.2f", $item->{'replacementprice'} );
138 if ( defined $item->{'copynumber'} ) {
139 $item->{'displaycopy'} = 1;
140 if ( defined $copynumbers->{ $item->{'copynumber'} } ) {
141 $item->{'copyvol'} = $copynumbers->{ $item->{'copynumber'} }
143 else {
144 $item->{'copyvol'} = $item->{'copynumber'};
148 # item has a host number if its biblio number does not match the current bib
149 if ($item->{biblionumber} ne $biblionumber){
150 $item->{hostbiblionumber} = $item->{biblionumber};
151 $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
154 my $order = GetOrderFromItemnumber( $item->{'itemnumber'} );
155 my $basket = GetBasket( $order->{'basketno'} );
156 $item->{'booksellerid'} = $basket->{'booksellerid'};
157 $item->{'ordernumber'} = $order->{'ordernumber'};
158 $item->{'basketno'} = $order->{'basketno'};
159 $item->{'booksellerinvoicenumber'} = $order->{'booksellerinvoicenumber'};
160 $item->{'orderdate'} = $order->{'entrydate'};
161 if ($item->{'basketno'}){
162 my $basket = GetBasket($item->{'basketno'});
163 my $bookseller = GetBookSellerFromId($basket->{'booksellerid'});
164 $item->{'vendor'} = $bookseller->{'name'};
166 $item->{'datereceived'} = $order->{'datereceived'};
168 if ($item->{notforloantext} or $item->{itemlost} or $item->{damaged} or $item->{wthdrawn}) {
169 $item->{status_advisory} = 1;
172 if (C4::Context->preference("IndependantBranches")) {
173 #verifying rights
174 my $userenv = C4::Context->userenv();
175 unless (($userenv->{'flags'} == 1) or ($userenv->{'branch'} eq $item->{'homebranch'})) {
176 $item->{'nomod'}=1;
179 $item->{'homebranchname'} = GetBranchName($item->{'homebranch'});
180 $item->{'holdingbranchname'} = GetBranchName($item->{'holdingbranch'});
181 if ($item->{'datedue'}) {
182 $item->{'issue'}= 1;
183 } else {
184 $item->{'issue'}= 0;
187 unless ($hidepatronname) {
188 if ( $item->{'borrowernumber'} ) {
189 my $curr_borrower = GetMember('borrowernumber' => $item->{'borrowernumber'} );
190 $item->{borrowerfirstname} = $curr_borrower->{'firstname'};
191 $item->{borrowersurname} = $curr_borrower->{'surname'};
196 $template->param(count => $data->{'count'},
197 subscriptionsnumber => $subscriptionsnumber,
198 subscriptiontitle => $data->{title},
199 C4::Search::enabled_staff_search_views,
202 $template->param(
203 ITEM_DATA => \@items,
204 moredetailview => 1,
205 loggedinuser => $loggedinuser,
206 biblionumber => $biblionumber,
207 biblioitemnumber => $bi,
208 itemnumber => $itemnumber,
209 z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
210 subtitle => $subtitle,
211 hidepatronname => $hidepatronname,
213 $template->param(ONLY_ONE => 1) if ( $itemnumber && $showncount != @items );
215 output_html_with_http_headers $query, $cookie, $template->output;