Skip to content

Commit

Permalink
Adding email confirmation messages
Browse files Browse the repository at this point in the history
  • Loading branch information
darthmolly committed Oct 10, 2011
1 parent bd64224 commit a3c2088
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 14 deletions.
22 changes: 12 additions & 10 deletions inc/configs.inc.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<?php

$constants = array(
"APPLICATION_NAME" => "SSN Remediation", # this will be the page title and the header for each page
"DATABASE_HOST" => "localhost", # your database server
"DATABASE_NAME" => "remediation", # the name of your database
"DATABASE_USER" => "remediator", # the database username
"DATABASE_PASSWORD" => "remediate", # the database password
"DATABASE_TABLE" => "users", # the database table -- no need to change unless you modified the schema
"USER_FIELD" => "computing_id", # the user identifier field -- no need to change unless you modified the schema
"STATUS_FIELD" => "completion_date", # the completion date field -- no need to change unless you modified the schema
"ADMINISTRATORS_TABLE" => "administrators" # the administrators table -- no need to change unless you modified the schema
"APPLICATION_NAME" => "SSN Remediation", # this will be the page title and the header for each page
"ADMIN_EMAIL" => "mst3k@virginia.edu", # the email address where confirmation emails are sent
"EMAIL_SUBJECT" => "Remediation Confirmation",# subject line of confirmation emails
"DATABASE_HOST" => "localhost", # your database server
"DATABASE_NAME" => "remediation", # the name of your database
"DATABASE_USER" => "remediator", # the database username
"DATABASE_PASSWORD" => "remediate", # the database password
"DATABASE_TABLE" => "users", # the database table -- no need to change unless you modified the schema
"USER_FIELD" => "computing_id", # the user identifier field -- no need to change unless you modified the schema
"STATUS_FIELD" => "completion_date", # the completion date field -- no need to change unless you modified the schema
"ADMINISTRATORS_TABLE" => "administrators" # the administrators table -- no need to change unless you modified the schema
);

foreach ($constants as $name => $value) {
define($name, $value);
define($name, $value);
}

?>
12 changes: 8 additions & 4 deletions inc/user.class.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<?php
class User {
//attributes
var $_computing_id;
var $_complete;
var $_administrator;

function getComputingId() {
return $this->_computing_id;
Expand All @@ -29,6 +25,12 @@ function getLastName() {
function setLastName($last_name) {
$this->_last_name = $last_name;
}
function getEmail() {
return $this->_email;
}
function setEmail($email) {
$this->_email = $email;
}
function isAdministrator() {
return $this->_administrator;
}
Expand All @@ -47,11 +49,13 @@ function setLdapInfo() {
if ($entries["count"] < 1) {
$this->setFirstName("");
$this->setLastName("");
$this->setEmail("$userID@Virginia.EDU");
return;
}
$entry = $entries[0];
$this->setFirstName($entry["givenname"][0]);
$this->setLastName($entry["sn"][0]);
$this->setEmail($entry["mail"][0]);
}

function User($computing_id, $completion_date) {
Expand Down
30 changes: 30 additions & 0 deletions inc/utils.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

function sendUserConfirmation($user) {
$to = $user->getEmail();
$subject = EMAIL_SUBJECT;
$file = "partials/user_confirmation_email.inc.php";
$handle = fopen($file, "r");
$body = fread($handle, filesize($file));
fclose($handle);
$headers = "From: " . ADMIN_EMAIL;
$extra = "-f" . ADMIN_EMAIL;
mail($to, $subject, $body, $headers, $extra);
}

function sendAdminConfirmation($user) {
$to = ADMIN_EMAIL;
$subject = EMAIL_SUBJECT . " [" . $user->getComputingId() . "]";
$file = "partials/admin_confirmation_email.inc.php";
$handle = fopen($file, "r");
$body = fread($handle, filesize($file));
fclose($handle);
$body = str_replace("{first_name}", $user->getFirstName(), $body);
$body = str_replace("{last_name}", $user->getLastName(), $body);
$body = str_replace("{computing_id}", $user->getComputingId(), $body);
$headers = "From: " . ADMIN_EMAIL;
$extra = "-f" . ADMIN_EMAIL;
mail($to, $subject, $body, $headers, $extra);
}

?>
3 changes: 3 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
include_once("inc/configs.inc.php");
include_once("inc/db.inc.php");
include_once("inc/utils.inc.php");
$user = getUser($_SERVER['PHP_AUTH_USER']);
include("partials/header.inc.php");
?>
Expand All @@ -10,6 +11,8 @@
include("partials/not_found.inc.php");
} else if (isset($_POST["complete"])) {
updateCompletionDate($user->getComputingId());
sendUserConfirmation($user);
sendAdminConfirmation($user);
include("partials/done.inc.php");
} else {
$user->complete() ? include("partials/complete.inc.php") : include("partials/incomplete.inc.php");
Expand Down
3 changes: 3 additions & 0 deletions partials/admin_confirmation_email.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The following user has completed remediation:

{first_name} {last_name} ({computing_id})
1 change: 1 addition & 0 deletions partials/user_confirmation_email.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Thank you for completing remediation. Please keep this email in your records.

0 comments on commit a3c2088

Please sign in to comment.