Просмотр исходного кода

Adds support for viewing the PDF that was sent.

Alan Lam 8 лет назад
Родитель
Сommit
1b3574238b
4 измененных файлов с 24 добавлено и 10 удалено
  1. 6 5
      controllers/test.php
  2. 8 3
      controllers/test_file.php
  3. 1 1
      engine/test.php
  4. 9 1
      views/test_verify_form.php

+ 6 - 5
controllers/test.php

@@ -200,6 +200,10 @@ else if(Core::$user->level >= User::LEVEL_ADMIN) {
 		array_map(function($value) { return $value->value; }, $values)
 	);
 
+	$directory = $test->getDirectory();
+
+	$has_pdf = file_exists($directory . "/pdf.pdf");
+
 	$submit = http::value("submit");
 	$tester_message = http::value("tester_message", "trim");
 	if($submit) {
@@ -308,13 +312,10 @@ else if(Core::$user->level >= User::LEVEL_ADMIN) {
 				// Save PDF
 				$pdf = $test->getPDF();
 				$pdf_string = $pdf->Output("S");
-
-				$directory = $test->getDirectory();
-				$pdf_path = $directory . "/test.pdf";
+				$pdf_path = $directory . "/pdf.pdf";
 
 				$success = file_put_contents($pdf_path, $pdf_string);
 
-				// TODO: Send email to venue/HQ/tester
 				$email_customer = http::value("email_customer");
 				$email_location = http::value("email_location");
 
@@ -340,7 +341,7 @@ else if(Core::$user->level >= User::LEVEL_ADMIN) {
 	}
 
 	View::includeOnce("header", compact("page_title"));
-	View::include("test_verify_form", compact("test", "tester", "location", "project", "customer", "template", "fields", "values", "tester_message"));
+	View::include("test_verify_form", compact("test", "has_pdf", "tester", "location", "project", "customer", "template", "fields", "values", "tester_message"));
 	View::includeOnce("footer");
 	return;
 }

+ 8 - 3
controllers/test_file.php

@@ -8,11 +8,16 @@ if(Core::$user->level < User::LEVEL_ADMIN) {
 }
 
 $directory = $test->getDirectory();
-$path = $directory . "/" . $name . ".jpg";
+$path_jpg = $directory . "/" . $name . ".jpg";
+$path_pdf = $directory . "/" . $name . ".pdf";
 
-if(file_exists($path)) {
+if(file_exists($path_jpg)) {
 	header("Content-Type: image/jpeg");
-	readfile($path);
+	readfile($path_jpg);
+}
+else if(file_exists($path_pdf)) {
+	header("Content-Type: application/pdf");
+	readfile($path_pdf);
 }
 else {
 	header("Content-Type: image/png");

+ 1 - 1
engine/test.php

@@ -122,7 +122,7 @@ class Test extends Model {
 
 		$location = $this->getLocation();
 
-		$pdf_path = $this->getDirectory() . "/test.pdf";
+		$pdf_path = $this->getDirectory() . "/pdf.pdf";
 
 		// Content
 		$name = htmlspecialchars($this->first_name);

+ 9 - 1
views/test_verify_form.php

@@ -70,7 +70,15 @@ function render_card_list_group($details) {
 				</button>
 				<div class="dropdown-menu dropdown-menu-right" aria-labelledby="actions-button">
 					<a class="dropdown-item" href="/account/projects/<?=$test->project_id?>">View Project</a>
-					<a class="dropdown-item" href="/account/tests/<?=$test->id?>/pdf" target="_blank">View PDF</a>
+					<div class="dropdown-divider"></div>
+					<a class="dropdown-item" href="/account/tests/<?=$test->id?>/pdf" target="_blank">Generate New PDF</a>
+					<?php
+					if($has_pdf) {
+						?>
+						<a class="dropdown-item" href="/account/tests/<?=$test->id?>/files/pdf" target="_blank">View Sent PDF</a>
+						<?php
+					}
+					?>
 				</div>
 			</div>
 		</div>