Test to check for XXX in kohaversion.pl or updatedatabase.pl
[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::Output;
31 use C4::Auth;
32 use C4::Serials;
33 use C4::Dates qw/format_date/;
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
39 my $query=new CGI;
40
41 # FIXME  subject is not exported to the template?
42 my $subject=$query->param('subject');
43
44 # if its a subject we need to use the subject.tmpl
45 my ($template, $loggedinuser, $cookie) = get_template_and_user({
46     template_name   => ($subject? 'catalogue/subject.tmpl':
47                       'catalogue/moredetail.tmpl'),
48     query           => $query,
49     type            => "intranet",
50     authnotrequired => 0,
51     flagsrequired   => {catalogue => 1},
52     });
53
54 if($query->cookie("holdfor")){ 
55     my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
56     $template->param(
57         holdfor => $query->cookie("holdfor"),
58         holdfor_surname => $holdfor_patron->{'surname'},
59         holdfor_firstname => $holdfor_patron->{'firstname'},
60         holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
61     );
62 }
63
64 # get variables
65
66 my $biblionumber=$query->param('biblionumber');
67 my $title=$query->param('title');
68 my $bi=$query->param('bi');
69 $bi = $biblionumber unless $bi;
70 my $itemnumber = $query->param('itemnumber');
71 my $data = &GetBiblioData($biblionumber);
72 my $dewey = $data->{'dewey'};
73 my $showallitems = $query->param('showallitems');
74
75 #coping with subscriptions
76 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
77
78 # FIXME Dewey is a string, not a number, & we should use a function
79 # $dewey =~ s/0+$//;
80 # if ($dewey eq "000.") { $dewey = "";};
81 # if ($dewey < 10){$dewey='00'.$dewey;}
82 # if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
83 # if ($dewey <= 0){
84 #      $dewey='';
85 # }
86 # $dewey=~ s/\.$//;
87 # $data->{'dewey'}=$dewey;
88
89 my $fw = GetFrameworkCode($biblionumber);
90 my @all_items= GetItemsInfo($biblionumber);
91 my @items;
92 for my $itm (@all_items) {
93     push @items, $itm unless ( $itm->{itemlost} && 
94                                GetHideLostItemsPreference($loggedinuser) &&
95                                !$showallitems && 
96                                ($itemnumber != $itm->{itemnumber}));
97 }
98
99 my $totalcount=@all_items;
100 my $showncount=@items;
101 my $hiddencount = $totalcount - $showncount;
102 $data->{'count'}=$totalcount;
103 $data->{'showncount'}=$showncount;
104 $data->{'hiddencount'}=$hiddencount;  # can be zero
105
106 my $ccodes= GetKohaAuthorisedValues('items.ccode',$fw);
107 my $itemtypes = GetItemTypes;
108
109 $data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'description'};
110
111 foreach ( keys %{$data} ) {
112     $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' );
113 }
114
115 ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items);
116 foreach my $item (@items){
117     $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
118     $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
119     $item->{'collection'}              = $ccodes->{ $item->{ccode} } if ($ccodes);
120     $item->{'itype'}                   = $itemtypes->{ $item->{'itype'} }->{'description'};
121     $item->{'replacementprice'}        = sprintf( "%.2f", $item->{'replacementprice'} );
122     $item->{'datelastborrowed'}        = format_date( $item->{'datelastborrowed'} );
123     $item->{'dateaccessioned'}         = format_date( $item->{'dateaccessioned'} );
124     $item->{'datelastseen'}            = format_date( $item->{'datelastseen'} );
125     $item->{'copyvol'}                 = $item->{'copynumber'};
126
127     my $order = GetOrderFromItemnumber( $item->{'itemnumber'} );
128     $item->{'ordernumber'}             = $order->{'ordernumber'};
129     $item->{'basketno'}                = $order->{'basketno'};
130     $item->{'booksellerinvoicenumber'} = $order->{'booksellerinvoicenumber'};
131
132     if ($item->{notforloantext} or $item->{itemlost} or $item->{damaged} or $item->{wthdrawn}) {
133         $item->{status_advisory} = 1;
134     }
135
136     if (C4::Context->preference("IndependantBranches")) {
137         #verifying rights
138         my $userenv = C4::Context->userenv();
139         unless (($userenv->{'flags'} == 1) or ($userenv->{'branch'} eq $item->{'homebranch'})) {
140                 $item->{'nomod'}=1;
141         }
142     }
143     $item->{'homebranchname'} = GetBranchName($item->{'homebranch'});
144     $item->{'holdingbranchname'} = GetBranchName($item->{'holdingbranch'});
145     if ($item->{'datedue'}) {
146         $item->{'datedue'} = format_date($item->{'datedue'});
147         $item->{'issue'}= 1;
148     } else {
149         $item->{'issue'}= 0;
150     }
151 }
152 my $borrower_link
153     = ( C4::Context->preference("BorrowingHistoryLink") eq 'details' )
154     ? 'members/moremember.pl'
155     : 'circ/circulation.pl';
156 $template->param(
157     count               => $data->{'count'},
158     subscriptionsnumber => $subscriptionsnumber,
159     subscriptiontitle   => $data->{title},
160     borrowerlink        => $borrower_link,
161     C4::Search::enabled_staff_search_views,
162 );
163
164 $template->param(
165     ITEM_DATA           => \@items,
166     moredetailview      => 1,
167     loggedinuser        => $loggedinuser,
168     biblionumber        => $biblionumber,
169     biblioitemnumber    => $bi,
170     itemnumber          => $itemnumber,
171     z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
172     subtitle            => $subtitle,
173 );
174 $template->param(ONLY_ONE => 1) if ( $itemnumber && $showncount != @items );
175
176 output_html_with_http_headers $query, $cookie, $template->output;
177