Explorar o código

Merge branch 'develop'

Alan Lam %!s(int64=8) %!d(string=hai) anos
pai
achega
a04e75910f
Modificáronse 63 ficheiros con 1648 adicións e 729 borrados
  1. 4 1
      .gitignore
  2. 1 0
      controllers/location_add.php
  3. 1 0
      controllers/location_edit.php
  4. 32 1
      controllers/locations.php
  5. 43 27
      controllers/performance.php
  6. 9 0
      controllers/project_add.php
  7. 2 0
      controllers/project_ajax.php
  8. 0 94
      controllers/project_csv.php
  9. 2 79
      controllers/project_customer_csv.php
  10. 9 1
      controllers/project_edit.php
  11. 33 0
      controllers/project_kml.php
  12. 1 0
      controllers/projects.php
  13. 5 0
      controllers/test.php
  14. 12 298
      controllers/test_pdf.php
  15. 1 1
      controllers/user_ajax.php
  16. 2 0
      controllers/user_edit.php
  17. 19 3
      controllers/users.php
  18. 11 2
      engine/chart.php
  19. 5 0
      engine/form.php
  20. 1 1
      engine/location.php
  21. 19 3
      engine/project.php
  22. 16 0
      engine/template.php
  23. 1 0
      engine/test.php
  24. 1 1
      engine/user.php
  25. 3 0
      files/empty.kml
  26. BIN=BIN
      files/id_response.pdf
  27. BIN=BIN
      files/machine_categories.pdf
  28. BIN=BIN
      files/testing_methodology.pdf
  29. BIN=BIN
      files/testing_procedure.pdf
  30. 18 9
      json/age_verification.json
  31. 0 189
      json/default_template.json
  32. 152 0
      json/mystery_shop.json
  33. BIN=BIN
      psd/marker.psd
  34. BIN=BIN
      public/img/markers/building-blue.png
  35. BIN=BIN
      public/img/markers/building-green.png
  36. BIN=BIN
      public/img/markers/building-grey.png
  37. BIN=BIN
      public/img/markers/building-orange.png
  38. BIN=BIN
      public/img/markers/building-pink.png
  39. BIN=BIN
      public/img/markers/building-red.png
  40. BIN=BIN
      public/img/markers/user-green.png
  41. BIN=BIN
      public/img/markers/user-grey.png
  42. BIN=BIN
      public/img/markers/user-orange.png
  43. BIN=BIN
      public/img/markers/user-red.png
  44. 86 3
      public/js/app-locations.js
  45. 6 0
      public/js/app-project.js
  46. 4 1
      public/js/app.js
  47. 1 0
      routes.php
  48. 99 0
      template_processing/age_verification/project_csv.php
  49. 87 0
      template_processing/age_verification/project_customer_csv.php
  50. 297 0
      template_processing/age_verification/test_pdf.php
  51. 90 0
      template_processing/mystery_shop/project_csv.php
  52. 79 0
      template_processing/mystery_shop/project_customer_csv.php
  53. 215 0
      template_processing/mystery_shop/test_pdf.php
  54. 6 0
      views/location_form.php
  55. 7 2
      views/locations.php
  56. 99 1
      views/performance.php
  57. 13 2
      views/project.php
  58. 46 1
      views/project_form.php
  59. 21 0
      views/project_list.php
  60. 19 4
      views/test_verify_form.php
  61. 5 0
      views/user.php
  62. 21 1
      views/user_edit_form.php
  63. 44 4
      views/users.php

+ 4 - 1
.gitignore

@@ -1,5 +1,7 @@
 config.php
-/files/
+/files/locations
+/files/tests
+/files/users
 node_modules/
 vendor/
 reference/
@@ -7,3 +9,4 @@ logs/
 tasks/PraesepeVenues.csv
 tasks/email_test.php
 tasks/data/
+backups/

+ 1 - 0
controllers/location_add.php

