Przeglądaj źródła

Merge branch 'develop'

Alan Lam 8 lat temu
rodzic
commit
8761cde4d0
45 zmienionych plików z 2371 dodań i 209 usunięć
  1. 21 1
      controllers/account.php
  2. 28 0
      controllers/account_deactivate.php
  3. 32 0
      controllers/account_delete.php
  4. 12 0
      controllers/account_reactivate.php
  5. 5 6
      controllers/address_add.php
  6. 2 0
      controllers/address_edit.php
  7. 3 2
      controllers/location_add.php
  8. 2 0
      controllers/location_edit.php
  9. 714 0
      controllers/performance.php
  10. 4 2
      controllers/project_ajax.php
  11. 4 1
      controllers/project_csv.php
  12. 118 0
      controllers/project_customer_csv.php
  13. 6 2
      controllers/register.php
  14. 12 0
      controllers/terms_accept.php
  15. 11 0
      controllers/terms_and_conditions.php
  16. 19 0
      controllers/terms_decline.php
  17. 1 8
      controllers/test_confirm.php
  18. 3 0
      controllers/test_invoice.php
  19. 73 0
      controllers/user_ajax.php
  20. 110 0
      engine/chart.php
  21. 8 0
      engine/core.php
  22. 12 1
      engine/test.php
  23. 56 1
      engine/user.php
  24. 1 0
      package.json
  25. 9 0
      public/js/Chart.bundle.min.js
  26. 27 0
      public/js/app-performance.js
  27. 21 4
      public/js/app-project.js
  28. 118 2
      public/js/app-user.js
  29. 10 0
      public/js/chartjs-plugin-datalabels.min.js
  30. 4 0
      router.php
  31. 13 1
      routes.php
  32. 53 3
      views/account.php
  33. 24 0
      views/account_deactivate.php
  34. 28 0
      views/account_delete.php
  35. 4 0
      views/address_add_form.php
  36. 4 0
      views/address_edit_form.php
  37. 2 1
      views/footer.php
  38. 6 0
      views/location_form.php
  39. 14 1
      views/locations.php
  40. 282 0
      views/performance.php
  41. 10 3
      views/project.php
  42. 14 0
      views/register.php
  43. 200 0
      views/terms_and_conditions.php
  44. 23 0
      views/terms_decline.php
  45. 248 170
      views/user.php

+ 21 - 1
controllers/account.php

@@ -6,6 +6,7 @@ Core::addBreadcrumb("/account", $page_title);
 
 
 $users_pending_verification = 0;
 $users_pending_verification = 0;
 $tests_pending_verification = 0;
 $tests_pending_verification = 0;
+$tests_remaining = 0;
 
 
 $links = [];
 $links = [];
 
 
