PluginProbe
RSVP and Event Management / 1.7.3
RSVP and Event Management v1.7.3
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.3, at rsvp_frontend.inc.php

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