Merged with rel-1-2 copy
[koha.git] / moredetail.pl
1 #!/usr/bin/perl
2 use HTML::Template;
3 use strict;
4 require Exporter;
5 use C4::Koha;
6 use CGI;
7 use C4::Search;
8 use C4::Acquisitions;
9 use C4::Output; # contains picktemplate
10   
11 my $query=new CGI;
12
13
14 my $language='french';
15
16
17 my %configfile;
18 open (KC, "/etc/koha.conf");
19 while (<KC>) {
20  chomp;
21  (next) if (/^\s*#/);
22  if (/(.*)\s*=\s*(.*)/) {
23    my $variable=$1;
24    my $value=$2;
25    # Clean up white space at beginning and end
26    $variable=~s/^\s*//g;
27    $variable=~s/\s*$//g;
28    $value=~s/^\s*//g;
29    $value=~s/\s*$//g;
30    $configfile{$variable}=$value;
31  }
32 }
33
34 my $includes=$configfile{'includes'};
35 ($includes) || ($includes="/usr/local/www/hdl/htdocs/includes");
36 my $templatebase="catalogue/moredetail.tmpl";
37 my $startfrom=$query->param('startfrom');
38 ($startfrom) || ($startfrom=0);
39 my $theme=picktemplate($includes, $templatebase);
40
41 my $subject=$query->param('subject');
42 # if its a subject we need to use the subject.tmpl
43 if ($subject){
44   $templatebase=~ s/searchresults\.tmpl/subject\.tmpl/;
45 }
46 my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]);
47
48 # get variables 
49
50 my $biblionumber=$query->param('bib');
51 my $title=$query->param('title');
52 my $bi=$query->param('bi');
53
54 my $data=bibitemdata($bi);
55 my $dewey = $data->{'dewey'};
56 $dewey =~ s/0+$//;
57 if ($dewey eq "000.") { $dewey = "";};
58 if ($dewey < 10){$dewey='00'.$dewey;}
59 if ($dewey < 100 && $dewey > 10){$dewey='0'.$dewey;}
60 if ($dewey <= 0){
61       $dewey='';
62 }
63 $dewey=~ s/\.$//;
64 $data->{'dewey'}=$dewey;
65
66 my @results;
67
68 my (@items)=itemissues($bi);
69 my $count=@items;
70 $data->{'count'}=$count;
71 my ($order,$ordernum)=getorder($bi,$biblionumber);
72
73 my $env;
74 $env->{itemcount}=1;
75
76 $results[0]=$data;
77
78 foreach my $item (@items){
79     $item->{'itemlost'}=~ s/0/No/;
80     $item->{'itemlost'}=~ s/1/Yes/;
81     $item->{'withdrawn'}=~ s/0/No/;
82     $item->{'withdrawn'}=~ s/1/Yes/;
83     $item->{'replacementprice'}+=0.00;
84     my $year=substr($item->{'timestamp0'},0,4);
85     my $mon=substr($item->{'timestamp0'},4,2);
86     my $day=substr($item->{'timestamp0'},6,2);
87     $item->{'timestamp0'}="$day/$mon/$year";
88     $item->{'dateaccessioned'} = slashifyDate($item->{'dateaccessioned'});
89     $item->{'datelastseen'} = slashifyDate($item->{'datelastseen'});
90     if ($item->{'date_due'} = 'Available'){
91         $item->{'issue'}="<b>Currently on issue to:</b><br>";
92     } else {
93         $item->{'issue'}="<b>Currently on issue to:</b> <a href=/cgi-bin/koha/moremember.pl?bornum=$item->{'borrower0'}>$item->{'card'}</a><br>";
94     }
95           
96 }
97
98 $template->param(includesdir => $includes);
99 $template->param(BIBITEM_DATA => \@results);
100 $template->param(ITEM_DATA => \@items);
101 print "Content-Type: text/html\n\n", $template->output;
102