Followup Adding subtitle opac-results.tmpl had to be updated
[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
21 use strict;
22 use C4::Koha;
23 use CGI;
24 use C4::Biblio;
25 use C4::Items;
26 use C4::Branch;
27 use C4::Acquisition;
28 use C4::Output;             # contains gettemplate
29 use C4::Auth;
30 use C4::Serials;
31 use C4::Dates qw/format_date/;
32 use C4::Circulation;  # to use itemissues
33 use C4::Search;         # enabled_staff_search_views
34
35 my $query=new CGI;
36
37 # FIXME  subject is not exported to the template?
38 my $subject=$query->param('subject');
39
40 # if its a subject we need to use the subject.tmpl
41 my ($template, $loggedinuser, $cookie) = get_template_and_user({
42     template_name   => ($subject? 'catalogue/subject.tmpl':
43                       'catalogue/moredetail.tmpl'),
44     query           => $query,
45     type            => "intranet",
46     authnotrequired => 0,
47     flagsrequired   => {catalogue => 1},
48     });
49
50 # get variables
51
52 my $biblionumber=$query->param('biblionumber');
53 my $title=$query->param('title');
54 my $itemnumber=$query->param('itemnumber');
55 my $bi=$query->param('bi');
56 # $bi = $biblionumber unless $bi;
57 my $data=GetBiblioData($biblionumber);
58 my $dewey = $data->{'dewey'};
59
60 #coping with subscriptions
61 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
62
63 # FIXME Dewey is a string, not a number, & we should use a function
64 # $dewey =~ s/0+$//;
65 # if ($dewey eq "000.") { $dewey = "";};
66 # if ($dewey < 10){$dewey='00'.$dewey;}
67 # if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
68 # if ($dewey <= 0){
69 #      $dewey='';
70 # }
71 # $dewey=~ s/\.$//;
72 # $data->{'dewey'}=$dewey;
73
74 my @results;
75 my $fw = GetFrameworkCode($biblionumber);
76 my @items= GetItemsInfo($biblionumber);
77 my $count=@items;
78 $data->{'count'}=$count;
79
80 my $ordernum = GetOrderNumber($biblionumber);
81 my $order = GetOrder($ordernum);
82 my $ccodes= GetKohaAuthorisedValues('items.ccode',$fw);
83 my $itemtypes = GetItemTypes;
84
85 $data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'description'};
86 $results[0]=$data;
87 ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items);
88 foreach my $item (@items){
89     $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
90     $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
91     $item->{'collection'} = $ccodes->{$item->{ccode}};
92     $item->{'itype'} = $itemtypes->{$item->{'itype'}}->{'description'}; 
93     $item->{'replacementprice'}=sprintf("%.2f", $item->{'replacementprice'});
94     $item->{'datelastborrowed'}= format_date($item->{'datelastborrowed'});
95     $item->{'dateaccessioned'} = format_date($item->{'dateaccessioned'});
96     $item->{'datelastseen'} = format_date($item->{'datelastseen'});
97     $item->{'ordernumber'} = $ordernum;
98     $item->{'booksellerinvoicenumber'} = $order->{'booksellerinvoicenumber'};
99     $item->{'copyvol'} = $item->{'copynumber'};
100     if ($item->{notforloantext} or $item->{itemlost} or $item->{damaged} or $item->{wthdrawn}) {
101         $item->{status_advisory} = 1;
102     }
103
104     if (C4::Context->preference("IndependantBranches")) {
105         #verifying rights
106         my $userenv = C4::Context->userenv();
107         unless (($userenv->{'flags'} == 1) or ($userenv->{'branch'} eq $item->{'homebranch'})) {
108                 $item->{'nomod'}=1;
109         }
110     }
111     $item->{'homebranchname'} = GetBranchName($item->{'homebranch'});
112     $item->{'holdingbranchname'} = GetBranchName($item->{'holdingbranch'});
113     if ($item->{'datedue'}) {
114         $item->{'datedue'} = format_date($item->{'datedue'});
115         $item->{'issue'}= 1;
116     } else {
117         $item->{'issue'}= 0;
118     }
119 }
120 $template->param(count => $data->{'count'},
121         subscriptionsnumber => $subscriptionsnumber,
122     subscriptiontitle   => $data->{title},
123         C4::Search::enabled_staff_search_views,
124 );
125 $template->param(BIBITEM_DATA => \@results);
126 $template->param(ITEM_DATA => \@items);
127 $template->param(moredetailview => 1);
128 $template->param(loggedinuser => $loggedinuser);
129 $template->param(biblionumber => $biblionumber);
130 $template->param(biblioitemnumber => $bi);
131 $template->param(itemnumber => $itemnumber);
132 $template->param(ONLY_ONE => 1) if ( $itemnumber && $count != @items );
133 $template->param(z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)));
134
135 output_html_with_http_headers $query, $cookie, $template->output;
136