time())) { return "

I am sorry but the ability to RSVP for our wedding won't open till ".date("m/d/Y", strtotime($openDate))."

"; } if((strtotime($closeDate) !== false) && (strtotime($closeDate) < time())) { return "

The deadline to RSVP for this wedding has passed, please contact the bride and groom to see if there is still a seat for you.

"; } if(isset($_POST['rsvpStep'])) { $output = ""; switch(strtolower($_POST['rsvpStep'])) { case("handlersvp") : if(is_numeric($_POST['attendeeID']) && ($_POST['attendeeID'] > 0)) { // update their information and what not.... if(strToUpper($_POST['mainRsvp']) == "Y") { $rsvpStatus = "Yes"; } else { $rsvpStatus = "No"; } $attendeeID = $_POST['attendeeID']; $wpdb->update(ATTENDEES_TABLE, array("rsvpDate" => date("Y-m-d"), "rsvpStatus" => $rsvpStatus, "note" => $_POST['note'], "kidsMeal" => ((isset($_POST['mainKidsMeal']) && (strToUpper($_POST['mainKidsMeal']) == "Y")) ? "Y" : "N"), "veggieMeal" => ((isset($_POST['mainVeggieMeal']) && (strToUpper($_POST['mainVeggieMeal']) == "Y")) ? "Y" : "N")), array("id" => $attendeeID), array("%s", "%s", "%s", "%s", "%s"), array("%d")); rsvp_handleAdditionalQuestions($attendeeID, "mainquestion"); $sql = "SELECT id FROM ".ATTENDEES_TABLE." WHERE (id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d) OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d)) AND rsvpStatus = 'NoResponse'"; $associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID)); foreach($associations as $a) { if($_POST['rsvpFor'.$a->id] == "Y") { if($_POST['attending'.$a->id] == "Y") { $rsvpStatus = "Yes"; } else { $rsvpStatus = "No"; } $wpdb->update(ATTENDEES_TABLE, array("rsvpDate" => date("Y-m-d"), "rsvpStatus" => $rsvpStatus, "kidsMeal" => ((strToUpper((isset($_POST['attending'.$a->id.'KidsMeal']) ? $_POST['attending'.$a->id.'KidsMeal'] : "N")) == "Y") ? "Y" : "N"), "veggieMeal" => ((strToUpper((isset($_POST['attending'.$a->id.'VeggieMeal']) ? $_POST['attending'.$a->id.'VeggieMeal'] : "N")) == "Y") ? "Y" : "N")), array("id" => $a->id), array("%s", "%s", "%s", "%s"), array("%d")); rsvp_handleAdditionalQuestions($a->id, $a->id."question"); } } if(get_option(OPTION_HIDE_ADD_ADDITIONAL) != "Y") { if(is_numeric($_POST['additionalRsvp']) && ($_POST['additionalRsvp'] > 0)) { for($i = 1; $i <= $_POST['additionalRsvp']; $i++) { if(($i <= 3) && !empty($_POST['newAttending'.$i.'FirstName']) && !empty($_POST['newAttending'.$i.'LastName'])) { $wpdb->insert(ATTENDEES_TABLE, array("firstName" => trim($_POST['newAttending'.$i.'FirstName']), "lastName" => trim($_POST['newAttending'.$i.'LastName']), "rsvpDate" => date("Y-m-d"), "rsvpStatus" => (($_POST['newAttending'.$i] == "Y") ? "Yes" : "No"), "kidsMeal" => (isset($_POST['newAttending'.$i.'KidsMeal']) ? $_POST['newAttending'.$i.'KidsMeal'] : "N"), "veggieMeal" => (isset($_POST['newAttending'.$i.'VeggieMeal']) ? $_POST['newAttending'.$i.'VeggieMeal'] : "N"), "additionalAttendee" => "Y"), array('%s', '%s', '%s', '%s', '%s', '%s')); $newAid = $wpdb->insert_id; rsvp_handleAdditionalQuestions($newAid, $i.'question'); // Add associations for this new user $wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID" => $newAid, "associatedAttendeeID" => $attendeeID), array("%d", "%d")); $wpdb->query($wpdb->prepare("INSERT INTO ".ASSOCIATED_ATTENDEES_TABLE."(attendeeID, associatedAttendeeID) SELECT ".$newAid.", associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = ".$attendeeID)); } } } } if((get_option(OPTION_NOTIFY_ON_RSVP) == "Y") && (get_option(OPTION_NOTIFY_EMAIL) != "")) { $sql = "SELECT firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE." WHERE id= ".$attendeeID; $attendee = $wpdb->get_results($sql); if(count($attendee) > 0) { $body = "Hello, \r\n\r\n"; $body .= stripslashes($attendee[0]->firstName)." ".stripslashes($attendee[0]->lastName). " has submitted their RSVP and has RSVP'd with '".$attendee[0]->rsvpStatus."'."; wp_mail(get_option(OPTION_NOTIFY_EMAIL), "New RSVP Submission", $body); } } return frontend_rsvp_thankyou(); } else { return rsvp_frontend_greeting(); } break; case("editattendee") : if(is_numeric($_POST['attendeeID']) && ($_POST['attendeeID'] > 0)) { // Try to find the user. $attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE." WHERE id = %d", $_POST['attendeeID'])); if($attendee != null) { $output .= "
\r\n"; $output .= "

Welcome back ".htmlentities($attendee->firstName." ".$attendee->lastName)."!

"; $output .= rsvp_frontend_main_form($attendee->id); return $output."
\r\n"; } } break; case("foundattendee") : if(is_numeric($_POST['attendeeID']) && ($_POST['attendeeID'] > 0)) { // Try to find the user. $attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE." WHERE id = %d", $_POST['attendeeID'])); if($attendee != null) { $output = "
\r\n"; if(strtolower($attendee->rsvpStatus) == "noresponse") { $output .= "

Hi ".htmlentities(stripslashes(utf8_decode($attendee->firstName." ".$attendee->lastName)))."!

". "

There are a few more questions we need to ask you if you could please fill them out below to finish up the RSVP process.

"; $output .= rsvp_frontend_main_form($attendee->id); } else { $output .= rsvp_frontend_prompt_to_edit($attendee); } return $output."
\r\n"; } return rsvp_frontend_greeting(); } else { return rsvp_frontend_greeting(); } break; case("find") : $_SESSION['rsvpFirstName'] = $_POST['firstName']; $_SESSION['rsvpLastName'] = $_POST['lastName']; $firstName = $_POST['firstName']; $lastName = $_POST['lastName']; if((strlen($_POST['firstName']) <= 1) || (strlen($_POST['lastName']) <= 1)) { $output = "

A first and last name must be specified

\r\n"; $output .= rsvp_frontend_greeting(); return $output; } // Try to find the user. $attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE." WHERE firstName = %s AND lastName = %s", $firstName, $lastName)); if($attendee != null) { // hey we found something, we should move on and print out any associated users and let them rsvp $output = "
\r\n"; if(strtolower($attendee->rsvpStatus) == "noresponse") { $output .= "

Hi ".htmlentities(stripslashes(utf8_decode($attendee->firstName." ".$attendee->lastName)))."!

". "

There are a few more questions we need to ask you if you could please fill them out below to finish up the RSVP process.

"; $output .= rsvp_frontend_main_form($attendee->id); } else { $output .= rsvp_frontend_prompt_to_edit($attendee); } return $output."
\r\n"; } // We did not find anyone let's try and do a rough search $attendees = null; for($i = 3; $i >= 1; $i--) { $truncFirstName = rsvp_chomp_name($firstName, $i); $attendees = $wpdb->get_results("SELECT id, firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE." WHERE lastName = '".mysql_real_escape_string($lastName)."' AND firstName LIKE '".mysql_real_escape_string($truncFirstName)."%'"); if(count($attendees) > 0) { $output = "

We could not find an exact match but could any of the below entries be you?

"; foreach($attendees as $a) { $output .= "
\r\n \r\n id."\" />\r\n

\r\n ".htmlentities(utf8_decode($a->firstName." ".$a->lastName))." \r\n

\r\n
\r\n"; } return $output; } else { $i = strlen($truncFirstName); } } return "

We were unable to find anyone with a name of ".htmlentities(utf8_decode($firstName." ".$lastName))."

\r\n".rsvp_frontend_greeting(); break; case("newsearch"): default: return rsvp_frontend_greeting(); break; } } else { return rsvp_frontend_greeting(); } } function rsvp_handleAdditionalQuestions($attendeeID, $formName) { global $wpdb; $wpdb->query($wpdb->prepare("DELETE FROM ".ATTENDEE_ANSWERS." WHERE attendeeID = %d ", $attendeeID)); $qRs = $wpdb->get_results("SELECT q.id, questionType FROM ".QUESTIONS_TABLE." q INNER JOIN ".QUESTION_TYPE_TABLE." qt ON qt.id = q.questionTypeID ORDER BY q.sortOrder"); if(count($qRs) > 0) { foreach($qRs as $q) { if(isset($_POST[$formName.$q->id]) && !empty($_POST[$formName.$q->id])) { if($q->questionType == QT_MULTI) { $selectedAnswers = ""; $aRs = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $q->id)); if(count($aRs) > 0) { foreach($aRs as $a) { if(in_array($a->id, $_POST[$formName.$q->id])) { $selectedAnswers .= ((strlen($selectedAnswers) == "0") ? "" : ",").stripslashes($a->answer); } } } if(!empty($selectedAnswers)) { $wpdb->insert(ATTENDEE_ANSWERS, array("attendeeID" => $attendeeID, "answer" => stripslashes($selectedAnswers), "questionID" => $q->id), array('%d', '%s', '%d')); } } else if (($q->questionType == QT_DROP) || ($q->questionType == QT_RADIO)) { $aRs = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $q->id)); if(count($aRs) > 0) { foreach($aRs as $a) { if($a->id == $_POST[$formName.$q->id]) { $wpdb->insert(ATTENDEE_ANSWERS, array("attendeeID" => $attendeeID, "answer" => stripslashes($a->answer), "questionID" => $q->id), array('%d', '%s', '%d')); break; } } } } else { $wpdb->insert(ATTENDEE_ANSWERS, array("attendeeID" => $attendeeID, "answer" => $_POST[$formName.$q->id], "questionID" => $q->id), array('%d', '%s', '%d')); } } } } } function rsvp_frontend_prompt_to_edit($attendee) { $prompt = "

Hi ".htmlentities(utf8_decode(stripslashes($attendee->firstName." ".$attendee->lastName)))." it looks like you have already RSVP'd. Would you like to edit your reservation?

"; $prompt .= "
\r\n id."\" />
\r\n"; return $prompt; } function rsvp_frontend_main_form($attendeeID) { global $wpdb; $attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus, note, kidsMeal, additionalAttendee, veggieMeal, personalGreeting FROM ".ATTENDEES_TABLE." WHERE id = %d", $attendeeID)); $sql = "SELECT id FROM ".ATTENDEES_TABLE." WHERE (id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d) OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d)) AND additionalAttendee = 'Y'"; $newRsvps = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID)); $form = "\r\n"; $form .= ""; $form .= "\r\n"; $form .= "\r\n"; $form .= "
\r\n"; $form .= " \r\n"; $form .= " \r\n"; $form .= "\r\n"; $yesVerbiage = ((trim(get_option(OPTION_YES_VERBIAGE)) != "") ? get_option(OPTION_YES_VERBIAGE) : "Yes, of course I will be there! Who doesn't like family, friends, weddings, and a good time?"); $noVerbiage = ((trim(get_option(OPTION_NO_VERBIAGE)) != "") ? get_option(OPTION_NO_VERBIAGE) : "Um, unfortunately, there is a Star Trek marathon on that day that I just cannot miss."); $kidsVerbiage = ((trim(get_option(OPTION_KIDS_MEAL_VERBIAGE)) != "") ? get_option(OPTION_KIDS_MEAL_VERBIAGE) : "We have the option of getting cheese pizza for the kids (and only kids). Do you want pizza instead of \"adult food?\""); $veggieVerbiage = ((trim(get_option(OPTION_VEGGIE_MEAL_VERBIAGE)) != "") ? get_option(OPTION_VEGGIE_MEAL_VERBIAGE) : "We also have the option of getting individual vegetarian meals instead of the fish or meat. Would you like a vegetarian dinner?"); $noteVerbiage = ((trim(get_option(OPTION_NOTE_VERBIAGE)) != "") ? get_option(OPTION_NOTE_VERBIAGE) : "If you have any food allergies, please indicate what they are in the "notes" section below. Or, if you just want to send us a note, please feel free. If you have any questions, please send us an email."); $form .= " \r\n \r\n \r\n \r\n \r\n "; if(!empty($attendee->personalGreeting)) { $form .= "\r\n \r\n \r\n"; } if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") { $form .= " \r\n \r\n \r\n \r\n "; } if(get_option(OPTION_HIDE_VEGGIE) != "Y") { $form .= " \r\n \r\n \r\n \r\n \r\n"; } $form .= rsvp_buildAdditionalQuestions($attendeeID, "main"); $form .= " \r\n "; $form .= "
So, how about it?
rsvpStatus == "No") ? "" : "checked=\"checked\"")." /> -
rsvpStatus == "No") ? "checked=\"checked\"" : "")." /> -

