-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patheme-formfields.php
5121 lines (4871 loc) · 237 KB
/
eme-formfields.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
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
function eme_new_formfield() {
$formfield = [
'field_type' => 'text',
'field_name' => '',
'field_values' => '',
'field_tags' => '',
'admin_values' => '',
'admin_tags' => '',
'field_attributes' => '',
'field_purpose' => '',
'field_condition' => '',
'field_required' => 0,
'export' => 0,
'extra_charge' => 0,
'searchable' => 0,
];
return $formfield;
}
function eme_formfields_page() {
global $wpdb;
if ( ! current_user_can( get_option( 'eme_cap_forms' ) ) && ( isset( $_GET['eme_admin_action'] ) || isset( $_POST['eme_admin_action'] ) ) ) {
$message = __( 'You have no right to update form fields!', 'events-made-easy' );
eme_formfields_table_layout( $message );
return;
}
if ( isset( $_GET['eme_admin_action'] ) && $_GET['eme_admin_action'] == 'edit_formfield' ) {
// edit formfield
$field_id = intval( $_GET['field_id'] );
eme_formfields_edit_layout( $field_id );
return;
}
if ( isset( $_POST['eme_admin_action'] ) && $_POST['eme_admin_action'] == 'add_formfield' ) {
check_admin_referer( 'eme_admin', 'eme_admin_nonce' );
eme_formfields_edit_layout();
return;
}
// Insert/Update/Delete Record
$formfields_table = EME_DB_PREFIX . EME_FORMFIELDS_TBNAME;
$validation_result = '';
$message = '';
if ( isset( $_POST['eme_admin_action'] ) ) {
check_admin_referer( 'eme_admin', 'eme_admin_nonce' );
if ( $_POST['eme_admin_action'] == 'do_editformfield' ) {
$formfield = [];
$field_id = intval( $_POST['field_id'] );
$formfield['field_name'] = trim( eme_sanitize_request( $_POST['field_name'] ) );
$formfield['field_type'] = trim( eme_esc_html( eme_sanitize_request( $_POST['field_type'] ) ) );
$formfield['extra_charge'] = intval( $_POST['extra_charge'] );
$formfield['searchable'] = intval( $_POST['searchable'] );
$formfield['field_required'] = intval( $_POST['field_required'] );
if ( eme_is_multifield( $formfield['field_type'] ) ) {
if (eme_is_empty_string($_POST['field_values'] )) {
$field_values_arr = array();
} else {
$field_values_arr = eme_sanitize_request( eme_convert_multi2array(eme_convert_array2multi(eme_text_split_newlines( $_POST['field_values'] ) )));
}
if (eme_is_empty_string($_POST['field_tags'] )) {
$field_tags_arr = array();
} else {
$field_tags_arr = eme_sanitize_request( eme_convert_multi2array(eme_convert_array2multi( eme_text_split_newlines( $_POST['field_tags'] ) )));
}
if (eme_is_empty_string($_POST['admin_values'] )) {
$admin_values_arr = array();
} else {
$admin_values_arr = eme_sanitize_request( eme_convert_multi2array(eme_convert_array2multi( eme_text_split_newlines( $_POST['admin_values'] ) )));
}
if (eme_is_empty_string($_POST['admin_tags'] )) {
$admin_tags_arr = array();
} else {
$admin_tags_arr = eme_sanitize_request( eme_convert_multi2array(eme_convert_array2multi( eme_text_split_newlines( $_POST['admin_tags'] ) )));
}
// some sanity checks
if (empty($field_values_arr)) {
$message = "<div id='message' class='eme-message-error'>".__( 'Error: the field value can not be empty for this type of field.', 'events-made-easy' )."</div>";
eme_formfields_edit_layout( $field_id, $message, $formfield );
return;
}
if (eme_array_has_dupes($field_values_arr) || eme_array_has_dupes($admin_values_arr)) {
$message = "<div id='message' class='eme-message-error'>".__( 'Error: the field values need to be unique for this type of field.', 'events-made-easy' )."</div>";
eme_formfields_edit_layout( $field_id, $message, $formfield );
return;
}
if (eme_array_has_dupes($field_tags_arr) || eme_array_has_dupes($admin_tags_arr)) {
$message = "<div id='message' class='eme-message-error'>".__( 'Error: the field tags need to be unique for this type of field.', 'events-made-easy' )."</div>";
eme_formfields_edit_layout( $field_id, $message, $formfield );
return;
}
if (! empty( $field_tags_arr ) && count( $field_values_arr ) != count( $field_tags_arr ) ) {
$message = "<div id='message' class='eme-message-error'>".__( 'Error: if you specify field tags, there need to be exact the same amount of tags as values.', 'events-made-easy' )."</div>";
eme_formfields_edit_layout( $field_id, $message, $formfield );
return;
}
if (! empty( $admin_tags_arr ) && count( $admin_values_arr ) != count( $admin_tags_arr ) ) {
$message = "<div id='message' class='eme-message-error'>".__( 'Error: if you specify field tags, there need to be exact the same amount of tags as values.', 'events-made-easy' )."</div>";
eme_formfields_edit_layout( $field_id, $message, $formfield );
return;
}
$formfield['field_values'] = eme_convert_array2multi( $field_values_arr );
$formfield['field_tags'] = eme_convert_array2multi( $field_tags_arr );
$formfield['admin_values'] = eme_convert_array2multi( $admin_values_arr );
$formfield['admin_tags'] = eme_convert_array2multi( $admin_tags_arr );
} else {
$formfield['field_values'] = trim( eme_sanitize_request( $_POST['field_values'] ) );
$formfield['field_tags'] = trim( eme_sanitize_request( $_POST['field_tags'] ) );
$formfield['admin_values'] = trim( eme_sanitize_request( $_POST['admin_values'] ) );
$formfield['admin_tags'] = trim( eme_sanitize_request( $_POST['admin_tags'] ) );
}
$formfield['field_attributes'] = trim( eme_sanitize_request( $_POST['field_attributes'] ) );
// for updates the field_purpose can be empty, so check for this
if ( ! empty( $_POST['field_purpose'] ) ) {
$formfield['field_purpose'] = trim( eme_sanitize_request( $_POST['field_purpose'] ) );
}
// condition can be null if there was a group assigned and the group got deleted, so let's check for that too
// we also remove group:0 from the array in case other groups are choosen too
if ( ! empty( $_POST['field_condition'] ) && is_array( $_POST['field_condition'] ) ) {
$condition_arr = eme_sanitize_request( $_POST['field_condition'] );
//Remove element by value using unset()
$key = array_search( 'group:0', $condition_arr );
if ( $key !== false ) {
unset( $condition_arr[ $key ] );
}
$formfield['field_condition'] = join( ',', eme_sanitize_request( $condition_arr ) );
}
if ( empty( $formfield['field_condition'] ) ) {
$formfield['field_condition'] = 'group:0';
}
if ( $formfield['field_type'] == 'file' || $formfield['field_type'] == 'multifile' || $formfield['field_purpose'] != 'people' ) {
$formfield['export'] = 0;
} elseif ( isset( $_POST['export'] ) ) {
$formfield['export'] = intval( $_POST['export'] );
} else {
$formfield['export'] = 0;
}
if ( $formfield['field_type'] == 'file' || $formfield['field_type'] == 'multifile' ) {
// files are not stored in the db, so we can't search on them
$formfield['searchable'] = 0;
// for type file, we only accept integers here
// since we use that as max size
if ( ! empty( $formfield['admin_values'] ) ) {
$formfield['admin_values'] = intval( $formfield['admin_values'] );
}
if ( ! empty( $formfield['field_values'] ) ) {
$formfield['field_values'] = intval( $formfield['field_values'] );
}
}
if ( $field_id > 0 ) {
$validation_result = $wpdb->update( $formfields_table, $formfield, [ 'field_id' => $field_id ] );
if ( $validation_result !== false ) {
$message = __( 'Successfully edited the field', 'events-made-easy' );
} else {
$message = __( 'There was a problem editing the field', 'events-made-easy' );
}
if ( get_option( 'eme_stay_on_edit_page' ) || $validation_result === false ) {
eme_formfields_edit_layout( $field_id, $message );
return;
}
} else {
$validation_result = $wpdb->insert( $formfields_table, $formfield );
if ( $validation_result !== false ) {
$new_field_id = $wpdb->insert_id;
$message = __( 'Successfully added the field', 'events-made-easy' );
} else {
$message = __( 'There was a problem adding the field', 'events-made-easy' );
}
if ( get_option( 'eme_stay_on_edit_page' ) || $validation_result === false ) {
eme_formfields_edit_layout( $new_field_id, $message );
return;
}
}
}
}
eme_formfields_table_layout( $message );
}
function eme_formfields_table_layout( $message = '' ) {
global $plugin_page;
$field_types = eme_get_fieldtypes();
$field_purposes = eme_get_fieldpurpose();
$nonce_field = wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false );
$destination = admin_url( "admin.php?page=$plugin_page" );
if ( empty( $message ) ) {
$hidden_class = 'eme-hidden';
} else {
$hidden_class = '';
}
?>
<div class="wrap nosubsub">
<div id="poststuff">
<div id="icon-edit" class="icon32">
</div>
<div id="formfields-message" class="notice is-dismissible eme-message-admin <?php echo $hidden_class; ?>">
<p><?php echo $message; ?></p>
</div>
<h1><?php esc_html_e( 'Add custom field', 'events-made-easy' ); ?></h1>
<div class="wrap">
<form id="formfields-new" method="post" action="<?php echo $destination; ?>">
<?php echo $nonce_field; ?>
<input type="hidden" name="eme_admin_action" value="add_formfield">
<input type="submit" class="button-primary" name="submit" value="<?php esc_html_e( 'Add custom field', 'events-made-easy' ); ?>">
</form>
</div>
<h1><?php esc_html_e( 'Manage custom fields', 'events-made-easy' ); ?></h1>
<form action="#" method="post">
<?php echo eme_ui_select( '', 'search_type', $field_types, __( 'Any', 'events-made-easy' ) ); ?>
<?php echo eme_ui_select( '', 'search_purpose', $field_purposes, __( 'Any', 'events-made-easy' ) ); ?>
<input type="search" name="search_name" id="search_name" placeholder="<?php esc_html_e( 'Field name', 'events-made-easy' ); ?>" class="eme_searchfilter" size=10>
<button id="FormfieldsLoadRecordsButton" class="button-secondary action"><?php esc_html_e( 'Filter fields', 'events-made-easy' ); ?></button>
</form>
<div id="bulkactions">
<form id='formfields-form' action="#" method="post">
<?php echo $nonce_field; ?>
<select id="eme_admin_action" name="eme_admin_action">
<option value="" selected="selected"><?php esc_html_e( 'Bulk Actions', 'events-made-easy' ); ?></option>
<option value="deleteFormfields"><?php esc_html_e( 'Delete selected fields', 'events-made-easy' ); ?></option>
</select>
<button id="FormfieldsActionsButton" class="button-secondary action"><?php esc_html_e( 'Apply', 'events-made-easy' ); ?></button>
<span class="rightclickhint" id="colvis">
<?php esc_html_e( 'Hint: rightclick on the column headers to show/hide columns', 'events-made-easy' ); ?>
</span>
</form>
</div>
<div id="FormfieldsTableContainer"></div>
</div>
</div>
<?php
}
function eme_formfields_edit_layout( $field_id = 0, $message = '', $t_formfield = [] ) {
global $plugin_page;
$field_types = eme_get_fieldtypes();
$field_purposes = eme_get_fieldpurpose();
$groups = eme_get_static_groups();
$peoplefieldconditions = [];
$peoplefieldconditions['group:0'] = __( 'Show for all people', 'events-made-easy' );
foreach ( $groups as $group ) {
$peoplefieldconditions[ 'group:' . $group['group_id'] ] = $group['name'];
}
$nonce_field = wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false );
if ( $field_id > 0 ) {
$used = eme_check_used_formfield( $field_id );
$formfield = eme_get_formfield( $field_id );
$h1_string = __( 'Edit field', 'events-made-easy' );
$action_string = __( 'Update field', 'events-made-easy' );
} else {
$used = 0;
$formfield = eme_new_formfield();
$h1_string = __( 'Create field', 'events-made-easy' );
$action_string = __( 'Add field', 'events-made-easy' );
}
if ( ! empty( $t_formfield ) ) {
$formfield = array_merge( $formfield, $t_formfield );
}
$layout = "
<div class='wrap'>
<div id='icon-edit' class='icon32'>
</div>
<h1>" . $h1_string . '</h1>';
if ( $message != '' ) {
$layout .= "
<div id='message' class='updated notice notice-success is-dismissible'>
<p>$message</p>
</div>";
}
if ( $used ) {
$layout .= "
<div id='eme_formfield_warning' class='updated below-h1 eme-message-admin'>
<p>" . __( 'Warning: this field is already used in RSVP replies, member signups, event or location definitions. Changing the field type or values might result in unwanted side effects.', 'events-made-easy' ) . '</p>
</div>';
}
$layout .= "
<div id='ajax-response'></div>
<form name='edit_formfield' id='edit_formfield' method='post' action='" . admin_url( "admin.php?page=$plugin_page" ) . "' class='validate'>
<input type='hidden' name='eme_admin_action' value='do_editformfield'>
$nonce_field
<input type='hidden' name='field_id' value='" . $field_id . "'>
<table class='form-table'>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='field_name'>" . __( 'Field name', 'events-made-easy' ) . "</label></th>
<td><input name='field_name' id='field_name' type='text' value='" . eme_esc_html( $formfield['field_name'] ) . "' size='40' required='required'></td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='field_type'>" . __( 'Field type', 'events-made-easy' ) . '</label></th>
<td>' . eme_ui_select( $formfield['field_type'], 'field_type', $field_types ) . '
<br>' . __( "For the types 'Date (JS)','Datetime (JS)' and 'Time (JS)' you can optionally enter a custom date format in 'HTML Field attributes' to be used when the field is shown.", 'events-made-easy' ) . '
<br>' . __( "For the type 'File' you can optionally enter a maximum upload size in MB in 'Field values'.", 'events-made-easy' ) . "
</td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='field_purpose'>" . __( 'Field purpose', 'events-made-easy' ) . '</label></th>
';
if ( ! $used || in_array( $formfield['field_purpose'], [ 'generic', 'rsvp', 'members' ] ) ) {
if ( in_array( $formfield['field_purpose'], [ 'rsvp', 'members' ] ) ) {
// for members or rsvp field: allow to change between those and generic
unset( $field_purposes['events'] );
unset( $field_purposes['locations'] );
unset( $field_purposes['memberships'] );
unset( $field_purposes['people'] );
}
$layout .= '
<td>' . eme_ui_select( $formfield['field_purpose'], 'field_purpose', $field_purposes ) . '
<br>' . __( "If you select 'RSVP field', 'People field' or 'Members field', this field will show up as an extra column in the overview table for bookings, people or members. Selecting 'Generic' will cause it to show up in the overview table for bookings or members.", 'events-made-easy' ) . '
<br>' . __( "If you select 'People field' you can add a condition to this field, meaning that if the person is in the group you selected in the condition, this is an extra field that will then be available to fill out for that person. This allows you to put people in e.g. a Volunteer group and then ask for more volunteer info.", 'events-made-easy' ) . '
<br>' . __( "If you select 'People field' and use this field in a RSVP or membership form, the info will be stored to the person, so you can ask for extra personal info when someone signs up. When editing the person, those fields will then be visible.", 'events-made-easy' ) . '
<br>' . __( "If you select 'Events field', 'Locations field' or 'Memberships field', this field will be used in the definition of the event, location or membership. Warning: this is unrelated to the use of custom fields in RSVP forms, so if you don't intend to use this field in the definition of events, locations or memberships, don't select this.", 'events-made-easy' ) . '
</td>';
} else {
$layout .= '<td>' . eme_get_fieldpurpose( $formfield['field_purpose'] );
$layout .= "<input type='hidden' name='field_purpose' id='field_purpose' value='" . $formfield['field_purpose'] . "'></td>";
}
$field_condition_arr = explode( ',', $formfield['field_condition'] );
$layout .= "
</tr>
<tr id='tr_export' class='form-field'>
<th scope='row' style='vertical-align:top'><label for='export'>" . __( 'Include in CSV export', 'events-made-easy' ) . '</label></th>
<td>' . eme_ui_select_binary( $formfield['export'], 'export' ) . '
<br>' . __( 'Include this field in the CSV export for bookings.', 'events-made-easy' ) . "
</td>
</tr>
<tr id='tr_field_condition' class='form-field'>
<th scope='row' style='vertical-align:top'><label for='field_condition'>" . __( 'Field condition', 'events-made-easy' ) . '</label></th>
<td>' . eme_ui_multiselect( $field_condition_arr, 'field_condition', $peoplefieldconditions, 5, '', 0, ' eme_select2_width50_class' ) . '
<br>' . __( 'Only show this field if the person is member of the selected group. Leave empty to add this field to all people.', 'events-made-easy' ) . "
</td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='field_required'>" . __( 'Required field', 'events-made-easy' ) . '</label></th>
<td>' . eme_ui_select_binary( $formfield['field_required'], 'field_required' ) . '
<br>' . __( 'Use this if the field is required to be filled out.', 'events-made-easy' ) . '
<br>' . __( 'This overrides the use of "#REQ" when defining a field in a form.', 'events-made-easy' ) . "
</tr>
<tr id='tr_searchable' class='form-field'>
<th scope='row' style='vertical-align:top'><label for='searchable'>" . __( 'Searchable or sortable', 'events-made-easy' ) . '</label></th>
<td>' . eme_ui_select_binary( $formfield['searchable'], 'searchable' ) . '
<br>' . __( 'When defining a custom field, it is also used in the administration interface for events, locations, people, members (depending on its purpose).', 'events-made-easy' ) . '
<br>' . __( 'However, being able to search or sort on such a field is more heavy on the database, that is why by default this parameter is set to "No".', 'events-made-easy' ) . '
<br>' . __( 'If you want to search or sort on such a field, set this parameter to "Yes".', 'events-made-easy' ) . "
</tr>
<tr id='tr_extra_charge' class='form-field'>
<th scope='row' style='vertical-align:top'><label for='extra_charge'>" . __( 'Extra charge', 'events-made-easy' ) . '</label></th>
<td>' . eme_ui_select_binary( $formfield['extra_charge'], 'extra_charge' ) . '
<br>' . __( 'Use this if the field indicates an extra charge to the total price (can be negative to indicate a discount), in which case you should also set the field value to the charge.', 'events-made-easy' ) . '
<br>' . __( 'For multivalue fields (like e.g. dropdown) the field values should indicate the price for that selection (and the price needs to be unique).', 'events-made-easy' ) . '
<br>' . __( "This is ignored for fields with purpose 'Events field', 'Locations field' or 'Memberships field'", 'events-made-easy' ) . "
</tr>
<tr id='tr_field_values' class='form-field'>
<th scope='row' style='vertical-align:top'><label for='field_values'>" . __( 'Field values', 'events-made-easy' ) . '</label></th>';
if ( eme_is_multifield( $formfield['field_type'] ) ) {
$value = str_replace( '||', "\n", eme_esc_html( $formfield['field_values'] ) );
// textarea should always start with a newline, but this causes an empty first line to be removed, so we add an extra newline
$layout .= "<td><textarea name='field_values' id='field_values'>\n$value</textarea>";
} else {
$layout .= "<td><input name='field_values' id='field_values' type='text' value='" . eme_esc_html( $formfield['field_values'] ) . "' size='40'>";
}
$layout .= '
<br>' . __( 'Enter here the default value a field should have, or for multivalue field types enter the list of values.', 'events-made-easy' ) . '
<br>' . __( 'For multivalue field types (like Drop Down), either use "||" to separate the different values (e.g.: a1||a2||a3), put one value per line (only possible when editing the custom field), or use a combination of both notations.', 'events-made-easy' ) . ' ' . __( 'If you want to start your custom dropdown field with an empty value, start with "||" (for example: "||a1||a2||a3") or start with an empty line (only possible when editing the custom field).', 'events-made-easy' ) . '
<br>' . __( "For the types 'Date (Javascript)', 'Datetime (Javascript)' and 'Time (Javascript)' you can optionally mention the string 'NOW', which will make sure the field uses the current date and/or time the moment it is shown.", 'events-made-easy' ) . '
<br>' . __( "For the type 'File' you can optionally enter a maximum upload size in MB.", 'events-made-easy' ) . "
</td>
</tr>
<tr id='tr_field_tags' class='form-field'>
<th scope='row' style='vertical-align:top'><label for='field_tags'>" . __( 'Field tags', 'events-made-easy' ) . '</label></th>';
if ( eme_is_multifield( $formfield['field_type'] ) ) {
$value = str_replace( '||', "\n", eme_esc_html( $formfield['field_tags'] ) );
// textarea should always start with a newline, but this causes an empty first line to be removed, so we add an extra newline
$layout .= "<td><textarea name='field_tags' id='field_tags'>\n$value</textarea>";
} else {
$layout .= "<td><input name='field_tags' id='field_tags' type='text' value='" . eme_esc_html( $formfield['field_tags'] ) . "' size='40'>";
}
$layout .= '
<br>' . __( 'This option determines the "visible" value people will see for the field.', 'events-made-easy' ) . '
<br>' . __( 'For multivalue fields, you can here enter the "visible" tag people will see per value (so, if "Field values" contain e.g. "a1||a2||a3", you can use here e.g. "Text a1||Text a2||Text a3").', 'events-made-easy' ) . '
<br>' . __( 'If left empty, the field values will be used (so the visible tag equals the value).', 'events-made-easy' ) . "
</td>
</tr>
<tr id='tr_admin_values' class='form-field'>
<th scope='row' style='vertical-align:top'><label for='admin_values'>" . __( 'Admin Field values', 'events-made-easy' ) . '</label></th>';
if ( eme_is_multifield( $formfield['field_type'] ) ) {
$value = str_replace( '||', "\n", eme_esc_html( $formfield['admin_values'] ) );
// textarea should always start with a newline, but this causes an empty first line to be removed, so we add an extra newline
$layout .= "<td><textarea name='admin_values' id='admin_values'>\n$value</textarea>";
} else {
$layout .= "<td><input name='admin_values' id='admin_values' type='text' value='" . eme_esc_html( $formfield['admin_values'] ) . "' size='40'>";
}
$layout .= '
<br>' . __( 'If you want a bigger number of choices for e.g. dropdown fields in the admin interface, enter the possible values here', 'events-made-easy' ) . '
<br>' . __( "For the type 'File' you can optionally enter a maximum upload size in MB.", 'events-made-easy' ) . "
</td>
</tr>
<tr id='tr_admin_tags' class='form-field'>
<th scope='row' style='vertical-align:top'><label for='admin_tags'>" . __( 'Admin Field tags', 'events-made-easy' ) . '</label></th>';
if ( eme_is_multifield( $formfield['field_type'] ) ) {
$value = str_replace( '||', "\n", eme_esc_html( $formfield['admin_tags'] ) );
// textarea should always start with a newline, but this causes an empty first line to be removed, so we add an extra newline
$layout .= "<td><textarea name='admin_tags' id='admin_tags'>\n$value</textarea>";
} else {
$layout .= "<td><input name='admin_tags' id='admin_tags' type='text' value='" . eme_esc_html( $formfield['admin_tags'] ) . "' size='40'>";
}
$layout .= '
<br>' . __( 'If you want a bigger number of choices for e.g. dropdown fields in the admin interface, enter the possible tags here', 'events-made-easy' ) . "
</td>
</tr>
<tr id='tr_field_attributes' class='form-field'>
<th scope='row' style='vertical-align:top'><label for='field_attributes'>" . __( 'HTML field attributes', 'events-made-easy' ) . "</label></th>
<td><input name='field_attributes' id='field_attributes' type='text' value='" . eme_esc_html( $formfield['field_attributes'] ) . "' size='40'>
<br>" . __( 'Here you can specify extra html attributes for your field (like size, maxlength, pattern, ...).', 'events-made-easy' ) . '
<br>' . __( "For the types 'Date (Javascript)', 'Datetime (Javascript)' and 'Time (Javascript)' enter a valid PHP-format of the date you like to see when entering/showing the value (unrecognized characters in the format will cause the result to be empty). If left empty, the WordPress settings for date format will be used.", 'events-made-easy' ) . "
</td>
</tr>
</table>
<p class='submit'><input type='submit' class='button-primary' name='submit' value='" . $action_string . "'></p>
</form>
</div>
<p>" . __( 'For more information about form fields, see ', 'events-made-easy' ) . "<a target='_blank' href='https://www.e-dynamics.be/wordpress/?cat=44'>" . __( 'the documentation', 'events-made-easy' ) . '</a></p>
';
echo $layout;
}
function eme_get_dyndata_conditions() {
$data = [
'eq' => __( 'equal to', 'events-made-easy' ),
'ne' => __( 'not equal to', 'events-made-easy' ),
'lt' => __( 'lower than', 'events-made-easy' ),
'gt' => __( 'greater than', 'events-made-easy' ),
'ge' => __( 'greater than or equal to', 'events-made-easy' ),
'contains' => __( 'contains', 'events-made-easy' ),
'notcontains' => __( 'does not contain', 'events-made-easy' ),
'incsv' => __( 'CSV list contains', 'events-made-easy' ),
'notincsv' => __( 'CSV list does not contain', 'events-made-easy' ),
];
return $data;
}
function eme_get_used_formfield_ids() {
global $wpdb;
$table = EME_DB_PREFIX . EME_ANSWERS_TBNAME;
return $wpdb->get_col( "SELECT DISTINCT field_id FROM $table" );
}
function eme_check_used_formfield( $field_id ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_ANSWERS_TBNAME;
$query = $wpdb->prepare( "SELECT COUNT(*) FROM $table WHERE field_id=%d", $field_id );
$count = $wpdb->get_var( $query );
$table = EME_DB_PREFIX . EME_EVENTS_CF_TBNAME;
$query = $wpdb->prepare( "SELECT COUNT(*) FROM $table WHERE field_id=%d", $field_id );
$count += $wpdb->get_var( $query );
$table = EME_DB_PREFIX . EME_LOCATIONS_CF_TBNAME;
$query = $wpdb->prepare( "SELECT COUNT(*) FROM $table WHERE field_id=%d", $field_id );
$count += $wpdb->get_var( $query );
return $count;
}
function eme_get_formfields( $ids = '', $purpose = '' ) {
global $wpdb;
$formfields_table = EME_DB_PREFIX . EME_FORMFIELDS_TBNAME;
$where = '';
$where_arr = [];
if ( ! empty( $ids ) && eme_is_list_of_int( $ids ) ) {
$where_arr[] = "field_id IN ($ids)";
}
if ( ! empty( $purpose ) ) {
$purposes = explode( ',', $purpose );
$purposes_arr = [];
foreach ( $purposes as $tmp_p ) {
$purposes_arr[] = "field_purpose='" . esc_sql( $tmp_p ) . "'";
}
$where_arr[] = '(' . join( ' OR ', $purposes_arr ) . ')';
}
if ( ! empty( $where_arr ) ) {
$where = 'WHERE ' . join( ' AND ', $where_arr );
}
return $wpdb->get_results( "SELECT * FROM $formfields_table $where", ARRAY_A );
}
function eme_get_searchable_formfields( $purpose = '', $include_generic = 0 ) {
global $wpdb;
$formfields_table = EME_DB_PREFIX . EME_FORMFIELDS_TBNAME;
$where = '';
$where_arr = [];
$where_arr[] = 'searchable=1';
$where_arr[] = "field_type <> 'file' AND field_type <> 'multifile'";
if ( ! empty( $purpose ) ) {
if ( $include_generic ) {
$where_arr[] = "(field_purpose='" . esc_sql( $purpose ) . "' OR field_purpose='generic')";
} else {
$where_arr[] = "field_purpose='" . esc_sql( $purpose ) . "'";
}
}
if ( ! empty( $where_arr ) ) {
$where = 'WHERE ' . join( ' AND ', $where_arr );
}
return $wpdb->get_results( "SELECT * FROM $formfields_table $where", ARRAY_A );
}
function eme_get_formfield( $field_info ) {
global $wpdb;
$formfields_table = EME_DB_PREFIX . EME_FORMFIELDS_TBNAME;
if ( is_numeric( $field_info ) || $field_info == 'performer' ) {
$formfield = wp_cache_get( "eme_formfield $field_info" );
} else {
$formfield = false;
}
if ( $formfield === false ) {
if ( is_numeric( $field_info ) ) {
$sql = $wpdb->prepare( "SELECT * FROM $formfields_table WHERE field_id=%d", $field_info ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
} else {
$sql = $wpdb->prepare( "SELECT * FROM $formfields_table WHERE field_name=%s LIMIT 1", $field_info ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
}
$formfield = $wpdb->get_row( $sql, ARRAY_A ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
if ( is_numeric( $field_info ) || $field_info == 'performer' ) {
wp_cache_set( "eme_formfield $field_info", $formfield, '', 60 );
}
}
return $formfield;
}
function eme_delete_formfields( $ids_arr ) {
global $wpdb;
$formfields_table = EME_DB_PREFIX . EME_FORMFIELDS_TBNAME;
if ( ! empty( $ids_arr ) && eme_is_numeric_array( $ids_arr ) ) {
$ids_list = implode(',', $ids_arr);
$validation_result = $wpdb->query( "DELETE FROM $formfields_table WHERE field_id IN ($ids_list)" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
if ( $validation_result !== false ) {
$answers_table = EME_DB_PREFIX . EME_ANSWERS_TBNAME;
$wpdb->query( "DELETE FROM $answers_table WHERE field_id IN ($ids_list)" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$events_customfields_table = EME_DB_PREFIX . EME_EVENTS_CF_TBNAME;
$wpdb->query( "DELETE FROM $events_customfields_table WHERE field_id IN ($ids_list)" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$locations_customfields_table = EME_DB_PREFIX . EME_LOCATIONS_CF_TBNAME;
$wpdb->query( "DELETE FROM $locations_customfields_table WHERE field_id IN ($ids_list)" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
$memberships_customfields_table = EME_DB_PREFIX . EME_MEMBERSHIPS_CF_TBNAME;
$wpdb->query( "DELETE FROM $memberships_customfields_table WHERE field_id IN ($ids_list)" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
return true;
} else {
return false;
}
} else {
return false;
}
}
function eme_get_fieldpurpose( $purpose = '' ) {
$uses = [
'generic' => __( 'Generic', 'events-made-easy' ),
'events' => __( 'Events field', 'events-made-easy' ),
'locations' => __( 'Locations field', 'events-made-easy' ),
'rsvp' => __( 'RSVP field', 'events-made-easy' ),
'people' => __( 'People field', 'events-made-easy' ),
'members' => __( 'Members field', 'events-made-easy' ),
'memberships' => __( 'Memberships field', 'events-made-easy' ),
];
if ( $purpose ) {
if ( isset( $uses[ $purpose ] ) ) {
return $uses[ $purpose ];
} else {
return $uses['generic'];
}
} else {
return $uses;
}
}
function eme_get_fieldtypes() {
$types = [
'text' => __( 'Text', 'events-made-easy' ),
'textarea' => __( 'Textarea', 'events-made-easy' ),
'dropdown' => __( 'Dropdown', 'events-made-easy' ),
'dropdown_multi' => __( 'Dropdown (multiple)', 'events-made-easy' ),
'radiobox' => __( 'Radiobox', 'events-made-easy' ),
'radiobox_vertical' => __( 'Radiobox (vertical)', 'events-made-easy' ),
'checkbox' => __( 'Checkbox', 'events-made-easy' ),
'checkbox_vertical' => __( 'Checkbox (vertical)', 'events-made-easy' ),
'password' => __( 'Password', 'events-made-easy' ),
'hidden' => __( 'Hidden', 'events-made-easy' ),
'readonly' => __( 'Readonly', 'events-made-easy' ),
'file' => __( 'File upload', 'events-made-easy' ),
'multifile' => __( 'Multiple files upload', 'events-made-easy' ),
'date_js' => __( 'Date (Javascript)', 'events-made-easy' ),
'date' => __( 'Date (HTML5)', 'events-made-easy' ),
'datetime_js' => __( 'Datetime (Javascript)', 'events-made-easy' ),
'datetime-local' => __( 'Datetime-local (HTML5)', 'events-made-easy' ),
'month' => __( 'Month (HTML5)', 'events-made-easy' ),
'week' => __( 'Week (HTML5)', 'events-made-easy' ),
'time' => __( 'Time (HTML5)', 'events-made-easy' ),
'time_js' => __( 'Time (Javascript)', 'events-made-easy' ),
'color' => __( 'Color (HTML5)', 'events-made-easy' ),
'email' => __( 'Email (HTML5)', 'events-made-easy' ),
'number' => __( 'Number (HTML5)', 'events-made-easy' ),
'range' => __( 'Range (HTML5)', 'events-made-easy' ),
'tel' => __( 'Tel (HTML5)', 'events-made-easy' ),
'url' => __( 'Url (HTML5)', 'events-made-easy' ),
];
return $types;
}
function eme_get_fieldtype( $type ) {
$fieldtypes = eme_get_fieldtypes();
return $fieldtypes[ $type ];
}
function eme_is_multifield( $type ) {
return in_array( $type, [ 'dropdown', 'dropdown_multi', 'radiobox', 'radiobox_vertical', 'checkbox', 'checkbox_vertical' ] );
}
function eme_get_formfield_html( $formfield, $field_name, $entered_val, $required, $class = '', $ro = 0, $force_single = 0, $force_edit = 0 ) {
if ( empty( $formfield ) ) {
return;
}
$simple_fieldname = 'FIELD' . $formfield['field_id'];
if ( empty( $field_name ) ) {
$field_name = $simple_fieldname;
}
$field_name = wp_strip_all_tags( $field_name );
if ( eme_is_admin_request() && has_filter( 'eme_admin_field_value_filter' ) ) {
$entered_val = apply_filters( 'eme_admin_field_value_filter', $formfield, $field_name, $entered_val );
} elseif ( ! eme_is_admin_request() && has_filter( 'eme_field_value_filter' ) ) {
$entered_val = apply_filters( 'eme_field_value_filter', $formfield, $field_name, $entered_val );
}
if ( ! is_array( $entered_val ) && eme_is_multi( $entered_val ) ) {
$entered_val = eme_convert_multi2array( $entered_val );
}
if ( $ro ) {
$readonly = "readonly='readonly'";
$disabled = "disabled='disabled'";
} else {
$readonly = '';
$disabled = '';
}
if ( $class ) {
$class_att = "class='$class'";
} else {
$class_att = '';
}
if ( $required ) {
$required_att = "required='required'";
} else {
$required_att = '';
}
if ( (eme_is_admin_request() && isset( $_REQUEST['eme_admin_action'] )) || $force_edit ) {
// fields can have a different value for front/backend for multi-fields
if ( ! empty( $formfield['admin_values'] ) ) {
$field_values = $formfield['admin_values'];
} else {
$field_values = $formfield['field_values'];
}
if ( ! empty( $formfield['admin_tags'] ) ) {
$field_tags = $formfield['admin_tags'];
} else {
$field_tags = $formfield['field_tags'];
}
} else {
$field_values = $formfield['field_values'];
$field_tags = $formfield['field_tags'];
}
$field_attributes = $formfield['field_attributes'];
if ( empty( $field_tags ) ) {
$field_tags = $field_values;
}
$html = '';
switch ( $formfield['field_type'] ) {
case 'text':
case 'date':
case 'datetime-local':
case 'month':
case 'week':
case 'time':
case 'color':
case 'email':
case 'number':
case 'range':
case 'tel':
case 'url':
# for text fields
$value = $entered_val;
if ( empty( $value ) ) {
$value = eme_translate( $field_tags );
}
if ( empty( $value ) ) {
$value = $field_values;
}
$value = eme_esc_html( $value );
$html = "<input $readonly $required_att type='" . $formfield['field_type'] . "' name='$field_name' id='$field_name' value='$value' $field_attributes $class_att>";
break;
case 'hidden':
$value = eme_translate( $field_tags );
if ( empty( $value ) ) {
$value = $field_values;
}
$value = eme_esc_html( $value );
if ( eme_is_admin_request() ) {
$html = "<input $readonly $required_att type='text' name='$field_name' id='$field_name' value='$value' $field_attributes $class_att><br>";
$html .= __( 'This is a hidden field, but in the backend it is shown as text so an admin can see its value and optionally change it', 'events-made-easy' );
} else {
$html = "<input $readonly $required_att type='hidden' name='$field_name' id='$field_name' value='$value' $field_attributes $class_att>";
}
break;
case 'password':
$value = eme_esc_html( $entered_val );
#$html = "<input $readonly $required_att type='".$formfield['field_type']."' name='$field_name' id='$field_name' value='$value' $field_attributes $class_att>";
$html = "<input $readonly $required_att type='text' class='eme_passwordfield' autocomplete='off' name='$field_name' id='$field_name' value='$value' $field_attributes $class_att>";
break;
case 'readonly':
$value = eme_esc_html( $entered_val );
if ( empty( $value ) ) {
$value = eme_translate( $field_tags );
}
if ( empty( $value ) ) {
$value = $field_values;
}
$value = eme_esc_html( $value );
$html = "<input readonly='readonly' $required_att type='text' name='$field_name' id='$field_name' value='$value' $field_attributes $class_att>";
break;
case 'dropdown':
# dropdown
$values = eme_convert_multi2array( $field_values );
$tags = eme_convert_multi2array( $field_tags );
$my_arr = [];
// since the values for a dropdown field need not be unique, we give them as an array to be built with eme_ui_select
foreach ( $values as $key => $val ) {
$tag = eme_translate( $tags[ $key ] );
$new_el = [
0 => $val,
1 => $tag,
];
$my_arr[] = $new_el;
}
$html = eme_ui_select( $entered_val, $field_name, $my_arr, '', $required, $class, $field_attributes . ' ' . $disabled );
break;
case 'dropdown_multi':
# dropdown, multiselect
$values = eme_convert_multi2array( $field_values );
$tags = eme_convert_multi2array( $field_tags );
$my_arr = [];
// since the values for a dropdown field need not be unique, we give them as an array to be built with eme_ui_select
foreach ( $values as $key => $val ) {
$tag = eme_translate( $tags[ $key ] );
$new_el = [
0 => $val,
1 => $tag,
];
$my_arr[] = $new_el;
}
// force_single can be 1 (only possible case is in the filterform for now)
if ( $force_single == 1 ) {
$html = eme_ui_select( $entered_val, $field_name, $my_arr, '', $required, $class, $field_attributes . ' ' . $disabled );
} else {
$html = eme_ui_multiselect( $entered_val, $field_name, $my_arr, 5, '', $required, $class . ' eme_select2_width50_class', $field_attributes . ' ' . $disabled );
}
break;
case 'textarea':
# textarea
$value = $entered_val;
if ( empty( $value ) ) {
$value = eme_translate( $field_tags );
}
if ( empty( $value ) ) {
$value = $field_values;
}
$value = eme_esc_html( $value );
$html = "<textarea $class_att $required_att name='$field_name' id='$field_name' $field_attributes $readonly>$value</textarea>";
break;
case 'radiobox':
# radiobox
$values = eme_convert_multi2array( $field_values );
$tags = eme_convert_multi2array( $field_tags );
$my_arr = [];
foreach ( $values as $key => $val ) {
$tag = $tags[ $key ];
$my_arr[ $val ] = eme_translate( $tag );
}
$html = eme_ui_radio( $entered_val, $field_name, $my_arr, true, $required, $class, $field_attributes . ' ' . $disabled );
break;
case 'radiobox_vertical':
# radiobox, vertical
$values = eme_convert_multi2array( $field_values );
$tags = eme_convert_multi2array( $field_tags );
$my_arr = [];
foreach ( $values as $key => $val ) {
$tag = $tags[ $key ];
$my_arr[ $val ] = eme_translate( $tag );
}
$html = eme_ui_radio( $entered_val, $field_name, $my_arr, false, $required, $class, $field_attributes . ' ' . $disabled );
break;
case 'checkbox':
# checkbox
$values = eme_convert_multi2array( $field_values );
$tags = eme_convert_multi2array( $field_tags );
$my_arr = [];
foreach ( $values as $key => $val ) {
$tag = $tags[ $key ];
$my_arr[ $val ] = eme_translate( $tag );
}
// checkboxes can't be made required in the frontend, since that would require all checkboxes to be checked
// so we use a div+jquery to accomplish this
$html = '';
if ( $required ) {
$html = '<div class="eme-checkbox-group-required">';
}
$html .= eme_ui_checkbox( $entered_val, $field_name, $my_arr, true, 0, $class, $field_attributes . ' ' . $disabled );
if ( $required ) {
$html .= '</div>';
}
break;
case 'checkbox_vertical':
# checkbox, vertical
$values = eme_convert_multi2array( $field_values );
$tags = eme_convert_multi2array( $field_tags );
$my_arr = [];
foreach ( $values as $key => $val ) {
$tag = $tags[ $key ];
$my_arr[ $val ] = eme_translate( $tag );
}
// checkboxes can't be made required in the frontend, since that would require all checkboxes to be checked
// so we use a div+jquery to accomplish this
$html = '';
if ( $required ) {
$html = '<div class="eme-checkbox-group-required">';
}
$html .= eme_ui_checkbox( $entered_val, $field_name, $my_arr, false, 0, $class, $field_attributes . ' ' . $disabled );
if ( $required ) {
$html .= '</div>';
}
break;
case 'file':
// file upload
// in the admin interface, no upload is required (otherwise edit will never work as well ...)
if ( eme_is_admin_request() || $force_edit ) {
$required = 0;
$required_att = '';
}
// only simple field names accepted, that way the upload code can stay simple and we don't need to worry about arrays and such
if ( $field_name != $simple_fieldname ) {
// the field_name can be something like an array name, so we remove redundant info (like the field id in it) and keep integers
$clean = preg_replace( "/$simple_fieldname/", '', $field_name );
$indexes = preg_replace( '/[^\d]/i', '', $clean );
$field_name = $simple_fieldname . '_' . $indexes;
}
// if the entered_val is not empty it means the file is already uploaded, so we don't show the form
$html = '<span>';
if ( ! empty( $entered_val ) ) {
$showhide_style = 'style="display:none;"';
} else {
$showhide_style = '';
}
$html .= "<input type='file' $disabled $class_att $required_att name='$field_name' id='$field_name' $showhide_style $field_attributes>";
if ( ! empty( $entered_val ) ) {
foreach ( $entered_val as $file ) {
$html .= eme_get_uploaded_file_linkdelete( $file );
}
}
if ( empty( $entered_val ) ) {
$html .= '<br>';
}
$html .= '</span>';
break;
case 'multifile':
// file upload
// in the admin interface, no upload is required (otherwise edit will never work as well ...)
if ( eme_is_admin_request() || $force_edit ) {
$required = 0;
$required_att = '';
}
// only simple field names accepted, that way the upload code can stay simple and we don't need to worry about arrays and such
if ( $field_name != $simple_fieldname ) {
// the field_name can be something like an array name, so we remove redundant info (like the field id in it) and keep integers
$clean = preg_replace( "/$simple_fieldname/", '', $field_name );
$indexes = preg_replace( '/[^\d]/i', '', $clean );
$field_name = $simple_fieldname . '_' . $indexes;
}
// if the entered_val is not empty it means the file is already uploaded, so we don't show the form
$html = '<span>';
if ( ! empty( $entered_val ) ) {
$showhide_style = 'style="display:none;"';
} else {
$showhide_style = '';
}
$html .= "<input type='file' $disabled $class_att $required_att name='{$field_name}[]' id='$field_name' multiple $showhide_style $field_attributes>";
if ( ! empty( $entered_val ) ) {
foreach ( $entered_val as $file ) {
$html .= eme_get_uploaded_file_linkdelete( $file );
}
}
if ( empty( $entered_val ) ) {
$html .= '<br>';
}
$html .= '</span>';
break;
case 'date_js':
# for date JS field
$value = $entered_val;
if ( empty( $value ) ) {
$value = eme_translate( $field_tags );
}
if ( empty( $value ) ) {
$value = $field_values;
}
if ( $value == 'NOW' ) {
$eme_date_obj = new ExpressiveDate( 'now', EME_TIMEZONE );
$value = $eme_date_obj->getDate();
}
$value = eme_esc_html( $value );
if ( empty( $field_attributes ) ) {
$field_attributes = EME_WP_DATE_FORMAT;
}
$dateformat = $field_attributes;
$html = "<input type='hidden' name='$field_name' id='$field_name' value='$value' $class_att>";
$html .= "<input $required_att readonly='readonly' $disabled type='text' name='dp_{$field_name}' id='dp_{$field_name}' data-date='$value' data-date-format='$dateformat' data-alt-field='#$field_name' class='eme_formfield_fdate $class'>";
break;
case 'datetime_js':
# for datetime JS field
$value = $entered_val;
if ( empty( $value ) ) {
$value = eme_translate( $field_tags );
}
if ( empty( $value ) ) {
$value = $field_values;
}
if ( $value == 'NOW' ) {
$eme_date_obj = new ExpressiveDate( 'now', EME_TIMEZONE );
$value = $eme_date_obj->getDateTime();
}
$value = eme_esc_html( $value );
$js_value = eme_js_datetime( $value, EME_TIMEZONE );
if ( empty( $field_attributes ) ) {
$field_attributes = EME_WP_DATE_FORMAT .' '. EME_WP_TIME_FORMAT;
}
$dateformat = $field_attributes;
$html = "<input type='hidden' name='$field_name' id='$field_name' value='$value' $class_att>";
$html .= "<input $required_att readonly='readonly' $disabled type='text' name='dp_{$field_name}' id='dp_{$field_name}' data-date='$js_value' data-date-format='$dateformat' data-alt-field='#$field_name' class='eme_formfield_fdatetime $class'>";
break;
case 'time_js':
# for time JS field
$value = $entered_val;
if ( empty( $value ) ) {
$value = eme_translate( $field_tags );
}
if ( empty( $value ) ) {
$value = $field_values;
}
if ( $value == 'NOW' ) {
$eme_date_obj = new ExpressiveDate( 'now', EME_TIMEZONE );
$value = $eme_date_obj->getTime();
}
$value = eme_esc_html( $value );
if ( empty( $field_attributes ) ) {
$field_attributes = EME_WP_TIME_FORMAT;
}
$dateformat = $field_attributes;
if ( ! empty( $value ) ) {
$date_obj = ExpressiveDate::createFromFormat( 'H:i:s', $value, ExpressiveDate::parseSuppliedTimezone( EME_TIMEZONE ) );
$value = $date_obj->format( $dateformat );
}
$html = "<input $required_att $disabled name='$field_name' id='$field_name' value='$value' data-time-format='$dateformat' class='eme_formfield_timepicker $class'>";
break;
}
return $html;
}
function eme_replace_eventtaskformfields_placeholders( $format, $task, $event ) {
$used_spaces = eme_count_task_approved_signups( $task['task_id'] );
$free_spaces = $task['spaces'] - $used_spaces;