Przeglądaj źródła

Add support for users to claim tests

Alan Lam 8 lat temu
rodzic
commit
0af58fb8a2

+ 1 - 0
controllers/project_add.php

@@ -39,6 +39,7 @@ if($submit) {
 		$project->max_age = http::value("max_age", "int");
 		$project->max_age = http::value("max_age", "int");
 		$project->default_tester_fee = http::value("default_tester_fee", "float");
 		$project->default_tester_fee = http::value("default_tester_fee", "float");
 		$project->time_of_day = http::value("time_of_day", "trim");
 		$project->time_of_day = http::value("time_of_day", "trim");
+		$project->tester_can_claim = http::value("tester_can_claim", "trim");
 
 
 		$date_start = http::getDateFromFields("date_start");
 		$date_start = http::getDateFromFields("date_start");
 		$date_deadline = http::getDateFromFields("date_deadline");
 		$date_deadline = http::getDateFromFields("date_deadline");

+ 1 - 0
controllers/project_edit.php

@@ -40,6 +40,7 @@ if($submit) {
 		$project->max_age = http::value("max_age", "int");
 		$project->max_age = http::value("max_age", "int");
 		$project->default_tester_fee = http::value("default_tester_fee", "float");
 		$project->default_tester_fee = http::value("default_tester_fee", "float");
 		$project->time_of_day = http::value("time_of_day", "trim");
 		$project->time_of_day = http::value("time_of_day", "trim");
+		$project->tester_can_claim = http::value("tester_can_claim", "trim");
 
 
 		$date_start = http::getDateFromFields("date_start");
 		$date_start = http::getDateFromFields("date_start");
 		$date_deadline = http::getDateFromFields("date_deadline");
 		$date_deadline = http::getDateFromFields("date_deadline");

+ 59 - 0
controllers/tests_available.php

@@ -0,0 +1,59 @@
+<?php
+
+Core::addScript("public/js/app-tests-available.js");
+
+$page_title = "Find Tests";
+
+Core::addBreadcrumb("/account", "Account");
+Core::addBreadcrumb("/account/tests", "Tests");
+Core::addBreadcrumb("/account/tests/available", $page_title);
+
+$user = Core::$user;
+if(!$user->can_claim) throw new Exception("You do not have permission to perform this action.");
+
+$dts = date("Y-m-d H:i:s");
+
+// Get active projects
+$projects = Project::query([
+	"tester_can_claim" => 1,
+	"dts_start" => (new Constraint("LESS_THAN_OR_EQUAL"))->setValues($dts),
+]);
+
+$project_ids = array_column($projects, "id");
+
+$tests = Test::query([
+	"project_id" => $project_ids,
+	"tester_id" => (new Constraint("IS_NULL")),
+	"status" => (new Constraint("MORE_THAN_OR_EQUAL"))->setValues(1),
+]);
+
+$locations = Location::load(array_column($tests, "location_id"));
+
+$addresses = $user->getAddresses();
+if(!$addresses) {
+	$latitude = 51.509865;
+	$longitude = -0.118092;
+}
+else {
+	$address = $addresses[0];
+	list($latitude, $longitude) = $address->getGeolocation();
+}
+
+// AJAX
+if(HTTP::isAJAX()) {
+	require "tests_available_ajax.php";
+}
+
+usort($tests, function($a, $b) use ($address) {
+	$distance_a = Geolocation::getDistance($a->getLocation()->getGeolocation(), $address->getGeolocation());
+	$distance_b = Geolocation::getDistance($b->getLocation()->getGeolocation(), $address->getGeolocation());
+
+	return $distance_a <=> $distance_b;
+});
+
+View::includeOnce("header", compact("page_title"));
+View::include("tests_available", compact("tests", "address", "latitude", "longitude"));
+View::include("modal_test_claim");
+View::includeOnce("footer");
+
+?>

+ 87 - 0
controllers/tests_available_ajax.php

@@ -0,0 +1,87 @@
+<?php
+JSON::header();
+
+$action = http::value("action");
+
+$response = [];
+
+switch($action) {
+
+	case "claim-test":
+
+		$id = http::value("id", "int");
+
+		$test = Test::queryOne([
+			"id" => $id,
+			"status" => Test::STATUS_UNASSIGNED,
+		]);
+
+		try {
+			if(!$test) throw new Exception("Test no longer available.");
+
+			$project = $test->getProject();
+
+			// Set due date
+			$date_due = date("Y-m-d", strtotime("+7 DAYS"));
+			$unix_due = strtotime("$date_due 23:59:59");
+
+			$user = Core::$user;
+			if($user->level == User::LEVEL_BANNED) throw new Exception("You are a banned tester.");
+			if($user->level == User::LEVEL_REGISTERED) throw new Exception("Your account is not verified.");
+			if($user->level == User::LEVEL_UNVERIFIED) throw new Exception("Your account is not verified.");
+			if($user->level == User::LEVEL_DEACTIVATED) throw new Exception("Your account is deactivated.");
+			if($user->level != User::LEVEL_TESTER) throw new Exception("You are not a tester.");
+
+			$test->status = Test::STATUS_CONFIRMED;
+			$test->tester_id = $user->id;
+			$test->dts_assigned = Util::getDateTime();
+			$test->dts_updated = Util::getDateTime();
+
+			if($unix_due) {
+				$test->dts_due = "$date_due 23:59:59";
+				if(strcmp($test->dts_due, $project->dts_start) < 0) throw new Exception("Too early.");
+			}
+
+			$success = $test->commit();
+			if(!$success) throw new Exception("Test cannot be claimed, please try again later.");
+
+			$test->sendClaimedEmail();
+		}
+		catch(Exception $e) {
+			JSON::fail($e->getMessage());
+		}
+
+		JSON::success();
+
+		break;
+
+	case "get-tests":
+
+		$output = [];
+
+		foreach($tests as $test) {
+
+			$location = $test->getLocation();
+
+			$output[] = (object) [
+				"id" => (int) $test->id,
+				"location" => (object) [
+					"id" => (int) $location->id,
+					"name" => $location->name,
+					"address" => $location->getDisplayAddress(),
+					"geolocation" => $location->getGeolocation(),
+				],
+			];
+
+		}
+
+		$response["tests"] = $output;
+
+		break;
+	default:
+		throw new Exception("Invalid action.");
+}
+
+JSON::success($response);
+
+?>

+ 1 - 0
controllers/user_edit.php

@@ -40,6 +40,7 @@ if($submit) {
 		$user->phone = http::value("phone", "trim");
 		$user->phone = http::value("phone", "trim");
 		$user->gender = http::value("gender", "trim");
 		$user->gender = http::value("gender", "trim");
 		$user->activated = http::value("activated", "int");
 		$user->activated = http::value("activated", "int");
+		$user->can_claim = http::value("can_claim", "int");
 
 
 		if($password && !User::validatePassword($password)) $form_exception->addError("Password must be at least 6 characters in length and contain at least one lowercase, uppercase, number and special character.");
 		if($password && !User::validatePassword($password)) $form_exception->addError("Password must be at least 6 characters in length and contain at least one lowercase, uppercase, number and special character.");
 		if(!isset(User::LEVELS[$user->level])) $form_exception->addError("User level is invalid.");
 		if(!isset(User::LEVELS[$user->level])) $form_exception->addError("User level is invalid.");

+ 2 - 1
engine/db.php

@@ -115,7 +115,8 @@ class db {
 					return "'$str'";
 					return "'$str'";
 				}, $value);
 				}, $value);
 
 