".nl2br(utf8_decode($attendee->personalGreeting))."


".$kidsVerbiage."
kidsMeal == "Y") ? "checked=\"checked\"" : "")." /> kidsMeal == "Y") ? "" : "checked=\"checked\"")." />


".$veggieVerbiage."
veggieMeal == "Y") ? "checked=\"checked\"" : "")."/> veggieMeal == "Y") ? "" : "checked=\"checked\"")." />

".$noteVerbiage."
\r\n"; $sql = "SELECT id, firstName, lastName FROM ".ATTENDEES_TABLE." WHERE (id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d) OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d)) AND rsvpStatus <> 'NoResponse'"; $rsvpd = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID)); if(count($rsvpd) > 0) { $form .= "

The following people associated with you have already registered: "; foreach($rsvpd as $r) { $form .= "
".htmlentities($r->firstName." ".$r->lastName); } $form .= "

\r\n"; } $sql = "SELECT id, firstName, lastName, personalGreeting FROM ".ATTENDEES_TABLE." WHERE (id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d) OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d)) AND rsvpStatus = 'NoResponse'"; $associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID)); if(count($associations) > 0) { $form .= "

The following people are associated with you. At this time you can RSVP for them as well.

"; foreach($associations as $a) { $form .= "
\r\n

id."\" id=\"rsvpFor".$a->id."\" value=\"Y\" />

"; $form .= "\r\n"; $form .= " \r\n \r\n "; if(!empty($a->personalGreeting)) { $form .= "\r\n \r\n \r\n"; } if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") { $form .= " "; } if(get_option(OPTION_HIDE_VEGGIE) != "Y") { $form .= " "; } $form .= rsvp_buildAdditionalQuestions($a->id, $a->id); $form .= "
Will ".htmlentities(utf8_decode($a->firstName))." be attending?id."\" value=\"Y\" id=\"attending".$a->id."Y\" checked=\"checked\" /> id."\" value=\"N\" id=\"attending".$a->id."N\" />

".nl2br(utf8_decode($a->personalGreeting))."

Does ".htmlentities(utf8_decode($a->firstName))." need a kids meal?  id."KidsMeal\" value=\"Y\" id=\"attending".$a->id."KidsMealY\" /> id."KidsMeal\" value=\"N\" id=\"attending".$a->id."KidsMealN\" checked=\"checked\" />

Does ".htmlentities(utf8_decode($a->firstName))." need a vegetarian meal?  id."VeggieMeal\" value=\"Y\" id=\"attending".$a->id."VeggieMealY\" /> id."VeggieMeal\" value=\"N\" id=\"attending".$a->id."VeggieMealN\" checked=\"checked\" />
\r\n"; $form .= "
\r\n"; } } if(get_option(OPTION_HIDE_ADD_ADDITIONAL) != "Y") { $form .= "

Did we slip up and forget to invite someone? If so, please add him or her here:

\r\n"; $form .= "
\r\n
"; } $form .= "

\r\n"; if(get_option(OPTION_HIDE_ADD_ADDITIONAL) != "Y") { $form .= "\r\n"; } $form .= "
\r\n"; return $form; } function rsvp_revtrievePreviousAnswer($attendeeID, $questionID) { global $wpdb; $answers = ""; if(($attendeeID > 0) && ($questionID > 0)) { $rs = $wpdb->get_results($wpdb->prepare("SELECT answer FROM ".ATTENDEE_ANSWERS." WHERE questionID = %d AND attendeeID = %d", $questionID, $attendeeID)); if(count($rs) > 0) { $answers = stripslashes($rs[0]->answer); } } return $answers; } function rsvp_buildAdditionalQuestions($attendeeID, $prefix) { global $wpdb; $output = ""; $sql = "SELECT q.id, q.question, questionType FROM ".QUESTIONS_TABLE." q INNER JOIN ".QUESTION_TYPE_TABLE." qt ON qt.id = q.questionTypeID WHERE q.permissionLevel = 'public' OR (q.permissionLevel = 'private' AND q.id IN (SELECT questionID FROM ".QUESTION_ATTENDEES_TABLE." WHERE attendeeID = $attendeeID)) ORDER BY q.sortOrder "; $questions = $wpdb->get_results($sql); if(count($questions) > 0) { foreach($questions as $q) { $oldAnswer = rsvp_revtrievePreviousAnswer($attendeeID, $q->id); $output .= "\r\n". "".$q->question."\r\n". ""; if($q->questionType == QT_MULTI) { $oldAnswers = explode(",", $oldAnswer); $output .= "\r\n"; $answers = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $q->id)); if(count($answers) > 0) { $i = 0; $output .= "\r\n"; foreach($answers as $a) { if($i % 3 == 0) { $output .= ""; } $output .= "\r\n"; $i++; } $output .= "\r\n"; } $output .= "
id."[]\" id=\"".$prefix."question".$q->id.$a->id."\" value=\"".$a->id."\" " .((in_array(stripslashes($a->answer), $oldAnswers)) ? " checked=\"checked\"" : "")." />". "
\r\n"; } else if ($q->questionType == QT_DROP) { $oldAnswers = explode(",", $oldAnswer); $output .= "\r\n"; } else if ($q->questionType == QT_LONG) { $output .= ""; } else if ($q->questionType == QT_RADIO) { $oldAnswers = explode(",", $oldAnswer); $output .= "\r\n"; $answers = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $q->id)); if(count($answers) > 0) { $i = 0; $output .= "\r\n"; foreach($answers as $a) { if($i % 3 == 0) { $output .= ""; } $output .= "\r\n"; $i++; } $output .= "\r\n"; } $output .= "
id."\" id=\"".$prefix."question".$q->id.$a->id."\" value=\"".$a->id."\" " .((in_array(stripslashes($a->answer), $oldAnswers)) ? " checked=\"checked\"" : "")." /> ". "
\r\n"; } else { // normal text input $output .= "id."\" value=\"".htmlentities($oldAnswer)."\" size=\"25\" />"; } $output .= "\r\n". "\r\n"; } } return $output; } function frontend_rsvp_thankyou() { $customTy = get_option(OPTION_THANKYOU); if(!empty($customTy)) { return nl2br($customTy); } else { return "

Thank you for RSVPing

"; } } function rsvp_chomp_name($name, $maxLength) { for($i = $maxLength; $maxLength >= 1; $i--) { if(strlen($name) >= $i) { return substr($name, 0, $i); } } } function rsvp_frontend_greeting() { $customGreeting = get_option(OPTION_GREETING); $output = "

Please enter your first and last name to RSVP.

"; $firstName = ""; $lastName = ""; if(isset($_SESSION['rsvpFirstName'])) { $firstName = $_SESSION['rsvpFirstName']; } if(isset($_SESSION['rsvpLastName'])) { $lastName = $_SESSION['rsvpLastName']; } if(!empty($customGreeting)) { $output = nl2br($customGreeting); } $output .= ""; $output .= ""; $output .= ""; $output .= "\r\n"; $output .= "
\r\n"; $output .= " "; $output .= "

\r\n"; $output .= "

\r\n"; $output .= "

"; $output .= "
\r\n"; return $output; } ?>