help.pl - bugfix module usage (HTML::Template::Pro)
[koha.git] / C4 / Print.pm
1 package C4::Print;
2
3 # Copyright 2000-2002 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 use strict;
21 use C4::Context;
22 use C4::Circulation;
23 use C4::Members;
24 use C4::Dates qw(format_date);
25
26 use vars qw($VERSION @ISA @EXPORT);
27
28 BEGIN {
29         # set the version for version checking
30         $VERSION = 3.01;
31         require Exporter;
32         @ISA    = qw(Exporter);
33         @EXPORT = qw(&remoteprint &printreserve &printslip);
34 }
35
36 =head1 NAME
37
38 C4::Print - Koha module dealing with printing
39
40 =head1 SYNOPSIS
41
42   use C4::Print;
43
44 =head1 DESCRIPTION
45
46 The functions in this module handle sending text to a printer.
47
48 =head1 FUNCTIONS
49
50 =over 2
51
52 =item remoteprint
53
54   &remoteprint($items, $borrower);
55
56 Prints the list of items in C<$items> to a printer.
57
58 C<$borrower> is a reference-to-hash giving information about a patron.
59 This may be gotten from C<&GetMemberDetails>. The patron's name
60 will be printed in the output.
61
62 C<$items> is a reference-to-list, where each element is a
63 reference-to-hash describing a borrowed item. C<$items> may be gotten
64 from C<&GetBorrowerIssues>.
65
66 =cut
67
68 # FIXME - It'd be nifty if this could generate pretty PostScript.
69 sub remoteprint ($$) {
70     my ($items, $borrower) = @_;
71
72     (return)
73       unless ( C4::Context->boolean_preference('printcirculationslips') );
74     my $queue = '';
75
76     # FIXME - If 'queue' is undefined or empty, then presumably it should
77     # mean "use the default queue", whatever the default is. Presumably
78     # the default depends on the physical location of the machine.
79     # FIXME - Perhaps "print to file" should be a supported option. Just
80     # set the queue to "file" (or " file", if real queues aren't allowed
81     # to have spaces in them). Or perhaps if $queue eq "" and
82     # $env->{file} ne "", then that should mean "print to $env->{file}".
83     if ( $queue eq "" || $queue eq 'nulllp' ) {
84         open( PRINTER, ">/tmp/kohaiss" );
85     }
86     else {
87
88         # FIXME - This assumes that 'lpr' exists, and works as expected.
89         # This is a reasonable assumption, but only because every other
90         # printing package has a wrapper script called 'lpr'. It'd still
91         # be better to be able to customize this.
92         open( PRINTER, "| lpr -P $queue > /dev/null" )
93           or die "Couldn't write to queue:$queue!\n";
94     }
95
96     #  print $queue;
97     #open (FILE,">/tmp/$file");
98     my $i      = 0;
99     # FIXME - This is HLT-specific. Put this stuff in a customizable
100     # site-specific file somewhere.
101     print PRINTER "Horowhenua Library Trust\r\n";
102     print PRINTER "Phone: 368-1953\r\n";
103     print PRINTER "Fax:    367-9218\r\n";
104     print PRINTER "Email:  renewals\@library.org.nz\r\n\r\n\r\n";
105     print PRINTER "$borrower->{'cardnumber'}\r\n";
106     print PRINTER
107       "$borrower->{'title'} $borrower->{'initials'} $borrower->{'surname'}\r\n";
108
109     # FIXME - Use   for ($i = 0; $items->[$i]; $i++)
110     # Or better yet,   foreach $item (@{$items})
111     while ( $items->[$i] ) {
112
113         #    print $i;
114         my $itemdata = $items->[$i];
115
116         # FIXME - This is just begging for a Perl format.
117         print PRINTER "$i $itemdata->{'title'}\r\n";
118         print PRINTER "$itemdata->{'barcode'}";
119         print PRINTER " " x 15;
120         print PRINTER "$itemdata->{'date_due'}\r\n";
121         $i++;
122     }
123     print PRINTER "\r\n" x 7 ;
124     close PRINTER;
125
126     #system("lpr /tmp/$file");
127 }
128
129 sub printreserve {
130     my ( $branchname, $bordata, $itemdata ) = @_;
131     my $printer = '';
132     (return) unless ( C4::Context->boolean_preference('printreserveslips') );
133     if ( $printer eq "" || $printer eq 'nulllp' ) {
134         open( PRINTER, ">>/tmp/kohares" )
135                   or die "Could not write to /tmp/kohares";
136     }
137     else {
138         open( PRINTER, "| lpr -P $printer >/dev/null" )
139           or die "Couldn't write to queue:$!\n";
140     }
141     my @da = localtime();
142     my $todaysdate = "$da[2]:$da[1]  " . C4::Dates->today();
143     my $slip = <<"EOF";
144 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145 Date: $todaysdate;
146
147 ITEM RESERVED: 
148 $itemdata->{'title'} ($itemdata->{'author'})
149 barcode: $itemdata->{'barcode'}
150
151 COLLECT AT: $branchname
152
153 BORROWER:
154 $bordata->{'surname'}, $bordata->{'firstname'}
155 card number: $bordata->{'cardnumber'}
156 Phone: $bordata->{'phone'}
157 $bordata->{'streetaddress'}
158 $bordata->{'suburb'}
159 $bordata->{'town'}
160 $bordata->{'emailaddress'}
161
162
163 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
164 EOF
165     print PRINTER $slip;
166     close PRINTER;
167     return $slip;
168 }
169
170 =item printslip
171
172   &printslip($borrowernumber)
173
174   print a slip for the given $borrowernumber
175   
176 =cut
177
178 #'
179 sub printslip ($) {
180     my ( $borrowernumber ) = shift;
181     my ( $borrower, $flags ) = GetMemberDetails( $borrowernumber);
182         my ($countissues,$issueslist) = GetPendingIssues($borrowernumber); 
183         foreach my $it (@$issueslist){
184                 $it->{'date_due'}=format_date($it->{'date_due'});
185     }           
186     my @issues = sort { $b->{'timestamp'} <=> $a->{'timestamp'} } @$issueslist;
187     remoteprint(\@issues, $borrower );
188 }
189
190 END { }    # module clean-up code here (global destructor)
191
192 1;
193 __END__
194
195 =back
196
197 =head1 AUTHOR
198
199 Koha Developement team <info@koha.org>
200
201 =head1 SEE ALSO
202
203 C4::Circulation::Circ2(3)
204
205 =cut