Bug 4330 : Adding some copyright BibLibre statements
[wip/koha-chris_n.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;             # contains gettemplate
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
38 my $query=new CGI;
39
40 # FIXME  subject is not exported to the template?
41 my $subject=$query->param('subject');
42
43 # if its a subject we need to use the subject.tmpl
44 my ($template, $loggedinuser, $cookie) = get_template_and_user({
45     template_name   => ($subject? 'catalogue/subject.tmpl':
46                       'catalogue/moredetail.tmpl'),
47     query           => $query,
48     type            => "intranet",
49     authnotrequired => 0,
50     flagsrequired   => {catalogue => 1},
51     });
52
53 if($query->cookie("holdfor")){ 
54     my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
55     $template->param(
56         holdfor => $query->cookie("holdfor"),
57         holdfor_surname => $holdfor_patron->{'surname'},
58         holdfor_firstname => $holdfor_patron->{'firstname'},
59         holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
60     );
61 }
62
63 # get variables
64
65 my $biblionumber=$query->param('biblionumber');
66 my $title=$query->param('title');
67 my $bi=$query->param('bi');
68 $bi = $biblionumber unless $bi;
69 my $data=GetBiblioData($biblionumber);
70 my $dewey = $data->{'dewey'};
71
72 #coping with subscriptions
73 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
74
75 # FIXME Dewey is a string, not a number, & we should use a function
76 # $dewey =~ s/0+$//;
77 # if ($dewey eq "000.") { $dewey = "";};
78 # if ($dewey < 10){$dewey='00'.$dewey;}
79 # if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
80 # if ($dewey <= 0){
81 #      $dewey='';
82 # }
83 # $dewey=~ s/\.$//;
84 # $data->{'dewey'}=$dewey;
85
86 my @results;
87 my $fw = GetFrameworkCode($biblionumber);
88 my @items= GetItemsInfo($biblionumber);
89 my $count=@items;
90 $data->{'count'}=$count;
91
92 my $ccodes= GetKohaAuthorisedValues('items.ccode',$fw);
93 my $itemtypes = GetItemTypes;
94
95 $data->{'itemtypename'} = $itemtypes->{$data->{'itemtype'}}->{'description'};
96 $results[0]=$data;
97 my $itemnumber;
98 ($itemnumber) and @items = (grep {$_->{'itemnumber'} == $itemnumber} @items);
99 foreach my $item (@items){
100     $item->{itemlostloop}= GetAuthorisedValues(GetAuthValCode('items.itemlost',$fw),$item->{itemlost}) if GetAuthValCode('items.itemlost',$fw);
101     $item->{itemdamagedloop}= GetAuthorisedValues(GetAuthValCode('items.damaged',$fw),$item->{damaged}) if GetAuthValCode('items.damaged',$fw);
102     $item->{'collection'}              = $ccodes->{ $item->{ccode} } if ($ccodes);
103     $item->{'itype'}                   = $itemtypes->{ $item->{'itype'} }->{'description'};
104     $item->{'replacementprice'}        = sprintf( "%.2f", $item->{'replacementprice'} );
105     $item->{'datelastborrowed'}        = format_date( $item->{'datelastborrowed'} );
106     $item->{'dateaccessioned'}         = format_date( $item->{'dateaccessioned'} );
107     $item->{'datelastseen'}            = format_date( $item->{'datelastseen'} );
108     $item->{'copyvol'}                 = $item->{'copynumber'};
109
110     my $order = GetOrderFromItemnumber( $item->{'itemnumber'} );
111     $item->{'ordernumber'}             = $order->{'ordernumber'};
112     $item->{'basketno'}                = $order->{'basketno'};
113     $item->{'booksellerinvoicenumber'} = $order->{'booksellerinvoicenumber'};
114
115     if ($item->{notforloantext} or $item->{itemlost} or $item->{damaged} or $item->{wthdrawn}) {
116         $item->{status_advisory} = 1;
117     }
118
119     if (C4::Context->preference("IndependantBranches")) {
120         #verifying rights
121         my $userenv = C4::Context->userenv();
122         unless (($userenv->{'flags'} == 1) or ($userenv->{'branch'} eq $item->{'homebranch'})) {
123                 $item->{'nomod'}=1;
124         }
125     }
126     $item->{'homebranchname'} = GetBranchName($item->{'homebranch'});
127     $item->{'holdingbranchname'} = GetBranchName($item->{'holdingbranch'});
128     if ($item->{'datedue'}) {
129         $item->{'datedue'} = format_date($item->{'datedue'});
130         $item->{'issue'}= 1;
131     } else {
132         $item->{'issue'}= 0;
133     }
134 }
135 $template->param(count => $data->{'count'},
136         subscriptionsnumber => $subscriptionsnumber,
137     subscriptiontitle   => $data->{title},
138         C4::Search::enabled_staff_search_views,
139 );
140 $template->param(BIBITEM_DATA => \@results);
141 $template->param(ITEM_DATA => \@items);
142 $template->param(moredetailview => 1);
143 $template->param(loggedinuser => $loggedinuser);
144 $template->param(biblionumber => $biblionumber);
145 $template->param(biblioitemnumber => $bi);
146 $template->param(itemnumber => $itemnumber);
147 $template->param(ONLY_ONE => 1) if ( $itemnumber && $count != @items );
148 $template->param(z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)));
149
150 output_html_with_http_headers $query, $cookie, $template->output;
151