Browse Source

Merge branch 'develop'

Alan Lam 8 years ago
parent
commit
a44b74e595

+ 1 - 0
.gitignore

@@ -11,3 +11,4 @@ tasks/email_test.php
 tasks/data/
 backups/
 files/countries.json
+scrap/

+ 2 - 1
composer.json

@@ -1,5 +1,6 @@
 {
     "require": {
-        "phpmailer/phpmailer": "^6.0"
+        "phpmailer/phpmailer": "^6.0",
+		"phpoffice/phppresentation": "dev-master"
     }
 }

+ 170 - 7
composer.lock

@@ -4,20 +4,57 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
         "This file is @generated automatically"
     ],
-    "content-hash": "6d67203b6e9fc952ae681c538683a497",
+    "content-hash": "d3cdf144ec8301681fb8f12546af92b8",
     "packages": [
+        {
+            "name": "pclzip/pclzip",
+            "version": "2.8.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/ivanlanin/pclzip.git",
+                "reference": "19dd1de9d3f5fc4d7d70175b4c344dee329f45fd"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/ivanlanin/pclzip/zipball/19dd1de9d3f5fc4d7d70175b4c344dee329f45fd",
+                "reference": "19dd1de9d3f5fc4d7d70175b4c344dee329f45fd",
+                "shasum": ""
+            },
+            "type": "library",
+            "autoload": {
+                "classmap": [
+                    "pclzip.lib.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "LGPL-2.1"
+            ],
+            "authors": [
+                {
+                    "name": "Vincent Blavet"
+                }
+            ],
+            "description": "A PHP library that offers compression and extraction functions for Zip formatted archives",
+            "homepage": "http://www.phpconcept.net/pclzip",
+            "keywords": [
+                "php",
+                "zip"
+            ],
+            "time": "2014-06-05T11:42:24+00:00"
+        },
         {
             "name": "phpmailer/phpmailer",
-            "version": "v6.0.3",
+            "version": "v6.0.5",
             "source": {
                 "type": "git",
                 "url": "https://github.com/PHPMailer/PHPMailer.git",
-                "reference": "44d49bab5ab1fef721d3ee07e75dc0865ddf4cc6"
+                "reference": "cb3ea134d4d3729e7857737d5f320cce9caf4d32"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/44d49bab5ab1fef721d3ee07e75dc0865ddf4cc6",
-                "reference": "44d49bab5ab1fef721d3ee07e75dc0865ddf4cc6",
+                "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/cb3ea134d4d3729e7857737d5f320cce9caf4d32",
+                "reference": "cb3ea134d4d3729e7857737d5f320cce9caf4d32",
                 "shasum": ""
             },
             "require": {
@@ -70,13 +107,139 @@
                 }
             ],
             "description": "PHPMailer is a full-featured email creation and transfer class for PHP",
-            "time": "2018-01-05T13:19:58+00:00"
+            "time": "2018-03-27T13:49:45+00:00"
+        },
+        {
+            "name": "phpoffice/common",
+            "version": "0.2.9",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/PHPOffice/Common.git",
+                "reference": "edb5d32b1e3400a35a5c91e2539ed6f6ce925e4d"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/PHPOffice/Common/zipball/edb5d32b1e3400a35a5c91e2539ed6f6ce925e4d",
+                "reference": "edb5d32b1e3400a35a5c91e2539ed6f6ce925e4d",
+                "shasum": ""
+            },
+            "require": {
+                "pclzip/pclzip": "^2.8",
+                "php": ">=5.3.0"
+            },
+            "require-dev": {
+                "phpdocumentor/phpdocumentor": "2.*",
+                "phploc/phploc": "2.*",
+                "phpmd/phpmd": "2.*",
+                "phpunit/phpunit": "^4.8.36 || ^7.0",
+                "sebastian/phpcpd": "2.*",
+                "squizlabs/php_codesniffer": "2.*"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "PhpOffice\\Common\\": "src/Common/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "LGPL"
+            ],
+            "authors": [
+                {
+                    "name": "Mark Baker"
+                },
+                {
+                    "name": "Franck Lefevre",
+                    "homepage": "http://rootslabs.net"
+                }
+            ],
+            "description": "PHPOffice Common",
+            "homepage": "http://phpoffice.github.io",
+            "keywords": [
+                "common",
+                "component",
+                "office",
+                "php"
+            ],
+            "time": "2018-07-13T14:12:34+00:00"
+        },
+        {
+            "name": "phpoffice/phppresentation",
+            "version": "dev-master",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/PHPOffice/PHPPresentation.git",
+                "reference": "1fcc84072ee0061f8991b8f83050a99e706fe5ce"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/PHPOffice/PHPPresentation/zipball/1fcc84072ee0061f8991b8f83050a99e706fe5ce",
+                "reference": "1fcc84072ee0061f8991b8f83050a99e706fe5ce",
+                "shasum": ""
+            },
+            "require": {
+                "ext-xml": "*",
+                "ext-zip": "*",
+                "php": ">=5.3.0",
+                "phpoffice/common": "0.2.*"
+            },
+            "require-dev": {
+                "codeclimate/php-test-reporter": "dev-master",
+                "phpdocumentor/phpdocumentor": "2.*",
+                "phploc/phploc": "2.*",
+                "phpmd/phpmd": "2.*",
+                "phpunit/phpunit": "3.7.*",
+                "sebastian/phpcpd": "2.*",
+                "squizlabs/php_codesniffer": "2.*",
+                "twig/twig": "1.27"
+            },
+            "suggest": {
+                "ext-gd2": "Required to add images"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "PhpOffice\\PhpPresentation\\": "src/PhpPresentation/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "LGPL"
+            ],
+            "authors": [
+                {
+                    "name": "Mark Baker"
+                },
+                {
+                    "name": "Ivan Lanin",
+                    "homepage": "http://ivan.lanin.org"
+                },
+                {
+                    "name": "Franck Lefevre",
+                    "homepage": "http://rootslabs.net"
+                }
+            ],
+            "description": "PHPPresentation - Read, Create and Write Presentations documents in PHP",
+            "homepage": "http://phpoffice.github.io",
+            "keywords": [
+                "LibreOffice",
+                "PowerPoint",
+                "odp",
+                "php",
+                "ppt",
+                "pptx",
+                "presentations"
+            ],
+            "time": "2017-07-05 12:13:02"
         }
     ],
     "packages-dev": [],
     "aliases": [],
     "minimum-stability": "stable",
