Add pl-PL to syspref test
[koha.git] / C4 / Print.pm
blob69986dc74078c7a3ddb400fac369250817ffb2e6
1 package C4::Print;
3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
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.
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.
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
20 use strict;
21 use C4::Context;
22 use C4::Circulation;
23 use C4::Members;
24 use C4::Dates qw(format_date);
26 use vars qw($VERSION @ISA @EXPORT);
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);
36 =head1 NAME
38 C4::Print - Koha module dealing with printing
40 =head1 SYNOPSIS
42 use C4::Print;
44 =head1 DESCRIPTION
46 The functions in this module handle sending text to a printer.
48 =head1 FUNCTIONS
50 =over 2
52 =item remoteprint
54 &remoteprint($items, $borrower);
56 Prints the list of items in C<$items> to a printer.
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.
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>.
66 =cut
68 # FIXME - It'd be nifty if this could generate pretty PostScript.
69 sub remoteprint ($$) {
70 my ($items, $borrower) = @_;
72 (return)
73 unless ( C4::Context->boolean_preference('printcirculationslips') );
74 my $queue = '';
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" );
86 else {
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";
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";
109 # FIXME - Use for ($i = 0; $items->[$i]; $i++)
110 # Or better yet, foreach $item (@{$items})
111 while ( $items->[$i] ) {
113 # print $i;
114 my $itemdata = $items->[$i];
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++;
123 print PRINTER "\r\n" x 7 ;
124 close PRINTER;
126 #system("lpr /tmp/$file");
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";
137 else {
138 open( PRINTER, "| lpr -P $printer >/dev/null" )
139 or die "Couldn't write to queue:$!\n";
141 my @da = localtime();
142 my $todaysdate = "$da[2]:$da[1] " . C4::Dates->today();
143 my $slip = <<"EOF";
144 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
145 Date: $todaysdate;
147 ITEM RESERVED:
148 $itemdata->{'title'} ($itemdata->{'author'})
149 barcode: $itemdata->{'barcode'}
151 COLLECT AT: $branchname
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'}
163 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
165 print PRINTER $slip;
166 close PRINTER;
167 return $slip;
170 =item printslip
172 &printslip($borrowernumber)
174 print a slip for the given $borrowernumber
176 =cut
179 sub printslip ($) {
180 my $borrowernumber = shift;
181 my $borrower = GetMemberDetails($borrowernumber);
182 my $issueslist = GetPendingIssues($borrowernumber);
183 foreach my $it (@$issueslist){
184 $it->{'date_due'}=format_date($it->{'date_due'});
186 my @issues = sort { $b->{'timestamp'} <=> $a->{'timestamp'} } @$issueslist;
187 remoteprint(\@issues, $borrower );
190 END { } # module clean-up code here (global destructor)
193 __END__
195 =back
197 =head1 AUTHOR
199 Koha Developement team <info@koha.org>
201 =head1 SEE ALSO
203 C4::Circulation::Circ2(3)
205 =cut