Bug 26511: [19.11.x] Remove PatronSelfRegistrationConfirmEmail from opac.pref
[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
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.
12 #
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.
17 #
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>.
20
21
22 use Modern::Perl;
23 use C4::Koha;
24 use CGI qw ( -utf8 );
25 use HTML::Entities;
26 use C4::Biblio;
27 use C4::Items;
28 use C4::Acquisition;
29 use C4::Output;
30 use C4::Auth;
31 use C4::Serials;
32 use C4::Search;         # enabled_staff_search_views
33
34 use Koha::Acquisition::Booksellers;
35 use Koha::AuthorisedValues;
36 use Koha::Biblios;
37 use Koha::DateUtils;
38 use Koha::Items;
39 use Koha::Patrons;
40
41 my $query=new CGI;
42
43 my ($template, $loggedinuser, $cookie) = get_template_and_user(
44     {
45         template_name   => 'catalogue/moredetail.tt',
46         query           => $query,
47         type            => "intranet",
48         flagsrequired   => { catalogue => 1 },
49     }
50 );
51
52 if($query->cookie("holdfor")){ 
53     my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
54     $template->param(
55         holdfor => $query->cookie("holdfor"),
56         holdfor_surname => $holdfor_patron->surname,
57         holdfor_firstname => $holdfor_patron->firstname,
58         holdfor_cardnumber => $holdfor_patron->cardnumber,
59     );
60 }
61
62 # get variables
63
64 my $biblionumber=$query->param('biblionumber');
65 $biblionumber = HTML::Entities::encode($biblionumber);
66 my $title=$query->param('title');
67 my $bi=$query->param('bi');
68 $bi = $biblionumber unless $bi;
69 my $itemnumber = $query->param('itemnumber');
70 my $data = &GetBiblioData($biblionumber);
71 my $dewey = $data->{'dewey'};
72 my $showallitems = $query->param('showallitems');
73
74 #coping with subscriptions
75 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
76
77 # FIXME Dewey is a string, not a number, & we should use a function
78 # $dewey =~ s/0+$//;
79 # if ($dewey eq "000.") { $dewey = "";};
80 # if ($dewey < 10){$dewey='00'.$dewey;}
81 # if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
82 # if ($dewey <= 0){
83 #      $dewey='';
84 # }
85 # $dewey=~ s/\.$//;
86 # $data->{'dewey'}=$dewey;
87
88 my $fw = GetFrameworkCode($biblionumber);
89 my @all_items= GetItemsInfo($biblionumber);
90 my @items;
91 my $patron = Koha::Patrons->find( $loggedinuser );
92 for my $itm (@all_items) {
93     push @items, $itm unless ( $itm->{itemlost} && 
94                                $patron->category->hidelostitems &&
95                                !$showallitems && 
96                                ($itemnumber != $itm->{itemnumber}));
97 }
98
99 my $record=GetMarcBiblio({ biblionumber => $biblionumber });
100
101 output_and_exit( $query, $cookie, $template, 'unknown_biblio')
102     unless $record;
103
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);
110 }
111
112 my $subtitle = GetRecordValue('subtitle', $record, $fw);
113
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
120
121 my $ccodes =
122   { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.ccode' } ) };
123 my $copynumbers =
124   { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.copynumber' } ) };
125
126 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
127
128 $data->{'itemtypename'} = $itemtypes->{ $data->{'itemtype'} }->{'translated_description'}
129   if $data->{itemtype} && exists $itemtypes->{ $data->{itemtype} };
130 foreach ( keys %{$data} ) {
131     $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
132 }
133
134 ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items);
135 foreach my $item (@items){
136     $item->{object} = Koha::Items->find( $item->{itemnumber} );
137     $item->{'collection'}              = $ccodes->{ $item->{ccode} } if $ccodes && $item->{ccode} && exists $ccodes->{ $item->{ccode} };
138     $item->{'itype'}                   = $itemtypes->{ $item->{'itype'} }->{'translated_description'} if exists $itemtypes->{ $item->{'itype'} };
139     $item->{'replacementprice'}        = $item->{'replacementprice'};
140     if ( defined $item->{'copynumber'} ) {
141         $item->{'displaycopy'} = 1;
142         if ( defined $copynumbers->{ $item->{'copynumber'} } ) {
143             $item->{'copyvol'} = $copynumbers->{ $item->{'copynumber'} }
144         }
145         else {
146             $item->{'copyvol'} = $item->{'copynumber'};
147         }
148     }
149
150     # item has a host number if its biblio number does not match the current bib
151     if ($item->{biblionumber} ne $biblionumber){
152         $item->{hostbiblionumber} = $item->{biblionumber};
153         $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
154     }
155
156     my $order  = GetOrderFromItemnumber( $item->{'itemnumber'} );
157     $item->{'ordernumber'}             = $order->{'ordernumber'};
158     $item->{'basketno'}                = $order->{'basketno'};
159     $item->{'orderdate'}               = $order->{'entrydate'};
160     if ($item->{'basketno'}){
161             my $basket = GetBasket($item->{'basketno'});
162         my $bookseller = Koha::Acquisition::Booksellers->find( $basket->{booksellerid} );
163         $item->{'vendor'} = $bookseller->name;
164     }
165     $item->{'invoiceid'}               = $order->{'invoiceid'};
166     if($item->{invoiceid}) {
167         my $invoice = GetInvoice($item->{invoiceid});
168         $item->{invoicenumber} = $invoice->{invoicenumber} if $invoice;
169     }
170     $item->{'datereceived'}            = $order->{'datereceived'};
171
172     if ($item->{notforloantext} or $item->{itemlost} or $item->{damaged} or $item->{withdrawn}) {
173         $item->{status_advisory} = 1;
174     }
175
176     if (C4::Context->preference("IndependentBranches")) {
177         #verifying rights
178         my $userenv = C4::Context->userenv();
179         unless (C4::Context->IsSuperLibrarian() or ($userenv->{'branch'} eq $item->{'homebranch'})) {
180                 $item->{'nomod'}=1;
181         }
182     }
183     if ($item->{'datedue'}) {
184         $item->{'issue'}= 1;
185     } else {
186         $item->{'issue'}= 0;
187     }
188
189     if ( $item->{'borrowernumber'} ) {
190         my $curr_borrower = Koha::Patrons->find( $item->{borrowernumber} );
191         $item->{patron} = $curr_borrower;
192     }
193 }
194
195 my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.itemlost', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
196 if ( $mss->count ) {
197     $template->param( itemlostloop => GetAuthorisedValues( $mss->next->authorised_value ) );
198 }
199 $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.damaged', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
200 if ( $mss->count ) {
201     $template->param( itemdamagedloop => GetAuthorisedValues( $mss->next->authorised_value ) );
202 }
203 $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.withdrawn', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
204 if ( $mss->count ) {
205     $template->param( itemwithdrawnloop => GetAuthorisedValues( $mss->next->authorised_value) );
206 }
207
208 $template->param(count => $data->{'count'},
209         subscriptionsnumber => $subscriptionsnumber,
210     subscriptiontitle   => $data->{title},
211         C4::Search::enabled_staff_search_views,
212 );
213
214 $template->param(
215     ITEM_DATA           => \@items,
216     moredetailview      => 1,
217     loggedinuser        => $loggedinuser,
218     biblionumber        => $biblionumber,
219     biblioitemnumber    => $bi,
220     itemnumber          => $itemnumber,
221     z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
222     subtitle            => $subtitle,
223 );
224 $template->param(ONLY_ONE => 1) if ( $itemnumber && $showncount != @items );
225 $template->{'VARS'}->{'searchid'} = $query->param('searchid');
226
227 my @allorders_using_biblio = GetOrdersByBiblionumber ($biblionumber);
228 my @deletedorders_using_biblio;
229 my @orders_using_biblio;
230 my @baskets_orders;
231 my @baskets_deletedorders;
232
233 foreach my $myorder (@allorders_using_biblio) {
234     my $basket = $myorder->{'basketno'};
235     if ((defined $myorder->{'datecancellationprinted'}) and  ($myorder->{'datecancellationprinted'} ne '0000-00-00') ){
236         push @deletedorders_using_biblio, $myorder;
237         unless (grep(/^$basket$/, @baskets_deletedorders)){
238             push @baskets_deletedorders,$myorder->{'basketno'};
239         }
240     }
241     else {
242         push @orders_using_biblio, $myorder;
243         unless (grep(/^$basket$/, @baskets_orders)){
244             push @baskets_orders,$myorder->{'basketno'};
245             }
246     }
247 }
248
249 my $count_orders_using_biblio = scalar @orders_using_biblio ;
250 $template->param (countorders => $count_orders_using_biblio);
251
252 my $count_deletedorders_using_biblio = scalar @deletedorders_using_biblio ;
253 $template->param (countdeletedorders => $count_deletedorders_using_biblio);
254
255 my $biblio = Koha::Biblios->find( $biblionumber );
256 my $holds = $biblio->holds;
257 $template->param( holdcount => $holds->count );
258
259 output_html_with_http_headers $query, $cookie, $template->output;
260