Bladeren bron

Send decline email to contact email address.

Alan Lam 8 jaren geleden
bovenliggende
commit
44fd464fd7
2 gewijzigde bestanden met toevoegingen van 36 en 4 verwijderingen
  1. 2 4
      controllers/test_confirm.php
  2. 34 0
      engine/test.php

+ 2 - 4
controllers/test_confirm.php

@@ -12,8 +12,6 @@ switch($action) {
 		$test->dts_updated = Util::getDateTime();
 		$test->commit();
 
-		// TODO: Email/notification?
-
 		Core::addAlert("success", "Test accepted successfully.");
 		HTTP::redirect("/account/tests");
 
@@ -21,6 +19,8 @@ switch($action) {
 
 	case "decline":
 
+		$test->sendDeclineEmail();
+
 		$test->status = Test::STATUS_UNASSIGNED;
 		$test->tester_id = null;
 		$test->dts_due = null;
@@ -28,8 +28,6 @@ switch($action) {
 		$test->dts_updated = Util::getDateTime();
 		$test->commit();
 
-		// TODO: Email/notification?
-
 		Core::addAlert("success", "Test declined successfully.");
 		HTTP::redirect("/account/tests");
 

+ 34 - 0
engine/test.php

@@ -82,6 +82,40 @@ class Test extends Model {
 		$mail->send();
 	}
 
+	public function sendDeclineEmail() {
+
+		$tester = $this->getTester();
+		$location = $this->getLocation();
+		$project = $this->getProject();
+
+		// Content
+		$name = htmlspecialchars($tester->getDisplayName());
+		$address = htmlspecialchars($location->name . ", " . $location->getDisplayAddress(["address_1", "address_2", "city", "county", "postal_code"]));
+		$project_name = htmlspecialchars($project->name);
+		$project_url = htmlspecialchars(PROTOCOL . "://" . DOMAIN . "/account/projects/" . $project->id);
+		$internal_id = "N/A";
+		if($location->internal_id) $internal_id = htmlspecialchars($location->internal_id);
+
+		// Build
+		$builder = new EmailBuilder;
+		$builder->addParagraph("<b>Hi,</b>");
+		$builder->addLeadParagraph("A tester has declined a test.");
+
+		$builder->addParagraph("<b>Project:</b><br />$project_name");
+		$builder->addParagraph("<b>Site:</b><br />$address<br />ID: $location->id | Internal ID: $internal_id");
+		$builder->addParagraph("<b>Who:</b><br />$name<br />ID: $tester->id");
+		$builder->addParagraph("<a href=\"$project_url\">Click here</a> to manage the project and reassign the test.");
+		$content = $builder->build();
+
+		// Send
+		$mail = new Email;
+		$mail->setHtmlContent($content);
+		$mail->setFrom(EMAIL_NO_REPLY, EMAIL_FROM_NAME);
+		$mail->addAddress(EMAIL_CONTACT, "Check Policy Contact");
+		$mail->setSubject("Test declined: $project->name / $location->name");
+		$mail->send();
+	}
+
 	public function getChallengeStageText() {
 		return Test::STAGES[$this->challenge_stage];
 	}