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

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