tidy up by mason.

This commit is contained in:
sushi 2006-07-19 01:09:42 +00:00
parent 7c2b207dd7
commit fd4959b404
6 changed files with 342 additions and 158 deletions

View file

@ -8,6 +8,8 @@ use C4::Interface::CGI::Output;
use C4::Context;
use HTML::Template;
#use Data::Dumper;
my $query = new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
@ -28,26 +30,30 @@ $sth->execute();
my $data = $sth->fetchrow_hashref;
$sth->finish;
# next line passes a var like 'EAN13_cheched' to the tmpl ,
# which makes the barcodetype sticky in the dropbox
$template->param( guidebox => 1 ) if ( $data->{'guidebox'} );
$data->{'printingtype'} = 'both' if ( !$data->{'printingtype'} );
$template->param( "printingtype_$data->{'printingtype'}" => 1 );
$template->param( "$data->{'barcodetype'}_checked" => 1 );
$template->param( "startrow" . $data->{'startrow'} . "_checked" => 1 );
$template->param(
itemtype => $data->{'itemtype'},
papertype => $data->{'papertype'},
author => $data->{'author'},
barcode => $data->{'barcode'},
id => $data->{'id'},
barcodetype => $data->{'barcodetype'},
title => $data->{'title'},
isbn => $data->{'isbn'},
dewey => $data->{'dewey'},
class => $data->{'class'},
startrow => $data->{'startrow'},
itemtype => $data->{'itemtype'},
papertype => $data->{'papertype'},
author => $data->{'author'},
barcode => $data->{'barcode'},
id => $data->{'id'},
barcodetype => $data->{'barcodetype'},
title => $data->{'title'},
isbn => $data->{'isbn'},
dewey => $data->{'dewey'},
class => $data->{'class'},
startrow => $data->{'startrow'},
intranetcolorstylesheet =>
C4::Context->preference("intranetcolorstylesheet"),
intranetstylesheet => C4::Context->preference("intranetstylesheet"),
IntranetNav => C4::Context->preference("IntranetNav"),
);
output_html_with_http_headers $query, $cookie, $template->output;

View file

