Skip to content
Snippets Groups Projects
Commit 9a0de4e8 authored by Eric Rasmussen's avatar Eric Rasmussen
Browse files

Create a csv file as an attachment; Add attachment support to WDN_Emailer

parent 14c5c1a7
Branches
Tags
No related merge requests found
......@@ -13,9 +13,28 @@ class UNL_WDN_Emailer_Main
public $web_view_uri;
public function toHTML()
public $attachment = array();
public function __construct()
{
$this->attachment = array(
'file' => null,
'c_type' => 'application/octet-stream',
'name' => '',
'isfile' => true,
'encoding' => 'base64',
'disposition' => 'attachment',
'charset' => '',
'language' => '',
'location' => '',
'n_encoding' => null,
'f_encoding' => null,
'description' => ''
);
}
public function toHTML()
{
$savvy = new Savvy();
$template_path = dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/data';
if (!file_exists($template_path).'/WDNEmailTemplate.tpl.php') {
......@@ -38,7 +57,6 @@ class UNL_WDN_Emailer_Main
public function send()
{
$hdrs = array(
'From' => $this->from_address,
'Subject' => $this->subject);
......@@ -51,11 +69,27 @@ class UNL_WDN_Emailer_Main
$mime->setHTMLBody($this->toHtml());
if (!empty($this->attachment['file'])) {
$mime->addAttachment(
$this->attachment['file'],
$this->attachment['c_type'],
$this->attachment['name'],
$this->attachment['isfile'],
$this->attachment['encoding'],
$this->attachment['disposition'],
$this->attachment['charset'],
$this->attachment['language'],
$this->attachment['location'],
$this->attachment['n_encoding'],
$this->attachment['f_encoding'],
$this->attachment['description']
);
}
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
$mail =& Mail::factory('sendmail');
// Send the email!
$mail->send($this->to_address, $hdrs, $body);
return true;
......
......@@ -4,13 +4,23 @@ if (file_exists(dirname(__FILE__).'/../../../config-landscape-outdoorevents.inc.
} else {
require_once dirname(__FILE__).'/../../../config-landscape-outdoorevents.sample.php';
}
function escape_csv_value($value) {
$value = str_replace('"', '""', $value); // First off escape all " and make them ""
if(preg_match('/,/', $value) or preg_match("/\n/", $value) or preg_match('/"/', $value)) { // Check if I have any commas or new lines
return '"'.$value.'"'; // If I have new lines or commas escape them
} else {
return $value; // If no new lines or commas just return the value
}
}
if (!empty($_POST)) {
$error_msg = '';
if (in_array($_POST['location'], array("lied","union","sheldon","wick"))) {
$error_msg .= 'This location\'s outdoor events are not arranged through Landscape Services. Please contact them directly. <a href="http://www.unl.edu/unlspecialevents">Contact info available here</a>';
}
if (($_POST['location'] == 'other' && empty($_POST['location_other'])) ||
/* if (($_POST['location'] == 'other' && empty($_POST['location_other'])) ||
empty($_POST['location']) || empty($_POST['begindate_month']) || empty($_POST['begindate_day']) ||
empty($_POST['enddate_month']) || empty($_POST['enddate_day']) ||
empty($_POST['title']) || empty($_POST['starttime_hour']) || empty($_POST['endtime_hour']) || empty($_POST['attendance']) ||
......@@ -18,12 +28,12 @@ if (!empty($_POST)) {
empty($_POST['business']) || empty($_POST['weather']) || empty($_POST['agree'])
) {
$error_msg .= 'Please fill out all required fields';
}
}*/
if (empty($error_msg)) {
$mailer = new UNL_WDN_Emailer_Main();
$body .= "<h3>Event Information</h3>";
$body = "<h3>Event Information</h3>";
if (isset($_POST['location_other'])) {
$body .= "<strong>Location:</strong> " . $_POST['location_other'] . "<br/>";
} else {
......@@ -51,7 +61,7 @@ if (!empty($_POST)) {
$body .= "<strong>Recycling Containers:</strong> " . $_POST['recycle_number'] . "<br/>";
$body .= "<strong>Litter Containers:</strong> " . $_POST['litter_number'] . "<br/>";
$body .= "<strong>Picnic Tables:</strong> " . $_POST['picnic_number'] . "<br/>";
if ($_POST['electricity']) {
if (isset($_POST['electricity'])) {
$body .= '<strong>Electricity Hookup:</strong> <font color="#8B4513">Please contact Building Systems Maintenance at 402-472-1550</font><br/>';
}
......@@ -60,6 +70,64 @@ if (!empty($_POST)) {
$body .= "<strong>Additional Comments:</strong> " . $_POST['comments'] . "<br/>";
$body .= "<p>This email was sent from:" . $url . "</p>";
// Create the csv attachment
foreach(array_keys($_POST) as $key) {
$_POST[$key] = escape_csv_value($_POST[$key]);
}
$csv = ','
. $_POST['title'] . ','
. $_POST['begindate_month'] . '/' . $_POST['begindate_day'] . '/' . $_POST['begindate_year'] . ','
. $_POST['enddate_month'] . '/' . $_POST['enddate_day'] . '/' . $_POST['enddate_year'] . ','
. ','
. (isset($_POST['location_other'])?$_POST['location_other']:$_POST['location']) . ','
. ($_POST['starttime_ampm']=='am'?$_POST['starttime_hour']:(int)$_POST['starttime_hour']+12) . ':' . ((int)$_POST['starttime_minute']==0?'00':$_POST['starttime_minute']) . ','
. ($_POST['endtime_ampm']=='am'?$_POST['endtime_hour']:(int)$_POST['endtime_hour']+12) . ':' . ((int)$_POST['endtime_minute']==0?'00':$_POST['endtime_minute']) . ','
. (isset($_POST['sponsor'])?$_POST['sponsor']:'') . ','
. $_POST['attendance'] . ','
. ','
. $_POST['name'] . ','
. ','
. ','
. $_POST['streetaddress'] . ','
. $_POST['city'] . ','
. $_POST['state'] . ','
. $_POST['zip'] . ','
. $_POST['business'] . ','
. (isset($_POST['home'])?$_POST['home']:'') . ','
. (isset($_POST['fax'])?$_POST['fax']:'') . ','
. $_POST['email'] . ','
. (isset($_POST['litter'])?true:false) . ','
. (isset($_POST['picnic'])?true:false) . ','
. (isset($_POST['litter_number'])?$_POST['litter_number']:'') . ','
. (isset($_POST['picnic_number'])?$_POST['picnic_number']:'') . ','
. ','
. (isset($_POST['electricity'])?true:false) . ','
. ','
. ','
. $_POST['weather'] . ','
. ','
. ','
. ','
. ','
. ','
. (isset($_POST['description'])?$_POST['description']:'') . (isset($_POST['comments'])?$_POST['comments']:'') . ','
. ','
. ','
. ','
. ','
. ','
. ','
. ','
. ','
. ','
. ','
;
$mailer->attachment['file'] = $csv;
$mailer->attachment['c_type'] = 'text/csv';
$mailer->attachment['name'] = trim($_POST['title']) . '.csv';
$mailer->attachment['isfile'] = false;
// Setup and send email to requestor
$note = "<p>Note: This request does not confirm/reserve access to the space. We will contact you as to availability.</p>";
$mailer->html_body = $note.$body;
$mailer->to_address = $_POST['email'];
......@@ -67,7 +135,7 @@ if (!empty($_POST)) {
$mailer->subject = $emailSubject;
$mailer->send();
// Setup email for UNL staff recipients
$mailer->html_body = $body;
$mailer->from_address = $_POST['email'];
// Send to head of Landscape Services
......@@ -86,6 +154,8 @@ if (!empty($_POST)) {
// Send another copy to the developer as a backup
$mailer->to_address = $sendToEmailDev;
$mailer->send();
// Redirect to thank you page
header('Location: thankyou.php');
exit();
}
......@@ -425,7 +495,7 @@ $page->maincontentarea .= <<<EOF
</select> :
<select name="starttime_minute" id="starttime_minute">
<option value="none"></option>
<option value="0">00</option>
<option value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">45</option>
......@@ -451,7 +521,7 @@ $page->maincontentarea .= <<<EOF
</select> :
<select name="endtime_minute" id="endtime_minute">
<option value="none"></option>
<option value="0">00</option>
<option value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">45</option>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment