-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrsvpmaker-plugabble.php
6799 lines (4208 loc) · 199 KB
/
rsvpmaker-plugabble.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
// start customizable functions, can be overriden by adding a rsvpmaker-custom.php file to the plugins directory (one level up from rsvpmaker directory)
function my_events_menu() {
global $rsvp_options;
if ( function_exists( 'do_blocks' ) ) {
return;
}
add_meta_box( 'EventDatesBox', __( 'Event Options', 'rsvpmaker' ), 'draw_eventdates', 'rsvpmaker', 'normal', 'high' );
if ( isset( $rsvp_options['additional_editors'] ) && $rsvp_options['additional_editors'] ) {
add_meta_box( 'ExtraEditorsBox', __( 'Additional Editors', 'rsvpmaker' ), 'additional_editors', 'rsvpmaker', 'normal', 'high' );
}
}
function draw_eventdates() {
global $post;
$post_id = ( isset( $_GET['post_id'] ) ) ? (int) $_GET['post_id'] : 0;
$post = ( $post_id ) ? get_post( $post_id ) : null;
global $wpdb;
global $rsvp_options;
global $custom_fields;
if ( isset( $_GET['debug'] ) ) {
echo '<pre>';
print_r( $post );
echo '</pre>';
}
if ( isset( $_GET['clone'] ) ) {
$id = (int) $_GET['clone'];
$custom_fields = get_rsvpmaker_custom( $id );
} elseif ( isset( $post->ID ) ) {
$custom_fields = get_rsvpmaker_custom( $post->ID );
}
if ( isset( $custom_fields['_rsvpmaker_special'][0] ) ) {
$rsvpmaker_special = $custom_fields['_rsvpmaker_special'][0];
if ( $rsvpmaker_special == 'Landing Page' ) {
?>
<p>This is a landing page for an RSVPMaker webinar.</p>
<p><input type="radio" name="_require_webinar_passcode" value="<?php echo esc_attr( $custom_fields['_webinar_passcode'][0] ); ?>"
<?php
if ( isset( $custom_fields['_require_webinar_passcode'][0] ) && $custom_fields['_require_webinar_passcode'][0] ) {
echo 'checked="checked"';}
?>
> Passcode required to view webinar</p>
<p><input type="radio" name="_require_webinar_passcode" value="0"
<?php
if ( ! isset( $custom_fields['_require_webinar_passcode'][0] ) || ! $custom_fields['_require_webinar_passcode'][0] ) {
echo 'checked="checked"';}
?>
> No passcode required</p>
<?php
} else {
do_action( 'rsvpmaker_special_metabox', $rsvpmaker_special );
}
return 'special';
} elseif ( ( isset( $post->ID ) && rsvpmaker_is_template( $post->ID ) ) || isset( $_GET['new_template'] ) ) {
?>
<p><em><strong><?php esc_html_e( 'Event Template', 'rsvpmaker' ); ?>:</strong> <?php esc_html_e( 'This form is for entering generic / boilerplate information, not specific details for an event on a specific date. Groups that meet on a monthly basis can post their standard meeting schedule, location, and contact details to make entering the individual events easier. You can also post multiple future meetings using the generic template and update those event listings as needed when the event date grows closer.', 'rsvpmaker' ); ?></em></p>
<?php
$template = get_template_sked( $post_id );
template_schedule( $template );
rsvp_time_options( $post->ID );
return;
}
if ( isset( $custom_fields['_meet_recur'][0] ) ) {
$t = (int) $custom_fields['_meet_recur'][0];
if ( $post_id ) {
printf(
'<p><a href="%s">%s</a> | <a href="%s">%s</a> | <a href="%s">%s</a> | <a href="%s">%s</a></p>',
admin_url( 'post.php?action=edit&post=' . $t ),
__( 'Edit Template Content', 'rsvpmaker' ),
admin_url( 'post.php?action=edit&tab=basics&post=' . $t ),
__( 'Edit Template Options', 'rsvpmaker' ),
admin_url( 'edit.php?post_type=rsvpmaker&page=rsvpmaker_template_list&t=' . $t ),
__( 'See Related Events', 'rsvpmaker' ),
admin_url(
'edit.php?post_type=rsvpmaker&page=rsvpmaker_template_list&apply_target=' . intval( $post->ID ) . '&apply_current=' . $t . '#applytemplate
'
),
__( 'Switch Template', 'rsvpmaker' )
);
}
} elseif ( isset( $post->ID ) ) {
printf(
'<p><a href="%s">%s</a></p>',
admin_url(
'edit.php?post_type=rsvpmaker&page=rsvpmaker_template_list&apply_target=' . intval( $post->ID ) . '#applytemplate
'
),
__( 'Apply Template', 'rsvpmaker' )
);
}
if(isset($post->ID))
$event = get_rsvpmaker_event( $post->ID );
$start = 0;
if ( !empty($event) ) {
$t = intval($event->ts_start);
$end = intval($event->ts_end);
echo "\n<div class=\"event_dates\"> \n";
if ( $rsvp_options['long_date'] ) {
echo mb_convert_encoding( rsvpmaker_date( $rsvp_options['long_date'], $t ), 'UTF-8' );
}
$dur = $event->display_type;
if ( ( $dur != 'allday' ) && ! strpos( $dur, '|' ) ) {
echo rsvpmaker_date( ' ' . $rsvp_options['time_format'], $t );
} elseif ( ( $dur == 'set' ) && $row['end_time'] ) {
echo ' to ' . rsvpmaker_date( $rsvp_options['time_format'], $end );
}
rsvpmaker_date_option_event( $t, $end, $dur );
echo "</div>\n";
return;
} else {
echo '<p><em>' . __( 'You can enter dates and times in either text format or the numeric/database format.', 'rsvpmaker' ) . '</em> </p>';
$t = time();
}
if ( isset( $_GET['t'] ) ) {
$t = (int) $_GET['t'];
$sked = get_template_sked( $t );
$times = rsvpmaker_get_projected( $sked );
foreach ( $times as $ts ) {
if ( $ts > time() ) {
break;
}
}
rsvpmaker_date_option( $ts, 0, rsvpmaker_date( 'Y-m-d H:i:s', $ts ), $sked );
$start = 1;
} elseif ( $start == 0 ) {
$start = 1;
$date = ( isset( $_GET['add_date'] ) ) ? sanitize_text_field($_GET['add_date']) : 'today ' . $rsvp_options['defaulthour'] . ':' . $rsvp_options['defaultmin'] . ':00';
rsvpmaker_date_option( $date, 0, rsvpmaker_date( 'Y-m-d H:i:s', $t ) );
}
if ( ! isset( $_GET['t'] ) ) { // if this is based on a template, use the template defaults
rsvp_time_options( $post_id );
}
if ( isset( $_GET['debug'] ) ) {
echo '<pre>';
// print_r($custom_fields);
echo '</pre>';
}
}
// end draw event dates
function template_schedule( $template ) {
global $post;
$sked = get_template_sked( $post->ID );
$occur = array('Varies','First','Second','Third','Fourth','Last','Every');
$schedule = '';
$day = 'tomorrow';
foreach($sked as $index => $value) {
if(in_array($index,$occur) && $value)
$schedule .= ' '.$index;
if(strpos($index,'day') && $value) {
if($day == 'tomorrow')
$day = $index;
$schedule .= ' '.$index;
}
}
echo '<p><em>Template: '.$schedule.' (set in editor)</em></p>';
?>
<p><?php esc_html_e( 'Stop date (optional)', 'rsvpmaker' ); ?>: <input type="text" name="sked[stop]" value="<?php
if ( isset( $template['stop'] ) ) {
echo esc_attr($template['stop']);
}
?>" placeholder="<?php
esc_html_e( 'example', 'rsvpmaker' );
echo ': ' . date( 'Y' ) . '-12-31';
?>" /> <em>(<?php esc_html_e( 'format', 'rsvpmaker' ); ?>: "YYYY-mm-dd" or "+6 month" or "+1 year")</em></p>
<?php
$auto = ( ( isset( $_GET['new_template'] ) && ! empty( $rsvp_options['autorenew'] ) ) || get_post_meta( $post->ID, 'rsvpautorenew', true ) );
?>
<p><input type="checkbox" name="rsvpautorenew" id="rsvpautorenew"
<?php
if ( $auto ) {
echo 'checked="checked"';}
?>
/> <?php esc_html_e( 'Automatically add dates according to schedule', 'rsvpmaker' ); ?></em></p>
<?php
}
// end template schedule
function rsvpmaker_sanitize_array_vars($array) {
if(!is_array($array))
return false;
foreach($array as $index => $var) {
if(is_array($var))
$var = array_map('sanitize_text_field',$var);
else
$var = sanitize_text_field($var);
$array[$index] = $var;
}
return $array;
}
function save_rsvp_template_meta( $post_id ) {
if ( ! isset( $_POST['sked'] ) && wp_verify_nonce(rsvpmaker_nonce_data('data'),rsvpmaker_nonce_data('key')) ) {
return;
}
// we only care about saving template data
global $wpdb;
global $post;
global $current_user;
if ( $parent_id = wp_is_post_revision( $post_id ) ) {
$post_id = $parent_id;
}
$sked = array_map('rsvpmaker_sanitize_array_vars',$_POST['sked']);
if ( $sked['time'] ) {
$p = explode( ':', $sked['time'] );
$sked['hour'] = $p[0];
$sked['minutes'] = $p[1];
}
if ( empty( $sked['dayofweek'] ) ) {
$sked['dayofweek'][0] = 9;
}
$sked['duration'] = $sked['end_time_type'] = sanitize_text_field( $_POST['end_time_type'] );
if(isset($_POST['rsvp_sql_end']))
$sked['end'] = $sked['rsvp_sql_end'] = sanitize_text_field( $_POST['rsvp_sql_end'] );
new_template_schedule( $post_id, $sked );
if ( isset( $_POST['rsvpautorenew'] ) && wp_verify_nonce(rsvpmaker_nonce_data('data'),rsvpmaker_nonce_data('key')) ) {
update_post_meta( $post_id, 'rsvpautorenew', 1 );
} else {
delete_post_meta( $post_id, 'rsvpautorenew' );
}
}
function rsvpmaker_roles() {
// by default, capabilities for events are the same as for blog posts
global $wp_roles;
if ( ! isset( $wp_roles ) ) {
$wp_roles = new WP_Roles();
}
// subscribers should not be able to edit
$wp_roles->remove_cap( 'subscriber', 'edit_rsvpmakers' );
// if roles persist from previous session, return
if ( ! empty( $wp_roles->roles['administrator']['capabilities']['edit_rsvpmakers'] ) ) {
return;
}
if ( is_array( $wp_roles->roles ) ) {
foreach ( $wp_roles->roles as $role => $rolearray ) {
foreach ( $rolearray['capabilities'] as $cap => $flag ) {
if ( strpos( $cap, 'post' ) ) {
$fbcap = str_replace( 'post', 'rsvpmaker', $cap );
$wp_roles->add_cap( $role, $fbcap );
}
}
}
}
}
function get_confirmation_options( $post_id = 0, $documents = array() ) {
global $post;
if ( isset( $post->ID ) ) {
$post_id = $post->ID;
}
$output = '';
$confirm = rsvp_get_confirm( $post_id, true );
$output = sprintf( '<h3 id="confirmation">%s</h3>', __( 'Confirmation Message', 'rsvpmaker' ) );
$output .= $confirm->post_content;
foreach ( $documents as $d ) {
$id = $d['id'];
if ( ( $id == 'edit_confirm' ) || ( $id == 'customize_confirmation' ) ) {
$output .= sprintf( '<p><a href="%s">Edit: %s</a></p>', esc_attr( $d['href'] ), esc_html( $d['title'] ) );
}
}
if ( ( empty( $_GET['page'] ) || $_GET['page'] != 'rsvp_reminders' ) ) {
$output .= sprintf( '<p><a href="%s" target="_blank">Create / Edit Reminders</a></p>', admin_url( 'edit.php?post_type=rsvpmaker&page=rsvp_reminders&message_type=confirmation&post_id=' . $post_id ) );
$payment_confirmation = (int) get_post_meta( $post_id, 'payment_confirmation_message', true );
if ( empty( $payment_confirmation ) || empty( get_post( $payment_confirmation ) ) ) {
$add_payment_conf = admin_url( 'edit.php?title=Payment%20Confirmation&post_type=rsvpmaker&page=rsvpmaker_details&rsvpcz=payment_confirmation_message&post_id=' . $post_id );
$output .= sprintf( '<p><a href="%s">%s</a></p>', $add_payment_conf, __( 'Add Payment Confirmation Message' ) );
} else {
$output .= sprintf( '<p><a href="%s">%s</a></p>', admin_url( 'post.php?post=' . $payment_confirmation . '&action=edit' ), __( 'Edit Payment Confirmation Message' ) );
}
}
$output = '<div style="max-width: 800px">' . $output . '</div>';
return $output;
}
function ajax_rsvp_email_lookup( $email, $event ) {
$p = get_permalink( $event );
if ( ! rsvpmail_contains_email( $email ) ) {
return;
}
global $wpdb;
$wpdb->show_errors();
$sql = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->prefix . 'rsvpmaker WHERE email LIKE %s AND event=%d', $email, $event );
$results = $wpdb->get_results( $sql );
if ( $results ) {
$out = '<div class="previous_rsvp_prompt">' . __( 'Did you RSVP previously?', 'rsvpmaker' ) . '</div>';
foreach ( $results as $row ) {
$out .= 'RSVP ';
$out .= ( $row->yesno ) ? __( 'YES', 'rsvpmaker' ) : __( 'NO', 'rsvpmaker' );
$out .= esc_html( ' ' . $row->first . ' ' . $row->last );
$sql = $wpdb->prepare( 'SELECT count(*) FROM ' . $wpdb->prefix . 'rsvpmaker WHERE master_rsvp=%d', intval( $row->id ) );
$guests = $wpdb->get_var( $sql );
if ( $guests ) {
$out .= ' + ' . esc_html( $guests ) . ' ' . __( 'guests', 'rsvpmaker' );
}
return sprintf(
'<div><a href="%s">%s</a> %s</div>',
add_query_arg(
array(
'e' => $row->email,
'update' => $row->id,
),
$p
),
__( 'Update', 'rsvpmaker' ),
$out
);
}
} else {
return;
}
}
function rsvp_form_setup_form( $rsvp_form ) {
$hidden = ( strpos( $rsvp_form, 'hidden="email"' ) );
$email_list_ok = ( strpos( $rsvp_form, 'checkbox="email_list_ok"' ) );
preg_match( '/textfield="([^"]+)"/', $rsvp_form, $match );
$emailfirst = ( $match[1] == 'email' ) ? ' checked="checked" ' : '';
?>
<div id="rsvp-dialog-form" title="Form setup">
<p><?php esc_html_e( 'First Name, Last Name, Email (required)', 'rsvpmaker' ); ?> Display options: <select id="name_email_hidden" name="name_email_hidden">
<option value="email_first"
<?php
if ( $emailfirst ) {
echo 'selected="selected"';}
?>
><?php esc_html_e( 'email, then name', 'rsvpmaker' ); ?></option>
<option value="name_first"
<?php
if ( ! $emailfirst && ! $hidden ) {
echo 'selected="selected"';}
?>
><?php esc_html_e( 'name, then email', 'rsvpmaker' ); ?></option>
<option value="hidden"
<?php
if ( $hidden ) {
echo 'selected="selected"';}
?>
><?php esc_html_e( 'hidden (use with login required)', 'rsvpmaker' ); ?></option>
</select>
<br /><?php esc_html_e( 'For radio buttons or select fields, use the format Label:option 1, option 2', 'rsvpmaker' ); ?> (<em><?php esc_html_e( 'Meal:Steak,Chicken,Vegitarian', 'rsvpmaker' ); ?></em>)</p>
<fieldset>
<?php
preg_match_all( '/(\[.+\])/', $rsvp_form, $matches );
preg_match( '/max_party="(\d+")/', $rsvp_form, $maxparty );
$codes = implode( $matches[1] );
$codes .= '[rsvpfield textfield=""][rsvpfield textfield=""][rsvpfield textfield=""]';
echo do_shortcode( $codes );
global $extrafield;
printf( '<input type="hidden" id="extrafields" value="%s" />', $extrafield );
$mp = ( empty( $maxparty[1] ) ) ? '' : $maxparty[1] - 1;
?>
<p><input type="checkbox" name="guests" id="guests" value="1"
<?php
if ( strpos( $rsvp_form, 'rsvpguests' ) ) {
echo 'checked="checked"';}
?>
/> <?php esc_html_e( 'Include guest form', 'rsvpmaker' ); ?> - <?php esc_html_e( 'up to', 'rsvpmaker' ); ?> <input type="text" name="maxguests" id="maxguests" value="<?php echo esc_attr($mp); ?>" size="2" /> <?php esc_html_e( ' guests (enter # or leave blank for no limit)', 'rsvpmaker' ); ?><br /> <input type="checkbox" name="note" id="note" value="1"
<?php
if ( strpos( $rsvp_form, 'rsvpnote' ) ) {
echo 'checked="checked"';}
?>
> <?php esc_html_e( 'Include notes field', 'rsvpmaker' ); ?> <input type="checkbox" name="emailcheckbox" id="emailcheckbox" value="1"
<?php
if ( $email_list_ok ) {
echo 'checked="checked"';}
?>
> <?php esc_html_e( 'Include "Add me to email list" checkbox', 'rsvpmaker' ); ?></p>
<p><input type="checkbox" name="guests" id="guests" value="1"
<?php
if ( strpos( $rsvp_form, 'rsvpguests' ) ) {
echo 'checked="checked"';}
?>
/> <?php esc_html_e( 'Include guest form', 'rsvpmaker' ); ?> - <?php esc_html_e( 'up to', 'rsvpmaker' ); ?> <input type="text" name="maxguests" id="maxguests" value="<?php echo esc_attr($mp); ?>" size="2" /> <?php esc_html_e( ' guests (enter # or leave blank for no limit)', 'rsvpmaker' ); ?><br /> <input type="checkbox" name="note" id="note" value="1"
<?php
if ( strpos( $rsvp_form, 'rsvpnote' ) ) {
echo 'checked="checked"';}
?>
> <?php esc_html_e( 'Include notes field', 'rsvpmaker' ); ?> <input type="checkbox" name="emailcheckbox" id="emailcheckbox" value="1"
<?php
if ( $email_list_ok ) {
echo 'checked="checked"';}
?>
> <?php esc_html_e( 'Include "Add me to email list" checkbox', 'rsvpmaker' ); ?></p>
<!-- Allow form submission with keyboard without duplicating the dialog button -->
<input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
</fieldset>
</div>
<?php
}
function rsvpmaker_capture_email( $rsvp ) {
// placeholder function, may be overriden to sign person up for email list
// or use this action, triggered by email_list_ok parameter in form
if ( isset( $rsvp['email_list_ok'] ) && $rsvp['email_list_ok'] ) {
do_action( 'rsvpmaker_email_list_okay', $rsvp );
}
}
function save_replay_rsvp() {
global $wpdb;
global $rsvp_options;
global $rsvp_id;
if ( isset( $_POST['replay_rsvp'] ) && wp_verify_nonce(rsvpmaker_nonce_data('data'),rsvpmaker_nonce_data('key')) ) {
if ( get_magic_quotes_gpc() ) {
$_POST = array_map( 'stripslashes_deep', $_POST );
}
$req_uri = trim( sanitize_text_field($_POST['replay_rsvp']) );
$req_uri .= ( strpos( $req_uri, '?' ) ) ? '&' : '?';
// sanitize input
foreach ( $_POST['profile'] as $name => $value ) {
$rsvp[ $name ] = sanitize_text_field( $value );
}
if ( isset( $_POST['note'] ) ) {
$note = sanitize_text_field( $_POST['note'] );
} else {
$note = '';
}
$answer = 'YES';
$event = ( ! empty( $_POST['event'] ) ) ? (int) $_POST['event'] : 0;
if ( ! $event ) {
die( 'Event ID not set' );
}
// page hasn't loaded yet, so retrieve post variables based on event
$post = get_post( $event );
// get rsvp_to
$custom_fields = get_post_custom( $post->ID );
$rsvp_to = $custom_fields['_rsvp_to'][0];
$rsvp_confirm = rsvp_get_confirm( $post->ID );
// if permalinks are not turned on, we need to append to query string not add our own ?
if ( ! is_admin() && isset( $custom_fields['_rsvp_captcha'][0] ) && $custom_fields['_rsvp_captcha'][0] ) {
if ( ! isset( $_SESSION['captcha_key'] ) ) {
session_start();
}
if ( $_SESSION['captcha_key'] != md5( $_POST['captcha'] ) ) {
header( 'Location: ' . $req_uri . '&err=' . urlencode( 'security code not entered correctly! Please try again.' ) );
exit();
}
}
if ( ! is_admin() && ! empty( $rsvp_options['rsvp_recaptcha_site_key'] ) && ! empty( $rsvp_options['rsvp_recaptcha_secret'] ) ) {
if ( ! rsvpmaker_recaptcha_check( $rsvp_options['rsvp_recaptcha_site_key'], $rsvp_options['rsvp_recaptcha_secret'] ) ) {
header( 'Location: ' . $req_uri . '&err=' . urlencode( 'failed recaptcha test' ) );
exit();
}
}
if ( isset( $_POST['required'] ) || empty( $rsvp['email'] ) ) {
$required = explode( ',', $_POST['required'] );
if ( ! in_array( 'email', $required ) ) {
$required[] = 'email';
}
$missing = '';
foreach ( $required as $r ) {
$r = sanitize_text_field($r);
if ( empty( $rsvp[ $r ] ) ) {
$missing .= $r . ' ';
}
}
if ( $missing != '' ) {
header( 'Location: ' . $req_uri . '&err=' . urlencode( 'missing required fields: ' . esc_attr( $missing ) ) );
exit();
}
}
if ( preg_match_all( '/http/', $_POST['note'], $matches ) > 2 ) {
header( 'Location: ' . $req_uri . '&err=Invalid input' );
exit();
}
if ( preg_match( '|//|', implode( ' ', $rsvp ) ) ) {
header( 'Location: ' . $req_uri . '&err=Invalid input' );
exit();
}
if ( isset( $rsvp['email'] ) ) {
// assuming the form includes email, test to make sure it's a valid one
if ( ! apply_filters( 'rsvmpmaker_spam_check', $rsvp['email'] ) ) {
header( 'Location: ' . $req_uri . '&err=' . urlencode( 'Invalid input.' ) );
exit();
}
if ( ! filter_var( $rsvp['email'], FILTER_VALIDATE_EMAIL ) ) {
header( 'Location: ' . $req_uri . '&err=' . urlencode( 'Invalid email.' ) );
exit();
}
}
if ( isset( $_POST['onfile'] ) ) {
$sql = $wpdb->prepare( 'SELECT details FROM ' . $wpdb->prefix . "rsvpmaker WHERE event='$event' AND email LIKE %s AND first LIKE %s AND last LIKE %s ORDER BY id DESC", $rsvp['email'], $rsvp['first'], $rsvp['last'] );
$details = $wpdb->get_var( $sql );
if ( $details ) {
$contact = unserialize( $details );
} else {
$contact = rsvpmaker_profile_lookup( $rsvp['email'] );
}
if ( $contact ) {
foreach ( $contact as $name => $value ) {
if ( ! isset( $rsvp[ $name ] ) ) {
$rsvp[ $name ] = $value;
}
}
}
}
global $current_user; // if logged in
$future = is_rsvpmaker_future( $event, 1 ); // if start time in the future (or within one hour)
$yesno = ( $future ) ? 1 : 2;// 2 for replay
$nv = array('first'=>$rsvp['first'], 'last'=>$rsvp['last'], 'email'=>$rsvp['email'], 'yesno' => $yesno, 'event'=>$event, 'note' => $note, 'details'=>serialize( $rsvp ), 'participants'=>1, 'user_id'=>$current_user->ID);
rsvpmaker_capture_email( $rsvp );
$rsvp_id = ( isset( $_POST['rsvp_id'] ) ) ? (int) $_POST['rsvp_id'] : 0;
if ( $rsvp_id ) {
$wpdb->update($wpdb->prefix . 'rsvpmaker',$nv,array('id'=>$rsvp_id));
} else {
$wpdb->insert($wpdb->prefix . 'rsvpmaker',$nv);
$rsvp_id = $wpdb->insert_id;
$sql = 'SELECT date FROM ' . $wpdb->prefix . "rsvpmaker_event WHERE event=$event ";
if ( empty( $wpdb->get_var( $sql ) ) ) {
$wpdb->insert($wpdb->prefix . 'rsvpmaker_event',array('event' => $event, 'post_title' => $post->post_title, 'date',get_rsvp_date( $event )));
}
}
if(!is_admin())
setcookie( 'rsvp_for_' . $event, $rsvp_id, time() + ( 60 * 60 * 24 * 90 ), '/', sanitize_text_field($_SERVER['SERVER_NAME']) );
if ( $future ) {
$cleanmessage = '';
foreach ( $rsvp as $name => $value ) {
$label = get_post_meta( $event, 'rsvpform' . $name, true );
if ( $label ) {
$name = $label;
}
$cleanmessage .= $name . ': ' . $value . "\n";// labels from form
}
$subject = __( 'You registered for ', 'rsvpmaker' ) . ' ' . esc_html( $post->post_title );
if ( ! empty( $_POST['note'] ) ) {
$cleanmessage .= ' Note: ' . sanitize_textarea_field( stripslashes( $_POST['note'] ) );
}
rsvp_notifications( $rsvp, $rsvp_to, $subject, $cleanmessage, $rsvp_confirm );
} else {
// cron for follow up messages
$sql = "SELECT *
FROM `$wpdb->postmeta`
WHERE meta_key REGEXP '_rsvp_reminder_msg_[0-9]{1,2}'
AND `post_id` = " . $event;
$results = $wpdb->get_results( $sql );
// $msg = var_export($results,true);
if ( $results ) {
foreach ( $results as $row ) {
$parts = explode( '_msg_', $row->meta_key );
$hours = $parts[1];
rsvpmaker_replay_cron( $event, $rsvp_id, $hours );
}
}
}
$landing_id = (int) $_POST['landing_id'];
$passcode = get_post_meta( $landing_id, '_webinar_passcode', true );
$landing_permalink = $req_uri . '&webinar=' . $passcode . '&e=' . $rsvp['email'];
header( 'Location: ' . $landing_permalink );
exit();
}
}
// end save replay rsvp
function save_rsvp($postdata, $live = true) {
global $wpdb;
global $rsvp_options;
global $post;
global $rsvp_id;
global $rsvpdata;
global $current_user; // if logged in
global $rsvpmaker_coupon_message;
$payment_details = '';
$currency = ( empty( $rsvp_options['paypal_currency'] ) ) ? 'usd' : strtolower( $rsvp_options['paypal_currency'] );
if ( $currency == 'usd' ) {
$currency = '$';
} elseif ( $currency == 'eur' ) {
$currency = '€';
}
else {
$currency = strtoupper($currency).' ';
}
$rsvp['fee_total'] = 0;
$rsvp_id = ( isset( $postdata['rsvp_id'] ) ) ? (int) $postdata['rsvp_id'] : 0;
$cleanmessage = '';
if ( isset( $postdata['withdraw'] ) ) {
foreach ( $postdata['withdraw'] as $withdraw_id ) {
$wpdb->query( 'UPDATE ' . $wpdb->prefix . "rsvpmaker SET yesno=0 WHERE id=".intval($withdraw_id) );
}
}
$test = ($live) ? wp_verify_nonce(rsvpmaker_nonce_data('data'),rsvpmaker_nonce_data('key')) : true;
if ( $test) {
$postdata = stripslashes_deep( $postdata );
// sanitize input
foreach ( $postdata['profile'] as $name => $value ) {
$rsvp[ $name ] = sanitize_text_field( $value );
}
if ( isset( $postdata['note'] ) ) {
$note = sanitize_textarea_field( $postdata['note'] );
} else {
$note = '';
}
$yesno = (int) $postdata['yesno'];
$answer = ( $yesno ) ? __( 'YES', 'rsvpmaker' ) : __( 'NO', 'rsvpmaker' );
$event = ( ! empty( $postdata['event'] ) ) ? (int) $postdata['event'] : 0;
if ( ! $event ) {
return 'Event ID not set';
}
if(!get_post_meta($event,'_rsvp_on'))
return;
// page hasn't loaded yet, so retrieve post variables based on event
$post = get_post( $event );
// get rsvp_to
$custom_fields = get_post_custom( $post->ID );
$rsvp_to = empty($custom_fields['_rsvp_to'][0]) ? $rsvp_options['rsvp_to'] : $custom_fields['_rsvp_to'][0];
$rsvp_confirm = rsvp_get_confirm( $post->ID );
$rsvp_max = empty($custom_fields['_rsvp_max'][0]) ? 0 : $custom_fields['_rsvp_max'][0];
$count = $wpdb->get_var( 'SELECT count(*) FROM ' . $wpdb->prefix . "rsvpmaker WHERE event=$event AND yesno=1" );
// if permalinks are not turned on, we need to append to query string not add our own ?
$guest_sql = array();
$guest_text = array();
if ( is_admin() ) {
$req_uri = admin_url( 'edit.php?page=rsvp_report&post_type=rsvpmaker&event=' . $event );
} else {
$req_uri = add_query_arg('e',$rsvp['email'],get_permalink($event));
}
if ( ! is_admin() && isset( $custom_fields['_rsvp_captcha'][0] ) && $custom_fields['_rsvp_captcha'][0] ) {
if ( ! isset( $_SESSION['captcha_key'] ) ) {
session_start();
}
if ( $_SESSION['captcha_key'] != md5( $postdata['captcha'] ) ) {
header( 'Location: ' . $req_uri . '&err=' . urlencode( 'security code not entered correctly! Please try again.' ) );
exit();
}
}
if ( ! is_admin() && ! empty( $rsvp_options['rsvp_recaptcha_site_key'] ) && ! empty( $rsvp_options['rsvp_recaptcha_secret'] ) ) {
if ( ! rsvpmaker_recaptcha_check( $rsvp_options['rsvp_recaptcha_site_key'], $rsvp_options['rsvp_recaptcha_secret'] ) ) {
header( 'Location: ' . $req_uri . '&err=' . urlencode( 'failed recaptcha test' ) );
exit();
}
}
if ( isset( $postdata['required'] ) || empty( $rsvp['email'] ) ) {
if(isset( $postdata['required'] ))
$required = explode( ',', $postdata['required'] );
if ( ! in_array( 'email', $required ) ) {
$required[] = 'email';
}
$missing = '';
if(!empty($required))
foreach ( $required as $r ) {
$r = sanitize_text_field($r);
if ( empty( $rsvp[ $r ] ) ) {
$missing .= $r . ' ';
}
}
if ( $missing != '' ) {
header( 'Location: ' . $req_uri . '&err=' . urlencode( 'missing required fields: ' . $missing ) );
exit();
}
}