rel_3_0 moved to HEAD
[koha.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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 # $Id$
21
22 use strict;
23 require Exporter;
24 use C4::Koha;
25 use CGI;
26 use C4::Biblio;             # to use &GetBiblioItemData &itemissues
27 use C4::Acquisition;
28 use C4::Output;             # contains gettemplate
29 use C4::Auth;
30 use C4::Interface::CGI::Output;
31 use C4::Date;
32 use C4::Circulation::Circ2;  # to use itemissues
33
34 my $query=new CGI;
35
36 # FIXME  subject is not exported to the template?
37 my $subject=$query->param('subject');
38
39 # if its a subject we need to use the subject.tmpl
40 my ($template, $loggedinuser, $cookie) = get_template_and_user({
41     template_name   => ($subject? 'catalogue/subject.tmpl':
42                       'catalogue/moredetail.tmpl'),
43     query           => $query,
44     type            => "intranet",
45     authnotrequired => 0,
46     flagsrequired   => {catalogue => 1},
47     });
48
49 # get variables
50
51 my $biblionumber=$query->param('biblionumber');
52 my $title=$query->param('title');
53 my $bi=$query->param('bi');
54
55 my $data=GetBiblioItemData($bi);
56 my $dewey = $data->{'dewey'};
57 # FIXME Dewey is a string, not a number, & we should use a function
58 $dewey =~ s/0+$//;
59 if ($dewey eq "000.") { $dewey = "";};
60 if ($dewey < 10){$dewey='00'.$dewey;}
61 if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
62 if ($dewey <= 0){
63       $dewey='';
64 }
65 $dewey=~ s/\.$//;
66 $data->{'dewey'}=$dewey;
67
68 my @results;
69
70 my (@items)= itemissues($bi);
71 my $count=@items;
72 $data->{'count'}=$count;
73
74 my $ordernum = GetOrderNumber($biblionumber,$bi);
75 my $order = GetOrder($ordernum);
76
77 my $env;
78 $env->{itemcount}=1;
79
80 $results[0]=$data;
81
82 foreach my $item (@items){
83     $item->{'replacementprice'}=sprintf("%.2f", $item->{'replacementprice'});
84     $item->{'datelastborrowed'}= format_date($item->{'datelastborrowed'});
85     $item->{'dateaccessioned'} = format_date($item->{'dateaccessioned'});
86     $item->{'datelastseen'} = format_date($item->{'datelastseen'});
87     $item->{'ordernumber'} = $ordernum;
88     $item->{'booksellerinvoicenumber'} = $order->{'booksellerinvoicenumber'};
89
90     if ($item->{'date_due'} eq 'Available'){
91         $item->{'issue'}= 0;
92     } else {
93         $item->{'date_due'} = format_date($item->{'date_due'});
94         $item->{'issue'}= 1;
95         $item->{'borrowernumber'} = $item->{'borrower'};
96         $item->{'cardnumber'} = $item->{'card'};
97     }
98 }
99
100 $template->param(BIBITEM_DATA => \@results);
101 $template->param(ITEM_DATA => \@items);
102 $template->param(loggedinuser => $loggedinuser);
103
104 output_html_with_http_headers $query, $cookie, $template->output;
105