Cert ID | */ ?>Date | /*Expiry | */ ?>Name | /*Course | Instructor | Issued | */ ?>Actions | “.$certid.” | “.date(“j/n/y”,strtotime($certdate)).” | “.date(“j/n/y”,strtotime($certexp)).” | “.$certname.” | “.$certcourse.” | “.$certinst.” | “.date(“j/n/y”,strtotime($certissued)).” | “; if ((!isset($filterdate)) || ($filterdate == $certdate)) { echo “
---|---|---|---|---|---|---|---|
“.date(“j/n/y”,strtotime($certdate)).” | “.$certname.” | “; ?>
SetAuthor(“fpdf”);
$pdf->SetTitle(“Clarke H&S Certificate”);
// Add custom font
// Read: http://www.fpdf.org/en/tutorial/tuto7.htm for more info
//$pdf->AddFont(“Trebuchet”);
//$pdf->SetFont(“Trebuchet”, “”, 16);
$pdf->SetFont(“Times”, “”, 20);
// Set line drawing defaults
$pdf->SetDrawColor(224);
$pdf->SetLineWidth(1);
// Load the base PDF into template
$pdf->setSourceFile(“template.pdf”);
$tplidx = $pdf->ImportPage(1);
// Add new page & use the base PDF as template
$pdf->AddPage();
$pdf->useTemplate($tplidx);
$pdf->SetXY(39,93);
$pdf->Cell(128, 12, $certdata[‘name’], 0,0,”C”);
$pdf->SetXY(63,120);
$pdf->Cell(80, 12, date(“jS F Y”,strtotime($certdata[‘date’])), 0,0,”C”);
$pdf->SetXY(39,148);
$pdf->Cell(128, 12, $certdata[‘course’], 0,0,”C”);
$pdf->SetXY(59,176);
$pdf->Cell(88, 12, date(“jS F Y”,strtotime($certdata[‘exp’])), 0,0,”C”);
$pdf->SetXY(31,206);
$pdf->Cell(144, 12, $certdata[‘inst’], 0,0,”C”);
$pdf->SetXY(31,231);
$pdf->Cell(65, 12, date(“j/m/Y”,strtotime($certdata[‘issued’])), 0,0,”C”);
$pdf->SetXY(109,231);
$pdf->Cell(65, 12, $certdata[‘id’], 0,0,”C”);
//$dest=”S”; // I inline D dowload S string
$filename = $certdata[‘id’].” “.$certdata[‘name’].”.pdf”;
return($pdf->Output($dest, $filename));
}
// Main
if (isset($_GET[‘action’])) {
$action = $_GET[‘action’];
} else {
$action = ‘default’;
}
if ($action==”fixcsv”) {
echo ‘Checking CSV for date errors…’;
fix_dates_in_CSV();
die(‘File updated.’);
}
if ($action == ‘addcert’) { // Add new cert
$cert_data = get_certdata();
$action = ‘new’; // show form again
}
if ($action==’genpdf’) { // Are we making a PDF now otherwise we’re showing the interface
// Ok lets generate the certificate now
$cert_data = get_certdata();
$cert = make_cert($cert_data);
}
if ($action==’genzip’) { // Are we getting a zip of PDF files?
if (isset($_GET[‘date’])) {
$filterdate = $_GET[‘date’];
} else {
die(‘Invalid filter date!’);
}
$certfile = fopen(“certs.csv”, “r”) or die(“Unable to open file!”);
$zip = new ZipArchive;
$res = $zip->open($zipfile, ZipArchive::OVERWRITE);
if ($res === TRUE) { // zip opened?
$i = 0;
$certs = array();
while (!feof($certfile)) {
$certdata = fgetcsv($certfile);
//var_dump($certdata);
if (($certdata[0] == “ID”) || ($certdata[0] == “”)) continue;
$cert_data[‘id’] = $certdata[0];
$cert_data[‘date’] = $certdata[1];
$cert_data[‘exp’] = $certdata[2];
$cert_data[‘name’] = $certdata[3];
$cert_data[‘course’] = $certdata[4];
$cert_data[‘inst’] = $certdata[5];
$cert_data[‘issued’] = $certdata[6];
if ($filterdate == $cert_data[‘date’]) $certs[$cert_data[‘id’].” “.$cert_data[‘name’].”.pdf”] = make_cert($cert_data,”S”);
}
if (count($certs) > 0) {
foreach ($certs as $filename => $filestring) {
$zip->addFromString($filename, $filestring);
}
$zip->close();
echo ‘Zipfile created – Download‘;
} else {
die(‘No certficates found!’);
}
} else {
die(‘Failed to create zip file!’);
}
exit;
}
// Interface
?>
Clarke Health and Safety – Certificate System
Download all as Zip Archive‘;
}
if ($dateerrors === TRUE) {
echo ‘
‘;
case “maintenance”: // Database maintenance menu
?>