Răsfoiți Sursa

Allow customers to view and edit locations

Alan Lam 7 ani în urmă
părinte
comite
95a56be7a1

+ 1 - 1
controllers/account.php

@@ -25,7 +25,6 @@ if($user->level >= User::LEVEL_ADMIN) {
 	$tests_pending_verification = count($tests);
 	$tests_pending_verification = count($tests);
 
 
 	$icons[] = new AccountIcon(__("Projects"), "/account/projects", "list");
 	$icons[] = new AccountIcon(__("Projects"), "/account/projects", "list");
-	$icons[] = new AccountIcon(__("Locations"), "/account/locations", "map-marker");
 	$icons[] = new AccountIcon(__("Templates"), "/account/templates", "file-alt");
 	$icons[] = new AccountIcon(__("Templates"), "/account/templates", "file-alt");
 	$icons[] = new AccountIcon(__("Venue Types"), "/account/venue-types", "list-alt");
 	$icons[] = new AccountIcon(__("Venue Types"), "/account/venue-types", "list-alt");
 
 
@@ -39,6 +38,7 @@ if($user->level >= User::LEVEL_ADMIN) {
 }
 }
 
 
 if($user->level >= User::LEVEL_CUSTOMER) {
 if($user->level >= User::LEVEL_CUSTOMER) {
+	$icons[] = new AccountIcon(__("Locations"), "/account/locations", "map-marker");
 	$icons[] = new AccountIcon(__("Reports"), "/account/reports", "chart-pie");
 	$icons[] = new AccountIcon(__("Reports"), "/account/reports", "chart-pie");
 	$icons[] = new AccountIcon(__("Test Results"), "/account/test-results", "clipboard-list-check");
 	$icons[] = new AccountIcon(__("Test Results"), "/account/test-results", "clipboard-list-check");
 }
 }

+ 3 - 1
controllers/customer_ajax.php

@@ -5,6 +5,8 @@ JSON::header();
 $customer = Customer::get($id);
 $customer = Customer::get($id);
 if(!$customer) JSON::fail("Customer not found.");
 if(!$customer) JSON::fail("Customer not found.");
 
 
+if(!Core::$user->hasPermission($customer)) throw new Exception(__("No permission."));
+
 switch($action) {
 switch($action) {
 	case "get-locations":
 	case "get-locations":
 
 
@@ -43,4 +45,4 @@ switch($action) {
 		]);
 		]);
 
 
 		break;
 		break;
-}
+}

+ 41 - 41
controllers/location_edit.php

