PluginProbe
RSVP and Event Management / 1.7.5
RSVP and Event Management v1.7.5
trunk 0.5.0 0.6.0 0.7.0 0.8.0 0.9.0 0.9.5 1.0.0 1.1.0 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.5.0 1.6.0 1.6.1 1.6.2 1.6.5 1.7.0 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 All 136 releases
rsvp / rsvp_frontend.inc.php

rsvp_frontend.inc.php in RSVP and Event Management 1.7.5, at rsvp_frontend.inc.php

955 lines 46.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 $rsvp_form_action = htmlspecialchars(rsvp_getCurrentPageURL());
3
4 if(get_option(OPTION_RSVP_DONT_USE_HASH) != "Y") {
5 $rsvp_form_action .= "#rsvpArea";
6 }
7 $rsvp_saved_form_vars = array();
8 // load some defaults
9 $rsvp_saved_form_vars['mainRsvp'] = "";
10 $rsvp_saved_form_vars['rsvp_note'] = "";
11
12 function rsvp_handle_output ($intialText, $rsvpText) {
13 $rsvpText = "<a name=\"rsvpArea\" id=\"rsvpArea\"></a>".$rsvpText;
14 return str_replace(RSVP_FRONTEND_TEXT_CHECK, $rsvpText, $intialText);
15 }
16
17 function rsvp_frontend_handler($text) {
18 global $wpdb;
19 $passcodeOptionEnabled = (rsvp_require_passcode()) ? true : false;
20 //QUIT if the replacement string doesn't exist
21 if (!strstr($text,RSVP_FRONTEND_TEXT_CHECK)) return $text;
22
23 // See if we should allow people to RSVP, etc...
24 $openDate = get_option(OPTION_OPENDATE);
25 $closeDate = get_option(OPTION_DEADLINE);
26 if((strtotime($openDate) !== false) && (strtotime($openDate) > time())) {
27 return rsvp_handle_output($text, sprintf(__(RSVP_START_PARA."I am sorry but the ability to RSVP for our wedding won't open till <strong>%s</strong>".RSVP_END_PARA, 'rsvp-plugin'), date("m/d/Y", strtotime($openDate))));
28 }
29
30 if((strtotime($closeDate) !== false) && (strtotime($closeDate) < time())) {
31 return rsvp_handle_output($text, __(RSVP_START_PARA."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.".RSVP_END_PARA, 'rsvp-plugin'));
32 }
33
34 if(isset($_POST['rsvpStep'])) {
35 $output = "";
36 switch(strtolower($_POST['rsvpStep'])) {
37 case("newattendee"):
38 return rsvp_handlenewattendee($output, $text);
39 break;
40 case("addattendee"):
41 return rsvp_handleNewRsvp($output, $text);
42 break;
43 case("handlersvp") :
44 $output = rsvp_handlersvp($output, $text);
45 if(!empty($output))
46 return $output;
47 break;
48 case("editattendee") :
49 $output = rsvp_editAttendee($output, $text);
50 if(!empty($output))
51 return $output;
52 break;
53 case("foundattendee") :
54 $output = rsvp_foundAttendee($output, $text);
55 if(!empty($output))
56 return $output;
57 break;
58 case("find") :
59 $output = rsvp_find($output, $text);
60 if(!empty($output))
61 return $output;
62 break;
63 case("newsearch"):
64 default:
65 return rsvp_handle_output($text, rsvp_frontend_greeting());
66 break;
67 }
68 } else {
69 return rsvp_handle_output($text, rsvp_frontend_greeting());
70 }
71 }
72
73 function rsvp_handlenewattendee($output, $text) {
74 $output = RSVP_START_CONTAINER;
75 $output .= rsvp_frontend_main_form(0, "addAttendee");
76 $output .= RSVP_END_CONTAINER;
77
78 return rsvp_handle_output($text, $output);
79 }
80
81 function rsvp_handleAdditionalQuestions($attendeeID, $formName) {
82 global $wpdb;
83
84 $wpdb->query($wpdb->prepare("DELETE FROM ".ATTENDEE_ANSWERS." WHERE attendeeID = %d ", $attendeeID));
85
86 $qRs = $wpdb->get_results("SELECT q.id, questionType FROM ".QUESTIONS_TABLE." q
87 INNER JOIN ".QUESTION_TYPE_TABLE." qt ON qt.id = q.questionTypeID
88 ORDER BY q.sortOrder");
89 if(count($qRs) > 0) {
90 foreach($qRs as $q) {
91 if(isset($_POST[$formName.$q->id]) && !empty($_POST[$formName.$q->id])) {
92 if($q->questionType == QT_MULTI) {
93 $selectedAnswers = "";
94 $aRs = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $q->id));
95 if(count($aRs) > 0) {
96 foreach($aRs as $a) {
97 if(in_array($a->id, $_POST[$formName.$q->id])) {
98 $selectedAnswers .= ((strlen($selectedAnswers) == "0") ? "" : ",").stripslashes($a->answer);
99 }
100 }
101 }
102
103 if(!empty($selectedAnswers)) {
104 $wpdb->insert(ATTENDEE_ANSWERS, array("attendeeID" => $attendeeID,
105 "answer" => stripslashes($selectedAnswers),
106 "questionID" => $q->id),
107 array('%d', '%s', '%d'));
108 rsvp_printQueryDebugInfo();
109 }
110 } else if (($q->questionType == QT_DROP) || ($q->questionType == QT_RADIO)) {
111 $aRs = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $q->id));
112 if(count($aRs) > 0) {
113 foreach($aRs as $a) {
114 if($a->id == $_POST[$formName.$q->id]) {
115 $wpdb->insert(ATTENDEE_ANSWERS, array("attendeeID" => $attendeeID,
116 "answer" => stripslashes($a->answer),
117 "questionID" => $q->id),
118 array('%d', '%s', '%d'));
119 rsvp_printQueryDebugInfo();
120 break;
121 }
122 }
123 }
124 } else {
125 $wpdb->insert(ATTENDEE_ANSWERS, array("attendeeID" => $attendeeID,
126 "answer" => $_POST[$formName.$q->id],
127 "questionID" => $q->id),
128 array('%d', '%s', '%d'));
129 rsvp_printQueryDebugInfo();
130 }
131 }
132 }
133 }
134 }
135
136 function rsvp_frontend_prompt_to_edit($attendee) {
137 global $rsvp_form_action;
138 $prompt = RSVP_START_CONTAINER;
139 $editGreeting = __("Hi %s it looks like you have already RSVP'd. Would you like to edit your reservation?", 'rsvp-plugin');
140 $prompt .= sprintf(RSVP_START_PARA.$editGreeting.RSVP_END_PARA,
141 htmlspecialchars(stripslashes($attendee->firstName." ".$attendee->lastName)));
142 $prompt .= "<form method=\"post\" action=\"$rsvp_form_action\">\r\n
143 <input type=\"hidden\" name=\"attendeeID\" value=\"".$attendee->id."\" />
144 <input type=\"hidden\" name=\"rsvpStep\" id=\"rsvpStep\" value=\"editattendee\" />
145 <input type=\"submit\" value=\"".__("Yes", 'rsvp-plugin')."\" onclick=\"document.getElementById('rsvpStep').value='editattendee';\" />
146 <input type=\"submit\" value=\"".__("No", 'rsvp-plugin')."\" onclick=\"document.getElementById('rsvpStep').value='newsearch';\" />
147 </form>\r\n";
148 $prompt .= RSVP_END_CONTAINER;
149 return $prompt;
150 }
151
152 function rsvp_frontend_main_form($attendeeID, $rsvpStep = "handleRsvp") {
153 global $wpdb, $rsvp_form_action, $rsvp_saved_form_vars;
154 $attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus, note, kidsMeal, additionalAttendee, veggieMeal, personalGreeting
155 FROM ".ATTENDEES_TABLE."
156 WHERE id = %d", $attendeeID));
157 $sql = "SELECT id FROM ".ATTENDEES_TABLE."
158 WHERE (id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
159 OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d))
160 AND additionalAttendee = 'Y'";
161 $newRsvps = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID));
162 $yesText = __("Yes", 'rsvp-plugin');
163 $noText = __("No", 'rsvp-plugin');
164 $yesVerbiage = ((trim(get_option(OPTION_YES_VERBIAGE)) != "") ? get_option(OPTION_YES_VERBIAGE) :
165 __("Yes, of course I will be there! Who doesn't like family, friends, weddings, and a good time?", 'rsvp-plugin'));
166 $noVerbiage = ((trim(get_option(OPTION_NO_VERBIAGE)) != "") ? get_option(OPTION_NO_VERBIAGE) :
167 __("Um, unfortunately, there is a Star Trek marathon on that day that I just cannot miss.", 'rsvp-plugin'));
168 $kidsVerbiage = ((trim(get_option(OPTION_KIDS_MEAL_VERBIAGE)) != "") ? get_option(OPTION_KIDS_MEAL_VERBIAGE) :
169 __("We have the option of getting cheese pizza for the kids (and only kids). Do you want pizza instead of \"adult food?\"", 'rsvp-plugin'));
170 $veggieVerbiage = ((trim(get_option(OPTION_VEGGIE_MEAL_VERBIAGE)) != "") ? get_option(OPTION_VEGGIE_MEAL_VERBIAGE) :
171 __("We also have the option of getting individual vegetarian meals instead of the fish or meat. Would you like a vegetarian dinner?", 'rsvp-plugin'));
172 $noteVerbiage = ((trim(get_option(OPTION_NOTE_VERBIAGE)) != "") ? get_option(OPTION_NOTE_VERBIAGE) :
173 __("If you have any <strong style=\"color:red;\">food allergies</strong>, please indicate what they are in the &quot;notes&quot; 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.", 'rsvp-plugin'));
174
175 $form = "<form id=\"rsvpForm\" name=\"rsvpForm\" method=\"post\" action=\"$rsvp_form_action\" autocomplete=\"off\">\r\n";
176 $form .= " <input type=\"hidden\" name=\"attendeeID\" value=\"".$attendeeID."\" />\r\n";
177 $form .= " <input type=\"hidden\" name=\"rsvpStep\" value=\"$rsvpStep\" />\r\n";
178
179 // New Attendee fields when open registration is allowed
180 if($attendeeID <= 0) {
181 $form .= RSVP_START_PARA;
182 $form .= rsvp_BeginningFormField("", "").
183 "<label for=\"attendeeFirstName\">".__("First Name: ", 'rsvp-plugin')."</label>".
184 "<input type=\"text\" name=\"attendeeFirstName\" id=\"attendeeFirstName\" value=\"".htmlspecialchars($rsvp_saved_form_vars['attendeeFirstName'])."\" />".
185 RSVP_END_FORM_FIELD;
186 $form .= RSVP_END_PARA;
187
188 $form .= RSVP_START_PARA;
189 $form .= rsvp_BeginningFormField("", "").
190 "<label for=\"attendeeLastName\">".__("Last Name: ", 'rsvp-plugin')."</label>".
191 "<input type=\"text\" name=\"attendeeLastName\" id=\"attendeeLastName\" value=\"".htmlspecialchars($rsvp_saved_form_vars['attendeeLastName'])."\" />".
192 RSVP_END_FORM_FIELD;
193 $form .= RSVP_END_PARA;
194 }
195
196 $form .= RSVP_START_PARA;
197 if(trim(get_option(OPTION_RSVP_QUESTION)) != "") {
198 $form .= trim(get_option(OPTION_RSVP_QUESTION));
199 } else {
200 $form .= __("So, how about it?", 'rsvp-plugin');
201 }
202
203 $form .= RSVP_END_PARA.
204 rsvp_BeginningFormField("", "").
205 "<input type=\"radio\" name=\"mainRsvp\" value=\"Y\" id=\"mainRsvpY\" ".((($attendee->rsvpStatus == "No") || ($rsvp_saved_form_vars['mainRsvp'] == "N")) ? "" : "checked=\"checked\"")." /> <label for=\"mainRsvpY\">".$yesVerbiage."</label>".
206 RSVP_END_FORM_FIELD.
207 rsvp_BeginningFormField("", "").
208 "<input type=\"radio\" name=\"mainRsvp\" value=\"N\" id=\"mainRsvpN\" ".((($attendee->rsvpStatus == "No") || ($rsvp_saved_form_vars['mainRsvp'] == "N")) ? "checked=\"checked\"" : "")." /> ".
209 "<label for=\"mainRsvpN\">".$noVerbiage."</label>".
210 RSVP_END_FORM_FIELD;
211 if(!empty($attendee->personalGreeting)) {
212 $form .= rsvp_BeginningFormField("rsvpCustomGreeting", "").nl2br(stripslashes($attendee->personalGreeting)).RSVP_END_FORM_FIELD;
213 }
214 if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {
215 $form .= rsvp_BeginningFormField("", "rsvpBorderTop").
216 RSVP_START_PARA.$kidsVerbiage.RSVP_END_PARA.
217 "<input type=\"radio\" name=\"mainKidsMeal\" value=\"Y\" id=\"mainKidsMealY\" ".
218 ((($attendee->kidsMeal == "Y") || ($rsvp_saved_form_vars['mainKidsMeal'] == "Y")) ? "checked=\"checked\"" : "")." /> <label for=\"mainKidsMealY\">$yesText</label> ".
219 "<input type=\"radio\" name=\"mainKidsMeal\" value=\"N\" id=\"mainKidsMealN\" ".((($attendee->kidsMeal == "Y") || ($rsvp_saved_form_vars['mainKidsMeal'] == "Y")) ? "" : "checked=\"checked\"")." /> <label for=\"mainKidsMealN\">$noText</label>".
220 RSVP_END_FORM_FIELD;
221 }
222
223 if(get_option(OPTION_HIDE_VEGGIE) != "Y") {
224 $form .= rsvp_BeginningFormField("", "rsvpBorderTop").
225 RSVP_START_PARA.$veggieVerbiage.RSVP_END_PARA.
226 "<input type=\"radio\" name=\"mainVeggieMeal\" value=\"Y\" id=\"mainVeggieMealY\" ".
227 ((($attendee->veggieMeal == "Y") || ($rsvp_saved_form_vars['mainVeggieMeal'] == "Y")) ? "checked=\"checked\"" : "")."/> <label for=\"mainVeggieMealY\">$yesText</label> ".
228 "<input type=\"radio\" name=\"mainVeggieMeal\" value=\"N\" id=\"mainVeggieMealN\" ".
229 ((($attendee->veggieMeal == "Y") || ($rsvp_saved_form_vars['mainVeggieMeal'] == "Y")) ? "" : "checked=\"checked\"")." /> <label for=\"mainVeggieMealN\">$noText</label>".
230 RSVP_END_FORM_FIELD;
231 }
232
233 $form .= rsvp_buildAdditionalQuestions($attendeeID, "main");
234
235 if(get_option(RSVP_OPTION_HIDE_NOTE) != "Y") {
236 $form .= RSVP_START_PARA.$noteVerbiage.RSVP_END_PARA.
237 rsvp_BeginningFormField("", "").
238 "<textarea name=\"rsvp_note\" id=\"rsvp_note\" rows=\"7\" cols=\"50\">".((!empty($attendee->note)) ? $attendee->note : $rsvp_saved_form_vars['rsvp_note'])."</textarea>".RSVP_END_FORM_FIELD;
239
240 }
241 $sql = "SELECT id, firstName, lastName FROM ".ATTENDEES_TABLE."
242 WHERE (id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
243 OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d) OR
244 id IN (SELECT waa1.attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." waa1
245 INNER JOIN ".ASSOCIATED_ATTENDEES_TABLE." waa2 ON waa2.attendeeID = waa1.attendeeID OR
246 waa1.associatedAttendeeID = waa2.attendeeID
247 WHERE waa2.associatedAttendeeID = %d AND waa1.attendeeID <> %d))
248 AND rsvpStatus <> 'NoResponse'";
249 $rsvpd = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID, $attendeeID, $attendeeID));
250 if(count($rsvpd) > 0) {
251 $form .= "<div class=\"rsvpAdditionalAttendee\">\r\n";
252 $form .= RSVP_START_PARA.__("The following people associated with you have already registered:", 'rsvp-plugin')." ";
253 foreach($rsvpd as $r) {
254 $form .= "<br />".htmlspecialchars($r->firstName." ".$r->lastName);
255 }
256 $form .= RSVP_END_PARA;
257 $form .= "</div>";
258 }
259
260 $sql = "SELECT id, firstName, lastName, personalGreeting FROM ".ATTENDEES_TABLE."
261 WHERE (id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
262 OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d) OR
263 id IN (SELECT waa1.attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." waa1
264 INNER JOIN ".ASSOCIATED_ATTENDEES_TABLE." waa2 ON waa2.attendeeID = waa1.attendeeID OR
265 waa1.associatedAttendeeID = waa2.attendeeID
266 WHERE waa2.associatedAttendeeID = %d AND waa1.attendeeID <> %d))
267 AND rsvpStatus = 'NoResponse'";
268
269 $associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID, $attendeeID, $attendeeID));
270 if(count($associations) > 0) {
271 $form .= "<h3>".__("The following people are associated with you. At this time you can RSVP for them as well.", 'rsvp-plugin')."</h3>";
272 foreach($associations as $a) {
273 if($a->id != $attendeeID) {
274 $form .= "<div class=\"rsvpAdditionalAttendee\">\r\n";
275 $form .= "<div class=\"rsvpAdditionalAttendeeQuestions\">\r\n";
276 $form .= rsvp_BeginningFormField("", "").sprintf(__(" Will %s be attending?", 'rsvp-plugin'), htmlspecialchars($a->firstName)).
277 "<input type=\"radio\" name=\"attending".$a->id."\" value=\"Y\" id=\"attending".$a->id."Y\" /> ".
278 "<label for=\"attending".$a->id."Y\">$yesText</label>
279 <input type=\"radio\" name=\"attending".$a->id."\" value=\"N\" id=\"attending".$a->id."N\" /> ".
280 "<label for=\"attending".$a->id."N\">$noText</label>".
281 RSVP_END_FORM_FIELD;
282
283 if(!empty($a->personalGreeting)) {
284 $form .= RSVP_START_PARA.nl2br($a->personalGreeting).RSVP_END_PARA;
285 }
286
287 if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {
288 $form .= rsvp_BeginningFormField("", "").
289 sprintf(__("Does %s need a kids meal?", 'rsvp-plugin'), htmlspecialchars($a->firstName))."&nbsp; ".
290 "<input type=\"radio\" name=\"attending".$a->id."KidsMeal\" value=\"Y\" id=\"attending".$a->id."KidsMealY\" /> ".
291 "<label for=\"attending".$a->id."KidsMealY\">$yesText</label>
292 <input type=\"radio\" name=\"attending".$a->id."KidsMeal\" value=\"N\" id=\"attending".$a->id."KidsMealN\" checked=\"checked\" /> ".
293 "<label for=\"attending".$a->id."KidsMealN\">$noText</label>".RSVP_END_FORM_FIELD;
294 }
295
296 if(get_option(OPTION_HIDE_VEGGIE) != "Y") {
297 $form .= rsvp_BeginningFormField("", "").
298 sprintf(__("Does %s need a vegetarian meal?", 'rsvp-plugin'), htmlspecialchars($a->firstName))."&nbsp; ".
299 "<input type=\"radio\" name=\"attending".$a->id."VeggieMeal\" value=\"Y\" id=\"attending".$a->id."VeggieMealY\" /> ".
300 "<label for=\"attending".$a->id."VeggieMealY\">$yesText</label>
301 <input type=\"radio\" name=\"attending".$a->id."VeggieMeal\" value=\"N\" id=\"attending".$a->id."VeggieMealN\" checked=\"checked\" /> ".
302 "<label for=\"attending".$a->id."VeggieMealN\">$noText</label>".RSVP_END_FORM_FIELD;
303 }
304
305 $form .= rsvp_buildAdditionalQuestions($a->id, $a->id);
306 $form .= "</div>\r\n"; //-- rsvpAdditionalAttendeeQuestions
307 $form .= "</div>\r\n";
308 } // if($a->id != ...)
309 } // foreach($associations...)
310 }
311
312 if(get_option(OPTION_HIDE_ADD_ADDITIONAL) != "Y") {
313 $text = __("Did we slip up and forget to invite someone? If so, please add him or her here:", 'rsvp-plugin');
314
315 if(trim(get_option(OPTION_RSVP_ADD_ADDITIONAL_VERBIAGE)) != "") {
316 $text = get_option(OPTION_RSVP_ADD_ADDITIONAL_VERBIAGE);
317 }
318
319 $form .= "<h3>$text</h3>\r\n";
320 $form .= "<div id=\"additionalRsvpContainer\">\r\n
321 <input type=\"hidden\" name=\"additionalRsvp\" id=\"additionalRsvp\" value=\"".count($newRsvps)."\" />
322 <div style=\"text-align:right\"><img ".
323 "src=\"".get_option("siteurl")."/wp-content/plugins/rsvp/plus.png\" width=\"24\" height=\"24\" border=\"0\" id=\"addRsvp\" /></div>".
324 "</div>";
325 }
326
327 $form .= RSVP_START_PARA."<input type=\"submit\" value=\"RSVP\" />".RSVP_END_PARA;
328 if(get_option(OPTION_HIDE_ADD_ADDITIONAL) != "Y") {
329 // TODO: Need to move this into the main JS file but not sure how to do that with the options and the custom questions.
330 // - Moving the options would be fairly easy. Just set two JS variables in here and then go off of that.
331 // - No clue on custom questions....
332 $form .= "<script type=\"text/javascript\" language=\"javascript\">\r\n
333 function handleAddRsvpClick() {
334 var numAdditional = jQuery(\"#additionalRsvp\").val();
335 numAdditional++;
336 if(numAdditional > 3) {
337 alert('".__("You have already added 3 additional rsvp\'s you can add no more.", 'rsvp-plugin')."');
338 } else {
339 jQuery(\"#additionalRsvpContainer\").append(\"<div class=\\\"rsvpAdditionalAttendee\\\">\" + \r\n
340 \"<div class=\\\"rsvpAdditionalAttendeeQuestions\\\">\" + \r\n
341 \"<div class=\\\"rsvpFormField\\\">\" + \r\n
342 \" <label for=\\\"newAttending\" + numAdditional + \"FirstName\\\">".__("Person's first name", 'rsvp-plugin')."&nbsp;</label>\" + \r\n
343 \" <input type=\\\"text\\\" name=\\\"newAttending\" + numAdditional + \"FirstName\\\" id=\\\"newAttending\" + numAdditional + \"FirstName\\\" />\" + \r\n
344 \"</div>\" + \r\n
345 \"<div class=\\\"rsvpFormField\\\">\" + \r\n
346 \" <label for=\\\"newAttending\" + numAdditional + \"LastName\\\">".__("Person's last name", 'rsvp-plugin')."</label>\" + \r\n
347 \" <input type=\\\"text\\\" name=\\\"newAttending\" + numAdditional + \"LastName\\\" id=\\\"newAttending\" + numAdditional + \"LastName\\\" />\" + \r\n
348 \"</div>\" + \r\n
349 \"<div class=\\\"rsvpFormField\\\">\" + \r\n
350 \"Will this person be attending?&nbsp;\" + \r\n
351 \"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"\\\" value=\\\"Y\\\" id=\\\"newAttending\" + numAdditional + \"Y\\\" checked=\\\"checked\\\" /> \" +
352 \"<label for=\\\"newAttending\" + numAdditional + \"Y\\\">$yesText</label> \" +
353 \"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"\\\" value=\\\"N\\\" id=\\\"newAttending\" + numAdditional + \"N\\\"> <label for=\\\"newAttending\" + numAdditional + \"N\\\">$noText</label>\" +
354 \"</div>\" + \r\n";
355 if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {
356 $form .= "\"<div class=\\\"rsvpFormField\\\">\" +
357 \"".__("Does this person need a kids meal?", 'rsvp-plugin')."&nbsp; \" +
358 \"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"KidsMeal\\\" value=\\\"Y\\\" id=\\\"newAttending\" + numAdditional + \"KidsMealY\\\" /> \" +
359 \"<label for=\\\"newAttending\" + numAdditional + \"KidsMealY\\\">$yesText</label> \" +
360 \"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"KidsMeal\\\" value=\\\"N\\\" id=\\\"newAttending\" + numAdditional + \"KidsMealN\\\" checked=\\\"checked\\\" /> \" +
361 \"<label for=\\\"newAttending\" + numAdditional + \"KidsMealN\\\">$noText</label>\" +
362 \"</div>\" +
363 \"</div>\" + \r\n";
364 }
365 if(get_option(OPTION_HIDE_VEGGIE) != "Y") {
366 $form .= "\"<div class=\\\"rsvpFormField\\\">\" + \r\n
367 \"".__("Does this person need a vegetarian meal?", 'rsvp-plugin')."&nbsp; \" +
368 \"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"VeggieMeal\\\" value=\\\"Y\\\" id=\\\"newAttending\" + numAdditional + \"VeggieMealY\\\" /> \" +
369 \"<label for=\\\"newAttending\" + numAdditional + \"VeggieMealY\\\">$yesText</label> \" +
370 \"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"VeggieMeal\\\" value=\\\"N\\\" id=\\\"newAttending\" + numAdditional + \"VeggieMealN\\\" checked=\\\"checked\\\" /> \" +
371 \"<label for=\\\"newAttending\" + numAdditional + \"VeggieMealN\\\">$noText</label>\" +
372 \"</div>\" + ";
373 }
374 $tmpVar = str_replace("\r\n", "", str_replace("|", "\"", addSlashes(rsvp_buildAdditionalQuestions(0, "| + numAdditional + |"))));
375
376 $form .= "\"".$tmpVar."\" +
377 \"</div>\");
378 jQuery(\"#additionalRsvp\").val(numAdditional);
379 }
380 }
381 </script>\r\n";
382 }
383 $form .= "</form>\r\n";
384
385 return $form;
386 }
387
388 function rsvp_revtrievePreviousAnswer($attendeeID, $questionID) {
389 global $wpdb;
390 $answers = "";
391 if(($attendeeID > 0) && ($questionID > 0)) {
392 $rs = $wpdb->get_results($wpdb->prepare("SELECT answer FROM ".ATTENDEE_ANSWERS." WHERE questionID = %d AND attendeeID = %d", $questionID, $attendeeID));
393 if(count($rs) > 0) {
394 $answers = stripslashes($rs[0]->answer);
395 }
396 }
397
398 return $answers;
399 }
400
401 function rsvp_buildAdditionalQuestions($attendeeID, $prefix) {
402 global $wpdb, $rsvp_saved_form_vars;
403 $output = "";
404
405 $sql = "SELECT q.id, q.question, questionType FROM ".QUESTIONS_TABLE." q
406 INNER JOIN ".QUESTION_TYPE_TABLE." qt ON qt.id = q.questionTypeID
407 WHERE q.permissionLevel = 'public'
408 OR (q.permissionLevel = 'private' AND q.id IN (SELECT questionID FROM ".QUESTION_ATTENDEES_TABLE." WHERE attendeeID = $attendeeID))
409 ORDER BY q.sortOrder ";
410 $questions = $wpdb->get_results($sql);
411 if(count($questions) > 0) {
412 foreach($questions as $q) {
413 $oldAnswer = rsvp_revtrievePreviousAnswer($attendeeID, $q->id);
414
415 $output .= rsvp_BeginningFormField("", "").RSVP_START_PARA.stripslashes($q->question).RSVP_END_PARA;
416
417 if($q->questionType == QT_MULTI) {
418 $oldAnswers = explode(",", $oldAnswer);
419
420 $answers = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $q->id));
421 if(count($answers) > 0) {
422 $i = 0;
423 foreach($answers as $a) {
424 $output .= rsvp_BeginningFormField("", "rsvpCheckboxCustomQ")."<input type=\"checkbox\" name=\"".$prefix."question".$q->id."[]\" id=\"".$prefix."question".$q->id.$a->id."\" value=\"".$a->id."\" "
425 .((in_array(stripslashes($a->answer), $oldAnswers)) ? " checked=\"checked\"" : "")." />".
426 "<label for=\"".$prefix."question".$q->id.$a->id."\">".stripslashes($a->answer)."</label>\r\n".RSVP_END_FORM_FIELD;
427 $i++;
428 }
429 $output .= "<div class=\"rsvpClear\">&nbsp;</div>\r\n";
430 }
431 } else if ($q->questionType == QT_DROP) {
432 $oldAnswers = explode(",", $oldAnswer);
433
434 $output .= "<select name=\"".$prefix."question".$q->id."\" size=\"1\">\r\n".
435 "<option value=\"\">--</option>\r\n";
436 $answers = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $q->id));
437 if(count($answers) > 0) {
438 foreach($answers as $a) {
439 $output .= "<option value=\"".$a->id."\" ".((in_array(stripslashes($a->answer), $oldAnswers)) ? " selected=\"selected\"" : "").">".stripslashes($a->answer)."</option>\r\n";
440 }
441 }
442 $output .= "</select>\r\n";
443 } else if ($q->questionType == QT_LONG) {
444 $output .= "<textarea name=\"".$prefix."question".$q->id."\" rows=\"5\" cols=\"35\">".htmlspecialchars($oldAnswer)."</textarea>";
445 } else if ($q->questionType == QT_RADIO) {
446 $oldAnswers = explode(",", $oldAnswer);
447 $answers = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $q->id));
448 if(count($answers) > 0) {
449 $i = 0;
450 $output .= RSVP_START_PARA;
451 foreach($answers as $a) {
452 $output .= "<input type=\"radio\" name=\"".$prefix."question".$q->id."\" id=\"".$prefix."question".$q->id.$a->id."\" value=\"".$a->id."\" "
453 .((in_array(stripslashes($a->answer), $oldAnswers)) ? " checked=\"checked\"" : "")." /> ".
454 "<label for=\"".$prefix."question".$q->id.$a->id."\">".stripslashes($a->answer)."</label>\r\n";
455 $i++;
456 }
457 $output .= RSVP_END_PARA;
458 }
459 } else {
460 // normal text input
461 $output .= "<input type=\"text\" name=\"".$prefix."question".$q->id."\" value=\"".htmlspecialchars($oldAnswer)."\" size=\"25\" />";
462 }
463
464 $output .= RSVP_END_FORM_FIELD;
465 }
466 }
467
468 return $output;
469 }
470
471 function rsvp_find(&$output, &$text) {
472 global $wpdb, $rsvp_form_action;
473 $passcodeOptionEnabled = (rsvp_require_passcode()) ? true : false;
474
475 $_SESSION['rsvpFirstName'] = $_POST['firstName'];
476 $_SESSION['rsvpLastName'] = $_POST['lastName'];
477 $passcode = "";
478 if(isset($_POST['passcode'])) {
479 $passcode = $_POST['passcode'];
480 $_SESSION['rsvpPasscode'] = $_POST['passcode'];
481 }
482
483 $firstName = $_POST['firstName'];
484 $lastName = $_POST['lastName'];
485
486 if((strlen($_POST['firstName']) <= 1) || (strlen($_POST['lastName']) <= 1)) {
487 $output = "<p class=\"rsvpParagraph\" style=\"color:red\">".__("A first and last name must be specified", 'rsvp-plugin')."</p>\r\n";
488 $output .= rsvp_frontend_greeting();
489
490 return rsvp_handle_output($text, $output);
491 }
492
493 // Try to find the user.
494 if($passcodeOptionEnabled) {
495 $attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus
496 FROM ".ATTENDEES_TABLE."
497 WHERE firstName = %s AND lastName = %s AND passcode = %s", $firstName, $lastName, $passcode));
498 } else {
499 $attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus
500 FROM ".ATTENDEES_TABLE."
501 WHERE firstName = %s AND lastName = %s", $firstName, $lastName));
502 }
503
504 if($attendee != null) {
505 // hey we found something, we should move on and print out any associated users and let them rsvp
506 $output = "<div>\r\n";
507 if(strtolower($attendee->rsvpStatus) == "noresponse") {
508 $output .= RSVP_START_PARA."Hi ".htmlspecialchars(stripslashes($attendee->firstName." ".$attendee->lastName))."!".RSVP_END_PARA;
509
510 if(trim(get_option(OPTION_WELCOME_TEXT)) != "") {
511 $output .= RSVP_START_PARA.trim(get_option(OPTION_WELCOME_TEXT)).RSVP_END_PARA;
512 } else {
513 $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;
514 }
515
516 $output .= rsvp_frontend_main_form($attendee->id);
517 } else {
518 $output .= rsvp_frontend_prompt_to_edit($attendee);
519 }
520 return rsvp_handle_output($text, $output."</div>\r\n");
521 }
522
523 // We did not find anyone let's try and do a rough search
524 $attendees = null;
525 if(!$passcodeOptionEnabled) {
526 for($i = 3; $i >= 1; $i--) {
527 $truncFirstName = rsvp_chomp_name($firstName, $i);
528 $attendees = $wpdb->get_results("SELECT id, firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE."
529 WHERE lastName = '".mysql_real_escape_string($lastName)."' AND firstName LIKE '".mysql_real_escape_string($truncFirstName)."%'");
530 if(count($attendees) > 0) {
531 $output = RSVP_START_PARA."<strong>".__("We could not find an exact match but could any of the below entries be you?", 'rsvp-plugin')."</strong>".RSVP_END_PARA;
532 foreach($attendees as $a) {
533 $output .= "<form method=\"post\" action=\"$rsvp_form_action\">\r\n
534 <input type=\"hidden\" name=\"rsvpStep\" value=\"foundattendee\" />\r\n
535 <input type=\"hidden\" name=\"attendeeID\" value=\"".$a->id."\" />\r\n
536 <p class=\"rsvpParagraph\" style=\"text-align:left;\">\r\n
537 ".htmlspecialchars($a->firstName." ".$a->lastName)."
538 <input type=\"submit\" value=\"RSVP\" />\r\n
539 </p>\r\n</form>\r\n";
540 }
541 return rsvp_handle_output($text, $output);
542 } else {
543 $i = strlen($truncFirstName);
544 }
545 }
546 }
547 $notFoundText = sprintf(__(RSVP_START_PARA.'<strong>We were unable to find anyone with a name of %1$s %2$s</strong>'.RSVP_END_PARA, 'rsvp-plugin'), htmlspecialchars($firstName), htmlspecialchars($lastName));
548 $notFoundText .= rsvp_frontend_greeting();
549 return rsvp_handle_output($text, $notFoundText);
550 }
551
552 function rsvp_handleNewRsvp(&$output, &$text) {
553 global $wpdb, $rsvp_saved_form_vars;
554 $thankYouPrimary = "";
555 $thankYouAssociated = array();
556 foreach($_POST as $key=>$val) {
557 $rsvp_saved_form_vars[$key] = $val;
558 }
559
560 if(empty($_POST['attendeeFirstName']) || empty($_POST['attendeeLastName'])) {
561 return rsvp_handlenewattendee($output, $text);
562 }
563
564 $rsvpPassword = "";
565 $rsvpStatus = "No";
566 if(strToUpper($_POST['mainRsvp']) == "Y") {
567 $rsvpStatus = "Yes";
568 }
569 $kidsMeal = ((isset($_POST['mainKidsMeal']) && (strToUpper($_POST['mainKidsMeal']) == "Y")) ? "Y" : "N");
570 $veggieMeal = ((isset($_POST['mainVeggieMeal']) && (strToUpper($_POST['mainVeggieMeal']) == "Y")) ? "Y" : "N");
571 $thankYouPrimary = $_POST['attendeeFirstName'];
572 $wpdb->insert(ATTENDEES_TABLE, array("rsvpDate" => date("Y-m-d"),
573 "firstName" => $_POST['attendeeFirstName'],
574 "lastName" => $_POST['attendeeLastName'],
575 "rsvpStatus" => $rsvpStatus,
576 "note" => $_POST['rsvp_note'],
577 "kidsMeal" => $kidsMeal,
578 "veggieMeal" => $veggieMeal),
579 array("%s", "%s", "%s", "%s", "%s", "%s", "%s"));
580 rsvp_printQueryDebugInfo();
581 $attendeeID = $wpdb->insert_id;
582
583 if(rsvp_require_passcode()) {
584 $rsvpPassword = trim(rsvp_generate_passcode());
585 $wpdb->update(ATTENDEES_TABLE,
586 array("passcode" => $rsvpPassword),
587 array("id"=>$attendeeID),
588 array("%s"),
589 array("%d"));
590 }
591
592 rsvp_handleAdditionalQuestions($attendeeID, "mainquestion");
593
594 $sql = "SELECT id, firstName FROM ".ATTENDEES_TABLE."
595 WHERE (id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
596 OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d))
597 AND rsvpStatus = 'NoResponse'";
598 $associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID));
599 foreach($associations as $a) {
600 if(isset($_POST['attending'.$a->id]) && (($_POST['attending'.$a->id] == "Y") || ($_POST['attending'.$a->id] == "N"))) {
601 if($_POST['attending'.$a->id] == "Y") {
602 $rsvpStatus = "Yes";
603 } else {
604 $rsvpStatus = "No";
605 }
606 $thankYouAssociated[] = stripslashes($a->firstName);
607 $wpdb->update(ATTENDEES_TABLE, array("rsvpDate" => date("Y-m-d"),
608 "rsvpStatus" => $rsvpStatus,
609 "kidsMeal" => ((strToUpper((isset($_POST['attending'.$a->id.'KidsMeal']) ? $_POST['attending'.$a->id.'KidsMeal'] : "N")) == "Y") ? "Y" : "N"),
610 "veggieMeal" => ((strToUpper((isset($_POST['attending'.$a->id.'VeggieMeal']) ? $_POST['attending'.$a->id.'VeggieMeal'] : "N")) == "Y") ? "Y" : "N")),
611 array("id" => $a->id),
612 array("%s", "%s", "%s", "%s"),
613 array("%d"));
614 rsvp_printQueryDebugInfo();
615 rsvp_handleAdditionalQuestions($a->id, $a->id."question");
616 }
617 }
618
619 if(get_option(OPTION_HIDE_ADD_ADDITIONAL) != "Y") {
620 if(is_numeric($_POST['additionalRsvp']) && ($_POST['additionalRsvp'] > 0)) {
621 for($i = 1; $i <= $_POST['additionalRsvp']; $i++) {
622 if(($i <= 3) &&
623 !empty($_POST['newAttending'.$i.'FirstName']) &&
624 !empty($_POST['newAttending'.$i.'LastName'])) {
625 $thankYouAssociated[] = $_POST['newAttending'.$i.'FirstName'];
626 $wpdb->insert(ATTENDEES_TABLE, array("firstName" => trim($_POST['newAttending'.$i.'FirstName']),
627 "lastName" => trim($_POST['newAttending'.$i.'LastName']),
628 "rsvpDate" => date("Y-m-d"),
629 "rsvpStatus" => (($_POST['newAttending'.$i] == "Y") ? "Yes" : "No"),
630 "kidsMeal" => (isset($_POST['newAttending'.$i.'KidsMeal']) ? $_POST['newAttending'.$i.'KidsMeal'] : "N"),
631 "veggieMeal" => (isset($_POST['newAttending'.$i.'VeggieMeal']) ? $_POST['newAttending'.$i.'VeggieMeal'] : "N"),
632 "additionalAttendee" => "Y"),
633 array('%s', '%s', '%s', '%s', '%s', '%s'));
634 rsvp_printQueryDebugInfo();
635 $newAid = $wpdb->insert_id;
636 rsvp_handleAdditionalQuestions($newAid, $i.'question');
637 // Add associations for this new user
638 $wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID" => $newAid,
639 "associatedAttendeeID" => $attendeeID),
640 array("%d", "%d"));
641 rsvp_printQueryDebugInfo();
642 $wpdb->query($wpdb->prepare("INSERT INTO ".ASSOCIATED_ATTENDEES_TABLE."(attendeeID, associatedAttendeeID)
643 SELECT ".$newAid.", associatedAttendeeID
644 FROM ".ASSOCIATED_ATTENDEES_TABLE."
645 WHERE attendeeID = ".$attendeeID));
646 rsvp_printQueryDebugInfo();
647 }
648 }
649 }
650 }
651
652 if((get_option(OPTION_NOTIFY_ON_RSVP) == "Y") && (get_option(OPTION_NOTIFY_EMAIL) != "")) {
653 $sql = "SELECT firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE." WHERE id= ".$attendeeID;
654 $attendee = $wpdb->get_results($sql);
655 if(count($attendee) > 0) {
656 $body = "Hello, \r\n\r\n";
657
658 $body .= stripslashes($attendee[0]->firstName)." ".stripslashes($attendee[0]->lastName).
659 " has submitted their RSVP and has RSVP'd with '".$attendee[0]->rsvpStatus."'.";
660
661 $sql = "SELECT firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE."
662 WHERE id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
663 OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d)";
664
665 $associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID));
666 if(count($associations) > 0) {
667 foreach($associations as $a) {
668 $body .= "\r\n\r\n--== Associated Attendees ==--\r\n";
669 $body .= stripslashes($a->firstName." ".$a->lastName)." rsvp status: ".$a->rsvpStatus."\r\n";
670 }
671 }
672
673 wp_mail(get_option(OPTION_NOTIFY_EMAIL), "New RSVP Submission", $body);
674 }
675 }
676
677 return rsvp_handle_output($text, rsvp_frontend_new_atendee_thankyou($thankYouPrimary, $thankYouAssociated, $rsvpPassword));
678 }
679
680 function rsvp_handlersvp(&$output, &$text) {
681 global $wpdb;
682 $thankYouPrimary = "";
683 $thankYouAssociated = array();
684 if(is_numeric($_POST['attendeeID']) && ($_POST['attendeeID'] > 0)) {
685 // update their information and what not....
686 if(strToUpper($_POST['mainRsvp']) == "Y") {
687 $rsvpStatus = "Yes";
688 } else {
689 $rsvpStatus = "No";
690 }
691 $attendeeID = $_POST['attendeeID'];
692 // Get Attendee first name
693 $thankYouPrimary = $wpdb->get_var($wpdb->prepare("SELECT firstName FROM ".ATTENDEES_TABLE." WHERE id = %d", $attendeeID));
694
695 $wpdb->update(ATTENDEES_TABLE, array("rsvpDate" => date("Y-m-d"),
696 "rsvpStatus" => $rsvpStatus,
697 "note" => $_POST['rsvp_note'],
698 "kidsMeal" => ((isset($_POST['mainKidsMeal']) && (strToUpper($_POST['mainKidsMeal']) == "Y")) ? "Y" : "N"),
699 "veggieMeal" => ((isset($_POST['mainVeggieMeal']) && (strToUpper($_POST['mainVeggieMeal']) == "Y")) ? "Y" : "N")),
700 array("id" => $attendeeID),
701 array("%s", "%s", "%s", "%s", "%s"),
702 array("%d"));
703 rsvp_printQueryDebugInfo();
704 rsvp_handleAdditionalQuestions($attendeeID, "mainquestion");
705
706 $sql = "SELECT id, firstName FROM ".ATTENDEES_TABLE."
707 WHERE (id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
708 OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d))
709 AND rsvpStatus = 'NoResponse'";
710 $associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID));
711 foreach($associations as $a) {
712 if(isset($_POST['attending'.$a->id]) && (($_POST['attending'.$a->id] == "Y") || ($_POST['attending'.$a->id] == "N"))) {
713 $thankYouAssociated[] = $a->firstName;
714 if($_POST['attending'.$a->id] == "Y") {
715 $rsvpStatus = "Yes";
716 } else {
717 $rsvpStatus = "No";
718 }
719 $wpdb->update(ATTENDEES_TABLE, array("rsvpDate" => date("Y-m-d"),
720 "rsvpStatus" => $rsvpStatus,
721 "kidsMeal" => ((strToUpper((isset($_POST['attending'.$a->id.'KidsMeal']) ? $_POST['attending'.$a->id.'KidsMeal'] : "N")) == "Y") ? "Y" : "N"),
722 "veggieMeal" => ((strToUpper((isset($_POST['attending'.$a->id.'VeggieMeal']) ? $_POST['attending'.$a->id.'VeggieMeal'] : "N")) == "Y") ? "Y" : "N")),
723 array("id" => $a->id),
724 array("%s", "%s", "%s", "%s"),
725 array("%d"));
726 rsvp_printQueryDebugInfo();
727 rsvp_handleAdditionalQuestions($a->id, $a->id."question");
728 }
729 }
730
731 if(get_option(OPTION_HIDE_ADD_ADDITIONAL) != "Y") {
732 if(is_numeric($_POST['additionalRsvp']) && ($_POST['additionalRsvp'] > 0)) {
733 for($i = 1; $i <= $_POST['additionalRsvp']; $i++) {
734 if(($i <= 3) &&
735 !empty($_POST['newAttending'.$i.'FirstName']) &&
736 !empty($_POST['newAttending'.$i.'LastName'])) {
737 $thankYouAssociated[] = $_POST['newAttending'.$i.'FirstName'];
738 $wpdb->insert(ATTENDEES_TABLE, array("firstName" => trim($_POST['newAttending'.$i.'FirstName']),
739 "lastName" => trim($_POST['newAttending'.$i.'LastName']),
740 "rsvpDate" => date("Y-m-d"),
741 "rsvpStatus" => (($_POST['newAttending'.$i] == "Y") ? "Yes" : "No"),
742 "kidsMeal" => (isset($_POST['newAttending'.$i.'KidsMeal']) ? $_POST['newAttending'.$i.'KidsMeal'] : "N"),
743 "veggieMeal" => (isset($_POST['newAttending'.$i.'VeggieMeal']) ? $_POST['newAttending'.$i.'VeggieMeal'] : "N"),
744 "additionalAttendee" => "Y"),
745 array('%s', '%s', '%s', '%s', '%s', '%s'));
746 rsvp_printQueryDebugInfo();
747 $newAid = $wpdb->insert_id;
748 rsvp_handleAdditionalQuestions($newAid, $i.'question');
749 // Add associations for this new user
750 $wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID" => $newAid,
751 "associatedAttendeeID" => $attendeeID),
752 array("%d", "%d"));
753 rsvp_printQueryDebugInfo();
754 $wpdb->query($wpdb->prepare("INSERT INTO ".ASSOCIATED_ATTENDEES_TABLE."(attendeeID, associatedAttendeeID)
755 SELECT ".$newAid.", associatedAttendeeID
756 FROM ".ASSOCIATED_ATTENDEES_TABLE."
757 WHERE attendeeID = %d", $attendeeID));
758 rsvp_printQueryDebugInfo();
759 }
760 }
761 }
762 }
763
764 if((get_option(OPTION_NOTIFY_ON_RSVP) == "Y") && (get_option(OPTION_NOTIFY_EMAIL) != "")) {
765 $sql = "SELECT firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE." WHERE id= ".$attendeeID;
766 $attendee = $wpdb->get_results($sql);
767 if(count($attendee) > 0) {
768 $body = "Hello, \r\n\r\n";
769
770 $body .= stripslashes($attendee[0]->firstName)." ".stripslashes($attendee[0]->lastName).
771 " has submitted their RSVP and has RSVP'd with '".$attendee[0]->rsvpStatus."'.";
772
773 $sql = "SELECT firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE."
774 WHERE id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
775 OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d)";
776
777 $associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID));
778 if(count($associations) > 0) {
779 $body .= "\r\n\r\n--== Associated Attendees ==--\r\n";
780 foreach($associations as $a) {
781 $body .= stripslashes($a->firstName." ".$a->lastName)." RSVP status: ".$a->rsvpStatus."\r\n";
782 }
783 }
784
785 wp_mail(get_option(OPTION_NOTIFY_EMAIL), "New RSVP Submission", $body);
786 }
787 }
788
789 return rsvp_handle_output($text, frontend_rsvp_thankyou($thankYouPrimary, $thankYouAssociated));
790 } else {
791 return rsvp_handle_output($text, rsvp_frontend_greeting());
792 }
793 }
794
795 function rsvp_editAttendee(&$output, &$text) {
796 global $wpdb;
797
798 if(is_numeric($_POST['attendeeID']) && ($_POST['attendeeID'] > 0)) {
799 // Try to find the user.
800 $attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus
801 FROM ".ATTENDEES_TABLE."
802 WHERE id = %d", $_POST['attendeeID']));
803 if($attendee != null) {
804 $output .= RSVP_START_CONTAINER;
805 $output .= RSVP_START_PARA.__("Welcome back", 'rsvp-plugin')." ".htmlspecialchars($attendee->firstName." ".$attendee->lastName)."!".RSVP_END_PARA;
806 $output .= rsvp_frontend_main_form($attendee->id);
807 return rsvp_handle_output($text, $output.RSVP_END_CONTAINER);
808 }
809 }
810 }
811
812 function rsvp_foundAttendee(&$output, &$text) {
813 global $wpdb;
814
815 if(is_numeric($_POST['attendeeID']) && ($_POST['attendeeID'] > 0)) {
816 $attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus
817 FROM ".ATTENDEES_TABLE."
818 WHERE id = %d", $_POST['attendeeID']));
819 if($attendee != null) {
820 $output = RSVP_START_CONTAINER;
821 if(strtolower($attendee->rsvpStatus) == "noresponse") {
822 $output .= RSVP_START_PARA.__("Hi", 'rsvp-plugin')." ".htmlspecialchars(stripslashes($attendee->firstName." ".$attendee->lastName))."!".RSVP_END_PARA;
823
824 if(trim(get_option(OPTION_WELCOME_TEXT)) != "") {
825 $output .= RSVP_START_PARA.trim(get_option(OPTION_WELCOME_TEXT)).RSVP_END_PARA;
826 } else {
827 $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;
828 }
829
830 $output .= rsvp_frontend_main_form($attendee->id);
831 } else {
832 $output .= rsvp_frontend_prompt_to_edit($attendee);
833 }
834 return rsvp_handle_output($text, $output.RSVP_END_CONTAINER);
835 }
836
837 return rsvp_handle_output($text, rsvp_frontend_greeting());
838 } else {
839 return rsvp_handle_output($text, rsvp_frontend_greeting());
840 }
841 }
842
843
844
845 function frontend_rsvp_thankyou($thankYouPrimary, $thankYouAssociated) {
846 $customTy = get_option(OPTION_THANKYOU);
847 if(!empty($customTy)) {
848 return nl2br($customTy);
849 } else {
850 $tyText = __("Thank you", 'rsvp-plugin');
851 if(!empty($thankYouPrimary)) {
852 $tyText .= " ".htmlspecialchars($thankYouPrimary);
853 }
854 $tyText .= __(" for RSVPing.", 'rsvp-plugin');
855
856 if(count($thankYouAssociated) > 0) {
857 $tyText .= __(" You have also RSVPed for - ", 'rsvp-plugin');
858 foreach($thankYouAssociated as $name) {
859 $tyText .= htmlspecialchars(" ".$name).", ";
860 }
861 $tyText = rtrim(trim($tyText), ",").".";
862 }
863 return RSVP_START_CONTAINER.RSVP_START_PARA.$tyText.RSVP_END_PARA.RSVP_END_CONTAINER;
864 }
865 }
866
867 function rsvp_frontend_new_atendee_thankyou($thankYouPrimary, $thankYouAssociated, $password = "") {
868 /*$customTy = get_option(OPTION_THANKYOU);
869 if(!empty($customTy)) {
870 return nl2br($customTy);
871 } else {*/
872 $thankYouText = __("Thank you ", 'rsvp-plugin');
873 if(!empty($thankYouPrimary)) {
874 $thankYouText .= htmlspecialchars($thankYouPrimary);
875 }
876 $thankYouText .= __(" for RSVPing. To modify your RSVP just come back ".
877 "to this page and enter in your first and last name.", 'rsvp-plugin');
878 if(!empty($password)) {
879 $thankYouText .= __(" You will also need to know your password which is", 'rsvp-plugin').
880 " - <strong>$password</strong>";
881 }
882
883 if(count($thankYouAssociated) > 0) {
884 $thankYouText .= __("<br /><br />You have also RSVPed for - ", 'rsvp-plugin');
885 foreach($thankYouAssociated as $name) {
886 $thankYouText .= htmlspecialchars(" ".$name).", ";
887 }
888 $thankYouText = rtrim(trim($thankYouText), ",").".";
889 }
890
891 return RSVP_START_CONTAINER.RSVP_START_PARA.$thankYouText.RSVP_END_PARA.RSVP_END_CONTAINER;
892 //}
893 }
894
895 function rsvp_chomp_name($name, $maxLength) {
896 for($i = $maxLength; $maxLength >= 1; $i--) {
897 if(strlen($name) >= $i) {
898 return substr($name, 0, $i);
899 }
900 }
901 }
902
903 function rsvp_BeginningFormField($id, $additionalClasses) {
904 return "<div ".(!empty($id) ? "id=\"$id\"" : "")." class=\"rsvpFormField ".(!empty($additionalClasses) ? $additionalClasses : "")."\">";
905 }
906
907 function rsvp_frontend_greeting() {
908 global $rsvp_form_action;
909 $customGreeting = get_option(OPTION_GREETING);
910 $output = RSVP_START_PARA.__("Please enter your first and last name to RSVP.", 'rsvp-plugin').RSVP_END_PARA;
911 $firstName = "";
912 $lastName = "";
913 $passcode = "";
914 if(isset($_SESSION['rsvpFirstName'])) {
915 $firstName = $_SESSION['rsvpFirstName'];
916 }
917 if(isset($_SESSION['rsvpLastName'])) {
918 $lastName = $_SESSION['rsvpLastName'];
919 }
920 if(isset($_SESSION['rsvpPasscode'])) {
921 $passcode = $_SESSION['rsvpPasscode'];
922 }
923 if(!empty($customGreeting)) {
924 $output = RSVP_START_PARA.nl2br($customGreeting).RSVP_END_PARA;
925 }
926
927 $output .= RSVP_START_CONTAINER;
928
929 if(get_option(OPTION_RSVP_OPEN_REGISTRATION) == "Y") {
930 $output .= "<form name=\"rsvpNew\" method=\"post\" id=\"rsvpNew\" action=\"$rsvp_form_action\">\r\n";
931 $output .= " <input type=\"hidden\" name=\"rsvpStep\" value=\"newattendee\" />";
932 $output .= "<input type=\"submit\" value=\"".__("New Attendee Registration", "rsvp-plugin")."\" />\r\n";
933 $output .= "</form>\r\n";
934
935 $output .= "<hr />";
936 $output .= RSVP_START_PARA.__("Need to modify your registration? Start with the below form.", "rsvp-plugin").RSVP_END_PARA;
937 }
938
939 $output .= "<form name=\"rsvp\" method=\"post\" id=\"rsvp\" action=\"$rsvp_form_action\" autocomplete=\"off\">\r\n";
940 $output .= " <input type=\"hidden\" name=\"rsvpStep\" value=\"find\" />";
941 $output .= RSVP_START_PARA."<label for=\"firstName\">".__("First Name", 'rsvp-plugin').":</label>
942 <input type=\"text\" name=\"firstName\" id=\"firstName\" size=\"30\" value=\"".htmlspecialchars($firstName)."\" class=\"required\" />".RSVP_END_PARA;
943 $output .= RSVP_START_PARA."<label for=\"lastName\">".__("Last Name", 'rsvp-plugin').":</label>
944 <input type=\"text\" name=\"lastName\" id=\"lastName\" size=\"30\" value=\"".htmlspecialchars($lastName)."\" class=\"required\" />".RSVP_END_PARA;
945 if(rsvp_require_passcode()) {
946 $output .= RSVP_START_PARA."<label for=\"passcode\">".__("Passcode", 'rsvp-plugin').":</label>
947 <input type=\"password\" name=\"passcode\" id=\"passcode\" size=\"30\" value=\"".htmlspecialchars($passcode)."\" class=\"required\" autocomplete=\"off\" />".RSVP_END_PARA;
948 }
949 $output .= RSVP_START_PARA."<input type=\"submit\" value=\"".__("Complete your RSVP!", 'rsvp-plugin')."\" />".RSVP_END_PARA;
950 $output .= "</form>\r\n";
951 $output .= RSVP_END_CONTAINER;
952 return $output;
953 }
954 ?>
955