PluginProbe
RSVP and Event Management / 1.7.0
RSVP and Event Management v1.7.0
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.0, at rsvp_frontend.inc.php

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