فهرست منبع

Add support for template processing files

Alan Lam 8 سال پیش
والد
کامیت
948177eb74

+ 0 - 94
controllers/project_csv.php

@@ -33,100 +33,6 @@ $testers = User::load(array_column($tests, "tester_id"));
 
 $handle = fopen("php://output", "w");
 
-$field_names = [
-	"Project ID", "Project Name",
-	"Template Name",
-	"Test ID", "Test Status", "Test Result",
-	"Location Name", "Legal Entity", "Address", "Email", "Phone", "Region", "Internal ID", "Area Manager",
-	"Tester Age", "Tester Gender", "Travel Costs",
-
-	"Date", "Start Time", "End Time", "Duration",
-];
-
-foreach($fields as $field) {
-	$field_names[] = $field->label;
-}
-
-fputcsv($handle, $field_names);
-
-foreach($tests as $test) {
-
-	$location = $test->getLocation();
-	$tester = $test->getTester();
-	$values = $test->getValues(true);
-
-	$test_date = "";
-	$test_start = "";
-	$test_end = "";
-	$test_duration = "";
-
-	$result = "Pending";
-
-	$age = "";
-	$gender = "";
-	$travel_costs = "";
-
-	$output = [];
-	$output[] = $id;
-	$output[] = $project->name;
-	$output[] = $template->name;
-	$output[] = $test->id;
-	$output[] = $test->getStatusText();
-
-	if(!is_null($test->pass)) {
-
-		$result = $test->pass ? "Pass" : "Fail";
-
-		$test_start_dt = new DateTime($test->dts_start);
-		$test_end_dt = new DateTime($test->dts_end);
-		$test_duration_diff = $test_start_dt->diff($test_end_dt, true);
-
-		$test_date = $test_start_dt->format("d/m/Y");
-		$test_start = $test_start_dt->format("H:i:s");
-		$test_end = $test_end_dt->format("H:i:s");
-		$test_duration = $test_duration_diff->h . ":" . $test_duration_diff->i . ":" . $test_duration_diff->s;
-
-		if($tester) {
-			$tester_dob_dt = new DateTime($tester->date_of_birth);
-			$dob_diff = $test_start_dt->diff($tester_dob_dt, true);
-			$age = $dob_diff->y;
-			$gender = $tester->gender;
-			$travel_costs = $test->test_travel_costs;
-		}
-	}
-
-
-	$output[] = $result;
-	$output[] = $location->name;
-	$output[] = $location->legal_entity_name;
-	$output[] = $location->getDisplayAddress();
-	$output[] = $location->email;
-	$output[] = $location->phone;
-	$output[] = $location->region;
-	$output[] = $location->internal_id;
-	$output[] = $location->area_manager;
-	$output[] = $age;
-	$output[] = $gender;
-	$output[] = $travel_costs;
-	$output[] = $test_date;
-	$output[] = $test_start;
-	$output[] = $test_end;
-	$output[] = $test_duration;
-
-	foreach($fields as $field) {
-		$field_name = $field->name;
-		$value = isset($test->$field_name) ? $test->$field_name : ($values[$field->name] ?? "");
-
-		if(!empty($field->displayStrings)) {
-			$index = array_search($value, $field->values);
-			$value = $field->displayStrings[$index];
-		}
-
-		$output[] = $value;
-	}
-
-	fputcsv($handle, $output);
-}
 
 fclose($handle);
 

+ 2 - 79
controllers/project_customer_csv.php

@@ -10,6 +10,7 @@ header("Cache-Control: private, max-age=0, must-revalidate");
 header("Pragma: public");
 
 $template = $project->getTemplate();
+$processing_file_path = $template->getProcessingFilePath("project_customer_csv.php");
 
 $object = json_decode($template->json);
 
@@ -33,85 +34,7 @@ $testers = User::load(array_column($tests, "tester_id"));
 
 $handle = fopen("php://output", "w");
 
-$field_names = [
-	"Project Name",
-	"Test Status", "Test Result",
-	"Location Name", "Address", "Region", "Internal ID", "Area Manager",
-
-	"Date",
-];
-
-foreach($fields as $field) {
-	$field_names[] = $field->label;
-}
-
-fputcsv($handle, $field_names);
-
-foreach($tests as $test) {
-
-	$location = $test->getLocation();
-	$tester = $test->getTester();
-	$values = $test->getValues(true);
-
-	$test_date = "";
-	$test_start = "";
-	$test_end = "";
-	$test_duration = "";
-
-	$result = "Pending";
-
-	$age = "";
-	$gender = "";
-	$travel_costs = "";
-
-	$output = [];
-	$output[] = $project->name;
-	$output[] = $test->getStatusText();
-
-	if(!is_null($test->pass)) {
-
-		$result = $test->pass ? "Pass" : "Fail";
-
-		$test_start_dt = new DateTime($test->dts_start);
-		$test_end_dt = new DateTime($test->dts_end);
-		$test_duration_diff = $test_start_dt->diff($test_end_dt, true);
-
-		$test_date = $test_start_dt->format("d/m/Y");
-		$test_start = $test_start_dt->format("H:i:s");
-		$test_end = $test_end_dt->format("H:i:s");
-		$test_duration = $test_duration_diff->h . ":" . $test_duration_diff->i . ":" . $test_duration_diff->s;
-
-		if($tester) {
-			$tester_dob_dt = new DateTime($tester->date_of_birth);
-			$dob_diff = $test_start_dt->diff($tester_dob_dt, true);
-			$age = $dob_diff->y;
-			$gender = $tester->gender;
-			$travel_costs = $test->test_travel_costs;
-		}
-	}
-
-	$output[] = $result;
-	$output[] = $location->name;
-	$output[] = $location->getDisplayAddress();
-	$output[] = $location->region;
-	$output[] = $location->internal_id;
-	$output[] = $location->area_manager;
-	$output[] = $test_date;
-
-	foreach($fields as $field) {
-		$field_name = $field->name;
-		$value = isset($test->$field_name) ? $test->$field_name : ($values[$field->name] ?? "");
-
-		if(!empty($field->displayStrings)) {
-			$index = array_search($value, $field->values);
-			$value = $field->displayStrings[$index];
-		}
-
-		$output[] = $value;
-	}
-
-	fputcsv($handle, $output);
-}
+require $processing_file_path;
 
 fclose($handle);
 