-				$string_array[] = "`$field` IN (" . implode(", ", $values) . ")";
+				if(empty($value)) $string_array[] = "0"; // Empty array
+				else $string_array[] = "`$field` IN (" . implode(", ", $values) . ")";
 			}
 			}
 			else if(is_a($value, "Constraint")) {
 			else if(is_a($value, "Constraint")) {
 				$string_array[] = "`$field` " . $value->getConstraintString();
 				$string_array[] = "`$field` " . $value->getConstraintString();

+ 1 - 1
engine/project.php

@@ -4,7 +4,7 @@ class Project extends Model {
 
 
 	protected static $table = "project";
 	protected static $table = "project";
 	protected static $id_field = "id";
 	protected static $id_field = "id";
-	protected static $fillable_fields = ["customer_id", "template_id", "name", "test_count", "min_age", "max_age", "default_tester_fee", "time_of_day", "dts_start", "dts_deadline", "dts_created", "dts_updated", "dts_report"];
+	protected static $fillable_fields = ["customer_id", "template_id", "name", "test_count", "min_age", "max_age", "default_tester_fee", "time_of_day", "tester_can_claim", "dts_start", "dts_deadline", "dts_created", "dts_updated", "dts_report"];
 
 
 	protected static $field_map = [
 	protected static $field_map = [
 	];
 	];

+ 31 - 0
engine/test.php

@@ -82,6 +82,37 @@ class Test extends Model {
 		$mail->send();
 		$mail->send();
 	}
 	}
 
 
+	public function sendClaimedEmail() {
+
+		$tester = $this->getTester();
+		$location = $this->getLocation();
+
+		// Content
+		$name = htmlspecialchars($tester->first_name);
+		$address = htmlspecialchars($location->name . ", " . $location->getDisplayAddress(["address_1", "address_2", "city", "county", "postal_code"]));
+		$date_due = date("j M Y", strtotime($this->dts_due));
+
+		// Build
+		$builder = new EmailBuilder;
+		$builder->addParagraph("<b>Hi $name,</b>");
+		$builder->addLeadParagraph("Congrats, you have claimed a test!");
+		$builder->addParagraph("The site address is: <b>$address</b>");
+		$builder->addParagraph("The date that need to complete and submit the results by is: <font color=\"red\"><b>$date_due</b></font>");
+		$builder->addParagraph("For methodology and further notes please check the <b>Useful Documents</b> section on the <b>Account</b> page.");
+		$builder->addParagraph("Log in and then go to <b>Tests</b> where you will be able to see the tests available to you. Please tap the <b>Begin</b> button and follow the instructions that is shown.");
+		$builder->addParagraph("If you have any questions please send them to <a href=\"mailto:tests@check-policy.com\">tests@check-policy.com</a> or call <b>Check Policy</b> on 07841 353775.");
+		$builder->addParagraph("If you are unable to submit the results via the web-based app please contact us and we can send you an offline form to complete.");
+		$content = $builder->build();
+
+		// Send
+		$mail = new Email;
+		$mail->setHtmlContent($content);
+		$mail->setFrom(EMAIL_CONTACT, EMAIL_FROM_NAME);
+		$mail->addAddress($tester->email, $tester->getDisplayName());
+		$mail->setSubject("You have claimed a test");
+		$mail->send();
+	}
+
 	public function sendDeclineEmail() {
 	public function sendDeclineEmail() {
 
 
 		$tester = $this->getTester();
 		$tester = $this->getTester();

+ 1 - 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", "reported", "reported_comment", "phone", "verify_token", "reset_token", "terms_accepted", "preferred_payment_method", "bank_name", "bank_sort_code", "bank_account_number", "paypal_email", "dts_registered", "dts_last_seen", "dts_verified", "dts_deleted", "verifier_id", "verifier_notes"];
+	protected static $fillable_fields = ["email", "old_id", "referrer_id", "password", "activated", "level", "score", "title", "first_name", "last_name", "gender", "date_of_birth", "reported", "reported_comment", "can_claim", "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
 
 

+ 170 - 0
public/js/app-tests-available.js

@@ -0,0 +1,170 @@
+$(function() {
+
+	$(".btn[data-test-id]").click(function() {
+		let testId = $(this).data("test-id");
+		toggleTest(testId);
+	});
+
+
+	$("#modal-test-claim").on("shown.bs.modal", function() {
+
+		$("#modal-confirm-button").removeClass("disabled");
+
+		let listGroup = $(this).find(".list-group");
+		$(listGroup).empty();
+
+		for(let i in selectedTests) {
+			let test = selectedTests[i];
+			let location = test.location;
+
+			$(listGroup).append('<div class="list-group-item d-flex justify-content-between" data-test-id="' + test.id + '">\
+				<div>\
+					' + location.name + '<br />\
+					<small class="text-danger" data-fail-message></small>\
+				</div>\
+				<span class="badge badge-lg badge-secondary align-self-center">Unclaimed</span>\
+			</div>');
+
+		}
+
+	});
+
+	$("#claim-confirm-button").click(function() {
+		if(queueInProgress) return;
+
+		$("#claim-cancel-button").hide();
+		$("#modal-close-button").hide();
+
+		$(this).addClass("disabled").text("Please wait...");
+		queuedTests = selectedTests.slice(0); // Clone
+		queueInProgress = true;
+		claimTests();
+	});
+
+});
+
+var markers = [];
+var selectedTests = [];
+var queuedTests = [];
+var queueInProgress = false;
+var tests = [];
+
+function getTests() {
+	$.get(window.location, {
+		action: "get-tests"
+	}, function(response) {
+		if(!response.success) return false;
+
+		let map = maps["map"];
+
+		for(var i in response.tests) {
+			let test = response.tests[i];
+			let location = test.location;
+
+			let latLng = {
+				lat: location.geolocation[0],
+				lng: location.geolocation[1],
+			};
+
+			let markerOptions = {
+				position: latLng,
+				map: map,
+				title: location.name,
+				icon: "/img/markers/building-grey.png"
+			};
+
+			let marker = new google.maps.Marker(markerOptions);
+			marker.testId = test.id;
+
+			tests[test.id] = test;
+
+			markers.push(marker);
+
+			marker.addListener("click", function() {
+				let testId = this.testId;
+				toggleTest(testId);
+			});
+		}
+
+	});
+}
+
+function toggleTest(id) {
+	let test = tests[id];
+	let index = selectedTests.indexOf(test);
+
+	if(index == -1) {
+		var icon = "building-green";
+		var btnFromClass = "btn-primary";
+		var btnToClass = "btn-danger";
+		var btnText = "Deselect";
+		selectedTests.push(test);
+
+	}
+	else {
+		var icon = "building-grey";
+		var btnFromClass = "btn-danger";
+		var btnToClass = "btn-primary";
+		var btnText = "Select";
+		selectedTests.splice(index, 1);
+	}
+
+	for(var i in markers) {
+		let marker = markers[i];
+		if(marker.testId == id) {
+			marker.setIcon("/img/markers/" + icon + ".png");
+		}
+	}
+
+	let selectedCount = selectedTests.length;
+
+	$(".btn[data-test-id=" + id + "]").removeClass(btnFromClass).addClass(btnToClass).text(btnText);
+	$("#claim-number").text(selectedCount);
+
+	if(selectedCount > 0) {
+		$("#claim-tests-button").removeClass("disabled");
+	}
+	else {
+		$("#claim-tests-button").addClass("disabled");
+	}
+
+}
+
+function claimTests() {
+	if(queuedTests.length > 0) {
+		let test = queuedTests.shift();
+		claimTest(test);
+	}
+	else {
+		$("#claim-confirm-button").hide();
+		$("#claim-finish-button").show();
+		queueInProgress = false;
+	}
+}
+
+function claimTest(test) {
+
+	let testId = test.id;
+	let listGroupItem = $("#modal-test-claim").find(".list-group-item[data-test-id=" + testId + "]");
+	let badge = $(listGroupItem).find(".badge");
+	let failMessage = $(listGroupItem).find("small[data-fail-message]");
+
+	badge.removeClass("badge-secondary").addClass("badge-warning").html("<i class=\"far fa-sync fa-pulse\"></i> Claiming...");
+
+	$.post(window.location, {
+		action: "claim-test",
+		id: test.id
+	}, function(response) {
+		if(response.success) {
+			badge.removeClass("badge-warning").addClass("badge-success").html("<i class=\"far fa-check\"></i> Claimed");
+		}
+		else {
+			badge.removeClass("badge-warning").addClass("badge-danger").html("<i class=\"far fa-times\"></i> Failed");
+			failMessage.text(response.message);
+		}
+
+		// Next
+		claimTests();
+	});
+
+}

+ 1 - 0
routes.php

@@ -71,6 +71,7 @@ $routes = [
 	// Tests
 	// Tests
 	"/^account\/tests$/" => ["controller" => "tests", "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/tests$/" => ["controller" => "tests", "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/tests\/kml$/" => ["controller" => "tests_tester_kml", "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/tests\/kml$/" => ["controller" => "tests_tester_kml", "require_user_level" => User::LEVEL_TESTER],
+	"/^account\/tests\/available$/" => ["controller" => "tests_available", "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/tests\/completed$/" => ["controller" => "tests_completed", "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/tests\/completed$/" => ["controller" => "tests_completed", "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/tests\/$id_pattern$/" => ["controller" => "test", "params" => ["id"], "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/tests\/$id_pattern$/" => ["controller" => "test", "params" => ["id"], "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/tests\/$id_pattern\/(selfie)$/" => ["controller" => "test_file", "params" => ["id", "name"], "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/tests\/$id_pattern\/(selfie)$/" => ["controller" => "test_file", "params" => ["id", "name"], "require_user_level" => User::LEVEL_TESTER],

+ 45 - 0
views/modal_test_claim.php

@@ -0,0 +1,45 @@
+<?php
+
+$unix_default = strtotime("+7 DAYS");
+$selected_year = date("Y", $unix_default);
+$selected_month = date("n", $unix_default);
+$selected_day = date("j", $unix_default);
+
+?>
+<div class="modal fade" id="modal-test-claim" tabindex="-1" role="dialog" data-backdrop="static">
+	<div class="modal-dialog modal-lg" role="document">
+		<div class="modal-content">
+			<form>
+				<div class="modal-header">
+					<h5 class="modal-title"><strong>Confirm Selected Tests</strong></h5>
+					<button type="button" class="close" data-dismiss="modal" aria-label="Close" id="modal-close-button">
+						<span aria-hidden="true">&times;</span>
+					</button>
+				</div>
+				<div class="modal-body">
+
+					<p>You have selected the following tests:</p>
+
+					<div class="list-group limit-height-2 mb-3">
+					</div>
+
+					<p>The due date is: <strong class="text-danger"><?=date("l jS F", $unix_default)?></strong></p>
+
+					<p>By confirming, you agree that:</p>
+
+					<ul>
+						<li>You will execute these tests by the due date displayed above.</li>
+						<li>Failure to complete tests by the due date without good reason may result in the tests being unassigned from yourself and limit your ability to claim tests in the future.</li>
+					</ul>
+
+
+				</div>
+				<div class="modal-footer">
+					<button type="button" class="btn btn-secondary" id="claim-cancel-button" data-dismiss="modal">Cancel</button>
+					<button type="button" class="btn btn-primary" id="claim-confirm-button">Confirm</button>
+					<a class="btn btn-primary" id="claim-finish-button" style="display: none;" href="/account/tests/available">Finish</a>
+				</div>
+			</form>
+		</div>
+	</div>
+</div>

+ 16 - 1
views/project_form.php

@@ -32,7 +32,6 @@ $time_of_day_options = [
 		<div class="row">
 		<div class="row">
 			<div class="col-lg">
 			<div class="col-lg">
 
 
-
 				<div class="row mb-1">
 				<div class="row mb-1">
 					<label class="col-sm-4 col-form-label" for="name">Name</label>
 					<label class="col-sm-4 col-form-label" for="name">Name</label>
 					<div class="col-sm">
 					<div class="col-sm">
@@ -87,6 +86,22 @@ $time_of_day_options = [
 						</select>
 						</select>
 					</div>
 					</div>
 				</div>
 				</div>
+				<div class="row mb-1">
+					<label class="col-sm-4 col-form-label" for="tester-can-claim">Tester Can Claim</label>
+					<div class="col-sm">
+						<select class="form-control" name="tester_can_claim" id="tester-can-claim">
+						<?php
+						foreach(Form::BOOLEAN_OPTIONS as $value => $display) {
+							$selected = ($value == $project->tester_can_claim) ? "selected" : "";
+							?>
+							<option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
+							<?php
+						}
+						?>
+						</select>
+						<small class="form-text text-muted">Tests will appear in "Find Tests" for testers.</small>
+					</div>
+				</div>
 			</div>
 			</div>
 			<div class="col-lg">
 			<div class="col-lg">
 
 

+ 17 - 10
views/test_list_assigned.php

@@ -2,25 +2,32 @@
 
 
 	<div class="row">
 	<div class="row">
 		<div class="col">
 		<div class="col">
-			<h2>Your Tests</h2>
+			<h2>Tests</h2>
 		</div>
 		</div>
+		<div class="col-auto">
 		<?php
 		<?php
+
+		if(Core::$user->can_claim) {
+			?>
+			<a class="btn btn-primary" href="/account/tests/available">Find Tests</a>
+			<?php
+		}
+
 		if(!empty($tests)) {
 		if(!empty($tests)) {
 			?>
 			?>
-			<div class="col-auto">
-				<div class="dropdown">
-					<a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="actions-button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
-						Actions
-					</a>
+			<div class="dropdown">
+				<a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="actions-button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+					Actions
+				</a>
 
 
-					<div class="dropdown-menu" aria-labelledby="actions-button">
-						<a class="dropdown-item" href="/account/tests/kml">Export KML</a>
-					</div>
+				<div class="dropdown-menu" aria-labelledby="actions-button">
+					<a class="dropdown-item" href="/account/tests/kml">Export KML</a>
 				</div>
 				</div>
 			</div>
 			</div>
 			<?php
 			<?php
 		}
 		}
 		?>
 		?>
+		</div>
 	</div>
 	</div>
 
 
 
 
@@ -29,7 +36,7 @@
 	if(empty($tests)) {
 	if(empty($tests)) {
 		?>
 		?>
 		<div class="alert alert-info">
 		<div class="alert alert-info">
-			There are no tests assigned to you at this time.
+			No tests have been assigned to you at this time.
 		</div>
 		</div>
 		<?php
 		<?php
 	}
 	}

+ 1 - 1
views/tests.php

@@ -7,7 +7,7 @@
 	if(empty($tests)) {
 	if(empty($tests)) {
 		?>
 		?>
 		<div class="alert alert-info">
 		<div class="alert alert-info">
-			There are no tests for you at this time.
+			You have no assigned tests at this time.
 		</div>
 		</div>
 		<?php
 		<?php
 	}
 	}

+ 60 - 0
views/tests_available.php

@@ -0,0 +1,60 @@
+<div class="container mt-3 py-4">
+
+	<input type="hidden" id="csrf-token" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>" />
+
+	<div class="row">
+		<div class="col">
+			<h2>Find Tests</h2>
+		</div>
+		<div class="col-auto">
+			<a id="claim-tests-button" class="btn btn-primary disabled" href="#" data-toggle="modal" data-target="#modal-test-claim">Claim <span id="claim-number">0</span> ...</a>
+		</div>
+	</div>
+
+	<div class="card mb-3">
+		<div class="card-body">
+			On this page you can search for tests that are currently available. Please use the "Select" buttons or click on the map markers to select and deselect a test. After you have made your selections, please click the "Claim" button on the top-right of this page to assign yourself the tests.
+		</div>
+	</div>
+
+	<div class="row">
+		<div class="col-lg-6 order-2 order-lg-1 mb-3 mb-lg-0">
+			<div class="list-group limit-height-2">
+			<?php
+			foreach($tests as $test) {
+				$location = $test->getLocation();
+				$distance = Geolocation::getDistance($location->getGeolocation(), $address->getGeolocation());
+				$distance_formatted = number_format($distance, 1);
+				?>
+				<div class="list-group-item">
+					<div class="d-flex justify-content-between">
+						<div>
+							<?=htmlspecialchars($location->name)?><br />
+							<small><?=htmlspecialchars($location->getDisplayAddress())?></small><br />
+							<small><?=htmlspecialchars($distance_formatted)?> mi from your <?=htmlspecialchars($address->name)?> address.</small>
+						</div>
+						<button class="btn btn-primary align-self-start" data-test-id="<?=$test->id?>">Select</button>
+					</div>
+				</div>
+				<?php
+			}
+			?>
+			</div>
+		</div>
+		<div class="col-lg-6 order-1 order-lg-2 mb-3 mb-lg-0">
+
+			<div class="input-group mb-3">
+				<div class="input-group-prepend">
+					<span class="input-group-text">
+						Location
+					</span>
+				</div>
+				<input class="form-control" type="text" data-autocomplete="map" />
+			</div>
+
+			<div id="map" data-maps data-lat="<?=$latitude?>" data-lng="<?=$longitude?>" data-zoom="9" data-callback="getTests" style="width: 100%; height: 458px;">
+			</div>
+		</div>
+	</div>
+
+</div>

+ 17 - 0
views/user_edit_form.php

@@ -2,6 +2,7 @@
 
 
 $date_of_birth_parts = explode("-", $user->date_of_birth);
 $date_of_birth_parts = explode("-", $user->date_of_birth);
 $activated_checked = ($user->activated) ? "checked" : "";
 $activated_checked = ($user->activated) ? "checked" : "";
+$can_claim_checked = ($user->can_claim) ? "checked" : "";
 
 
 ?>
 ?>
 <script>
 <script>
@@ -157,6 +158,22 @@ var userId = <?=$user->id?>;
 						<textarea class="form-control" name="reported_comment" id="reported-comment" placeholder="Enter reported notes" rows="4"><?=htmlspecialchars($user->reported_comment)?></textarea>
 						<textarea class="form-control" name="reported_comment" id="reported-comment" placeholder="Enter reported notes" rows="4"><?=htmlspecialchars($user->reported_comment)?></textarea>
 					</div>
 					</div>
 				</div>
 				</div>
+
+				<div class="row mb-1">
+					<label class="col-sm-4 col-form-label" for="can-claim">Enable "Find Tests"</label>
+					<div class="col-sm">
+						<select class="form-control" name="can_claim" id="can-claim" />
+						<?php
+						foreach(Form::BOOLEAN_OPTIONS as $value => $display) {
+							$selected = ($user->can_claim == $value) ? "selected" : "";
+							?>
+							<option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
+							<?php
+						}
+						?>
+						</select>
+					</div>
+				</div>
 			</div>
 			</div>
 			<div class="col-lg-6 mb-3">
 			<div class="col-lg-6 mb-3">