Added POD.
[koha.git] / C4 / Print.pm
1 package C4::Print; #assumes C4/Print.pm
2
3
4 # Copyright 2000-2002 Katipo Communications
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 with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA  02111-1307 USA
20
21 use strict;
22 require Exporter;
23 #use C4::InterfaceCDK;
24
25 use vars qw($VERSION @ISA @EXPORT);
26
27 # set the version for version checking
28 $VERSION = 0.01;
29
30 =head1 NAME
31
32 C4::Print - FIXME
33
34 =head1 SYNOPSIS
35
36   use C4::Print;
37
38 =head1 DESCRIPTION
39
40 FIXME
41
42 =head1 FUNCTIONS
43
44 =over 2
45
46 =cut
47
48 @ISA = qw(Exporter);
49 @EXPORT = qw(&remoteprint &printslip);
50
51 =item remoteprint
52
53   &remoteprint($env, $items, $borrower);
54
55 Prints the list of items in C<$items> to a printer.
56
57 C<$env> is a reference-to-hash. C<$env-E<gt>{queue}> specifies the
58 queue to print to; if it is empty or has the special value C<nulllp>,
59 C<&remoteprint> will print to the file F</tmp/kohaiss>.
60
61 C<$borrower> is a reference-to-hash giving information about a patron.
62 This may be gotten from C<&getpatroninformation>. The patron's name
63 will be printed in the output.
64
65 C<$items> is a reference-to-list, where each element is a
66 reference-to-hash describing a borrowed item. C<$items> may be gotten
67 from C<&currentissues>.
68
69 =cut
70 #'
71 # FIXME - It'd be nifty if this could generate pretty PostScript.
72 sub remoteprint {
73   my ($env,$items,$borrower)=@_;
74   #open (FILE,">/tmp/olwen");
75   #print FILE "queue $env->{'queue'}";
76   #close FILE;
77   #debug_msg($env,"In print");
78   my $file=time;                # FIXME - Not used
79   my $queue = $env->{'queue'};
80   # FIXME - If 'queue' is undefined or empty, then presumably it should
81   # mean "use the default queue", whatever the default is. Presumably
82   # the default depends on the physical location of the machine.
83   # FIXME - Perhaps "print to file" should be a supported option. Just
84   # set the queue to "file" (or " file", if real queues aren't allowed
85   # to have spaces in them). Or perhaps if $queue eq "" and
86   # $env->{file} ne "", then that should mean "print to $env->{file}".
87   if ($queue eq "" || $queue eq 'nulllp') {
88     open (PRINTER,">/tmp/kohaiss");
89   } else {
90     # FIXME - This assumes that 'lpr' exists, and works as expected.
91     # This is a reasonable assumption, but only because every other
92     # printing package has a wrapper script called 'lpr'. It'd still
93     # be better to be able to customize this.
94     open(PRINTER, "| lpr -P $queue") or die "Couldn't write to queue:$queue!\n";
95   }
96 #  print $queue;
97   #open (FILE,">/tmp/$file");
98   my $i=0;
99   my $brdata = $env->{'brdata'};        # FIXME - Not used
100   # FIXME - This is HLT-specific. Put this stuff in a customizable
101   # site-specific file somewhere.
102   print PRINTER "Horowhenua Library Trust\r\n";
103 #  print PRINTER "$brdata->{'branchname'}\r\n";
104   print PRINTER "Phone: 368-1953\r\n";
105   print PRINTER "Fax:    367-9218\r\n";
106   print PRINTER "Email:  renewals\@library.org.nz\r\n\r\n\r\n";
107   print PRINTER "$borrower->{'cardnumber'}\r\n";
108   print PRINTER "$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]){
112 #    print $i;
113     my $itemdata = $items->[$i];
114     # FIXME - This is just begging for a Perl format.
115     print PRINTER "$i $itemdata->{'title'}\r\n";
116     print PRINTER "$itemdata->{'barcode'}";
117     print PRINTER " "x15;
118     print PRINTER "$itemdata->{'date_due'}\r\n";
119     $i++;
120   }
121   print PRINTER "\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
122   if ($env->{'printtype'} eq "docket"){
123     #print chr(27).chr(105);
124   }
125   close PRINTER;
126   #system("lpr /tmp/$file");
127 }
128
129 =item printslip
130
131   &printslip($env, $text)
132
133 Prints the string C<$text> to a printer. C<$env-E<gt>{queue}>
134 specifies the queue to print to.
135
136 If C<$env-E<gt>{queue}> is empty or set to C<nulllp>, C<&printslip>
137 will print to the file F</tmp/kohares>.
138
139 =cut
140 #'
141 sub printslip {
142   my($env, $slip)=@_;
143   my $printer = $env->{'printer'};
144   if ($printer eq "" || $printer eq 'nulllp') {
145     open (PRINTER,">/tmp/kohares");
146   } else {
147     open (PRINTER, "| lpr -P $printer") or die "Couldn't write to queue:$!\n";
148   }
149   print PRINTER $slip;
150   close PRINTER;
151 }
152
153 END { }       # module clean-up code here (global destructor)
154
155 1;
156 __END__
157
158 =back
159
160 =head1 AUTHOR
161
162 Koha Developement team <info@koha.org>
163
164 =head1 SEE ALSO
165
166 L<perl>.
167
168 L<C4::Circulation::Circ2(3)>
169
170 =cut