@@ -51,52 +51,54 @@ if($submit) {
 		else if(empty($location->longitude)) $form_exception->addError("Map location is required.");
 		else if(empty($location->longitude)) $form_exception->addError("Map location is required.");
 
 
 		// Photo
 		// Photo
-		$photo = (object) $_FILES["photo"];
-		if($photo->error != UPLOAD_ERR_NO_FILE) {
-			try {
-				if($photo->error != UPLOAD_ERR_OK) throw new Exception(HTTP::getUploadErrorString($photo->error));
-				if(!Image::isJPEG($photo->tmp_name)) throw new Exception("Photo is not a JPEG image.");
 
 
-				// Photo OK
-				$file = new LocationFile;
-				$file->location_id = $id;
-				$file->type = LocationFile::TYPE_PHOTO;
-				$file->dts_uploaded = Util::getDateTime();
-				$file->commit();
-
-				$id = $file->id;
-
-				$directory = $location->getDirectory();
-				$file_path = $directory . "/$id.jpg";
-
-				$output_image = Image::normalise($photo->tmp_name);
-				$success = imagejpeg($output_image, $file_path);
-				imagedestroy($output_image);
-				if(!$success) throw new Exception("Failed to save photo.");
-			}
-			catch(Exception $e) {
-				$form_exception->addError($e->getMessage());
+		if(Core::$user->isAdmin()) {
+			$photo = (object) $_FILES["photo"];
+			if($photo->error != UPLOAD_ERR_NO_FILE) {
+				try {
+					if($photo->error != UPLOAD_ERR_OK) throw new Exception(HTTP::getUploadErrorString($photo->error));
+					if(!Image::isJPEG($photo->tmp_name)) throw new Exception("Photo is not a JPEG image.");
+
+					// Photo OK
+					$file = new LocationFile;
+					$file->location_id = $id;
+					$file->type = LocationFile::TYPE_PHOTO;
+					$file->dts_uploaded = Util::getDateTime();
+					$file->commit();
+
+					$id = $file->id;
+
+					$directory = $location->getDirectory();
+					$file_path = $directory . "/$id.jpg";
+
+					$output_image = Image::normalise($photo->tmp_name);
+					$success = imagejpeg($output_image, $file_path);
+					imagedestroy($output_image);
+					if(!$success) throw new Exception("Failed to save photo.");
+				}
+				catch(Exception $e) {
+					$form_exception->addError($e->getMessage());
+				}
 			}
 			}
-		}
 
 
-		// Delete Photos
-		$delete_file_ids = http::value("delete_file_ids", "int");
-		$files = LocationFile::query([
-			"id" => $delete_file_ids,
-			"location_id" => $id,
-		]);
-		if($files) {
-			$directory = $location->getDirectory();
-			foreach($files as $file) {
-				$pattern = $directory . "/$file->id.*";
-				foreach(glob($pattern) as $path) {
-					unlink($path);
+			// Delete Photos
+			$delete_file_ids = http::value("delete_file_ids", "int");
+			$files = LocationFile::query([
+				"id" => $delete_file_ids,
+				"location_id" => $id,
+			]);
+			if($files) {
+				$directory = $location->getDirectory();
+				foreach($files as $file) {
+					$pattern = $directory . "/$file->id.*";
+					foreach(glob($pattern) as $path) {
+						unlink($path);
+					}
+					$file->delete();
 				}
 				}
-				$file->delete();
 			}
 			}
 		}
 		}
 
 
-
 		if($form_exception->hasErrors()) throw $form_exception;
 		if($form_exception->hasErrors()) throw $form_exception;
 		$success = $location->commit();
 		$success = $location->commit();
 		if(!$success) throw new Exception("Failed to edit location at this time. Please try again later.");
 		if(!$success) throw new Exception("Failed to edit location at this time. Please try again later.");
@@ -132,5 +134,3 @@ Core::addBreadcrumb("/account/locations/$id/edit", $page_title);
 View::includeOnce("header", compact("page_title"));
 View::includeOnce("header", compact("page_title"));
 View::include("location_form", compact("location", "photos"));
 View::include("location_form", compact("location", "photos"));
 View::includeOnce("footer");
 View::includeOnce("footer");
-
-?>

+ 1 - 23
controllers/location_view.php

@@ -13,28 +13,6 @@ Core::addBreadcrumb("/account/locations", "Locations");
 Core::addBreadcrumb("/account/locations?customer_id=$customer->id", "$customer->name Locations");
 Core::addBreadcrumb("/account/locations?customer_id=$customer->id", "$customer->name Locations");
 Core::addBreadcrumb("/account/locations/$location->id", $page_title);
 Core::addBreadcrumb("/account/locations/$location->id", $page_title);
 
 
-$status_constraint = new Constraint("BETWEEN");
-
-if(Core::$user->level >= User::LEVEL_ADMIN) {
-	$status_constraint->setValues(Test::STATUS_UNASSIGNED, Test::STATUS_COMPLETED);
-}
-else {
-	$status_constraint->setValues(Test::STATUS_COMPLETED, Test::STATUS_COMPLETED);
-}
-
-$tests = Test::query([
-	"location_id" => $location->id,
-	"status" => $status_constraint,
-], [
-	"sort" => "status",
-	"order" => "asc",
-]);
-
-$projects = Project::load(array_column($tests, "project_id"));
-
-
 View::includeOnce("header", compact("page_title"));
 View::includeOnce("header", compact("page_title"));
-View::include("location", compact("location", "tests"));
+View::include("location", compact("location"));
 View::includeOnce("footer");
 View::includeOnce("footer");
-
-?>

+ 33 - 2
engine/location.php

@@ -1,5 +1,9 @@
 <?php
 <?php
 
 
+/**
+ * @method Location get(int $id)
+ */
+
 class Location extends Model {
 class Location extends Model {
 
 
 	protected static $table = "location";
 	protected static $table = "location";
@@ -57,6 +61,9 @@ class Location extends Model {
 		];
 		];
 	}
 	}
 
 
