Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 61 additions & 1 deletion class/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,38 @@ public static function logEmail($message)
fclose($fd);
}

/**
* Logs a Swift_Message object to a text file
*/
public static function logSwiftmailMessageLong(\Swift_Message $message)
{
$fd = fopen(PHPWS_SOURCE_DIR . 'logs/email.log', 'a');
fprintf($fd, "=======================\n");
foreach($message->getFrom() as $address => $name) {
fprintf($fd, "From: %s <%s>\n", $name, $address);
}
foreach($message->getTo() as $address => $name) {
fprintf($fd, "To: %s <%s>\n", $name, $address);
}
$cc = $message->getCc();
if(!empty($cc)){
foreach($cc() as $address => $name) {
fprintf($fd, "Cc: %s <%s>\n", $name, $address);
}
}
$bcc = $message->getBcc();
if(!empty($bcc)){
foreach($bcc as $address => $name) {
fprintf($fd, "Bcc: %s <%s>\n", $name, $address);
}
}
fprintf($fd, "Sender: %s\n", $message->getSender());
fprintf($fd, "Subject: %s\n", $message->getSubject());
fprintf($fd, "Date: %s\n", date('Y-m-d H:i:s'));
fprintf($fd, "Content: \n");
fprintf($fd, "%s\n\n", $message->toString());
}

/**
* Sends an email to the registrar notifying them to register
* the student for the appropriate internship course.
Expand Down Expand Up @@ -380,7 +412,7 @@ public static function sendIntlInternshipCreateNoticeStudent(Internship $i)

$dept = new Department($i->department_id);
$tpl['DEPARTMENT'] = $dept->getName();
$to = $i->email . '@appstate.edu';
$to = $i->email . $settings->getEmailDomain();

$subject = "International Internship Created - {$i->first_name} {$i->last_name}";

Expand Down Expand Up @@ -505,6 +537,34 @@ public static function sendRegistrationConfirmationEmail(Internship $i, Agency $
email::sendTemplateMessage($to, $subject, 'email/RegistrationConfirmation.tpl', $tpl, $cc);
}

/**
* Sends the internship contract to the student.
*
*@param Inernship $i
*@param InternshipContractPdfView $pdfView
*/
public static function emailContractToStudent(Internship $i, InternshipContractPdfView $pdfView)
{
$settings = InternSettings::getInstance();

try{
$message = \Swift_Message::newInstance();
$message->setSubject('Internship Contract');
$message->setFrom(array(('noreply' . $settings->getEmailDomain()) => $settings->getSystemName()));
$message->setTo(array(($i->email . $settings->getEmailDomain()) => $i->getFullName()));
$message->setBody('Attached is a copy of your internship contract. If you have any issues with your contract, please contact your faculty supervisor.');
$attachment = \Swift_Attachment::newInstance($pdfView->getPdf()->output('internship-contract.pdf', 'S'), $i->getFullName() . ' Internship Contract.pdf');
$message->attach($attachment);

$transport = \Swift_SmtpTransport::newInstance('localhost');
$mailer = \Swift_Mailer::newInstance($transport);

self::logSwiftmailMessageLong($message);
}catch(\Swift_TransportException $e){
$transport->stop();
}
}

/**
* Sends the 'Registration Issue' notification email.
*
Expand Down
9 changes: 9 additions & 0 deletions class/InternshipInventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ public function handleRequest()
$pdf = $pdfView->getPdf();
$pdf->output();
exit;
case 'emailPdf' :
$i = InternshipFactory::getInternshipById($_REQUEST['internship_id']);
$emgContacts = EmergencyContactFactory::getContactsForInternship($i);
$pdfView = new InternshipContractPdfView($i, $emgContacts);
Email::emailContractToStudent($i, $pdfView);
\NQ::simple('intern', \Intern\UI\NotifyUI::SUCCESS, 'Contract emailed to student.');
\NQ::close();
\PHPWS_Core::reroute("index.php?module=intern&action=ShowInternship&internship_id=" . $i->getId());
exit;
case 'upload_document_form':
$docManager = new DocumentManager();
echo $docManager->edit();
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"require": {
"setasign/fpdi-fpdf": "^1.6"
"setasign/fpdi-fpdf": "^1.6",
"swiftmailer/swiftmailer": "@stable"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
Expand Down
Loading