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

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