-    "stability-flags": [],
+    "stability-flags": {
+        "phpoffice/phppresentation": 20
+    },
     "prefer-stable": false,
     "prefer-lowest": false,
     "platform": [],

+ 20 - 60
controllers/performance.php

@@ -23,6 +23,7 @@ $from_quarter = http::value("from_quarter");
 $to_quarter = http::value("to_quarter");
 
 $project_ids = http::value("project_ids", "int");
+if(!is_array($project_ids)) $project_ids = [];
 
 $all_projects = Project::query([
 	"customer_id" => $customer->id
@@ -444,66 +445,10 @@ if($submit) {
 			]
 		]);
 		$chart->setDatalabelSuffixes(" Test");
-
-		// Generate table
-		ob_start();
-		?>
-
-		<table class="table table-sm small table-bordered mt-3">
-			<thead>
-				<tr>
-					<th></th>
-					<th>Stage 1</th>
-					<th>Stage 2</th>
-					<th>Stage 3</th>
-					<th>Stage 4</th>
-					<th>Stage 5</th>
-				</tr>
-			</thead>
-			<tbody>
-			<?php
-			foreach(["value", "percent"] as $field) {
-
-				switch($field) {
-					case "value": $label = "Test Count"; break;
-					case "percent": $label = "Percentage"; break;
-				}
-
-				?>
-				<tr>
-					<td><?=htmlspecialchars($label)?></td>
-					<?php
-					foreach(range(1, 5) as $stage) {
-
-						$key = "stage{$stage}Count";
-						$count = $total_data->{$key};
-
-						switch($field) {
-							case "value":
-								$string = $count;
-								break;
-							case "percent":
-								$string = (floor(($count * 10000) / $test_count) / 100) . "%";
-								break;
-						}
-
-						?>
-						<td class="text-right"><?=$string?></td>
-						<?php
-					}
-					?>
-				</tr>
-				<?php
-
-			}
-			?>
-			</tbody>
-		</table>
-
-		<?php
-		$html = ob_get_clean();
-
-		$chart->setAfterHtml($html);
+		$chart->setPrintSuffixes("");
+		$chart->print = true;
+		$chart->printPercentages = true;
+		$chart->setPrintLabels(["Stage 1", "Stage 2", "Stage 3", "Stage 4", "Stage 5"]);
 
 		$charts[] = $chart;
 
@@ -827,6 +772,21 @@ if($submit) {
 		Core::addAlert("danger", $e->getMessage());
 	}
 
+
+	// Export hook
+	if(!empty($action)) {
+		switch($action) {
+			case "export-pptx":
+			case "export-odp":
+
+				require "performance_presentation.php";
+
+				break;
+			default:
+				break;
+		}
+	}
+
 }
 
 

+ 185 - 0
controllers/performance_presentation.php

