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

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