PluginProbe
RSVP and Event Management / 1.7.4
RSVP and Event Management v1.7.4
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.4, at rsvp_frontend.inc.php

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