PluginProbe
RSVP and Event Management / 1.7.6
RSVP and Event Management v1.7.6
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.6, at rsvp_frontend.inc.php

965 lines 47.5 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("", "").RSVP_START_PARA.sprintf(__(" Will %s be attending?", 'rsvp-plugin'), htmlspecialchars($a->firstName)).RSVP_END_FORM_FIELD.
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 RSVP_START_PARA.sprintf(__("Does %s need a kids meal?", 'rsvp-plugin'), htmlspecialchars($a->firstName)).
290 RSVP_END_PARA."&nbsp; ".
291 "<input type=\"radio\" name=\"attending".$a->id."KidsMeal\" value=\"Y\" id=\"attending".$a->id."KidsMealY\" /> ".
292 "<label for=\"attending".$a->id."KidsMealY\">$yesText</label>
293 <input type=\"radio\" name=\"attending".$a->id."KidsMeal\" value=\"N\" id=\"attending".$a->id."KidsMealN\" checked=\"checked\" /> ".
294 "<label for=\"attending".$a->id."KidsMealN\">$noText</label>".RSVP_END_FORM_FIELD;
295 }
296
297 if(get_option(OPTION_HIDE_VEGGIE) != "Y") {
298 $form .= rsvp_BeginningFormField("", "").
299 RSVP_START_PARA.sprintf(__("Does %s need a vegetarian meal?", 'rsvp-plugin'), htmlspecialchars($a->firstName)).
300 RSVP_END_FORM_FIELD."&nbsp; ".
301 "<input type=\"radio\" name=\"attending".$a->id."VeggieMeal\" value=\"Y\" id=\"attending".$a->id."VeggieMealY\" /> ".
302 "<label for=\"attending".$a->id."VeggieMealY\">$yesText</label>
303 <input type=\"radio\" name=\"attending".$a->id."VeggieMeal\" value=\"N\" id=\"attending".$a->id."VeggieMealN\" checked=\"checked\" /> ".
304 "<label for=\"attending".$a->id."VeggieMealN\">$noText</label>".RSVP_END_FORM_FIELD;
305 }
306
307 $form .= rsvp_buildAdditionalQuestions($a->id, $a->id);
308 $form .= "</div>\r\n"; //-- rsvpAdditionalAttendeeQuestions
309 $form .= "</div>\r\n";
310 } // if($a->id != ...)
311 } // foreach($associations...)
312 }
313
314 if(get_option(OPTION_HIDE_ADD_ADDITIONAL) != "Y") {
315 $text = __("Did we slip up and forget to invite someone? If so, please add him or her here:", 'rsvp-plugin');
316
317 if(trim(get_option(OPTION_RSVP_ADD_ADDITIONAL_VERBIAGE)) != "") {
318 $text = get_option(OPTION_RSVP_ADD_ADDITIONAL_VERBIAGE);
319 }
320
321 $form .= "<h3>$text</h3>\r\n";
322 $form .= "<div id=\"additionalRsvpContainer\">\r\n
323 <input type=\"hidden\" name=\"additionalRsvp\" id=\"additionalRsvp\" value=\"".count($newRsvps)."\" />
324 <div style=\"text-align:right\"><img ".
325 "src=\"".get_option("siteurl")."/wp-content/plugins/rsvp/plus.png\" width=\"24\" height=\"24\" border=\"0\" id=\"addRsvp\" /></div>".
326 "</div>";
327 }
328
329 $form .= RSVP_START_PARA."<input type=\"submit\" value=\"RSVP\" />".RSVP_END_PARA;
330 if(get_option(OPTION_HIDE_ADD_ADDITIONAL) != "Y") {
331 // TODO: Need to move this into the main JS file but not sure how to do that with the options and the custom questions.
332 // - Moving the options would be fairly easy. Just set two JS variables in here and then go off of that.
333 // - No clue on custom questions....
334 $form .= "<script type=\"text/javascript\" language=\"javascript\">\r\n
335 function handleAddRsvpClick() {
336 var numAdditional = jQuery(\"#additionalRsvp\").val();
337 numAdditional++;
338 if(numAdditional > 3) {
339 alert('".__("You have already added 3 additional rsvp\'s you can add no more.", 'rsvp-plugin')."');
340 } else {
341 jQuery(\"#additionalRsvpContainer\").append(\"<div class=\\\"rsvpAdditionalAttendee\\\">\" + \r\n
342 \"<div class=\\\"rsvpAdditionalAttendeeQuestions\\\">\" + \r\n
343 \"<div class=\\\"rsvpFormField\\\">\" + \r\n
344 \" <label for=\\\"newAttending\" + numAdditional + \"FirstName\\\">".__("Person's first name", 'rsvp-plugin')."&nbsp;</label>\" + \r\n
345 \" <input type=\\\"text\\\" name=\\\"newAttending\" + numAdditional + \"FirstName\\\" id=\\\"newAttending\" + numAdditional + \"FirstName\\\" />\" + \r\n
346 \"</div>\" + \r\n
347 \"<div class=\\\"rsvpFormField\\\">\" + \r\n
348 \" <label for=\\\"newAttending\" + numAdditional + \"LastName\\\">".__("Person's last name", 'rsvp-plugin')."</label>\" + \r\n
349 \" <input type=\\\"text\\\" name=\\\"newAttending\" + numAdditional + \"LastName\\\" id=\\\"newAttending\" + numAdditional + \"LastName\\\" />\" + \r\n
350 \"</div>\" + \r\n
351 \"<div class=\\\"rsvpFormField\\\">\" + \r\n
352 \"<p>Will this person be attending?</p>\" + \r\n
353 \"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"\\\" value=\\\"Y\\\" id=\\\"newAttending\" + numAdditional + \"Y\\\" checked=\\\"checked\\\" /> \" +
354 \"<label for=\\\"newAttending\" + numAdditional + \"Y\\\">$yesText</label> \" +
355 \"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"\\\" value=\\\"N\\\" id=\\\"newAttending\" + numAdditional + \"N\\\"> <label for=\\\"newAttending\" + numAdditional + \"N\\\">$noText</label>\" +
356 \"</div>\" + \r\n";
357 if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {
358 $form .= "\"<div class=\\\"rsvpFormField\\\">\" +
359 \"<p>".__("Does this person need a kids meal?", 'rsvp-plugin')."</p>\" +
360 \"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"KidsMeal\\\" value=\\\"Y\\\" id=\\\"newAttending\" + numAdditional + \"KidsMealY\\\" /> \" +
361 \"<label for=\\\"newAttending\" + numAdditional + \"KidsMealY\\\">$yesText</label> \" +
362 \"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"KidsMeal\\\" value=\\\"N\\\" id=\\\"newAttending\" + numAdditional + \"KidsMealN\\\" checked=\\\"checked\\\" /> \" +
363 \"<label for=\\\"newAttending\" + numAdditional + \"KidsMealN\\\">$noText</label>\" +
364 \"</div>\" +
365 \"</div>\" + \r\n";
366 }
367 if(get_option(OPTION_HIDE_VEGGIE) != "Y") {
368 $form .= "\"<div class=\\\"rsvpFormField\\\">\" + \r\n
369 \"<p>".__("Does this person need a vegetarian meal?", 'rsvp-plugin')."</p>\" +
370 \"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"VeggieMeal\\\" value=\\\"Y\\\" id=\\\"newAttending\" + numAdditional + \"VeggieMealY\\\" /> \" +
371 \"<label for=\\\"newAttending\" + numAdditional + \"VeggieMealY\\\">$yesText</label> \" +
372 \"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"VeggieMeal\\\" value=\\\"N\\\" id=\\\"newAttending\" + numAdditional + \"VeggieMealN\\\" checked=\\\"checked\\\" /> \" +
373 \"<label for=\\\"newAttending\" + numAdditional + \"VeggieMealN\\\">$noText</label>\" +
374 \"</div>\" + ";
375 }
376 $tmpVar = str_replace("\r\n", "", str_replace("|", "\"", addSlashes(rsvp_buildAdditionalQuestions(0, "| + numAdditional + |"))));
377
378 $form .= "\"".$tmpVar."\" +
379 \"<p><button onclick=\\\"removeAdditionalRSVP(this);\\\">Remove Guest</button></p>\" +
380 \"</div>\");
381 jQuery(\"#additionalRsvp\").val(numAdditional);
382 }
383 }
384
385 function removeAdditionalRSVP(rsvp) {
386 var numAdditional = jQuery(\"#additionalRsvp\").val();
387 numAdditional--;
388 jQuery(rsvp).parent().parent().remove();
389 jQuery(\"#additionalRsvp\").val(numAdditional);
390 }
391 </script>\r\n";
392 }
393 $form .= "</form>\r\n";
394
395 return $form;
396 }
397
398 function rsvp_revtrievePreviousAnswer($attendeeID, $questionID) {
399 global $wpdb;
400 $answers = "";
401 if(($attendeeID > 0) && ($questionID > 0)) {
402 $rs = $wpdb->get_results($wpdb->prepare("SELECT answer FROM ".ATTENDEE_ANSWERS." WHERE questionID = %d AND attendeeID = %d", $questionID, $attendeeID));
403 if(count($rs) > 0) {
404 $answers = stripslashes($rs[0]->answer);
405 }
406 }
407
408 return $answers;
409 }
410
411 function rsvp_buildAdditionalQuestions($attendeeID, $prefix) {
412 global $wpdb, $rsvp_saved_form_vars;
413 $output = "";
414
415 $sql = "SELECT q.id, q.question, questionType FROM ".QUESTIONS_TABLE." q
416 INNER JOIN ".QUESTION_TYPE_TABLE." qt ON qt.id = q.questionTypeID
417 WHERE q.permissionLevel = 'public'
418 OR (q.permissionLevel = 'private' AND q.id IN (SELECT questionID FROM ".QUESTION_ATTENDEES_TABLE." WHERE attendeeID = $attendeeID))
419 ORDER BY q.sortOrder ";
420 $questions = $wpdb->get_results($sql);
421 if(count($questions) > 0) {
422 foreach($questions as $q) {
423 $oldAnswer = rsvp_revtrievePreviousAnswer($attendeeID, $q->id);
424
425 $output .= rsvp_BeginningFormField("", "").RSVP_START_PARA.stripslashes($q->question).RSVP_END_PARA;
426
427 if($q->questionType == QT_MULTI) {
428 $oldAnswers = explode(",", $oldAnswer);
429
430 $answers = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $q->id));
431 if(count($answers) > 0) {
432 $i = 0;
433 foreach($answers as $a) {
434 $output .= rsvp_BeginningFormField("", "rsvpCheckboxCustomQ")."<input type=\"checkbox\" name=\"".$prefix."question".$q->id."[]\" id=\"".$prefix."question".$q->id.$a->id."\" value=\"".$a->id."\" "
435 .((in_array(stripslashes($a->answer), $oldAnswers)) ? " checked=\"checked\"" : "")." />".
436 "<label for=\"".$prefix."question".$q->id.$a->id."\">".stripslashes($a->answer)."</label>\r\n".RSVP_END_FORM_FIELD;
437 $i++;
438 }
439 $output .= "<div class=\"rsvpClear\">&nbsp;</div>\r\n";
440 }
441 } else if ($q->questionType == QT_DROP) {
442 $oldAnswers = explode(",", $oldAnswer);
443
444 $output .= "<select name=\"".$prefix."question".$q->id."\" size=\"1\">\r\n".
445 "<option value=\"\">--</option>\r\n";
446 $answers = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $q->id));
447 if(count($answers) > 0) {
448 foreach($answers as $a) {
449 $output .= "<option value=\"".$a->id."\" ".((in_array(stripslashes($a->answer), $oldAnswers)) ? " selected=\"selected\"" : "").">".stripslashes($a->answer)."</option>\r\n";
450 }
451 }
452 $output .= "</select>\r\n";
453 } else if ($q->questionType == QT_LONG) {
454 $output .= "<textarea name=\"".$prefix."question".$q->id."\" rows=\"5\" cols=\"35\">".htmlspecialchars($oldAnswer)."</textarea>";
455 } else if ($q->questionType == QT_RADIO) {
456 $oldAnswers = explode(",", $oldAnswer);
457 $answers = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $q->id));
458 if(count($answers) > 0) {
459 $i = 0;
460 $output .= RSVP_START_PARA;
461 foreach($answers as $a) {
462 $output .= "<input type=\"radio\" name=\"".$prefix."question".$q->id."\" id=\"".$prefix."question".$q->id.$a->id."\" value=\"".$a->id."\" "
463 .((in_array(stripslashes($a->answer), $oldAnswers)) ? " checked=\"checked\"" : "")." /> ".
464 "<label for=\"".$prefix."question".$q->id.$a->id."\">".stripslashes($a->answer)."</label>\r\n";
465 $i++;
466 }
467 $output .= RSVP_END_PARA;
468 }
469 } else {
470 // normal text input
471 $output .= "<input type=\"text\" name=\"".$prefix."question".$q->id."\" value=\"".htmlspecialchars($oldAnswer)."\" size=\"25\" />";
472 }
473
474 $output .= RSVP_END_FORM_FIELD;
475 }
476 }
477
478 return $output;
479 }
480
481 function rsvp_find(&$output, &$text) {
482 global $wpdb, $rsvp_form_action;
483 $passcodeOptionEnabled = (rsvp_require_passcode()) ? true : false;
484
485 $_SESSION['rsvpFirstName'] = $_POST['firstName'];
486 $_SESSION['rsvpLastName'] = $_POST['lastName'];
487 $passcode = "";
488 if(isset($_POST['passcode'])) {
489 $passcode = $_POST['passcode'];
490 $_SESSION['rsvpPasscode'] = $_POST['passcode'];
491 }
492
493 $firstName = $_POST['firstName'];
494 $lastName = $_POST['lastName'];
495
496 if((strlen($_POST['firstName']) <= 1) || (strlen($_POST['lastName']) <= 1)) {
497 $output = "<p class=\"rsvpParagraph\" style=\"color:red\">".__("A first and last name must be specified", 'rsvp-plugin')."</p>\r\n";
498 $output .= rsvp_frontend_greeting();
499
500 return rsvp_handle_output($text, $output);
501 }
502
503 // Try to find the user.
504 if($passcodeOptionEnabled) {
505 $attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus
506 FROM ".ATTENDEES_TABLE."
507 WHERE firstName = %s AND lastName = %s AND passcode = %s", $firstName, $lastName, $passcode));
508 } else {
509 $attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus
510 FROM ".ATTENDEES_TABLE."
511 WHERE firstName = %s AND lastName = %s", $firstName, $lastName));
512 }
513
514 if($attendee != null) {
515 // hey we found something, we should move on and print out any associated users and let them rsvp
516 $output = "<div>\r\n";
517 if(strtolower($attendee->rsvpStatus) == "noresponse") {
518 $output .= RSVP_START_PARA."Hi ".htmlspecialchars(stripslashes($attendee->firstName." ".$attendee->lastName))."!".RSVP_END_PARA;
519
520 if(trim(get_option(OPTION_WELCOME_TEXT)) != "") {
521 $output .= RSVP_START_PARA.trim(get_option(OPTION_WELCOME_TEXT)).RSVP_END_PARA;
522 } else {
523 $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;
524 }
525
526 $output .= rsvp_frontend_main_form($attendee->id);
527 } else {
528 $output .= rsvp_frontend_prompt_to_edit($attendee);
529 }
530 return rsvp_handle_output($text, $output."</div>\r\n");
531 }
532
533 // We did not find anyone let's try and do a rough search
534 $attendees = null;
535 if(!$passcodeOptionEnabled) {
536 for($i = 3; $i >= 1; $i--) {
537 $truncFirstName = rsvp_chomp_name($firstName, $i);
538 $attendees = $wpdb->get_results("SELECT id, firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE."
539 WHERE lastName = '".mysql_real_escape_string($lastName)."' AND firstName LIKE '".mysql_real_escape_string($truncFirstName)."%'");
540 if(count($attendees) > 0) {
541 $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;
542 foreach($attendees as $a) {
543 $output .= "<form method=\"post\" action=\"$rsvp_form_action\">\r\n
544 <input type=\"hidden\" name=\"rsvpStep\" value=\"foundattendee\" />\r\n
545 <input type=\"hidden\" name=\"attendeeID\" value=\"".$a->id."\" />\r\n
546 <p class=\"rsvpParagraph\" style=\"text-align:left;\">\r\n
547 ".htmlspecialchars($a->firstName." ".$a->lastName)."
548 <input type=\"submit\" value=\"RSVP\" />\r\n
549 </p>\r\n</form>\r\n";
550 }
551 return rsvp_handle_output($text, $output);
552 } else {
553 $i = strlen($truncFirstName);
554 }
555 }
556 }
557 $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));
558 $notFoundText .= rsvp_frontend_greeting();
559 return rsvp_handle_output($text, $notFoundText);
560 }
561
562 function rsvp_handleNewRsvp(&$output, &$text) {
563 global $wpdb, $rsvp_saved_form_vars;
564 $thankYouPrimary = "";
565 $thankYouAssociated = array();
566 foreach($_POST as $key=>$val) {
567 $rsvp_saved_form_vars[$key] = $val;
568 }
569
570 if(empty($_POST['attendeeFirstName']) || empty($_POST['attendeeLastName'])) {
571 return rsvp_handlenewattendee($output, $text);
572 }
573
574 $rsvpPassword = "";
575 $rsvpStatus = "No";
576 if(strToUpper($_POST['mainRsvp']) == "Y") {
577 $rsvpStatus = "Yes";
578 }
579 $kidsMeal = ((isset($_POST['mainKidsMeal']) && (strToUpper($_POST['mainKidsMeal']) == "Y")) ? "Y" : "N");
580 $veggieMeal = ((isset($_POST['mainVeggieMeal']) && (strToUpper($_POST['mainVeggieMeal']) == "Y")) ? "Y" : "N");
581 $thankYouPrimary = $_POST['attendeeFirstName'];
582 $wpdb->insert(ATTENDEES_TABLE, array("rsvpDate" => date("Y-m-d"),
583 "firstName" => $_POST['attendeeFirstName'],
584 "lastName" => $_POST['attendeeLastName'],
585 "rsvpStatus" => $rsvpStatus,
586 "note" => $_POST['rsvp_note'],
587 "kidsMeal" => $kidsMeal,
588 "veggieMeal" => $veggieMeal),
589 array("%s", "%s", "%s", "%s", "%s", "%s", "%s"));
590 rsvp_printQueryDebugInfo();
591 $attendeeID = $wpdb->insert_id;
592
593 if(rsvp_require_passcode()) {
594 $rsvpPassword = trim(rsvp_generate_passcode());
595 $wpdb->update(ATTENDEES_TABLE,
596 array("passcode" => $rsvpPassword),
597 array("id"=>$attendeeID),
598 array("%s"),
599 array("%d"));
600 }
601
602 rsvp_handleAdditionalQuestions($attendeeID, "mainquestion");
603
604 $sql = "SELECT id, firstName FROM ".ATTENDEES_TABLE."
605 WHERE (id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
606 OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d))
607 AND rsvpStatus = 'NoResponse'";
608 $associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID));
609 foreach($associations as $a) {
610 if(isset($_POST['attending'.$a->id]) && (($_POST['attending'.$a->id] == "Y") || ($_POST['attending'.$a->id] == "N"))) {
611 if($_POST['attending'.$a->id] == "Y") {
612 $rsvpStatus = "Yes";
613 } else {
614 $rsvpStatus = "No";
615 }
616 $thankYouAssociated[] = stripslashes($a->firstName);
617 $wpdb->update(ATTENDEES_TABLE, array("rsvpDate" => date("Y-m-d"),
618 "rsvpStatus" => $rsvpStatus,
619 "kidsMeal" => ((strToUpper((isset($_POST['attending'.$a->id.'KidsMeal']) ? $_POST['attending'.$a->id.'KidsMeal'] : "N")) == "Y") ? "Y" : "N"),
620 "veggieMeal" => ((strToUpper((isset($_POST['attending'.$a->id.'VeggieMeal']) ? $_POST['attending'.$a->id.'VeggieMeal'] : "N")) == "Y") ? "Y" : "N")),
621 array("id" => $a->id),
622 array("%s", "%s", "%s", "%s"),
623 array("%d"));
624 rsvp_printQueryDebugInfo();
625 rsvp_handleAdditionalQuestions($a->id, $a->id."question");
626 }
627 }
628
629 if(get_option(OPTION_HIDE_ADD_ADDITIONAL) != "Y") {
630 if(is_numeric($_POST['additionalRsvp']) && ($_POST['additionalRsvp'] > 0)) {
631 for($i = 1; $i <= $_POST['additionalRsvp']; $i++) {
632 if(($i <= 3) &&
633 !empty($_POST['newAttending'.$i.'FirstName']) &&
634 !empty($_POST['newAttending'.$i.'LastName'])) {
635 $thankYouAssociated[] = $_POST['newAttending'.$i.'FirstName'];
636 $wpdb->insert(ATTENDEES_TABLE, array("firstName" => trim($_POST['newAttending'.$i.'FirstName']),
637 "lastName" => trim($_POST['newAttending'.$i.'LastName']),
638 "rsvpDate" => date("Y-m-d"),
639 "rsvpStatus" => (($_POST['newAttending'.$i] == "Y") ? "Yes" : "No"),
640 "kidsMeal" => (isset($_POST['newAttending'.$i.'KidsMeal']) ? $_POST['newAttending'.$i.'KidsMeal'] : "N"),
641 "veggieMeal" => (isset($_POST['newAttending'.$i.'VeggieMeal']) ? $_POST['newAttending'.$i.'VeggieMeal'] : "N"),
642 "additionalAttendee" => "Y"),
643 array('%s', '%s', '%s', '%s', '%s', '%s'));
644 rsvp_printQueryDebugInfo();
645 $newAid = $wpdb->insert_id;
646 rsvp_handleAdditionalQuestions($newAid, $i.'question');
647 // Add associations for this new user
648 $wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID" => $newAid,
649 "associatedAttendeeID" => $attendeeID),
650 array("%d", "%d"));
651 rsvp_printQueryDebugInfo();
652 $wpdb->query($wpdb->prepare("INSERT INTO ".ASSOCIATED_ATTENDEES_TABLE."(attendeeID, associatedAttendeeID)
653 SELECT ".$newAid.", associatedAttendeeID
654 FROM ".ASSOCIATED_ATTENDEES_TABLE."
655 WHERE attendeeID = ".$attendeeID));
656 rsvp_printQueryDebugInfo();
657 }
658 }
659 }
660 }
661
662 if((get_option(OPTION_NOTIFY_ON_RSVP) == "Y") && (get_option(OPTION_NOTIFY_EMAIL) != "")) {
663 $sql = "SELECT firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE." WHERE id= ".$attendeeID;
664 $attendee = $wpdb->get_results($sql);
665 if(count($attendee) > 0) {
666 $body = "Hello, \r\n\r\n";
667
668 $body .= stripslashes($attendee[0]->firstName)." ".stripslashes($attendee[0]->lastName).
669 " has submitted their RSVP and has RSVP'd with '".$attendee[0]->rsvpStatus."'.";
670
671 $sql = "SELECT firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE."
672 WHERE id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
673 OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d)";
674
675 $associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID));
676 if(count($associations) > 0) {
677 foreach($associations as $a) {
678 $body .= "\r\n\r\n--== Associated Attendees ==--\r\n";
679 $body .= stripslashes($a->firstName." ".$a->lastName)." rsvp status: ".$a->rsvpStatus."\r\n";
680 }
681 }
682
683 wp_mail(get_option(OPTION_NOTIFY_EMAIL), "New RSVP Submission", $body);
684 }
685 }
686
687 return rsvp_handle_output($text, rsvp_frontend_new_atendee_thankyou($thankYouPrimary, $thankYouAssociated, $rsvpPassword));
688 }
689
690 function rsvp_handlersvp(&$output, &$text) {
691 global $wpdb;
692 $thankYouPrimary = "";
693 $thankYouAssociated = array();
694 if(is_numeric($_POST['attendeeID']) && ($_POST['attendeeID'] > 0)) {
695 // update their information and what not....
696 if(strToUpper($_POST['mainRsvp']) == "Y") {
697 $rsvpStatus = "Yes";
698 } else {
699 $rsvpStatus = "No";
700 }
701 $attendeeID = $_POST['attendeeID'];
702 // Get Attendee first name
703 $thankYouPrimary = $wpdb->get_var($wpdb->prepare("SELECT firstName FROM ".ATTENDEES_TABLE." WHERE id = %d", $attendeeID));
704
705 $wpdb->update(ATTENDEES_TABLE, array("rsvpDate" => date("Y-m-d"),
706 "rsvpStatus" => $rsvpStatus,
707 "note" => $_POST['rsvp_note'],
708 "kidsMeal" => ((isset($_POST['mainKidsMeal']) && (strToUpper($_POST['mainKidsMeal']) == "Y")) ? "Y" : "N"),
709 "veggieMeal" => ((isset($_POST['mainVeggieMeal']) && (strToUpper($_POST['mainVeggieMeal']) == "Y")) ? "Y" : "N")),
710 array("id" => $attendeeID),
711 array("%s", "%s", "%s", "%s", "%s"),
712 array("%d"));
713 rsvp_printQueryDebugInfo();
714 rsvp_handleAdditionalQuestions($attendeeID, "mainquestion");
715
716 $sql = "SELECT id, firstName FROM ".ATTENDEES_TABLE."
717 WHERE (id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
718 OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d))
719 AND rsvpStatus = 'NoResponse'";
720 $associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID));
721 foreach($associations as $a) {
722 if(isset($_POST['attending'.$a->id]) && (($_POST['attending'.$a->id] == "Y") || ($_POST['attending'.$a->id] == "N"))) {
723 $thankYouAssociated[] = $a->firstName;
724 if($_POST['attending'.$a->id] == "Y") {
725 $rsvpStatus = "Yes";
726 } else {
727 $rsvpStatus = "No";
728 }
729 $wpdb->update(ATTENDEES_TABLE, array("rsvpDate" => date("Y-m-d"),
730 "rsvpStatus" => $rsvpStatus,
731 "kidsMeal" => ((strToUpper((isset($_POST['attending'.$a->id.'KidsMeal']) ? $_POST['attending'.$a->id.'KidsMeal'] : "N")) == "Y") ? "Y" : "N"),
732 "veggieMeal" => ((strToUpper((isset($_POST['attending'.$a->id.'VeggieMeal']) ? $_POST['attending'.$a->id.'VeggieMeal'] : "N")) == "Y") ? "Y" : "N")),
733 array("id" => $a->id),
734 array("%s", "%s", "%s", "%s"),
735 array("%d"));
736 rsvp_printQueryDebugInfo();
737 rsvp_handleAdditionalQuestions($a->id, $a->id."question");
738 }
739 }
740
741 if(get_option(OPTION_HIDE_ADD_ADDITIONAL) != "Y") {
742 if(is_numeric($_POST['additionalRsvp']) && ($_POST['additionalRsvp'] > 0)) {
743 for($i = 1; $i <= $_POST['additionalRsvp']; $i++) {
744 if(($i <= 3) &&
745 !empty($_POST['newAttending'.$i.'FirstName']) &&
746 !empty($_POST['newAttending'.$i.'LastName'])) {
747 $thankYouAssociated[] = $_POST['newAttending'.$i.'FirstName'];
748 $wpdb->insert(ATTENDEES_TABLE, array("firstName" => trim($_POST['newAttending'.$i.'FirstName']),
749 "lastName" => trim($_POST['newAttending'.$i.'LastName']),
750 "rsvpDate" => date("Y-m-d"),
751 "rsvpStatus" => (($_POST['newAttending'.$i] == "Y") ? "Yes" : "No"),
752 "kidsMeal" => (isset($_POST['newAttending'.$i.'KidsMeal']) ? $_POST['newAttending'.$i.'KidsMeal'] : "N"),
753 "veggieMeal" => (isset($_POST['newAttending'.$i.'VeggieMeal']) ? $_POST['newAttending'.$i.'VeggieMeal'] : "N"),
754 "additionalAttendee" => "Y"),
755 array('%s', '%s', '%s', '%s', '%s', '%s'));
756 rsvp_printQueryDebugInfo();
757 $newAid = $wpdb->insert_id;
758 rsvp_handleAdditionalQuestions($newAid, $i.'question');
759 // Add associations for this new user
760 $wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID" => $newAid,
761 "associatedAttendeeID" => $attendeeID),
762 array("%d", "%d"));
763 rsvp_printQueryDebugInfo();
764 $wpdb->query($wpdb->prepare("INSERT INTO ".ASSOCIATED_ATTENDEES_TABLE."(attendeeID, associatedAttendeeID)
765 SELECT ".$newAid.", associatedAttendeeID
766 FROM ".ASSOCIATED_ATTENDEES_TABLE."
767 WHERE attendeeID = %d", $attendeeID));
768 rsvp_printQueryDebugInfo();
769 }
770 }
771 }
772 }
773
774 if((get_option(OPTION_NOTIFY_ON_RSVP) == "Y") && (get_option(OPTION_NOTIFY_EMAIL) != "")) {
775 $sql = "SELECT firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE." WHERE id= ".$attendeeID;
776 $attendee = $wpdb->get_results($sql);
777 if(count($attendee) > 0) {
778 $body = "Hello, \r\n\r\n";
779
780 $body .= stripslashes($attendee[0]->firstName)." ".stripslashes($attendee[0]->lastName).
781 " has submitted their RSVP and has RSVP'd with '".$attendee[0]->rsvpStatus."'.";
782
783 $sql = "SELECT firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE."
784 WHERE id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
785 OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d)";
786
787 $associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID));
788 if(count($associations) > 0) {
789 $body .= "\r\n\r\n--== Associated Attendees ==--\r\n";
790 foreach($associations as $a) {
791 $body .= stripslashes($a->firstName." ".$a->lastName)." RSVP status: ".$a->rsvpStatus."\r\n";
792 }
793 }
794
795 wp_mail(get_option(OPTION_NOTIFY_EMAIL), "New RSVP Submission", $body);
796 }
797 }
798
799 return rsvp_handle_output($text, frontend_rsvp_thankyou($thankYouPrimary, $thankYouAssociated));
800 } else {
801 return rsvp_handle_output($text, rsvp_frontend_greeting());
802 }
803 }
804
805 function rsvp_editAttendee(&$output, &$text) {
806 global $wpdb;
807
808 if(is_numeric($_POST['attendeeID']) && ($_POST['attendeeID'] > 0)) {
809 // Try to find the user.
810 $attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus
811 FROM ".ATTENDEES_TABLE."
812 WHERE id = %d", $_POST['attendeeID']));
813 if($attendee != null) {
814 $output .= RSVP_START_CONTAINER;
815 $output .= RSVP_START_PARA.__("Welcome back", 'rsvp-plugin')." ".htmlspecialchars($attendee->firstName." ".$attendee->lastName)."!".RSVP_END_PARA;
816 $output .= rsvp_frontend_main_form($attendee->id);
817 return rsvp_handle_output($text, $output.RSVP_END_CONTAINER);
818 }
819 }
820 }
821
822 function rsvp_foundAttendee(&$output, &$text) {
823 global $wpdb;
824
825 if(is_numeric($_POST['attendeeID']) && ($_POST['attendeeID'] > 0)) {
826 $attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus
827 FROM ".ATTENDEES_TABLE."
828 WHERE id = %d", $_POST['attendeeID']));
829 if($attendee != null) {
830 $output = RSVP_START_CONTAINER;
831 if(strtolower($attendee->rsvpStatus) == "noresponse") {
832 $output .= RSVP_START_PARA.__("Hi", 'rsvp-plugin')." ".htmlspecialchars(stripslashes($attendee->firstName." ".$attendee->lastName))."!".RSVP_END_PARA;
833
834 if(trim(get_option(OPTION_WELCOME_TEXT)) != "") {
835 $output .= RSVP_START_PARA.trim(get_option(OPTION_WELCOME_TEXT)).RSVP_END_PARA;
836 } else {
837 $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;
838 }
839
840 $output .= rsvp_frontend_main_form($attendee->id);
841 } else {
842 $output .= rsvp_frontend_prompt_to_edit($attendee);
843 }
844 return rsvp_handle_output($text, $output.RSVP_END_CONTAINER);
845 }
846
847 return rsvp_handle_output($text, rsvp_frontend_greeting());
848 } else {
849 return rsvp_handle_output($text, rsvp_frontend_greeting());
850 }
851 }
852
853
854
855 function frontend_rsvp_thankyou($thankYouPrimary, $thankYouAssociated) {
856 $customTy = get_option(OPTION_THANKYOU);
857 if(!empty($customTy)) {
858 return nl2br($customTy);
859 } else {
860 $tyText = __("Thank you", 'rsvp-plugin');
861 if(!empty($thankYouPrimary)) {
862 $tyText .= " ".htmlspecialchars($thankYouPrimary);
863 }
864 $tyText .= __(" for RSVPing.", 'rsvp-plugin');
865
866 if(count($thankYouAssociated) > 0) {
867 $tyText .= __(" You have also RSVPed for - ", 'rsvp-plugin');
868 foreach($thankYouAssociated as $name) {
869 $tyText .= htmlspecialchars(" ".$name).", ";
870 }
871 $tyText = rtrim(trim($tyText), ",").".";
872 }
873 return RSVP_START_CONTAINER.RSVP_START_PARA.$tyText.RSVP_END_PARA.RSVP_END_CONTAINER;
874 }
875 }
876
877 function rsvp_frontend_new_atendee_thankyou($thankYouPrimary, $thankYouAssociated, $password = "") {
878 /*$customTy = get_option(OPTION_THANKYOU);
879 if(!empty($customTy)) {
880 return nl2br($customTy);
881 } else {*/
882 $thankYouText = __("Thank you ", 'rsvp-plugin');
883 if(!empty($thankYouPrimary)) {
884 $thankYouText .= htmlspecialchars($thankYouPrimary);
885 }
886 $thankYouText .= __(" for RSVPing. To modify your RSVP just come back ".
887 "to this page and enter in your first and last name.", 'rsvp-plugin');
888 if(!empty($password)) {
889 $thankYouText .= __(" You will also need to know your password which is", 'rsvp-plugin').
890 " - <strong>$password</strong>";
891 }
892
893 if(count($thankYouAssociated) > 0) {
894 $thankYouText .= __("<br /><br />You have also RSVPed for - ", 'rsvp-plugin');
895 foreach($thankYouAssociated as $name) {
896 $thankYouText .= htmlspecialchars(" ".$name).", ";
897 }
898 $thankYouText = rtrim(trim($thankYouText), ",").".";
899 }
900
901 return RSVP_START_CONTAINER.RSVP_START_PARA.$thankYouText.RSVP_END_PARA.RSVP_END_CONTAINER;
902 //}
903 }
904
905 function rsvp_chomp_name($name, $maxLength) {
906 for($i = $maxLength; $maxLength >= 1; $i--) {
907 if(strlen($name) >= $i) {
908 return substr($name, 0, $i);
909 }
910 }
911 }
912
913 function rsvp_BeginningFormField($id, $additionalClasses) {
914 return "<div ".(!empty($id) ? "id=\"$id\"" : "")." class=\"rsvpFormField ".(!empty($additionalClasses) ? $additionalClasses : "")."\">";
915 }
916
917 function rsvp_frontend_greeting() {
918 global $rsvp_form_action;
919 $customGreeting = get_option(OPTION_GREETING);
920 $output = RSVP_START_PARA.__("Please enter your first and last name to RSVP.", 'rsvp-plugin').RSVP_END_PARA;
921 $firstName = "";
922 $lastName = "";
923 $passcode = "";
924 if(isset($_SESSION['rsvpFirstName'])) {
925 $firstName = $_SESSION['rsvpFirstName'];
926 }
927 if(isset($_SESSION['rsvpLastName'])) {
928 $lastName = $_SESSION['rsvpLastName'];
929 }
930 if(isset($_SESSION['rsvpPasscode'])) {
931 $passcode = $_SESSION['rsvpPasscode'];
932 }
933 if(!empty($customGreeting)) {
934 $output = RSVP_START_PARA.nl2br($customGreeting).RSVP_END_PARA;
935 }
936
937 $output .= RSVP_START_CONTAINER;
938
939 if(get_option(OPTION_RSVP_OPEN_REGISTRATION) == "Y") {
940 $output .= "<form name=\"rsvpNew\" method=\"post\" id=\"rsvpNew\" action=\"$rsvp_form_action\">\r\n";
941 $output .= " <input type=\"hidden\" name=\"rsvpStep\" value=\"newattendee\" />";
942 $output .= "<input type=\"submit\" value=\"".__("New Attendee Registration", "rsvp-plugin")."\" />\r\n";
943 $output .= "</form>\r\n";
944
945 $output .= "<hr />";
946 $output .= RSVP_START_PARA.__("Need to modify your registration? Start with the below form.", "rsvp-plugin").RSVP_END_PARA;
947 }
948
949 $output .= "<form name=\"rsvp\" method=\"post\" id=\"rsvp\" action=\"$rsvp_form_action\" autocomplete=\"off\">\r\n";
950 $output .= " <input type=\"hidden\" name=\"rsvpStep\" value=\"find\" />";
951 $output .= RSVP_START_PARA."<label for=\"firstName\">".__("First Name", 'rsvp-plugin').":</label>
952 <input type=\"text\" name=\"firstName\" id=\"firstName\" size=\"30\" value=\"".htmlspecialchars($firstName)."\" class=\"required\" />".RSVP_END_PARA;
953 $output .= RSVP_START_PARA."<label for=\"lastName\">".__("Last Name", 'rsvp-plugin').":</label>
954 <input type=\"text\" name=\"lastName\" id=\"lastName\" size=\"30\" value=\"".htmlspecialchars($lastName)."\" class=\"required\" />".RSVP_END_PARA;
955 if(rsvp_require_passcode()) {
956 $output .= RSVP_START_PARA."<label for=\"passcode\">".__("Passcode", 'rsvp-plugin').":</label>
957 <input type=\"password\" name=\"passcode\" id=\"passcode\" size=\"30\" value=\"".htmlspecialchars($passcode)."\" class=\"required\" autocomplete=\"off\" />".RSVP_END_PARA;
958 }
959 $output .= RSVP_START_PARA."<input type=\"submit\" value=\"".__("Complete your RSVP!", 'rsvp-plugin')."\" />".RSVP_END_PARA;
960 $output .= "</form>\r\n";
961 $output .= RSVP_END_CONTAINER;
962 return $output;
963 }
964 ?>
965