adding a warn to log why we're redirecting to installer
[koha.git] / barcodes / label-print-opus-pdf.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18 use strict;
19 use CGI;
20 use C4::Labels;
21 use C4::Auth;
22 use C4::Output;
23 use C4::Context;
24 use PDF::Reuse;
25 use PDF::Reuse::Barcode;
26 use POSIX;
27 use Text::Wrap;
28
29
30 $Text::Wrap::columns   = 39;
31 $Text::Wrap::separator = "\n";
32
33 my $htdocs_path = C4::Context->config('intrahtdocs');
34 my $cgi         = new CGI;
35 my $spine_text  = "";
36
37 # get the printing settings
38 my $conf_data    = get_label_options();
39 my @resultsloop  = get_label_items();
40 my $barcodetype  = $conf_data->{'barcodetype'};
41 my $printingtype = $conf_data->{'printingtype'};
42 my $guidebox     = $conf_data->{'guidebox'};
43 my $startrow     = $conf_data->{'startrow'};
44
45 # if none selected, then choose 'both'
46 if ( !$printingtype ) {
47     $printingtype = 'both';
48 }
49
50 # opus paper dims. in *millimeters*
51 # multiply values by '2.83465', to find their value in Postscript points.
52
53 # $xmargin           = 12;
54 # $label_height     = 34;
55 # $label_width      = 74;
56 # $x_pos_spine      = 12;
57 # $pageheight       = 304;
58 # $pagewidth       = 174;
59 # $line_spacer      = 10;
60 # $label_rows       = 8;
61
62 # sheet dimensions in PS points.
63
64 my $top_margin       = 7;
65 my $left_margin      = 34;
66 my $top_text_margin  = 20;
67 my $left_text_margin = 10;
68 my $label_height     = 96;
69 my $spine_width      = 210;
70 my $colspace         = 9;
71 my $rowspace         = 11;
72 my $x_pos_spine      = 36;
73 my $pageheight       = 861;
74 my $pagewidth        = 493;
75 my $line_spacer      = 10;
76 my $label_rows       = 8;
77
78 # setting up the pdf doc
79 #remove the file before write, for testing
80 #unlink "$htdocs_path/barcodes/new.pdf";
81 #prFile("$htdocs_path/barcodes/new.pdf");
82 #prLogDir("$htdocs_path/barcodes");
83
84 # fix, no longer writes to temp dir
85 prInitVars();    # To initiate ALL global variables and tables
86 $| = 1;
87 print STDOUT "Content-Type: application/pdf \n\n";
88 prFile();
89
90 prMbox( 0, 0, $pagewidth, $pageheight );
91 prFont('courier');    # Just setting a font
92 prFontSize(9);
93
94 my $str;
95
96 my $y_pos_initial = ( ( $pageheight - $top_margin ) - $label_height );
97 my $y_pos_initial_startrow =
98   ( ( $pageheight - $top_margin ) - ( $label_height * $startrow ) );
99 my $y_pos = $y_pos_initial_startrow;
100
101 my $page_break_count = $startrow;
102 my $codetype         = 'Code39';
103
104 #do page border
105 # commented out coz it was running into the side-feeds of the paper.
106 # drawbox( 0, 0 , $pagewidth, $pageheight );
107
108 my $item;
109
110 # for loop
111 my $i2 = 1;
112
113 foreach $item (@resultsloop) {
114     my $x_pos_spine_tmp = $x_pos_spine;
115
116     for ( 1 .. 2 ) {
117
118         if ( $guidebox == 1 ) {
119             warn
120 "COUNT1, PBREAKCNT=$page_break_count,  y=$y_pos, labhght = $label_height";
121             drawbox( $x_pos_spine_tmp, $y_pos, $spine_width, $label_height );
122         }
123
124         #-----------------draw spine text
125         if ( $printingtype eq 'spine' || $printingtype eq 'both' ) {
126
127             #warn "PRINTTYPE = $printingtype";
128
129             # add your printable fields manually in here
130             my @fields = qw (itemtype dewey isbn classification);
131             my $vPos   = ( $y_pos + ( $label_height - $top_text_margin ) );
132             my $hPos   = ( $x_pos_spine_tmp + $left_text_margin );
133             foreach my $field (@fields) {
134
135                # if the display option for this field is selected in the DB,
136                # and the item record has some values for this field, display it.
137                 if ( $conf_data->{"$field"} && $item->{"$field"} ) {
138
139                     #warn "CONF_TYPE = $field";
140
141                     # get the string
142                     $str = $item->{"$field"};
143
144                     # strip out naughty existing nl/cr's
145                     $str =~ s/\n//g;
146                     $str =~ s/\r//g;
147
148                     # chop the string up into _upto_ 12 chunks
149                     # and seperate the chunks with newlines
150
151                     $str = wrap( "", "", "$str" );
152                     $str = wrap( "", "", "$str" );
153
154                     # split the chunks between newline's, into an array
155                     my @strings = split /\n/, $str;
156
157                     # then loop for each string line
158                     foreach my $str (@strings) {
159
160                         warn "HPOS ,  VPOS $hPos, $vPos ";
161                         prText( $hPos, $vPos, $str );
162                         $vPos = $vPos - $line_spacer;
163                     }
164                 }    # if field is valid
165             }    # foreach   @field
166         }    #if spine
167
168         $x_pos_spine_tmp = ( $x_pos_spine_tmp + $spine_width + $colspace );
169     }    # for 1 ..2
170     warn " $y_pos - $label_height - $rowspace";
171     $y_pos = ( $y_pos - $label_height - $rowspace );
172     warn " $y_pos - $label_height - $rowspace";
173
174     #-----------------draw spine text
175
176     # the gaylord labels have 8 rows per sheet, this pagebreaks after 8 rows
177     if ( $page_break_count == $label_rows ) {
178         prPage();
179         $page_break_count = 0;
180         $i2               = 0;
181         $y_pos            = $y_pos_initial;
182     }
183     $page_break_count++;
184     $i2++;
185 }
186 prEnd();
187
188 #print $cgi->redirect("/intranet-tmpl/barcodes/new.pdf");
189