+ 12 - 298
controllers/test_pdf.php

@@ -5,6 +5,9 @@
 $test = Test::get($id);
 if(!$test) throw new Exception("Test not found.");
 
+$project = $test->getProject();
+$template = $project->getTemplate();
+
 if(!isset($output)) $output = true;
 
 $location = $test->getLocation();
@@ -42,7 +45,15 @@ $diff = $dt_start->diff($dt_end, true);
 
 $date_start = date("d/m/Y", strtotime($test->dts_start . " UTC"));
 
+$location_text = " $location->name";
+if($location->internal_id) {
+	$location_text .= " (ID: $location->internal_id)";
+}
+
+$template_processing_file_path = $template->getProcessingFilePath("test_pdf.php");
+
 // A4 size: 210x297mm
+// Start PDF Building
 
 $pdf = new TestPDF("P", "mm", "A4");
 
@@ -86,305 +97,8 @@ $pdf->Cell(80, 4, "info@check-policy.com", 0, 1, "R");
 $pdf->SetLeftMargin(10);
 $pdf->SetXY(10, $pdf->GetY() + $cell_margin);
 
-// Header
-$pdf->SetTextColor(56, 87, 35);
-$pdf->SetFont("Arial", "B", $header_font_size);
-$pdf->Cell(190, 10, " Test Result", 0, 1, "L", true);
-
-// Pass/Fail
-$image_width = 130;
-
-if($test->pass) {
-	$pdf->Image("public/img/pass.png", (210 - $image_width) / 2, $pdf->GetY() + 2, $image_width);
-}
-else {
-	$pdf->Image("public/img/fail.png", (210 - $image_width) / 2, $pdf->GetY() + 2, $image_width);
-}
-
-$pdf->SetY($pdf->GetY() + 30);
-
-$pdf->SetTextColor(56, 87, 35);
-
-// Location / Tester Headers
-$pdf->SetFont("Arial", "B", $header_font_size);
-
-$tester_x = 150;
-$tester_y = $pdf->GetY();
-
-$header = " $location->name";
-if($location->internal_id) {
-	$header .= " (ID: $location->internal_id)";
-}
-
-$pdf->Cell(135, 10, $header, 0, 1, "L", true);
-$pdf->SetY($pdf->GetY() + 2);
-
-$pdf->SetFont("Arial", "", $normal_font_size);
-$pdf->SetTextColor(0, 0, 0);
-
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
-$pdf->Cell(30, $cell_height, "Region / Manager:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Write($cell_height, $location->region);
-$pdf->Write($cell_height, "/ ");
-$pdf->Write($cell_height, $location->area_manager);
-$pdf->SetY($pdf->GetY() + $cell_height);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
-
-$pdf->Cell(30, $cell_height, "Address:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->MultiCell(100, $cell_height, $location->getDisplayAddress(["address_1", "address_2", "city"], "\n"), 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
-
-$pdf->Cell(30, $cell_height, "Postcode:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell(100, $cell_height, $location->postal_code, 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
-
-$pdf->Cell(30, $cell_height, "Shop Name - Left:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell(100, $cell_height, $test->shop_left, 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
-
-$pdf->Cell(30, $cell_height, "Shop Name - Right:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell(100, $cell_height, $test->shop_right, 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
-
-$test_details_y = $pdf->GetY();
-
-// Tester Info
-$pdf->SetXY($tester_x, $tester_y);
-$pdf->SetLeftMargin(150);
-
-$pdf->SetTextColor(56, 87, 35);
-$pdf->SetFont("Arial", "B", $header_font_size);
-
-$pdf->Cell(50, 10, " Tester", 0, 1, "L", true);
-$pdf->SetY($pdf->GetY() + 2);
-
-$pdf->SetFont("Arial", "", $normal_font_size);
-$pdf->SetTextColor(0, 0, 0);
-
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 50, $pdf->GetY());
-$pdf->Cell(20, $cell_height, "Gender:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell(20, $cell_height, $tester->getGenderText(), 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 50, $pdf->GetY());
-
-$pdf->Cell(20, $cell_height, "Attire:", 0, 1);
-$pdf->SetX(150);
-$pdf->SetFont("Arial", "", $small_font_size);
-$pdf->MultiCell(50, 4, $test->attire, 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 50, $pdf->GetY());
-
-
-// Test Details
-$pdf->SetLeftMargin(10);
-
-$pdf->setXY(10, $test_details_y + 5 + 2);
-
-$pdf->SetTextColor(56, 87, 35);
-$pdf->SetFont("Arial", "B", $header_font_size);
-
-$pdf->Cell(190, 10, " Test Details", 0, 1, "L", true);
-$pdf->SetY($pdf->GetY() + 2);
-
-// Date / Time
-$id_requests_y = $pdf->GetY();
-
-$pdf->SetFont("Arial", "B", $normal_font_size);
-$pdf->SetTextColor(0, 0, 0);
-
-$pdf->Cell(95, $cell_height, "Date & Time", 0, 1);
-$pdf->SetY($pdf->GetY() + 2);
-
-$pdf->SetFont("Arial");
-
-$pdf->Cell(23, $cell_height, "Date");
-$pdf->Cell(23, $cell_height, "Entry");
-$pdf->Cell(23, $cell_height, "Exit");
-$pdf->Cell(23, $cell_height, "Duration", 0, 1);
-
-$pdf->SetFont("Arial", "", $small_font_size);
-
-$pdf->Cell(23, $cell_height, $date_start);
-$pdf->Cell(23, $cell_height, $time_start);
-$pdf->Cell(23, $cell_height, $time_end);
-$pdf->Cell(23, $cell_height, str_pad($diff->h, 2, "0", STR_PAD_LEFT) . ":" . str_pad($diff->i, 2, "0", STR_PAD_LEFT) . ":" . str_pad($diff->s, 2, "0", STR_PAD_LEFT), 0, 1);
-
-$pdf->SetY($pdf->GetY() + 2);
-
-// Staff
-
-$pdf->SetFont("Arial", "B", $normal_font_size);
-$pdf->Cell(95, $cell_height, "Staff", 0, 1);
-$pdf->SetY($pdf->GetY() + 2);
-
-$pdf->SetFont("Arial");
-
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-$pdf->Cell(30, $cell_height, "Name:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell(57.5, $cell_height, $test->challenger_name, 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-
-$pdf->Cell(30, $cell_height, "Gender:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell(57.5, $cell_height, $test->challenger_gender, 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-
-$pdf->Cell(30, $cell_height, "Description:", 0, 1);
-$pdf->SetFont("Arial", "", $small_font_size);
-$pdf->MultiCell(90, 4, $test->challenger_description, 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-$pdf->SetY($pdf->GetY() + 2);
-
-$pdf->SetFont("Arial", "B", $normal_font_size);
-$pdf->Cell(95, $cell_height, "Tester's Notes", 0, 1);
-$pdf->SetY($pdf->GetY() + 2);
-$pdf->SetFont("Arial");
-
-$pdf->SetFont("Arial", "", $small_font_size);
-$pdf->MultiCell(90, 4, $test->additional_notes, 0, 1);
-$pdf->SetY($pdf->GetY() + 2);
-
-// Challenge
-$pdf->SetLeftMargin(107.5);
-$pdf->SetY($id_requests_y);
-
-$pdf->SetFont("Arial", "B", $normal_font_size);
-$pdf->Cell(95, $cell_height, "ID Request", 0, 1);
-$pdf->SetY($pdf->GetY() + 2);
-$pdf->SetFont("Arial");
-
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-
-$pdf->Cell(30, $cell_height, "Result:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell(60, $cell_height, $test->getPassText(), 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-
-$pdf->Cell(30, $cell_height, "ID Stage:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell(60, $cell_height, $test->challenge_stage . " - " . $test->getChallengeStageText(), 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-
-$pdf->SetY($pdf->GetY() + 2);
-
-$pdf->SetFont("Arial", "", $small_font_size);
-$pdf->SetTextColor(0, 128, 0);
-$pdf->MultiCell(95, 4, "1: Challenge on entry", 0, 1);
-
-$pdf->SetTextColor(255, 128, 0);
-$pdf->MultiCell(95, 4, "2: Challenge while browsing
-3: Challenge during play", 0, 1);
-
-$pdf->SetTextColor(255, 0, 0);
-
-$pdf->MultiCell(95, 4, "4: Challenge on exit
-5: No challenge", 0, 1);
-
-$pdf->SetFont("Arial", "", $normal_font_size);
-$pdf->SetTextColor(0, 0, 0);
-
-$pdf->SetY($pdf->GetY() + 2);
-
-$pdf->SetFont("Arial", "", $normal_font_size);
-
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-$pdf->Cell(30, $cell_height, "Eye Contact:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell(60, $cell_height, $test->challenger_eye_contact ? "Y" : "N", 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-
-$pdf->Cell(95, $cell_height, "Description:", 0, 1);
-$pdf->SetFont("Arial", "", $small_font_size);
-$pdf->MultiCell(90, 4, $test->challenge_description, 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-
-$pdf->SetY($pdf->GetY() + 2);
-
-// Details / Signage
-
-$pdf->SetFont("Arial", "B", $normal_font_size);
-$pdf->Cell(95, $cell_height, "Play Details & Signage", 0, 1);
-$pdf->SetY($pdf->GetY() + 2);
-$pdf->SetFont("Arial");
-
-$field_width = 50;
-$value_width = 40;
-
-
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-
-$pdf->Cell($field_width, $cell_height, "Machine Played:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell($value_width, $cell_height, $values["play_machine"] ?? "N/A", 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-
-$value = $values["play_jackpot"] ?? "N/A";
-if($value != "N/A") $value = "\xa3" . number_format($value);
-
-$pdf->Cell($field_width, $cell_height, "Jackpot Value:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell($value_width, $cell_height, $value, 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-
-$value = $values["play_machine_stake"] ?? "N/A";
-if($value != "N/A") $value = "\xa3" . number_format($value, 2);
-
-$pdf->Cell($field_width, $cell_height, "Stake Played:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell($value_width, $cell_height, $value, 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-
-$pdf->Cell($field_width, $cell_height, "Minutes Played:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell($value_width, $cell_height, $values["play_minutes"] ?? "N/A", 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-
-$value = $values["play_spent"] ?? "N/A";
-if($value != "N/A") $value = "\xa3" . number_format($value, 2);
-
-$pdf->Cell($field_width, $cell_height, "Amount Spent:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell($value_width, $cell_height, $value, 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-
-$pdf->Cell($field_width, $cell_height, "Think 21/25:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell($value_width, $cell_height, $values["think_21_25"] ?? "N/A", 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-
-$value = $values["citizen_card_brochure_displayed"] ?? "";
-if(strlen($value) > 0) $value = $value ? "Yes" : "No";
-
-$pdf->Cell($field_width, $cell_height, "Citizen Card Brochure Displayed:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell($value_width, $cell_height, $value ?? "N/A", 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-
-$value = $values["think_21_badge"] ?? "";
-if(strlen($value) > 0) $value = $value ? "Yes" : "No";
-
-$pdf->Cell($field_width, $cell_height, "Think 21/25 Badge Worn by Staff:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell($value_width, $cell_height, $value ?? "N/A", 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
-
-$value = $values["think_21_poster"] ?? "";
-if(strlen($value) > 0) $value = $value ? "Yes" : "No";
-
-$pdf->Cell($field_width, $cell_height, "Think 21/25 Posters Displayed:", 0, 0);
-$pdf->SetX($pdf->GetX() + 5);
-$pdf->Cell($value_width, $cell_height, $value ?? "N/A", 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+require $template_processing_file_path;
 
-$pdf->Cell($field_width, $cell_height, "Think 21/25 Poster Notes:", 0, 1);
-$pdf->SetFont("Arial", "", $small_font_size);
-$pdf->MultiCell(95, 4, $values["think_21_poster_notes"] ?? "N/A", 0, 1);
-$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
 
 // Output
 if($output) {

+ 12 - 0
engine/template.php

@@ -11,6 +11,18 @@ class Template extends Model {
 		return Customer::get($this->customer_id);
 	}
 
+	public function getProcessingFilePath($file) {
+		if(!$this->folder) throw new Exception("Template processing folder not set.");
+
+		$folder_path = ROOT_DIR . "/template_processing/" . $this->folder;
+		if(!file_exists($folder_path)) throw new Exception("Template processing folder does not exist.");
+
+		$file_path = $folder_path . "/" . $file;
+		if(!file_exists($file_path)) throw new Exception("Template processing file does not exist.");
+
+		return $file_path;
+	}
+
 	public function renderBeforeTestForm() {
 
 		$json = json_decode($this->json);

+ 1 - 0
engine/test.php

@@ -166,6 +166,7 @@ class Test extends Model {
 	}
 
 	public function getChallengeStageText() {
+		if(is_null($this->challenge_stage)) return "";
 		return Test::STAGES[$this->challenge_stage];
 	}
 

+ 99 - 0
template_processing/age_verification/project_csv.php

@@ -0,0 +1,99 @@
+<?php
+
+
+$field_names = [
+	"Project ID", "Project Name",
+	"Template Name",
+	"Test ID", "Test Status", "Test Result",
+	"Location Name", "Legal Entity", "Address", "Email", "Phone", "Region", "Internal ID", "Area Manager",
+	"Tester Age", "Tester Gender", "Travel Costs",
+
+	"Date", "Start Time", "End Time", "Duration",
+];
+
+foreach($fields as $field) {
+	$field_names[] = $field->label;
+}
+
+fputcsv($handle, $field_names);
+
+foreach($tests as $test) {
+
+	$location = $test->getLocation();
+	$tester = $test->getTester();
+	$values = $test->getValues(true);
+
+	$test_date = "";
+	$test_start = "";
+	$test_end = "";
+	$test_duration = "";
+
+	$result = "Pending";
+
+	$age = "";
+	$gender = "";
+	$travel_costs = "";
+
+	$output = [];
+	$output[] = $id;
+	$output[] = $project->name;
+	$output[] = $template->name;
+	$output[] = $test->id;
+	$output[] = $test->getStatusText();
+
+	if(!is_null($test->pass)) {
+
+		$result = $test->pass ? "Pass" : "Fail";
+
+		$test_start_dt = new DateTime($test->dts_start);
+		$test_end_dt = new DateTime($test->dts_end);
+		$test_duration_diff = $test_start_dt->diff($test_end_dt, true);
+
+		$test_date = $test_start_dt->format("d/m/Y");
+		$test_start = $test_start_dt->format("H:i:s");
+		$test_end = $test_end_dt->format("H:i:s");
+		$test_duration = $test_duration_diff->h . ":" . $test_duration_diff->i . ":" . $test_duration_diff->s;
+
+		if($tester) {
+			$tester_dob_dt = new DateTime($tester->date_of_birth);
+			$dob_diff = $test_start_dt->diff($tester_dob_dt, true);
+			$age = $dob_diff->y;
+			$gender = $tester->gender;
+			$travel_costs = $test->test_travel_costs;
+		}
+	}
+
+
+	$output[] = $result;
+	$output[] = $location->name;
+	$output[] = $location->legal_entity_name;
+	$output[] = $location->getDisplayAddress();
+	$output[] = $location->email;
+	$output[] = $location->phone;
+	$output[] = $location->region;
+	$output[] = $location->internal_id;
+	$output[] = $location->area_manager;
+	$output[] = $age;
+	$output[] = $gender;
+	$output[] = $travel_costs;
+	$output[] = $test_date;
+	$output[] = $test_start;
+	$output[] = $test_end;
+	$output[] = $test_duration;
+
+	foreach($fields as $field) {
+		$field_name = $field->name;
+		$value = isset($test->$field_name) ? $test->$field_name : ($values[$field->name] ?? "");
+
+		if(!empty($field->displayStrings)) {
+			$index = array_search($value, $field->values);
+			$value = $field->displayStrings[$index];
+		}
+
+		$output[] = $value;
+	}
+
+	fputcsv($handle, $output);
+}
+
+?>

+ 83 - 0
template_processing/age_verification/project_customer_csv.php

@@ -0,0 +1,83 @@
+<?php
+
+$field_names = [
+	"Project Name",
+	"Test Status", "Test Result",
+	"Location Name", "Address", "Region", "Internal ID", "Area Manager",
+
+	"Date",
+];
+
+foreach($fields as $field) {
+	$field_names[] = $field->label;
+}
+
+fputcsv($handle, $field_names);
+
+foreach($tests as $test) {
+
+	$location = $test->getLocation();
+	$tester = $test->getTester();
+	$values = $test->getValues(true);
+
+	$test_date = "";
+	$test_start = "";
+	$test_end = "";
+	$test_duration = "";
+
+	$result = "Pending";
+
+	$age = "";
+	$gender = "";
+	$travel_costs = "";
+
+	$output = [];
+	$output[] = $project->name;
+	$output[] = $test->getStatusText();
+
+	if(!is_null($test->pass)) {
+
+		$result = $test->pass ? "Pass" : "Fail";
+
+		$test_start_dt = new DateTime($test->dts_start);
+		$test_end_dt = new DateTime($test->dts_end);
+		$test_duration_diff = $test_start_dt->diff($test_end_dt, true);
+
+		$test_date = $test_start_dt->format("d/m/Y");
+		$test_start = $test_start_dt->format("H:i:s");
+		$test_end = $test_end_dt->format("H:i:s");
+		$test_duration = $test_duration_diff->h . ":" . $test_duration_diff->i . ":" . $test_duration_diff->s;
+
+		if($tester) {
+			$tester_dob_dt = new DateTime($tester->date_of_birth);
+			$dob_diff = $test_start_dt->diff($tester_dob_dt, true);
+			$age = $dob_diff->y;
+			$gender = $tester->gender;
+			$travel_costs = $test->test_travel_costs;
+		}
+	}
+
+	$output[] = $result;
+	$output[] = $location->name;
+	$output[] = $location->getDisplayAddress();
+	$output[] = $location->region;
+	$output[] = $location->internal_id;
+	$output[] = $location->area_manager;
+	$output[] = $test_date;
+
+	foreach($fields as $field) {
+		$field_name = $field->name;
+		$value = isset($test->$field_name) ? $test->$field_name : ($values[$field->name] ?? "");
+
+		if(!empty($field->displayStrings)) {
+			$index = array_search($value, $field->values);
+			$value = $field->displayStrings[$index];
+		}
+
+		$output[] = $value;
+	}
+
+	fputcsv($handle, $output);
+}
+
+?>

+ 297 - 0
template_processing/age_verification/test_pdf.php

@@ -0,0 +1,297 @@
+<?php
+
+// Header
+$pdf->SetTextColor(56, 87, 35);
+$pdf->SetFont("Arial", "B", $header_font_size);
+$pdf->Cell(190, 10, " Test Result", 0, 1, "L", true);
+
+// Pass/Fail
+$image_width = 130;
+
+if($test->pass) {
+	$pdf->Image("public/img/pass.png", (210 - $image_width) / 2, $pdf->GetY() + 2, $image_width);
+}
+else {
+	$pdf->Image("public/img/fail.png", (210 - $image_width) / 2, $pdf->GetY() + 2, $image_width);
+}
+
+$pdf->SetY($pdf->GetY() + 30);
+
+$pdf->SetTextColor(56, 87, 35);
+
+// Location / Tester Headers
+$pdf->SetFont("Arial", "B", $header_font_size);
+
+$tester_x = 150;
+$tester_y = $pdf->GetY();
+
+$pdf->Cell(135, 10, $location_text, 0, 1, "L", true);
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial", "", $normal_font_size);
+$pdf->SetTextColor(0, 0, 0);
+
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+$pdf->Cell(30, $cell_height, "Region / Manager:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Write($cell_height, $location->region);
+$pdf->Write($cell_height, "/ ");
+$pdf->Write($cell_height, $location->area_manager);
+$pdf->SetY($pdf->GetY() + $cell_height);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Address:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->MultiCell(100, $cell_height, $location->getDisplayAddress(["address_1", "address_2", "city"], "\n"), 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Postcode:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(100, $cell_height, $location->postal_code, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Shop Name - Left:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(100, $cell_height, $test->shop_left, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Shop Name - Right:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(100, $cell_height, $test->shop_right, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+
+$test_details_y = $pdf->GetY();
+
+// Tester Info
+$pdf->SetXY($tester_x, $tester_y);
+$pdf->SetLeftMargin(150);
+
+$pdf->SetTextColor(56, 87, 35);
+$pdf->SetFont("Arial", "B", $header_font_size);
+
+$pdf->Cell(50, 10, " Tester", 0, 1, "L", true);
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial", "", $normal_font_size);
+$pdf->SetTextColor(0, 0, 0);
+
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 50, $pdf->GetY());
+$pdf->Cell(20, $cell_height, "Gender:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(20, $cell_height, $tester->getGenderText(), 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 50, $pdf->GetY());
+
+$pdf->Cell(20, $cell_height, "Attire:", 0, 1);
+$pdf->SetX(150);
+$pdf->SetFont("Arial", "", $small_font_size);
+$pdf->MultiCell(50, 4, $test->attire, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 50, $pdf->GetY());
+
+
+// Test Details
+$pdf->SetLeftMargin(10);
+
+$pdf->setXY(10, $test_details_y + 5 + 2);
+
+$pdf->SetTextColor(56, 87, 35);
+$pdf->SetFont("Arial", "B", $header_font_size);
+
+$pdf->Cell(190, 10, " Test Details", 0, 1, "L", true);
+$pdf->SetY($pdf->GetY() + 2);
+
+// Date / Time
+$id_requests_y = $pdf->GetY();
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->SetTextColor(0, 0, 0);
+
+$pdf->Cell(95, $cell_height, "Date & Time", 0, 1);
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial");
+
+$pdf->Cell(23, $cell_height, "Date");
+$pdf->Cell(23, $cell_height, "Entry");
+$pdf->Cell(23, $cell_height, "Exit");
+$pdf->Cell(23, $cell_height, "Duration", 0, 1);
+
+$pdf->SetFont("Arial", "", $small_font_size);
+
+$pdf->Cell(23, $cell_height, $date_start);
+$pdf->Cell(23, $cell_height, $time_start);
+$pdf->Cell(23, $cell_height, $time_end);
+$pdf->Cell(23, $cell_height, str_pad($diff->h, 2, "0", STR_PAD_LEFT) . ":" . str_pad($diff->i, 2, "0", STR_PAD_LEFT) . ":" . str_pad($diff->s, 2, "0", STR_PAD_LEFT), 0, 1);
+
+$pdf->SetY($pdf->GetY() + 2);
+
+// Staff
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->Cell(95, $cell_height, "Staff", 0, 1);
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial");
+
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+$pdf->Cell(30, $cell_height, "Name:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(57.5, $cell_height, $test->challenger_name, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Gender:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(57.5, $cell_height, $test->challenger_gender, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Description:", 0, 1);
+$pdf->SetFont("Arial", "", $small_font_size);
+$pdf->MultiCell(90, 4, $test->challenger_description, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->Cell(95, $cell_height, "Tester's Notes", 0, 1);
+$pdf->SetY($pdf->GetY() + 2);
+$pdf->SetFont("Arial");
+
+$pdf->SetFont("Arial", "", $small_font_size);
+$pdf->MultiCell(90, 4, $test->additional_notes, 0, 1);
+$pdf->SetY($pdf->GetY() + 2);
+
+// Challenge
+$pdf->SetLeftMargin(107.5);
+$pdf->SetY($id_requests_y);
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->Cell(95, $cell_height, "ID Request", 0, 1);
+$pdf->SetY($pdf->GetY() + 2);
+$pdf->SetFont("Arial");
+
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Result:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(60, $cell_height, $test->getPassText(), 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "ID Stage:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(60, $cell_height, $test->challenge_stage . " - " . $test->getChallengeStageText(), 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial", "", $small_font_size);
+$pdf->SetTextColor(0, 128, 0);
+$pdf->MultiCell(95, 4, "1: Challenge on entry", 0, 1);
+
+$pdf->SetTextColor(255, 128, 0);
+$pdf->MultiCell(95, 4, "2: Challenge while browsing
+3: Challenge during play", 0, 1);
+
+$pdf->SetTextColor(255, 0, 0);
+
+$pdf->MultiCell(95, 4, "4: Challenge on exit
+5: No challenge", 0, 1);
+
+$pdf->SetFont("Arial", "", $normal_font_size);
+$pdf->SetTextColor(0, 0, 0);
+
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial", "", $normal_font_size);
+
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+$pdf->Cell(30, $cell_height, "Eye Contact:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(60, $cell_height, $test->challenger_eye_contact ? "Y" : "N", 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell(95, $cell_height, "Description:", 0, 1);
+$pdf->SetFont("Arial", "", $small_font_size);
+$pdf->MultiCell(90, 4, $test->challenge_description, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->SetY($pdf->GetY() + 2);
+
+// Details / Signage
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->Cell(95, $cell_height, "Play Details & Signage", 0, 1);
+$pdf->SetY($pdf->GetY() + 2);
+$pdf->SetFont("Arial");
+
+$field_width = 50;
+$value_width = 40;
+
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell($field_width, $cell_height, "Machine Played:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $values["play_machine"] ?? "N/A", 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["play_jackpot"] ?? "N/A";
+if($value != "N/A") $value = "\xa3" . number_format($value);
+
+$pdf->Cell($field_width, $cell_height, "Jackpot Value:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $value, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["play_machine_stake"] ?? "N/A";
+if($value != "N/A") $value = "\xa3" . number_format($value, 2);
+
+$pdf->Cell($field_width, $cell_height, "Stake Played:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $value, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell($field_width, $cell_height, "Minutes Played:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $values["play_minutes"] ?? "N/A", 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["play_spent"] ?? "N/A";
+if($value != "N/A") $value = "\xa3" . number_format($value, 2);
+
+$pdf->Cell($field_width, $cell_height, "Amount Spent:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $value, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell($field_width, $cell_height, "Think 21/25:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $values["think_21_25"] ?? "N/A", 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["citizen_card_brochure_displayed"] ?? "";
+if(strlen($value) > 0) $value = $value ? "Yes" : "No";
+
+$pdf->Cell($field_width, $cell_height, "Citizen Card Brochure Displayed:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $value ?? "N/A", 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["think_21_badge"] ?? "";
+if(strlen($value) > 0) $value = $value ? "Yes" : "No";
+
+$pdf->Cell($field_width, $cell_height, "Think 21/25 Badge Worn by Staff:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $value ?? "N/A", 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["think_21_poster"] ?? "";
+if(strlen($value) > 0) $value = $value ? "Yes" : "No";
+
+$pdf->Cell($field_width, $cell_height, "Think 21/25 Posters Displayed:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell($value_width, $cell_height, $value ?? "N/A", 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$pdf->Cell($field_width, $cell_height, "Think 21/25 Poster Notes:", 0, 1);
+$pdf->SetFont("Arial", "", $small_font_size);
+$pdf->MultiCell(95, 4, $values["think_21_poster_notes"] ?? "N/A", 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+?>

+ 90 - 0
template_processing/mystery_shop/project_csv.php

@@ -0,0 +1,90 @@
+<?php
+
+$field_names = [
+	"Project ID", "Project Name",
+	"Template Name",
+	"Test ID", "Test Status",
+	"Location Name", "Legal Entity", "Address", "Email", "Phone", "Region", "Internal ID", "Area Manager",
+	"Tester Age", "Tester Gender", "Travel Costs",
+
+	"Date", "Start Time", "End Time", "Duration",
+];
+
+foreach($fields as $field) {
+	$field_names[] = $field->label;
+}
+
+fputcsv($handle, $field_names);
+
+foreach($tests as $test) {
+
+	$location = $test->getLocation();
+	$tester = $test->getTester();
+	$values = $test->getValues(true);
+
+	$test_date = "";
+	$test_start = "";
+	$test_end = "";
+	$test_duration = "";
+
+	$age = "";
+	$gender = "";
+	$travel_costs = "";
+
+	$output = [];
+	$output[] = $id;
+	$output[] = $project->name;
+	$output[] = $template->name;
+	$output[] = $test->id;
+	$output[] = $test->getStatusText();
+
+	if(!is_null($test->dts_end)) {
+
+		$test_start_dt = new DateTime($test->dts_start);
+		$test_end_dt = new DateTime($test->dts_end);
+		$test_duration_diff = $test_start_dt->diff($test_end_dt, true);
+
+		$test_date = $test_start_dt->format("d/m/Y");
+		$test_start = $test_start_dt->format("H:i:s");
+		$test_end = $test_end_dt->format("H:i:s");
+		$test_duration = $test_duration_diff->h . ":" . $test_duration_diff->i . ":" . $test_duration_diff->s;
+
+		if($tester) {
+			$tester_dob_dt = new DateTime($tester->date_of_birth);
+			$dob_diff = $test_start_dt->diff($tester_dob_dt, true);
+			$age = $dob_diff->y;
+			$gender = $tester->gender;
+			$travel_costs = $test->test_travel_costs;
+		}
+	}
+
+	$output[] = $location->name;
+	$output[] = $location->legal_entity_name;
+	$output[] = $location->getDisplayAddress();
+	$output[] = $location->email;
+	$output[] = $location->phone;
+	$output[] = $location->region;
+	$output[] = $location->internal_id;
+	$output[] = $location->area_manager;
+	$output[] = $age;
+	$output[] = $gender;
+	$output[] = $travel_costs;
+	$output[] = $test_date;
+	$output[] = $test_start;
+	$output[] = $test_end;
+	$output[] = $test_duration;
+
+	foreach($fields as $field) {
+		$field_name = $field->name;
+		$value = isset($test->$field_name) ? $test->$field_name : ($values[$field->name] ?? "");
+
+		if(!empty($field->displayStrings)) {
+			$index = array_search($value, $field->values);
+			$value = $field->displayStrings[$index];
+		}
+
+		$output[] = $value;
+	}
+
+	fputcsv($handle, $output);
+}

+ 79 - 0
template_processing/mystery_shop/project_customer_csv.php

@@ -0,0 +1,79 @@
+<?php
+
+$field_names = [
+	"Project Name",
+	"Test Status",
+	"Location Name", "Address", "Region", "Internal ID", "Area Manager",
+
+	"Date",
+];
+
+foreach($fields as $field) {
+	$field_names[] = $field->label;
+}
+
+fputcsv($handle, $field_names);
+
+foreach($tests as $test) {
+
+	$location = $test->getLocation();
+	$tester = $test->getTester();
+	$values = $test->getValues(true);
+
+	$test_date = "";
+	$test_start = "";
+	$test_end = "";
+	$test_duration = "";
+
+
+	$age = "";
+	$gender = "";
+	$travel_costs = "";
+
+	$output = [];
+	$output[] = $project->name;
+	$output[] = $test->getStatusText();
+
+	if(!is_null($test->dts_end)) {
+
+		$test_start_dt = new DateTime($test->dts_start);
+		$test_end_dt = new DateTime($test->dts_end);
+		$test_duration_diff = $test_start_dt->diff($test_end_dt, true);
+
+		$test_date = $test_start_dt->format("d/m/Y");
+		$test_start = $test_start_dt->format("H:i:s");
+		$test_end = $test_end_dt->format("H:i:s");
+		$test_duration = $test_duration_diff->h . ":" . $test_duration_diff->i . ":" . $test_duration_diff->s;
+
+		if($tester) {
+			$tester_dob_dt = new DateTime($tester->date_of_birth);
+			$dob_diff = $test_start_dt->diff($tester_dob_dt, true);
+			$age = $dob_diff->y;
+			$gender = $tester->gender;
+			$travel_costs = $test->test_travel_costs;
+		}
+	}
+
+	$output[] = $location->name;
+	$output[] = $location->getDisplayAddress();
+	$output[] = $location->region;
+	$output[] = $location->internal_id;
+	$output[] = $location->area_manager;
+	$output[] = $test_date;
+
+	foreach($fields as $field) {
+		$field_name = $field->name;
+		$value = isset($test->$field_name) ? $test->$field_name : ($values[$field->name] ?? "");
+
+		if(!empty($field->displayStrings)) {
+			$index = array_search($value, $field->values);
+			$value = $field->displayStrings[$index];
+		}
+
+		$output[] = $value;
+	}
+
+	fputcsv($handle, $output);
+}
+
+?>

+ 231 - 0
template_processing/mystery_shop/test_pdf.php

@@ -0,0 +1,231 @@
+<?php
+
+// Location / Tester Headers
+$pdf->SetTextColor(56, 87, 35);
+$pdf->SetFont("Arial", "B", $header_font_size);
+
+$tester_x = 150;
+$tester_y = $pdf->GetY();
+
+$pdf->Cell(135, 10, $location_text, 0, 1, "L", true);
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial", "", $normal_font_size);
+$pdf->SetTextColor(0, 0, 0);
+
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+$pdf->Cell(30, $cell_height, "Region / Manager:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Write($cell_height, $location->region);
+$pdf->Write($cell_height, "/ ");
+$pdf->Write($cell_height, $location->area_manager);
+$pdf->SetY($pdf->GetY() + $cell_height);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Address:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->MultiCell(100, $cell_height, $location->getDisplayAddress(["address_1", "address_2", "city"], "\n"), 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Postcode:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(100, $cell_height, $location->postal_code, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Shop Name - Left:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(100, $cell_height, $test->shop_left, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+
+$pdf->Cell(30, $cell_height, "Shop Name - Right:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(100, $cell_height, $test->shop_right, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 135, $pdf->GetY());
+
+$test_details_y = $pdf->GetY();
+
+// Tester Info
+$pdf->SetXY($tester_x, $tester_y);
+$pdf->SetLeftMargin(150);
+
+$pdf->SetTextColor(56, 87, 35);
+$pdf->SetFont("Arial", "B", $header_font_size);
+
+$pdf->Cell(50, 10, " Tester", 0, 1, "L", true);
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial", "", $normal_font_size);
+$pdf->SetTextColor(0, 0, 0);
+
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 50, $pdf->GetY());
+$pdf->Cell(20, $cell_height, "Gender:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(20, $cell_height, $tester->getGenderText(), 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 50, $pdf->GetY());
+
+$pdf->Cell(20, $cell_height, "Attire:", 0, 1);
+$pdf->SetX(150);
+$pdf->SetFont("Arial", "", $small_font_size);
+$pdf->MultiCell(50, 4, $test->attire, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 50, $pdf->GetY());
+
+
+// Test Details
+$pdf->SetLeftMargin(10);
+
+$pdf->setXY(10, $test_details_y + 5 + 2);
+
+$pdf->SetTextColor(56, 87, 35);
+$pdf->SetFont("Arial", "B", $header_font_size);
+
+$pdf->Cell(190, 10, " Test Details", 0, 1, "L", true);
+$pdf->SetY($pdf->GetY() + 2);
+
+// Date / Time
+$id_requests_y = $pdf->GetY();
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->SetTextColor(0, 0, 0);
+
+$pdf->Cell(95, $cell_height, "Date & Time", 0, 1);
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial");
+
+$pdf->Cell(23, $cell_height, "Date");
+$pdf->Cell(23, $cell_height, "Entry");
+$pdf->Cell(23, $cell_height, "Exit");
+$pdf->Cell(23, $cell_height, "Duration", 0, 1);
+
+$pdf->SetFont("Arial", "", $small_font_size);
+
+$pdf->Cell(23, $cell_height, $date_start);
+$pdf->Cell(23, $cell_height, $time_start);
+$pdf->Cell(23, $cell_height, $time_end);
+$pdf->Cell(23, $cell_height, str_pad($diff->h, 2, "0", STR_PAD_LEFT) . ":" . str_pad($diff->i, 2, "0", STR_PAD_LEFT) . ":" . str_pad($diff->s, 2, "0", STR_PAD_LEFT), 0, 1);
+
+$pdf->SetY($pdf->GetY() + 2);
+
+// Venue Details
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->Cell(95, $cell_height, "Venue", 0, 1);
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial");
+
+$cleanliness = $values["cleanliness"];
+switch($cleanliness) {
+	case 1: $cleanliness = "Very dirty"; break;
+	case 2: $cleanliness = "Dirty"; break;
+	case 3: $cleanliness = "Adequate"; break;
+	case 4: $cleanliness = "Clean"; break;
+	case 5: $cleanliness = "Very clean"; break;
+}
+
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+$pdf->Cell(30, $cell_height, "Cleanliness:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(57.5, $cell_height, $cleanliness, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+$pdf->SetY($pdf->GetY() + 2);
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->Cell(95, $cell_height, "Tester's Notes", 0, 1);
+$pdf->SetY($pdf->GetY() + 2);
+$pdf->SetFont("Arial");
+
+$pdf->SetFont("Arial", "", $small_font_size);
+$pdf->MultiCell(90, 4, $test->additional_notes, 0, 1);
+$pdf->SetY($pdf->GetY() + 2);
+
+// Staff Details
+$pdf->SetLeftMargin(107.5);
+$pdf->SetY($id_requests_y);
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->Cell(95, $cell_height, "Staff Details", 0, 1);
+$pdf->SetY($pdf->GetY() + 2);
+$pdf->SetFont("Arial");
+
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["staff_badge_worn"] ?? "";
+if(strlen($value) == 0) $value = "Don't know/Not approached";
+else $value = ($value == 0) ? "No" : "Yes";
+$pdf->Cell(30, $cell_height, "Staff Badge Worn:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(60, $cell_height, $value, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["staff_name"] ?? "";
+$pdf->Cell(30, $cell_height, "Staff Name:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(60, $cell_height, $value, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["drink_offered"] ?? "";
+$value = $value ? "Yes" : "No";
+$pdf->Cell(30, $cell_height, "Drink Offered:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(60, $cell_height, $value, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["staff_offered_drink_name"] ?? "";
+$value = $value ?: "No drink offered";
+$pdf->Cell(30, $cell_height, "Drink Name:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(60, $cell_height, $value, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["staff_offered_promotion"] ?? "";
+$value = $value ? "Yes" : "No";
+$pdf->Cell(30, $cell_height, "Promotion Offered:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(60, $cell_height, $value, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["staff_offered_promotion_name"] ?? "";
+$value = $value ?: "No promotion offered";
+$pdf->Cell(95, $cell_height, "Promotion Name:", 0, 1);
+$pdf->SetFont("Arial", "", $small_font_size);
+$pdf->MultiCell(90, 4, $value, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["staff_help"] ?? "";
+$value = $value ? "Yes" : "No";
+$pdf->Cell(30, $cell_height, "Machine Explanation:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(60, $cell_height, $value, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["staff_behaviour"];
+switch($value) {
+	case 1: $value = "Rude"; break;
+	case 2: $value = "Slightly rude"; break;
+	case 3: $value = "Neither rude or polite"; break;
+	case 4: $value = "Polite and friendly"; break;
+	case 5: $value = "Very polite and friendly"; break;
+	default: $value = "N/A"; break;
+}
+
+$pdf->Cell(30, $cell_height, "Staff Behaviour:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(60, $cell_height, $value, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["staff_uniform"] ?? "";
+$value = $value ? "Yes" : "No";
+$pdf->Cell(30, $cell_height, "Staff Uniform:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(60, $cell_height, $value, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+$value = $values["staff_uniform_description"] ?? "";
+$value = $value ?: "N/A";
+$pdf->Cell(95, $cell_height, "Staff Uniform Description:", 0, 1);
+$pdf->SetFont("Arial", "", $small_font_size);
+$pdf->MultiCell(90, 4, $value, 0, 1);
+$pdf->Line($pdf->GetX(), $pdf->GetY(), $pdf->GetX() + 92.5, $pdf->GetY());
+
+?>