PluginProbe
RSVP and Event Management / 1.5.0
RSVP and Event Management v1.5.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.5.0, at rsvp_frontend.inc.php

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