* Copyright (C) 2010 David Grant * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation, version 2. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ ?> prepare("SELECT registrations.id AS regid, students.id AS studentid, students.firstname \t \t\t\tFROM registrations,students \t \t\tWHERE students.email=? AND registrations.num=? AND registrations.id=? AND students.registrations_id=registrations.id AND registrations.year=? AND students.year=?"); '?=?' ; $registration_id = $_SESSION['registration_id']; $q->execute([$_SESSION['email'],$_SESSION['registration_number'],$_SESSION['registration_id'],$config['FAIRYEAR'], $config['FAIRYEAR'],$registration_number,$_SESSION['registration_number']]); show_pdo_errors_if_any($pdo); if ($q->rowCount() == 0) { header('Location: register_participants.php'); exit; } $authinfo = $q->fetch(PDO::FETCH_OBJ); } // END OF AUTH, now lets try to generate a PDF using only PHP :) this should be fun! $pdf = new pdf("Participant Signature Page ($registration_number)"); $pdf->setFontSize(11); $pdf->SetFont('times'); $height_sigspace = 15; // mm $height_sigfont = $pdf->GetFontSize(); // mm $pdf->AddPage(); if ($_GET['sample']) { $projectinfo->title = 'Sample Project Title'; $projectinfo->division = 'Proj Division'; $projectinfo->category = 'Proj Category'; $studentinfo->firstname = 'SampleFirst'; $studentinfo->lastname = 'SampleLast'; $studentinfo->grade = '10'; $studentinfoarray[] = $studentinfo; $rr->school = 'SampleSchool'; } else { // grab the project info $q = $pdo->prepare("SELECT projects.*, projectcategories.category, projectdivisions.division FROM projects JOIN projectdivisions ON projects.projectdivisions_id=projectdivisions.id JOIN projectcategories ON projects.projectcategories_id=projectcategories.id WHERE registrations_id=? AND projects.year=? AND projectdivisions.year=? AND projectcategories.year=? "); $q->execute([$_SESSION['registration_id'],$config['FAIRYEAR'],$config['FAIRYEAR'],$config['FAIRYEAR']]); $projectinfo = $q->fetch(PDO::FETCH_OBJ); $q = $pdo->prepare("SELECT * FROM students WHERE registrations_id=? AND year=?"); $q->execute([$_SESSION['registration_id'], $config['FAIRYEAR']]); while ($si = $q->fetch(PDO::FETCH_OBJ)) $studentinfoarray[] = $si; } $plural = (count($studentinfoarray) > 1) ? 's' : ''; $pdf->WriteHTML('

' . i18n('Registration Summary') . '

' . i18n('Registration Number') . ": $registration_number
" . i18n('Project Title') . ": {$projectinfo->title}
" . i18n($projectinfo->category) . ' / ' . i18n($projectinfo->division)); $students = ''; foreach ($studentinfoarray AS $studentinfo) { if (!$_GET['sample']) { $qq = $pdo->prepare("SELECT school FROM schools WHERE id=?"); $qq->execute([$studentinfo->schools_id]); $rr = $qq->fetch(PDO::FETCH_OBJ); } if ($students != '') $students .= '
'; $students .= "{$studentinfo->firstname} {$studentinfo->lastname}, Grade {$studentinfo->grade}, {$rr->school}"; } $e = i18n("Exhibitor$plural") . ':'; $w = $pdf->GetStringWidth($e) + 2; $pdf->WriteHTML("
$e$students
"); $pdf->WriteHTML('


'); function sig($pdf, $text) { global $height_sigspace, $height_font; $x = $pdf->GetX(); /* * One cell for the whole thing, to force a page break if needed, leave * the current pos to the right so the Y is unchanged */ $pdf->Cell(0, $height_sigspace + $height_font, '', 0, 0); /* Restore X, and indent a bit, move Y down the signature space */ $pdf->SetXY($x + 15, $pdf->GetY() + $height_sigspace); /* Box with a top line, then a space, then a box with a top line for the date */ $pdf->Cell(85, $height_font, $text, 'T', 0, 'C'); $pdf->SetX($pdf->GetX() + 15); $pdf->Cell(60, $height_font, i18n('Date'), 'T', 1, 'C'); } $q = $pdo->prepare("SELECT * FROM signaturepage WHERE name='exhibitordeclaration'"); $q->execute(); $r = $q->fetch(PDO::FETCH_ASSOC); if ($r['use']) { $t = nl2br($r['text']); $pdf->WriteHTML('

' . i18n('Exhibitor Declaration') . "

$t"); foreach ($studentinfoarray AS $studentinfo) { sig($pdf, i18n('%1 %2 (signature)', array($studentinfo->firstname, $studentinfo->lastname))); } $pdf->WriteHTML('

'); } $q = $pdo->prepare("SELECT * FROM signaturepage WHERE name='parentdeclaration'"); $q->execute(); $r = $q->fetch(PDO::FETCH_ASSOC); if ($r['use']) { $t = nl2br($r['text']); $pdf->WriteHTML('

' . i18n('Parent/Guardian Declaration') . "

$t"); foreach ($studentinfoarray AS $studentinfo) { sig($pdf, i18n('Parent/Guardian of %1 %2 (signature)', array($studentinfo->firstname, $studentinfo->lastname))); } $pdf->WriteHTML('

'); } $q = $pdo->prepare("SELECT * FROM signaturepage WHERE name='teacherdeclaration'"); $q->execute(); $r = $q->fetch(PDO::FETCH_ASSOC); if ($r['use']) { $t = nl2br($r['text']); $pdf->WriteHTML('

' . i18n('Teacher Declaration') . "

$t"); sig($pdf, i18n('Teacher Signature')); $pdf->WriteHTML('

'); } $q = $pdo->prepare("SELECT * FROM signaturepage WHERE name='regfee'"); $q->execute(); $r = $q->fetch(PDO::FETCH_ASSOC); if ($r['use']) { $pdf->WriteHTML('

' . i18n('Registration Fee Summary') . '


'); list($regfee, $rfeedata) = computeRegistrationFee($registration_id); $x = $pdf->GetX() + 20; $pdf->SetX($x); $pdf->Cell(60, 0, i18n('Item'), 'B', 0, 'C'); $pdf->Cell(15, 0, i18n('Unit'), 'B', 0, 'C'); $pdf->Cell(10, 0, i18n('Qty'), 'B', 0, 'C'); $pdf->Cell(20, 0, i18n('Extended'), 'B', 1, 'C'); foreach ($rfeedata as $rf) { $u = '$' . sprintf('%.02f', $rf['base']); $e = '$' . sprintf('%.02f', $rf['ext']); $pdf->SetX($x); $pdf->Cell(60, 0, $rf['text'], 0, 0, 'L'); $pdf->Cell(15, 0, $u, 0, 0, 'R'); $pdf->Cell(10, 0, $rf['num'], 0, 0, 'C'); $pdf->Cell(20, 0, $e, 0, 1, 'R'); } $t = '$' . sprintf('%.02f', $regfee); $pdf->SetX($x); $pdf->Cell(85, 0, i18n('Total (including all taxes)'), 'T', 0, 'R'); $pdf->Cell(20, 0, $t, 'T', 1, 'R'); $pdf->WriteHTML('

'); } $q = $pdo->prepare("SELECT * FROM signaturepage WHERE name='postamble'"); $q->execute(); $r = $q->fetch(PDO::FETCH_ASSOC); if ($r['use']) { $t = nl2br($r['text']); $pdf->WriteHTML('

' . i18n('Additional Information') . "

$t"); $pdf->WriteHTML('

'); } echo $pdf->output(); ?>