@@ -22,6 +23,7 @@ if(Core::$user->level >= User::LEVEL_ADMIN) {
 }
 }
 
 
 if(Core::$user->level >= User::LEVEL_CUSTOMER) {
 if(Core::$user->level >= User::LEVEL_CUSTOMER) {
+	$links["/account/performance"] = "Performance";
 	$links["/account/projects"] = "Projects";
 	$links["/account/projects"] = "Projects";
 	$links["/account/locations"] = "Locations";
 	$links["/account/locations"] = "Locations";
 	$links["/account/templates"] = "Templates";
 	$links["/account/templates"] = "Templates";
@@ -30,6 +32,10 @@ if(Core::$user->level >= User::LEVEL_CUSTOMER) {
 if(Core::$user->level >= User::LEVEL_TESTER) {
 if(Core::$user->level >= User::LEVEL_TESTER) {
 	$links["/account/tests"] = "Tests";
 	$links["/account/tests"] = "Tests";
 	$links["/account/practice"] = "Practice";
 	$links["/account/practice"] = "Practice";
+
+	$tests = Core::$user->getPendingTests();
+	$tests_remaining = count($tests);
+
 }
 }
 
 
 if(Core::$user->level == User::LEVEL_TESTER) {
 if(Core::$user->level == User::LEVEL_TESTER) {
@@ -41,14 +47,28 @@ if(Core::$user->level == User::LEVEL_REGISTERED) {
 	$links["/account/submit-id"] = "Submit ID";
 	$links["/account/submit-id"] = "Submit ID";
 }
 }
 
 
+if(!Core::$user->terms_accepted) {
+	$links = [];
+}
+
 $links["/account/settings"] = "Settings";
 $links["/account/settings"] = "Settings";
 
 
 asort($links);
 asort($links);
 
 
+// Actions
+$actions = [];
+if(Core::$user->level == User::LEVEL_DEACTIVATED) {
+	$actions["/account/reactivate"] = "Reactivate Account";
+}
+else if(Core::$user->level == User::LEVEL_TESTER) {
+	$actions["/account/deactivate"] = "Deactivate Account...";
+}
+$actions["/account/delete"] = "Delete Account...";
+
 $referrals = Core::$user->getReferrals();
 $referrals = Core::$user->getReferrals();
 
 
 View::includeOnce("header", compact("page_title"));
 View::includeOnce("header", compact("page_title"));
-View::include("account", compact("links", "referrals", "users_pending_verification", "tests_pending_verification"));
+View::include("account", compact("links", "actions", "referrals", "users_pending_verification", "tests_pending_verification", "tests_remaining"));
 View::includeOnce("footer");
 View::includeOnce("footer");
 
 
 ?>
 ?>

+ 28 - 0
controllers/account_deactivate.php

@@ -0,0 +1,28 @@
+<?php
+
+$page_title = "Deactivate Account";
+
+Core::addBreadcrumb("/account", "Account");
+Core::addBreadcrumb("/account/deactivate", $page_title);
+
+$submit = http::value("submit");
+if($submit) {
+	try {
+		Core::validateCSRFToken($submit);
+
+		$success = Core::$user->deactivate();
+		if(!$success) throw new Exception("Failed to deactivate account. Please try again later.");
+
+		Core::addAlert("success", "Deactivated account successfully.");
+		HTTP::redirect("/account");
+	}
+	catch(Exception $e) {
+		Core::addAlert("danger", $e->getMessage());
+	}
+}
+
+View::includeOnce("header", compact("page_title"));
+View::include("account_deactivate");
+View::includeOnce("footer");
+
+?>

+ 32 - 0
controllers/account_delete.php

@@ -0,0 +1,32 @@
+<?php
+
+$page_title = "Delete Account";
+
+Core::addBreadcrumb("/account", "Account");
+Core::addBreadcrumb("/account/delete", $page_title);
+
+$submit = http::value("submit");
+if($submit) {
+	try {
+		Core::validateCSRFToken($submit);
+
+		$user = Core::$user;
+		$success = $user->softDelete();
+		if(!$success) throw new Exception("Failed to delete account. Please try again later.");
+
+		Core::addAlert("success", "Account deleted successfully.");
+
+		unset($_SESSION["user_id"]);
+
+		HTTP::redirect("/register");
+	}
+	catch(Exception $e) {
+		Core::addAlert("danger", $e->getMessage());
+	}
+}
+
+View::includeOnce("header", compact("page_title"));
+View::include("account_delete");
+View::includeOnce("footer");
+
+?>

+ 12 - 0
controllers/account_reactivate.php

@@ -0,0 +1,12 @@
+<?php
+
+$user = Core::$user;
+$user->level = User::LEVEL_TESTER;
+$success = $user->commit();
+if(!$success) throw new Exception("Failed to update our records. Please try again later.");
+
+Core::addAlert("success", "Account reactivated successfully.");
+
+HTTP::redirect("/account");
+
+?>

+ 5 - 6
controllers/address_add.php

@@ -18,15 +18,15 @@ if($submit) {
 		$user_address->user_id = Core::$user->id;
 		$user_address->user_id = Core::$user->id;
 		$user_address->name = http::value("name", "trim");
 		$user_address->name = http::value("name", "trim");
 		$user_address->postal_code = http::value("postal_code", "trim");
 		$user_address->postal_code = http::value("postal_code", "trim");
+		$user_address->country = http::value("country", "trim");
 
 
 		if(empty($user_address->name)) $form_exception->addError("Name is required.");
 		if(empty($user_address->name)) $form_exception->addError("Name is required.");
-		if(empty($user_address->postal_code)) {
-			$form_exception->addError("Postal code is required.");
-		}
+		if(empty($user_address->postal_code)) $form_exception->addError("Postal code is required.");
+		else if(empty($user_address->country)) $form_exception->addError("Country is required.");
 		else {
 		else {
-			// Geocode the postal code
+			// Geocode the postal code and country
 			try {
 			try {
-				$results = Geolocation::geocode($user_address->postal_code);
+				$results = Geolocation::geocode($user_address->postal_code . ", " . $user_address->country);
 
 
 				$result = $results[0];
 				$result = $results[0];
 
 
@@ -36,7 +36,6 @@ if($submit) {
 					if(in_array("route", $types)) $user_address->address_1 = $component->long_name;
 					if(in_array("route", $types)) $user_address->address_1 = $component->long_name;
 					if(in_array("postal_town", $types)) $user_address->city = $component->long_name;
 					if(in_array("postal_town", $types)) $user_address->city = $component->long_name;
 					if(in_array("administrative_area_level_1", $types)) $user_address->state = $component->long_name;
 					if(in_array("administrative_area_level_1", $types)) $user_address->state = $component->long_name;
-					if(in_array("country", $types)) $user_address->country = $component->long_name;
 				}
 				}
 
 
 				$user_address->latitude = $result->geometry->location->lat;
 				$user_address->latitude = $result->geometry->location->lat;

+ 2 - 0
controllers/address_edit.php

@@ -18,6 +18,7 @@ if($submit) {
 		$user_address->city = http::value("city", "trim");
 		$user_address->city = http::value("city", "trim");
 		$user_address->county = http::value("county", "trim");
 		$user_address->county = http::value("county", "trim");
 		$user_address->postal_code = http::value("postal_code", "trim");
 		$user_address->postal_code = http::value("postal_code", "trim");
+		$user_address->country = http::value("country", "trim");
 		$user_address->max_radius_miles = http::value("max_radius_miles", "float");
 		$user_address->max_radius_miles = http::value("max_radius_miles", "float");
 
 
 		$user_address->latitude = http::value("latitude", "float");
 		$user_address->latitude = http::value("latitude", "float");
@@ -27,6 +28,7 @@ if($submit) {
 		if(empty($user_address->address_1)) $form_exception->addError("Address line 1 is required.");
 		if(empty($user_address->address_1)) $form_exception->addError("Address line 1 is required.");
 		if(empty($user_address->city)) $form_exception->addError("City is required.");
 		if(empty($user_address->city)) $form_exception->addError("City is required.");
 		if(empty($user_address->postal_code)) $form_exception->addError("Postal code is required.");
 		if(empty($user_address->postal_code)) $form_exception->addError("Postal code is required.");
+		if(empty($user_address->country)) $form_exception->addError("Country is required.");
 		if(empty($user_address->max_radius_miles)) $form_exception->addError("Max distance is required.");
 		if(empty($user_address->max_radius_miles)) $form_exception->addError("Max distance is required.");
 		if(!in_array($user_address->max_radius_miles, UserAddress::RADIUSES)) $form_exception->addError("Max distance is invalid.");
 		if(!in_array($user_address->max_radius_miles, UserAddress::RADIUSES)) $form_exception->addError("Max distance is invalid.");
 
 

+ 3 - 2
controllers/location_add.php

@@ -26,6 +26,7 @@ if($submit) {
 		$location->city = http::value("city", "trim");
 		$location->city = http::value("city", "trim");
 		$location->county = http::value("county", "trim");
 		$location->county = http::value("county", "trim");
 		$location->postal_code = http::value("postal_code", "trim");
 		$location->postal_code = http::value("postal_code", "trim");
+		$location->country = http::value("country", "trim");
 		$location->email = http::value("email", "email");
 		$location->email = http::value("email", "email");
 		$location->phone = http::value("phone", "trim");
 		$location->phone = http::value("phone", "trim");
 		$location->opening_hours = http::value("opening_hours", "trim");
 		$location->opening_hours = http::value("opening_hours", "trim");
@@ -42,17 +43,17 @@ if($submit) {
 		if(empty($location->address_1)) $form_exception->addError("Location line 1 is required.");
 		if(empty($location->address_1)) $form_exception->addError("Location line 1 is required.");
 		if(empty($location->city)) $form_exception->addError("City is required.");
 		if(empty($location->city)) $form_exception->addError("City is required.");
 		if(empty($location->postal_code)) $form_exception->addError("Postal code is required.");
 		if(empty($location->postal_code)) $form_exception->addError("Postal code is required.");
+		if(empty($location->country)) $form_exception->addError("Country is required.");
 
 
 		// Geocode
 		// Geocode
 		try {
 		try {
-			$results = Geolocation::geocode($location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]));
+			$results = Geolocation::geocode($location->getDisplayAddress(["address_1", "address_2", "city", "postal_code", "country"]));
 
 
 			$result = $results[0];
 			$result = $results[0];
 
 
 			foreach($result->address_components as $component) {
 			foreach($result->address_components as $component) {
 				$types = $component->types;
 				$types = $component->types;
 				if(in_array("administrative_area_level_1", $types)) $location->state = $component->long_name;
 				if(in_array("administrative_area_level_1", $types)) $location->state = $component->long_name;
-				if(in_array("country", $types)) $location->country = $component->long_name;
 			}
 			}
 
 
 			$location->latitude = $result->geometry->location->lat;
 			$location->latitude = $result->geometry->location->lat;

+ 2 - 0
controllers/location_edit.php

@@ -21,6 +21,7 @@ if($submit) {
 		$location->city = http::value("city", "trim");
 		$location->city = http::value("city", "trim");
 		$location->county = http::value("county", "trim");
 		$location->county = http::value("county", "trim");
 		$location->postal_code = http::value("postal_code", "trim");
 		$location->postal_code = http::value("postal_code", "trim");
+		$location->country = http::value("country", "trim");
 		$location->email = http::value("email", "email");
 		$location->email = http::value("email", "email");
 		$location->phone = http::value("phone", "trim");
 		$location->phone = http::value("phone", "trim");
 		$location->opening_hours = http::value("opening_hours", "trim");
 		$location->opening_hours = http::value("opening_hours", "trim");
@@ -42,6 +43,7 @@ if($submit) {
 		if(empty($location->address_1)) $form_exception->addError("Location line 1 is required.");
 		if(empty($location->address_1)) $form_exception->addError("Location line 1 is required.");
 		if(empty($location->city)) $form_exception->addError("City is required.");
 		if(empty($location->city)) $form_exception->addError("City is required.");
 		if(empty($location->postal_code)) $form_exception->addError("Postal code is required.");
 		if(empty($location->postal_code)) $form_exception->addError("Postal code is required.");
+		if(empty($location->country)) $form_exception->addError("Country is required.");
 
 
 		if(empty($location->latitude)) $form_exception->addError("Map location is required.");
 		if(empty($location->latitude)) $form_exception->addError("Map location is required.");
 		else if(empty($location->longitude)) $form_exception->addError("Map location is required.");
 		else if(empty($location->longitude)) $form_exception->addError("Map location is required.");

+ 714 - 0
controllers/performance.php

@@ -0,0 +1,714 @@
+<?php
+
+Core::addScript("public/js/Chart.bundle.min.js");
+Core::addScript("public/js/chartjs-plugin-datalabels.min.js");
+Core::addScript("public/js/app-performance.js");
+
+Core::addBreadcrumb("/account", "Account");
+Core::addBreadcrumb("/account/performance", "Performance");
+
+$customer = Customer::getForAdmin();
+if(!$customer) throw new Exception("You do not have permission to access this page.");
+
+$page_title = "$customer->name Performance";
+
+Core::addBreadcrumb("/account/performance?customer_id=$customer->id", $page_title);
+
+$date_range = http::value("date_range");
+if(!$date_range) $date_range = "ytd";
+
+$date_resolution = http::value("date_resolution");
+
+$from_quarter = http::value("from_quarter");
+$to_quarter = http::value("to_quarter");
+
+$all_projects = Project::query([
+	"customer_id" => $customer->id
+]);
+
+$data = [];
+$region_data = [];
+$area_manager_data = [];
+$total_data = false;
+
+$locations_missing_region = [];
+$locations_missing_area_manager = [];
+
+$charts = [];
+
+$colours = [
+	"#f44336",
+	"#673ab7",
+	"#03a9f4",
+	"#4caf50",
+	"#ffeb3b",
+	"#ff5722",
+	"#607d8b",
+	"#e91e63",
+	"#3f51b5",
+	"#00bcd4",
+	"#8bc34a",
+	"#ffc107",
+	"#795548",
+	"#9c27b0",
+	"#2196f3",
+	"#009688",
+	"#cddc39",
+	"#ff9800",
+	"#9e9e9e",
+];
+
+$project_ids = [];
+
+$submit = http::value("submit");
+if($submit) {
+	try {
+		Core::validateCSRFToken($submit);
+
+		$form_exception = new FormException;
+		if($form_exception->hasErrors()) throw $form_exception;
+
+
+		// Get all tests
+		$projects = Project::query([
+			"customer_id" => $customer->id
+		]);
+
+		$project_ids = array_column($projects, "id");
+
+		$tests = Test::query([
+			"project_id" => $project_ids,
+			"status" => Test::STATUS_COMPLETED
+		]);
+
+		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"));
+
+		uksort($regions, "strnatcasecmp");
+		uksort($area_managers, "strnatcasecmp");
+
+		foreach($regions as $region) {
+			$region_data[$region] = [];
+		}
+
+		foreach($area_managers as $area_manager) {
+			$area_manager_data[$area_manager] = [];
+		}
+
+		$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;
+		}
+
+		$min_year = date("Y");
+		$max_year = date("Y");
+
+		$min_unix = strtotime("$min_year-01-01 UTC");
+		$max_unix = strtotime("$max_year-12-31 23:59:59 UTC");
+
+		switch($date_range) {
+			case "ytd":
+				// Nothing to do
+				$date_range_label = "YTD";
+				break;
+
+			case "unbound":
+				// Work out year range
+				foreach($tests as $test) {
+					$dt = new DateTime($test->dts_start . " UTC");
+					$dt->setTimezone(new DateTimeZone(TIMEZONE));
+
+					$year = $dt->format("Y");
+
+					if($year < $min_year) $min_year = $year;
+					if($year > $max_year) $max_year = $year;
+				}
+				$date_range_label = "$min_year - $max_year";
+				break;
+
+			case "custom":
+				$check = strcmp($from_quarter, $to_quarter);
+				if($check > 0) {
+					$temp = $to_quarter;
+					$from_quarter = $to_quarter;
+					$to_quarter = $temp;
+				}
+
+				list($min_year, $min_quarter) = explode("-", $from_quarter);
+				list($max_year, $max_quarter) = explode("-", $to_quarter);
+
+				switch($min_quarter) {
+					case 1: $unix_string = "$min_year-01-01 UTC"; break;
+					case 2: $unix_string = "$min_year-04-01 UTC"; break;
+					case 3: $unix_string = "$min_year-07-01 UTC"; break;
+					case 4: $unix_string = "$min_year-10-01 UTC"; break;
+				}
+
+				$min_unix = strtotime($unix_string);
+
+				switch($max_quarter) {
+					case 1: $unix_string = "$max_year-03-31 23:59:59 UTC"; break;
+					case 2: $unix_string = "$max_year-06-30 23:59:59 UTC"; break;
+					case 3: $unix_string = "$max_year-09-30 23:59:59 UTC"; break;
+					case 4: $unix_string = "$max_year-12-31 23:59:59 UTC"; break;
+				}
+
+				$max_unix = strtotime($unix_string);
+
+				$date_range_label = "$min_year Q$min_quarter - $max_year Q$max_quarter";
+
+				break;
+		}
+
+		// Filter tests based on date range
+		$tests = array_filter($tests, function($test) use ($min_unix, $max_unix) {
+
+			$dt = new DateTime($test->dts_start . " UTC");
+			$unix = $dt->format("U");
+
+			if($unix < $min_unix) {
+				return false;
+			}
+			if($unix > $max_unix) {
+				return false;
+			}
+
+			return true;
+		});
+
+
+		$empty_data = (object) [
+			"label" => "",
+			"testCount" => 0,
+			"passCount" => 0,
+			"failCount" => 0,
+
+			"maleTesterCount" => 0,
+			"femaleTesterCount" => 0,
+			"maleChallengerCount" => 0,
+			"femaleChallengerCount" => 0,
+
+			"maleChallengeMaleCount" => 0,
+			"maleChallengeMalePassCount" => 0,
+
+			"maleChallengeFemaleCount" => 0,
+			"maleChallengeFemalePassCount" => 0,
+
+			"femaleChallengeMaleCount" => 0,
+			"femaleChallengeMalePassCount" => 0,
+
+			"femaleChallengeFemaleCount" => 0,
+			"femaleChallengeFemalePassCount" => 0,
+
+			"stage1Count" => 0,
+			"stage2Count" => 0,
+			"stage3Count" => 0,
+			"stage4Count" => 0,
+			"stage5Count" => 0,
+		];
+
+		$total_data = (object) [
+			"maleTesterCount" => 0,
+			"femaleTesterCount" => 0,
+			"maleChallengerCount" => 0,
+			"femaleChallengerCount" => 0,
+			"testCount" => 0,
+			"passCount" => 0,
+			"failCount" => 0,
+
+			"stage1Count" => 0,
+			"stage2Count" => 0,
+			"stage3Count" => 0,
+			"stage4Count" => 0,
+			"stage5Count" => 0,
+		];
+
+		$resolution_name = "";
+
+		// Initialise date-array based on date range and resolution
+		$keys = [];
+		$key_labels = [];
+
+		for($year = $min_year; $year <= $max_year; $year++) {
+			switch($date_resolution) {
+				case "monthly":
+
+					$resolution_name = "Month";
+
+					foreach(range(1, 12) as $month) {
+
+						$label = date("M Y", mktime(0, 0, 0, $month, 1, date("Y")));
+
+						$month = str_pad($month, 2, "0", STR_PAD_LEFT);
+						$key = "$year-$month";
+						$data[$key] = clone $empty_data;
+						$data[$key]->label = $label;
+
+						foreach($region_data as &$r) {
+							$r[$key] = clone $empty_data;
+							$r[$key]->label = $label;
+						}
+
+						foreach($area_manager_data as &$a) {
+							$a[$key] = clone $empty_data;
+							$a[$key]->label = $label;
+						}
+
+						$keys[] = $key;
+						$key_labels[] = $label;
+					}
+
+					break;
+
+				case "quarterly":
+				default:
+
+					$resolution_name = "Quarter";
+
+					foreach(range(1, 4) as $quarter) {
+
+						$label = "Q$quarter $year";
+
+						$key = "$year-$quarter";
+						$data[$key] = clone $empty_data;
+						$data[$key]->label = $label;
+
+						foreach($region_data as &$r) {
+							$r[$key] = clone $empty_data;
+							$r[$key]->label = $label;
+						}
+
+						foreach($area_manager_data as &$a) {
+							$a[$key] = clone $empty_data;
+							$a[$key]->label = $label;
+						}
+
+						$keys[] = $key;
+						$key_labels[] = $label;
+					}
+
+					break;
+			}
+		}
+
+		$max_unix = 0;
+
+		// Increment counts based on test results
+		foreach($tests as $test) {
+
+			$tester = $test->getTester();
+			$location = $test->getLocation();
+
+			$region = $location->region;
+			$area_manager = $location->area_manager;
+
+			$dt = new DateTime($test->dts_start . " UTC");
+			$dt->setTimezone(new DateTimeZone(TIMEZONE));
+
+			$unix = $dt->format("U");
+			$year = $dt->format("Y");
+			$month = $dt->format("m");
+			$quarter = ceil($month / 3);
+
+			if($unix > $max_unix) {
+				$max_unix = $unix;
+			}
+
+			switch($date_resolution) {
+				case "monthly":
+					$key = "$year-$month";
+					break;
+				case "quarterly":
+				default:
+					$key = "$year-$quarter";
+					break;
+			}
+
+			$total_data->testCount++;
+			$data[$key]->testCount++;
+			if($region) $region_data[$region][$key]->testCount++;
+			if($area_manager) $area_manager_data[$area_manager][$key]->testCount++;
+
+			$stage_key = "stage" . $test->challenge_stage . "Count";
+			$data[$key]->$stage_key++;
+
+			if($test->pass) {
+				$data[$key]->passCount++;
+				$total_data->passCount++;
+				if($region) $region_data[$region][$key]->passCount++;
+				if($area_manager) $area_manager_data[$area_manager][$key]->passCount++;
+			}
+			else {
+				$data[$key]->failCount++;
+				$total_data->failCount++;
+				if($region) $region_data[$region][$key]->failCount++;
+				if($area_manager) $area_manager_data[$area_manager][$key]->failCount++;
+			}
+
+			if($tester->gender == "M") {
+				$data[$key]->maleTesterCount++;
+				$total_data->maleTesterCount++;
+			}
+			if($tester->gender == "F") {
+				$data[$key]->femaleTesterCount++;
+				$total_data->femaleTesterCount++;
+			}
+
+			if($test->challenger_gender == "M") {
+				$data[$key]->maleChallengerCount++;
+				$total_data->maleChallengerCount++;
+			}
+			if($test->challenger_gender == "F") {
+				$data[$key]->femaleChallengerCount++;
+				$total_data->femaleChallengerCount++;
+			}
+
+			if($tester->gender == "M") {
+				if($test->challenger_gender == "M") {
+					$data[$key]->maleChallengeMaleCount++;
+					if($test->pass) $data[$key]->maleChallengeMalePassCount++;
+				}
+				if($test->challenger_gender == "F") {
+					$data[$key]->femaleChallengeMaleCount++;
+					if($test->pass) $data[$key]->femaleChallengeMalePassCount++;
+				}
+			}
+
+			if($tester->gender == "F") {
+				if($test->challenger_gender == "M") {
+					$data[$key]->maleChallengeFemaleCount++;
+					if($test->pass) $data[$key]->maleChallengeFemalePassCount++;
+				}
+				if($test->challenger_gender == "F") {
+					$data[$key]->femaleChallengeFemaleCount++;
+					if($test->pass) $data[$key]->femaleChallengeFemalePassCount++;
+				}
+			}
+		}
+
+		$current_month = date("m", $max_unix);
+		$current_quarter = ceil(date("n", $max_unix) / 3);
+
+		$x_data_labels = array_values(array_map(function($d) {
+			return $d->label;
+		}, $data));
+
+		// Current Period
+		if($date_resolution == "monthly") {
+			$key = date("Y") . "-" . $current_month;
+			$current_period_name = date("M Y", $max_unix);
+		}
+		if($date_resolution == "quarterly") {
+			$key = date("Y") . "-" . $current_quarter;
+			$current_period_name = "Q" . $current_quarter . " " . date("Y", $max_unix);
+		}
+
+		// Tests by Stage
+
+		$chart = new Chart;
+		$chart->setType("pie");
+		$chart->setTitle("Tests by Stage $date_range_label");
+		$chart->setLabels(["On Entry", "While Browsing", "During Play", "On Exit", "No Challenge"]);
+		$chart->addDataset("Counts", [
+			array_sum(array_column($data, "stage1Count")),
+			array_sum(array_column($data, "stage2Count")),
+			array_sum(array_column($data, "stage3Count")),
+			array_sum(array_column($data, "stage4Count")),
+			array_sum(array_column($data, "stage5Count")),
+		], [
+			"background_colours" => [
+				"#4CAF50",
+				"#FFEB3B",
+				"#FBC02D",
+				"#FFAB91",
+				"#F44336",
+			]
+		]);
+		$charts[] = $chart;
+
+
+		// Challenger Gender
+		$chart = new Chart;
+		$chart->setType("pie");
+		$chart->setTitle("Staff Gender $date_range_label");
+		$chart->setLabels(["Male", "Female"]);
+		$chart->addDataset("Counts", [
+			$total_data->maleChallengerCount,
+			$total_data->femaleChallengerCount,
+		], [
+			"background_colours" => [
+				"#2196F3",
+				"#E91E63",
+			]
+		]);
+		$charts[] = $chart;
+
+		// Tester Gender
+		$chart = new Chart;
+		$chart->setType("pie");
+		$chart->setTitle("Tester Gender $date_range_label");
+		$chart->setLabels(["Male", "Female"]);
+		$chart->addDataset("Counts", [
+			$total_data->maleTesterCount,
+			$total_data->femaleTesterCount,
+		], [
+			"background_colours" => [
+				"#2196F3",
+				"#E91E63",
+			]
+		]);
+		$charts[] = $chart;
+
+		// Pass / Fail
+		$chart = new Chart;
+		$chart->setType("pie");
+		$chart->setTitle("Pass / Fail $date_range_label");
+		$chart->setLabels(["Pass", "Fail"]);
+		$chart->addDataset("Counts", [
+			$total_data->passCount,
+			$total_data->failCount,
+		], [
+			"background_colours" => [
+				"#4CAF50",
+				"#F44336",
+			]
+		]);
+		$charts[] = $chart;
+
+		// Performance by Period
+		$performance = array_values(array_map(function($d) {
+			if($d->testCount == 0) return 0;
+			return round(($d->passCount / $d->testCount) * 100);
+		}, $data));
+
+		$chart = new Chart;
+		$chart->setType("bar");
+		$chart->setTitle("Performance by $resolution_name");
+		$chart->setLabels($x_data_labels);
+		$chart->addDataset("Performance (%)", $performance, [
+			"background_colours" => "#2196F3"
+		]);
+		$charts[] = $chart;
+
+		// Monthly Totals by Period
+
+		$test_counts = array_column($data, "testCount");
+		$pass_counts = array_column($data, "passCount");
+		$fail_counts = array_column($data, "failCount");
+
+		$chart = new Chart;
+		$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->addDataset("Test Count", $test_counts, [
+			"background_colours" => "#2196F3",
+			"type" => "bar",
+			"y_axis_id" => "y-axis-1",
+		]);
+		$chart->addDataset("Pass", $pass_counts, [
+			"background_colours" => "#4CAF50",
+			"type" => "bar",
+			"y_axis_id" => "y-axis-1",
+		]);
+		$chart->addDataset("Fail", $fail_counts, [
+			"background_colours" => "#F44336",
+			"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)
+
+		foreach($keys as $index => $key) {
+			$key_label = $key_labels[$index];
+
+			$period_data = $data[$key];
+
+			if($period_data->testCount == 0) continue;
+
+			$chart = new Chart;
+			$chart->setType("pie");
+			$chart->setTitle("$key_label Point of Challenge");
+			$chart->setLabels(["On Entry", "While Browsing", "During Play", "On Exit", "No Challenge"]);
+			$chart->addDataset("Counts", [
+				$period_data->stage1Count,
+				$period_data->stage2Count,
+				$period_data->stage3Count,
+				$period_data->stage4Count,
+				$period_data->stage5Count,
+			], [
+				"background_colours" => [
+					"#4CAF50",
+					"#FFEB3B",
+					"#FBC02D",
+					"#FFAB91",
+					"#F44336",
+				]
+			]);
+			$charts[] = $chart;
+		}
+
+
+
+
+
+		// Tester Genders by Period
+		$male_counts = array_values(array_map(function($d) {
+			return $d->maleTesterCount;
+		}, $data));
+
+		$female_counts = array_values(array_map(function($d) {
+			return $d->femaleTesterCount;
+		}, $data));
+
+		$chart = new Chart;
+		$chart->setType("bar");
+		$chart->setTitle("Tester Gender by $resolution_name");
+		$chart->setLabels($x_data_labels);
+		$chart->addDataset("Male", $male_counts, [
+			"background_colours" => "#2196F3"
+		]);
+		$chart->addDataset("Female", $female_counts, [
+			"background_colours" => "#E91E63"
+		]);
+		$charts[] = $chart;
+
+		// Test Count by Period
+		$test_counts = array_values(array_map(function($d) {
+			return $d->testCount;
+		}, $data));
+
+		$chart = new Chart;
+		$chart->setType("bar");
+		$chart->setTitle("Tests by $resolution_name");
+		$chart->setLabels($x_data_labels);
+		$chart->addDataset("Tests", $test_counts, [
+			"background_colours" => "#2196F3"
+		]);
+		$charts[] = $chart;
+
+		$pass_counts = array_column($data, "passCount");
+		$fail_counts = array_column($data, "failCount");
+
+
+		if($has_regions) {
+
+			$x_data_labels = array_map(function($key) {
+				return "Region $key";
+			}, $regions);
+
+			// Region Performance (Selected Date Range)
+			$data_values = [];
+			foreach($region_data as $region => $r_data) {
+				$total_region_test_count = array_sum(array_column($r_data, "testCount"));
+				$total_region_pass_count = array_sum(array_column($r_data, "passCount"));
+
+				$data_values[] = ($total_region_test_count == 0) ? 0 : round(($total_region_pass_count * 100) / $total_region_test_count);
+			}
+
+			$chart = new Chart;
+			$chart->setType("bar");
+			$chart->setTitle("Region Performance");
+			$chart->setLabels($x_data_labels);
+			$chart->addDataset("Performance", $data_values , [
+				"background_colours" => "#2196F3"
+			]);
+			$charts[] = $chart;
+
+			// Region Performance by Period
+			$chart = new Chart;
+			$chart->setType("bar");
+			$chart->setTitle("Region Performance by $resolution_name");
+			$chart->setLabels($x_data_labels);
+
+			foreach($keys as $index => $key) {
+				$data_values = [];
+				foreach($regions as $region) {
+					$r_data = $region_data[$region][$key];
+					$data_values[] = ($r_data->testCount == 0) ? 0 : round(($r_data->passCount * 100) / $r_data->testCount);
+				}
+				$chart->addDataset($key_labels[$index], $data_values, ["background_colours" => $colours[$index]]);
+			}
+
+			$charts[] = $chart;
+
+		}
+
+		if($has_area_managers) {
+
+			$x_data_labels = array_map(function($key) {
+				return "$key";
+			}, $area_managers);
+
+			// Area Performance (Selected Date Range)
+			$data_values = [];
+			foreach($area_manager_data as $area_manager => $a_data) {
+				$total_area_manager_test_count = array_sum(array_column($a_data, "testCount"));
+				$total_area_manager_pass_count = array_sum(array_column($a_data, "passCount"));
+				$total_area_manager_fail_count = array_sum(array_column($a_data, "failCount"));
+
+				$data_values[] = ($total_region_test_count == 0) ? 0 : round(($total_area_manager_pass_count * 100) / $total_area_manager_test_count);
+			}
+
+			$chart = new Chart;
+			$chart->setType("bar");
+			$chart->setTitle("Area Manager Performance");
+			$chart->setLabels($x_data_labels);
+			$chart->addDataset("Performance", $data_values , [
+				"background_colours" => "#2196F3"
+			]);
+			$charts[] = $chart;
+
+			// Area Performance by Period
+			$chart = new Chart;
+			$chart->setType("bar");
+			$chart->setTitle("Area Manager Performance by $resolution_name");
+			$chart->setLabels($x_data_labels);
+
+			foreach($keys as $index => $key) {
+				$data_values = [];
+				foreach($area_managers 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);
+				}
+				$chart->addDataset($key_labels[$index], $data_values, ["background_colours" => $colours[$index]]);
+			}
+
+			$charts[] = $chart;
+
+		}
+
+
+
+	}
+	catch(FormException $e) {
+		$e->generateAlerts();
+	}
+	catch(Exception $e) {
+		Core::addAlert("danger", $e->getMessage());
+	}
+
+}
+
+
+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::includeOnce("footer");
+
+?>

+ 4 - 2
controllers/project_ajax.php

@@ -90,11 +90,11 @@ if($submit) {
 				break;
 				break;
 			}
 			}
 
 
-
 			// Gets testers near a project
 			// Gets testers near a project
 			case "get-testers": {
 			case "get-testers": {
 
 
 				$location_id = http::value("location_id", "int");
 				$location_id = http::value("location_id", "int");
+				$include_unverified = http::value("include_unverified", "int");
 				$location = Location::get($location_id);
 				$location = Location::get($location_id);
 				if(!$location) throw new Exception("Location not found.");
 				if(!$location) throw new Exception("Location not found.");
 
 
@@ -157,9 +157,10 @@ if($submit) {
 					$is_current_tester = $user->id == $test->tester_id;
 					$is_current_tester = $user->id == $test->tester_id;
 					$is_deactivated = $user->level == User::LEVEL_DEACTIVATED;
 					$is_deactivated = $user->level == User::LEVEL_DEACTIVATED;
 					$is_registered = $user->level == User::LEVEL_REGISTERED;
 					$is_registered = $user->level == User::LEVEL_REGISTERED;
-					$is_unverified = $user->level == User::LEVEL_UNVERIFIED;
+					$is_unverified = $user->level <= User::LEVEL_UNVERIFIED;
 
 
 					if($is_deactivated) continue;
 					if($is_deactivated) continue;
+					if(!$include_unverified && $is_unverified) continue;
 
 
 					$distance_miles = Geolocation::getDistance($location->getGeolocation(), $address->getGeolocation());
 					$distance_miles = Geolocation::getDistance($location->getGeolocation(), $address->getGeolocation());
 					$distance_kilometers = $distance_miles * Geolocation::KMS_IN_MILE;
 					$distance_kilometers = $distance_miles * Geolocation::KMS_IN_MILE;
@@ -204,6 +205,7 @@ if($submit) {
 						"isUnverified" => $is_unverified,
 						"isUnverified" => $is_unverified,
 						"levelText" => $user->getLevelText(),
 						"levelText" => $user->getLevelText(),
 						"levelClass" => $user->getLevelClass(),
 						"levelClass" => $user->getLevelClass(),
+						"termsAccepted" => boolval($user->terms_accepted),
 					];
 					];
 
 
 				}
 				}

+ 4 - 1
controllers/project_csv.php

@@ -38,7 +38,7 @@ $field_names = [
 	"Template Name",
 	"Template Name",
 	"Test ID", "Test Status", "Test Result",
 	"Test ID", "Test Status", "Test Result",
 	"Location Name", "Legal Entity", "Address", "Email", "Phone", "Region", "Internal ID", "Area Manager",
 	"Location Name", "Legal Entity", "Address", "Email", "Phone", "Region", "Internal ID", "Area Manager",
-	"Tester Age", "Tester Gender",
+	"Tester Age", "Tester Gender", "Travel Costs",
 
 
 	"Date", "Start Time", "End Time", "Duration",
 	"Date", "Start Time", "End Time", "Duration",
 ];
 ];
@@ -64,6 +64,7 @@ foreach($tests as $test) {
 
 
 	$age = "";
 	$age = "";
 	$gender = "";
 	$gender = "";
+	$travel_costs = "";
 
 
 	$output = [];
 	$output = [];
 	$output[] = $id;
 	$output[] = $id;
@@ -90,6 +91,7 @@ foreach($tests as $test) {
 			$dob_diff = $test_start_dt->diff($tester_dob_dt, true);
 			$dob_diff = $test_start_dt->diff($tester_dob_dt, true);
 			$age = $dob_diff->y;
 			$age = $dob_diff->y;
 			$gender = $tester->gender;
 			$gender = $tester->gender;
+			$travel_costs = $test->test_travel_costs;
 		}
 		}
 	}
 	}
 
 
@@ -105,6 +107,7 @@ foreach($tests as $test) {
 	$output[] = $location->area_manager;
 	$output[] = $location->area_manager;
 	$output[] = $age;
 	$output[] = $age;
 	$output[] = $gender;
 	$output[] = $gender;
+	$output[] = $travel_costs;
 	$output[] = $test_date;
 	$output[] = $test_date;
 	$output[] = $test_start;
 	$output[] = $test_start;
 	$output[] = $test_end;
 	$output[] = $test_end;

+ 118 - 0
controllers/project_customer_csv.php

@@ -0,0 +1,118 @@
+<?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.");
+
+header("Content-Type: text/csv");
+header("Content-Disposition: attachment; filename=\"export.csv\"");
+header("Cache-Control: private, max-age=0, must-revalidate");
+header("Pragma: public");
+
+$template = $project->getTemplate();
+
+$object = json_decode($template->json);
+
+$fields_1 = $object->beforeTest;
+$fields_2 = $object->duringTest;
+
+$fields = array_merge($fields_1, $fields_2);
+$fields = array_filter($fields, function($field) {
+	if(!isset($field->name)) return false;
+	if($field->type == "file") return false;
+	return true;
+});
+
+$tests = Test::query([
+	"project_id" => $id,
+	"status" => (new Constraint("NOT_EQUALS"))->setValues(Test::STATUS_CANCELLED),
+]);
+
+$locations = Location::load(array_column($tests, "location_id"));
+$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);
+}
+
+fclose($handle);
+
+?>

+ 6 - 2
controllers/register.php

@@ -31,9 +31,11 @@ try {
 		$user->gender = http::value("gender", "trim");
 		$user->gender = http::value("gender", "trim");
 		$user->date_of_birth = http::getDateFromFields("date_of_birth");
 		$user->date_of_birth = http::getDateFromFields("date_of_birth");
 		$user->phone = http::value("phone", "trim");
 		$user->phone = http::value("phone", "trim");
+		$user->terms_accepted = http::value("terms_accepted", "int");
 		$user->dts_registered = gmdate("Y-m-d H:i:s");
 		$user->dts_registered = gmdate("Y-m-d H:i:s");
 
 
 		$user_address->postal_code = http::value("postal_code");
 		$user_address->postal_code = http::value("postal_code");
+		$user_address->country = http::value("country");
 
 
 		// Referrer
 		// Referrer
 		$referrer_id = http::value("r", "int");
 		$referrer_id = http::value("r", "int");
@@ -48,15 +50,17 @@ try {
 		if(empty($user->last_name)) $form_exception->addError("Last name is required.");
 		if(empty($user->last_name)) $form_exception->addError("Last name is required.");
 		if(empty($user->date_of_birth)) $form_exception->addError("Date of birth is required.");
 		if(empty($user->date_of_birth)) $form_exception->addError("Date of birth is required.");
 		if(empty($user->phone)) $form_exception->addError("Mobile number is required.");
 		if(empty($user->phone)) $form_exception->addError("Mobile number is required.");
+		if(empty($user->terms_accepted)) $form_exception->addError("Acceptance of Terms and Conditions is required.");
 
 
 		if(empty($user_address->postal_code)) $form_exception->addError("Postal code is required.");
 		if(empty($user_address->postal_code)) $form_exception->addError("Postal code is required.");
+		if(empty($user_address->country)) $form_exception->addError("Country is required.");
 
 
 		$email_exists = User::query(["email" => $user->email]);
 		$email_exists = User::query(["email" => $user->email]);
 		if($email_exists) $form_exception->addError("Email address is already registered.");
 		if($email_exists) $form_exception->addError("Email address is already registered.");
 
 
 		// Geocode the postal code
 		// Geocode the postal code
 		try {
 		try {
-			$results = Geolocation::geocode($user_address->postal_code);
+			$results = Geolocation::geocode($user_address->postal_code . ", " . $user_address->country);
 
 
 			$result = $results[0];
 			$result = $results[0];
 
 
@@ -73,7 +77,7 @@ try {
 			$user_address->longitude = $result->geometry->location->lng;
 			$user_address->longitude = $result->geometry->location->lng;
 		}
 		}
 		catch(Exception $e) {
 		catch(Exception $e) {
-			$form_exception->addError("Failed to get location from postal code.");
+			$form_exception->addError("Failed to get location from postal code and country.");
 		}
 		}
 
 
 		if($form_exception->hasErrors()) {
 		if($form_exception->hasErrors()) {

+ 12 - 0
controllers/terms_accept.php

@@ -0,0 +1,12 @@
+<?php
+
+$user = Core::$user;
+$user->terms_accepted = 1;
+$success = $user->commit();
+if(!$success) throw new Exception("Failed to update our records. Please try again later.");
+
+Core::addAlert("success", "Terms and Conditions accepted successfully.");
+
+HTTP::redirect("/account");
+
+?>

+ 11 - 0
controllers/terms_and_conditions.php

@@ -0,0 +1,11 @@
+<?php
+
+$page_title = "Terms and Conditions";
+
+Core::addBreadcrumb("/terms-and-conditions", $page_title);
+
+View::includeOnce("header", compact("page_title"));
+View::include("terms_and_conditions");
+View::includeOnce("footer");
+
+?>

+ 19 - 0
controllers/terms_decline.php

@@ -0,0 +1,19 @@
+<?php
+
+$page_title = "Decline Terms & Conditions";
+
+Core::addBreadcrumb("/account", "Account");
+Core::addBreadcrumb("/account/decline-terms", $page_title);
+
+$user = Core::$user;
+$user->terms_accepted = 0;
+$success = $user->commit();
+if(!$success) throw new Exception("Failed to update our records. Please try again later.");
+
+View::includeOnce("header", compact("page_title"));
+View::include("terms_decline");
+View::includeOnce("footer");
+
+
+
+?>

+ 1 - 8
controllers/test_confirm.php

@@ -19,14 +19,7 @@ switch($action) {
 
 
 	case "decline":
 	case "decline":
 
 
-		$test->sendDeclineEmail();
-
-		$test->status = Test::STATUS_UNASSIGNED;
-		$test->tester_id = null;
-		$test->dts_due = null;
-		$test->dts_assigned = null;
-		$test->dts_updated = Util::getDateTime();
-		$test->commit();
+		$test->decline();
 
 
 		Core::addAlert("success", "Test declined successfully.");
 		Core::addAlert("success", "Test declined successfully.");
 		HTTP::redirect("/account/tests");
 		HTTP::redirect("/account/tests");

+ 3 - 0
controllers/test_invoice.php

@@ -20,6 +20,9 @@ $travel_cost = (float) http::value("travel_cost", "float");
 
 
 $invoice_total = $fee + $play_spent + $travel_cost;
 $invoice_total = $fee + $play_spent + $travel_cost;
 
 
+$test->test_travel_cost = $travel_cost;
+$test->commit();
+
 $address = $tester->getInvoiceAddress();
 $address = $tester->getInvoiceAddress();
 if(!$address) throw new Exception("Invoice address not found. Please set an address as the invoice address then try again.");
 if(!$address) throw new Exception("Invoice address not found. Please set an address as the invoice address then try again.");
 if(!$tester->hasValidPaymentMethod()) throw new Exception("No valid payment method found. Please go to the Settings page and make sure all respective fields are filled in and then try again.");
 if(!$tester->hasValidPaymentMethod()) throw new Exception("No valid payment method found. Please go to the Settings page and make sure all respective fields are filled in and then try again.");

+ 73 - 0
controllers/user_ajax.php

@@ -24,5 +24,78 @@ switch($action) {
 			"addresses" => $output
 			"addresses" => $output
 		]);
 		]);
 
 
+		break;
+
+	case "get-locations":
+
+		$output = [];
+
+		$address_id = http::value("address_id", "int");
+		$max_distance = http::value("max_distance", "int");
+		if($max_distance <= 0) $max_distance = 25;
+
+		$address = UserAddress::queryOne([
+			"id" => $address_id,
+			"user_id" => $id,
+		]);
+
+		if(!$address) throw new Exception("Cannot find address.");
+
+		$bounds = Geolocation::getBounds($address->getGeolocation(), $max_distance);
+
+		list($min_lat, $min_lng) = $bounds->southWest;
+		list($max_lat, $max_lng) = $bounds->northEast;
+
+		$locations = Location::query([
+			"latitude" => (new Constraint("BETWEEN"))->setValues($min_lat, $max_lat),
+			"longitude" => (new Constraint("BETWEEN"))->setValues($min_lng, $max_lng),
+			"closed" => 0
+		]);
+
+		$customers = Customer::load(array_column($locations, "customer_id"));
+
+		usort($locations, function($a, $b) use ($address) {
+			return
+			Geolocation::getDistance($address->getGeolocation(), $a->getGeolocation())
+			<=>
+			Geolocation::getDistance($address->getGeolocation(), $b->getGeolocation());
+		});
+
+		foreach($locations as $location) {
+
+			$distance = Geolocation::getDistance($address->getGeolocation(), $location->getGeolocation());
+			if($distance > $max_distance) continue;
+
+			$customer = $location->getCustomer();
+
+			$customer_slug = str_replace("-", "_", Util::slug($customer->name));
+
+			$icon = null;
+			$icon_file = "{$customer_slug}.png";
+
+			if($icon_file && file_exists("public/img/markers/$icon_file")) {
+				$icon = $icon_file;
+			}
+
+			$output[] = [
+				"id" => (int) $location->id,
+				"internalId" => (int) $location->internal_id,
+				"name" => $location->name,
+				"address" => $location->getDisplayAddress(),
+				"distance" => $distance,
+				"latitude" => (double) $location->latitude,
+				"longitude" => (double) $location->longitude,
+				"icon" => $icon,
+			];
+		}
+
+		JSON::success([
+			"name" => $address->name,
+			"latitude" => (double) $address->latitude,
+			"longitude" => (double) $address->longitude,
+			"locations" => $output
+		]);
+
+
 		break;
 		break;
 }
 }

+ 110 - 0
engine/chart.php

@@ -0,0 +1,110 @@
+<?php
+
+class Chart {
+
+	private $id = "";
+	private $title = "Untitled";
+	private $type = "bar";
+	private $datasets = [];
+	private $labels = [];
+	private $yAxes = [];
+
+	public function __construct() {
+		$this->id = bin2hex(random_bytes(8));
+	}
+
+	public function addYAxis($type, $position, $id, $grid_lines = true) {
+		$this->yAxes[] = [
+			"type" => $type,
+			"display" => true,
+			"position" => $position,
+			"id" => $id,
+			"gridLines" => [
+				"drawOnChartArea" => $grid_lines
+			],
+		];
+	}
+
+	public function getID() {
+		return $this->id;
+	}
+
+	public function getTitle() {
+		return $this->title;
+	}
+
+	public function setTitle($title) {
+		$this->title = $title;
+	}
+
+	public function setType($type) {
+		$this->type = $type;
+	}
+
+	public function addDataset($label, $data, $options = []) {
+
+		$background_colours = $options["background_colours"] ?? false;
+		$border_colours = $options["border_colours"] ?? false;
+		$border_width = $options["border_width"] ?? false;
+		$y_axis_id = $options["y_axis_id"] ?? false;
+		$type = $options["type"] ?? false;
+
+		$dataset = [
+			"label" => $label,
+			"data" => $data,
+		];
+
+		if($background_colours) $dataset["backgroundColor"] = $background_colours;
+		if($border_colours) $dataset["borderColor"] = $border_colours;
+		if($border_width) $dataset["borderWidth"] = (int) $border_width;
+		if($y_axis_id) $dataset["yAxisID"] = $y_axis_id;
+		if($type) $dataset["type"] = $type;
+
+		$this->datasets[] = $dataset;
+
+	}
+
+	public function setLabels($labels) {
+		$this->labels = $labels;
+	}
+
+	public function getJSON() {
+
+		$object = (object) [
+			"type" => $this->type,
+			"data" => (object) [
+				"labels" => $this->labels,
+				"datasets" => $this->datasets
+			],
+			"options" => (object) [
+				"title" => (object) [
+					"display" => true,
+					"fontSize" => 32,
+					"fontFamily" => "Roboto",
+					"fontStyle" => "300",
+					"text" => $this->title
+				],
+				"legend" => (object) [
+					"position" => "top",
+				],
+				"plugins" => (object) [
+					"datalabels" => [
+						"color" => "white",
+					],
+				],
+			],
+		];
+
+		if($this->yAxes) {
+			$object->options->scales = new stdClass;
+			$object->options->scales->yAxes = $this->yAxes;
+		}
+
+
+		return json_encode($object);
+
+	}
+
+}
+
+?>

+ 8 - 0
engine/core.php

@@ -49,6 +49,14 @@ class Core {
 		}
 		}
 	}
 	}
 
 
+	public static function requireTerms() {
+		Core::requireLogIn();
+		if(Core::$user->terms_accepted == false) {
+			Core::addAlert("danger", "You must accept Terms and Conditions to view this page.");
+			http::redirect("/account");
+		}
+	}
+
 	public static function requireAdmin() {
 	public static function requireAdmin() {
 		Core::requireLogIn();
 		Core::requireLogIn();
 		if(Core::$user->canAdmin() === false) {
 		if(Core::$user->canAdmin() === false) {

+ 12 - 1
engine/test.php

@@ -4,7 +4,7 @@ class Test extends Model {
 
 
 	protected static $table = "test";
 	protected static $table = "test";
 	protected static $id_field = "id";
 	protected static $id_field = "id";
-	protected static $fillable_fields = ["project_id", "location_id", "tester_id", "status", "test_fee", "test_time", "shop_left", "shop_right", "attire", "challenge_stage", "challenge_description", "challenger_name", "challenger_description", "challenger_gender", "challenger_eye_contact", "additional_notes", "dts_due", "dts_start", "dts_end", "verifier_id", "verifier_notes", "pass", "dts_created", "dts_updated", "dts_assigned", "dts_verified"];
+	protected static $fillable_fields = ["project_id", "location_id", "tester_id", "status", "test_fee", "test_time", "test_travel_cost", "shop_left", "shop_right", "attire", "challenge_stage", "challenge_description", "challenger_name", "challenger_description", "challenger_gender", "challenger_eye_contact", "additional_notes", "dts_due", "dts_start", "dts_end", "verifier_id", "verifier_notes", "pass", "dts_created", "dts_updated", "dts_assigned", "dts_verified"];
 
 
 	const TEST_FIELDS = ["shop_left", "shop_right", "attire", "challenge_stage", "challenge_description", "challenger_name", "challenger_description", "challenger_gender", "challenger_eye_contact", "additional_notes"];
 	const TEST_FIELDS = ["shop_left", "shop_right", "attire", "challenge_stage", "challenge_description", "challenger_name", "challenger_description", "challenger_gender", "challenger_eye_contact", "additional_notes"];
 
 
@@ -154,6 +154,17 @@ class Test extends Model {
 		$mail->send();
 		$mail->send();
 	}
 	}
 
 
+	public function decline() {
+		$this->sendDeclineEmail();
+
+		$this->status = Test::STATUS_UNASSIGNED;
+		$this->tester_id = null;
+		$this->dts_due = null;
+		$this->dts_assigned = null;
+		$this->dts_updated = Util::getDateTime();
+		return $this->commit();
+	}
+
 	public function getChallengeStageText() {
 	public function getChallengeStageText() {
 		return Test::STAGES[$this->challenge_stage];
 		return Test::STAGES[$this->challenge_stage];
 	}
 	}

+ 56 - 1
engine/user.php

@@ -4,7 +4,7 @@ class User extends Model {
 
 
 	protected static $table = "user";
 	protected static $table = "user";
 	protected static $id_field = "id";
 	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", "preferred_payment_method", "bank_name", "bank_sort_code", "bank_account_number", "paypal_email", "dts_registered", "dts_last_seen", "dts_verified", "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", "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
 	// Constants
 
 
@@ -307,6 +307,51 @@ class User extends Model {
 		return false;
 		return false;
 	}
 	}
 
 
+	public function deactivate() {
+		// Decline all pending tests
+		$pending_tests = $this->getPendingTests();
+		foreach($pending_tests as $test) {
+			$test->decline();
+		}
+
+		// Set user level to Deactivated
+		$this->level = User::LEVEL_DEACTIVATED;
+		return $this->commit();
+	}
+
+	public function softDelete() {
+
+		// Delete identification documents
+		$this->deleteIDFiles();
+
+		// Delete addresses
+		$this->deleteAddresses();
+
+		// Decline all pending tests
+		$pending_tests = $this->getPendingTests();
+		foreach($pending_tests as $test) {
+			$test->decline();
+		}
+
+		// Delete personal information
+		$this->email = null;
+		$this->title = null;
+		$this->first_name = null;
+		$this->last_name = null;
+		$this->phone = null;
+		$this->bank_name = null;
+		$this->bank_sort_code = null;
+		$this->bank_account_number = null;
+		$this->paypal_email = null;
+
+		// Set deleted time
+		$this->dts_deleted = Util::getDateTime();
+
+		$success = $this->commit();
+
+		return true;
+	}
+
 	public function deleteIDFiles() {
 	public function deleteIDFiles() {
 
 
 		$files = UserFile::query([
 		$files = UserFile::query([
@@ -324,6 +369,16 @@ class User extends Model {
 		return true;
 		return true;
 	}
 	}
 
 
+
+	public function deleteAddresses() {
+		$addresses = $this->getAddresses();
+		foreach($addresses as $address) {
+			$address->delete();
+		}
+
+		return true;
+	}
+
 	public function getAddresses() {
 	public function getAddresses() {
 
 
 		$addresses = UserAddress::query([
 		$addresses = UserAddress::query([

+ 1 - 0
package.json

@@ -10,6 +10,7 @@
   "license": "ISC",
   "license": "ISC",
   "dependencies": {
   "dependencies": {
     "bootstrap": "^4.0.0",
     "bootstrap": "^4.0.0",
+    "chart.js": "^2.7.2",
     "clipboard": "^2.0.0",
     "clipboard": "^2.0.0",
     "holderjs": "^2.9.4",
     "holderjs": "^2.9.4",
     "jquery": "^3.3.1",
     "jquery": "^3.3.1",

Plik diff jest za duży
+ 9 - 0
public/js/Chart.bundle.min.js


+ 27 - 0
public/js/app-performance.js

@@ -0,0 +1,27 @@
+$(function() {
+
+	$("canvas[data-chart]").each(function() {
+		var object = $(this).data("chart");
+
+		object.options.plugins.datalabels.display = function(context) {
+			var dataset = context.dataset;
+			var count = dataset.data.length;
+			var value = dataset.data[context.dataIndex];
+			return value;
+		};
+
+		var chart = new Chart(this, object);
+	});
+
+	$("input[data-date-range-radio-input]").change(function() {
+		let checked = $(this).is(":checked");
+		let value = $(this).val();
+		if(value == "custom") {
+			$("#date-range-custom-fields").slideDown("fast");
+		}
+		else {
+			$("#date-range-custom-fields").slideUp("fast");
+		}
+	});
+
+});

+ 21 - 4
public/js/app-project.js

@@ -56,7 +56,7 @@ $(function() {
 
 
 		return true;
 		return true;
 	});
 	});
-	$("#testers-max-distance").change(function() {
+	$("#testers-max-distance, #testers-include-unverified").change(function() {
 		if(selectedLocation) {
 		if(selectedLocation) {
 			clearTesters();
 			clearTesters();
 			initialiseTesters();
 			initialiseTesters();
@@ -283,9 +283,12 @@ function initialiseTesters() {
 
 
 	$("#tester-list-loading-container").text("Loading available testers...");
 	$("#tester-list-loading-container").text("Loading available testers...");
 
 
+	let includeUnverified = $("#testers-include-unverified").val();
+
 	$.post("/account/projects/" + projectID + "/get-testers", {
 	$.post("/account/projects/" + projectID + "/get-testers", {
 		submit: $("#submit").val(),
 		submit: $("#submit").val(),
-		location_id: selectedLocation.id
+		location_id: selectedLocation.id,
+		include_unverified: includeUnverified
 	}, function(response) {
 	}, function(response) {
 		if(!response.success) return;
 		if(!response.success) return;
 		if(!response.testers || response.testers.length == 0) {
 		if(!response.testers || response.testers.length == 0) {
@@ -344,13 +347,22 @@ function initialiseTesters() {
 			var td = $("<td></td>");
 			var td = $("<td></td>");
 			td.append("<a href=\"/account/users/" + tester.id + "\" target=\"_blank\">" + tester.name + "</a> ");
 			td.append("<a href=\"/account/users/" + tester.id + "\" target=\"_blank\">" + tester.name + "</a> ");
 
 
-			td.append("<small>(" +  tester.score + ")</small>");
+			var scoreClass = "secondary";
+			if(tester.score > 0) {
+				scoreClass = "success";
+			}
+			else if(tester.score < 0) {
+				scoreClass = "danger";
+			}
+
+			td.append("<span class=\"badge badge-pill badge-" + scoreClass + "\" title=\"Score\">" +  tester.score + "</span>");
 
 
 			td.append("<br />");
 			td.append("<br />");
 
 
-			var small = $("<small>Distance: " + tester.distanceMiles + " / " + tester.maxRadiusMiles + " miles</small>");
+			var small = $("<small>" + tester.distanceMiles + " / " + tester.maxRadiusMiles + " miles</small>");
 			if(tester.maxRadiusExceeded) {
 			if(tester.maxRadiusExceeded) {
 				small.addClass("text-danger");
 				small.addClass("text-danger");
+				small.append(" <i class=\"fas fa-exclamation-circle\"></i>");
 			}
 			}
 			td.append(small);
 			td.append(small);
 			tr.append(td);
 			tr.append(td);
@@ -360,6 +372,11 @@ function initialiseTesters() {
 			tr.append(td);
 			tr.append(td);
 
 
 			td = $("<td class=\"text-right align-middle\"></td>");
 			td = $("<td class=\"text-right align-middle\"></td>");
+
+			if(!tester.termsAccepted) {
+				td.append("<span class=\"badge badge-danger\" title=\"Terms and Conditions not accepted\">T&amp;C</span> ");
+			}
+
 			td.append("<span class=\"badge badge-" + tester.levelClass + "\">" + tester.levelText + "</span>");
 			td.append("<span class=\"badge badge-" + tester.levelClass + "\">" + tester.levelText + "</span>");
 			td.append("<br />");
 			td.append("<br />");
 			td.append($("<small>").text(tester.phone));
 			td.append($("<small>").text(tester.phone));

+ 118 - 2
public/js/app-user.js

@@ -1,12 +1,38 @@
+var addressesInitialised = false;
+var locationsInitialised = false;
+
+var addressMarkers = [];
+var locationMarkers = [];
+
+$(function() {
+
+	$("[data-toggle=tab]").on("shown.bs.tab", function(event) {
+
+		if(event.target.id == "addresses-tab" && addressesInitialised == false) {
+			initialiseAddresses();
+		}
+
+		if(event.target.id == "nearby-locations-tab" && locationsInitialised == false) {
+			initialiseLocations();
+		}
+
+	});
+
+	$("#address-id").change(function() {
+		initialiseLocations();
+	});
+
+});
+
 function initialiseAddresses() {
 function initialiseAddresses() {
 
 
+	let map = maps["map"];
+
 	$.get("/api/users/" + userId + "/get-addresses", {
 	$.get("/api/users/" + userId + "/get-addresses", {
 	}, function(response) {
 	}, function(response) {
 		if(!response.success) return false;
 		if(!response.success) return false;
 		if(!response.addresses) return false;
 		if(!response.addresses) return false;
 
 
-		let map = maps["map"];
-
 		let bounds = new google.maps.LatLngBounds;
 		let bounds = new google.maps.LatLngBounds;
 
 
 		for(let i in response.addresses) {
 		for(let i in response.addresses) {
@@ -33,4 +59,94 @@ function initialiseAddresses() {
 
 
 	});
 	});
 
 
+}
+
+
+
+function initialiseLocations() {
+
+	for(var i in locationMarkers) {
+		let marker = locationMarkers[i];
+		marker.setMap(null);
+		marker = null;
+	}
+
+	locationMarkers = [];
+
+	$("#nearby-locations-list-group").empty();
+
+	let map = maps["nearby-locations-map"];
+
+	$.get("/api/users/" + userId + "/get-locations", {
+		"address_id": $("#address-id").val()
+	}, function(response) {
+		if(!response.success) return false;
+		if(!response.locations) return false;
+
+		let bounds = new google.maps.LatLngBounds;
+
+		// User Address
+		let position = {
+			lat: response.latitude,
+			lng: response.longitude
+		};
+
+		let options = {
+			map: map,
+			position: position,
+			title: response.name
+		}
+
+		bounds.extend(position);
+
+		let marker = new google.maps.Marker(options);
+		locationMarkers.push(marker);
+
+		// Locations
+
+		for(let i in response.locations) {
+
+			let location = response.locations[i];
+			let position = {
+				lat: location.latitude,
+				lng: location.longitude
+			};
+
+			let options = {
+				map: map,
+				position: position,
+				title: location.name
+			}
+
+			if(location.icon) options.icon = "/img/markers/" + location.icon;
+
+			bounds.extend(position);
+
+			let marker = new google.maps.Marker(options);
+
+			locationMarkers.push(marker);
+
+			if(location.internalId == 0) {
+				location.internalId = "N/A";
+			}
+
+
+			// Add to list group
+			let listGroupItem = $("div[data-nearby-location-list-group-item-template]").clone();
+			listGroupItem.removeAttr("data-nearby-location-list-group-item-template");
+
+			listGroupItem.find("a[data-location-name]").text(location.name);
+			listGroupItem.find("span[data-location-distance]").text(location.distance + " miles");
+			listGroupItem.find("span[data-location-id]").text(location.id);
+			listGroupItem.find("span[data-location-internal-id]").text(location.internalId);
+			listGroupItem.find("small[data-location-address]").text(location.address);
+
+			listGroupItem.appendTo("#nearby-locations-list-group").show();
+
+		}
+
+		map.fitBounds(bounds);
+
+	});
+
 }
 }

Plik diff jest za duży
+ 10 - 0
public/js/chartjs-plugin-datalabels.min.js


+ 4 - 0
router.php

@@ -46,6 +46,10 @@ try {
 				Core::requireLogIn();
 				Core::requireLogIn();
 			}
 			}
 
 
+			if(preg_match("/^account/", $path) && $path != "account" && !preg_match("/(settings|deactivate|reactivate|delete|accept-terms|decline-terms)$/", $path)) {
+				Core::requireTerms();
+			}
+
 			if($require_admin) {
 			if($require_admin) {
 				Core::requireAdmin();
 				Core::requireAdmin();
 			}
 			}

+ 13 - 1
routes.php

@@ -26,6 +26,11 @@ $routes = [
 	"/^privacy-policy$/" => ["controller" => "privacy_policy"],
 	"/^privacy-policy$/" => ["controller" => "privacy_policy"],
 	"/^verify-email\/([a-f0-9]+)$/" => ["controller" => "user_activation", "params" => ["token"]],
 	"/^verify-email\/([a-f0-9]+)$/" => ["controller" => "user_activation", "params" => ["token"]],
 
 
+	// Terms and Conditions
+	"/^terms-and-conditions$/" => ["controller" => "terms_and_conditions"],
+	"/^account\/accept-terms$/" => ["controller" => "terms_accept", "require_log_in" => true],
+	"/^account\/decline-terms$/" => ["controller" => "terms_decline", "require_log_in" => true],
+
 	// Marketing
 	// Marketing
 	"/^services$/" => ["controller" => "services"],
 	"/^services$/" => ["controller" => "services"],
 	"/^become-a-tester$/" => ["controller" => "become_a_tester"],
 	"/^become-a-tester$/" => ["controller" => "become_a_tester"],
@@ -38,6 +43,9 @@ $routes = [
 	// Account
 	// Account
 	"/^account$/" => ["controller" => "account", "require_log_in" => true],
 	"/^account$/" => ["controller" => "account", "require_log_in" => true],
 	"/^account\/settings$/" => ["controller" => "settings", "require_log_in" => true],
 	"/^account\/settings$/" => ["controller" => "settings", "require_log_in" => true],
+	"/^account\/deactivate$/" => ["controller" => "account_deactivate", "require_user_level" => User::LEVEL_TESTER],
+	"/^account\/reactivate$/" => ["controller" => "account_reactivate", "require_log_in" => true],
+	"/^account\/delete$/" => ["controller" => "account_delete", "require_log_in" => true],
 
 
 	// Addresses
 	// Addresses
 	"/^account\/addresses$/" => ["controller" => "addresses", "require_log_in" => true],
 	"/^account\/addresses$/" => ["controller" => "addresses", "require_log_in" => true],
@@ -56,6 +64,7 @@ $routes = [
 	"/^account\/projects\/$id_pattern$/" => ["controller" => "project", "params" => ["id"], "require_user_level" => User::LEVEL_CUSTOMER],
 	"/^account\/projects\/$id_pattern$/" => ["controller" => "project", "params" => ["id"], "require_user_level" => User::LEVEL_CUSTOMER],
 	"/^account\/projects\/$id_pattern\/edit$/" => ["controller" => "project_edit", "params" => ["id"], "require_user_level" => User::LEVEL_ADMIN],
 	"/^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-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\/(get-locations|get-testers|create-test|assign-tester)$/" => ["controller" => "project_ajax", "params" => ["id", "action"], "type" => "json", "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
 	// Tests
@@ -83,7 +92,7 @@ $routes = [
 	"/^account\/users\/$id_pattern\/verify\/(id-document|photo)$/" => ["controller" => "user_verify_image", "params" => ["id", "type"], "require_user_level" => User::LEVEL_ADMIN],
 	"/^account\/users\/$id_pattern\/verify\/(id-document|photo)$/" => ["controller" => "user_verify_image", "params" => ["id", "type"], "require_user_level" => User::LEVEL_ADMIN],
 	"/^account\/users\/$id_pattern\/(id-document|photo)$/" => ["controller" => "user_verify_image", "params" => ["id", "type"], "require_user_level" => User::LEVEL_ADMIN],
 	"/^account\/users\/$id_pattern\/(id-document|photo)$/" => ["controller" => "user_verify_image", "params" => ["id", "type"], "require_user_level" => User::LEVEL_ADMIN],
 
 
-	"/^api\/users\/$id_pattern\/(get-addresses)$/" => ["controller" => "user_ajax", "params" => ["id", "action"], "require_user_level" => User::LEVEL_ADMIN],
+	"/^api\/users\/$id_pattern\/(get-addresses|get-locations)$/" => ["controller" => "user_ajax", "params" => ["id", "action"], "require_user_level" => User::LEVEL_ADMIN],
 
 
 	// Locations
 	// Locations
 	"/^account\/locations$/" => ["controller" => "locations", "require_user_level" => User::LEVEL_CUSTOMER],
 	"/^account\/locations$/" => ["controller" => "locations", "require_user_level" => User::LEVEL_CUSTOMER],
@@ -108,6 +117,9 @@ $routes = [
 	// Submit ID
 	// Submit ID
 	"/^account\/submit-id$/" => ["controller" => "submit_id", "require_user_level" => User::LEVEL_REGISTERED],
 	"/^account\/submit-id$/" => ["controller" => "submit_id", "require_user_level" => User::LEVEL_REGISTERED],
 
 
+	// Performance
+	"/^account\/performance$/" => ["controller" => "performance", "require_user_level" => User::LEVEL_VENUE],
+
 
 
 ];
 ];
 
 

+ 53 - 3
views/account.php

@@ -31,7 +31,7 @@
 	<div class="row">
 	<div class="row">
 		<div class="col-lg-4 mb-3 mb-lg-0">
 		<div class="col-lg-4 mb-3 mb-lg-0">
 			<h3>Main Menu</h3>
 			<h3>Main Menu</h3>
-			<div class="list-group">
+			<div class="list-group mb-3">
 			<?php
 			<?php
 			foreach($links as $path => $text) {
 			foreach($links as $path => $text) {
 				?>
 				?>
@@ -42,13 +42,26 @@
 			}
 			}
 			?>
 			?>
 			</div>
 			</div>
+			<h3>Actions</h3>
+			<div class="list-group mb-3">
+			<?php
+			foreach($actions as $path => $text) {
+				$text_class = preg_match("/delete/i", $text) ? "text-danger" : "";
+				?>
+				<a class="list-group-item list-group-item-action <?=$text_class?>" href="<?=htmlspecialchars($path)?>">
+					<?=htmlspecialchars($text)?>
+				</a>
+				<?php
+			}
+			?>
+			</div>
 		</div>
 		</div>
 		<div class="col-lg mb-3 mb-lg-0">
 		<div class="col-lg mb-3 mb-lg-0">
 
 
 			<?php
 			<?php
-			$has_to_do = !empty($users_pending_verification) || !empty($tests_pending_verification);
+			$has_to_do = !empty($users_pending_verification) || !empty($tests_pending_verification) || !empty($tests_remaining);
 
 
-			if($has_to_do && Core::$user->level >= User::LEVEL_ADMIN) {
+			if($has_to_do) {
 				?>
 				?>
 				<h3>To-Do</h3>
 				<h3>To-Do</h3>
 
 
@@ -75,7 +88,44 @@
 					</div>
 					</div>
 					<?php
 					<?php
 				}
 				}
+				if($tests_remaining) {
+					$s = ($tests_remaining == 1) ? "" : "s";
+					?>
+					<div class="alert alert-info mb-3 d-flex flex-row justify-content-between">
+						<div class="align-self-center">
+							<i class="fal fa-fw fa-info-circle"></i> <?=number_format($tests_remaining)?> test<?=$s?> remaining.
+						</div>
+						<a class="btn btn-primary" href="/account/tests">View</a>
+					</div>
+					<?php
+				}
 			}
 			}
+
+			if(Core::$user->level != User::LEVEL_DEACTIVATED && !Core::$user->terms_accepted) {
+				?>
+				<div class="alert alert-danger">
+					<p><i class="fas fa-info-circle"></i> <strong>IMPORTANT</strong></p>
+
+					<?php
+					if(is_null(Core::$user->terms_accepted)) {
+						?>
+						<p><a href="/terms-and-conditions">Terms and Conditions</a> have been published.</p>
+						<p>Our records show that you have not accepted the <a href="/terms-and-conditions">Terms and Conditions</a> on registration. Please take time to read our Terms and Conditions and then click Accept or Decline to continue.</p>
+						<?php
+					}
+					else {
+						?>
+						<p>Our records show that you have declined the <a href="/terms-and-conditions">Terms and Conditions</a>. If you have changed your mind, please click Accept to continue or Decline for other actions.</p>
+						<?php
+					}
+					?>
+
+					<a class="btn btn-success" href="/account/accept-terms">Accept</a>
+					<a class="btn btn-danger" href="/account/decline-terms">Decline</a>
+				</div>
+				<?php
+			}
+
 			?>
 			?>
 
 
 			<h3>Useful Documents</h3>
 			<h3>Useful Documents</h3>

+ 24 - 0
views/account_deactivate.php

@@ -0,0 +1,24 @@
+<div class="container mt-3 py-4">
+
+	<h2>Deactivate Account</h2>
+
+	<p>By deactivating your account, you will:</p>
+
+	<ul>
+		<li>No longer be assigned tests.</li>
+		<li>No longer be able to participate in tests.</li>
+		<li>Unassign yourself from all currently assigned tests.</li>
+	</ul>
+
+	<p>You can always log into your account and reactivate the account should you wish to continue to use our services, however you will lose your currently assigned tests.</p>
+
+	<p class="text-danger">
+		This action cannot be undone.
+	</p>
+
+	<form method="post">
+		<button class="btn btn-danger" type="submit" name="submit" value="<?=$_SESSION["csrf_token"]?>">Deactivate Account</button>
+		<a class="btn btn-secondary" href="/account">Cancel</a>
+	</form>
+
+</div>

+ 28 - 0
views/account_delete.php

@@ -0,0 +1,28 @@
+<div class="container mt-3 py-4">
+
+	<h2>Delete Account</h2>
+
+	<p>By deleting your account, you will:</p>
+
+	<ul>
+		<li>No longer be assigned tests.</li>
+		<li>No longer be able to participate in tests.</li>
+		<li>No longer be able to generate invoices for completed tests.</li>
+		<li>Unassign yourself from all currently assigned tests.</li>
+		<li>Delete all personal identifiable information associated with your account.</li>
+	</ul>
+
+	<p>If you have participated in tests, we will need to keep only your age and gender for test reporting purposes. This information will not and cannot be used to identify you.</p>
+
+	<p>You will need to register again should you wish to continue to use our services.</p>
+
+	<p class="text-danger">
+		This action cannot be undone.
+	</p>
+
+	<form method="post">
+		<button class="btn btn-lg btn-danger" type="submit" name="submit" value="<?=$_SESSION["csrf_token"]?>">Delete Account</button>
+		<a class="btn btn-lg btn-secondary" href="/account">Cancel</a>
+	</form>
+
+</div>

+ 4 - 0
views/address_add_form.php

@@ -11,6 +11,10 @@
 			<label for="postal-code">Postal Code</label>
 			<label for="postal-code">Postal Code</label>
 			<input class="form-control" type="text" name="postal_code" id="postal-code" placeholder="Enter postal code" value="<?=htmlspecialchars($user_address->postal_code)?>" required />
 			<input class="form-control" type="text" name="postal_code" id="postal-code" placeholder="Enter postal code" value="<?=htmlspecialchars($user_address->postal_code)?>" required />
 		</div>
 		</div>
+		<div class="form-group">
+			<label  for="country">Country</label>
+			<input class="form-control" type="text" name="country" id="country" placeholder="Enter country" value="<?=htmlspecialchars($user_address->country)?>" required />
+		</div>
 		<button class="btn btn-primary" type="submit" name="submit" value="<?=$_SESSION["csrf_token"]?>">Add</button>
 		<button class="btn btn-primary" type="submit" name="submit" value="<?=$_SESSION["csrf_token"]?>">Add</button>
 	</form>
 	</form>
 </div>
 </div>

+ 4 - 0
views/address_edit_form.php

@@ -29,6 +29,10 @@
 					<label for="postal-code">Postal Code</label>
 					<label for="postal-code">Postal Code</label>
 					<input class="form-control" type="text" name="postal_code" id="postal-code" placeholder="Enter postal code" value="<?=htmlspecialchars($user_address->postal_code)?>" required />
 					<input class="form-control" type="text" name="postal_code" id="postal-code" placeholder="Enter postal code" value="<?=htmlspecialchars($user_address->postal_code)?>" required />
 				</div>
 				</div>
+				<div class="form-group">
+					<label  for="country">Country</label>
+					<input class="form-control" type="text" name="country" id="country" placeholder="Enter country" value="<?=htmlspecialchars($user_address->country)?>" required />
+				</div>
 			</div>
 			</div>
 			<div class="col-lg">
 			<div class="col-lg">
 				<label>Map</label>
 				<label>Map</label>

+ 2 - 1
views/footer.php

@@ -52,7 +52,8 @@
 				<div class="text-center">
 				<div class="text-center">
 					&copy; <?=date("Y")?> <?=APP_NAME?><br />
 					&copy; <?=date("Y")?> <?=APP_NAME?><br />
 					<small>
 					<small>
-						<a href="/privacy-policy">Privacy Policy</a>
+						<a class="mx-1" href="/terms-and-conditions">Terms &amp; Conditions</a>
+						<a class="mx-1" href="/privacy-policy">Privacy Policy</a>
 					</small>
 					</small>
 				</div>
 				</div>
 			</div>
 			</div>

+ 6 - 0
views/location_form.php

@@ -75,6 +75,12 @@ $tabs = [
 								<input class="form-control" type="text" name="postal_code" id="postal-code" placeholder="Enter postal code" value="<?=htmlspecialchars($location->postal_code)?>" required />
 								<input class="form-control" type="text" name="postal_code" id="postal-code" placeholder="Enter postal code" value="<?=htmlspecialchars($location->postal_code)?>" required />
 							</div>
 							</div>
 						</div>
 						</div>
+						<div class="row mb-1">
+							<label class="col-sm-4 col-form-label" for="country">Country</label>
+							<div class="col-sm">
+								<input class="form-control" type="text" name="country" id="country" placeholder="Enter country" value="<?=htmlspecialchars($location->country)?>" required />
+							</div>
+						</div>
 
 
 						<div class="row mb-1">
 						<div class="row mb-1">
 							<label class="col-sm-4 col-form-label" for="email">Email Address</label>
 							<label class="col-sm-4 col-form-label" for="email">Email Address</label>

+ 14 - 1
views/locations.php

@@ -27,7 +27,20 @@ var customerId = <?=$customer->id?>;
 				}
 				}
 				?>
 				?>
 			</button>
 			</button>
-			<a class="btn btn-outline-success" href="/account/locations/add?customer_id=<?=$customer->id?>">Add</a>
+		</div>
+		<div class="col-auto">
+
+
+			<div class="dropdown">
+				<button class="btn btn-secondary dropdown-toggle" type="button" id="actions-button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+					Actions
+				</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>
+				</div>
+			</div>
+
 		</div>
 		</div>
 	</div>
 	</div>
 
 

+ 282 - 0
views/performance.php

@@ -0,0 +1,282 @@
+<?php
+
+$date_resolutions = [
+	"quarterly" => "Quarterly",
+	"monthly" => "Monthly",
+];
+
+$date_ranges = [
+	"ytd" => "Year to Date",
+	//"unbound" => "Unbound",
+	"custom" => "Custom",
+];
+
+$years = range(2018, date("Y"));
+
+$date_range_custom_style = ($date_range == "custom") ? "" : "display: none";
+
+?>
+<div class="container">
+	<div class="row">
+		<div class="col-auto">
+			<h2><?=htmlspecialchars($customer->name)?> Performance</h2>
+		</div>
+		<div class="col">
+		</div>
+	</div>
+
+	<form class="mb-4" method="post">
+
+		<input type="hidden" name="customer_id" value="<?=htmlspecialchars($customer->id)?>" />
+
+		<div class="row">
+			<div class="col-md">
+				<div class="row mb-1">
+					<label class="col-sm-4 col-form-label text-sm-right">
+						Date Range
+					</label>
+					<div class="col-sm">
+					<?php
+					foreach($date_ranges as $value => $display) {
+						$checked = ($value == $date_range) ? "checked" : "";
+						?>
+						<div class="form-check form-check-inline">
+							<input class="form-check-input" type="radio" name="date_range" id="date-range-<?=htmlspecialchars($value)?>" value="<?=htmlspecialchars($value)?>" <?=$checked?> data-date-range-radio-input />
+							<label class="form-check-label" for="date-range-<?=htmlspecialchars($value)?>"><?=htmlspecialchars($display)?></label>
+						</div>
+						<?php
+					}
+					?>
+						<div class="row mt-1" id="date-range-custom-fields" style="<?=$date_range_custom_style?>">
+							<div class="col-lg">
+								<div class="input-group">
+									<div class="input-group-prepend">
+										<span class="input-group-text">
+											From
+										</span>
+									</div>
+									<select class="form-control" name="from_quarter">
+									<?php
+									foreach($years as $year) {
+										foreach(range(1, 4) as $quarter) {
+
+											$value = "$year-$quarter";
+											$selected = ($value == $from_quarter) ? "selected" : "";
+
+											switch($quarter) {
+												case 1: $quarter_text = "Q1 (Jan-Mar)"; break;
+												case 2: $quarter_text = "Q2 (Apr-Jun)"; break;
+												case 3: $quarter_text = "Q3 (Jul-Sep)"; break;
+												case 4: $quarter_text = "Q4 (Oct-Dec)"; break;
+											}
+											?>
+											<option value="<?=$value?>" <?=$selected?>><?=$year?> <?=$quarter_text?></option>
+											<?php
+										}
+									}
+									?>
+									</select>
+								</div>
+							</div>
+							<div class="col-lg">
+								<div class="input-group">
+									<div class="input-group-prepend">
+										<span class="input-group-text">
+											To
+										</span>
+									</div>
+									<select class="form-control" name="to_quarter">
+									<?php
+									foreach($years as $year) {
+										foreach(range(1, 4) as $quarter) {
+
+											$value = "$year-$quarter";
+											$selected = ($value == $to_quarter) ? "selected" : "";
+
+											switch($quarter) {
+												case 1: $quarter_text = "Q1 (Jan-Mar)"; break;
+												case 2: $quarter_text = "Q2 (Apr-Jun)"; break;
+												case 3: $quarter_text = "Q3 (Jul-Sep)"; break;
+												case 4: $quarter_text = "Q4 (Oct-Dec)"; break;
+											}
+											?>
+											<option value="<?=$value?>" <?=$selected?>><?=$year?> <?=$quarter_text?></option>
+											<?php
+										}
+									}
+									?>
+									</select>
+								</div>
+							</div>
+						</div>
+
+					</div>
+				</div>
+				<div class="row mb-1">
+					<label class="col-sm-4 col-form-label text-sm-right" for="date-resolution">
+						Date Resolution
+					</label>
+					<div class="col-sm">
+						<select class="form-control" name="date_resolution" id="date-resolution">
+						<?php
+						foreach($date_resolutions as $value => $display) {
+							$selected = ($value == $date_resolution) ? "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 text-sm-right" for="project-ids">
+						Projects
+					</label>
+					<div class="col-sm">
+						<select class="form-control" name="project_ids[]" id="project-ids" multiple size="8">
+						<?php
+						foreach($all_projects as $project) {
+							$selected = in_array($project->id, $project_ids) ? "selected" : "";
+							?>
+							<option value="<?=$project->id?>" <?=$selected?>><?=htmlspecialchars($project->name)?></option>
+							<?php
+						}
+						?>
+						</select>
+						<small class="form-text text-muted">Hint: Ctrl+Click / Cmd+Click to select multiple projects.</small>
+					</div>
+				</div>
+				<div class="row">
+					<div class="col-sm offset-sm-4">
+						<button class="btn btn-primary" type="submit" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>">
+							Submit
+						</button>
+					</div>
+				</div>
+			</div>
+		</div>
+	</form>
+
+	<?php
+	if($locations_missing_region) {
+		?>
+		<div class="alert alert-warning">
+			There are some locations that are missing "region" information:
+			<ul class="mb-0">
+			<?php
+			foreach($locations_missing_region as $location) {
+				$url = (Core::$user->canAdmin()) ? "/account/locations/$location->id/edit" : "#";
+				?>
+				<li>
+					<a href="<?=htmlspecialchars($url)?>"><?=htmlspecialchars($location->name)?></a>
+					<?php
+					if($location->internal_id) {
+						?>
+						<small class="text-info">(Internal ID: <?=htmlspecialchars($location->internal_id)?>)</small>
+						<?php
+					}
+					?>
+				</li>
+				<?php
+			}
+			?>
+			</ul>
+		</div>
+		<?php
+	}
+	?>
+
+	<?php
+	if($locations_missing_area_manager) {
+		?>
+		<div class="alert alert-warning">
+			There are some locations that are missing "area manager" information:
+			<ul class="mb-0">
+			<?php
+			foreach($locations_missing_area_manager as $location) {
+				$url = (Core::$user->canAdmin()) ? "/account/locations/$location->id/edit" : "#";
+				?>
+				<li>
+					<a href="<?=htmlspecialchars($url)?>"><?=htmlspecialchars($location->name)?></a>
+					<?php
+					if($location->internal_id) {
+						?>
+						<small class="text-info">(Internal ID: <?=htmlspecialchars($location->internal_id)?>)</small>
+						<?php
+					}
+					?>
+				</li>
+				<?php
+			}
+			?>
+			</ul>
+		</div>
+		<?php
+	}
+	?>
+
+	<?php
+	if($charts) {
+		?>
+
+		<h2>Charts / Statistics</h2>
+
+		<div class="row">
+			<div class="col-md-6">
+				<div class="card card-body mb-3">
+					Test Count
+					<div class="stat">
+						<?=$total_data->testCount?>
+					</div>
+				</div>
+			</div>
+			<div class="col-md-6">
+				<div class="card card-body mb-3">
+					Pass/Fail Count
+					<div class="stat">
+						<?=$total_data->passCount?> /
+						<?=$total_data->failCount?>
+					</div>
+				</div>
+			</div>
+		</div>
+
+		<div class="row">
+			<div class="col-md-4" style="position: relative;">
+				<h3>Chart List</h3>
+				<div class="list-group" style="position: sticky; top: 7rem;">
+				<?php
+				foreach($charts as $index => $chart) {
+					?>
+					<a class="list-group-item list-group-item-action" href="#chart-<?=$index?>">
+						<?=htmlspecialchars($chart->getTitle())?>
+					</a>
+					<?php
+				}
+				?>
+				</div>
+			</div>
+			<div class="col-md">
+			<?php
+			foreach($charts as $index => $chart) {
+				if($index > 0) {
+					?>
+					<br />
+					<?php
+				}
+				?>
+				<a id="chart-<?=$index?>" style="display: block; position: relative; top: -7rem; visibility: hidden;"></a>
+				<canvas id="<?=$chart->getID()?>" data-chart="<?=htmlspecialchars($chart->getJSON())?>" width="400" height="300">
+				</canvas>
+				<?php
+			}
+			?>
+			</div>
+		</div>
+
+		<?php
+	}
+	?>
+
+</div>

+ 10 - 3
views/project.php

@@ -20,6 +20,7 @@ var projectID = <?=$project->id?>;
 				<div class="dropdown-menu dropdown-menu-right" aria-labelledby="actions-button">
 				<div class="dropdown-menu dropdown-menu-right" aria-labelledby="actions-button">
 					<a class="dropdown-item" href="/account/projects/<?=$project->id?>/edit">Edit</a>
 					<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-csv">Export CSV</a>
+					<a class="dropdown-item" href="/account/projects/<?=$project->id?>/export-customer-csv">Export Customer CSV</a>
 				</div>
 				</div>
 			</div>
 			</div>
 			<?php
 			<?php
@@ -155,17 +156,23 @@ var projectID = <?=$project->id?>;
 					<div class="input-group mb-3">
 					<div class="input-group mb-3">
 						<div class="input-group-prepend">
 						<div class="input-group-prepend">
 							<span class="input-group-text">
 							<span class="input-group-text">
-								Filter
+								<i class="fal fa-filter"></i>
 							</span>
 							</span>
 						</div>
 						</div>
-						<input class="form-control" type="text" placeholder="Enter name or ID" data-filter-target="#testers-tbody" />
+						<input class="form-control" type="text" placeholder="Name / ID" data-filter-target="#testers-tbody" />
 					</div>
 					</div>
 				</div>
 				</div>
+				<div class="col-md">
+					<select class="form-control mb-3" id="testers-include-unverified">
+						<option value="0">Exc. Unverified</option>
+						<option value="1">Inc. Unverified</option>
+					</select>
+				</div>
 				<div class="col-md">
 				<div class="col-md">
 					<div class="input-group mb-3">
 					<div class="input-group mb-3">
 						<div class="input-group-prepend">
 						<div class="input-group-prepend">
 							<span class="input-group-text">
 							<span class="input-group-text">
-								Up to
+								<i class="fal fa-car"></i>
 							</span>
 							</span>
 						</div>
 						</div>
 						<select class="form-control" id="testers-max-distance">
 						<select class="form-control" id="testers-max-distance">

+ 14 - 0
views/register.php

@@ -112,6 +112,20 @@
 						<input class="form-control" type="text" name="postal_code" id="postal-code" placeholder="Enter postal code" value="<?=htmlspecialchars($user_address->postal_code)?>" required />
 						<input class="form-control" type="text" name="postal_code" id="postal-code" placeholder="Enter postal code" value="<?=htmlspecialchars($user_address->postal_code)?>" required />
 					</div>
 					</div>
 				</div>
 				</div>
+				<div class="row mb-3">
+					<label class="col-sm-4 col-form-label" for="country">Country</label>
+					<div class="col-sm">
+						<input class="form-control" type="text" name="country" id="country" placeholder="Enter country" value="<?=htmlspecialchars($user_address->country)?>" required />
+					</div>
+				</div>
+				<div class="row mb-1">
+					<div class="col-sm offset-sm-4">
+						<label>
+							<input type="checkbox" value="1" name="terms_accepted" /> I agree to and have read the <a href="/terms-and-conditions" target="_blank">Terms and Conditions</a> and <a href="/privacy-policy" target="_blank">Privacy Policy</a>
+						</label>
+
+					</div>
+				</div>
 				<div class="row">
 				<div class="row">
 					<div class="col-sm offset-sm-4">
 					<div class="col-sm offset-sm-4">
 						<?php
 						<?php

+ 200 - 0
views/terms_and_conditions.php

@@ -0,0 +1,200 @@
+<div class="container mt-3 py-4">
+
+	<h2>Terms and Conditions</h2>
+
+	<ol>
+		<li class="mb-4">
+			<p>AGREEMENT</p>
+			<ol>
+				<li>
+					<p>In registering with Check Policy Limited, You ("you" or "your") confirm that, by entering
+					into this agreement, Check Policy Limited whose company registration number is
+					09506865 and whose registered office address is 8 Market Street, Liskeard, Cornwall. PL14
+					3JJ ("the Company") has engaged you as a self-employed Approved Tester to provide the
+					Services (defined below).</p>
+				</li>
+			</ol>
+		</li>
+		<li class="mb-4">
+			<p>APPROVED TESTER SERVICES</p>
+			<ol>
+				<li>
+					<p>You agree to provide the Company with Services (defined below) on an Assignment-by-Assignment
+					basis. You acknowledge that the Company is not under any obligation to
+					engage you in the provision of the Services for any particular Assignments, or at all.</p>
+				</li>
+				<li>
+					<p>When we refer to an Assignment, we mean an approved testing instruction that is
+					allocated to your Approved Tester online account ("Account") provided via the Company’s
+					website ("Assignment"). The Services mean the attendance at client premises and
+					observation, evaluation and recording of certain age verification procedures in
+					accordance with Company’s clients’ ("Clients") requirements for the Assignment
+					("Services"). These requirements may vary with each Assignment. They will be
+					communicated to you prior to acceptance of each Assignment. The Company’s
+					specifications for each Assignment will relate directly to the results expected and not to
+					the details of performance, which shall be at your sole discretion. Within the confines of
+					the Assignment, you will control the time, the date, and the manner in which you perform
+					the Assignment.</p>
+				</li>
+				<li>
+					<p>The Company reserves the right to vary any of your Assignments at any time. We will
+					notify you of this variation by contacting you using the contact details that you have
+					provided to us, or otherwise by posting a notification on your Account.</p>
+				</li>
+				<li>
+					<p>You cannot provide the Services where:</p>
+					<ol>
+						<li>
+							<p>You are or were (or are in the process of becoming) engaged as an employee,
+							representative, director, agent, member, owner, shareholder, partner or a self-employed
+							contractor for a Client;</p>
+						</li>
+						<li>
+							<p>You are or were related to, live with or are close friends with anyone who is or
+							was (or is in the process of becoming) an employee, representative, director,
+							agent, member, owner, shareholder, partner or a self-employed contractor for a
+							Client; unless full disclosure of the relationship is provided to the Company and
+							they give express consent for you to act.</p>
+						</li>
+					</ol>
+				</li>
+				<li>
+					<p>You must not allow any other third party including friends or other family members to
+					provide the Services without the prior written approval of the Company.</p>
+				</li>
+			</ol>
+		</li>
+		<li class="mb-4">
+			<p>FEES</p>
+			<ol>
+				<li>
+					<p>Where expressly stipulated at the time that you accept an Assignment, you will receive payment
+					in respect of your provision of Services for an Assignment. The amount of the payment will be
+					stipulated in your Assignment. This payment will be processed following completion of the
+					Assignment by you provided that you have observed and performed the relevant obligations out
+					in these terms and conditions, and the Assignment (if any). Payment will be made by the Company
+					via BACS to your bank account within one week following completion of the relevant Services or
+					as stipulated in the Assignment particulars.</p>
+				</li>
+				<li>
+					<p>All fees received by you must be processed by you in accordance with your responsibilities as
+					stipulated within Clause 4.</p>
+				</li>
+			</ol>
+		</li>
+		<li class="mb-4">
+			<p>SELF-EMPLOYED STATUS</p>
+			<ol>
+				<li>
+					<p>You confirm that nothing in the course of our relationship shall render you to be an employee,
+					worker, agent or partner of the Company and you confirm that you will not hold yourself out as
+					such. Accordingly, you shall be fully responsible for and shall indemnify the Company for and in
+					respect of:</p>
+					<ol>
+						<li>
+							<p>any income tax, National Insurance and social security contributions and any other
+							liability, deduction, contribution, assessment or claim arising from or made in connection
+							with the performance of the Services Agreement where such recovery is not prohibited
+							by law;</p>
+						</li>
+						<li>
+							<p>all reasonable costs, expenses and any penalty, fine or interest incurred or payable by
+							the Company in connection with or in consequence of any such liability, deduction,
+							contribution, assessment or claim; and</p>
+						</li>
+						<li>
+							<p>any liability arising from any employment-related claim or any claim based on worker
+							status (including reasonable costs and expenses) brought by you against the Company
+							arising out of or in connection with your engagement by the Company.</p>
+						</li>
+					</ol>
+				</li>
+				<li>
+					<p>You confirm that the Company may at its option satisfy the indemnity as detailed above (in whole
+					or in part) by way of deduction from any payments due to you.</p>
+				</li>
+			</ol>
+		</li>
+		<li class="mb-4">
+			<p>LIABILITY</p>
+			<ol>
+				<li>
+					<p>This clause sets out the Company’s entire liability to you for all damages arising from breach of
+					agreement, tort (including negligence), and breach of statutory duty or otherwise.</p>
+				</li>
+				<li>
+					<p>Nothing in this agreement excludes or limits the liability of the Company for death or personal
+					injury caused by the Company’s negligence or for fraud or fraudulent misrepresentation.</p>
+				</li>
+				<li>
+					<p>Subject to clause 5.2, the Company shall not be liable to you for any loss of profit, loss of business,
+					loss of reputation or depletion of goodwill, loss of opportunity or for any indirect, consequential,
+					special or purely economic loss.</p>
+				</li>
+				<li>
+					<p>Subject to clause 5.2 and 5.3, the Company’s total liability to you arising under this agreement
+					shall be capped on a per claim basis at the lower of £500 or the payments made to you for the
+					three month period immediately prior to the date that your claim arose.</p>
+				</li>
+			</ol>
+		</li>
+
+		<li class="mb-4">
+			<p>TERMINATION</p>
+			<ol>
+				<li>
+					<p>The Company may terminate this agreement at any time. If the Company does terminate the
+					agreement, you will be notified in writing via the email address held by the Company at the time
+					of the termination.</p>
+				</li>
+				<li>
+					<p>You may terminate this agreement at any time by providing us with written notice which must be
+					sent to <a href="mailto:legal@check-policy.com">legal@check-policy.com</a>.</p>
+				</li>
+				<li>
+					<p>In the event that any aspect of the Assignment is found to be fraudulent, Check Policy reserves
+					the right to terminate this agreement with immediate effect and withhold any payments due.
+					Furthermore, your details may be disclosed to our Client for the purpose of investigating
+					allegations.</p>
+				</li>
+			</ol>
+		</li>
+
+		<li class="mb-4">
+			<p>GENERAL PROVISIONS</p>
+			<ol>
+				<li>
+					<p>If a court decides that any part of the agreement cannot be enforced, that particular part of the
+					agreement will not apply, but the rest of the agreement will. A waiver by a party of a breach of
+					any provision shall not be deemed a continuing waiver or a waiver of any subsequent breach of
+					the same or any other provisions. Failure or delay in exercising any right under the agreement
+					shall not prevent the exercise of that or any other right. You cannot assign or transfer any benefit,
+					burden, interest or obligation under the agreement. No person other than a party to this
+					agreement shall have any rights to enforce any terms of this agreement.</p>
+				</li>
+				<li>
+					<p>You must keep confidential all information that you receive in the course of providing the Services
+					and should not make any such information available to the public or to any third parties including
+					your friends or family without the Company’s prior written consent.</p>
+				</li>
+				<li>
+					<p>By entering into this agreement you consent to our use of your personal data in accordance with
+					our privacy policy which can be found here: <a href="https://check-policy.com">https://check-policy.com</a> - For the avoidance of
+					doubt we are obliged to include certain private data to our clients in order for them to rely upon
+					the report produced in support of their age verification and compliance procedures. In this regard
+					our report will include your name, date of birth, photograph and the date and time of visit to
+					their premises. This data is lawfully provided within the definitions of General Data Protection
+					Regulations as necessary in the performance of the tri partite contract between the parties.</p>
+				</li>
+				<li>
+					<p>This agreement and any dispute or claim arising out of or in connection with it or its subject
+					matter or formation (including non-contractual disputes or claims) shall be governed by and
+					construed in accordance with the law of England and Wales and the parties submit to the exclusive
+					jurisdiction of the courts of England and Wales to settle any such dispute or claim.</p>
+				</li>
+			</ol>
+		</li>
+
+	</ol>
+
+</div>

+ 23 - 0
views/terms_decline.php

@@ -0,0 +1,23 @@
+<div class="container mt-3 py-4">
+
+	<h2>Decline Terms and Conditions</h2>
+
+	<p>We are sorry that you have chosen not to accept our <a href="/terms-and-conditions">Terms and Conditions</a>.</p>
+
+	<p>Please select an action below:</p>
+
+	<div class="list-group">
+		<a class="list-group-item list-group-item-action" href="/account/deactivate">
+			<strong>Deactivate Account</strong><br />
+			Mark your account as deactivated. You will not be assigned any tests. You will be able to login to your account to reactivate your account and/or accept the Terms and Conditions if you choose to do so at a later date. You will be taken to a confirmation page before your account is deactivated.
+		</a>
+		<a class="list-group-item list-group-item-action text-danger" href="/account/delete">
+			<strong>Delete Account</strong><br />
+			Delete all personal identifiable information associated with your account. If you choose to use our services at a later date, you will be required to re-register. You will be taken to a confirmation page before your account is deleted.
+		</a>
+		<a class="list-group-item list-group-item-action text-success" href="/account/accept-terms">
+			<strong>Accept Terms and Conditions</strong>
+		</a>
+	</div>
+
+</div>

+ 248 - 170
views/user.php

@@ -54,198 +54,276 @@ var userId = <?=$user->id?>;
 		</div>
 		</div>
 	</div>
 	</div>
 
 
-	<div class="row">
-		<div class="col-md-8 col-lg-8 col-xl-9 mb-4">
-			<h3>General Details</h3>
+	<ul class="nav nav-tabs mb-3" id="user-tab" role="tablist">
+		<li class="nav-item">
+			<a class="nav-link active" id="general-details-tab" data-toggle="tab" href="#general-details" role="tab" aria-controls="general-details" aria-selected="true">General Details</a>
+		</li>
+		<li class="nav-item">
+			<a class="nav-link" id="addresses-tab" data-toggle="tab" href="#addresses" role="tab" aria-controls="addresses" aria-selected="true">Addresses</a>
+		</li>
+		<li class="nav-item">
+			<a class="nav-link" id="tests-tab" data-toggle="tab" href="#tests" role="tab" aria-controls="tests" aria-selected="true">Tests</a>
+		</li>
+		<li class="nav-item">
+			<a class="nav-link" id="nearby-locations-tab" data-toggle="tab" href="#nearby-locations" role="tab" aria-controls="nearby-locations" aria-selected="true">Nearby Locations</a>
+		</li>
+	</ul>
 
 
-			<div class="list-group">
-				<?php
-				foreach($details as $title => $html) {
-					?>
-					<div class="list-group-item">
-						<div class="row">
-							<div class="col-sm">
-								<?=htmlspecialchars($title)?>
-							</div>
-							<div class="col-sm-auto">
-								<?=$html?>
+	<div class="tab-content" id="user-tab-content">
+		<div class="tab-pane fade show active" id="general-details" role="tabpanel" aria-labelledby="general-details-tab">
+			<div class="row">
+				<div class="col-md-8 col-lg-8 col-xl-9 mb-4">
+					<h3>General Details</h3>
+
+					<div class="list-group">
+						<?php
+						foreach($details as $title => $html) {
+							?>
+							<div class="list-group-item">
+								<div class="row">
+									<div class="col-sm">
+										<?=htmlspecialchars($title)?>
+									</div>
+									<div class="col-sm-auto">
+										<?=$html?>
+									</div>
+								</div>
 							</div>
 							</div>
+							<?php
+						}
+						?>
+					</div>
+				</div>
+				<div class="col-md mb-4">
+					<h3>Photo / ID</h3>
+					<div class="card mb-3">
+						<div class="card-body text-center">
+							<a href="/account/users/<?=$user->id?>/photo">
+								<img class="img-fluid" src="/account/users/<?=$user->id?>/photo" alt="Photo" />
+							</a>
+						</div>
+					</div>
+					<div class="card">
+						<div class="card-body text-center">
+							<a href="/account/users/<?=$user->id?>/id-document">
+								<img class="img-fluid" src="/account/users/<?=$user->id?>/id-document" alt="ID Document" />
+							</a>
 						</div>
 						</div>
 					</div>
 					</div>
-					<?php
-				}
-				?>
-			</div>
-		</div>
-		<div class="col-md mb-4">
-			<h3>Photo / ID</h3>
-			<div class="card mb-3">
-				<div class="card-body text-center">
-					<a href="/account/users/<?=$user->id?>/photo">
-						<img class="img-fluid" src="/account/users/<?=$user->id?>/photo" alt="Photo" />
-					</a>
 				</div>
 				</div>
 			</div>
 			</div>
-			<div class="card">
-				<div class="card-body text-center">
-					<a href="/account/users/<?=$user->id?>/id-document">
-						<img class="img-fluid" src="/account/users/<?=$user->id?>/id-document" alt="ID Document" />
-					</a>
+		</div>
+		<div class="tab-pane fade" id="addresses" role="tabpanel" aria-labelledby="addresses-tab">
+			<h3>Addresses</h3>
+
+			<?php
+			if(empty($addresses)) {
+				?>
+				<div class="alert alert-info">This user has no addresses.</div>
+				<?php
+			}
+			else {
+				?>
+				<div class="row">
+					<div class="col-lg-6 mb-4">
+						<div class="list-group">
+						<?php
+						foreach($addresses as $address) {
+							?>
+							<div class="list-group-item">
+								<strong><?=htmlspecialchars($address->name)?></strong><br />
+								<small><?=htmlspecialchars($address->getDisplayAddress())?></small>
+							</div>
+							<?php
+						}
+						?>
+						</div>
+					</div>
+					<div class="col-lg-6 mb-4">
+						<div id="map" style="height: 248px;" data-maps data-lat="0" data-lng="0" data-zoom="10"></div>
+					</div>
 				</div>
 				</div>
-			</div>
+				<?php
+			}
+			?>
 		</div>
 		</div>
-	</div>
+		<div class="tab-pane fade" id="tests" role="tabpanel" aria-labelledby="tests-tab">
+			<h3>Assigned Tests</h3>
+
+			<?php
+			if(empty($pending_tests)) {
+				?>
+				<div class="alert alert-info">This user has no assigned tests.</div>
+				<?php
+			}
+			else {
+				?>
+				<table class="table table-sm table-hover">
+					<col style="width: 10%;" />
+					<col style="width: 40%;" />
+					<col style="width: 20%;" />
+					<col style="width: 10%;" />
+					<col style="width: 10%;" />
+					<thead>
+						<th>ID</th>
+						<th>Location</th>
+						<th>Project</th>
+						<th>Date Due</th>
+						<th></th>
+					</thead>
+				<?php
+				foreach($pending_tests as $test) {
+					$project = $test->getProject();
+					$location = $test->getLocation();
 
 
+					if(!is_null($test->dts_due)) {
+						$date = explode(" ", $test->dts_due)[0];
+						$unix_date = strtotime($date);
+					}
+					else {
+						$date = explode(" ", $project->dts_deadline)[0];
+						$unix_date = strtotime($date);
+					}
 
 
-	<h3>Addresses</h3>
+					$date = date("d/m/Y", $unix_date);
 
 
-	<?php
-	if(empty($addresses)) {
-		?>
-		<div class="alert alert-info">This user has no addresses.</div>
-		<?php
-	}
-	else {
-		?>
-		<div class="row">
-			<div class="col-lg-6 mb-4">
-				<div class="list-group">
+					?>
+						<tr>
+							<td><?=$test->id?></td>
+							<td>
+								<a href="/account/locations/<?=$location->id?>"><?=htmlspecialchars($location->name)?></a><br />
+								<small><?=htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city", "postcode"]))?></small>
+							</td>
+							<td class="align-middle">
+								<a href="/account/projects/<?=$project->id?>"><?=htmlspecialchars($project->name)?></a>
+							</td>
+							<td class="align-middle">
+								<?=$date?>
+							</td>
+							<td class="align-middle text-right">
+							</td>
+						</tr>
+					<?php
+				}
+				?>
+				</table>
 				<?php
 				<?php
-				foreach($addresses as $address) {
+			}
+			?>
+
+			<h3>Completed Tests</h3>
+
+			<?php
+			if(empty($completed_tests)) {
+				?>
+				<div class="alert alert-info">This user has no completed tests.</div>
+				<?php
+			}
+			else {
+				?>
+				<table class="table table-sm table-hover">
+					<col style="width: 10%;" />
+					<col style="width: 40%;" />
+					<col style="width: 20%;" />
+					<col style="width: 10%;" />
+					<col style="width: 10%;" />
+					<thead>
+						<th>ID</th>
+						<th>Location</th>
+						<th>Project</th>
+						<th>Date</th>
+						<th></th>
+					</thead>
+				<?php
+				foreach($completed_tests as $test) {
+					$project = $test->getProject();
+					$location = $test->getLocation();
+					$date = explode(" ", $test->dts_start)[0];
+					$date = date("d/m/Y", strtotime($date));
 					?>
 					?>
-					<div class="list-group-item">
-						<strong><?=htmlspecialchars($address->name)?></strong><br />
-						<small><?=htmlspecialchars($address->getDisplayAddress())?></small>
-					</div>
+						<tr>
+							<td><?=$test->id?></td>
+							<td>
+								<a href="/account/locations/<?=$location->id?>"><?=htmlspecialchars($location->name)?></a><br />
+								<small><?=htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city", "postcode"]))?></small>
+							</td>
+							<td class="align-middle">
+								<a href="/account/projects/<?=$project->id?>"><?=htmlspecialchars($project->name)?></a>
+							</td>
+							<td class="align-middle">
+								<?=$date?>
+							</td>
+							<td class="align-middle text-right">
+								<a class="btn btn-outline-primary" href="/account/tests/<?=$test->id?>">View</a>
+							</td>
+						</tr>
 					<?php
 					<?php
 				}
 				}
 				?>
 				?>
-				</div>
-			</div>
-			<div class="col-lg-6 mb-4">
-				<div id="map" style="height: 248px;" data-maps data-lat="0" data-lng="0" data-zoom="5" data-callback="initialiseAddresses"></div>
-			</div>
+				</table>
+				<?php
+			}
+			?>
 		</div>
 		</div>
-		<?php
-	}
-	?>
-
-	<h3>Assigned Tests</h3>
-
-	<?php
-	if(empty($pending_tests)) {
-		?>
-		<div class="alert alert-info">This user has no assigned tests.</div>
-		<?php
-	}
-	else {
-		?>
-		<table class="table table-sm table-hover">
-			<col style="width: 10%;" />
-			<col style="width: 40%;" />
-			<col style="width: 20%;" />
-			<col style="width: 10%;" />
-			<col style="width: 10%;" />
-			<thead>
-				<th>ID</th>
-				<th>Location</th>
-				<th>Project</th>
-				<th>Date Due</th>
-				<th></th>
-			</thead>
-		<?php
-		foreach($pending_tests as $test) {
-			$project = $test->getProject();
-			$location = $test->getLocation();
-
-			if(!is_null($test->dts_due)) {
-				$date = explode(" ", $test->dts_due)[0];
-				$unix_date = strtotime($date);
+		<div class="tab-pane fade" id="nearby-locations" role="tabpanel" aria-labelledby="nearby-locations-tab">
+			<h3>Nearby Locations</h3>
+
+			<?php
+			if(empty($addresses)) {
+				?>
+				<div class="alert alert-info">This user has no addresses so nearby locations cannot be displayed.</div>
+				<?php
 			}
 			}
 			else {
 			else {
-				$date = explode(" ", $project->dts_deadline)[0];
-				$unix_date = strtotime($date);
-			}
+				$address = $addresses[0];
+
+				?>
+				<div class="row">
+					<div class="col-lg-6 mb-4">
+						<select class="form-control mb-3" id="address-id">
+						<?php
+						foreach($addresses as $address) {
+							?>
+							<option value="<?=$address->id?>"><?=htmlspecialchars($address->name)?> - <?=htmlspecialchars($address->getDisplayAddress())?></option>
+							<?php
+						}
+						?>
+						</select>
 
 
-			$date = date("d/m/Y", $unix_date);
+						<div class="list-group" id="nearby-locations-list-group">
+						</div>
 
 
+						<div data-nearby-location-list-group-item-template class="list-group-item" style="display: none;" aria-hidden="true">
+							<div class="row">
+								<div class="col-md">
+									<a href="#" data-location-name>Location Name</a>
+								</div>
+								<div class="col-md-auto">
+									Distance: <span data-location-distance></span>
+								</div>
+							</div>
+							<span class="badge badge-primary">ID: <span data-location-id>123</span></span>
+							<span class="badge badge-info">Internal ID: <span data-location-internal-id>123</span></span><br />
+							<small data-location-address>Address</small>
+						</div>
+
+					</div>
+					<div class="col-lg-6 mb-4">
+						<div id="nearby-locations-map" style="height: 480px;" data-maps data-lat="<?=$address->latitude?>" data-lng="<?=$address->longitude?>" data-zoom="10">
+					</div>
+					</div>
+				</div>
+				<?php
+			}
 			?>
 			?>
-				<tr>
-					<td><?=$test->id?></td>
-					<td>
-						<a href="/account/locations/<?=$location->id?>"><?=htmlspecialchars($location->name)?></a><br />
-						<small><?=htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city", "postcode"]))?></small>
-					</td>
-					<td class="align-middle">
-						<a href="/account/projects/<?=$project->id?>"><?=htmlspecialchars($project->name)?></a>
-					</td>
-					<td class="align-middle">
-						<?=$date?>
-					</td>
-					<td class="align-middle text-right">
-					</td>
-				</tr>
-			<?php
-		}
-		?>
-		</table>
-		<?php
-	}
-	?>
-
-	<h3>Completed Tests</h3>
-
-	<?php
-	if(empty($completed_tests)) {
-		?>
-		<div class="alert alert-info">This user has no completed tests.</div>
-		<?php
-	}
-	else {
-		?>
-		<table class="table table-sm table-hover">
-			<col style="width: 10%;" />
-			<col style="width: 40%;" />
-			<col style="width: 20%;" />
-			<col style="width: 10%;" />
-			<col style="width: 10%;" />
-			<thead>
-				<th>ID</th>
-				<th>Location</th>
-				<th>Project</th>
-				<th>Date</th>
-				<th></th>
-			</thead>
-		<?php
-		foreach($completed_tests as $test) {
-			$project = $test->getProject();
-			$location = $test->getLocation();
-			$date = explode(" ", $test->dts_start)[0];
-			$date = date("d/m/Y", strtotime($date));
-			?>
-				<tr>
-					<td><?=$test->id?></td>
-					<td>
-						<a href="/account/locations/<?=$location->id?>"><?=htmlspecialchars($location->name)?></a><br />
-						<small><?=htmlspecialchars($location->getDisplayAddress(["address_1", "address_2", "city", "postcode"]))?></small>
-					</td>
-					<td class="align-middle">
-						<a href="/account/projects/<?=$project->id?>"><?=htmlspecialchars($project->name)?></a>
-					</td>
-					<td class="align-middle">
-						<?=$date?>
-					</td>
-					<td class="align-middle text-right">
-						<a class="btn btn-outline-primary" href="/account/tests/<?=$test->id?>">View</a>
-					</td>
-				</tr>
-			<?php
-		}
-		?>
-		</table>
-		<?php
-	}
-	?>
+
+
+
+		</div>
+	</div>
+
+
+
 
 
 
 
 </div>
 </div>

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików