".__("A first and last name must be specified", 'rsvp-plugin')."
\r\n";
$output .= rsvp_frontend_greeting();
return rsvp_handle_output($text, $output);
}
// Try to find the user.
if($passcodeOptionEnabled) {
$attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus
FROM ".ATTENDEES_TABLE."
WHERE firstName = %s AND lastName = %s AND passcode = %s", $firstName, $lastName, $passcode));
} else {
$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 .= RSVP_START_PARA."Hi ".htmlentities(stripslashes($attendee->firstName." ".$attendee->lastName))."!".RSVP_END_PARA;
if(trim(get_option(OPTION_WELCOME_TEXT)) != "") {
$output .= RSVP_START_PARA.trim(get_option(OPTION_WELCOME_TEXT)).RSVP_END_PARA;
} else {
$output .= RSVP_START_PARA.__("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.", 'rsvp-plugin').RSVP_END_PARA;
}
$output .= rsvp_frontend_main_form($attendee->id);
} else {
$output .= rsvp_frontend_prompt_to_edit($attendee);
}
return rsvp_handle_output($text, $output."
\r\n");
}
// We did not find anyone let's try and do a rough search
$attendees = null;
if(!$passcodeOptionEnabled) {
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 = RSVP_START_PARA."".__("We could not find an exact match but could any of the below entries be you?", 'rsvp-plugin')."".RSVP_END_PARA;
foreach($attendees as $a) {
$output .= "\r\n";
}
return rsvp_handle_output($text, $output);
} else {
$i = strlen($truncFirstName);
}
}
}
$notFoundText = sprintf(__(RSVP_START_PARA.'We were unable to find anyone with a name of %1$s %2$s'.RSVP_END_PARA, 'rsvp-plugin'), htmlentities($firstName), htmlentities($lastName));
$notFoundText .= rsvp_frontend_greeting();
return rsvp_handle_output($text, $notFoundText);
}
function rsvp_handlersvp(&$output, &$text) {
global $wpdb;
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['rsvp_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_printQueryDebugInfo();
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_printQueryDebugInfo();
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'));
rsvp_printQueryDebugInfo();
$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"));
rsvp_printQueryDebugInfo();
$wpdb->query($wpdb->prepare("INSERT INTO ".ASSOCIATED_ATTENDEES_TABLE."(attendeeID, associatedAttendeeID)
SELECT ".$newAid.", associatedAttendeeID
FROM ".ASSOCIATED_ATTENDEES_TABLE."
WHERE attendeeID = ".$attendeeID));
rsvp_printQueryDebugInfo();
}
}
}
}
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 rsvp_handle_output($text, frontend_rsvp_thankyou());
} else {
return rsvp_handle_output($text, rsvp_frontend_greeting());
}
}
function rsvp_editAttendee(&$output, &$text) {
global $wpdb;
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 .= RSVP_START_CONTAINER;
$output .= RSVP_START_PARA.__("Welcome back", 'rsvp-plugin')." ".htmlentities($attendee->firstName." ".$attendee->lastName)."!".RSVP_END_PARA;
$output .= rsvp_frontend_main_form($attendee->id);
return rsvp_handle_output($text, $output.RSVP_END_CONTAINER);
}
}
}
function rsvp_foundAttendee(&$output, &$text) {
global $wpdb;
if(is_numeric($_POST['attendeeID']) && ($_POST['attendeeID'] > 0)) {
$attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus
FROM ".ATTENDEES_TABLE."
WHERE id = %d", $_POST['attendeeID']));
if($attendee != null) {
$output = RSVP_START_CONTAINER;
if(strtolower($attendee->rsvpStatus) == "noresponse") {
$output .= RSVP_START_PARA.__("Hi", 'rsvp-plugin')." ".htmlentities(stripslashes($attendee->firstName." ".$attendee->lastName))."!".RSVP_END_PARA;
if(trim(get_option(OPTION_WELCOME_TEXT)) != "") {
$output .= RSVP_START_PARA.trim(get_option(OPTION_WELCOME_TEXT)).RSVP_END_PARA;
} else {
$output .= RSVP_START_PARA.__("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.", 'rsvp-plugin').RSVP_END_PARA;
}
$output .= rsvp_frontend_main_form($attendee->id);
} else {
$output .= rsvp_frontend_prompt_to_edit($attendee);
}
return rsvp_handle_output($text, $output.RSVP_END_CONTAINER);
}
return rsvp_handle_output($text, rsvp_frontend_greeting());
} else {
return rsvp_handle_output($text, rsvp_frontend_greeting());
}
}
function frontend_rsvp_thankyou() {
$customTy = get_option(OPTION_THANKYOU);
if(!empty($customTy)) {
return nl2br($customTy);
} else {
return RSVP_START_CONTAINER.RSVP_START_PARA.__("Thank you for RSVPing", 'rsvp-plugin').RSVP_END_PARA.RSVP_END_CONTAINER;
}
}
function rsvp_chomp_name($name, $maxLength) {
for($i = $maxLength; $maxLength >= 1; $i--) {
if(strlen($name) >= $i) {
return substr($name, 0, $i);
}
}
}
function rsvp_BeginningFormField($id, $additionalClasses) {
return "
";
}
function rsvp_frontend_greeting() {
$customGreeting = get_option(OPTION_GREETING);
$output = RSVP_START_PARA.__("Please enter your first and last name to RSVP.", 'rsvp-plugin').RSVP_END_PARA;
$firstName = "";
$lastName = "";
$passcode = "";
if(isset($_SESSION['rsvpFirstName'])) {
$firstName = $_SESSION['rsvpFirstName'];
}
if(isset($_SESSION['rsvpLastName'])) {
$lastName = $_SESSION['rsvpLastName'];
}
if(isset($_SESSION['rsvpPasscode'])) {
$passcode = $_SESSION['rsvpPasscode'];
}
if(!empty($customGreeting)) {
$output = RSVP_START_PARA.nl2br($customGreeting).RSVP_END_PARA;
}
$output .= RSVP_START_CONTAINER;
$output .= "\r\n";
$output .= RSVP_END_CONTAINER;
return $output;
}
?>