forked from WPChill/rsvp
/
wp-rsvp.php
1639 lines (1542 loc) · 80.8 KB
/
wp-rsvp.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
/**
* @package rsvp
* @author MDE Development, LLC
* @version 2.1.1
*/
/*
Plugin Name: RSVP
Text Domain: rsvp-plugin
Plugin URI: http://wordpress.org/extend/plugins/rsvp/
Description: This plugin allows guests to RSVP to an event. It was made initially for weddings but could be used for other things.
Author: MDE Development, LLC
Version: 2.1.1
Author URI: http://www.swimordiesoftware.com
License: GPL
*/
#
# INSTALLATION: see readme.txt
#
# USAGE: Once the RSVP plugin has been installed, you can set the custom text
# via Settings -> RSVP Options in the admin area.
#
# To add, edit, delete and see rsvp status there will be a new RSVP admin
# area just go there.
#
# To allow people to rsvp create a new page and add "rsvp-pluginhere" to the text
define("ATTENDEES_TABLE", $wpdb->prefix."attendees");
define("ASSOCIATED_ATTENDEES_TABLE", $wpdb->prefix."associatedAttendees");
define("QUESTIONS_TABLE", $wpdb->prefix."rsvpCustomQuestions");
define("QUESTION_TYPE_TABLE", $wpdb->prefix."rsvpQuestionTypes");
define("ATTENDEE_ANSWERS", $wpdb->prefix."attendeeAnswers");
define("QUESTION_ANSWERS_TABLE", $wpdb->prefix."rsvpCustomQuestionAnswers");
define("QUESTION_ATTENDEES_TABLE", $wpdb->prefix."rsvpCustomQuestionAttendees");
define("RSVP_FRONTEND_TEXT_CHECK", "rsvp-pluginhere");
define("OPTION_GREETING", "rsvp_custom_greeting");
define("OPTION_THANKYOU", "rsvp_custom_thankyou");
define("OPTION_DEADLINE", "rsvp_deadline");
define("OPTION_OPENDATE", 'rsvp_opendate');
define("OPTION_YES_VERBIAGE", "rsvp_yes_verbiage");
define("OPTION_NO_VERBIAGE", "rsvp_no_verbiage");
define("OPTION_KIDS_MEAL_VERBIAGE", "rsvp_kids_meal_verbiage");
define("OPTION_VEGGIE_MEAL_VERBIAGE", "rsvp_veggie_meal_verbiage");
define("OPTION_NOTE_VERBIAGE", "rsvp_note_verbiage");
define("RSVP_OPTION_HIDE_NOTE", "rsvp_hide_note_field");
define("OPTION_HIDE_VEGGIE", "rsvp_hide_veggie");
define("OPTION_HIDE_KIDS_MEAL", "rsvp_hide_kids_meal");
define("OPTION_HIDE_ADD_ADDITIONAL", "rsvp_hide_add_additional");
define("OPTION_NOTIFY_ON_RSVP", "rsvp_notify_when_rsvp");
define("OPTION_NOTIFY_EMAIL", "rsvp_notify_email_address");
define("OPTION_DEBUG_RSVP_QUERIES", "rsvp_debug_queries");
define("OPTION_WELCOME_TEXT", "rsvp_custom_welcome");
define("OPTION_RSVP_QUESTION", "rsvp_custom_question_text");
define("OPTION_RSVP_CUSTOM_YES_NO", "rsvp_custom_yes_no");
define("OPTION_RSVP_PASSCODE", "rsvp_passcode");
define("OPTION_RSVP_OPEN_REGISTRATION", "rsvp_open_registration");
define("OPTION_RSVP_DONT_USE_HASH", "rsvp_dont_use_has");
define("OPTION_RSVP_ADD_ADDITIONAL_VERBIAGE", "rsvp_add_additional_verbiage");
define("OPTION_RSVP_GUEST_EMAIL_CONFIRMATION", "rsvp_guest_email_confirmation");
define("OPTION_RSVP_NUM_ADDITIONAL_GUESTS", "rsvp_num_additional_guests");
define("OPTION_RSVP_HIDE_EMAIL_FIELD", "rsvp_hide_email_field");
define("OPTION_RSVP_DISABLE_CUSTOM_EMAIL_FROM", "rsvp_disable_custom_from_email");
define("OPTION_RSVP_ONLY_PASSCODE", "rsvp_only_passcode");
define("OPTION_RSVP_EMAIL_TEXT", "rsvp_email_text");
define("OPTION_RSVP_DISABLE_USER_SEARCH", "rsvp_disable_user_search");
define("RSVP_DB_VERSION", "11");
define("QT_SHORT", "shortAnswer");
define("QT_MULTI", "multipleChoice");
define("QT_LONG", "longAnswer");
define("QT_DROP", "dropdown");
define("QT_RADIO", "radio");
define("RSVP_START_PARA", "<p class=\"rsvpParagraph\">");
define("RSVP_END_PARA", "</p>\r\n");
define("RSVP_START_CONTAINER", "<div id=\"rsvpPlugin\">\r\n");
define("RSVP_END_CONTAINER", "</div>\r\n");
define("RSVP_START_FORM_FIELD", "<div class=\"rsvpFormField\">\r\n");
define("RSVP_END_FORM_FIELD", "</div>\r\n");
$my_plugin_file = __FILE__;
if (isset($plugin)) {
$my_plugin_file = $plugin;
}
else if (isset($mu_plugin)) {
$my_plugin_file = $mu_plugin;
}
else if (isset($network_plugin)) {
$my_plugin_file = $network_plugin;
}
define('RSVP_PLUGIN_FILE', $my_plugin_file);
define('RSVP_PLUGIN_PATH', WP_PLUGIN_DIR.'/'.basename(dirname($my_plugin_file)));
if((isset($_GET['page']) && (strToLower($_GET['page']) == 'rsvp-admin-export')) ||
(isset($_POST['rsvp-bulk-action']) && (strToLower($_POST['rsvp-bulk-action']) == "export"))) {
add_action('init', 'rsvp_admin_export');
}
require_once("rsvp_frontend.inc.php");
/*
* Description: Database setup for the rsvp plug-in.
*/
function rsvp_database_setup() {
global $wpdb;
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
require_once("rsvp_db_setup.inc.php");
}
function rsvp_install_passcode_field() {
global $wpdb;
$table = ATTENDEES_TABLE;
$sql = "SHOW COLUMNS FROM `$table` LIKE 'passcode'";
if(!$wpdb->get_results($sql)) {
$sql = "ALTER TABLE `$table` ADD `passcode` VARCHAR(50) NOT NULL DEFAULT '';";
$wpdb->query($sql);
}
}
function rsvp_require_passcode() {
return ((get_option(OPTION_RSVP_PASSCODE) == "Y") || (get_option(OPTION_RSVP_OPEN_REGISTRATION) == "Y") || (get_option(OPTION_RSVP_ONLY_PASSCODE) == "Y"));
}
function rsvp_require_only_passcode_to_register() {
return (get_option(OPTION_RSVP_ONLY_PASSCODE) == "Y");
}
function rsvp_require_unique_passcode() {
return rsvp_require_only_passcode_to_register();
}
function rsvp_is_passcode_unique($passcode, $attendeeID) {
global $wpdb;
$isUnique = false;
$sql = $wpdb->prepare("SELECT * FROM ".ATTENDEES_TABLE." WHERE id <> %d AND passcode = %s", $attendeeID, $passcode);
if(!$wpdb->get_results($sql)) {
$isUnique = true;
}
return $isUnique;
}
/**
* This generates a random 6 character passcode to be used for guests when the option is enabled.
*/
function rsvp_generate_passcode() {
$length = 6;
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$passcode = "";
for ($p = 0; $p < $length; $p++) {
$passcode .= $characters[mt_rand(0, strlen($characters))];
}
return $passcode;
}
function rsvp_admin_guestlist_options() {
global $wpdb;
if(rsvp_require_unique_passcode()) {
$sql = "SELECT id, passcode FROM ".ATTENDEES_TABLE." a WHERE passcode <> '' AND (SELECT COUNT(*) FROM ".ATTENDEES_TABLE." WHERE passcode = a.passcode) > 1";
$attendees = $wpdb->get_results($sql);
foreach($attendees as $a) {
$wpdb->update(ATTENDEES_TABLE,
array("passcode" => rsvp_generate_passcode()),
array("id" => $a->id),
array("%s"),
array("%d"));
}
}
if(rsvp_require_passcode()) {
rsvp_install_passcode_field();
$sql = "SELECT id, passcode FROM ".ATTENDEES_TABLE." WHERE passcode = ''";
$attendees = $wpdb->get_results($sql);
foreach($attendees as $a) {
$wpdb->update(ATTENDEES_TABLE,
array("passcode" => rsvp_generate_passcode()),
array("id" => $a->id),
array("%s"),
array("%d"));
}
}
?>
<script type="text/javascript" language="javascript">
jQuery(document).ready(function() {
jQuery("#rsvp_opendate").datepicker();
jQuery("#rsvp_deadline").datepicker();
});
</script>
<div class="wrap">
<h2><?php echo __("RSVP Guestlist Options", 'rsvp-plugin'); ?></h2>
<form method="post" action="options.php">
<?php settings_fields( 'rsvp-option-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"><label for="rsvp_opendate"><?php echo __("RSVP Open Date:", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="text" name="rsvp_opendate" id="rsvp_opendate" value="<?php echo htmlspecialchars(get_option(OPTION_OPENDATE)); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="rsvp_deadline"><?php echo __("RSVP Deadline:", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="text" name="rsvp_deadline" id="rsvp_deadline" value="<?php echo htmlspecialchars(get_option(OPTION_DEADLINE)); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="rsvp_num_additional_guests"><?php echo __("Number of Additional Guests Allowed (default is three):", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="text" name="rsvp_num_additional_guests" id="rsvp_num_additional_guests" value="<?php echo htmlspecialchars(get_option(OPTION_RSVP_NUM_ADDITIONAL_GUESTS)); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="rsvp_custom_greeting"><?php echo __("Custom Greeting:", 'rsvp-plugin'); ?></label></th>
<td align="left"><textarea name="rsvp_custom_greeting" id="rsvp_custom_greeting" rows="5" cols="60"><?php echo htmlspecialchars(get_option(OPTION_GREETING)); ?></textarea></td>
</tr>
<tr valign="top">
<th scope="row"><label for="rsvp_custom_welcome"><?php echo __("Custom Welcome:", 'rsvp-plugin'); ?></label></th>
<td align="left"><?php echo __("Default is: "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'); ?><br />
<textarea name="rsvp_custom_welcome" id="rsvp_custom_welcome" rows="5" cols="60"><?php echo htmlspecialchars(get_option(OPTION_WELCOME_TEXT)); ?></textarea></td>
</tr>
<tr valign="top">
<th scope="row"><label for="<?php echo OPTION_RSVP_EMAIL_TEXT; ?>"><?php echo __("Email Text: <br />Sent to guests in confirmation, at top of email", 'rsvp-plugin'); ?></label></th>
<td align="left"><textarea name="<?php echo OPTION_RSVP_EMAIL_TEXT; ?>" id="<?php echo OPTION_RSVP_EMAIL_TEXT; ?>" rows="5" cols="60"><?php echo htmlspecialchars(get_option(OPTION_RSVP_EMAIL_TEXT)); ?></textarea></td>
</tr>
<tr valign="top">
<th scope="row"><label for="rsvp_custom_question_text"><?php echo __("RSVP Question Verbiage:", 'rsvp-plugin'); ?></label></th>
<td align="left"><?php echo __("Default is: "So, how about it?"", 'rsvp-plugin'); ?><br />
<input type="text" name="rsvp_custom_question_text" id="rsvp_custom_question_text"
value="<?php echo htmlspecialchars(get_option(OPTION_RSVP_QUESTION)); ?>" size="65" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="rsvp_yes_verbiage"><?php echo __("RSVP Yes Verbiage:", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="text" name="rsvp_yes_verbiage" id="rsvp_yes_verbiage"
value="<?php echo htmlspecialchars(get_option(OPTION_YES_VERBIAGE)); ?>" size="65" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="rsvp_no_verbiage"><?php echo __("RSVP No Verbiage:", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="text" name="rsvp_no_verbiage" id="rsvp_no_verbiage"
value="<?php echo htmlspecialchars(get_option(OPTION_NO_VERBIAGE)); ?>" size="65" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="rsvp_kids_meal_verbiage"><?php echo __("RSVP Kids Meal Verbiage:", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="text" name="rsvp_kids_meal_verbiage" id="rsvp_kids_meal_verbiage"
value="<?php echo htmlspecialchars(get_option(OPTION_KIDS_MEAL_VERBIAGE)); ?>" size="65" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="rsvp_hide_kids_meal"><?php echo __("Hide Kids Meal Question:", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="checkbox" name="rsvp_hide_kids_meal" id="rsvp_hide_kids_meal"
value="Y" <?php echo ((get_option(OPTION_HIDE_KIDS_MEAL) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="rsvp_veggie_meal_verbiage"><?php echo __("RSVP Vegetarian Meal Verbiage:", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="text" name="rsvp_veggie_meal_verbiage" id="rsvp_veggie_meal_verbiage"
value="<?php echo htmlspecialchars(get_option(OPTION_VEGGIE_MEAL_VERBIAGE)); ?>" size="65" /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="rsvp_hide_veggie"><?php echo __("Hide Vegetarian Meal Question:", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="checkbox" name="rsvp_hide_veggie" id="rsvp_hide_veggie"
value="Y" <?php echo ((get_option(OPTION_HIDE_VEGGIE) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="rsvp_note_verbiage"><?php echo __("Note Verbiage:", 'rsvp-plugin'); ?></label></th>
<td align="left"><textarea name="rsvp_note_verbiage" id="rsvp_note_verbiage" rows="3" cols="60"><?php
echo htmlspecialchars(get_option(OPTION_NOTE_VERBIAGE)); ?></textarea></td>
</tr>
<tr valign="top">
<th scope="row"><label for="rsvp_hide_note_field"><?php echo __("Hide Note Field:", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="checkbox" name="rsvp_hide_note_field" id="rsvp_hide_note_field" value="Y"
<?php echo ((get_option(RSVP_OPTION_HIDE_NOTE) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="rsvp_custom_thankyou"><?php echo __("Custom Thank You:", 'rsvp-plugin'); ?></label></th>
<td align="left"><textarea name="rsvp_custom_thankyou" id="rsvp_custom_thankyou" rows="5" cols="60"><?php echo htmlspecialchars(get_option(OPTION_THANKYOU)); ?></textarea></td>
</tr>
<tr>
<th scope="row"><label for="rsvp_hide_add_additional"><?php echo __("Do not allow additional guests", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="checkbox" name="rsvp_hide_add_additional" id="rsvp_hide_add_additional" value="Y"
<?php echo ((get_option(OPTION_HIDE_ADD_ADDITIONAL) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="<?php echo OPTION_RSVP_ADD_ADDITIONAL_VERBIAGE; ?>"><?php echo __("Add Additional Verbiage:", 'rsvp-plugin'); ?></label></th>
<td align="left"><?php echo __("Default is: "Did we slip up and forget to invite someone? If so, please add him or her here:"", 'rsvp-plugin'); ?><br />
<input type="text" name="<?php echo OPTION_RSVP_ADD_ADDITIONAL_VERBIAGE; ?>" id="<?php echo OPTION_RSVP_ADD_ADDITIONAL_VERBIAGE; ?>"
value="<?php echo htmlspecialchars(get_option(OPTION_RSVP_ADD_ADDITIONAL_VERBIAGE)); ?>" size="65" /></td>
</tr>
<tr>
<th scope="row"><label for="rsvp_notify_when_rsvp"><?php echo __("Notify When Guest RSVPs", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="checkbox" name="rsvp_notify_when_rsvp" id="rsvp_notify_when_rsvp" value="Y"
<?php echo ((get_option(OPTION_NOTIFY_ON_RSVP) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
</tr>
<tr>
<th scope="row"><label for="rsvp_notify_email_address"><?php echo __("Email address to notify", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="text" name="rsvp_notify_email_address" id="rsvp_notify_email_address" value="<?php echo htmlspecialchars(get_option(OPTION_NOTIFY_EMAIL)); ?>"/></td>
</tr>
<tr valign="top">
<th scope="row"><label for="rsvp_guest_email_confirmation"><?php echo __("Send email to main guest when they RSVP", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="checkbox" name="rsvp_guest_email_confirmation" id="rsvp_guest_email_confirmation" value="Y"
<?php echo ((get_option(OPTION_RSVP_GUEST_EMAIL_CONFIRMATION) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
</tr>
<tr>
<th scope="ropw"><label for="<?php echo OPTION_RSVP_PASSCODE; ?>"><?php echo __("Require a Passcode to RSVP:", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="checkbox" name="<?php echo OPTION_RSVP_PASSCODE; ?>" id="<?php echo OPTION_RSVP_PASSCODE; ?>" value="Y"
<?php echo ((get_option(OPTION_RSVP_PASSCODE) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
</tr>
<tr>
<th scope="ropw"><label for="<?php echo OPTION_RSVP_ONLY_PASSCODE; ?>"><?php echo __("Require only a Passcode to RSVP<br />(requires that passcodes are unique):", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="checkbox" name="<?php echo OPTION_RSVP_ONLY_PASSCODE; ?>" id="<?php echo OPTION_RSVP_ONLY_PASSCODE; ?>" value="Y"
<?php echo ((get_option(OPTION_RSVP_ONLY_PASSCODE) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="<?PHP echo OPTION_RSVP_OPEN_REGISTRATION; ?>"><?php echo __("Allow Open Registration (note - this will force passcodes for attendees):", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="checkbox" name="<?php echo OPTION_RSVP_OPEN_REGISTRATION; ?>" id="<?php echo OPTION_RSVP_OPEN_REGISTRATION; ?>" value="Y"
<?php echo ((get_option(OPTION_RSVP_OPEN_REGISTRATION) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="<?PHP echo OPTION_RSVP_DONT_USE_HASH; ?>"><?php echo __("Do not scroll page to the top of the RSVP form:", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="checkbox" name="<?php echo OPTION_RSVP_DONT_USE_HASH; ?>" id="<?php echo OPTION_RSVP_DONT_USE_HASH; ?>" value="Y"
<?php echo ((get_option(OPTION_RSVP_DONT_USE_HASH) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="<?php echo OPTION_RSVP_HIDE_EMAIL_FIELD; ?>"><?php echo __("Hide email field on rsvp form:", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="checkbox" name="<?php echo OPTION_RSVP_HIDE_EMAIL_FIELD; ?>" id="<?php echo OPTION_RSVP_HIDE_EMAIL_FIELD; ?>"
value="Y" <?php echo ((get_option(OPTION_RSVP_HIDE_EMAIL_FIELD) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="<?php echo OPTION_RSVP_DISABLE_CUSTOM_EMAIL_FROM; ?>"><?php echo __("Do not use the specified notification email as the from email<br /> (if you are not receiving email notifications try this):", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="checkbox" name="<?php echo OPTION_RSVP_DISABLE_CUSTOM_EMAIL_FROM; ?>" id="<?php echo OPTION_RSVP_DISABLE_CUSTOM_EMAIL_FROM; ?>"
value="Y" <?php echo ((get_option(OPTION_RSVP_DISABLE_CUSTOM_EMAIL_FROM) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
</tr>
<tr valign="top">
<th scope="row"><label for="<?php echo OPTION_RSVP_DISABLE_USER_SEARCH; ?>"><?php echo __("Disable searching for a user when no user is found:", 'rsvp-plugin'); ?></label></th>
<td align="left"><input type="checkbox" name="<?php echo OPTION_RSVP_DISABLE_USER_SEARCH; ?>" id="<?php echo OPTION_RSVP_DISABLE_USER_SEARCH; ?>"
value="Y" <?php echo ((get_option(OPTION_RSVP_DISABLE_USER_SEARCH) == "Y") ? " checked=\"checked\"" : ""); ?> /></td>
</tr>
</table>
<input type="hidden" name="action" value="update" />
<p class="submit">
<input type="submit" class="button-primary" value="<?php echo __('Save Changes', 'rsvp-plugin'); ?>" />
</p>
</form>
</div>
<?php
}
function rsvp_admin_guestlist() {
global $wpdb;
if(get_option("rsvp_db_version") != RSVP_DB_VERSION) {
rsvp_database_setup();
}
rsvp_install_passcode_field();
if((count($_POST) > 0) && ($_POST['rsvp-bulk-action'] == "delete") && (is_array($_POST['attendee']) && (count($_POST['attendee']) > 0))) {
foreach($_POST['attendee'] as $attendee) {
if(is_numeric($attendee) && ($attendee > 0)) {
$wpdb->query($wpdb->prepare("DELETE FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeID = %d OR associatedAttendeeID = %d",
$attendee,
$attendee));
$wpdb->query($wpdb->prepare("DELETE FROM ".ATTENDEES_TABLE." WHERE id = %d",
$attendee));
}
}
}
$sql = "SELECT id, firstName, lastName, rsvpStatus, note, kidsMeal, additionalAttendee, veggieMeal, personalGreeting, passcode, email FROM ".ATTENDEES_TABLE;
$orderBy = " lastName, firstName";
if(isset($_GET['sort'])) {
if(strToLower($_GET['sort']) == "rsvpstatus") {
$orderBy = " rsvpStatus ".((strtolower($_GET['sortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
}else if(strToLower($_GET['sort']) == "attendee") {
$direction = ((strtolower($_GET['sortDirection']) == "desc") ? "DESC" : "ASC");
$orderBy = " lastName $direction, firstName $direction";
} else if(strToLower($_GET['sort']) == "kidsmeal") {
$orderBy = " kidsMeal ".((strtolower($_GET['sortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
} else if(strToLower($_GET['sort']) == "additional") {
$orderBy = " additionalAttendee ".((strtolower($_GET['sortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
} else if(strToLower($_GET['sort']) == "vegetarian") {
$orderBy = " veggieMeal ".((strtolower($_GET['sortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
}
}
$sql .= " ORDER BY ".$orderBy;
$attendees = $wpdb->get_results($sql);
$sort = "";
$sortDirection = "asc";
if(isset($_GET['sort'])) {
$sort = $_GET['sort'];
}
if(isset($_GET['sortDirection'])) {
$sortDirection = $_GET['sortDirection'];
}
?>
<div class="updated">
<p><?php echo __("We now have a pro-version of this plugin, if you want to multiple event support or just
want to contribute to the maintenance and continued development of this plugin,
<a href=\"https://www.swimordiesoftware.com/downloads/rsvp-pro-plugin/\" target=\"_blank\">check it out!</a>", 'rsvp-plugin'); ?></p>
</div>
<script type="text/javascript" language="javascript">
jQuery(document).ready(function() {
jQuery("#cb").click(function() {
if(jQuery("#cb").attr("checked")) {
jQuery("input[name='attendee[]']").attr("checked", "checked");
} else {
jQuery("input[name='attendee[]']").removeAttr("checked");
}
});
});
</script>
<div class="wrap">
<div id="icon-edit" class="icon32"><br /></div>
<h2><?php echo __("List of current attendees", 'rsvp-plugin'); ?></h2>
<form method="post" id="rsvp-form" enctype="multipart/form-data">
<input type="hidden" id="rsvp-bulk-action" name="rsvp-bulk-action" />
<input type="hidden" id="sortValue" name="sortValue" value="<?php echo htmlentities($sort, ENT_QUOTES); ?>" />
<input type="hidden" name="exportSortDirection" value="<?php echo htmlentities($sortDirection, ENT_QUOTES); ?>" />
<div class="tablenav">
<div class="alignleft actions">
<select id="rsvp-action-top" name="action">
<option value="" selected="selected"><?php _e('Bulk Actions', 'rsvp-plugin'); ?></option>
<option value="delete"><?php _e('Delete', 'rsvp-plugin'); ?></option>
</select>
<input type="submit" value="<?php _e('Apply', 'rsvp-plugin'); ?>" name="doaction" id="doaction" class="button-secondary action" onclick="document.getElementById('rsvp-bulk-action').value = document.getElementById('rsvp-action-top').value;" />
<input type="submit" value="<?php _e('Export Attendees', 'rsvp-plugin'); ?>" name="exportButton" id="exportButton" class="button-secondary action" onclick="document.getElementById('rsvp-bulk-action').value = 'export';" />
</div>
<?php
$yesResults = $wpdb->get_results("SELECT COUNT(*) AS yesCount FROM ".ATTENDEES_TABLE." WHERE rsvpStatus = 'Yes'");
$noResults = $wpdb->get_results("SELECT COUNT(*) AS noCount FROM ".ATTENDEES_TABLE." WHERE rsvpStatus = 'No'");
$noResponseResults = $wpdb->get_results("SELECT COUNT(*) AS noResponseCount FROM ".ATTENDEES_TABLE." WHERE rsvpStatus = 'NoResponse'");
$kidsMeals = $wpdb->get_results("SELECT COUNT(*) AS kidsMealCount FROM ".ATTENDEES_TABLE." WHERE kidsMeal = 'Y'");
$veggieMeals = $wpdb->get_results("SELECT COUNT(*) AS veggieMealCount FROM ".ATTENDEES_TABLE." WHERE veggieMeal = 'Y'");
?>
<div class="alignright"><?php __("RSVP Count -", 'rsvp-plugin'); ?>
<?php echo __("Yes:", 'rsvp-plugin'); ?> <strong><?php echo $yesResults[0]->yesCount; ?></strong>
<?php echo __("No:", 'rsvp-plugin'); ?> <strong><?php echo $noResults[0]->noCount; ?></strong>
<?php echo __("No Response:", 'rsvp-plugin'); ?> <strong><?php echo $noResponseResults[0]->noResponseCount; ?></strong>
<?php echo __("Kids Meals:", 'rsvp-plugin'); ?> <strong><?php echo $kidsMeals[0]->kidsMealCount; ?></strong>
<?php echo __("Veggie Meals:", 'rsvp-plugin'); ?> <strong><?php echo $veggieMeals[0]->veggieMealCount; ?></strong>
</div>
<div class="clear"></div>
</div>
<table class="widefat post fixed" cellspacing="0">
<thead>
<tr>
<th scope="col" class="manage-column column-cb check-column" style=""><input type="checkbox" id="cb" /></th>
<th scope="col" id="attendeeName" class="manage-column column-title" style=""><?php echo __("Attendee", 'rsvp-plugin'); ?><br />
<a href="admin.php?page=rsvp-top-level&sort=attendee&sortDirection=asc">
<img src="<?php echo plugins_url(); ?>/rsvp/uparrow<?php
echo ((($sort == "attendee") && ($sortDirection == "asc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
alt="Sort Ascending Attendee Status" title="Sort Ascending Attendee Status" border="0"></a>
<a href="admin.php?page=rsvp-top-level&sort=attendee&sortDirection=desc">
<img src="<?php echo plugins_url(); ?>/rsvp/downarrow<?php
echo ((($sort == "attendee") && ($sortDirection == "desc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
alt="Sort Descending Attendee Status" title="Sort Descending Attendee Status" border="0"></a>
</th>
<th scope="col" id="rsvpEmail" class="manage-column column-title"><?php echo __("Email", 'rsvp-plugin'); ?></th>
<th scope="col" id="rsvpStatus" class="manage-column column-title" style=""><?php echo __("RSVP Status", 'rsvp-plugin'); ?><br />
<a href="admin.php?page=rsvp-top-level&sort=rsvpStatus&sortDirection=asc">
<img src="<?php echo plugins_url(); ?>/rsvp/uparrow<?php
echo ((($sort == "rsvpStatus") && ($sortDirection == "asc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
alt="Sort Ascending RSVP Status" title="Sort Ascending RSVP Status" border="0"></a>
<a href="admin.php?page=rsvp-top-level&sort=rsvpStatus&sortDirection=desc">
<img src="<?php echo plugins_url(); ?>/rsvp/downarrow<?php
echo ((($sort == "rsvpStatus") && ($sortDirection == "desc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
alt="Sort Descending RSVP Status" title="Sort Descending RSVP Status" border="0"></a>
</th>
<?php if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {?>
<th scope="col" id="kidsMeal" class="manage-column column-title" style=""><?php echo __("Kids Meal", 'rsvp-plugin'); ?><br />
<a href="admin.php?page=rsvp-top-level&sort=kidsMeal&sortDirection=asc">
<img src="<?php echo plugins_url(); ?>/rsvp/uparrow<?php
echo ((($sort == "kidsMeal") && ($sortDirection == "asc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
alt="Sort Ascending Kids Meal Status" title="Sort Ascending Kids Meal Status" border="0"></a>
<a href="admin.php?page=rsvp-top-level&sort=kidsMeal&sortDirection=desc">
<img src="<?php echo plugins_url(); ?>/rsvp/downarrow<?php
echo ((($sort == "kidsMeal") && ($sortDirection == "desc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
alt="Sort Descending Kids Meal Status" title="Sort Descending Kids Meal Status" border="0"></a>
</th>
<?php } ?>
<th scope="col" id="additionalAttendee" class="manage-column column-title" style=""><?php echo __("Additional Attendee", 'rsvp-plugin'); ?> <br />
<a href="admin.php?page=rsvp-top-level&sort=additional&sortDirection=asc">
<img src="<?php echo plugins_url(); ?>/rsvp/uparrow<?php
echo ((($sort == "additional") && ($sortDirection == "asc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
alt="Sort Ascending Additional Attendees Status" title="Sort Ascending Additional Attendees Status" border="0"></a>
<a href="admin.php?page=rsvp-top-level&sort=additional&sortDirection=desc">
<img src="<?php echo plugins_url(); ?>/rsvp/downarrow<?php
echo ((($sort == "additional") && ($sortDirection == "desc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
alt="Sort Descending Additional Attendees Status" title="Sort Descending Additional Atttendees Status" border="0"></a>
</th>
<?php if(get_option(OPTION_HIDE_VEGGIE) != "Y") {?>
<th scope="col" id="veggieMeal" class="manage-column column-title" style=""><?php echo __("Vegetarian", 'rsvp-plugin'); ?> <br />
<a href="admin.php?page=rsvp-top-level&sort=vegetarian&sortDirection=asc">
<img src="<?php echo plugins_url(); ?>/rsvp/uparrow<?php
echo ((($sort == "vegetarian") && ($sortDirection == "asc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
alt="Sort Ascending Vegetarian Status" title="Sort Ascending Vegetarian Status" border="0"></a>
<a href="admin.php?page=rsvp-top-level&sort=vegetarian&sortDirection=desc">
<img src="<?php echo plugins_url(); ?>/rsvp/downarrow<?php
echo ((($sort == "vegetarian") && ($sortDirection == "desc")) ? "_selected" : ""); ?>.gif" width="11" height="9"
alt="Sort Descending Vegetarian Status" title="Sort Descending Vegetarian Status" border="0"></a>
</th>
<?php } ?>
<th scope="col" id="customMessage" class="manage-column column-title" style=""><?php echo __("Custom Message", 'rsvp-plugin'); ?></th>
<th scope="col" id="note" class="manage-column column-title" style=""><?php echo __("Note", 'rsvp-plugin'); ?></th>
<?php
if(rsvp_require_passcode()) {
?>
<th scope="col" id="passcode" class="manage-column column-title" style=""><?php echo __("Passcode", 'rsvp-plugin'); ?></th>
<?php
}
?>
<?php
$qRs = $wpdb->get_results("SELECT id, question FROM ".QUESTIONS_TABLE." ORDER BY sortOrder, id");
if(count($qRs) > 0) {
foreach($qRs as $q) {
?>
<th scope="col" class="manage-column -column-title"><?php echo htmlspecialchars(stripslashes($q->question)); ?></th>
<?php
}
}
?>
<th scope="col" id="associatedAttendees" class="manage-column column-title" style=""><?php echo __("Associated Attendees", 'rsvp-plugin'); ?></th>
</tr>
</thead>
</table>
<div style="overflow: auto;height: 450px;">
<table class="widefat post fixed" cellspacing="0">
<?php
$i = 0;
foreach($attendees as $attendee) {
?>
<tr class="<?php echo (($i % 2 == 0) ? "alternate" : ""); ?> author-self">
<th scope="row" class="check-column"><input type="checkbox" name="attendee[]" value="<?php echo $attendee->id; ?>" /></th>
<td>
<a href="<?php echo get_option("siteurl"); ?>/wp-admin/admin.php?page=rsvp-admin-guest&id=<?php echo $attendee->id; ?>"><?php echo htmlspecialchars(stripslashes($attendee->firstName)." ".stripslashes($attendee->lastName)); ?></a>
</td>
<td><?php echo htmlspecialchars(stripslashes($attendee->email)); ?></td>
<td><?php echo $attendee->rsvpStatus; ?></td>
<?php if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {?>
<td><?php
if($attendee->rsvpStatus == "NoResponse") {
echo "--";
} else {
echo (($attendee->kidsMeal == "Y") ? __("Yes", 'rsvp-plugin') : __("No", 'rsvp-plugin'));
}?></td>
<?php } ?>
<td><?php
if($attendee->rsvpStatus == "NoResponse") {
echo "--";
} else {
echo (($attendee->additionalAttendee == "Y") ? __("Yes", 'rsvp-plugin') : __("No", 'rsvp-plugin'));
}
?></td>
<?php if(get_option(OPTION_HIDE_VEGGIE) != "Y") {?>
<td><?php
if($attendee->rsvpStatus == "NoResponse") {
echo "--";
} else {
echo (($attendee->veggieMeal == "Y") ? __("Yes", 'rsvp-plugin') : __("No", 'rsvp-plugin'));
}
?></td>
<?php } ?>
<td><?php
echo nl2br(stripslashes(trim($attendee->personalGreeting)));
?></td>
<td><?php echo nl2br(stripslashes(trim($attendee->note))); ?></td>
<?php
if(rsvp_require_passcode()) {
?>
<td><?php echo $attendee->passcode; ?></td>
<?php
}
$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, $attendee->id));
if(count($aRs) > 0) {
foreach($aRs as $a) {
?>
<td><?php echo htmlspecialchars(stripslashes($a->answer)); ?></td>
<?php
}
}
?>
<td>
<?php
$sql = "SELECT 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)";
$associations = $wpdb->get_results($wpdb->prepare($sql, $attendee->id, $attendee->id));
foreach($associations as $a) {
echo htmlspecialchars(stripslashes($a->firstName." ".$a->lastName))."<br />";
}
?>
</td>
</tr>
<?php
$i++;
}
?>
</table>
</div>
</form>
</div>
<?php
}
function rsvp_admin_export() {
global $wpdb;
$customLinkBase = "";
// Get page associated with the page to build out prefill link.
$query = new WP_Query( 's=rsvp-pluginhere' );
if($query->have_posts()) {
$query->the_post();
$customLinkBase = get_permalink();
if(strpos($customLinkBase, "?") !== false) {
$customLinkBase .= "&";
} else {
$customLinkBase .= "?";
}
if(rsvp_require_only_passcode_to_register()) {
$customLinkBase .= "passcode=%s";
} else {
$customLinkBase .= "firstName=%s&lastName=%s";
if(rsvp_require_passcode()) {
$customLinkBase .= "&passcode=%s";
}
}
}
wp_reset_postdata();
$sql = "SELECT id, firstName, lastName, email, rsvpStatus, note, kidsMeal, additionalAttendee, veggieMeal, passcode
FROM ".ATTENDEES_TABLE;
$orderBy = " lastName, firstName";
if(isset($_POST['sortValue'])) {
if(strToLower($_POST['sortValue']) == "rsvpstatus") {
$orderBy = " rsvpStatus ".((strtolower($_POST['exportSortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
}else if(strToLower($_POST['sortValue']) == "attendee") {
$direction = ((strtolower($_POST['exportSortDirection']) == "desc") ? "DESC" : "ASC");
$orderBy = " lastName $direction, firstName $direction";
} else if(strToLower($_POST['sortValue']) == "kidsmeal") {
$orderBy = " kidsMeal ".((strtolower($_POST['exportSortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
} else if(strToLower($_POST['sortValue']) == "additional") {
$orderBy = " additionalAttendee ".((strtolower($_POST['exportSortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
} else if(strToLower($_POST['sortValue']) == "vegetarian") {
$orderBy = " veggieMeal ".((strtolower($_POST['exportSortDirection']) == "desc") ? "DESC" : "ASC") .", ".$orderBy;
}
}
$sql .= " ORDER BY ".$orderBy;
$attendees = $wpdb->get_results($sql);
$csv = "\"".__("Attendee", 'rsvp-plugin')."\",\"".__("Email", 'rsvp-plugin')."\",\"".__("RSVP Status", 'rsvp-plugin')."\",";
if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {
$csv .= "\"".__("Kids Meal", 'rsvp-plugin')."\",";
}
$csv .= "\"".__("Additional Attendee", 'rsvp-plugin')."\",";
if(get_option(OPTION_HIDE_VEGGIE) != "Y") {
$csv .= "\"".__("Vegatarian", 'rsvp-plugin')."\",";
}
if(rsvp_require_passcode()) {
$csv .= "\"".__("Passcode", 'rsvp-plugin')."\",";
}
$csv .= "\"".__("Note", 'rsvp-plugin')."\",\"".__("Associated Attendees", 'rsvp-plugin')."\"";
$qRs = $wpdb->get_results("SELECT id, question FROM ".QUESTIONS_TABLE." ORDER BY sortOrder, id");
if(count($qRs) > 0) {
foreach($qRs as $q) {
$csv .= ",\"".stripslashes($q->question)."\"";
}
}
$csv .= ",\"".__("pre-fill URL", 'rsvp-plugin')."\"";
$csv .= "\r\n";
foreach($attendees as $a) {
$csv .= "\"".stripslashes($a->firstName." ".$a->lastName)."\",\"".stripslashes($a->email)."\",\"".($a->rsvpStatus)."\",";
if(get_option(OPTION_HIDE_KIDS_MEAL) != "Y") {
$csv .= "\"".(($a->kidsMeal == "Y") ? __("Yes", 'rsvp-plugin') : __("No", 'rsvp-plugin'))."\",";
}
$csv .= "\"".(($a->additionalAttendee == "Y") ? __("Yes", 'rsvp-plugin') : __("No", 'rsvp-plugin'))."\",";
if(get_option(OPTION_HIDE_VEGGIE) != "Y") {
$csv .= "\"".(($a->veggieMeal == "Y") ? __("Yes", 'rsvp-plugin') : __("No", 'rsvp-plugin'))."\",";
}
if(rsvp_require_passcode()) {
$csv .= "\"".(($a->passcode))."\",";
}
$csv .= "\"".(str_replace("\"", "\"\"", stripslashes($a->note)))."\",\"";
$sql = "SELECT 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)";
$associations = $wpdb->get_results($wpdb->prepare($sql, $a->id, $a->id));
foreach($associations as $assc) {
$csv .= trim(stripslashes($assc->firstName." ".$assc->lastName))."\r\n";
}
$csv .= "\"";
$qRs = $wpdb->get_results("SELECT id, question FROM ".QUESTIONS_TABLE." ORDER BY sortOrder, id");
if(count($qRs) > 0) {
foreach($qRs as $q) {
$aRs = $wpdb->get_results($wpdb->prepare("SELECT answer FROM ".ATTENDEE_ANSWERS." WHERE attendeeID = %d AND questionID = %d", $a->id, $q->id));
if(count($aRs) > 0) {
$csv .= ",\"".stripslashes($aRs[0]->answer)."\"";
} else {
$csv .= ",\"\"";
}
}
}
if(empty($customLinkBase)) {
$csv .= ",\"\"";
} else {
if(rsvp_require_only_passcode_to_register()) {
$csv .= ",\"".sprintf($customLinkBase, urlencode(stripslashes($a->passcode)))."\"";
} else if(rsvp_require_passcode()) {
$csv .= ",\"".sprintf($customLinkBase, urlencode(stripslashes($a->firstName)), urlencode(stripslashes($a->lastName)), urlencode(stripslashes($a->passcode)))."\"";
} else {
$csv .= ",\"".sprintf($customLinkBase, urlencode(stripslashes($a->firstName)), urlencode(stripslashes($a->lastName)))."\"";
}
}
$csv .= "\r\n";
}
if(isset($_SERVER['HTTP_USER_AGENT']) && preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT'])) {
// IE Bug in download name workaround
ini_set( 'zlib.output_compression','Off' );
}
header('Content-Description: RSVP Export');
header("Content-Type: application/vnd.ms-excel", true);
header('Content-Disposition: attachment; filename="rsvpEntries.csv"');
echo $csv;
exit();
}
function rsvp_admin_import() {
global $wpdb;
if(count($_FILES) > 0) {
check_admin_referer('rsvp-import');
require_once("Excel/reader.php");
$data = new Spreadsheet_Excel_Reader();
$data->read($_FILES['importFile']['tmp_name']);
$skipFirstRow = false;
if($data->sheets[0]['numCols'] >= 6) {
// Associating private questions... have to skip the first row
$skipFirstRow = true;
}
if($data->sheets[0]['numCols'] >= 2) {
$count = 0;
$i = ($skipFirstRow) ? 2 : 1;
for ($i; $i <= $data->sheets[0]['numRows']; $i++) {
$fName = trim($data->sheets[0]['cells'][$i][1]);
$fName = mb_convert_encoding($fName, 'UTF-8', mb_detect_encoding($fName, 'UTF-8, ISO-8859-1', true));
$lName = trim($data->sheets[0]['cells'][$i][2]);
$lName = mb_convert_encoding($lName, 'UTF-8', mb_detect_encoding($lName, 'UTF-8, ISO-8859-1', true));
$email = trim($data->sheets[0]['cells'][$i][3]);
$personalGreeting = (isset($data->sheets[0]['cells'][$i][5])) ? $personalGreeting = $data->sheets[0]['cells'][$i][5] : "";
$passcode = (isset($data->sheets[0]['cells'][$i][6])) ? $data->sheets[0]['cells'][$i][6] : "";
if(rsvp_require_unique_passcode() && !rsvp_is_passcode_unique($passcode, 0)) {
$passcode = rsvp_generate_passcode();
}
if(!empty($fName) && !empty($lName)) {
$sql = "SELECT id FROM ".ATTENDEES_TABLE."
WHERE firstName = %s AND lastName = %s ";
$res = $wpdb->get_results($wpdb->prepare($sql, $fName, $lName));
if(count($res) == 0) {
$wpdb->insert(ATTENDEES_TABLE, array("firstName" => $fName,
"lastName" => $lName,
"email" => $email,
"personalGreeting" => $personalGreeting,
"passcode" => $passcode),
array('%s', '%s', '%s', '%s'));
$count++;
}
}
}
if($data->sheets[0]['numCols'] >= 4) {
// There must be associated users so let's associate them
$i = ($skipFirstRow) ? 2 : 1;
for ($i; $i <= $data->sheets[0]['numRows']; $i++) {
$fName = trim($data->sheets[0]['cells'][$i][1]);
$fName = mb_convert_encoding($fName, 'UTF-8', mb_detect_encoding($fName, 'UTF-8, ISO-8859-1', true));
$lName = trim($data->sheets[0]['cells'][$i][2]);
$lName = mb_convert_encoding($lName, 'UTF-8', mb_detect_encoding($lName, 'UTF-8, ISO-8859-1', true));
if(!empty($fName) && !empty($lName) && (count($data->sheets[0]['cells'][$i]) >= 3)) {
// Get the user's id
$sql = "SELECT id FROM ".ATTENDEES_TABLE."
WHERE firstName = %s AND lastName = %s ";
$res = $wpdb->get_results($wpdb->prepare($sql, $fName, $lName));
if((count($res) > 0) && isset($data->sheets[0]['cells'][$i][4])) {
$userId = $res[0]->id;
// Deal with the assocaited users...
$associatedUsers = explode(",", trim($data->sheets[0]['cells'][$i][4]));
if(is_array($associatedUsers)) {
foreach($associatedUsers as $au) {
$user = explode(" ", trim($au), 2);
// Three cases, they didn't enter in all of the information, user exists or doesn't.
// If user exists associate the two users
// If user does not exist add the user and then associate the two
if(is_array($user) && (count($user) == 2)) {
$sql = "SELECT id FROM ".ATTENDEES_TABLE."
WHERE firstName = %s AND lastName = %s ";
$userRes = $wpdb->get_results($wpdb->prepare($sql,
mb_convert_encoding(trim($user[0]), 'UTF-8', mb_detect_encoding(trim($user[0]), 'UTF-8, ISO-8859-1', true)),
mb_convert_encoding(trim($user[1]), 'UTF-8', mb_detect_encoding(trim($user[1]), 'UTF-8, ISO-8859-1', true))));
if(count($userRes) > 0) {
$newUserId = $userRes[0]->id;
} else {
// Insert them and then we can associate them...
$wpdb->insert(ATTENDEES_TABLE, array("firstName" => mb_convert_encoding(trim($user[0]), 'UTF-8', mb_detect_encoding(trim($user[0]), 'UTF-8, ISO-8859-1', true)),
"lastName" => mb_convert_encoding(trim($user[1]), 'UTF-8', mb_detect_encoding(trim($user[1]), 'UTF-8, ISO-8859-1', true))),
array('%s', '%s'));
$newUserId = $wpdb->insert_id;
$count++;
}
$wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID" => $newUserId,
"associatedAttendeeID" => $userId),
array("%d", "%d"));
$wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID" => $userId,
"associatedAttendeeID" => $newUserId),
array("%d", "%d"));
}
}
}
}
}
}
} // if($data->sheets[0]['numCols'] >= 3)...
if($data->sheets[0]['numCols'] >= 6) {
$private_questions = array();
for($qid = 6; $qid <= $data->sheets[0]['numCols']; $qid++) {
$pqid = str_replace("pq_", "", $data->sheets[0]['cells'][1][$qid]);
if(is_numeric($pqid)) {
$private_questions[$qid] = $pqid;
}
}
if(count($private_questions) > 0) {
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
$fName = trim($data->sheets[0]['cells'][$i][1]);
$fName = mb_convert_encoding($fName, 'UTF-8', mb_detect_encoding($fName, 'UTF-8, ISO-8859-1', true));
$lName = trim($data->sheets[0]['cells'][$i][2]);
$lName = mb_convert_encoding($lName, 'UTF-8', mb_detect_encoding($lName, 'UTF-8, ISO-8859-1', true));
if(!empty($fName) && !empty($lName)) {
// Get the user's id
$sql = "SELECT id FROM ".ATTENDEES_TABLE."
WHERE firstName = %s AND lastName = %s ";
$res = $wpdb->get_results($wpdb->prepare($sql, $fName, $lName));
if(count($res) > 0) {
$userId = $res[0]->id;
foreach($private_questions as $key => $val) {
if(strToUpper($data->sheets[0]['cells'][$i][$key]) == "Y") {
$wpdb->insert(QUESTION_ATTENDEES_TABLE, array("attendeeID" => $userId,
"questionID" => $val),
array("%d", "%d"));
}
}
}
}
}
} // if(count($priv...))
} // if($data->sheets[0]['numCols'] >= 6)....
?>
<p><strong><?php echo $count; ?></strong> <?php echo __("total records were imported", 'rsvp-plugin'); ?>.</p>
<p><?php echo __("Continue to the RSVP", 'rsvp-plugin'); ?> <a href="admin.php?page=rsvp-top-level"><?php echo __("list", 'rsvp-plugin'); ?></a></p>
<?php
}
} else {
?>
<form name="rsvp_import" method="post" enctype="multipart/form-data">
<?php wp_nonce_field('rsvp-import'); ?>
<p><?php echo __("Select an excel file (only xls please, xlsx is not supported....yet) in the following format:", 'rsvp-plugin'); ?><br />
<strong><?php echo __("First Name", 'rsvp-plugin'); ?></strong> | <strong><?php echo __("Last Name", 'rsvp-plugin'); ?></strong> | <strong><?php echo __("Email", 'rsvp-plugin'); ?></strong> |
<strong><?php echo __("Associated Attendees", 'rsvp-plugin'); ?>*</strong> | <strong><?php echo __("Custom Message", 'rsvp-plugin'); ?></strong> | <strong><?php echo __("Passcode", 'rsvp-plugin'); ?></strong> | <strong><?php echo __("Private Question Association", 'rsvp-plugin'); ?>**</strong>
</p>
<p>
* <?php echo __("associated attendees should be separated by a comma it is assumed that the first space encountered will separate the first and last name.", 'rsvp-plugin'); ?>
</p>
<p>
** <?php echo __("This can be multiple columns each column is associated with one of the following private questions. If you wish
to have the guest associated with the question put a "Y" in the column otherwise put whatever else you want. The header name will be the "private import key" which is also listed below. It has the format of pq_* where * is a number.", 'rsvp-plugin'); ?>
<ul>
<?php
$questions = $wpdb->get_results("SELECT id, question FROM ".QUESTIONS_TABLE." WHERE permissionLevel = 'private'");
foreach($questions as $q) {
?>
<li><?php echo htmlspecialchars(stripslashes($q->question)); ?> - pq_<?php echo $q->id; ?></li>
<?php
}
?>
</ul>
</p>
<p><?php echo __("A header row is not expected, UNLESS you are associating private questions.", 'rsvp-plugin'); ?></p>
<p><input type="file" name="importFile" id="importFile" /></p>
<p><input type="submit" value="Import File" name="goRsvp" /></p>
</form>
<?php
}
}
function rsvp_admin_guest() {
global $wpdb;
if((count($_POST) > 0) && !empty($_POST['firstName']) && !empty($_POST['lastName'])) {
check_admin_referer('rsvp_add_guest');
$passcode = (isset($_POST['passcode'])) ? $_POST['passcode'] : "";
if(isset($_POST['attendeeId']) && is_numeric($_POST['attendeeId']) && ($_POST['attendeeId'] > 0)) {
$wpdb->update(ATTENDEES_TABLE,
array("firstName" => trim($_POST['firstName']),
"lastName" => trim($_POST['lastName']),
"email" => trim($_POST['email']),
"personalGreeting" => trim($_POST['personalGreeting']),
"rsvpStatus" => trim($_POST['rsvpStatus'])),
array("id" => $_POST['attendeeId']),
array("%s", "%s", "%s", "%s", "%s"),
array("%d"));
rsvp_printQueryDebugInfo();
$attendeeId = $_POST['attendeeId'];
$wpdb->query($wpdb->prepare("DELETE FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeId = %d", $attendeeId));
$wpdb->query($wpdb->prepare("DELETE FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = %d", $attendeeId));
} else {
$wpdb->insert(ATTENDEES_TABLE, array("firstName" => trim($_POST['firstName']),
"lastName" => trim($_POST['lastName']),
"email" => trim($_POST['email']),
"personalGreeting" => trim($_POST['personalGreeting']),
"rsvpStatus" => trim($_POST['rsvpStatus'])),
array('%s', '%s', '%s', '%s', '%s'));
$attendeeId = $wpdb->insert_id;
}
if(isset($_POST['associatedAttendees']) && is_array($_POST['associatedAttendees'])) {
foreach($_POST['associatedAttendees'] as $aid) {
if(is_numeric($aid) && ($aid > 0)) {
$wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID"=>$attendeeId, "associatedAttendeeID"=>$aid), array("%d", "%d"));
$wpdb->insert(ASSOCIATED_ATTENDEES_TABLE, array("attendeeID"=>$aid, "associatedAttendeeID"=>$attendeeId), array("%d", "%d"));
}
}
}
if(rsvp_require_passcode()) {
if(empty($passcode)) {
$passcode = rsvp_generate_passcode();
}
if(rsvp_require_unique_passcode() && !rsvp_is_passcode_unique($passcode, $attendeeId)) {
$passcode = rsvp_generate_passcode();
}
$wpdb->update(ATTENDEES_TABLE,
array("passcode" => trim($passcode)),
array("id"=>$attendeeId),
array("%s"),
array("%d"));
}
?>
<p><?php echo __("Attendee", 'rsvp-plugin'); ?> <?php echo htmlspecialchars(stripslashes($_POST['firstName']." ".$_POST['lastName']));?> <?php echo __("has been successfully saved", 'rsvp-plugin'); ?></p>
<p>
<a href="<?php echo get_option('siteurl'); ?>/wp-admin/admin.php?page=rsvp-top-level"><?php echo __("Continue to Attendee List", 'rsvp-plugin'); ?></a> |
<a href="<?php echo get_option('siteurl'); ?>/wp-admin/admin.php?page=rsvp-admin-guest"><?php echo __("Add a Guest", 'rsvp-plugin'); ?></a>
</p>
<?php
} else {
$attendee = null;
$associatedAttendees = array();
$firstName = "";
$lastName = "";
$email = "";
$personalGreeting = "";
$rsvpStatus = "NoResponse";
$passcode = "";
$attendeeId = 0;
if(isset($_GET['id']) && is_numeric($_GET['id'])) {
$attendee = $wpdb->get_row("SELECT id, firstName, lastName, email, personalGreeting, rsvpStatus, passcode FROM ".ATTENDEES_TABLE." WHERE id = ".$_GET['id']);
if($attendee != null) {
$attendeeId = $attendee->id;
$firstName = stripslashes($attendee->firstName);
$lastName = stripslashes($attendee->lastName);
$email = stripslashes($attendee->email);
$personalGreeting = stripslashes($attendee->personalGreeting);
$rsvpStatus = $attendee->rsvpStatus;
$passcode = stripslashes($attendee->passcode);
// Get the associated attendees and add them to an array
$associations = $wpdb->get_results("SELECT associatedAttendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE attendeeId = ".$attendee->id.
" UNION ".
"SELECT attendeeID FROM ".ASSOCIATED_ATTENDEES_TABLE." WHERE associatedAttendeeID = ".$attendee->id);
foreach($associations as $aId) {