+	/**
+	 * @return LocationFile[]
+	 */
 	public function getPhotos() {
 	public function getPhotos() {
 		return LocationFile::query([
 		return LocationFile::query([
 			"location_id" => $this->id,
 			"location_id" => $this->id,
@@ -64,6 +71,30 @@ class Location extends Model {
 		]);
 		]);
 	}
 	}
 
 
-}
+	/**
+	 * @return Test[]
+	 */
+	public function getTests() {
+		return Test::query([
+			"location_id" => $this->id,
+			"status" => (new Constraint("MORE_THAN_OR_EQUAL"))->setValues(Test::STATUS_UNASSIGNED),
+		], [
+			"sort" => "dts_start",
+			"order" => "desc",
+		]);
+	}
 
 
-?>
+	/**
+	 * @return Test[]
+	 */
+	public function getCompletedTests() {
+		return Test::query([
+			"location_id" => $this->id,
+			"status" => Test::STATUS_COMPLETED,
+		], [
+			"sort" => "dts_start",
+			"order" => "desc",
+		]);
+	}
+
+}

+ 5 - 6
engine/user.php

@@ -314,25 +314,24 @@ class User extends Model {
 
 
 	public function hasPermission($object) {
 	public function hasPermission($object) {
 
 
-		if($this->level == User::LEVEL_SUPERADMIN) return true;
-		if($this->level == User::LEVEL_ADMIN) return true;
+		if($this->isAdmin()) return true;
 
 
 		$customers = $this->getCustomers();
 		$customers = $this->getCustomers();
 		$customer_ids = array_column($customers, "id");
 		$customer_ids = array_column($customers, "id");
 
 
-		if(is_a($object, "Customer")) {
+		if($object instanceof Customer) {
 			return in_array($object->id, $customer_ids);
 			return in_array($object->id, $customer_ids);
 		}
 		}
 
 
-		if(is_a($object, "Location")) {
+		if($object instanceof Location) {
 			return in_array($object->customer_id, $customer_ids);
 			return in_array($object->customer_id, $customer_ids);
 		}
 		}
 
 
-		if(is_a($object, "Project")) {
+		if($object instanceof Project) {
 			return in_array($object->customer_id, $customer_ids);
 			return in_array($object->customer_id, $customer_ids);
 		}
 		}
 
 
-		if(is_a($object, "Template")) {
+		if($object instanceof Template) {
 			return in_array($object->customer_id, $customer_ids);
 			return in_array($object->customer_id, $customer_ids);
 		}
 		}
 
 

+ 1 - 1
routes.php

@@ -127,7 +127,7 @@ $routes = [
 	"/^account\/customers\/$id_pattern$/" => ["controller" => "customer_view", "params" => ["id"], "require_user_level" => User::LEVEL_ADMIN],
 	"/^account\/customers\/$id_pattern$/" => ["controller" => "customer_view", "params" => ["id"], "require_user_level" => User::LEVEL_ADMIN],
 	"/^account\/customers\/$id_pattern\/edit$/" => ["controller" => "customer_edit", "params" => ["id"], "require_user_level" => User::LEVEL_ADMIN],
 	"/^account\/customers\/$id_pattern\/edit$/" => ["controller" => "customer_edit", "params" => ["id"], "require_user_level" => User::LEVEL_ADMIN],
 
 
-	"/^api\/customers\/$id_pattern\/(get-locations)$/" => ["controller" => "customer_ajax", "params" => ["id", "action"], "require_user_level" => User::LEVEL_ADMIN],
+	"/^api\/customers\/$id_pattern\/(get-locations)$/" => ["controller" => "customer_ajax", "params" => ["id", "action"], "require_user_level" => User::LEVEL_CUSTOMER],
 
 
 	// Practice
 	// Practice
 	"/^account\/practice$/" => ["controller" => "practice_template_select", "require_user_level" => User::LEVEL_TESTER],
 	"/^account\/practice$/" => ["controller" => "practice_template_select", "require_user_level" => User::LEVEL_TESTER],

+ 12 - 93
views/location.php

@@ -1,9 +1,9 @@
 <?php
 <?php
-$tabs = [
-	["details", "Details"],
-	["photos", "Photos"],
-	["tests", "Tests"],
-];
+
+$tabs = [];
+$tabs[] = ["details", __("Details")];
+if(Core::$user->isAdmin()) $tabs[] = ["photos", __("Photos")];
+$tabs[] = ["tests", __("Tests")];
 
 
 $details = [
 $details = [
 	"ID" => $location->id,
 	"ID" => $location->id,
@@ -18,12 +18,10 @@ if($location->region) $details["Region"] = $location->region;
 if($location->internal_id) $details["Internal ID"] = $location->internal_id;
 if($location->internal_id) $details["Internal ID"] = $location->internal_id;
 if($location->area_manager) $details["Area Manager"] = $location->area_manager;
 if($location->area_manager) $details["Area Manager"] = $location->area_manager;
 
 
-$photos = $location->getPhotos();
 $venue_types = $location->getVenueTypes();
 $venue_types = $location->getVenueTypes();
 $type_names = array_column($venue_types, "name");
 $type_names = array_column($venue_types, "name");
 $type_names_csv = implode(", ", $type_names);
 $type_names_csv = implode(", ", $type_names);
 
 
-
 if($venue_types) $details["Types"] = $type_names_csv;
 if($venue_types) $details["Types"] = $type_names_csv;
 
 
 ?>
 ?>
@@ -86,94 +84,15 @@ if($venue_types) $details["Types"] = $type_names_csv;
 				</div>
 				</div>
 			</div>
 			</div>
 		</div>
 		</div>
-		<div class="tab-pane fade" id="photos" role="tabpanel" aria-labelledby="photos-tab">
+
 		<?php
 		<?php
-		if(empty($photos)) {
-			?>
-			<div class="alert alert-info">
-				<i class="fal fa-fw fa-info-circle"></i> No photos are available for this location.
-			</div>
-			<?php
-		}
-		else {
-			?>
-			<div class="row">
-			<?php
-			foreach($photos as $photo) {
-				$uri = "/account/locations/$location->id/photos/$photo->id";
-				?>
-				<div class="col-md-4">
-					<a href="<?=$uri?>">
-						<img class="border img-fluid img-contain" src="/img/blank_4_3.png" style="background-image: url(<?=$uri?>)" />
-					</a>
-				</div>
-				<?php
-			}
-			?>
-			</div>
-			<?php
+		if(Core::$user->isAdmin()) {
+			View::include("location_photos_tab", compact("location"));
 		}
 		}
+
+		View::include("location_tests_tab", compact("location"));
 		?>
 		?>
-		</div>
-		<div class="tab-pane fade" id="tests" role="tabpanel" aria-labelledby="tests-tab">
-			<?php
-			if(empty($tests)) {
-				?>
-				<div class="alert alert-info">
-					This location has no tests.
-				</div>
-				<?php
-			}
-			else {
-				?>
-				<table class="table table-hover">
-					<thead>
-						<tr>
-							<th>ID</th>
-							<th>Project</th>
-							<th>Status</th>
-							<th></th>
-						</tr>
-					</thead>
-					<tbody>
-					<?php
-					foreach($tests as $test) {
-						$project = $test->getProject();
-						?>
-						<tr>
-							<td class="text-right align-middle">
-								<?=$test->id?>
-							</td>
-							<td class="align-middle">
-								<a href="/account/projects/<?=$project->id?>"><?=htmlspecialchars($project->name)?></a>
-							</td>
-							<td class="align-middle">
-								<span class="badge badge-lg badge-<?=$test->getStatusClass()?>"><?=htmlspecialchars($test->getStatusText())?></span>
-							</td>
-							<td class="text-right">
-							<?php
-							if($test->status >= Test::STATUS_PENDING_VERIFICATION) {
-								?>
-								<a class="btn btn-outline-primary" href="/account/tests/<?=$test->id?>">View Results</a>
-								<?php
-							}
-							else {
-								?>
-								<a class="btn btn-outline-primary" href="/account/projects/<?=$test->project_id?>">View Project</a>
-								<?php
-							}
-							?>
-							</td>
-						</tr>
-						<?php
-					}
-					?>
-					</tbody>
-				</table>
-				<?php
-			}
-			?>
-		</div>
+
 	</div>
 	</div>
 
 
-</div>
+</div>

+ 55 - 46
views/location_form.php

@@ -1,9 +1,12 @@
 <?php
 <?php
 $tabs = [
 $tabs = [
 	["details", "Details"],
 	["details", "Details"],
-	["photos", "Photos"],
 ];
 ];
 
 
+if(Core::$user->isAdmin()) {
+	$tabs[] = ["photos", "Photos"];
+}
+
 $venue_types = VenueType::getAll();
 $venue_types = VenueType::getAll();
 $venue_type_count = count($venue_types);
 $venue_type_count = count($venue_types);
 $venue_type_columns = array_chunk($venue_types, ceil($venue_type_count / 2));
 $venue_type_columns = array_chunk($venue_types, ceil($venue_type_count / 2));
@@ -212,72 +215,78 @@ if($location->id) {
 				</div>
 				</div>
 			</div>
 			</div>
 
 
-			<div class="tab-pane fade" id="photos" role="tabpanel" aria-labelledby="photos-tab">
-				<div class="row">
-					<div class="col-lg">
-						<div class="row mb-1">
-							<label class="col-sm-4 col-form-label" for="shop-left">Shop Name (Left)</label>
-							<div class="col-sm">
-								<input class="form-control" type="text" name="shop_left" id="shop-left" placeholder="Enter shop name (left)" value="<?=htmlspecialchars($location->shop_left)?>" />
+			<?php
+			if(Core::$user->isAdmin()) {
+				?>
+
+				<div class="tab-pane fade" id="photos" role="tabpanel" aria-labelledby="photos-tab">
+					<div class="row">
+						<div class="col-lg">
+							<div class="row mb-1">
+								<label class="col-sm-4 col-form-label" for="shop-left">Shop Name (Left)</label>
+								<div class="col-sm">
+									<input class="form-control" type="text" name="shop_left" id="shop-left" placeholder="Enter shop name (left)" value="<?=htmlspecialchars($location->shop_left)?>" />
+								</div>
 							</div>
 							</div>
-						</div>
-						<div class="row mb-1">
-							<label class="col-sm-4 col-form-label" for="shop-right">Shop Name (Right)</label>
-							<div class="col-sm">
-								<input class="form-control" type="text" name="shop_right" id="shop-right" placeholder="Enter shop name (right)" value="<?=htmlspecialchars($location->shop_right)?>" />
+							<div class="row mb-1">
+								<label class="col-sm-4 col-form-label" for="shop-right">Shop Name (Right)</label>
+								<div class="col-sm">
+									<input class="form-control" type="text" name="shop_right" id="shop-right" placeholder="Enter shop name (right)" value="<?=htmlspecialchars($location->shop_right)?>" />
+								</div>
 							</div>
 							</div>
-						</div>
 
 
-					</div>
-					<div class="col-lg">
-					<?php
-					if($location->id) {
-						?>
-						<div class="row mb-3">
-							<label class="col-sm-4 col-form-label" for="photo">JPEG File</label>
-							<div class="col-sm">
-								<input class="form-control-file" type="file" name="photo" id="photo" />
-							</div>
 						</div>
 						</div>
+						<div class="col-lg">
 						<?php
 						<?php
-						if(!empty($photos)) {
+						if($location->id) {
 							?>
 							?>
-							<h3>Manage Photos</h3>
-
-							<div class="row">
+							<div class="row mb-3">
+								<label class="col-sm-4 col-form-label" for="photo">JPEG File</label>
+								<div class="col-sm">
+									<input class="form-control-file" type="file" name="photo" id="photo" />
+								</div>
+							</div>
 							<?php
 							<?php
-							foreach($photos as $photo) {
+							if(!empty($photos)) {
 								?>
 								?>
-								<div class="col-md-6">
-									<div class="card">
-										<img class="card-img-top img-cover" src="/img/blank_4_3.png" alt="Photo" style="background-image: url(/account/locations/6/photos/<?=$photo->id?>)" />
-										<div class="card-body">
-											<div class="form-check">
-												<input class="form-check-input" type="checkbox" name="delete_file_ids[]" id="photo-<?=$photo->id?>" value="<?=$photo->id?>" />
-												<label class="form-check-label" for="photo-<?=$photo->id?>">Delete</label>
+								<h3>Manage Photos</h3>
+
+								<div class="row">
+								<?php
+								foreach($photos as $photo) {
+									?>
+									<div class="col-md-6">
+										<div class="card">
+											<img class="card-img-top img-cover" src="/img/blank_4_3.png" alt="Photo" style="background-image: url(/account/locations/6/photos/<?=$photo->id?>)" />
+											<div class="card-body">
+												<div class="form-check">
+													<input class="form-check-input" type="checkbox" name="delete_file_ids[]" id="photo-<?=$photo->id?>" value="<?=$photo->id?>" />
+													<label class="form-check-label" for="photo-<?=$photo->id?>">Delete</label>
+												</div>
 											</div>
 											</div>
 										</div>
 										</div>
 									</div>
 									</div>
+									<?php
+								}
+								?>
 								</div>
 								</div>
 								<?php
 								<?php
 							}
 							}
+						}
+						else {
 							?>
 							?>
+							<div class="alert alert-info">
+								<i class="fal fa-fw fa-info-circle"></i> Adding photos will become available when location is added.
 							</div>
 							</div>
 							<?php
 							<?php
 						}
 						}
-					}
-					else {
 						?>
 						?>
-						<div class="alert alert-info">
-							<i class="fal fa-fw fa-info-circle"></i> Adding photos will become available when location is added.
 						</div>
 						</div>
-						<?php
-					}
-					?>
 					</div>
 					</div>
 				</div>
 				</div>
-			</div>
-
+				<?php
+			}
+			?>
 		</div>
 		</div>
 
 
 		<div class="row">
 		<div class="row">
@@ -293,4 +302,4 @@ if($location->id) {
 		</div>
 		</div>
 
 
 	</form>
 	</form>
-</div>
+</div>

+ 38 - 0
views/location_photos_tab.php

@@ -0,0 +1,38 @@
+
+<?php
+/**
+ * @var Location $location
+ */
+
+$photos = $location->getPhotos();
+
+?>
+<div class="tab-pane fade" id="photos" role="tabpanel" aria-labelledby="photos-tab">
+<?php
+if(empty($photos)) {
+    ?>
+    <div class="alert alert-info">
+        <i class="fal fa-fw fa-info-circle"></i> No photos are available for this location.
+    </div>
+    <?php
+}
+else {
+    ?>
+    <div class="row">
+    <?php
+    foreach($photos as $photo) {
+        $uri = "/account/locations/$location->id/photos/$photo->id";
+        ?>
+        <div class="col-md-4">
+            <a href="<?=$uri?>">
+                <img class="border img-fluid img-contain" src="/img/blank_4_3.png" style="background-image: url(<?=$uri?>)" />
+            </a>
+        </div>
+        <?php
+    }
+    ?>
+    </div>
+    <?php
+}
+?>
+</div>

+ 162 - 0
views/location_tests_tab.php

@@ -0,0 +1,162 @@
+<?php
+/**
+ * @var Location $location
+ */
+
+if(Core::$user->isAdmin()) {
+    $tests = $location->getTests();
+}
+else {
+    $tests = $location->getCompletedTests();
+}
+
+?>
+
+<div class="tab-pane fade" id="tests" role="tabpanel" aria-labelledby="tests-tab">
+    <?php
+    if(empty($tests)) {
+        ?>
+        <div class="alert alert-info">
+            This location has no tests.
+        </div>
+        <?php
+    }
+    else {
+        ?>
+        <table class="table table-bordered table-hover">
+            <thead>
+                <tr>
+                    <th>ID</th>
+                    <?php
+                    if(Core::$user->isAdmin()) {
+                        ?>
+                        <th>Project</th>
+                        <?php
+                    }
+                    else {
+                        ?>
+                        <th>Date/Time</th>
+                        <?php
+                    }
+                    ?>
+                    <th>Status</th>
+                    <th>Result</th>
+                    <th>Challenge Stage</th>
+                    <th>PDF</th>
+                    <?php
+                    if(Core::$user->isAdmin()) {
+                        ?>
+                        <th>Actions</th>
+                        <?php
+                    }
+                    ?>
+                </tr>
+            </thead>
+            <tbody>
+            <?php
+            foreach($tests as $test) {
+                $project = $test->getProject();
+                $template = $project->getTemplate();
+                $has_pass_fail = $template->hasPassFail();
+
+                $pass_text = $test->getPassText();
+                $pass_class = $test->getPassClass();
+                $pass_icon = $test->getPassIcon();
+
+                $challenge_stage = $test->challenge_stage;
+                $challenge_stage_text = $test->getChallengeStageText();
+                ?>
+                <tr>
+                    <td class="text-right align-middle">
+                        <?=$test->id?>
+                    </td>
+                    <td>
+                        <?php
+                        if(Core::$user->isAdmin()) {
+                            ?>
+                            <a href="/account/projects/<?=$project->id?>"><?=htmlspecialchars($project->name)?></a>
+                            <?php
+                        }
+                        else {
+                            echo Util::getDisplayDateTimeFromUTC($test->dts_start);
+                        }
+                        ?>
+                    </td>
+                    <td class="text-center">
+                        <span class="badge badge-lg badge-<?=$test->getStatusClass()?>"><?=htmlspecialchars($test->getStatusText())?></span>
+                    </td>
+                    <td class="text-center">
+                    <?php
+                    if($has_pass_fail) {
+                        ?>
+                        <strong class="text-<?=$pass_class?>"><?=htmlspecialchars($pass_text)?></strong>
+                        <?php
+                    }
+                    else {
+                        echo htmlspecialchars(__("N/A"));
+                    }
+                    ?>
+                    </td>
+                    <td>
+                    <?php
+                    if($has_pass_fail) {
+                        if($test->isPending()) {
+                            ?>
+                            <?=htmlspecialchars(__("Pending"))?>
+                            <?php
+                        }
+                        else {
+                            ?>
+                            <strong class="text-<?=$pass_class?>"><?=htmlspecialchars(__("Stage %d", $challenge_stage))?></strong> -
+                            <?=htmlspecialchars($challenge_stage_text)?>
+                            <?php
+                        }
+                    }
+                    else {
+                        echo htmlspecialchars(__("N/A"));
+                    }
+                    ?>
+                    </td>
+                    <td>
+                    <?php
+                    if($test->hasPDF()) {
+                        $pdf_url = $test->getPDFUrl();
+                        ?>
+                        <a href="<?=htmlspecialchars($pdf_url)?>" target="_blank">View PDF</a>
+                        <?php
+                    }
+                    else {
+                        echo htmlspecialchars(__("No PDF available"));
+                    }
+                    ?>
+                    </td>
+                    <?php
+                    if(Core::$user->isAdmin()) {
+                        ?>
+                        <td>
+                        <?php
+                        if($test->status >= Test::STATUS_PENDING_VERIFICATION) {
+                            ?>
+                            <a href="/account/tests/<?=$test->id?>">View Results</a>
+                            <?php
+                        }
+                        else {
+                            ?>
+                            <a href="/account/projects/<?=$test->project_id?>">View Project</a>
+                            <?php
+                        }
+                        ?>
+                        </td>
+                        <?php
+                    }
+                    ?>
+                </tr>
+                <?php
+            }
+            ?>
+            </tbody>
+        </table>
+        <?php
+    }
+    ?>
+</div>