From 56c5b32df9e69d8b995d5f91e082682269a7c7fd Mon Sep 17 00:00:00 2001 From: Eric Rasmussen <erasmussen2@unl.edu> Date: Mon, 18 Apr 2011 21:18:28 +0000 Subject: [PATCH] Change isset to !empty; More formatting and work on the csv file --- www/landscape/outdoorevents/index.php | 79 ++++++++++++++------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/www/landscape/outdoorevents/index.php b/www/landscape/outdoorevents/index.php index 175367e..abb1ccb 100644 --- a/www/landscape/outdoorevents/index.php +++ b/www/landscape/outdoorevents/index.php @@ -6,12 +6,12 @@ if (file_exists(dirname(__FILE__).'/../../../config-landscape-outdoorevents.inc. } 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 - } + $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)) { @@ -20,7 +20,7 @@ if (!empty($_POST)) { 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']) || @@ -28,13 +28,13 @@ 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>"; - if (isset($_POST['location_other'])) { + if (!empty($_POST['location_other'])) { $body .= "<strong>Location:</strong> " . $_POST['location_other'] . "<br/>"; } else { $body .= "<strong>Location:</strong> " . $_POST['location'] . "<br/>"; @@ -72,18 +72,19 @@ if (!empty($_POST)) { // Create the csv attachment foreach(array_keys($_POST) as $key) { - $_POST[$key] = escape_csv_value($_POST[$key]); + if ($key != 'attendance') + $_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']) . ',' + . (!empty($_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'] . ',' + . (!empty($_POST['sponsor'])?$_POST['sponsor']:'') . ',' + . str_replace(",", "",$_POST['attendance']) . ',' . ',' . $_POST['name'] . ',' . ',' @@ -93,39 +94,34 @@ if (!empty($_POST)) { . $_POST['state'] . ',' . $_POST['zip'] . ',' . $_POST['business'] . ',' - . (isset($_POST['home'])?$_POST['home']:'') . ',' - . (isset($_POST['fax'])?$_POST['fax']:'') . ',' + . (!empty($_POST['home'])?$_POST['home']:'') . ',' + . (!empty($_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) . ',' - . ',' - . ',' + . (!empty($_POST['litter'])?'true':'false') . ',' + . (!empty($_POST['picnic'])?'true':'false') . ',' + . (!empty($_POST['litter_number'])?$_POST['litter_number']:'') . ',' + . (!empty($_POST['picnic_number'])?$_POST['picnic_number']:'') . ',' + . 'true,' + . (!empty($_POST['electricity'])?'true':'false') . ',' + . (!empty($_POST['litter_number'])? 12+((int)$_POST['litter_number']-1)*4 :'') . ',' + . (!empty($_POST['picnic_number'])? 25+((int)$_POST['picnic_number']-1)*10 :'') . ',' . $_POST['weather'] . ',' + . 'TBD,' + . 'TBD,' + . 'TBD,' + . 'T. Moore,' . ',' + . (!empty($_POST['description'])?$_POST['description']:'') . ' --- ' . (!empty($_POST['comments'])?$_POST['comments']:'') . ',' . ',' . ',' - . ',' - . ',' - . (isset($_POST['description'])?$_POST['description']:'') . (isset($_POST['comments'])?$_POST['comments']:'') . ',' - . ',' - . ',' - . ',' - . ',' - . ',' - . ',' - . ',' - . ',' - . ',' + . 'false,' + . 'false,' + . 'false,' + . 'false,' + . 'false,' + . 'false,' . ',' ; - $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>"; @@ -135,6 +131,11 @@ if (!empty($_POST)) { $mailer->subject = $emailSubject; $mailer->send(); + // Add the attachment for internal emails + $mailer->attachment['file'] = $csv; + $mailer->attachment['c_type'] = 'text/csv'; + $mailer->attachment['name'] = 'newevent.csv'; + $mailer->attachment['isfile'] = false; // Setup email for UNL staff recipients $mailer->html_body = $body; $mailer->from_address = $_POST['email']; -- GitLab