Fix for Bug 3659, Add place hold option from patron checkout tab
[wip/koha-chris_n.git] / catalogue / moredetail.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2003 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
21 use strict;
22 #use warnings; FIXME - Bug 2505
23 use C4::Koha;
24 use CGI;
25 use C4::Biblio;
26 use C4::Items;
27 use C4::Branch;
28 use C4::Acquisition;
29 use C4::Output;             # contains gettemplate
30 use C4::Auth;
31 use C4::Serials;
32 use C4::Dates qw/format_date/;
33 use C4::Circulation;  # to use itemissues
34 use C4::Members; # to use GetMember
35 use C4::Search;         # enabled_staff_search_views
36
37 my $query=new CGI;
38
39 # FIXME  subject is not exported to the template?
40 my $subject=$query->param('subject');
41
42 # if its a subject we need to use the subject.tmpl
43 my ($template, $loggedinuser, $cookie) = get_template_and_user({
44     template_name   => ($subject? 'catalogue/subject.tmpl':
45                       'catalogue/moredetail.tmpl'),
46     query           => $query,
47     type            => "intranet",
48     authnotrequired => 0,
49     flagsrequired   => {catalogue => 1},
50     });
51
52 if($query->cookie("holdfor")){ 
53     my $holdfor_patron = GetMember('borrowernumber' => $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 my $title=$query->param('title');
66 my $bi=$query->param('bi');
67 $bi = $biblionumber unless $bi;
68 my $data=GetBiblioData($biblionumber);
69 my $dewey = $data->{'dewey'};
70
71 #coping with subscriptions
72 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
73
74 # FIXME Dewey is a string, not a number, & we should use a function
75 # $dewey =~ s/0+$//;
76 # if ($dewey eq "000.") { $dewey = "";};
77 # if ($dewey < 10){$dewey='00'.$dewey;}
78 # if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
79 # if ($dewey <= 0){
80 #      $dewey='';
81 # }
82 # $dewey=~ s/\.$//;
83 # $data->{'dewey'}=$dewey;
84
85 my @results;
86 my $fw = GetFrameworkCode($biblionumber);
87 my @items= GetItemsInfo($biblionumber);
88 my $count=@items;
89 $data->{'count'}=$count;
90
91 my $ccodes= GetKohaAuthorisedValues('items.ccode',$fw);
92 my $itemtypes = GetItemTypes;
93
94 $data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'description'};
95 $results[0]=$data;
96 my $itemnumber;
97 ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items);
98 foreach my $item (@items){
99     $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
100     $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
101     $item->{'collection'}              = $ccodes->{ $item->{ccode} };
102     $item->{'itype'}                   = $itemtypes->{ $item->{'itype'} }->{'description'};
103     $item->{'replacementprice'}        = sprintf( "%.2f", $item->{'replacementprice'} );
104     $item->{'datelastborrowed'}        = format_date( $item->{'datelastborrowed'} );
105     $item->{'dateaccessioned'}         = format_date( $item->{'dateaccessioned'} );
106     $item->{'datelastseen'}            = format_date( $item->{'datelastseen'} );
107     $item->{'copyvol'}                 = $item->{'copynumber'};
108
109     my $order = GetOrderFromItemnumber( $item->{'itemnumber'} );
110     $item->{'ordernumber'}             = $order->{'ordernumber'};
111     $item->{'basketno'}                = $order->{'basketno'};
112     $item->{'booksellerinvoicenumber'} = $order->{'booksellerinvoicenumber'};
113
114     if ($item->{notforloantext} or $item->{itemlost} or $item->{damaged} or $item->{wthdrawn}) {
115         $item->{status_advisory} = 1;
116     }
117
118     if (C4::Context->preference("IndependantBranches")) {
119         #verifying rights
120         my $userenv = C4::Context->userenv();
121         unless (($userenv->{'flags'} == 1) or ($userenv->{'branch'} eq $item->{'homebranch'})) {
122                 $item->{'nomod'}=1;
123         }
124     }
125     $item->{'homebranchname'} = GetBranchName($item->{'homebranch'});
126     $item->{'holdingbranchname'} = GetBranchName($item->{'holdingbranch'});
127     if ($item->{'datedue'}) {
128         $item->{'datedue'} = format_date($item->{'datedue'});
129         $item->{'issue'}= 1;
130     } else {
131         $item->{'issue'}= 0;
132     }
133 }
134 $template->param(count => $data->{'count'},
135         subscriptionsnumber => $subscriptionsnumber,
136     subscriptiontitle   => $data->{title},
137         C4::Search::enabled_staff_search_views,
138 );
139 $template->param(BIBITEM_DATA => \@results);
140 $template->param(ITEM_DATA => \@items);
141 $template->param(moredetailview => 1);
142 $template->param(loggedinuser => $loggedinuser);
143 $template->param(biblionumber => $biblionumber);
144 $template->param(biblioitemnumber => $bi);
145 $template->param(itemnumber => $itemnumber);
146 $template->param(ONLY_ONE => 1) if ( $itemnumber && $count != @items );
147 $template->param(z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)));
148
149 output_html_with_http_headers $query, $cookie, $template->output;
150