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

Add support to send documentation email to user

Alan Lam 6 лет назад
Родитель
Сommit
6188d4398e
4 измененных файлов с 54 добавлено и 10 удалено
  1. 5 2
      controllers/user.php
  2. 2 0
      engine/email.php
  3. 30 0
      engine/user.php
  4. 17 8
      views/user.php

+ 5 - 2
controllers/user.php

@@ -17,6 +17,11 @@ if($submit) {
 				Core::addAlert("success", "Activation email sent.");
 				http::redirect("/account/users/$id");
 				break;
+			case "send_documentation_email":
+				$success = $user->sendDocumentationEmail();
+				Core::addAlert("success", "Documentation email sent.");
+				http::redirect("/account/users/$id");
+				break;
 		}
 	}
 	catch(Exception $e) {
@@ -33,5 +38,3 @@ Core::addBreadcrumb("/account/users/$id", $page_title);
 View::includeOnce("header", compact("page_title"));
 View::include("user", compact("user"));
 View::includeOnce("footer");
-
-?>

+ 2 - 0
engine/email.php

@@ -112,6 +112,7 @@ class Email {
 	 * @param string $email
 	 * @param string $name
 	 * @return bool
+	 * @throws \PHPMailer\PHPMailer\Exception
 	 */
 	public function addAddress(string $email, string $name = "") {
 		return $this->instance->addAddress($email, $name);
@@ -121,6 +122,7 @@ class Email {
 	 * @param string $email
 	 * @param string $name
 	 * @return bool
+	 * @throws \PHPMailer\PHPMailer\Exception
 	 */
 	public function addReplyTo(string $email, string $name = "") {
 		return $this->instance->addReplyTo($email, $name);

+ 30 - 0
engine/user.php

@@ -309,6 +309,36 @@ class User extends Model {
 
 	}
 
+	/**
+	 * @return bool
+	 * @throws Exception
+	 */
+	public function sendDocumentationEmail(): bool {
+
+		// Content
+		$name = htmlspecialchars($this->first_name);
+
+		// Build
+		$builder = new EmailBuilder;
+		$builder->addParagraph("<b>" . sprintf(__("Hi %s"), $name) . "</b>");
+		$builder->addLeadParagraph(__("Thanks for registering with us!"));
+		$builder->addParagraph(__("The good news is that we have tests for you straight away."));
+		$builder->addParagraph(__("We are testing if you are asked for ID in a pubs and also in amusement arcades before playing a slot machine. I have attached two documents with the test protocol for you to read and we will assign you the tests. Take a look at the protocol and let us know when you are ready."));
+		$content = $builder->build();
+
+		// Send
+
+		$mail = new Email;
+		$mail->setHtmlContent($content);
+		$mail->setFrom(EMAIL_NO_REPLY, EMAIL_FROM_NAME);
+		$mail->addAddress($this->email, $this->getDisplayName());
+		$mail->addAttachment("public/files/testing_procedure_arcades.pdf", "Testing Procedure - Arcades.pdf");
+		$mail->addAttachment("public/files/testing_procedure_pubs.pdf", "Testing Procedure - Pubs.pdf");
+		$mail->setSubject(__("Documentation"));
+
+		return $mail->send();
+	}
+
 	/**
 	 * @return bool
 	 */

+ 17 - 8
views/user.php

@@ -59,14 +59,23 @@ const userId = <?=$user->id?>;
 		<div class="col-auto text-right">
 			<form class="form-inline" method="post">
 				<input type="hidden" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>" />
-				<?php
-				if(!$user->activated) {
-					?>
-					<button class="btn btn-outline-primary" type="submit" name="action" value="send_activation_email">Send Activation Email</button>
-					<?php
-				}
-				?>
-				<a class="btn btn-outline-primary ml-1" href="/account/users/<?=$user->id?>/edit">Edit</a>
+				<div class="btn-group">
+					<a class="btn btn-primary" href="/account/users/<?=$user->id?>/edit">Edit</a>
+					<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+						<span class="sr-only"><?=htmlspecialchars(__("Toggle Dropdown"))?></span>
+					</button>
+					<div class="dropdown-menu dropdown-menu-right">
+						<?php
+						if(!$user->activated) {
+							?>
+							<button class="dropdown-item" type="submit" name="action" value="send_activation_email">Send Activation Email</button>
+							<?php
+						}
+						?>
+						<button class="dropdown-item" type="submit" name="action" value="send_documentation_email"><?=htmlspecialchars(__("Send Documentation Email"))?></button>
+					</div>
+				</div>
+
 			</form>
 		</div>
 	</div>