@ -8,21 +8,25 @@ use C4::Interface::CGI::Output;
use HTML::Template;
use POSIX;
my $dbh = C4::Context->dbh;
my $query = new CGI;
my $op = $query->param('op');
my $barcodetype = $query->param('barcodetype');
my $title = $query->param('title');
my $isbn = $query->param('isbn');
my $itemtype = $query->param('itemtype');
my $bcn = $query->param('bcn');
my $dcn = $query->param('dcn');
my $classif = $query->param('classif');
my $author = $query->param('author');
my $papertype = $query->param('papertype');
my $itemnumber = $query->param('itemnumber');
my $summary = $query->param('summary');
my $startrow = $query->param('startrow');
my $dbh = C4::Context->dbh;
my $query = new CGI;
my $op = $query->param('op');
my $barcodetype = $query->param('barcodetype');
my $title = $query->param('title');
my $isbn = $query->param('isbn');
my $itemtype = $query->param('itemtype');
my $bcn = $query->param('bcn');
my $dcn = $query->param('dcn');
my $classif = $query->param('classif');
my $author = $query->param('author');
my $papertype = $query->param('papertype');
my $itemnumber = $query->param('itemnumber');
my $summary = $query->param('summary');
my $startrow = $query->param('startrow');
my $printingtype = $query->param('printingtype');
my $guidebox = $query->param('guidebox');
warn $printingtype;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
@ -42,12 +46,14 @@ if ( $op eq 'save_conf' ) {
$sth2->finish;
my $query2 = "INSERT INTO labels_conf
( barcodetype, title, isbn, itemtype, barcode,
dewey, class, author, papertype, startrow)
values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
dewey, class, author, papertype, printingtype,
guidebox, startrow)
values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
my $sth2 = $dbh->prepare($query2);
$sth2->execute(
$barcodetype, $title, $isbn, $itemtype, $bcn,
$dcn, $classif, $author, $papertype, $startrow
$barcodetype, $title, $isbn, $itemtype,
$bcn, $dcn, $classif, $author,
$papertype, $printingtype, $guidebox, $startrow
);
$sth2->finish;
@ -65,6 +71,7 @@ elsif ( $op eq 'deleteall' ) {
$sth2->finish;
}
elsif ( $op eq 'delete' ) {
warn "MASON, deleting label..";
my $query2 = "DELETE FROM labels where itemnumber = ?";
my $sth2 = $dbh->prepare($query2);
$sth2->execute($itemnumber);
@ -123,17 +130,17 @@ if ( !$startrow ) {
#calc-ing number of sheets
my $number_of_results = scalar @resultsloop;
my $sheets_needed = ( ( --$number_of_results + $startrow ) / 8 );
$sheets_needed = ceil($sheets_needed); # rounding up int's
$sheets_needed = ceil($sheets_needed); # rounding up int's
my $tot_labels = ($sheets_needed * 8);
my $start_results = ($number_of_results + $startrow);
my $labels_remaining = ($tot_labels - $start_results);
my $tot_labels = ( $sheets_needed * 8 );
my $start_results = ( $number_of_results + $startrow );
my $labels_remaining = ( $tot_labels - $start_results );
$template->param(
resultsloop => \@resultsloop,
startrow => $startrow,
sheets => $sheets_needed,
labels_remaining => $labels_remaining,
resultsloop => \@resultsloop,
startrow => $startrow,
sheets => $sheets_needed,
labels_remaining => $labels_remaining,
intranetcolorstylesheet =>
C4::Context->preference("intranetcolorstylesheet"),

View file

@ -0,0 +1,62 @@
#!/usr/bin/perl
#use lib '/usr/local/opus-dev/intranet/modules';
#use C4::Context("/etc/koha-opus-dev.conf");
use strict;
use CGI;
use C4::Labels;
use C4::Auth;
use C4::Bull;
use C4::Output;
use C4::Interface::CGI::Output;
use C4::Context;
use PDF::Reuse;
use PDF::Reuse::Barcode;
use PDF::Report;
use PDF::Create;
use PDF::Labels;
use Acme::Comment;
use Data::Dumper;
warn "-------";
my $htdocs_path = C4::Context->config('intrahtdocs');
my $cgi = new CGI;
my $pdf = new PDF::Labels(
$PDF::Labels::PageFormats[1],
filename => "$htdocs_path/barcodes/opus.pdf",
Author => 'PDF Labelmaker',
'PageMode' => 'UseOutlines',
Title => 'My Labels'
);
warn "$htdocs_path/barcodes/opus.pdf";
my @resultsloop = get_label_items();
#warn Dumper @resultsloop;
warn Dumper $pdf->{'filename'};
$pdf->setlabel(0); # Start with label 5 on first page
foreach my $result (@resultsloop) {
warn Dumper $result;
$pdf->label( $result->{'itemtype'}, $result->{'number'}, 'LAK',
$result->{'barcode'} );
$pdf->label( $result->{'itemtype'}, $result->{'dewey'}, 'LAK',
$result->{'barcode'} );
}
warn "HERE";
$pdf->close();
#--------------------------------------------------
use PDF::Reuse;
prFile("$htdocs_path/barcodes/opus1.pdf");
prDoc("$htdocs_path/barcodes/opus.pdf");
prEnd();
print $cgi->redirect("/intranet-tmpl/barcodes/opus1.pdf");

View file

@ -11,8 +11,8 @@
# the reason for this goofyness, it that i couldnt find a single perl package that handled both barcodes and decent text placement.
use lib '/usr/local/opus-dev/intranet/modules';
use C4::Context("/etc/koha-opus-dev.conf");
#use lib '/usr/local/hlt/intranet/modules';
#use C4::Context("/etc/koha-hlt.conf");
#use strict;
use CGI;
@ -26,6 +26,7 @@ use HTML::Template;
use PDF::Reuse;
use PDF::Reuse::Barcode;
use PDF::Report;
use Data::Dumper;
#use Acme::Comment;
#use Data::Dumper;
@ -40,8 +41,21 @@ my $spine_text = "";
my $conf_data = get_label_options();
my @resultsloop = get_label_items();
my $barcodetype = $conf_data->{'barcodetype'};
my $startrow = $conf_data->{'startrow'};
warn Dumper $conf_data;
my $barcodetype = $conf_data->{'barcodetype'};
my $printingtype = $conf_data->{'printingtype'};
my $guidebox = $conf_data->{'guidebox'};
my $startrow = $conf_data->{'startrow'};
if (!$printingtype) {
$printingtype = 'both';
}
warn $printingtype;
warn $guidebox;
#warn Dumper @resultsloop;
@ -54,6 +68,9 @@ my $upperRightY = 792;
#----------------------------------
# setting up the pdf doc
#remove the file before write, for testing
unlink "$htdocs_path/barcodes/new.pdf";
prFile("$htdocs_path/barcodes/new.pdf");
prLogDir("$htdocs_path/barcodes");
@ -76,18 +93,18 @@ my $x_pos_circ2 = 369;
my $pageheight = 792;
#warn "STARTROW = $startrow\n";
warn "STARTROW = $startrow\n";
#my $y_pos_initial = ( ( 792 - 36 ) - 90 );
my $y_pos_initial = ( ( $pageheight - $margin ) - $label_height );
my $y_pos_initial_startrow =
( ( $pageheight - $margin ) - ( $label_height * $startrow ) );
my $y_pos_initial = ( ( 792 - 36 ) - 90 );
my $y_pos = $y_pos_initial_startrow;
my $y_pos = $y_pos_initial_startrow;
#warn "Y POS INITAL : $y_pos_initial";
#warn "Y POS : $y_pos";
#warn "Y START ROW = $y_pos_initial_startrow";
warn "Y POS INITAL : $y_pos_initial";
warn "Y POS : $y_pos";
warn "Y START ROW = $y_pos_initial_startrow";
my $rowspace = 36;
my $page_break_count = $startrow;
@ -111,7 +128,7 @@ my $item;
my $i2 = 1;
foreach $item (@resultsloop) {
if ( $i2 == 1 ) {
if ( $i2 == 1 && $guidebox == 1) {
draw_boundaries(
$x_pos_spine, $x_pos_circ1, $x_pos_circ2, $y_pos,
$spine_width, $label_height, $circ_width
@ -127,13 +144,14 @@ foreach $item (@resultsloop) {
$DB::single = 1;
#warn "COUNT=$i2, PBREAKCNT=$page_break_count, X,Y POS x=$x_pos_circ1, y=$y_pos";
warn
"COUNT=$i2, PBREAKCNT=$page_break_count, X,Y POS x=$x_pos_circ1, y=$y_pos";
if ( $printingtype eq 'barcode' || $printingtype eq 'both' ) {
build_circ_barcode( $x_pos_circ1, $y_pos, $item->{'barcode'},
$conf_data->{'barcodetype'}, \$item );
build_circ_barcode( $x_pos_circ2, $y_pos, $item->{'barcode'},
$conf_data->{'barcodetype'}, \$item );
}
# added for xpdf compat. doesnt use type3 fonts., but increases filesize from 20k to 200k
# i think its embedding extra fonts in the pdf file.
# mode => 'graphic',
@ -154,106 +172,118 @@ foreach $item (@resultsloop) {
}
############## end of loop
prEnd();
#----------------------------------------------------------------------------
# this second section of the script uses a diff perl class than the previous section
# it opens the 'new.pdf' file that the previous section has just saved
$file = '/usr/local/opus-dev/intranet/htdocs/intranet-tmpl/barcodes/new.pdf';
if ( $printingtype eq 'spine' || $printingtype eq 'both' ) {
my $pdf = new PDF::Report( File => $file );
$file = "$htdocs_path/barcodes/new.pdf";
# my $pdf = new PDF::Report(PageSize => "letter",
# PageOrientation => "Landscape");
my $pdf = new PDF::Report( File => $file );
#$pdf->newpage($nopage);
my $pagenumber = 1;
$pdf->openpage($pagenumber);
# my $pdf = new PDF::Report(PageSize => "letter",
# PageOrientation => "Landscape");
( $pagewidth, $pageheight ) = $pdf->getPageDimensions();
#warn "PAGE DIM = $pagewidth, $pageheight";
#warn "Y START ROW = $y_pos_initial_startrow";
my $y_pos = ( $y_pos_initial_startrow + 90 );
#$pdf->newpage($nopage);
my $pagenumber = 1;
$pdf->openpage($pagenumber);
#my $y_pos = ( $y_pos_initial_startrow );
#warn "Y POS = $y_pos";
$pdf->setAlign('left');
$pdf->setSize(11);
( $pagewidth, $pageheight ) = $pdf->getPageDimensions();
my $page_break_count = $startrow;
#warn "INIT PAGEBREAK COUNT = $page_break_count";
#warn "PAGE DIM = $pagewidth, $pageheight";
#warn "Y START ROW = $y_pos_initial_startrow";
my $y_pos = ( $y_pos_initial_startrow + 90 );
#warn "#----------------------------------\n";
#warn "INIT VPOS = $vPos, hPos = $hPos";
#my $y_pos = ( $y_pos_initial_startrow );
#warn "Y POS = $y_pos";
my $vPosSpacer = 15;
my $start_text_pos = 39; # ( 36 - 5 = 31 ) 5 is an inside border for text.
my $spine_label_text_with = 67;
# now needed now we are using centerString().
#$pdf->setAlign('left');
# SET THE FONT SIZE
$pdf->setSize(9);
foreach $item (@resultsloop) {
my $page_break_count = $startrow;
#warn Dumper $item;
#warn "START Y_POS=$y_pos";
my $firstrow = 0;
#warn "INIT PAGEBREAK COUNT = $page_break_count";
$pdf->setAddTextPos( $start_text_pos, ( $y_pos - 20 ) ); # INIT START POS
( $hPos, $vPos ) = $pdf->getAddTextPos();
my $hPosEnd = ( $hPos + $spine_label_text_with ); # 72
if ( $conf_data->{'dewey'} && $item->{'dewey'} ) {
( $hPos, $vPos1 ) = $pdf->getAddTextPos();
$pdf->centerString( $hPos, $hPosEnd, $vPos, $item->{'dewey'} );
$vPos = $vPos - $vPosSpacer;
}
if ( $conf_data->{'isbn'} && $item->{'isbn'} ) {
( $hPos, $vPos1 ) = $pdf->getAddTextPos();
$pdf->centerString( $hPos, $hPosEnd, $vPos, $item->{'isbn'} );
$vPos = $vPos - $vPosSpacer;
}
if ( $conf_data->{'class'} && $item->{'classification'} ) {
( $hPos, $vPos1 ) = $pdf->getAddTextPos();
$pdf->centerString( $hPos, $hPosEnd, $vPos, $item->{'classification'} );
$vPos = $vPos - $vPosSpacer;
}
if ( $conf_data->{'itemtype'} && $item->{'itemtype'} ) {
( $hPos, $vPos1 ) = $pdf->getAddTextPos();
$pdf->centerString( $hPos, $hPosEnd, $vPos, $item->{'itemtype'} );
$vPos = $vPos - $vPosSpacer;
}
#$pdf->drawRect(
# $x_pos_spine, $y_pos,
# ( $x_pos_spine + $spine_width ),
# ( $y_pos - $label_height )
#);
$y_pos = ( $y_pos - $label_height );
#warn "END LOOP Y_POS =$y_pos";
# warn "PAGECOUNT END LOOP=$page_break_count";
if ( $page_break_count == 8 ) {
$pagenumber++;
$pdf->openpage($pagenumber);
#warn "############# PAGEBREAK ###########";
$page_break_count = 0;
$i2 = 0;
$y_pos = ( $y_pos_initial + 90 );
}
$page_break_count++;
$i2++;
#warn "#----------------------------------\n";
#warn "INIT VPOS = $vPos, hPos = $hPos";
my $vPosSpacer = 15;
my $start_text_pos = 39; # ( 36 - 5 = 31 ) 5 is an inside border for text.
my $spine_label_text_with = 67;
foreach $item (@resultsloop) {
#warn Dumper $item;
#warn "START Y_POS=$y_pos";
my $firstrow = 0;
$pdf->setAddTextPos( $start_text_pos, ( $y_pos - 20 ) )
; # INIT START POS
( $hPos, $vPos ) = $pdf->getAddTextPos();
my $hPosEnd = ( $hPos + $spine_label_text_with ); # 72
if ( $conf_data->{'dewey'} && $item->{'dewey'} ) {
( $hPos, $vPos1 ) = $pdf->getAddTextPos();
$pdf->centerString( $hPos, $hPosEnd, $vPos, $item->{'dewey'} );
$vPos = $vPos - $vPosSpacer;
}
if ( $conf_data->{'isbn'} && $item->{'isbn'} ) {
( $hPos, $vPos1 ) = $pdf->getAddTextPos();
$pdf->centerString( $hPos, $hPosEnd, $vPos, $item->{'isbn'} );
$vPos = $vPos - $vPosSpacer;
}
if ( $conf_data->{'class'} && $item->{'classification'} ) {
( $hPos, $vPos1 ) = $pdf->getAddTextPos();
$pdf->centerString( $hPos, $hPosEnd, $vPos,
$item->{'classification'} );
$vPos = $vPos - $vPosSpacer;
}
if ( $conf_data->{'itemtype'} && $item->{'itemtype'} ) {
( $hPos, $vPos1 ) = $pdf->getAddTextPos();
$pdf->centerString( $hPos, $hPosEnd, $vPos, $item->{'itemtype'} );
$vPos = $vPos - $vPosSpacer;
}
#$pdf->drawRect(
# $x_pos_spine, $y_pos,
# ( $x_pos_spine + $spine_width ),
# ( $y_pos - $label_height )
#);
$y_pos = ( $y_pos - $label_height );
#warn "END LOOP Y_POS =$y_pos";
# warn "PAGECOUNT END LOOP=$page_break_count";
if ( $page_break_count == 8 ) {
$pagenumber++;
$pdf->openpage($pagenumber);
#warn "############# PAGEBREAK ###########";
$page_break_count = 0;
$i2 = 0;
$y_pos = ( $y_pos_initial + 90 );
}
$page_break_count++;
$i2++;
#warn "#----------------------------------\n";
}
$DB::single = 1;
$pdf->saveAs($file);
}
$DB::single = 1;
$pdf->saveAs($file);
#------------------------------------------------
print $cgi->redirect("/intranet-tmpl/barcodes/new.pdf");

View file

@ -3,14 +3,20 @@
use strict;
use CGI;
use C4::Auth;
use C4::Bull;
use C4::Output;
use C4::Interface::CGI::Output;
use C4::Context;
use HTML::Template;
use GD::Barcode::UPCE;
use Data::Random qw(:all);
my $htdocs_path = C4::Context->config('intrahtdocs');
my $query = new CGI;
use Data::Dumper;
my $query = new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => "barcodes/label-print.tmpl",
@ -26,10 +32,11 @@ my $dbh = C4::Context->dbh;
my $query2 = "SELECT * FROM labels_conf LIMIT 1";
my $sth = $dbh->prepare($query2);
$sth->execute();
my $conf_data = $sth->fetchrow_hashref;
# get barcode type from $conf_data
my $barcodetype = $conf_data->{'barcodetype'};
#warn Dumper $conf_data;
$sth->finish;
my @data;
@ -42,14 +49,16 @@ my $i1 = 1;
while ( my $data = $sth->fetchrow_hashref ) {
# lets get some summary info from each item
my $query1 = "
SELECT * FROM biblio,biblioitems,items WHERE itemnumber=? AND
items.biblioitemnumber=biblioitems.biblioitemnumber AND
select * from biblio,biblioitems,items where itemnumber=? and
items.biblioitemnumber=biblioitems.biblioitemnumber and
biblioitems.biblionumber=biblio.biblionumber";
my $sth1 = $dbh->prepare($query1);
$sth1->execute( $data->{'itemnumber'} );
my $data1 = $sth1->fetchrow_hashref();
push( @resultsloop, $data1 );
$sth1->finish;
@ -57,36 +66,73 @@ while ( my $data = $sth->fetchrow_hashref ) {
}
$sth->finish;
#warn Dumper @resultsloop;
#------------------------------------------------------
#lets write barcode files to tmp dir for every item in @resultsloop
binmode(FILE);
foreach my $item (@resultsloop) {
my $filename = "$htdocs_path/barcodes/$barcodetype-$item->{'barcode'}.png";
open( FILE, ">$filename" );
eval {
print FILE GD::Barcode->new( $barcodetype, $item->{'barcode'} )
->plot->png;
};
if ($@) {
$item->{'barcodeerror'} = 1;
}
close(FILE);
foreach my $item (@resultsloop){
my $random = int( rand(100000000000)) + 999999999999;
#warn "$random\n";
$item->{'barcode'} = $random;
# my $itembarcode = $item->{'barcode'};
# warn $item->{'barcode'};
my $filename = "$htdocs_path/barcodes/$item->{'barcode'}.png";
#warn $filename;
open(FILE, ">$filename");
print FILE GD::Barcode->new('EAN13', $item->{'barcode'})->plot->png;
# warn $GD::Barcode::errStr;
close(FILE);
#warn Dumper $item->{'barcode'};
}
# lets pass the config setting
$template->param(
resultsloop => \@resultsloop,
itemtype_opt => $conf_data->{'itemtype'},
papertype_opt => $conf_data->{'papertype'},
author_opt => $conf_data->{'author'},
id_opt => $conf_data->{'id'},
barcodetype_opt => $conf_data->{'barcodetype'},
title_opt => $conf_data->{'title'},
isbn_opt => $conf_data->{'isbn'},
dewey_opt => $conf_data->{'dewey'},
class_opt => $conf_data->{'class'},
itemtype_opt => $conf_data->{'itemtype'},
papertype_opt => $conf_data->{'papertype'},
author_opt => $conf_data->{'author'},
barcode_opt => $conf_data->{'barcode'},
id_opt => $conf_data->{'id'},
type_opt => $conf_data->{'type'},
title_opt => $conf_data->{'title'},
isbn_opt => $conf_data->{'isbn'},
dewey_opt => $conf_data->{'dewey'},
class_opt => $conf_data->{'class'},
intranetcolorstylesheet =>
C4::Context->preference("intranetcolorstylesheet"),
intranetstylesheet => C4::Context->preference("intranetstylesheet"),
IntranetNav => C4::Context->preference("IntranetNav"),
);
output_html_with_http_headers $query, $cookie, $template->output;

33
barcodes/test.textblock.pl Executable file
View file

@ -0,0 +1,33 @@
#!/usr/bin/perl
use C4::Context;
use PDF::API2;
use PDF::Table;
my $pdftable = new PDF::Table;
my $pdf = PDF::API2->new();
#$pdf->mediabox(612,792);
my $fnt = $pdf->corefont('Helvetica-Bold');
my $page = $pdf->page; # returns the last page
my $txt = $page->text;
$txt->{' font'}=$fnt;
$text_to_place = "moo moo";
($width_of_last_line, $ypos_of_last_line, $left_over_text) =
$pdftable->text_block(
$txt,
$text_to_place,
-x => 100,
-y => 300,
-w => 50,
-h => 40,
# -lead => 13,
# -font_size => 12,
# -parspace => 0,
# -align => "left",
# -hang => 1,
);
$pdf->saveas("$htdocs_path/barcodes/foo.pdf");