forked from WPChill/rsvp
/
rsvp_frontend.inc.php
1149 lines (1022 loc) · 56 KB
/
rsvp_frontend.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
$rsvp_form_action = htmlspecialchars(rsvp_getCurrentPageURL());
if(get_option(OPTION_RSVP_DONT_USE_HASH) != "Y") {
$rsvp_form_action .= "#rsvpArea";
}
$rsvp_saved_form_vars = array();
// load some defaults
$rsvp_saved_form_vars['mainRsvp'] = "";
$rsvp_saved_form_vars['rsvp_note'] = "";
function rsvp_handle_output ($intialText, $rsvpText) {
$rsvpText = "<a name=\"rsvpArea\" id=\"rsvpArea\"></a>".$rsvpText;
remove_filter("the_content", "wpautop");
return str_replace(RSVP_FRONTEND_TEXT_CHECK, $rsvpText, $intialText);
}
function rsvp_frontend_handler($text) {
global $wpdb;
$passcodeOptionEnabled = (rsvp_require_passcode()) ? true : false;
//QUIT if the replacement string doesn't exist
if (!strstr($text,RSVP_FRONTEND_TEXT_CHECK)) return $text;
// See if we should allow people to RSVP, etc...
$openDate = get_option(OPTION_OPENDATE);
$closeDate = get_option(OPTION_DEADLINE);
if((strtotime($openDate) !== false) && (strtotime($openDate) > time())) {
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>%s</strong>".RSVP_END_PARA, 'rsvp-plugin'), date("m/d/Y", strtotime($openDate))));
}
if((strtotime($closeDate) !== false) && (strtotime($closeDate) < time())) {
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'));
}
if(isset($_POST['rsvpStep'])) {
$output = "";
switch(strtolower($_POST['rsvpStep'])) {
case("newattendee"):
return rsvp_handlenewattendee($output, $text);
break;
case("addattendee"):
return rsvp_handleNewRsvp($output, $text);
break;
case("handlersvp") :
$output = rsvp_handlersvp($output, $text);
if(!empty($output))
return $output;
break;
case("editattendee") :
$output = rsvp_editAttendee($output, $text);
if(!empty($output))
return $output;
break;
case("foundattendee") :
$output = rsvp_foundAttendee($output, $text);
if(!empty($output))
return $output;
break;
case("find") :
$output = rsvp_find($output, $text);
if(!empty($output))
return $output;
break;
case("newsearch"):
default:
return rsvp_handle_output($text, rsvp_frontend_greeting());
break;
}
} else {
return rsvp_handle_output($text, rsvp_frontend_greeting());
}
}
function rsvp_handlenewattendee($output, $text) {
$output = RSVP_START_CONTAINER;
$output .= rsvp_frontend_main_form(0, "addAttendee");
$output .= RSVP_END_CONTAINER;
return rsvp_handle_output($text, $output);
}
function rsvp_handleAdditionalQuestions($attendeeID, $formName) {
global $wpdb;
$wpdb->query($wpdb->prepare("DELETE FROM ".ATTENDEE_ANSWERS." WHERE attendeeID = %d ", $attendeeID));
$qRs = $wpdb->get_results("SELECT q.id, questionType FROM ".QUESTIONS_TABLE." q
INNER JOIN ".QUESTION_TYPE_TABLE." qt ON qt.id = q.questionTypeID
ORDER BY q.sortOrder");
if(count($qRs) > 0) {
foreach($qRs as $q) {
if(isset($_POST[$formName.$q->id]) && !empty($_POST[$formName.$q->id])) {
if($q->questionType == QT_MULTI) {
$selectedAnswers = "";
$aRs = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $q->id));
if(count($aRs) > 0) {
foreach($aRs as $a) {
if(in_array($a->id, $_POST[$formName.$q->id])) {
$selectedAnswers .= ((strlen($selectedAnswers) == "0") ? "" : "||").stripslashes($a->answer);
}
}
}
if(!empty($selectedAnswers)) {
$wpdb->insert(ATTENDEE_ANSWERS, array("attendeeID" => $attendeeID,
"answer" => stripslashes($selectedAnswers),
"questionID" => $q->id),
array('%d', '%s', '%d'));
rsvp_printQueryDebugInfo();
}
} else if (($q->questionType == QT_DROP) || ($q->questionType == QT_RADIO)) {
$aRs = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $q->id));
if(count($aRs) > 0) {
foreach($aRs as $a) {
if($a->id == $_POST[$formName.$q->id]) {
$wpdb->insert(ATTENDEE_ANSWERS, array("attendeeID" => $attendeeID,
"answer" => stripslashes($a->answer),
"questionID" => $q->id),
array('%d', '%s', '%d'));
rsvp_printQueryDebugInfo();
break;
}
}
}
} else {
$wpdb->insert(ATTENDEE_ANSWERS, array("attendeeID" => $attendeeID,
"answer" => $_POST[$formName.$q->id],
"questionID" => $q->id),
array('%d', '%s', '%d'));
rsvp_printQueryDebugInfo();
}
}
}
}
}
function rsvp_frontend_prompt_to_edit($attendee) {
global $rsvp_form_action;
$prompt = RSVP_START_CONTAINER;
$editGreeting = __("Hi %s it looks like you have already RSVP'd. Would you like to edit your reservation?", 'rsvp-plugin');
$prompt .= sprintf(RSVP_START_PARA.$editGreeting.RSVP_END_PARA,
htmlspecialchars(stripslashes($attendee->firstName." ".$attendee->lastName)));
$prompt .= "<form method=\"post\" action=\"$rsvp_form_action\">\r\n
<input type=\"hidden\" name=\"attendeeID\" value=\"".$attendee->id."\" />
<input type=\"hidden\" name=\"rsvpStep\" id=\"rsvpStep\" value=\"editattendee\" />
<input type=\"submit\" value=\"".__("Yes", 'rsvp-plugin')."\" onclick=\"document.getElementById('rsvpStep').value='editattendee';\" />
<input type=\"submit\" value=\"".__("No", 'rsvp-plugin')."\" onclick=\"document.getElementById('rsvpStep').value='newsearch';\" />
</form>\r\n";
$prompt .= RSVP_END_CONTAINER;
return $prompt;
}
function rsvp_frontend_main_form($attendeeID, $rsvpStep = "handleRsvp") {
global $wpdb, $rsvp_form_action, $rsvp_saved_form_vars;
$attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, email, rsvpStatus, note, kidsMeal, additionalAttendee, veggieMeal, personalGreeting
FROM ".ATTENDEES_TABLE."
WHERE id = %d", $attendeeID));
$sql = "SELECT id FROM ".ATTENDEES_TABLE."
WHERE (id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d))
AND additionalAttendee = 'Y'";
$newRsvps = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID));
$yesText = __("Yes", 'rsvp-plugin');
$noText = __("No", 'rsvp-plugin');
$yesVerbiage = ((trim(get_option(OPTION_YES_VERBIAGE)) != "") ? get_option(OPTION_YES_VERBIAGE) :
__("Yes, of course I will be there! Who doesn't like family, friends, weddings, and a good time?", 'rsvp-plugin'));
$noVerbiage = ((trim(get_option(OPTION_NO_VERBIAGE)) != "") ? get_option(OPTION_NO_VERBIAGE) :
__("Um, unfortunately, there is a Star Trek marathon on that day that I just cannot miss.", 'rsvp-plugin'));
$kidsVerbiage = ((trim(get_option(OPTION_KIDS_MEAL_VERBIAGE)) != "") ? get_option(OPTION_KIDS_MEAL_VERBIAGE) :
__("We have the option of getting cheese pizza for the kids (and only kids). Do you want pizza instead of \"adult food?\"", 'rsvp-plugin'));
$veggieVerbiage = ((trim(get_option(OPTION_VEGGIE_MEAL_VERBIAGE)) != "") ? get_option(OPTION_VEGGIE_MEAL_VERBIAGE) :
__("We also have the option of getting individual vegetarian meals instead of the fish or meat. Would you like a vegetarian dinner?", 'rsvp-plugin'));
$noteVerbiage = ((trim(get_option(OPTION_NOTE_VERBIAGE)) != "") ? get_option(OPTION_NOTE_VERBIAGE) :
__("If you have any <strong style=\"color:red;\">food allergies</strong>, please indicate what they are in the "notes" 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'));
$form = "<form id=\"rsvpForm\" name=\"rsvpForm\" method=\"post\" action=\"$rsvp_form_action\" autocomplete=\"off\">";
$form .= " <input type=\"hidden\" name=\"attendeeID\" value=\"".$attendeeID."\" />";
$form .= " <input type=\"hidden\" name=\"rsvpStep\" value=\"$rsvpStep\" />";
// New Attendee fields when open registration is allowed
if($attendeeID <= 0) {
$form .= RSVP_START_PARA;
$form .= rsvp_BeginningFormField("", "").
"<label for=\"attendeeFirstName\">".__("First Name: ", 'rsvp-plugin')."</label>".
"<input type=\"text\" name=\"attendeeFirstName\" id=\"attendeeFirstName\" value=\"".htmlspecialchars($rsvp_saved_form_vars['attendeeFirstName'])."\" />".
RSVP_END_FORM_FIELD;
$form .= RSVP_END_PARA;
$form .= RSVP_START_PARA;
$form .= rsvp_BeginningFormField("", "").
"<label for=\"attendeeLastName\">".__("Last Name: ", 'rsvp-plugin')."</label>".
"<input type=\"text\" name=\"attendeeLastName\" id=\"attendeeLastName\" value=\"".htmlspecialchars($rsvp_saved_form_vars['attendeeLastName'])."\" />".
RSVP_END_FORM_FIELD;
$form .= RSVP_END_PARA;
}
$form .= RSVP_START_PARA;
if(trim(get_option(OPTION_RSVP_QUESTION)) != "") {
$form .= trim(get_option(OPTION_RSVP_QUESTION));
} else {
$form .= __("So, how about it?", 'rsvp-plugin');
}
$form .= RSVP_END_PARA.
rsvp_BeginningFormField("", "").
"<input type=\"radio\" name=\"mainRsvp\" value=\"Y\" id=\"mainRsvpY\" ".((($attendee->rsvpStatus == "No") || ($rsvp_saved_form_vars['mainRsvp'] == "N")) ? "" : "checked=\"checked\"")." /> <label for=\"mainRsvpY\">".$yesVerbiage."</label>".
RSVP_END_FORM_FIELD.
rsvp_BeginningFormField("", "").
"<input type=\"radio\" name=\"mainRsvp\" value=\"N\" id=\"mainRsvpN\" ".((($attendee->rsvpStatus == "No") || ($rsvp_saved_form_vars['mainRsvp'] == "N")) ? "checked=\"checked\"" : "")." /> ".
"<label for=\"mainRsvpN\">".$noVerbiage."</label>".
RSVP_END_FORM_FIELD;
if(!empty($attendee->personalGreeting)) {
$form .= rsvp_BeginningFormField("rsvpCustomGreeting", "").nl2br(stripslashes($attendee->personalGreeting)).RSVP_END_FORM_FIELD;
}
if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {
$form .= rsvp_BeginningFormField("", "rsvpBorderTop").
RSVP_START_PARA.$kidsVerbiage.RSVP_END_PARA.
"<input type=\"radio\" name=\"mainKidsMeal\" value=\"Y\" id=\"mainKidsMealY\" ".
((($attendee->kidsMeal == "Y") || ($rsvp_saved_form_vars['mainKidsMeal'] == "Y")) ? "checked=\"checked\"" : "")." /> <label for=\"mainKidsMealY\">$yesText</label> ".
"<input type=\"radio\" name=\"mainKidsMeal\" value=\"N\" id=\"mainKidsMealN\" ".((($attendee->kidsMeal == "Y") || ($rsvp_saved_form_vars['mainKidsMeal'] == "Y")) ? "" : "checked=\"checked\"")." /> <label for=\"mainKidsMealN\">$noText</label>".
RSVP_END_FORM_FIELD;
}
if(get_option(OPTION_HIDE_VEGGIE) != "Y") {
$form .= rsvp_BeginningFormField("", "rsvpBorderTop").
RSVP_START_PARA.$veggieVerbiage.RSVP_END_PARA.
"<input type=\"radio\" name=\"mainVeggieMeal\" value=\"Y\" id=\"mainVeggieMealY\" ".
((($attendee->veggieMeal == "Y") || ($rsvp_saved_form_vars['mainVeggieMeal'] == "Y")) ? "checked=\"checked\"" : "")."/> <label for=\"mainVeggieMealY\">$yesText</label> ".
"<input type=\"radio\" name=\"mainVeggieMeal\" value=\"N\" id=\"mainVeggieMealN\" ".
((($attendee->veggieMeal == "Y") || ($rsvp_saved_form_vars['mainVeggieMeal'] == "Y")) ? "" : "checked=\"checked\"")." /> <label for=\"mainVeggieMealN\">$noText</label>".
RSVP_END_FORM_FIELD;
}
if(get_option(OPTION_RSVP_HIDE_EMAIL_FIELD) != "Y") {
$form .= rsvp_BeginningFormField("", "rsvpBorderTop").
RSVP_START_PARA."<label for=\"mainEmail\">".__("Email Address", 'rsvp-plugin')."</label>".RSVP_END_PARA.
"<input type=\"text\" name=\"mainEmail\" id=\"mainEmail\" value=\"".htmlspecialchars($attendee->email)."\" />".
RSVP_END_FORM_FIELD;
}
$form .= rsvp_buildAdditionalQuestions($attendeeID, "main");
if(get_option(RSVP_OPTION_HIDE_NOTE) != "Y") {
$form .= RSVP_START_PARA.$noteVerbiage.RSVP_END_PARA.
rsvp_BeginningFormField("", "").
"<textarea name=\"rsvp_note\" id=\"rsvp_note\" rows=\"7\" cols=\"50\">".((!empty($attendee->note)) ? $attendee->note : $rsvp_saved_form_vars['rsvp_note'])."</textarea>".RSVP_END_FORM_FIELD;
}
$sql = "SELECT id, firstName, lastName FROM ".ATTENDEES_TABLE."
WHERE (id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d) OR
id IN (SELECT waa1.attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." waa1
INNER JOIN ".ASSOCIATED_ATTENDEES_TABLE." waa2 ON waa2.attendeeID = waa1.attendeeID OR
waa1.associatedAttendeeID = waa2.attendeeID
WHERE waa2.associatedAttendeeID = %d AND waa1.attendeeID <> %d))
AND rsvpStatus <> 'NoResponse'";
$rsvpd = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID, $attendeeID, $attendeeID));
if(count($rsvpd) > 0) {
$form .= "<div class=\"rsvpAdditionalAttendee\">\r\n";
$form .= RSVP_START_PARA.__("The following people associated with you have already registered:", 'rsvp-plugin')." ";
foreach($rsvpd as $r) {
$form .= "<br />".htmlspecialchars($r->firstName." ".$r->lastName);
}
$form .= RSVP_END_PARA;
$form .= "</div>";
}
$sql = "SELECT id, firstName, lastName, email, personalGreeting FROM ".ATTENDEES_TABLE."
WHERE (id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d) OR
id IN (SELECT waa1.attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." waa1
INNER JOIN ".ASSOCIATED_ATTENDEES_TABLE." waa2 ON waa2.attendeeID = waa1.attendeeID OR
waa1.associatedAttendeeID = waa2.attendeeID
WHERE waa2.associatedAttendeeID = %d AND waa1.attendeeID <> %d))
AND rsvpStatus = 'NoResponse'";
$associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID, $attendeeID, $attendeeID));
if(count($associations) > 0) {
$form .= "<h3>".__("The following people are associated with you. At this time you can RSVP for them as well.", 'rsvp-plugin')."</h3>";
foreach($associations as $a) {
if($a->id != $attendeeID) {
$form .= "<div class=\"rsvpAdditionalAttendee\">\r\n";
$form .= "<div class=\"rsvpAdditionalAttendeeQuestions\">\r\n";
$form .= rsvp_BeginningFormField("", "").RSVP_START_PARA.sprintf(__(" Will %s be attending?", 'rsvp-plugin'), htmlspecialchars($a->firstName." ".$a->lastName)).RSVP_END_PARA.
"<input type=\"radio\" name=\"attending".$a->id."\" value=\"Y\" id=\"attending".$a->id."Y\" /> ".
"<label for=\"attending".$a->id."Y\">$yesText</label>
<input type=\"radio\" name=\"attending".$a->id."\" value=\"N\" id=\"attending".$a->id."N\" /> ".
"<label for=\"attending".$a->id."N\">$noText</label>".
RSVP_END_FORM_FIELD;
if(!empty($a->personalGreeting)) {
$form .= RSVP_START_PARA.nl2br($a->personalGreeting).RSVP_END_PARA;
}
if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {
$form .= rsvp_BeginningFormField("", "").
RSVP_START_PARA.sprintf(__("Does %s need a kids meal?", 'rsvp-plugin'), htmlspecialchars($a->firstName)).
RSVP_END_PARA." ".
"<input type=\"radio\" name=\"attending".$a->id."KidsMeal\" value=\"Y\" id=\"attending".$a->id."KidsMealY\" /> ".
"<label for=\"attending".$a->id."KidsMealY\">$yesText</label>
<input type=\"radio\" name=\"attending".$a->id."KidsMeal\" value=\"N\" id=\"attending".$a->id."KidsMealN\" checked=\"checked\" /> ".
"<label for=\"attending".$a->id."KidsMealN\">$noText</label>".RSVP_END_FORM_FIELD;
}
if(get_option(OPTION_HIDE_VEGGIE) != "Y") {
$form .= rsvp_BeginningFormField("", "").
RSVP_START_PARA.sprintf(__("Does %s need a vegetarian meal?", 'rsvp-plugin'), htmlspecialchars($a->firstName)).
RSVP_END_PARA." ".
"<input type=\"radio\" name=\"attending".$a->id."VeggieMeal\" value=\"Y\" id=\"attending".$a->id."VeggieMealY\" /> ".
"<label for=\"attending".$a->id."VeggieMealY\">$yesText</label>
<input type=\"radio\" name=\"attending".$a->id."VeggieMeal\" value=\"N\" id=\"attending".$a->id."VeggieMealN\" checked=\"checked\" /> ".
"<label for=\"attending".$a->id."VeggieMealN\">$noText</label>".RSVP_END_FORM_FIELD;
}
if(get_option(OPTION_RSVP_HIDE_EMAIL_FIELD) != "Y") {
$form .= rsvp_BeginningFormField("", "rsvpBorderTop").
RSVP_START_PARA."<label for=\"attending".$a->id."Email\">".__("Email Address", 'rsvp-plugin')."</label>".RSVP_END_PARA.
"<input type=\"text\" name=\"attending".$a->id."Email\" id=\"attending".$a->id."Email\" value=\"".htmlspecialchars($a->email)."\" />".
RSVP_END_FORM_FIELD;
}
$form .= rsvp_buildAdditionalQuestions($a->id, $a->id);
$form .= "</div>\r\n"; //-- rsvpAdditionalAttendeeQuestions
$form .= "</div>\r\n";
} // if($a->id != ...)
} // foreach($associations...)
}
if(get_option(OPTION_HIDE_ADD_ADDITIONAL) != "Y") {
$text = __("Did we slip up and forget to invite someone? If so, please add him or her here:", 'rsvp-plugin');
if(trim(get_option(OPTION_RSVP_ADD_ADDITIONAL_VERBIAGE)) != "") {
$text = get_option(OPTION_RSVP_ADD_ADDITIONAL_VERBIAGE);
}
$form .= "<h3>$text</h3>\r\n";
$form .= "<div id=\"additionalRsvpContainer\">\r\n
<input type=\"hidden\" name=\"additionalRsvp\" id=\"additionalRsvp\" value=\"".count($newRsvps)."\" />
<div style=\"text-align:right\"><img ".
"src=\"".get_option("siteurl")."/wp-content/plugins/rsvp/plus.png\" width=\"24\" height=\"24\" border=\"0\" id=\"addRsvp\" /></div>".
"</div>";
}
$form .= RSVP_START_PARA."<input type=\"submit\" value=\"RSVP\" />".RSVP_END_PARA;
if(get_option(OPTION_HIDE_ADD_ADDITIONAL) != "Y") {
// TODO: Need to move this into the main JS file but not sure how to do that with the options and the custom questions.
// - Moving the options would be fairly easy. Just set two JS variables in here and then go off of that.
// - No clue on custom questions....
$numGuests = 3;
if(get_option(OPTION_RSVP_NUM_ADDITIONAL_GUESTS) != "") {
$numGuests = get_option(OPTION_RSVP_NUM_ADDITIONAL_GUESTS);
if(!is_numeric($numGuests) || ($numGuests < 0)) {
$numGuests = 3;
}
}
$form .= "<script type=\"text/javascript\" language=\"javascript\">\r\n
function handleAddRsvpClick() {
var numAdditional = jQuery(\"#additionalRsvp\").val();
numAdditional++;
if(numAdditional > ".$numGuests.") {
alert('".__("You have already added ".$numGuests." additional rsvp\'s you can add no more.", 'rsvp-plugin')."');
} else {
jQuery(\"#additionalRsvpContainer\").append(\"<div class=\\\"rsvpAdditionalAttendee\\\">\" + \r\n
\"<div class=\\\"rsvpAdditionalAttendeeQuestions\\\">\" + \r\n
\"<div class=\\\"rsvpFormField\\\">\" + \r\n
\" <label for=\\\"newAttending\" + numAdditional + \"FirstName\\\">".__("Person's first name", 'rsvp-plugin')." </label>\" + \r\n
\" <input type=\\\"text\\\" name=\\\"newAttending\" + numAdditional + \"FirstName\\\" id=\\\"newAttending\" + numAdditional + \"FirstName\\\" />\" + \r\n
\"</div>\" + \r\n
\"<div class=\\\"rsvpFormField\\\">\" + \r\n
\" <label for=\\\"newAttending\" + numAdditional + \"LastName\\\">".__("Person's last name", 'rsvp-plugin')."</label>\" + \r\n
\" <input type=\\\"text\\\" name=\\\"newAttending\" + numAdditional + \"LastName\\\" id=\\\"newAttending\" + numAdditional + \"LastName\\\" />\" + \r\n
\"</div>\" + \r\n";
if(get_option(OPTION_RSVP_HIDE_EMAIL_FIELD) != "Y") {
$form .= "\"<div class=\\\"rsvpFormField\\\">\" + \r\n
\" <label for=\\\"newAttending\" + numAdditional + \"Email\\\">".__("Person's email address", 'rsvp-plugin')."</label>\" + \r\n
\" <input type=\\\"text\\\" name=\\\"newAttending\" + numAdditional + \"Email\\\" id=\\\"newAttending\" + numAdditional + \"Email\\\" />\" + \r\n
\"</div>\" + \r\n";
}
$form .= "\"<div class=\\\"rsvpFormField\\\">\" + \r\n
\"<p>Will this person be attending?</p>\" + \r\n
\"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"\\\" value=\\\"Y\\\" id=\\\"newAttending\" + numAdditional + \"Y\\\" checked=\\\"checked\\\" /> \" +
\"<label for=\\\"newAttending\" + numAdditional + \"Y\\\">$yesText</label> \" +
\"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"\\\" value=\\\"N\\\" id=\\\"newAttending\" + numAdditional + \"N\\\"> <label for=\\\"newAttending\" + numAdditional + \"N\\\">$noText</label>\" +
\"</div>\" + \r\n";
if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {
$form .= "\"<div class=\\\"rsvpFormField\\\">\" +
\"<p>".__("Does this person need a kids meal?", 'rsvp-plugin')."</p>\" +
\"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"KidsMeal\\\" value=\\\"Y\\\" id=\\\"newAttending\" + numAdditional + \"KidsMealY\\\" /> \" +
\"<label for=\\\"newAttending\" + numAdditional + \"KidsMealY\\\">$yesText</label> \" +
\"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"KidsMeal\\\" value=\\\"N\\\" id=\\\"newAttending\" + numAdditional + \"KidsMealN\\\" checked=\\\"checked\\\" /> \" +
\"<label for=\\\"newAttending\" + numAdditional + \"KidsMealN\\\">$noText</label>\" +
\"</div>\" +
\"</div>\" + \r\n";
}
if(get_option(OPTION_HIDE_VEGGIE) != "Y") {
$form .= "\"<div class=\\\"rsvpFormField\\\">\" + \r\n
\"<p>".__("Does this person need a vegetarian meal?", 'rsvp-plugin')."</p>\" +
\"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"VeggieMeal\\\" value=\\\"Y\\\" id=\\\"newAttending\" + numAdditional + \"VeggieMealY\\\" /> \" +
\"<label for=\\\"newAttending\" + numAdditional + \"VeggieMealY\\\">$yesText</label> \" +
\"<input type=\\\"radio\\\" name=\\\"newAttending\" + numAdditional + \"VeggieMeal\\\" value=\\\"N\\\" id=\\\"newAttending\" + numAdditional + \"VeggieMealN\\\" checked=\\\"checked\\\" /> \" +
\"<label for=\\\"newAttending\" + numAdditional + \"VeggieMealN\\\">$noText</label>\" +
\"</div>\" + ";
}
$tmpVar = str_replace("\r\n", "", str_replace("|", "\"", addSlashes(rsvp_buildAdditionalQuestions($attendeeID, "| + numAdditional + |"))));
$form .= "\"".$tmpVar."\" +
\"<p><button onclick=\\\"removeAdditionalRSVP(this);\\\">Remove Guest</button></p>\" +
\"</div>\");
jQuery(\"#additionalRsvp\").val(numAdditional);
}
}
function removeAdditionalRSVP(rsvp) {
var numAdditional = jQuery(\"#additionalRsvp\").val();
numAdditional--;
jQuery(rsvp).parent().parent().remove();
jQuery(\"#additionalRsvp\").val(numAdditional);
}
</script>\r\n";
}
$form .= "</form>\r\n";
return $form;
}
function rsvp_revtrievePreviousAnswer($attendeeID, $questionID) {
global $wpdb;
$answers = "";
if(($attendeeID > 0) && ($questionID > 0)) {
$rs = $wpdb->get_results($wpdb->prepare("SELECT answer FROM ".ATTENDEE_ANSWERS." WHERE questionID = %d AND attendeeID = %d", $questionID, $attendeeID));
if(count($rs) > 0) {
$answers = stripslashes($rs[0]->answer);
}
}
return $answers;
}
function rsvp_buildAdditionalQuestions($attendeeID, $prefix) {
global $wpdb, $rsvp_saved_form_vars;
$output = "<div class=\"rsvpCustomQuestions\">";
$sql = "SELECT q.id, q.question, questionType FROM ".QUESTIONS_TABLE." q
INNER JOIN ".QUESTION_TYPE_TABLE." qt ON qt.id = q.questionTypeID
WHERE q.permissionLevel = 'public'
OR (q.permissionLevel = 'private' AND q.id IN (SELECT questionID FROM ".QUESTION_ATTENDEES_TABLE." WHERE attendeeID = $attendeeID))
ORDER BY q.sortOrder ";
$questions = $wpdb->get_results($sql);
if(count($questions) > 0) {
foreach($questions as $q) {
$oldAnswer = rsvp_revtrievePreviousAnswer($attendeeID, $q->id);
$output .= rsvp_BeginningFormField("", "").RSVP_START_PARA.stripslashes($q->question).RSVP_END_PARA;
if($q->questionType == QT_MULTI) {
$oldAnswers = explode("||", $oldAnswer);
$answers = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $q->id));
if(count($answers) > 0) {
$i = 0;
foreach($answers as $a) {
$output .= rsvp_BeginningFormField("", "rsvpCheckboxCustomQ")."<input type=\"checkbox\" name=\"".$prefix."question".$q->id."[]\" id=\"".$prefix."question".$q->id.$a->id."\" value=\"".$a->id."\" "
.((in_array(stripslashes($a->answer), $oldAnswers)) ? " checked=\"checked\"" : "")." />".
"<label for=\"".$prefix."question".$q->id.$a->id."\">".stripslashes($a->answer)."</label>\r\n".RSVP_END_FORM_FIELD;
$i++;
}
$output .= "<div class=\"rsvpClear\"> </div>\r\n";
}
} else if ($q->questionType == QT_DROP) {
//$oldAnswers = explode("||", $oldAnswer);
$output .= "<select name=\"".$prefix."question".$q->id."\" size=\"1\">\r\n".
"<option value=\"\">--</option>\r\n";
$answers = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $q->id));
if(count($answers) > 0) {
foreach($answers as $a) {
$output .= "<option value=\"".$a->id."\" ".((stripslashes($a->answer) == $oldAnswer) ? " selected=\"selected\"" : "").">".stripslashes($a->answer)."</option>\r\n";
}
}
$output .= "</select>\r\n";
} else if ($q->questionType == QT_LONG) {
$output .= "<textarea name=\"".$prefix."question".$q->id."\" rows=\"5\" cols=\"35\">".htmlspecialchars($oldAnswer)."</textarea>";
} else if ($q->questionType == QT_RADIO) {
//$oldAnswers = explode("||", $oldAnswer);
$answers = $wpdb->get_results($wpdb->prepare("SELECT id, answer FROM ".QUESTION_ANSWERS_TABLE." WHERE questionID = %d", $q->id));
if(count($answers) > 0) {
$i = 0;
$output .= RSVP_START_PARA;
foreach($answers as $a) {
$output .= "<input type=\"radio\" name=\"".$prefix."question".$q->id."\" id=\"".$prefix."question".$q->id.$a->id."\" value=\"".$a->id."\" "
.((stripslashes($a->answer) == $oldAnswer) ? " checked=\"checked\"" : "")." /> ".
"<label for=\"".$prefix."question".$q->id.$a->id."\">".stripslashes($a->answer)."</label>\r\n";
$i++;
}
$output .= RSVP_END_PARA;
}
} else {
// normal text input
$output .= "<input type=\"text\" name=\"".$prefix."question".$q->id."\" value=\"".htmlspecialchars($oldAnswer)."\" size=\"25\" />";
}
$output .= RSVP_END_FORM_FIELD;
}
}
return $output."</div>";
}
function rsvp_find(&$output, &$text) {
global $wpdb, $rsvp_form_action;
$passcodeOptionEnabled = (rsvp_require_passcode()) ? true : false;
$passcodeOnlyOption = (rsvp_require_only_passcode_to_register()) ? true : false;
$_SESSION['rsvpFirstName'] = $_POST['firstName'];
$_SESSION['rsvpLastName'] = $_POST['lastName'];
$passcode = "";
if(isset($_POST['passcode'])) {
$passcode = $_POST['passcode'];
$_SESSION['rsvpPasscode'] = $_POST['passcode'];
}
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
if(!$passcodeOnlyOption && ((strlen($_POST['firstName']) <= 1) || (strlen($_POST['lastName']) <= 1))) {
$output = "<p class=\"rsvpParagraph\" style=\"color:red\">".__("A first and last name must be specified", 'rsvp-plugin')."</p>\r\n";
$output .= rsvp_frontend_greeting();
return rsvp_handle_output($text, $output);
}
// Try to find the user.
if($passcodeOptionEnabled) {
if($passcodeOnlyOption) {
$attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus
FROM ".ATTENDEES_TABLE."
WHERE passcode = %s", $passcode));
} else {
$attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus
FROM ".ATTENDEES_TABLE."
WHERE firstName = %s AND lastName = %s AND passcode = %s", $firstName, $lastName, $passcode));
}
} else {
$attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus
FROM ".ATTENDEES_TABLE."
WHERE firstName = %s AND lastName = %s", $firstName, $lastName));
}
if($attendee != null) {
// hey we found something, we should move on and print out any associated users and let them rsvp
$output = "<div>\r\n";
if(strtolower($attendee->rsvpStatus) == "noresponse") {
$output .= RSVP_START_PARA."Hi ".htmlspecialchars(stripslashes($attendee->firstName." ".$attendee->lastName))."!".RSVP_END_PARA;
if(trim(get_option(OPTION_WELCOME_TEXT)) != "") {
$output .= RSVP_START_PARA.trim(get_option(OPTION_WELCOME_TEXT)).RSVP_END_PARA;
} else {
$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;
}
$output .= rsvp_frontend_main_form($attendee->id);
} else {
$output .= rsvp_frontend_prompt_to_edit($attendee);
}
return rsvp_handle_output($text, $output."</div>\r\n");
}
// We did not find anyone let's try and do a rough search
$attendees = null;
if(!$passcodeOptionEnabled) {
for($i = 3; $i >= 1; $i--) {
$truncFirstName = rsvp_chomp_name($firstName, $i);
$attendees = $wpdb->get_results("SELECT id, firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE."
WHERE lastName = '".mysql_real_escape_string($lastName)."' AND firstName LIKE '".mysql_real_escape_string($truncFirstName)."%'");
if(count($attendees) > 0) {
$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;
foreach($attendees as $a) {
$output .= "<form method=\"post\" action=\"$rsvp_form_action\">\r\n
<input type=\"hidden\" name=\"rsvpStep\" value=\"foundattendee\" />\r\n
<input type=\"hidden\" name=\"attendeeID\" value=\"".$a->id."\" />\r\n
<p class=\"rsvpParagraph\" style=\"text-align:left;\">\r\n
".htmlspecialchars($a->firstName." ".$a->lastName)."
<input type=\"submit\" value=\"RSVP\" />\r\n
</p>\r\n</form>\r\n";
}
return rsvp_handle_output($text, $output);
} else {
$i = strlen($truncFirstName);
}
}
}
if(rsvp_require_only_passcode_to_register()) {
$notFoundText = sprintf(__(RSVP_START_PARA.'<strong>We were unable to find anyone with the password you specified.</strong>'.RSVP_END_PARA, 'rsvp-plugin'));
} else {
$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'), htmlspecialchars($firstName), htmlspecialchars($lastName));
}
$notFoundText .= rsvp_frontend_greeting();
return rsvp_handle_output($text, $notFoundText);
}
function rsvp_handleNewRsvp(&$output, &$text) {
global $wpdb, $rsvp_saved_form_vars;
$thankYouPrimary = "";
$thankYouAssociated = array();
foreach($_POST as $key=>$val) {
$rsvp_saved_form_vars[$key] = $val;
}
if(empty($_POST['attendeeFirstName']) || empty($_POST['attendeeLastName'])) {
return rsvp_handlenewattendee($output, $text);
}
$rsvpPassword = "";
$rsvpStatus = "No";
if(strToUpper($_POST['mainRsvp']) == "Y") {
$rsvpStatus = "Yes";
}
$kidsMeal = ((isset($_POST['mainKidsMeal']) && (strToUpper($_POST['mainKidsMeal']) == "Y")) ? "Y" : "N");
$veggieMeal = ((isset($_POST['mainVeggieMeal']) && (strToUpper($_POST['mainVeggieMeal']) == "Y")) ? "Y" : "N");
$thankYouPrimary = $_POST['attendeeFirstName'];
$wpdb->insert(ATTENDEES_TABLE, array("rsvpDate" => date("Y-m-d"),
"firstName" => $_POST['attendeeFirstName'],
"lastName" => $_POST['attendeeLastName'],
"email" => $_POST['mainEmail'],
"rsvpStatus" => $rsvpStatus,
"note" => $_POST['rsvp_note'],
"kidsMeal" => $kidsMeal,
"veggieMeal" => $veggieMeal),
array("%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s"));
rsvp_printQueryDebugInfo();
$attendeeID = $wpdb->insert_id;
if(rsvp_require_passcode()) {
$rsvpPassword = trim(rsvp_generate_passcode());
$wpdb->update(ATTENDEES_TABLE,
array("passcode" => $rsvpPassword),
array("id"=>$attendeeID),
array("%s"),
array("%d"));
}
rsvp_handleAdditionalQuestions($attendeeID, "mainquestion");
$sql = "SELECT id, firstName FROM ".ATTENDEES_TABLE."
WHERE (id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d))
AND rsvpStatus = 'NoResponse'";
$associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID));
foreach($associations as $a) {
if(isset($_POST['attending'.$a->id]) && (($_POST['attending'.$a->id] == "Y") || ($_POST['attending'.$a->id] == "N"))) {
if($_POST['attending'.$a->id] == "Y") {
$rsvpStatus = "Yes";
} else {
$rsvpStatus = "No";
}
$thankYouAssociated[] = stripslashes($a->firstName);
$wpdb->update(ATTENDEES_TABLE, array("rsvpDate" => date("Y-m-d"),
"rsvpStatus" => $rsvpStatus,
"email" => $_POST['attending'.$a->id."Email"],
"kidsMeal" => ((strToUpper((isset($_POST['attending'.$a->id.'KidsMeal']) ? $_POST['attending'.$a->id.'KidsMeal'] : "N")) == "Y") ? "Y" : "N"),
"veggieMeal" => ((strToUpper((isset($_POST['attending'.$a->id.'VeggieMeal']) ? $_POST['attending'.$a->id.'VeggieMeal'] : "N")) == "Y") ? "Y" : "N")),
array("id" => $a->id),
array("%s", "%s", "%s", "%s", "%s"),
array("%d"));
rsvp_printQueryDebugInfo();
rsvp_handleAdditionalQuestions($a->id, $a->id."question");
}
}
if(get_option(OPTION_HIDE_ADD_ADDITIONAL) != "Y") {
if(is_numeric($_POST['additionalRsvp']) && ($_POST['additionalRsvp'] > 0)) {
for($i = 1; $i <= $_POST['additionalRsvp']; $i++) {
$numGuests = 3;
if(get_option(OPTION_RSVP_NUM_ADDITIONAL_GUESTS) != "") {
$numGuests = get_optioN(OPTION_RSVP_NUM_ADDITIONAL_GUESTS);
if(!is_numeric($numGuests) || ($numGuests < 0)) {
$numGuests = 3;
}
}
if(($i <= $numGuests) &&
!empty($_POST['newAttending'.$i.'FirstName']) &&
!empty($_POST['newAttending'.$i.'LastName'])) {
$thankYouAssociated[] = $_POST['newAttending'.$i.'FirstName'];
$wpdb->insert(ATTENDEES_TABLE, array("firstName" => trim($_POST['newAttending'.$i.'FirstName']),
"lastName" => trim($_POST['newAttending'.$i.'LastName']),
"email" => trim($_POST['newAttending'.$i."Email"]),
"rsvpDate" => date("Y-m-d"),
"rsvpStatus" => (($_POST['newAttending'.$i] == "Y") ? "Yes" : "No"),
"kidsMeal" => (isset($_POST['newAttending'.$i.'KidsMeal']) ? $_POST['newAttending'.$i.'KidsMeal'] : "N"),
"veggieMeal" => (isset($_POST['newAttending'.$i.'VeggieMeal']) ? $_POST['newAttending'.$i.'VeggieMeal'] : "N"),
"additionalAttendee" => "Y"),
array('%s', '%s', '%s', '%s', '%s', '%s', '%s'));
rsvp_printQueryDebugInfo();
$newAid = $wpdb->insert_id;
rsvp_handleAdditionalQuestions($newAid, $i.'question');
// Add associations for this new user
$wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID" => $newAid,
"associatedAttendeeID" => $attendeeID),
array("%d", "%d"));
rsvp_printQueryDebugInfo();
$wpdb->query("INSERT INTO ".ASSOCIATED_ATTENDEES_TABLE."(attendeeID, associatedAttendeeID)
SELECT ".$newAid.", associatedAttendeeID
FROM ".ASSOCIATED_ATTENDEES_TABLE."
WHERE attendeeID = ".$attendeeID);
rsvp_printQueryDebugInfo();
}
}
}
}
if((get_option(OPTION_NOTIFY_ON_RSVP) == "Y") && (get_option(OPTION_NOTIFY_EMAIL) != "")) {
$sql = "SELECT firstName, lastName, rsvpStatus, note, kidsMeal, veggieMeal FROM ".ATTENDEES_TABLE." WHERE id= ".$attendeeID;
$attendee = $wpdb->get_results($sql);
if(count($attendee) > 0) {
$body = "Hello, \r\n\r\n";
$body .= stripslashes($attendee[0]->firstName)." ".stripslashes($attendee[0]->lastName).
" has submitted their RSVP and has RSVP'd with '".$attendee[0]->rsvpStatus."'.\r\n";
if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {
$body .= "Kids Meal: ".$attendee[0]->kidsMeal."\r\n";
}
if(get_option(OPTION_HIDE_VEGGIE) != "Y") {
$body .= "Vegetarian Meal: ".$attendee[0]->veggieMeal."\r\n";
}
if(get_option(RSVP_OPTION_HIDE_NOTE) != "Y") {
$body .= "Note: ".stripslashes($attendee[0]->note)."\r\n";
}
$sql = "SELECT question, answer FROM ".QUESTIONS_TABLE." q
LEFT JOIN ".ATTENDEE_ANSWERS." ans ON q.id = ans.questionID AND ans.attendeeID = %d
ORDER BY q.sortOrder, q.id";
$aRs = $wpdb->get_results($wpdb->prepare($sql, $attendeeID));
if(count($aRs) > 0) {
$body .= "\r\n\r\n--== Custom Questions ==--\r\n";
foreach($aRs as $a) {
$body .= stripslashes($a->question).": ".stripslashes($a->answer)."\r\n";
}
}
$sql = "SELECT firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE."
WHERE id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d)";
$associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID));
if(count($associations) > 0) {
foreach($associations as $a) {
$body .= "\r\n\r\n--== Associated Attendees ==--\r\n";
$body .= stripslashes($a->firstName." ".$a->lastName)." rsvp status: ".$a->rsvpStatus."\r\n";
}
}
$emailAddy = get_option(OPTION_NOTIFY_EMAIL);
$headers = "";
if(get_option(OPTION_RSVP_DISABLE_CUSTOM_EMAIL_FROM) != "Y")
$headers = 'From: '. $emailAddy . "\r\n";
wp_mail($emailAddy, "New RSVP Submission", $body, $headers);
}
}
if((get_option(OPTION_RSVP_GUEST_EMAIL_CONFIRMATION) == "Y") && !empty($_POST['mainEmail'])) {
$sql = "SELECT firstName, lastName, email, rsvpStatus FROM ".ATTENDEES_TABLE." WHERE id= ".$attendeeID;
$attendee = $wpdb->get_results($sql);
if(count($attendee) > 0) {
$body = "Hello ".stripslashes($attendee[0]->firstName)." ".stripslashes($attendee[0]->lastName).", \r\n\r\n";
$body .= "You have successfully RSVP'd with '".$attendee[0]->rsvpStatus."'.";
$sql = "SELECT firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE."
WHERE id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d)";
$associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID));
if(count($associations) > 0) {
foreach($associations as $a) {
$body .= "\r\n\r\n--== Associated Attendees ==--\r\n";
$body .= stripslashes($a->firstName." ".$a->lastName)." rsvp status: ".$a->rsvpStatus."\r\n";
}
}
$emailAddy = get_option(OPTION_NOTIFY_EMAIL);
$headers = "";
if(!empty($emailAddy) && (get_option(OPTION_RSVP_DISABLE_CUSTOM_EMAIL_FROM) != "Y")) {
$headers = 'From: '. $emailAddy . "\r\n";
}
wp_mail($attendee[0]->email, "RSVP Confirmation", $body, $headers);
}
}
return rsvp_handle_output($text, rsvp_frontend_new_atendee_thankyou($thankYouPrimary, $thankYouAssociated, $rsvpPassword));
}
function rsvp_handlersvp(&$output, &$text) {
global $wpdb;
$thankYouPrimary = "";
$thankYouAssociated = array();
if(is_numeric($_POST['attendeeID']) && ($_POST['attendeeID'] > 0)) {
// update their information and what not....
if(strToUpper($_POST['mainRsvp']) == "Y") {
$rsvpStatus = "Yes";
} else {
$rsvpStatus = "No";
}
$attendeeID = $_POST['attendeeID'];
// Get Attendee first name
$thankYouPrimary = $wpdb->get_var($wpdb->prepare("SELECT firstName FROM ".ATTENDEES_TABLE." WHERE id = %d", $attendeeID));
$wpdb->update(ATTENDEES_TABLE, array("rsvpDate" => date("Y-m-d"),
"rsvpStatus" => $rsvpStatus,
"note" => $_POST['rsvp_note'],
"email" => $_POST['mainEmail'],
"kidsMeal" => ((isset($_POST['mainKidsMeal']) && (strToUpper($_POST['mainKidsMeal']) == "Y")) ? "Y" : "N"),
"veggieMeal" => ((isset($_POST['mainVeggieMeal']) && (strToUpper($_POST['mainVeggieMeal']) == "Y")) ? "Y" : "N")),
array("id" => $attendeeID),
array("%s", "%s", "%s", "%s", "%s", "%s"),
array("%d"));
rsvp_printQueryDebugInfo();
rsvp_handleAdditionalQuestions($attendeeID, "mainquestion");
$sql = "SELECT id, firstName FROM ".ATTENDEES_TABLE."
WHERE (id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d))
AND rsvpStatus = 'NoResponse'";
$associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID));
foreach($associations as $a) {
if(isset($_POST['attending'.$a->id]) && (($_POST['attending'.$a->id] == "Y") || ($_POST['attending'.$a->id] == "N"))) {
$thankYouAssociated[] = $a->firstName;
if($_POST['attending'.$a->id] == "Y") {
$rsvpStatus = "Yes";
} else {
$rsvpStatus = "No";
}
$wpdb->update(ATTENDEES_TABLE, array("rsvpDate" => date("Y-m-d"),
"rsvpStatus" => $rsvpStatus,
"email" => $_POST['attending'.$a->id."Email"],
"kidsMeal" => ((strToUpper((isset($_POST['attending'.$a->id.'KidsMeal']) ? $_POST['attending'.$a->id.'KidsMeal'] : "N")) == "Y") ? "Y" : "N"),
"veggieMeal" => ((strToUpper((isset($_POST['attending'.$a->id.'VeggieMeal']) ? $_POST['attending'.$a->id.'VeggieMeal'] : "N")) == "Y") ? "Y" : "N")),
array("id" => $a->id),
array("%s", "%s", "%s", "%s", "%s"),
array("%d"));
rsvp_printQueryDebugInfo();
rsvp_handleAdditionalQuestions($a->id, $a->id."question");
}
}
if(get_option(OPTION_HIDE_ADD_ADDITIONAL) != "Y") {
if(is_numeric($_POST['additionalRsvp']) && ($_POST['additionalRsvp'] > 0)) {
for($i = 1; $i <= $_POST['additionalRsvp']; $i++) {
$numGuests = 3;
if(get_option(OPTION_RSVP_NUM_ADDITIONAL_GUESTS) != "") {
$numGuests = get_optioN(OPTION_RSVP_NUM_ADDITIONAL_GUESTS);
if(!is_numeric($numGuests) || ($numGuests < 0)) {
$numGuests = 3;
}
}
if(($i <= $numGuests) &&
!empty($_POST['newAttending'.$i.'FirstName']) &&
!empty($_POST['newAttending'.$i.'LastName'])) {
$thankYouAssociated[] = $_POST['newAttending'.$i.'FirstName'];
$wpdb->insert(ATTENDEES_TABLE, array("firstName" => trim($_POST['newAttending'.$i.'FirstName']),
"lastName" => trim($_POST['newAttending'.$i.'LastName']),
"email" => trim($_POST['newAttending'.$i.'Email']),
"rsvpDate" => date("Y-m-d"),
"rsvpStatus" => (($_POST['newAttending'.$i] == "Y") ? "Yes" : "No"),
"kidsMeal" => (isset($_POST['newAttending'.$i.'KidsMeal']) ? $_POST['newAttending'.$i.'KidsMeal'] : "N"),
"veggieMeal" => (isset($_POST['newAttending'.$i.'VeggieMeal']) ? $_POST['newAttending'.$i.'VeggieMeal'] : "N"),
"additionalAttendee" => "Y"),
array('%s', '%s', '%s', '%s', '%s', '%s', '%s'));
rsvp_printQueryDebugInfo();
$newAid = $wpdb->insert_id;
rsvp_handleAdditionalQuestions($newAid, $i.'question');
// Add associations for this new user
$wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID" => $newAid,
"associatedAttendeeID" => $attendeeID),
array("%d", "%d"));
rsvp_printQueryDebugInfo();
$wpdb->query($wpdb->prepare("INSERT INTO ".ASSOCIATED_ATTENDEES_TABLE."(attendeeID, associatedAttendeeID)
SELECT ".$newAid.", associatedAttendeeID
FROM ".ASSOCIATED_ATTENDEES_TABLE."
WHERE attendeeID = %d", $attendeeID));
rsvp_printQueryDebugInfo();
}
}
}
}
$email = get_option(OPTION_NOTIFY_EMAIL);
if((get_option(OPTION_NOTIFY_ON_RSVP) == "Y") && ($email != "")) {
$sql = "SELECT firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE." WHERE id= ".$attendeeID;
$attendee = $wpdb->get_results($sql);
if(count($attendee) > 0) {
$body = "Hello, \r\n\r\n";
$body .= stripslashes($attendee[0]->firstName)." ".stripslashes($attendee[0]->lastName).
" has submitted their RSVP and has RSVP'd with '".$attendee[0]->rsvpStatus."'.";
if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {
$body .= "Kids Meal: ".$attendee[0]->kidsMeal."\r\n";
}
if(get_option(OPTION_HIDE_VEGGIE) != "Y") {
$body .= "Vegetarian Meal: ".$attendee[0]->veggieMeal."\r\n";
}
if(get_option(RSVP_OPTION_HIDE_NOTE) != "Y") {
$body .= "Note: ".stripslashes($attendee[0]->note)."\r\n";
}
$sql = "SELECT question, answer FROM ".QUESTIONS_TABLE." q
LEFT JOIN ".ATTENDEE_ANSWERS." ans ON q.id = ans.questionID AND ans.attendeeID = %d
ORDER BY q.sortOrder, q.id";
$aRs = $wpdb->get_results($wpdb->prepare($sql, $attendeeID));
if(count($aRs) > 0) {
$body .= "\r\n\r\n--== Custom Questions ==--\r\n";
foreach($aRs as $a) {
$body .= stripslashes($a->question).": ".stripslashes($a->answer)."\r\n";
}
}
$sql = "SELECT firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE."
WHERE id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d)";
$associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID));
if(count($associations) > 0) {
$body .= "\r\n\r\n--== Associated Attendees ==--\r\n";
foreach($associations as $a) {
$body .= stripslashes($a->firstName." ".$a->lastName)." RSVP status: ".$a->rsvpStatus."\r\n";
}
}
$headers = "";
if(get_option(OPTION_RSVP_DISABLE_CUSTOM_EMAIL_FROM) != "Y")
$headers = 'From: '. $email . "\r\n";
wp_mail($email, "New RSVP Submission", $body, $headers);
}
}
if((get_option(OPTION_RSVP_GUEST_EMAIL_CONFIRMATION) == "Y") && !empty($_POST['mainEmail'])) {
$sql = "SELECT firstName, lastName, email, rsvpStatus FROM ".ATTENDEES_TABLE." WHERE id= ".$attendeeID;
$attendee = $wpdb->get_results($sql);
if(count($attendee) > 0) {
$body = "Hello ".stripslashes($attendee[0]->firstName)." ".stripslashes($attendee[0]->lastName).", \r\n\r\n";
$body .= "You have successfully RSVP'd with '".$attendee[0]->rsvpStatus."'.";
$sql = "SELECT firstName, lastName, rsvpStatus FROM ".ATTENDEES_TABLE."
WHERE id IN (SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d)
OR id in (SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d)";
$associations = $wpdb->get_results($wpdb->prepare($sql, $attendeeID, $attendeeID));
if(count($associations) > 0) {
foreach($associations as $a) {
$body .= "\r\n\r\n--== Associated Attendees ==--\r\n";
$body .= stripslashes($a->firstName." ".$a->lastName)." rsvp status: ".$a->rsvpStatus."\r\n";
}
}
$headers = "";
if(!empty($email) && (get_option(OPTION_RSVP_DISABLE_CUSTOM_EMAIL_FROM) != "Y")) {
$headers = 'From: '. $email . "\r\n";
}
wp_mail($attendee[0]->email, "RSVP Confirmation", $body, $headers);
}
}
return rsvp_handle_output($text, frontend_rsvp_thankyou($thankYouPrimary, $thankYouAssociated));
} else {
return rsvp_handle_output($text, rsvp_frontend_greeting());
}
}
function rsvp_editAttendee(&$output, &$text) {
global $wpdb;
if(is_numeric($_POST['attendeeID']) && ($_POST['attendeeID'] > 0)) {
// Try to find the user.
$attendee = $wpdb->get_row($wpdb->prepare("SELECT id, firstName, lastName, rsvpStatus
FROM ".ATTENDEES_TABLE."
WHERE id = %d", $_POST['attendeeID']));
if($attendee != null) {
$output .= RSVP_START_CONTAINER;
$output .= RSVP_START_PARA.__("Welcome back", 'rsvp-plugin')." ".htmlspecialchars($attendee->firstName." ".$attendee->lastName)."!".RSVP_END_PARA;
$output .= rsvp_frontend_main_form($attendee->id);
return rsvp_handle_output($text, $output.RSVP_END_CONTAINER);
}
}
}
function rsvp_foundAttendee(&$output, &$text) {
global $wpdb;