@@ -0,0 +1,185 @@
+<?php
+
+use PhpOffice\PhpPresentation\PhpPresentation;
+use PhpOffice\PhpPresentation\IOFactory;
+use PhpOffice\PhpPresentation\Style\Color;
+use PhpOffice\PhpPresentation\Style\Alignment;
+use PhpOffice\PhpPresentation\Shape\Drawing\Base64;
+
+$presentation = new PhpPresentation(); // 960x720
+
+// Draw title slide
+{
+	// Create slide
+	$slide = $presentation->getActiveSlide();
+
+	// Create a shape (drawing)
+	$shape = $slide->createDrawingShape();
+	$shape->setName("Check Policy logo")
+		  ->setDescription("Check Policy logo")
+		  ->setPath("./public/img/logo.png")
+		  ->setWidth(200)
+		  ->setOffsetX(380)
+		  ->setOffsetY(10);
+
+	// Title
+	$shape = $slide->createRichTextShape()
+		  ->setHeight(120)
+		  ->setWidth(940)
+		  ->setOffsetX(10)
+		  ->setOffsetY(315);
+	$shape->getActiveParagraph()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_CENTER );
+	$run = $shape->createTextRun($customer->name . " " . date("F Y") . " Tests");
+	$run->getFont()->setBold(true)
+					   ->setSize(45);
+}
+
+$names = [];
+
+$charts_b64 = http::value("charts_b64");
+foreach($charts_b64 as $index => $b64) {
+
+	$chart = $charts[$index];
+
+	$labels = $chart->getLabels();
+	$datasets = $chart->getDatasets();
+
+	$column_count = 1 + count($labels);
+
+	$slide = $presentation->createSlide();
+
+	list($ignore, $png_b64) = explode("base64,", $b64);
+
+	$name = tempnam("/tmp", "ppt");
+	$name .= ".png";
+
+	$handle = fopen($name, "w");
+	fwrite($handle, base64_decode($png_b64));
+
+	fclose($handle);
+
+	$chart_offset_y = 100;
+	if($chart->print) {
+		$chart_offset_y = 10;
+	}
+
+
+	$shape = $slide->createDrawingShape();
+	$shape->setName("Chart")
+		->setDescription("Chart")
+		->setPath($name)
+		->setHeight(520)
+		->setOffsetX(133)
+		->setOffsetY($chart_offset_y);
+
+
+	if($chart->print) {
+		// Table
+
+		$shape = $slide->createTableShape($column_count)
+			->setWidth(900)
+			->setOffsetX(30)
+			->setOffsetY(540);
+		// Create header row
+		$row = $shape->createRow();
+		$row->setHeight(20);
+		$cell = $row->nextCell();
+
+		$labels = $chart->getPrintLabels() ?? $chart->getLabels();
+
+		foreach($labels as $label) {
+			$cell = $row->nextCell();
+			$cell->getActiveParagraph()->getAlignment()
+				->setMarginBottom(4)
+				->setMarginLeft(4)
+				->setMarginRight(4)
+				->setMarginTop(4);
+			$cell->createTextRun($label)
+				->getFont()->setBold(true);
+		}
+
+		$suffixes = $chart->getPrintSuffixes() ?? $chart->getDatalabelSuffixes();
+
+		// Datasets
+		foreach($datasets as $index => $dataset) {
+			$label = $dataset->label;
+			$data = $dataset->data;
+
+			$suffix = $suffixes[$index] ?? "";
+
+			$row = $shape->createRow();
+			$row->setHeight(20);
+			$cell = $row->nextCell();
+			$cell->getActiveParagraph()->getAlignment()
+				->setMarginBottom(4)
+				->setMarginLeft(4)
+				->setMarginRight(4)
+				->setMarginTop(4);
+			$cell->createTextRun($label)
+				->getFont()->setBold(true);
+			foreach($data as $value) {
+				$cell = $row->nextCell();
+				$cell->getActiveParagraph()->getAlignment()
+					->setHorizontal(Alignment::HORIZONTAL_RIGHT)
+					->setMarginBottom(4)
+					->setMarginLeft(4)
+					->setMarginRight(4)
+					->setMarginTop(4);
+				$cell->createTextRun($value . $suffix);
+			}
+
+			if($chart->printPercentages) {
+				$total = array_sum($data);
+
+				$percentages = [];
+				foreach($data as $value) {
+					$percentages[] = (floor(($value * 10000) / $total) / 100) . "%";
+				}
+
+				$row = $shape->createRow();
+				$row->setHeight(20);
+				$cell = $row->nextCell();
+				$cell->getActiveParagraph()->getAlignment()
+					->setMarginBottom(4)
+					->setMarginLeft(4)
+					->setMarginRight(4)
+					->setMarginTop(4);
+				$cell->createTextRun("Percentage")
+					->getFont()->setBold(true);
+				foreach($percentages as $string) {
+					$cell = $row->nextCell();
+					$cell->getActiveParagraph()->getAlignment()
+						->setHorizontal(Alignment::HORIZONTAL_RIGHT)
+						->setMarginBottom(4)
+						->setMarginLeft(4)
+						->setMarginRight(4)
+						->setMarginTop(4);
+					$cell->createTextRun($string);
+				}
+			}
+
+		}
+	}
+
+	$names[] = $name;
+}
+
+if($action == "export-pptx") {
+	header("Content-Type: application/vnd.openxmlformats-officedocument.presentationml.presentation");
+	$pptx_writer = IOFactory::createWriter($presentation, "PowerPoint2007");
+	$pptx_writer->save("php://output");
+}
+
+if($action == "export-odp") {
+	header("Content-Type: application/vnd.oasis.opendocument.presentation");
+	$odp_writer = IOFactory::createWriter($presentation, "ODPresentation");
+	$odp_writer->save("php://output");
+}
+
+foreach($names as $name) {
+	@unlink($name);
+}
+
+exit;
+
+?>

