#!/usr/bin/perl -w use strict; use PDF::Create; use TrainingBoard::Utilities; use TrainingBoard::PDF; use CGI qw/:standard/; use URI::Escape; print "Content-type: application/pdf\n\n"; # initialise variables and get the submitted venue id and course title: my $dbh= GetDBH; my $Params; my $VenueID = param('ID'); my $Title = ''; if (param('Title')) { $Title = '(Course: ' . uri_unescape(param('Title')) . ')'; } # get the data from db and load into Params my @VenueCols = qw/ VenueName VenueAddress1 VenueAddress2 VenueAddress3 VenuePostTown VenuePostCode VenueTelephone VenueFAX VenueEMail VenueWebSite VenueRating VenueGym VenueSwimmingPool VenueDisabled /; my $sth = $dbh->prepare("SELECT " . join (",", @VenueCols) . " FROM venue WHERE VenueID = ?") or die $dbh->errstr; $sth->execute($VenueID) or die $dbh->errstr; $Params = $sth->fetchrow_hashref; if ($Params->{VenueRating}) { push @{$Params->{Info}}, "$Params->{VenueRating} star rating"; } if ($Params->{VenueDisabled}) { push @{$Params->{Info}}, 'Facilities for disabled people'; } if ($Params->{VenueGym}) { push @{$Params->{Info}}, 'Gym Facilities'; } if ($Params->{VenueSwimmingPool}) { push @{$Params->{Info}}, 'Swimming Pool'; } my @addr = qw/ VenueAddress1 VenueAddress2 VenueAddress3 VenuePostTown VenuePostCode /; for (@addr) { push @{$Params->{Address}}, $Params->{$_} if $Params->{$_}; } $Params->{Title} = $Title; # initialise pdf creation - set up print header, fonts and pdf object, # and set default values for positioning my $pdf = new PDF::Create( 'Version' => 1.2, 'Author' => 'jbr', 'Title' => time, 'fh' => *STDOUT, ); $pdf->{width} = 530; $pdf->{x} = 60; $pdf->{bottom} = 110; $pdf->{gap} = 60; $pdf->{cols} = 2; $pdf->{colnr} = 1; $pdf->{pagenr} = 0; $pdf->{pagearray} = []; my $fn = $pdf->font( 'Subtype' => 'Type1', 'Encoding' => 'WinAnsiEncoding', 'BaseFont' => 'Helvetica' ); my $fb = $pdf->font( 'Subtype' => 'Type1', 'Encoding' => 'WinAnsiEncoding', 'BaseFont' => 'Helvetica-Bold' ); my $fo = $pdf->font( 'Subtype' => 'Type1', 'Encoding' => 'WinAnsiEncoding', 'BaseFont' => 'Helvetica-Oblique' ); $pdf->{pagearray}->[$pdf->{pagenr}] = $pdf->new_page('MediaBox' => [ 0, 0, 650, 920 ]); # get height of header based on height of text in course title and # course provider name, and initialise top of print-out my $h = GetHeight($pdf,"$Params->{VenuePostTown} Venue",250,$fb,20,30); $h += GetHeight($pdf,$Params->{Title},250,$fo,20,30); $h += 10; $pdf->{top} = 840 - $h, $pdf->{y} = 825 - $h, # insert info AddBreak($pdf,11,8,0); AddLine($pdf,["Venue Information"],[$fb],12); AddBreak($pdf,11,8,0); AddBreak($pdf,11,8,1); AddBreak($pdf,11,8,0); AddGenInfo( $pdf, $fn, $fo, 'Venue:', $Params->{VenueName} ); AddBreak($pdf,11,8,1); AddBreak($pdf,11,8,0); my $addr = 'Address:'; for (@{$Params->{Address}}) { AddGenInfo( $pdf, $fn, $fo, $addr, $_ ); $addr = ''; } if ($Params->{VenueTelephone}) { AddBreak($pdf,11,8,1); AddBreak($pdf,11,8,0); AddGenInfo( $pdf, $fn, $fo, 'Tel No:', $Params->{VenueTelephone} ) } if ($Params->{VenueFAX}) { AddBreak($pdf,11,8,1); AddBreak($pdf,11,8,0); AddGenInfo( $pdf, $fn, $fo, 'Fax No:', $Params->{VenueFAX} ) } if ($Params->{VenueEMail}) { AddBreak($pdf,11,8,1); AddBreak($pdf,11,8,0); AddGenInfo( $pdf, $fn, $fo, 'EMail:', $Params->{VenueEMail} ) } if ($Params->{VenueWebSite}) { AddBreak($pdf,11,8,1); AddBreak($pdf,11,8,0); AddGenInfo( $pdf, $fn, $fo, 'Website:', $Params->{VenueWebSite} ) } if ($Params->{Info}) { AddBreak($pdf,11,8,1); AddBreak($pdf,11,8,0); AddLine($pdf,["Other Facilities:"],[$fb],10); for (@{$Params->{Info}}) { $pdf->{pagearray}->[$pdf->{pagenr}]->string($fb,20,$pdf->{x},$pdf->{y} - 4,'·'); $pdf->{x} += 10; AddLine($pdf,[$_],[$fn],10,15); $pdf->{x} -= 10; } } AddBreak($pdf,22,15,0); AddBreak($pdf,11,8,1); # add headers and footers: my $tl = scalar @{$pdf->{pagearray}}; my $no = $tl; for (reverse @{$pdf->{pagearray}}) { # I simply don't know why it has to be done backwards, or how I # get away without changing the page number. Maybe I shd # try and figure this out later on. $_->string($fo,14,60,860,'allmytraining.com'); $_->stringr($fo,14,590,860,'venue info sheet'); $_->line(60,850,590,850); $pdf->{y} = 825; $pdf->{x} = 60; $pdf->{cols} = 1; AddLine($pdf,["$Params->{VenuePostTown} Venue"],[$fb],20); AddLine($pdf,[$Params->{Title}],[$fo],20); $_->line(60,$pdf->{y}+18,590,$pdf->{y}+18); $_->line(60,80,590,80); $_->stringr($fn,10,590,50,"Page $no of $tl"); $no --; } $pdf->close;