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

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