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

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