Email result link to user

This commit is contained in:
Mark Wane 2019-10-06 10:03:07 +01:00
parent 2d743e8546
commit 8592bc0c3c
3 changed files with 20 additions and 1 deletions

View file

@ -1,4 +1,5 @@
<?php
use TestProject\User;
use TestProject\Quiz;
use TestProject\Question;
require_once 'init.php';
@ -26,8 +27,12 @@ if ( count( $questID_arr ) > $index_int ){
$data_arr['ans'][] = array( 'id' => $answer->getID(), 'text' => $answer->getText() );
}
} else {
$user = new User( $_POST['user'] );
$accessKey_str = $quiz->saveResult( $_POST['user'] );
$user->emailResult( $accessKey_str );
$data_arr = array(
'done' => true,
'result' => $accessKey_str

View file

@ -105,4 +105,18 @@ class User extends Item {
public function getEmail(){
return $this->email_str;
}
/**
* Email a link to the results page
*
* @param string $accessKey_str Access key for result
*/
public function emailResult( string $accessKey_str ){
$to_str = $this->name_str . " <" . $this->email_str . ">";
$subject_str = "Your results";
$url_str = $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['SERVER_NAME'] . dirname( $_SERVER['PHP_SELF'] ) . "/result.php?key=" . $accessKey_str;
$body_str = "Thank you for completing the quiz, your result can be viewed at the following link. \r\n" . $url_str;
mail( $to_str, $subject_str, $body_str );
}
}

View file

@ -52,7 +52,7 @@ if ( $scorePer_num > $averagePer_num + 10 ){
<div class="col-md-6">
<p>Average score</p>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: <?php echo $averagePer_num; ?>%"><?php echo $data_arr['average'] . " / " . $maxScore_int ?></div>
<div class="progress-bar" role="progressbar" style="width: <?php echo $averagePer_num; ?>%"><?php echo round( $data_arr['average'], 1 ) . " / " . $maxScore_int ?></div>
</div>
</div>
</div>