diff --git a/lib/php/UNL/WDN/Emailer/Main.php b/lib/php/UNL/WDN/Emailer/Main.php index 87d38e8921f627b7120638d507521b2247a563d5..5e15a5a7b70ff9c8bf40f575b4f67c729587b1a1 100644 --- a/lib/php/UNL/WDN/Emailer/Main.php +++ b/lib/php/UNL/WDN/Emailer/Main.php @@ -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') { @@ -30,7 +49,7 @@ class UNL_WDN_Emailer_Main '</html>'; return $html; } - + public function toTxt() { return $this->text_body; @@ -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; diff --git a/www/landscape/outdoorevents/index.php b/www/landscape/outdoorevents/index.php index 1805c509466f3d576f5777ead0e68ac609952791..175367ee53b1b97a6916e76bff4cc441f0351386 100644 --- a/www/landscape/outdoorevents/index.php +++ b/www/landscape/outdoorevents/index.php @@ -4,26 +4,36 @@ 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']) || - empty($_POST['name']) || empty($_POST['email']) || empty($_POST['streetaddress']) || empty($_POST['city']) || empty($_POST['state']) || empty($_POST['zip']) || + empty($_POST['name']) || empty($_POST['email']) || empty($_POST['streetaddress']) || empty($_POST['city']) || empty($_POST['state']) || empty($_POST['zip']) || 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 { @@ -37,7 +47,7 @@ if (!empty($_POST)) { $body .= "<strong>End Time:</strong> " . $_POST['endtime_hour'].":".$_POST['endtime_minute']." ".$_POST['endtime_ampm']. "<br/>"; $body .= "<strong>Expected Attendance:</strong> " . $_POST['attendance'] . "<br/>"; $body .= "<strong>Sponsor:</strong> " . $_POST['sponsor'] . "<br/>"; - + $body .= "<h3>Contact Information</h3>"; $body .= "<strong>Name:</strong> " . $_POST['name'] . "<br/>"; $body .= "<strong>Email:</strong> " . $_POST['email'] . "<br/>"; @@ -46,28 +56,86 @@ if (!empty($_POST)) { $body .= "<strong>Daytime Phone:</strong> " . $_POST['business'] . "<br/>"; $body .= "<strong>Home Phone:</strong> " . $_POST['home'] . "<br/>"; $body .= "<strong>Fax:</strong> " . $_POST['fax'] . "<br/>"; - + $body .= "<h3>Additional Event Requests</h3>"; $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/>'; } - + $body .= "<h3>Other Information</h3>"; $body .= "<strong>Bad Weather Contingency:</strong> " . $_POST['weather'] . "<br/>"; $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']; $mailer->from_address = $sendFromEmail; $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> @@ -478,7 +548,7 @@ $page->maincontentarea .= <<<EOF <input type="text" id="sponsor" name="sponsor" /> </li> </ol> - </fieldset> + </fieldset> <fieldset> <legend>Contact Information</legend> <ol> @@ -525,8 +595,8 @@ $page->maincontentarea .= <<<EOF </label> <input type="text" id="zip" name="zip" /> </li> - - + + <li style="clear:left;float:left"> <label for="business"> <span class="required">*</span> @@ -649,7 +719,7 @@ $page->maincontentarea .= <<<EOF <textarea id="comments" name="comments" rows="4" cols="auto"></textarea> </li> <li> - <fieldset> + <fieldset> <legend> <span class="required">*</span> You must read and agree to the <br><a href="http://bf.unl.edu/policies/fmp/GuidelinesUseUNLCampusOutdoorSpaces.shtml" target="_blank" class="external">Guidelines for Use of UNL Campus Outdoor Spaces</a>