+ 1 - 0
controllers/project_add.php

@@ -39,6 +39,7 @@ if($submit) {
 		$project->max_age = http::value("max_age", "int");
 		$project->default_tester_fee = http::value("default_tester_fee", "float");
 		$project->time_of_day = http::value("time_of_day", "trim");
+		$project->tester_can_claim = http::value("tester_can_claim", "trim");
 
 		$date_start = http::getDateFromFields("date_start");
 		$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->default_tester_fee = http::value("default_tester_fee", "float");
 		$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_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->gender = http::value("gender", "trim");
 		$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(!isset(User::LEVELS[$user->level])) $form_exception->addError("User level is invalid.");

+ 64 - 4
engine/chart.php

@@ -7,6 +7,7 @@ class Chart {
 	private $type = "bar";
 	private $datasets = [];
 	private $labels = [];
+	private $printLabels = null;
 
 	private $xAxes = [];
 	private $yAxes = [];
@@ -14,9 +15,12 @@ class Chart {
 	private $datalabelSuffixes = [];
 	private $datalabelFormatterCallback = false;
 
+	private $printSuffixes = null;
+
 	public $beforeHtml = null;
 	public $afterHtml = null;
 	public $print = false;
+	public $printPercentages = false;
 
 	public function __construct() {
 		$this->id = bin2hex(random_bytes(8));
@@ -112,10 +116,30 @@ class Chart {
 
 	}
 
+	public function getDatasets() {
+		return $this->datasets;
+	}
+
+	public function getLabels() {
+		return $this->labels;
+	}
+
 	public function setLabels($labels) {
 		$this->labels = $labels;
 	}
 
+	public function getPrintLabels() {
+		return $this->printLabels;
+	}
+
+	public function setPrintLabels($labels) {
+		$this->printLabels = $labels;
+	}
+
+	public function getDatalabelSuffixes() {
+		return $this->datalabelSuffixes;
+	}
+
 	public function setDatalabelSuffixes(... $suffixes) {
 		$this->datalabelSuffixes = $suffixes;
 	}
@@ -124,6 +148,14 @@ class Chart {
 		$this->datalabelFormatterCallback = $callback;
 	}
 
+	public function getPrintSuffixes() {
+		return $this->printSuffixes;
+	}
+
+	public function setPrintSuffixes(... $suffixes) {
+		$this->printSuffixes = $suffixes;
+	}
+
 	public function getJSON() {
 
 		$object = (object) [
@@ -183,7 +215,10 @@ class Chart {
 				<tr>
 					<th></th>
 					<?php
-					foreach($this->labels as $label) {
+
+					$labels = $this->printLabels ?? $this->labels;
+
+					foreach($labels as $label) {
 						?>
 						<th><?=htmlspecialchars($label)?></th>
 						<?php
@@ -196,15 +231,20 @@ class Chart {
 			foreach($this->datasets as $index => $dataset) {
 
 				$suffix = "";
-				if($this->datalabelSuffixes) {
-					$suffix = $this->datalabelSuffixes[$index];
+
+				$suffixes = $this->printSuffixes ?? $this->datalabelSuffixes;
+
+				if($suffixes) {
+					$suffix = $suffixes[$index];
 				}
 
+				$data = $dataset->data;
+
 				?>
 				<tr>
 					<td><?=htmlspecialchars($dataset->label)?></td>
 					<?php
-					foreach($dataset->data as $value) {
+					foreach($data as $value) {
 						?>
 						<td class="text-right"><?=htmlspecialchars($value)?><?=htmlspecialchars($suffix)?></td>
 						<?php
@@ -212,6 +252,26 @@ class Chart {
 					?>
 				</tr>
 				<?php
+
+				if($this->printPercentages) {
+					$total = array_sum($data);
+					$percentages = [];
+					foreach($data as $value) {
+						$percentages[] = (floor(($value * 10000) / $total) / 100) . "%";
+					}
+					?>
+					<tr>
+						<td>Percentage</td>
+						<?php
+						foreach($percentages as $string) {
+							?>
+							<td class="text-right"><?=$string?></td>
+							<?php
+						}
+						?>
+					</tr>
+					<?php
+				}
 			}
 			?>
 			</tbody>

+ 2 - 1
engine/db.php

@@ -115,7 +115,8 @@ class db {
 					return "'$str'";
 				}, $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")) {
 				$string_array[] = "`$field` " . $value->getConstraintString();

+ 1 - 1
engine/project.php

@@ -4,7 +4,7 @@ class Project extends Model {
 
 	protected static $table = "project";
 	protected static $id_field = "id";
-	protected static $fillable_fields = ["customer_id", "template_id", "name", "test_count", "min_age", "max_age", "default_tester_fee", "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 = [
 	];

+ 31 - 0
engine/test.php

@@ -82,6 +82,37 @@ class Test extends Model {
 		$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() {
 
 		$tester = $this->getTester();

+ 1 - 1
engine/user.php

@@ -4,7 +4,7 @@ class User extends Model {
 
 	protected static $table = "user";
 	protected static $id_field = "id";
-	protected static $fillable_fields = ["email", "old_id", "referrer_id", "password", "activated", "level", "score", "title", "first_name", "last_name", "gender", "date_of_birth", "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
 

+ 1 - 1
package.json

@@ -9,7 +9,7 @@
   "author": "Alan Lam",
   "license": "ISC",
   "dependencies": {
-    "bootstrap": "^4.1.2",
+    "bootstrap": "^4.1.3",
     "chart.js": "^2.7.2",
     "clipboard": "^2.0.0",
     "holderjs": "^2.9.4",

File diff suppressed because it is too large
+ 1 - 1
public/css/bootstrap.min.css


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

@@ -42,6 +42,16 @@ $(function() {
 		}
 	});
 
+	$("#export-pptx-action").click(function() {
+		exportCharts("pptx");
+		return true;
+	});
+
+	$("#export-odp-action").click(function() {
+		exportCharts("odp");
+		return true;
+	});
+
 });
 
 function testsByStageFormatter(value, context) {
@@ -60,4 +70,41 @@ function testsByStageFormatter(value, context) {
 	label += percentage + "%";
 
 	return label;
+}
+
+function exportCharts(action) {
+
+	let formId = "";
+
+	if(action == "pptx") {
+		formId = "form-pptx";
+	}
+
+	if(action == "odp") {
+		formId = "form-odp";
+	}
+
+	let form = $("#" + formId);
+	let rendered = $(form).data("rendered");
+
+	console.log(formId, form);
+
+	if(rendered == "0") {
+
+		for(var i in Chart.instances) {
+			let chart = Chart.instances[i];
+			let base64 = chart.toBase64Image();
+
+			$(form).append("<input type=\"hidden\" name=\"charts_b64[]\" value=\"" + base64 + "\" />");
+
+		}
+
+		$(form).data("rendered", "1");
+
+	}
+
+	console.log("done");
+
+	$(form).find("input[type=submit]").click();
+
 }

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

File diff suppressed because it is too large
+ 1 - 1
public/js/bootstrap.min.js


File diff suppressed because it is too large
+ 0 - 0
public/js/bootstrap.min.js.map


File diff suppressed because it is too large
+ 1 - 1
public/js/fontawesome-all.min.js


+ 2 - 0
routes.php

@@ -71,6 +71,7 @@ $routes = [
 	// Tests
 	"/^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\/available$/" => ["controller" => "tests_available", "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\/(selfie)$/" => ["controller" => "test_file", "params" => ["id", "name"], "require_user_level" => User::LEVEL_TESTER],
@@ -121,6 +122,7 @@ $routes = [
 
 	// Performance
 	"/^account\/performance$/" => ["controller" => "performance", "require_user_level" => User::LEVEL_VENUE],
+	"/^account\/performance\/(export-odp|export-pptx)$/" => ["controller" => "performance", "params" => ["action"], "require_user_level" => User::LEVEL_VENUE],
 
 
 ];

+ 28 - 0
scss/_print.scss

@@ -0,0 +1,28 @@
+%print-styles {
+	body {
+		padding-top: 0;
+	}
+
+	.container {
+		width: auto;
+	}
+
+	canvas[data-chart] {
+		width: 1110px !important;
+		height: 832px !important;
+		padding-right: 2cm;
+		padding-bottom: 1.5cm;
+	}
+}
+
+@media print {
+	@extend %print-styles;
+}
+
+.print {
+	@extend %print-styles;
+
+	.d-print-none {
+		display: none;
+	}
+}

+ 3 - 1
scss/bootstrap.scss

@@ -12,4 +12,6 @@ $enable-gradients: true;
 
 @import "../node_modules/bootstrap/scss/bootstrap.scss";
 
-@import "main.scss";
+@import "main.scss";
+
+@import "print.scss";

+ 1 - 1
views/breadcrumbs.php

@@ -5,7 +5,7 @@ $breadcrumbs = Core::$breadcrumbs;
 if(count($breadcrumbs) > 1) {
 	$breadcrumb_count = count($breadcrumbs);
 	?>
-	<nav class="breadcrumb-nav" aria-label="breadcrumb" role="navigation">
+	<nav class="breadcrumb-nav d-print-none" aria-label="breadcrumb" role="navigation">
 		<ol class="breadcrumb">
 			<?php
 

+ 1 - 1
views/footer.php

@@ -2,7 +2,7 @@
 		if(Core::$show_footer_content) {
 		?>
 
-		<footer class="my-3">
+		<footer class="my-3 d-print-none">
 			<div class="container">
 
 				<hr />

+ 10 - 4
views/header.php

@@ -8,6 +8,12 @@ if(!PRODUCTION) {
 	$icon = "/img/dev_icon.png";
 }
 
+$body_class = "";
+
+$print = http::value("print");
+if($print) $body_class = "print";
+
+
 ?>
 <!DOCTYPE html>
 <html>
@@ -28,7 +34,7 @@ if(!PRODUCTION) {
 		<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" rel="stylesheet" />
 		<link rel="stylesheet" href="/css/bootstrap.min.css?<?=filemtime("public/css/bootstrap.min.css")?>" />
 		<link rel="icon" href="<?=$icon?>?<?=filemtime("public" . $icon)?>" />
-		<script type="text/javascript" src="/js/fontawesome-all.min.js"></script>
+		<script type="text/javascript" src="/js/fontawesome-all.min.js?<?=filemtime("public/js/fontawesome-all.min.js")?>"></script>
 		<script type="text/javascript" src="https://www.google.com/recaptcha/api.js"></script>
 		<?php
 		if(GOOGLE_ANALYTICS_ID) {
@@ -46,9 +52,9 @@ if(!PRODUCTION) {
 		}
 		?>
 	</head>
-	<body>
+	<body class="<?=htmlspecialchars($body_class)?>">
 
-		<div class="fixed-top" style="overflow-y: auto; max-height: 100%;">
+		<div class="fixed-top d-print-none" style="overflow-y: auto; max-height: 100%;">
 			<nav class="navbar navbar-expand-lg navbar-light bg-light">
 				<div class="navbar-brand p-0">
 					<a href="/">
@@ -115,7 +121,7 @@ if(!PRODUCTION) {
 		if(!PRODUCTION) {
 			$style = (count(Core::$breadcrumbs) > 1) ? "margin-top: -1rem;" : "";
 			?>
-			<div class="p-2 mb-3 bg-danger text-white text-center" style="<?=$style?>">
+			<div class="p-2 mb-3 bg-danger text-white text-center d-print-none" style="<?=$style?>">
 				<strong>PLEASE NOTE:</strong> This is a development version of the site.
 			</div>
 			<?php

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

+ 125 - 87
views/performance.php

@@ -17,15 +17,29 @@ $date_range_custom_style = ($date_range == "custom") ? "" : "display: none";
 
 ?>
 <div class="container">
-	<div class="row">
-		<div class="col-auto">
+	<div class="row d-print-none">
+		<div class="col">
 			<h2><?=htmlspecialchars($customer->name)?> Performance</h2>
 		</div>
-		<div class="col">
+		<div class="col-auto">
+			<?php
+			if($charts) {
+				?>
+				<div class="dropdown">
+					<button type="button" class="btn btn-secondary dropdown-toggle" id="actions-button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+						Actions
+					</button>
+					<div class="dropdown-menu" aria-labelledby="actions-button">
+						<a class="dropdown-item" href="#" id="export-pptx-action">Export PPTX</a>
+					</div>
+				</div>
+				<?php
+			}
+			?>
 		</div>
 	</div>
 
-	<form class="mb-4" method="post">
+	<form class="mb-4 d-print-none" method="post">
 
 		<input type="hidden" name="customer_id" value="<?=htmlspecialchars($customer->id)?>" />
 
@@ -161,7 +175,7 @@ $date_range_custom_style = ($date_range == "custom") ? "" : "display: none";
 	<?php
 	if($locations_missing_region) {
 		?>
-		<div class="alert alert-warning">
+		<div class="alert alert-warning d-print-none">
 			There are some locations that are missing "region" information:
 			<ul class="mb-0">
 			<?php
@@ -190,7 +204,7 @@ $date_range_custom_style = ($date_range == "custom") ? "" : "display: none";
 	<?php
 	if($locations_missing_area_manager) {
 		?>
-		<div class="alert alert-warning">
+		<div class="alert alert-warning d-print-none">
 			There are some locations that are missing "area manager" information:
 			<ul class="mb-0">
 			<?php
@@ -243,7 +257,7 @@ $date_range_custom_style = ($date_range == "custom") ? "" : "display: none";
 		</div>
 
 		<div class="row mb-4">
-			<div class="col-md-4" style="position: relative;">
+			<div class="col-md-4 d-print-none" style="position: relative;">
 				<h3>Chart List</h3>
 				<div class="list-group" style="position: sticky; top: 7rem;">
 				<?php
@@ -289,102 +303,126 @@ $date_range_custom_style = ($date_range == "custom") ? "" : "display: none";
 		</div>
 
 		<?php
+		foreach(["pptx", "odp"] as $format) {
+			?>
+			<form id="form-<?=$format?>" method="post" action="/account/performance/export-<?=$format?>" data-rendered="0">
+				<input type="hidden" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>" />
+				<input type="hidden" name="customer_id" value="<?=intval($customer->id)?>" />
+				<input type="hidden" name="date_range" value="<?=htmlspecialchars($date_range)?>" />
+				<input type="hidden" name="from_quarter" value="<?=htmlspecialchars($from_quarter)?>" />
+				<input type="hidden" name="to_quarter" value="<?=htmlspecialchars($to_quarter)?>" />
+				<input type="hidden" name="date_resolution" value="<?=htmlspecialchars($date_resolution)?>" />
+				<?php
+				foreach($project_ids as $project_id) {
+					?>
+					<input type="hidden" name="project_ids[]" value="<?=intval($project_id)?>" />
+					<?php
+				}
+				?>
+				<input type="submit" value="Submit" class="d-none" />
+			</form>
+			<?php
+		}
 
 		if(PRODUCTION == false) {
 			?>
-			<h2>Debug Information</h2>
+			<div class="d-print-none">
+				<h2>Debug Information</h2>
 
-			<h3>Region Data</h3>
+				<h3>Region Data</h3>
 
-			<?php
+				<?php
 
-			foreach($region_data as $region => $rows) {
+				foreach($region_data as $region => $rows) {
 
-				?>
-				<h4>Region: <?=htmlspecialchars($region)?></h4>
-
-				<table class="table">
-					<col style="width: 20%" />
-					<col style="width: 20%" />
-					<col style="width: 20%" />
-					<col style="width: 20%" />
-					<col style="width: 20%" />
-					<thead>
-						<tr>
-							<th>Key</th>
-							<th>Tests</th>
-							<th>Passes</th>
-							<th>Fails</th>
-							<th>Rate</th>
-						</tr>
-					</thead>
-					<tbody>
-					<?php
-					foreach($rows as $key => $data) {
-						$rate = ($data->testCount == 0) ? "0.00" : number_format(($data->passCount * 100) / $data->testCount, 2);
-						?>
-						<tr>
-							<td><?=htmlspecialchars($key)?></td>
-							<td><?=number_format($data->testCount)?></td>
-							<td><?=number_format($data->passCount)?></td>
-							<td><?=number_format($data->failCount)?></td>
-							<td><?=$rate?>%</td>
-						</tr>
-						<?php
-					}
 					?>
-					</tbody>
-				</table>
+					<h4>Region: <?=htmlspecialchars($region)?></h4>
+
+					<table class="table">
+						<col style="width: 20%" />
+						<col style="width: 20%" />
+						<col style="width: 20%" />
+						<col style="width: 20%" />
+						<col style="width: 20%" />
+						<thead>
+							<tr>
+								<th>Key</th>
+								<th>Tests</th>
+								<th>Passes</th>
+								<th>Fails</th>
+								<th>Rate</th>
+							</tr>
+						</thead>
+						<tbody>
+						<?php
+						foreach($rows as $key => $data) {
+							$rate = ($data->testCount == 0) ? "0.00" : number_format(($data->passCount * 100) / $data->testCount, 2);
+							?>
+							<tr>
+								<td><?=htmlspecialchars($key)?></td>
+								<td><?=number_format($data->testCount)?></td>
+								<td><?=number_format($data->passCount)?></td>
+								<td><?=number_format($data->failCount)?></td>
+								<td><?=$rate?>%</td>
+							</tr>
+							<?php
+						}
+						?>
+						</tbody>
+					</table>
 
-				<?php
+					<?php
 
-			}
+				}
 
-			?>
-			<h3>Area Manager Data</h3>
-			<?php
+				?>
+				<h3>Area Manager Data</h3>
+				<?php
 
-			foreach($area_manager_data as $area_manager => $rows) {
+				foreach($area_manager_data as $area_manager => $rows) {
 
-				?>
-				<h4>Area Manager: <?=htmlspecialchars($area_manager)?></h4>
-
-				<table class="table">
-					<col style="width: 20%" />
-					<col style="width: 20%" />
-					<col style="width: 20%" />
-					<col style="width: 20%" />
-					<col style="width: 20%" />
-					<thead>
-						<tr>
-							<th>Key</th>
-							<th>Tests</th>
-							<th>Passes</th>
-							<th>Fails</th>
-							<th>Rate</th>
-						</tr>
-					</thead>
-					<tbody>
-					<?php
-					foreach($rows as $key => $data) {
-						$rate = ($data->testCount == 0) ? "0.00" : number_format(($data->passCount * 100) / $data->testCount, 2);
-						?>
-						<tr>
-							<td><?=htmlspecialchars($key)?></td>
-							<td><?=number_format($data->testCount)?></td>
-							<td><?=number_format($data->passCount)?></td>
-							<td><?=number_format($data->failCount)?></td>
-							<td><?=$rate?>%</td>
-						</tr>
-						<?php
-					}
 					?>
-					</tbody>
-				</table>
+					<h4>Area Manager: <?=htmlspecialchars($area_manager)?></h4>
+
+					<table class="table">
+						<col style="width: 20%" />
+						<col style="width: 20%" />
+						<col style="width: 20%" />
+						<col style="width: 20%" />
+						<col style="width: 20%" />
+						<thead>
+							<tr>
+								<th>Key</th>
+								<th>Tests</th>
+								<th>Passes</th>
+								<th>Fails</th>
+								<th>Rate</th>
+							</tr>
+						</thead>
+						<tbody>
+						<?php
+						foreach($rows as $key => $data) {
+							$rate = ($data->testCount == 0) ? "0.00" : number_format(($data->passCount * 100) / $data->testCount, 2);
+							?>
+							<tr>
+								<td><?=htmlspecialchars($key)?></td>
+								<td><?=number_format($data->testCount)?></td>
+								<td><?=number_format($data->passCount)?></td>
+								<td><?=number_format($data->failCount)?></td>
+								<td><?=$rate?>%</td>
+							</tr>
+							<?php
+						}
+						?>
+						</tbody>
+					</table>
 
-				<?php
+					<?php
 
-			}
+				}
+			?>
+			</div>
+			<?php
 		}
 
 	}

+ 16 - 1
views/project_form.php

@@ -32,7 +32,6 @@ $time_of_day_options = [
 		<div class="row">
 			<div class="col-lg">
 
-
 				<div class="row mb-1">
 					<label class="col-sm-4 col-form-label" for="name">Name</label>
 					<div class="col-sm">
@@ -87,6 +86,22 @@ $time_of_day_options = [
 						</select>
 					</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 class="col-lg">
 

+ 17 - 10
views/test_list_assigned.php

@@ -2,25 +2,32 @@
 
 	<div class="row">
 		<div class="col">
-			<h2>Your Tests</h2>
+			<h2>Tests</h2>
 		</div>
+		<div class="col-auto">
 		<?php
+
+		if(Core::$user->can_claim) {
+			?>
+			<a class="btn btn-primary" href="/account/tests/available">Find Tests</a>
+			<?php
+		}
+
 		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>
 			<?php
 		}
 		?>
+		</div>
 	</div>
 
 
@@ -29,7 +36,7 @@
 	if(empty($tests)) {
 		?>
 		<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>
 		<?php
 	}

+ 1 - 1
views/tests.php

@@ -7,7 +7,7 @@
 	if(empty($tests)) {
 		?>
 		<div class="alert alert-info">
-			There are no tests for you at this time.
+			You have no assigned tests at this time.
 		</div>
 		<?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);
 $activated_checked = ($user->activated) ? "checked" : "";
+$can_claim_checked = ($user->can_claim) ? "checked" : "";
 
 ?>
 <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>
 					</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 class="col-lg-6 mb-3">
 

Some files were not shown because too many files changed in this diff