@@ -38,6 +38,7 @@ if($submit) {
 		$location->region = http::value("region", "trim");
 		$location->internal_id = http::value("internal_id", "trim");
 		$location->area_manager = http::value("area_manager", "trim");
+		$location->area_manager_email = http::value("area_manager_email", "email");
 
 		if(empty($location->name)) $form_exception->addError("Name is required.");
 		if(empty($location->address_1)) $form_exception->addError("Location line 1 is required.");

+ 1 - 0
controllers/location_edit.php

@@ -36,6 +36,7 @@ if($submit) {
 		$location->region = http::value("region", "trim");
 		$location->internal_id = http::value("internal_id", "trim");
 		$location->area_manager = http::value("area_manager", "trim");
+		$location->area_manager_email = http::value("area_manager_email", "email");
 
 		$location->closed = http::value("closed", "int");
 

+ 32 - 1
controllers/locations.php

@@ -8,6 +8,8 @@ Core::addBreadcrumb("/account/locations", "Locations");
 $customer = Customer::getForAdmin();
 if(!$customer) throw new Exception("You do not have permission to access this page.");
 
+$customer_slug = Util::slug($customer->name);
+
 $sorts = [
 	"name" => "Name",
 	"last-added" => "Last Added",
@@ -21,10 +23,12 @@ Core::addBreadcrumb("/account/locations?customer_id=$customer->id", $page_title)
 $nvp = ["customer_id" => $customer->id];
 
 $id = http::value("id", "int");
+$ids = http::value("ids", "int");
 $internal_id = http::value("internal_id", "trim");
 $name = http::value("name", "trim");
 
 if($id) $nvp["id"] = $id;
+if($ids) $nvp["id"] = $ids;
 if($internal_id) $nvp["internal_id"] = db::escape($internal_id);
 if($name) $nvp["name"] = (new Constraint("CONTAINS"))->setValues(db::escape($name));
 
@@ -56,7 +60,7 @@ if(!empty($action)) {
 			if(!Core::$user->canAdmin()) throw new Exception("You do not have permission to access this resource.");
 
 			header("Content-Type: text/csv; charset=utf-8");
-			header("Content-Disposition: attachment; filename=export.csv");
+			header("Content-Disposition: attachment; filename=$customer_slug-export.csv");
 
 			$handle = fopen("php://output", "w");
 
@@ -84,6 +88,33 @@ if(!empty($action)) {
 
 			fclose($handle);
 
+			exit;
+
+		case "export-kml":
+
+			header("Content-Type: text/xml; charset=utf-8");
+			header("Content-Disposition: attachment; filename=$customer_slug-export.kml");
+
+			$xml = simplexml_load_file(ROOT_DIR . "/files/empty.kml");
+
+			$folder_node = $xml->addChild("Folder");
+			$folder_node->addChild("name", $customer->name);
+			$folder_node->addChild("open", 1);
+			$folder_node->addChild("description", $customer->name . " Locations");
+
+			foreach($locations as $location) {
+				$placemark_node = $folder_node->addChild("Placemark");
+
+				$placemark_node->addChild("name", htmlspecialchars($location->name));
+				$placemark_node->addChild("description", htmlspecialchars($location->getDisplayAddress()));
+
+				$point_node = $placemark_node->addChild("Point");
+				$point_node->addChild("coordinates", $location->longitude . "," . $location->latitude);
+
+			}
+
+			echo $xml->asXML();
+
 			exit;
 	}
 }

+ 43 - 27
controllers/performance.php

@@ -22,6 +22,8 @@ $date_resolution = http::value("date_resolution");
 $from_quarter = http::value("from_quarter");
 $to_quarter = http::value("to_quarter");
 
+$project_ids = http::value("project_ids", "int");
+
 $all_projects = Project::query([
 	"customer_id" => $customer->id
 ]);
@@ -58,8 +60,6 @@ $colours = [
 	"#9e9e9e",
 ];
 
-$project_ids = [];
-
 $submit = http::value("submit");
 if($submit) {
 	try {
@@ -68,22 +68,22 @@ if($submit) {
 		$form_exception = new FormException;
 		if($form_exception->hasErrors()) throw $form_exception;
 
-
 		// Get all tests
 		$projects = Project::query([
-			"customer_id" => $customer->id
+			"customer_id" => $customer->id,
+			"id" => $project_ids
 		]);
 
-		$project_ids = array_column($projects, "id");
-
 		$tests = Test::query([
 			"project_id" => $project_ids,
 			"status" => Test::STATUS_COMPLETED
 		]);
+		$test_count = count($tests);
 
 		User::load(array_column($tests, "tester_id"));
 		$locations = Location::load(array_column($tests, "location_id"));
 
+
 		$regions = array_filter(array_column($locations, "region"));
 		$area_managers = array_filter(array_column($locations, "area_manager"));
 
@@ -101,7 +101,6 @@ if($submit) {
 		$has_regions = !empty($region_data);
 		$has_area_managers = !empty($area_manager_data);
 
-
 		foreach($locations as $location) {
 			if($has_regions && !$location->region) $locations_missing_region[] = $location;
 			if($has_area_managers && !$location->area_manager) $locations_missing_area_manager[] = $location;
@@ -170,7 +169,11 @@ if($submit) {
 		// Filter tests based on date range
 		$tests = array_filter($tests, function($test) use ($min_unix, $max_unix) {
 
-			$dt = new DateTime($test->dts_start . " UTC");
+			$project = $test->getProject();
+
+			$dts = $project->dts_report ?: $test->dts_start;
+
+			$dt = new DateTime($dts . " UTC");
 			$unix = $dt->format("U");
 
 			if($unix < $min_unix) {
@@ -306,10 +309,14 @@ if($submit) {
 			$tester = $test->getTester();
 			$location = $test->getLocation();
 
+			$project = $test->getProject();
+
 			$region = $location->region;
 			$area_manager = $location->area_manager;
 
-			$dt = new DateTime($test->dts_start . " UTC");
+			$dts = $project->dts_report ?: $test->dts_start;
+
+			$dt = new DateTime($dts . " UTC");
 			$dt->setTimezone(new DateTimeZone(TIMEZONE));
 
 			$unix = $dt->format("U");
@@ -489,6 +496,7 @@ if($submit) {
 		}, $data));
 
 		$chart = new Chart;
+		$chart->addYAxis("linear", "left", "y-axis-1", true, ["min" => 0, "max" => 100]);
 		$chart->setType("bar");
 		$chart->setTitle("Pass Rate by $resolution_name");
 		$chart->setLabels($x_data_labels);
@@ -507,9 +515,18 @@ if($submit) {
 		$chart->setType("bar");
 		$chart->setTitle("Totals by $resolution_name");
 		$chart->setLabels($x_data_labels);
-		$chart->addYAxis("linear", "left", "y-axis-1");
-		$chart->addYAxis("linear", "right", "y-axis-2", false);
+		$chart->addYAxis("linear", "left", "y-axis-1", true, ["min" => 0, "max" => ceil($test_count / 10) * 10]);
+		$chart->addYAxis("linear", "right", "y-axis-2", false, ["min" => 0, "max" => 100]);
 
+		$chart->addDataset("Performance (%)", $performance, [
+			"border_colours" => "#FFEB3B",
+			"background_colours" => "transparent",
+			"type" => "line",
+			"y_axis_id" => "y-axis-2",
+			"datalabels" => [
+				"display" => false
+			],
+		]);
 		$chart->addDataset("Test Count", $test_counts, [
 			"background_colours" => "#2196F3",
 			"type" => "bar",
@@ -525,12 +542,6 @@ if($submit) {
 			"type" => "bar",
 			"y_axis_id" => "y-axis-1",
 		]);
-		$chart->addDataset("Performance (%)", $performance, [
-			"border_colours" => "#FFEB3B",
-			"background_colours" => "transparent",
-			"type" => "line",
-			"y_axis_id" => "y-axis-2",
-		]);
 		$charts[] = $chart;
 
 		// Point of Challenge (Each Period)
@@ -564,10 +575,6 @@ if($submit) {
 			$charts[] = $chart;
 		}
 
-
-
-
-
 		// Tester Genders by Period
 		$male_counts = array_values(array_map(function($d) {
 			return $d->maleTesterCount;
@@ -578,6 +585,7 @@ if($submit) {
 		}, $data));
 
 		$chart = new Chart;
+		$chart->addYAxis("linear", "left", "y-axis-1", true, ["min" => 0, "max" => ceil(max(max($male_counts), max($female_counts)) / 10) * 10]);
 		$chart->setType("bar");
 		$chart->setTitle("Tester Gender by $resolution_name");
 		$chart->setLabels($x_data_labels);
@@ -595,6 +603,7 @@ if($submit) {
 		}, $data));
 
 		$chart = new Chart;
+		$chart->addYAxis("linear", "left", "y-axis-1", true, ["min" => 0, "max" => ceil(max($test_counts) / 10) * 10]);
 		$chart->setType("bar");
 		$chart->setTitle("Tests by $resolution_name");
 		$chart->setLabels($x_data_labels);
@@ -606,9 +615,10 @@ if($submit) {
 		$pass_counts = array_column($data, "passCount");
 		$fail_counts = array_column($data, "failCount");
 
-
 		if($has_regions) {
 
+			ksort($region_data, SORT_NATURAL);
+
 			$region_keys = array_keys($region_data);
 
 			$x_data_labels = array_map(function($key) {
@@ -625,8 +635,9 @@ if($submit) {
 			}
 
 			$chart = new Chart;
+			$chart->addYAxis("linear", "left", "y-axis-1", true, ["min" => 0, "max" => 100]);
 			$chart->setType("bar");
-			$chart->setTitle("Region Performance");
+			$chart->setTitle("Region Performance $date_range_label");
 			$chart->setLabels($x_data_labels);
 			$chart->addDataset("Performance (%)", $data_values , [
 				"background_colours" => "#2196F3"
@@ -635,13 +646,14 @@ if($submit) {
 
 			// Region Pass Rate Period
 			$chart = new Chart;
+			$chart->addYAxis("linear", "left", "y-axis-1", true, ["min" => 0, "max" => 100]);
 			$chart->setType("bar");
 			$chart->setTitle("Region Pass Rate by $resolution_name");
 			$chart->setLabels($x_data_labels);
 
 			foreach($keys as $index => $key) {
 				$data_values = [];
-				foreach($regions as $region) {
+				foreach($region_keys as $region) {
 					$r_data = $region_data[$region][$key];
 					$data_values[] = ($r_data->testCount == 0) ? 0 : round(($r_data->passCount * 100) / $r_data->testCount);
 				}
@@ -654,6 +666,8 @@ if($submit) {
 
 		if($has_area_managers) {
 
+			ksort($area_manager_data, SORT_NATURAL);
+
 			$area_manager_keys = array_keys($area_manager_data);
 
 			$x_data_labels = array_map(function($key) {
@@ -671,8 +685,9 @@ if($submit) {
 			}
 
 			$chart = new Chart;
+			$chart->addYAxis("linear", "left", "y-axis-1", true, ["min" => 0, "max" => 100]);
 			$chart->setType("bar");
-			$chart->setTitle("Area Manager Performance");
+			$chart->setTitle("Area Manager Performance $date_range_label");
 			$chart->setLabels($x_data_labels);
 			$chart->addDataset("Performance (%)", $data_values , [
 				"background_colours" => "#2196F3"
@@ -681,13 +696,14 @@ if($submit) {
 
 			// Area Pass Rate Period
 			$chart = new Chart;
+			$chart->addYAxis("linear", "left", "y-axis-1", true, ["min" => 0, "max" => 100]);
 			$chart->setType("bar");
 			$chart->setTitle("Area Manager Pass Rate by $resolution_name");
 			$chart->setLabels($x_data_labels);
 
 			foreach($keys as $index => $key) {
 				$data_values = [];
-				foreach($area_managers as $area_manager) {
+				foreach($area_manager_keys as $area_manager) {
 					$a_data = $area_manager_data[$area_manager][$key];
 					$data_values[] = ($a_data->testCount == 0) ? 0 : round(($a_data->passCount * 100) / $a_data->testCount);
 				}
@@ -712,7 +728,7 @@ if($submit) {
 
 
 View::includeOnce("header", compact("page_title"));
-View::include("performance", compact("customer", "date_range", "from_quarter", "to_quarter", "date_resolution", "all_projects", "project_ids", "charts", "data", "total_data", "locations_missing_region", "locations_missing_area_manager", "region_data"));
+View::include("performance", compact("customer", "date_range", "from_quarter", "to_quarter", "date_resolution", "all_projects", "project_ids", "charts", "data", "total_data", "locations_missing_region", "locations_missing_area_manager", "region_data", "area_manager_data"));
 View::includeOnce("footer");
 
 ?>

+ 9 - 0
controllers/project_add.php

@@ -38,9 +38,11 @@ if($submit) {
 		$project->min_age = http::value("min_age", "int");
 		$project->max_age = http::value("max_age", "int");
 		$project->default_tester_fee = http::value("default_tester_fee", "float");
+		$project->time_of_day = http::value("time_of_day", "trim");
 
 		$date_start = http::getDateFromFields("date_start");
 		$date_deadline = http::getDateFromFields("date_deadline");
+		$date_report = http::getDateFromFields("date_report");
 
 		$form_exception = new FormException;
 
@@ -54,16 +56,23 @@ if($submit) {
 		if(empty($project->min_age)) $form_exception->addError("Minimum age is required.");
 		if(empty($project->max_age)) $form_exception->addError("Maximum age is required.");
 		if(empty($project->default_tester_fee)) $form_exception->addError("Default tester fee is required.");
+		if(empty($project->time_of_day)) $form_exception->addError("Time of day is required.");
+		else if(!in_array($project->time_of_day, ["A", "D", "N"])) $form_exception->addError("Invalid time of day selected.");
 		if(empty($date_start)) $form_exception->addError("Start Date is required.");
 		if(empty($date_deadline)) $form_exception->addError("Deadline is required.");
 		if($project->min_age > $project->max_age) $form_exception->addError("Minimum age cannot be greater than maximum age.");
 
 		$unix_start = strtotime($date_start . " 00:00:00");
 		$unix_deadline = strtotime($date_deadline . " 23:59:59");
+		$unix_report = null;
+		if(!empty($date_report)) {
+			$unix_report = strtotime($date_report . " 12:00:00");
+		}
 
 		$project->dts_start = Util::getDateTime($unix_start);
 		$project->dts_deadline = Util::getDateTime($unix_deadline);
 		$project->dts_created = Util::getDateTime();
+		$project->dts_report = Util::getDateTime($unix_report);
 
 		if($unix_start > $unix_deadline) $form_exception->addError("Start Date cannot be after the Deadline.");
 

+ 2 - 0
controllers/project_ajax.php

@@ -206,6 +206,8 @@ if($submit) {
 						"levelText" => $user->getLevelText(),
 						"levelClass" => $user->getLevelClass(),
 						"termsAccepted" => boolval($user->terms_accepted),
+						"reported" => (int) $user->reported,
+						"reportedComment" => $user->reported_comment
 					];
 
 				}

+ 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);
 

+ 9 - 1
controllers/project_edit.php

@@ -39,9 +39,11 @@ if($submit) {
 		$project->min_age = http::value("min_age", "int");
 		$project->max_age = http::value("max_age", "int");
 		$project->default_tester_fee = http::value("default_tester_fee", "float");
+		$project->time_of_day = http::value("time_of_day", "trim");
 
 		$date_start = http::getDateFromFields("date_start");
 		$date_deadline = http::getDateFromFields("date_deadline");
+		$date_report = http::getDateFromFields("date_report");
 
 		$form_exception = new FormException;
 
@@ -55,16 +57,22 @@ if($submit) {
 		if(empty($project->min_age)) $form_exception->addError("Minimum age is required.");
 		if(empty($project->max_age)) $form_exception->addError("Maximum age is required.");
 		if(empty($project->default_tester_fee)) $form_exception->addError("Default tester fee is required.");
+		if(empty($project->time_of_day)) $form_exception->addError("Time of day is required.");
+		else if(!in_array($project->time_of_day, ["A", "D", "N"])) $form_exception->addError("Invalid time of day selected.");
 		if(empty($date_start)) $form_exception->addError("Start Date is required.");
 		if(empty($date_deadline)) $form_exception->addError("Deadline is required.");
 		if($project->min_age > $project->max_age) $form_exception->addError("Minimum age cannot be greater than maximum age.");
 
 		$unix_start = strtotime($date_start . " 00:00:00");
 		$unix_deadline = strtotime($date_deadline . " 23:59:59");
+		$unix_report = null;
+		if(!empty($date_report)) {
+			$unix_report = strtotime($date_report . " 12:00:00");
+		}
 
 		$project->dts_start = Util::getDateTime($unix_start);
 		$project->dts_deadline = Util::getDateTime($unix_deadline);
-		$project->dts_created = Util::getDateTime();
+		$project->dts_report = is_null($unix_rpeort) ? null : Util::getDateTime($unix_report);
 
 		if($unix_start > $unix_deadline) $form_exception->addError("Start Date cannot be after the Deadline.");
 

+ 33 - 0
controllers/project_kml.php

@@ -0,0 +1,33 @@
+<?php
+
+$project = Project::get($id);
+if(!$project) throw new Exception("Project cannot be found.");
+if(!Core::$user->hasPermission($project)) throw new Exception("You do not have permission to access this resource.");
+
+$slug = Util::slug($project->name);
+
+$locations = $project->getLocations();
+
+header("Content-Type: text/xml; charset=utf-8");
+//header("Content-Disposition: attachment; filename={$slug}-export.kml");
+
+$xml = simplexml_load_file(ROOT_DIR . "/files/empty.kml");
+
+$folder_node = $xml->addChild("Folder");
+$folder_node->addChild("name", $project->name);
+$folder_node->addChild("open", 1);
+$folder_node->addChild("description", $project->name . " Locations");
+
+foreach($locations as $location) {
+	$placemark_node = $folder_node->addChild("Placemark");
+
+	$placemark_node->addChild("name", htmlspecialchars($location->name));
+	$placemark_node->addChild("description", htmlspecialchars($location->getDisplayAddress()));
+
+	$point_node = $placemark_node->addChild("Point");
+	$point_node->addChild("coordinates", $location->longitude . "," . $location->latitude);
+}
+
+echo $xml->asXML();
+
+?>

+ 1 - 0
controllers/projects.php

@@ -19,6 +19,7 @@ if($id) $nvp["id"] = $id;
 if($name) $nvp["name"] = (new Constraint("CONTAINS"))->setValues($name);
 
 $projects = Project::query($nvp, ["sort" => "dts_deadline", "order" => "desc"]);
+$templates = Template::load(array_column($projects, "template_id"));
 
 $filter_count = count($nvp) - 1;
 

+ 5 - 0
controllers/test.php

@@ -318,6 +318,7 @@ else if(Core::$user->level >= User::LEVEL_ADMIN) {
 
 				$email_customer = http::value("email_customer");
 				$email_location = http::value("email_location");
+				$email_location_area_manager = http::value("email_location_area_manager");
 
 				if($email_customer && $customer->email_after_test && $customer->email) {
 					$test->sendResultEmail($customer->email);
@@ -327,6 +328,10 @@ else if(Core::$user->level >= User::LEVEL_ADMIN) {
 					$test->sendResultEmail($location->email);
 				}
 
+				if($email_location_area_manager && $customer->email_locations_after_test && $location->area_manager_email) {
+					$test->sendResultEmail($location->area_manager_email);
+				}
+
 				if(EMAIL_TEST_RESULT) {
 					$test->sendResultEmail(EMAIL_TEST_RESULT);
 				}

+ 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) {

+ 1 - 1
controllers/user_ajax.php

@@ -32,7 +32,7 @@ switch($action) {
 
 		$address_id = http::value("address_id", "int");
 		$max_distance = http::value("max_distance", "int");
-		if($max_distance <= 0) $max_distance = 25;
+		if($max_distance <= 0) $max_distance = 50;
 
 		$address = UserAddress::queryOne([
 			"id" => $address_id,

+ 2 - 0
controllers/user_edit.php

@@ -35,6 +35,8 @@ if($submit) {
 		$user->first_name = http::value("first_name", "trim");
 		$user->last_name = http::value("last_name", "trim");
 		$user->date_of_birth = http::getDateFromFields("date_of_birth");
+		$user->reported = http::value("reported", "int");
+		$user->reported_comment = http::value("reported_comment", "trim");
 		$user->phone = http::value("phone", "trim");
 		$user->gender = http::value("gender", "trim");
 		$user->activated = http::value("activated", "int");

+ 19 - 3
controllers/users.php

@@ -7,10 +7,14 @@ else {
 	$page_title = "Testers";
 }
 
-
 Core::addBreadcrumb("/account", "Account");
 Core::addBreadcrumb("/account/users", $page_title);
 
+$sorts = [
+	"newest" => "Newest",
+	"score" => "Score",
+];
+
 $id = http::value("id", "int");
 $first_name = http::value("first_name", "trim");
 $last_name = http::value("last_name", "trim");
@@ -34,7 +38,19 @@ if(empty($nvp)) {
 	$nvp["level"] = (new Constraint("NOT_EQUALS"))->setValues(User::LEVEL_REGISTERED);
 }
 
-$users = User::query($nvp);
+$sort = http::value("sort");
+switch($sort) {
+	case "score":
+		$query_options = ["sort" => "score", "order" => "desc"];
+		break;
+	default:
+		$sort = "newest";
+		$query_options = ["sort" => "id", "order" => "desc"];
+		break;
+}
+
+
+$users = User::query($nvp, $query_options);
 
 $pagination_object = Util::getPaginationObject($users);
 
@@ -45,7 +61,7 @@ $users = array_slice($users, $pagination_object->offset, $pagination_object->pag
 
 
 View::includeOnce("header", compact("page_title"));
-View::include("users", compact("users", "pagination_object", "filter_count", "id", "first_name", "last_name", "email", "level", "customer_id", "location_id"));
+View::include("users", compact("users", "pagination_object", "filter_count", "id", "first_name", "last_name", "email", "level", "customer_id", "location_id", "sort", "sorts"));
 View::includeOnce("modal_page_jump");
 View::includeOnce("footer");
 

+ 11 - 2
engine/chart.php

@@ -13,8 +13,9 @@ class Chart {
 		$this->id = bin2hex(random_bytes(8));
 	}
 
-	public function addYAxis($type, $position, $id, $grid_lines = true) {
-		$this->yAxes[] = [
+	public function addYAxis($type, $position, $id, $grid_lines = true, $tick_config = []) {
+
+		$axis = [
 			"type" => $type,
 			"display" => true,
 			"position" => $position,
@@ -23,6 +24,12 @@ class Chart {
 				"drawOnChartArea" => $grid_lines
 			],
 		];
+
+		if($tick_config) {
+			$axis["ticks"] = $tick_config;
+		}
+
+		$this->yAxes[] = $axis;
 	}
 
 	public function getID() {
@@ -48,6 +55,7 @@ class Chart {
 		$border_width = $options["border_width"] ?? false;
 		$y_axis_id = $options["y_axis_id"] ?? false;
 		$type = $options["type"] ?? false;
+		$datalabels = $options["datalabels"] ?? false;
 
 		$dataset = [
 			"label" => $label,
@@ -59,6 +67,7 @@ class Chart {
 		if($border_width) $dataset["borderWidth"] = (int) $border_width;
 		if($y_axis_id) $dataset["yAxisID"] = $y_axis_id;
 		if($type) $dataset["type"] = $type;
+		if($datalabels) $dataset["datalabels"] = $datalabels;
 
 		$this->datasets[] = $dataset;
 

+ 5 - 0
engine/form.php

@@ -2,6 +2,11 @@
 
 class Form {
 
+	const BOOLEAN_OPTIONS = [
+		0 => "No",
+		1 => "Yes",
+	];
+
 	public static function checked($value) {
 		return !empty($value) ? "checked" : "";
 	}

+ 1 - 1
engine/location.php

@@ -4,7 +4,7 @@ class Location extends Model {
 
 	protected static $table = "location";
 	protected static $id_field = "id";
-	protected static $fillable_fields = ["customer_id", "name", "legal_entity_name", "address_1", "address_2", "city", "county", "postal_code", "state", "country", "email", "phone", "opening_hours", "shop_left", "shop_right", "region", "internal_id", "area_manager", "closed", "latitude", "longitude", "dts_verified"];
+	protected static $fillable_fields = ["customer_id", "name", "legal_entity_name", "address_1", "address_2", "city", "county", "postal_code", "state", "country", "email", "phone", "opening_hours", "shop_left", "shop_right", "region", "internal_id", "area_manager", "area_manager_email", "closed", "latitude", "longitude", "dts_verified"];
 
 	// Object methods
 	public function getCustomer() {

+ 19 - 3
engine/project.php

@@ -4,7 +4,7 @@ class Project extends Model {
 
 	protected static $table = "project";
 	protected static $id_field = "id";
-	protected static $fillable_fields = ["customer_id", "template_id", "name", "test_count", "min_age", "max_age", "default_tester_fee", "dts_start", "dts_deadline", "dts_created", "dts_updated"];
+	protected static $fillable_fields = ["customer_id", "template_id", "name", "test_count", "min_age", "max_age", "default_tester_fee", "time_of_day", "dts_start", "dts_deadline", "dts_created", "dts_updated", "dts_report"];
 
 	protected static $field_map = [
 	];
@@ -24,8 +24,8 @@ class Project extends Model {
 	}
 
 	public function getLocations() {
-		$links = ProjectLocation::query(["project_id" => $this->id]);
-		return Location::query(["id" => array_column($links, "location_id")]);
+		$tests = $this->getTests();
+		return Location::query(["id" => array_column($tests, "location_id")]);
 	}
 
 	public function getDisplayAgeRange() {
@@ -62,6 +62,22 @@ class Project extends Model {
 		return Template::get($this->template_id);
 	}
 
+	public function getTimeOfDayText() {
+		switch($this->time_of_day) {
+			case "A": return "Anytime";
+			case "D": return "Daytime";
+			case "N": return "Nighttime";
+		}
+	}
+
+	public function getTimeOfDayIcon() {
+		switch($this->time_of_day) {
+			case "A": return "adjust";
+			case "D": return "sun";
+			case "N": return "moon";
+		}
+	}
+
 }
 
 ?>

+ 16 - 0
engine/template.php

@@ -11,6 +11,22 @@ 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 getURL() {
+		return "/account/templates/" . $this->id;
+	}
+
 	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];
 	}
 

+ 1 - 1
engine/user.php

@@ -4,7 +4,7 @@ class User extends Model {
 
 	protected static $table = "user";
 	protected static $id_field = "id";
-	protected static $fillable_fields = ["email", "old_id", "referrer_id", "password", "activated", "level", "score", "title", "first_name", "last_name", "gender", "date_of_birth", "phone", "verify_token", "reset_token", "terms_accepted", "preferred_payment_method", "bank_name", "bank_sort_code", "bank_account_number", "paypal_email", "dts_registered", "dts_last_seen", "dts_verified", "dts_deleted", "verifier_id", "verifier_notes"];
+	protected static $fillable_fields = ["email", "old_id", "referrer_id", "password", "activated", "level", "score", "title", "first_name", "last_name", "gender", "date_of_birth", "reported", "reported_comment", "phone", "verify_token", "reset_token", "terms_accepted", "preferred_payment_method", "bank_name", "bank_sort_code", "bank_account_number", "paypal_email", "dts_registered", "dts_last_seen", "dts_verified", "dts_deleted", "verifier_id", "verifier_notes"];
 
 	// Constants
 

+ 3 - 0
files/empty.kml

@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kml xmlns="http://www.opengis.net/kml/2.2">
+</kml>

BIN=BIN
files/id_response.pdf


BIN=BIN
files/machine_categories.pdf


BIN=BIN
files/testing_methodology.pdf


BIN=BIN
files/testing_procedure.pdf


+ 18 - 9
json/bacta.json → json/age_verification.json

@@ -9,21 +9,24 @@
 			"name": "shop_left",
 			"label": "Shop Name (Left)",
 			"maxLength": 32,
-			"required": true
+			"required": true,
+			"customerExport": false
 		},
 		{
 			"type": "text",
 			"name": "shop_right",
 			"label": "Shop Name (Right)",
 			"maxLength": 32,
-			"required": true
+			"required": true,
+			"customerExport": false
 		},
 		{
 			"type": "text",
 			"name": "attire",
 			"label": "Tester Clothing",
 			"maxLength": 50,
-			"required": true
+			"required": true,
+			"customerExport": false
 		},
 		{
 			"type": "file",
@@ -67,28 +70,32 @@
 			"type": "text",
 			"name": "challenger_name",
 			"label": "Name",
-			"maxLength": 32
+			"maxLength": 32,
+			"customerExport": false
 		},
 		{
 			"type": "textarea",
 			"name": "challenger_description",
 			"label": "Description",
 			"maxLength": 250,
-			"helpText": "Describe the person who challenged you and any comments you feel that are relevant. For example: \"She was about 150cm tall and had long red hair and glasses. She approached me and asked me if I wanted some water and then asked if I had any ID.\""
+			"helpText": "Describe the person who challenged you and any comments you feel that are relevant. For example: \"She was about 150cm tall and had long red hair and glasses. She approached me and asked me if I wanted some water and then asked if I had any ID.\"",
+			"customerExport": false
 		},
 		{
 			"type": "dropdown",
 			"name": "challenger_gender",
 			"label": "Gender",
 			"values": ["", "M", "F"],
-			"displayStrings": ["No challenge/Don't know", "M", "F"]
+			"displayStrings": ["No challenge/Don't know", "M", "F"],
+			"customerExport": false
 		},
 		{
 			"type": "dropdown",
 			"name": "challenger_eye_contact",
 			"label": "Eye Contact",
 			"values": ["", "0", "1"],
-			"displayStrings": ["No challenge/Don't know", "No", "Yes"]
+			"displayStrings": ["No challenge/Don't know", "No", "Yes"],
+			"customerExport": false
 		},
 
 		{
@@ -99,14 +106,16 @@
 			"type": "text",
 			"name": "play_machine",
 			"label": "Machine Played",
-			"maxLength": 20
+			"maxLength": 20,
+			"customerExport": false
 		},
 		{
 			"type": "dropdown",
 			"name": "play_jackpot",
 			"label": "Jackpot Value",
 			"values": ["", 5, 10, 15, 20, 25, 35, 50, 100, 500],
-			"displayStrings": ["Did not play/Don't know", "£5", "£10", "£15", "£20", "£25", "£35", "£50", "£100", "£500"]
+			"displayStrings": ["Did not play/Don't know", "£5", "£10", "£15", "£20", "£25", "£35", "£50", "£100", "£500"],
+			"customerExport": false
 		},
 		{
 			"type": "dropdown",

+ 0 - 189
json/default_template.json

@@ -1,189 +0,0 @@
-{
-	"beforeTest": [
-		{
-			"type": "header",
-			"content": "Before the Test"
-		},
-		{
-			"type": "text",
-			"name": "shop_left",
-			"label": "Shop Name (Left)",
-			"maxLength": 32,
-			"required": true
-		},
-		{
-			"type": "text",
-			"name": "shop_right",
-			"label": "Shop Name (Right)",
-			"maxLength": 32,
-			"required": true
-		},
-		{
-			"type": "text",
-			"name": "attire",
-			"label": "Tester Clothing",
-			"maxLength": 50,
-			"required": true
-		},
-		{
-			"type": "file",
-			"label": "Selfie",
-			"name": "selfie",
-			"required": true
-		},
-		{
-			"type": "file",
-			"label": "Location Photo",
-			"name": "location_photo",
-			"required": true
-		}
-	],
-	"duringTest": [
-		{
-			"type": "header",
-			"content": "Challenge Details"
-		},
-		{
-			"type": "dropdown",
-			"name": "challenge_stage",
-			"label": "Stage",
-			"values": ["", 1, 2, 3, 4, 5],
-			"displayStrings": ["Select stage", "Challenge on entry", "Challenge during browsing", "Challenge during play", "Challenge on exit", "No challenge"],
-			"required": true
-		},
-		{
-			"type": "textarea",
-			"name": "challenge_description",
-			"label": "Description",
-			"maxLength": 250,
-			"helpText": "Describe how the challenge took place. For example: \"While entering I was approached politely and asked for ID.\""
-		},
-
-		{
-			"type": "header",
-			"content": "Challenger Details (if challenged)"
-		},
-		{
-			"type": "text",
-			"name": "challenger_name",
-			"label": "Name",
-			"maxLength": 32
-		},
-		{
-			"type": "textarea",
-			"name": "challenger_description",
-			"label": "Description",
-			"maxLength": 250,
-			"helpText": "Describe the person who challenged you and any comments you feel that are relevant. For example: \"She was about 150cm tall and had long red hair and glasses. She approached me and asked me if I wanted some water and then asked if I had any ID.\""
-		},
-		{
-			"type": "dropdown",
-			"name": "challenger_gender",
-			"label": "Gender",
-			"values": ["", "M", "F"],
-			"displayStrings": ["No challenge/Don't know", "M", "F"]
-		},
-		{
-			"type": "dropdown",
-			"name": "challenger_eye_contact",
-			"label": "Eye Contact",
-			"values": ["", "0", "1"],
-			"displayStrings": ["No challenge/Don't know", "No", "Yes"]
-		},
-
-		{
-			"type": "header",
-			"content": "Play Details"
-		},
-		{
-			"type": "text",
-			"name": "play_machine",
-			"label": "Machine Played",
-			"maxLength": 32
-		},
-		{
-			"type": "dropdown",
-			"name": "play_jackpot",
-			"label": "Jackpot Value",
-			"values": ["", 5, 10, 15, 20, 25, 35, 50, 100, 500],
-			"displayStrings": ["Did not play/Don't know", "£5", "£10", "£15", "£20", "£25", "£35", "£50", "£100", "£500"]
-		},
-		{
-			"type": "dropdown",
-			"name": "play_machine_stake",
-			"label": "Stake Played",
-			"values": ["", 0.1, 0.2, 0.25, 0.3, 0.5, 1, 2],
-			"displayStrings": ["Did not play/Don't know", "10p", "20p", "25p", "30p", "50p", "£1", "£2"],
-			"helpText": "This is how much the machine charges you per spin."
-		},
-		{
-			"type": "dropdown",
-			"name": "play_minutes",
-			"label": "Time Played (Minutes)",
-			"values": ["", "1", "2", "3", "4", "5"],
-			"displayStrings": ["Did not play/Don't know", "1 minute", "2 minutes", "3 minutes", "4 minutes", "5 minutes or more"]
-		},
-		{
-			"type": "number",
-			"name": "play_spent",
-			"label": "Total Spent",
-			"maxLength": 10,
-			"min": 0,
-			"max": 20,
-			"step": 0.01,
-			"prependText": "£",
-			"helpText": "For example: Enter 1.50 if you have spent £1.50."
-		},
-
-		{
-			"type": "header",
-			"content": "Signage Details"
-		},
-		{
-			"type": "dropdown",
-			"name": "citizen_card_brochure_displayed",
-			"label": "Citizen Card Brochure Displayed",
-			"values": ["", "0", "1"],
-			"displayStrings": ["Don't know", "No", "Yes"]
-		},
-		{
-			"type": "dropdown",
-			"name": "think_21_25",
-			"label": "Think 21 or Think 25",
-			"values": ["", "Think 21", "Think 25"],
-			"displayStrings": ["Don't know", "Think 21", "Think 25"]
-		},
-		{
-			"type": "dropdown",
-			"name": "think_21_badge",
-			"label": "Think 21/25 Badge Worn by Staff",
-			"values": ["", "0", "1"],
-			"displayStrings": ["Don't know", "No", "Yes"]
-		},
-		{
-			"type": "dropdown",
-			"name": "think_21_poster",
-			"label": "Think 21/25 Poster Displayed",
-			"values": ["", "0", "1"],
-			"displayStrings": ["Don't know", "No", "Yes"]
-		},
-		{
-			"type": "textarea",
-			"name": "think_21_poster_notes",
-			"label": "Think 21/25 Poster Details",
-			"maxLength": 200,
-			"helpText": "Describe the location of the poster that was displayed."
-		},
-
-		{
-			"type": "header",
-			"content": "Notes"
-		},
-		{
-			"type": "textarea",
-			"name": "additional_notes",
-			"label": "Additional Notes",
-			"maxLength": 200
-		}
-	]
-}

+ 152 - 0
json/mystery_shop.json

@@ -0,0 +1,152 @@
+{
+	"beforeTest": [
+		{
+			"type": "header",
+			"content": "Before the Test"
+		},
+		{
+			"type": "text",
+			"name": "shop_left",
+			"label": "Shop Name (Left)",
+			"maxLength": 32,
+			"required": true
+		},
+		{
+			"type": "text",
+			"name": "shop_right",
+			"label": "Shop Name (Right)",
+			"maxLength": 32,
+			"required": true
+		},
+		{
+			"type": "text",
+			"name": "attire",
+			"label": "Tester Clothing",
+			"maxLength": 50,
+			"required": true
+		},
+		{
+			"type": "file",
+			"label": "Selfie",
+			"name": "selfie",
+			"required": true
+		},
+		{
+			"type": "file",
+			"label": "Location Photo",
+			"name": "location_photo",
+			"required": true
+		}
+	],
+	"duringTest": [
+		{
+			"type": "header",
+			"content": "Venue Details"
+		},
+		{
+			"type": "dropdown",
+			"name": "cleanliness",
+			"label": "Cleanliness",
+			"values": ["", 1, 2, 3, 4, 5],
+			"displayStrings": ["Select", "Very dirty", "Dirty", "Adequate", "Clean", "Very clean"],
+			"required": true
+		},
+
+		{
+			"type": "header",
+			"content": "Staff Details"
+		},
+
+		{
+			"type": "dropdown",
+			"name": "staff_badge_worn",
+			"label": "Staff Badge Worn",
+			"values": ["", "0", "1"],
+			"displayStrings": ["Don't know/Not approached", "No", "Yes"]
+		},
+
+		{
+			"type": "text",
+			"name": "staff_name",
+			"label": "Staff Name",
+			"maxLength": 32
+		},
+
+		{
+			"type": "dropdown",
+			"name": "staff_offered_drink",
+			"label": "Drink Offered",
+			"values": ["0", "1"],
+			"displayStrings": ["No", "Yes"]
+		},
+
+		{
+			"type": "text",
+			"name": "staff_offered_drink_name",
+			"label": "Drink Name",
+			"maxLength": 32,
+			"helpText": "Leave blank if no drink offered."
+		},
+
+		{
+			"type": "dropdown",
+			"name": "staff_offered_promotion",
+			"label": "Promotion Offered",
+			"values": ["0", "1"],
+			"displayStrings": ["No", "Yes"]
+		},
+
+		{
+			"type": "text",
+			"name": "staff_offered_promotion_name",
+			"label": "Promotion Name",
+			"maxLength": 200,
+			"helpText": "Leave blank if no drink offered."
+		},
+
+		{
+			"type": "dropdown",
+			"name": "staff_help",
+			"label": "Machine Explanation",
+			"values": ["0", "1"],
+			"displayStrings": ["No", "Yes"],
+			"helpText": "Did staff explain how the machines work and how to play them?"
+		},
+		{
+			"type": "dropdown",
+			"name": "staff_behaviour",
+			"label": "Staff Behaviour",
+			"values": ["", 1, 2, 3, 4, 5],
+			"displayStrings": ["N/A", "Rude", "Slightly rude", "Neither rude or polite", "Polite and friendly","Very polite and friendly"]
+		},
+
+		{
+			"type": "dropdown",
+			"name": "staff_uniform",
+			"label": "Staff Uniform",
+			"values": ["0", "1"],
+			"displayStrings": ["No", "Yes"]
+		},
+
+		{
+			"type": "textarea",
+			"name": "staff_uniform_description",
+			"label": "Staff Uniform Description",
+			"maxLength": 200,
+			"helpText": "For example: \"They were in uniform but they were wearing trainers.\""
+		},
+
+
+
+		{
+			"type": "header",
+			"content": "Notes"
+		},
+		{
+			"type": "textarea",
+			"name": "additional_notes",
+			"label": "Additional Notes",
+			"maxLength": 600
+		}
+	]
+}

BIN=BIN
psd/marker.psd


BIN=BIN
public/img/markers/building-blue.png


BIN=BIN
public/img/markers/building-green.png


BIN=BIN
public/img/markers/building-grey.png


BIN=BIN
public/img/markers/building-orange.png


BIN=BIN
public/img/markers/building-pink.png


BIN=BIN
public/img/markers/building-red.png


BIN=BIN
public/img/markers/user-green.png


BIN=BIN
public/img/markers/user-grey.png


BIN=BIN
public/img/markers/user-orange.png


BIN=BIN
public/img/markers/user-red.png


+ 86 - 3
public/js/app-locations.js

@@ -1,5 +1,13 @@
+var infoWindow = false;
+var exportIds = [];
+var markerMap = {};
+
 function initialiseLocations() {
 
+	if(!infoWindow) {
+		infoWindow = new google.maps.InfoWindow();
+	}
+
 	$.get("/api/customers/" + customerId + "/get-locations", {
 		id: $("#id").val(),
 		internal_id: $("#internal-id").val(),
@@ -27,22 +35,97 @@ function initialiseLocations() {
 			}
 
 			if(location.icon) {
-				options.icon = "/img/markers/" + location.icon;
+				options.icon = "/img/markers/building-red.png";
 			}
 
 			bounds.extend(position);
 
+			let key = "marker-" + location.id;
+
 			let marker = new google.maps.Marker(options);
-			marker.locationId = location.id;
+			marker.location = location;
 
 			marker.addListener("click", function() {
-				window.open("/account/locations/" + this.locationId, "_blank");
+				displayInfoWindow(this);
 			});
 
+			markerMap[key] = marker;
+
 		}
 
 		map.fitBounds(bounds);
 
 	});
 
+	$(document).on("click", "a[data-export-location-id]", function(event) {
+
+		let locationId = parseInt($(this).attr("data-export-location-id"));
+		let index = exportIds.indexOf(locationId);
+		let key = "marker-" + locationId;
+		let marker = markerMap[key];
+
+		if(index == -1) {
+			exportIds.push(locationId);
+			marker.setOptions({
+				icon: "/img/markers/building-green.png"
+			});
+		}
+		else {
+			exportIds.splice(index, 1);
+			marker.setOptions({
+				icon: "/img/markers/building-red.png"
+			});
+		}
+
+		displayInfoWindow(marker);
+	});
+
+	$("#export-csv-button, #export-kml-button").click(function(event) {
+
+		if(exportIds.length > 0) {
+			event.preventDefault();
+
+			let action = $(this).attr("data-action");
+
+			$("#locations-export-form input[name='ids[]']").remove();
+			$("#locations-export-form input[name='action']").val(action);
+
+			for(let i in exportIds) {
+				let locationId = exportIds[i];
+				$("#locations-export-form").append("<input type=\"hidden\" name=\"ids[]\" value=\"" + locationId + "\" />");
+			}
+
+			$("#locations-export-form").submit();
+		}
+
+	});
+
+}
+
+function displayInfoWindow(marker) {
+
+	let locationId = parseInt(marker.location.id);
+	let index = exportIds.indexOf(locationId);
+
+	let exportText = "Select for Export";
+	let exportClass = "btn-primary";
+
+	if(index > -1) {
+		exportText = "Deselect for Export";
+		exportClass = "btn-success";
+	}
+
+	let content = "<div class=\"container-fluid\" style=\"font-size: 1rem; font-weight: normal;\">";
+	content += "<p>" + marker.location.name + "</p>\n";
+
+	content += "<div class=\"row\">";
+
+	content += "<div class=\"col\"><a class=\"btn btn-block " + exportClass + "\" href=\"#\" data-export-location-id=\"" + marker.location.id + "\">" + exportText + "</a></div>";
+	content += "<div class=\"col\"><a class=\"btn btn-block btn-primary\" href=\"/account/locations/" + marker.location.id + "\" target=\"_blank\">View Details</a></div>";
+	content += "</div>";
+	content += "</div>";
+
+	infoWindow.setContent(content);
+	infoWindow.open(map, marker);
+
 }

+ 6 - 0
public/js/app-project.js

@@ -377,6 +377,10 @@ function initialiseTesters() {
 				td.append("<span class=\"badge badge-danger\" title=\"Terms and Conditions not accepted\">T&amp;C</span> ");
 			}
 
+			if(tester.reported) {
+				td.append("<span class=\"badge badge-danger\" data-toggle=\"tooltip\" data-title=\"" + tester.reportedComment + "\">Reported</span> ");
+			}
+
 			td.append("<span class=\"badge badge-" + tester.levelClass + "\">" + tester.levelText + "</span>");
 			td.append("<br />");
 			td.append($("<small>").text(tester.phone));
@@ -393,6 +397,8 @@ function initialiseTesters() {
 
 		$("#testers-table").append(tbody);
 
+		initialiseTooltips();
+
 	});
 }
 

+ 4 - 1
public/js/app.js

@@ -1,5 +1,4 @@
 $(function() {
-	$('[data-toggle="tooltip"]').tooltip();
 
 	$("#page-jump-button").click(function(event) {
 		let urlTemplate = $(this).data("url-template");
@@ -50,6 +49,10 @@ $(function() {
 
 var maps = [];
 
+function initialiseTooltips() {
+	$('[data-toggle="tooltip"]').tooltip();
+}
+
 function initialiseMaps() {
 
 	$("div[data-maps]").each(function() {

+ 1 - 0
routes.php

@@ -65,6 +65,7 @@ $routes = [
 	"/^account\/projects\/$id_pattern\/edit$/" => ["controller" => "project_edit", "params" => ["id"], "require_user_level" => User::LEVEL_ADMIN],
 	"/^account\/projects\/$id_pattern\/export-csv$/" => ["controller" => "project_csv", "params" => ["id"], "require_user_level" => User::LEVEL_ADMIN],
 	"/^account\/projects\/$id_pattern\/export-customer-csv$/" => ["controller" => "project_customer_csv", "params" => ["id"], "require_user_level" => User::LEVEL_ADMIN],
+	"/^account\/projects\/$id_pattern\/export-kml$/" => ["controller" => "project_kml", "params" => ["id"], "require_user_level" => User::LEVEL_ADMIN],
 	"/^account\/projects\/$id_pattern\/(get-locations|get-testers|create-test|assign-tester)$/" => ["controller" => "project_ajax", "params" => ["id", "action"], "type" => "json", "require_user_level" => User::LEVEL_ADMIN],
 
 	// Tests

+ 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);
+}
+
+?>

+ 87 - 0
template_processing/age_verification/project_customer_csv.php

@@ -0,0 +1,87 @@
+<?php
+
+$field_names = [
+	"Test Result",
+	"Location Name", "Address", "Region", "Internal ID", "Area Manager",
+
+	"Date",
+];
+
+foreach($fields as $field) {
+	$customer_export = $field->customerExport ?? true;
+	if(!$customer_export) continue;
+
+	$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 = [];
+
+	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) {
+
+		$customer_export = $field->customerExport ?? true;
+		if(!$customer_export) continue;
+
+		$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);
+}
+
+?>

+ 215 - 0
template_processing/mystery_shop/test_pdf.php

@@ -0,0 +1,215 @@
+<?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->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->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->Cell(30, $cell_height, "Postcode:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(100, $cell_height, $location->postal_code, 0, 1);
+
+$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->Cell(30, $cell_height, "Shop Name - Right:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(100, $cell_height, $test->shop_right, 0, 1);
+
+$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->Cell(20, $cell_height, "Gender:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(20, $cell_height, $tester->getGenderText(), 0, 1);
+
+$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);
+
+
+// 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->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() + $cell_height);
+
+// Venue Details
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->Cell(95, $cell_height, "Venue", 0, 1);
+
+$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->Cell(30, $cell_height, "Cleanliness:", 0, 0);
+$pdf->SetX($pdf->GetX() + 5);
+$pdf->Cell(57.5, $cell_height, $cleanliness, 0, 1);
+
+$pdf->SetY($pdf->GetY() + $cell_height);
+
+$pdf->SetFont("Arial", "B", $normal_font_size);
+$pdf->Cell(95, $cell_height, "Tester's Notes", 0, 1);
+$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->SetFont("Arial");
+
+$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);
+
+$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->SetY($pdf->GetY() + $cell_height);
+
+$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);
+
+$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->SetY($pdf->GetY() + $cell_height);
+
+$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);
+
+$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->SetY($pdf->GetY() + $cell_height);
+
+$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->SetY($pdf->GetY() + $cell_height);
+
+$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->SetY($pdf->GetY() + $cell_height);
+
+$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);
+
+$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);
+
+?>

+ 6 - 0
views/location_form.php

@@ -156,6 +156,12 @@ $tabs = [
 								<input class="form-control" type="text" name="area_manager" id="area-manager" placeholder="Enter area manager" value="<?=htmlspecialchars($location->area_manager)?>" />
 							</div>
 						</div>
+						<div class="row mb-1">
+							<label class="col-sm-4 col-form-label" for="area-manager-email">Area Manager Email Address</label>
+							<div class="col-sm">
+								<input class="form-control" type="email" name="area_manager_email" id="area-manager-email" placeholder="Enter area manager email address" value="<?=htmlspecialchars($location->area_manager_email)?>" />
+							</div>
+						</div>
 
 					</div>
 				</div>

+ 7 - 2
views/locations.php

@@ -37,7 +37,8 @@ var customerId = <?=$customer->id?>;
 				</button>
 				<div class="dropdown-menu dropdown-menu-right" aria-labelledby="actions-button">
 					<a class="dropdown-item" href="/account/locations/add?customer_id=<?=$customer->id?>/edit">Add</a>
-					<a class="dropdown-item" href="/account/locations?customer_id=<?=$customer->id?>&amp;action=export">Export CSV</a>
+					<a id="export-csv-button" class="dropdown-item" href="/account/locations?customer_id=<?=$customer->id?>&amp;action=export" data-action="export">Export CSV</a>
+					<a id="export-kml-button" class="dropdown-item" href="/account/locations?customer_id=<?=$customer->id?>&amp;action=export-kml" data-action="export-kml">Export KML</a>
 				</div>
 			</div>
 
@@ -129,4 +130,8 @@ var customerId = <?=$customer->id?>;
 	<?php
 	View::include("location_list", compact("locations"));
 	?>
-</div>
+</div>
+
+<form method="post" id="locations-export-form">
+	<input type="hidden" name="action" value="" />
+</form>

+ 99 - 1
views/performance.php

@@ -242,7 +242,7 @@ $date_range_custom_style = ($date_range == "custom") ? "" : "display: none";
 			</div>
 		</div>
 
-		<div class="row">
+		<div class="row mb-4">
 			<div class="col-md-4" style="position: relative;">
 				<h3>Chart List</h3>
 				<div class="list-group" style="position: sticky; top: 7rem;">
@@ -276,6 +276,104 @@ $date_range_custom_style = ($date_range == "custom") ? "" : "display: none";
 		</div>
 
 		<?php
+
+		if(PRODUCTION == false) {
+			?>
+			<h2>Debug Information</h2>
+
+			<h3>Region Data</h3>
+
+			<?php
+
+			foreach($region_data as $region => $rows) {
+
+				?>
+				<h4>Region: <?=htmlspecialchars($region)?></h4>
+
+				<table class="table">
+					<col style="width: 20%" />
+					<col style="width: 20%" />
+					<col style="width: 20%" />
+					<col style="width: 20%" />
+					<col style="width: 20%" />
+					<thead>
+						<tr>
+							<th>Key</th>
+							<th>Tests</th>
+							<th>Passes</th>
+							<th>Fails</th>
+							<th>Rate</th>
+						</tr>
+					</thead>
+					<tbody>
+					<?php
+					foreach($rows as $key => $data) {
+						$rate = ($data->testCount == 0) ? "0.00" : number_format(($data->passCount * 100) / $data->testCount, 2);
+						?>
+						<tr>
+							<td><?=htmlspecialchars($key)?></td>
+							<td><?=number_format($data->testCount)?></td>
+							<td><?=number_format($data->passCount)?></td>
+							<td><?=number_format($data->failCount)?></td>
+							<td><?=$rate?>%</td>
+						</tr>
+						<?php
+					}
+					?>
+					</tbody>
+				</table>
+
+				<?php
+
+			}
+
+			?>
+			<h3>Area Manager Data</h3>
+			<?php
+
+			foreach($area_manager_data as $area_manager => $rows) {
+
+				?>
+				<h4>Area Manager: <?=htmlspecialchars($area_manager)?></h4>
+
+				<table class="table">
+					<col style="width: 20%" />
+					<col style="width: 20%" />
+					<col style="width: 20%" />
+					<col style="width: 20%" />
+					<col style="width: 20%" />
+					<thead>
+						<tr>
+							<th>Key</th>
+							<th>Tests</th>
+							<th>Passes</th>
+							<th>Fails</th>
+							<th>Rate</th>
+						</tr>
+					</thead>
+					<tbody>
+					<?php
+					foreach($rows as $key => $data) {
+						$rate = ($data->testCount == 0) ? "0.00" : number_format(($data->passCount * 100) / $data->testCount, 2);
+						?>
+						<tr>
+							<td><?=htmlspecialchars($key)?></td>
+							<td><?=number_format($data->testCount)?></td>
+							<td><?=number_format($data->passCount)?></td>
+							<td><?=number_format($data->failCount)?></td>
+							<td><?=$rate?>%</td>
+						</tr>
+						<?php
+					}
+					?>
+					</tbody>
+				</table>
+
+				<?php
+
+			}
+		}
+
 	}
 	?>
 

+ 13 - 2
views/project.php

@@ -1,3 +1,10 @@
+<?php
+
+$time_of_day_icon = $project->getTimeOfDayIcon();
+$time_of_day_text = $project->getTimeOfDayText();
+
+?>
+
 <script>
 var projectID = <?=$project->id?>;
 </script>
@@ -7,7 +14,10 @@ var projectID = <?=$project->id?>;
 <div class="container pt-3 my-4">
 	<div class="row">
 		<div class="col-auto">
-			<h2><?=htmlspecialchars($project->name)?></h2>
+			<h2>
+				<?=htmlspecialchars($project->name)?>
+				<i class="fal fa-<?=$time_of_day_icon?>" data-toggle="tooltip" data-title="<?=$time_of_day_text?> Tests"></i>
+			</h2>
 		</div>
 		<div class="col text-right">
 		<?php
@@ -21,6 +31,7 @@ var projectID = <?=$project->id?>;
 					<a class="dropdown-item" href="/account/projects/<?=$project->id?>/edit">Edit</a>
 					<a class="dropdown-item" href="/account/projects/<?=$project->id?>/export-csv">Export CSV</a>
 					<a class="dropdown-item" href="/account/projects/<?=$project->id?>/export-customer-csv">Export Customer CSV</a>
+					<a class="dropdown-item" href="/account/projects/<?=$project->id?>/export-kml">Export KML</a>
 				</div>
 			</div>
 			<?php
@@ -48,7 +59,7 @@ var projectID = <?=$project->id?>;
 				<div class="card-body">
 					Pass/Fail Ratio
 					<div class="stat mb-3">
-						<?=number_format($pass_count)?> Pass / <?=number_format($fail_count)?> Fail
+						<?=number_format($pass_count)?> Pass / <?=number_format($fail_count)?> Fail (<?=intval($pass_percentage)?>%)
 					</div>
 					<div class="progress">
 						<div class="progress-bar bg-success" role="progressbar" style="width: <?=$pass_percentage?>%"></div>

+ 46 - 1
views/project_form.php

@@ -6,6 +6,18 @@ $date_start_parts = explode("-", $date_start);
 $date_deadline = explode(" ", date("Y-m-d H:i:s", strtotime($project->dts_deadline . " UTC")))[0];
 $date_deadline_parts = explode("-", $date_deadline);
 
+$date_report_parts = [0, 0, 0];
+if($project->dts_report) {
+	$date_report = explode(" ", date("Y-m-d H:i:s", strtotime($project->dts_report . " UTC")))[0];
+	$date_report_parts = explode("-", $date_report);
+}
+
+$time_of_day_options = [
+	"A" => "Anytime",
+	"D" => "Daytime",
+	"N" => "Nighttime",
+];
+
 ?>
 <div class="container mt-3 py-4">
 	<h2>
@@ -35,7 +47,7 @@ $date_deadline_parts = explode("-", $date_deadline);
 						foreach($templates as $template) {
 							$selected = ($template->id == $project->template_id) ? "selected" : "";
 							?>
-							<option value="<?=$template->id?>"><?=htmlspecialchars($template->name)?></option>
+							<option value="<?=$template->id?>" <?=$selected?>><?=htmlspecialchars($template->name)?></option>
 							<?php
 						}
 						?>
@@ -60,6 +72,21 @@ $date_deadline_parts = explode("-", $date_deadline);
 						</div>
 					</div>
 				</div>
+				<div class="row mb-1">
+					<label class="col-sm-4 col-form-label" for="time-of-day">Time of Day</label>
+					<div class="col-sm">
+						<select class="form-control" name="time_of_day" id="time-of-day" required>
+						<?php
+						foreach($time_of_day_options as $value => $display) {
+							$selected = ($value == $project->time_of_day) ? "selected" : "";
+							?>
+							<option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
+							<?php
+						}
+						?>
+						</select>
+					</div>
+				</div>
 			</div>
 			<div class="col-lg">
 
@@ -121,6 +148,24 @@ $date_deadline_parts = explode("-", $date_deadline);
 						</select>
 					</div>
 				</div>
+				<div class="row mb-1">
+					<label class="col-sm-4 col-form-label" for="date-report">Report Month</label>
+					<div class="col-sm">
+						<input name="date_report_day" id="date-report-day" value="12" type="hidden" />
+						<select class="form-control w-auto d-inline-block" name="date_report_month" id="date-report-month">
+							<option value="">Month</option>
+							<?php
+							Form::renderMonthOptions($date_report_parts[1]);
+							?>
+						</select>
+						<select class="form-control w-auto d-inline-block" name="date_report_year" id="date-report-year">
+							<option value="">Year</option>
+							<?php
+							Form::renderYearOptions(2017, date("Y") + 1, $date_report_parts[0]);
+							?>
+						</select>
+					</div>
+				</div>
 			</div>
 		</div>
 		<hr />

+ 21 - 0
views/project_list.php

@@ -3,7 +3,9 @@
 		<tr>
 			<th class="text-right pr-3">ID</th>
 			<th>Name</th>
+			<th>Template</th>
 			<th>Deadline</th>
+			<th>Report Month</th>
 			<th></th>
 		</tr>
 	</thead>
@@ -11,6 +13,18 @@
 	<?php
 	foreach($projects as $project) {
 		$date_deadline = explode(" ", $project->dts_deadline)[0];
+
+		$report_month = "N/A";
+		if($project->dts_report) {
+			$dt_report = new DateTime($project->dts_report . " UTC");
+			$report_month = $dt_report->format("M Y");
+		}
+
+		$time_of_day_icon = $project->getTimeOfDayIcon();
+		$time_of_day_text = $project->getTimeOfDayText();
+
+		$template = $project->getTemplate();
+
 		?>
 		<tr>
 			<td class="text-right pr-3 align-middle">
@@ -18,10 +32,17 @@
 			</td>
 			<td class="align-middle">
 				<a href="/account/projects/<?=$project->id?>"><?=htmlspecialchars($project->name)?></a>
+				<i class="fal fa-<?=$time_of_day_icon?>" data-toggle="tooltip" data-title="<?=$time_of_day_text?> Tests"></i>
+			</td>
+			<td class="align-middle">
+				<a href="<?=htmlspecialchars($template->getURL())?>"><?=htmlspecialchars($template->name)?></a>
 			</td>
 			<td class="align-middle">
 				<?=$date_deadline?>
 			</td>
+			<td class="align-middle">
+				<?=$report_month?>
+			</td>
 			<td class="text-right align-middle">
 				<a class="btn btn-outline-primary" href="/account/projects/<?=$project->id?>/edit">Edit</a>
 			</td>

+ 19 - 4
views/test_verify_form.php

@@ -295,10 +295,11 @@ function render_card_list_group($details) {
 							if($customer->email) {
 								?>
 								<div class="row mb-1">
-									<div class="col-sm offset-sm-4">
+									<div class="col-sm-4">Email Headquarters</div>
+									<div class="col-sm">
 										<div class="form-check">
 											<input class="form-check-input" type="checkbox" name="email_customer" id="email-customer" value="1" <?=Form::checked($customer->email_after_test)?> />
-											<label class="form-check-label" for="email-customer">Email Headquarters (<?=htmlspecialchars($customer->email)?>)</label>
+											<label class="form-check-label" for="email-customer"><?=htmlspecialchars($customer->email)?></label>
 										</div>
 									</div>
 								</div>
@@ -307,10 +308,24 @@ function render_card_list_group($details) {
 							if($location->email) {
 								?>
 								<div class="row mb-1">
-									<div class="col-sm offset-sm-4">
+									<div class="col-sm-4">Email Venue</div>
+									<div class="col-sm">
 										<div class="form-check">
 											<input class="form-check-input" type="checkbox" name="email_location" id="email-location" value="1" <?=Form::checked($customer->email_locations_after_test)?> />
-											<label class="form-check-label" for="email-location">Email Venue (<?=htmlspecialchars($location->email)?>)</label>
+											<label class="form-check-label" for="email-location"><?=htmlspecialchars($location->email)?></label>
+										</div>
+									</div>
+								</div>
+								<?php
+							}
+							if($location->area_manager_email) {
+								?>
+								<div class="row mb-1">
+									<div class="col-sm-4">Email Area Manager</div>
+									<div class="col-sm">
+										<div class="form-check">
+											<input class="form-check-input" type="checkbox" name="email_location_area_manager" id="email-location-area-manager" value="1" <?=Form::checked($customer->email_locations_after_test)?> />
+											<label class="form-check-label" for="email-location-area-manager"><?=htmlspecialchars($location->area_manager_email)?></label>
 										</div>
 									</div>
 								</div>

+ 5 - 0
views/user.php

@@ -17,8 +17,13 @@ $details = [
 	"Score" => number_format($user->score),
 	"Registered" => $user->dts_registered,
 	"Last Seen" => $user->dts_last_seen,
+	"Reported" => $user->reported ? "<span class=\"text-danger\"><i class=\"fas fa-exclamation-circle\"></i> Yes</span>" : "No"
 ];
 
+if($user->reported_comment) {
+	$details["Reported Notes"] = htmlspecialchars($user->reported_comment);
+}
+
 if($referrer) {
 	$details["Referrer"] = "<a href=\"/account/users/$referrer->id\">" . htmlspecialchars($referrer->getDisplayName()) . "</a>";
 }

+ 21 - 1
views/user_edit_form.php

@@ -136,12 +136,32 @@ var userId = <?=$user->id?>;
 						</select>
 					</div>
 				</div>
+				<div class="row mb-1">
+					<label class="col-sm-4 col-form-label" for="reported">Reported</label>
+					<div class="col-sm">
+						<select class="form-control" name="reported" id="reported" />
+						<?php
+						foreach(Form::BOOLEAN_OPTIONS as $value => $display) {
+							$selected = ($user->reported == $value) ? "selected" : "";
+							?>
+							<option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
+							<?php
+						}
+						?>
+						</select>
+					</div>
+				</div>
+				<div class="row mb-1">
+					<label class="col-sm-4 col-form-label" for="reported-comment">Reported Notes</label>
+					<div class="col-sm">
+						<textarea class="form-control" name="reported_comment" id="reported-comment" placeholder="Enter reported notes" rows="4"><?=htmlspecialchars($user->reported_comment)?></textarea>
+					</div>
+				</div>
 			</div>
 			<div class="col-lg-6 mb-3">
 
 				<h3>Addresses</h3>
 
-
 				<?php
 				$addresses = $user->getAddresses();
 				if(empty($addresses)) {

+ 44 - 4
views/users.php

@@ -1,12 +1,43 @@
+<?php
+
+$query = $_GET;
+unset($query["path"]);
+$query["sort"] = "SORT";
+
+?>
 <div class="container mt-3 py-4">
 	<div class="row">
 		<div class="col">
 			<h2>Users</h2>
 		</div>
 		<div class="col-auto">
-			<a class="btn btn-outline-primary" href="#filters" data-toggle="collapse">
-				Toggle Filters <span class="badge badge-pill badge-danger"><?=$filter_count?></span>
-			</a>
+			<div class="row">
+				<div class="col-auto">
+
+					<a class="btn btn-outline-primary" href="#filters" data-toggle="collapse">
+						Toggle Filters <span class="badge badge-pill badge-danger"><?=$filter_count?></span>
+					</a>
+				</div>
+				<div class="col">
+					<div class="input-group">
+						<div class="input-group-prepend">
+							<span class="input-group-text">
+								Sort
+							</span>
+						</div>
+						<select class="form-control" id="sort-dropdown" data-url-template="/account/users?<?=htmlspecialchars(http_build_query($query))?>">
+						<?php
+						foreach($sorts as $value => $display) {
+							$selected = ($value == $sort) ? "selected" : "";
+							?>
+							<option value="<?=$value?>" <?=$selected?>><?=$display?></option>
+							<?php
+						}
+						?>
+						</select>
+					</div>
+				</div>
+			</div>
 		</div>
 	</div>
 
@@ -129,7 +160,16 @@
 						<?=$user->id?>
 					</td>
 					<td class="align-middle">
-						<a href="/account/users/<?=$user->id?>"><?=htmlspecialchars($user->getDisplayName())?></a><br />
+						<a href="/account/users/<?=$user->id?>"><?=htmlspecialchars($user->getDisplayName())?></a>
+						<?php
+						if($user->reported) {
+							$comment = $user->reported_comment ?: "Reported";
+							?>
+							<span class="text-danger" data-toggle="tooltip" data-title="<?=htmlspecialchars($comment)?>"><i class="fas fa-exclamation-circle"></i></span>
+							<?php
+						}
+						?>
+						<br />
 						<small><?=htmlspecialchars($user->email)?> <?=$activated?></small>
 					</td>
 					<td class="text-center align-middle">