-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
eme-discounts.php
1849 lines (1724 loc) · 72.6 KB
/
eme-discounts.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_discount() {
$discount = [
'name' => '',
'description' => '',
'type' => EME_DISCOUNT_TYPE_FIXED,
'value' => 0,
'coupon' => '',
'dgroup' => '',
'valid_from' => '',
'valid_to' => '',
'properties' => [],
'use_per_seat' => 0,
'strcase' => 1,
'count' => 0,
'maxcount' => 0,
];
$discount['properties'] = eme_init_discount_props( $discount['properties'] );
return $discount;
}
function eme_new_discountgroup() {
$discountgroup = [
'name' => '',
'description' => '',
'maxdiscounts' => 0,
];
return $discountgroup;
}
function eme_init_discount_props( $props ) {
if ( ! isset( $props['invite_only'] ) ) {
$props['invite_only'] = 0;
}
if ( ! isset( $props['wp_users_only'] ) ) {
$props['wp_users_only'] = 0;
}
if ( ! isset( $props['wp_role'] ) ) {
$props['wp_role'] = '';
}
if ( ! isset( $props['group_ids'] ) ) {
$props['group_ids'] = [];
}
if ( ! isset( $props['membership_ids'] ) ) {
$props['membership_ids'] = [];
}
return $props;
}
function eme_discounts_page() {
if ( ! current_user_can( get_option( 'eme_cap_discounts' ) ) && ( isset( $_GET['eme_admin_action'] ) || isset( $_POST['eme_admin_action'] ) ) ) {
$message = __( 'You have no right to manage discounts!', 'events-made-easy' );
eme_discounts_main_layout( $message );
return;
}
$message = '';
$csvMimes = [ 'text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain' ];
// handle possible ations
if ( isset( $_POST['eme_admin_action'] ) ) {
check_admin_referer( 'eme_admin', 'eme_admin_nonce' );
if ( $_POST['eme_admin_action'] == 'do_importdiscounts' && isset( $_FILES['eme_csv'] ) && current_user_can( get_option( 'eme_cap_cleanup' ) ) ) {
$inserted = 0;
$errors = 0;
$error_msg = '';
//validate whether uploaded file is a csv file
if ( ! empty( $_FILES['eme_csv']['name'] ) && in_array( $_FILES['eme_csv']['type'], $csvMimes ) ) {
if ( is_uploaded_file( $_FILES['eme_csv']['tmp_name'] ) ) {
$handle = fopen( $_FILES['eme_csv']['tmp_name'], 'r' );
if ( ! $handle ) {
$message = __( 'Problem accessing the uploaded the file, maybe some security issue?', 'events-made-easy' );
} else {
// BOM as a string for comparison.
$bom = "\xef\xbb\xbf";
// Progress file pointer and get first 3 characters to compare to the BOM string.
if ( fgets( $handle, 4 ) !== $bom ) {
// BOM not found - rewind pointer to start of file.
rewind( $handle );
}
if ( ! eme_is_empty_string( $_POST['enclosure'] ) ) {
$enclosure = eme_sanitize_request( $_POST['enclosure'] );
$enclosure = substr( $enclosure, 0, 1 );
} else {
$enclosure = '"';
}
if ( ! eme_is_empty_string( $_POST['delimiter'] ) ) {
$delimiter = eme_sanitize_request( $_POST['delimiter'] );
} else {
$delimiter = ',';
}
// first line is the column headers
$headers = array_map( 'strtolower', fgetcsv( $handle, 0, $delimiter, $enclosure ) );
// check required columns
if ( ! in_array( 'name', $headers ) || ! in_array( 'type', $headers ) || ! in_array( 'coupon', $headers ) || ! in_array( 'value', $headers ) ) {
$message = __( 'Not all required fields present.', 'events-made-easy' );
} else {
$empty_props = [];
$empty_props = eme_init_discount_props( $empty_props );
while ( ( $row = fgetcsv( $handle, 0, $delimiter, $enclosure ) ) !== false ) {
$line = array_combine( $headers, $row );
// also import properties
foreach ( $line as $key => $value ) {
if ( preg_match( '/^prop_(.*)$/', $key, $matches ) ) {
$prop = $matches[1];
if ( ! isset( $line['properties'] ) ) {
$line['properties'] = [];
}
if ( array_key_exists( $prop, $empty_props ) ) {
$line['properties'][ $prop ] = $value;
}
}
}
// convert dgroup names to id's
if ( ! empty( $line['dgroup'] ) ) {
$dgroups = $line['group'];
$dgroup_arr = explode( ',', $dgroups );
if ( ! eme_is_numeric_array( $dgroup_arr ) ) {
$selected_dgroup_arr = [];
foreach ( $dgroup_arr as $dgroup_name ) {
$dgroup = eme_get_discountgroup_by_name( $dgroup_name );
// take the case where the group no longer exists into account
if ( ! empty( $dgroup ) ) {
$selected_dgroup_arr[] = $dgroup['id'];
}
}
if ( ! empty( $selected_dgroup_arr ) ) {
$line['dgroup'] = join( ',', $selected_dgroup_arr );
}
}
}
$res = eme_db_insert_discount( $line );
if ( $res ) {
++$inserted;
} else {
++$errors;
$error_msg .= '<br>' . eme_esc_html( sprintf( __( 'Not imported: %s', 'events-made-easy' ), implode( ',', $row ) ) );
}
}
$message = sprintf( __( 'Import finished: %d inserts, %d errors', 'events-made-easy' ), $inserted, $errors );
if ( $errors ) {
$message .= '<br>' . $error_msg;
}
}
fclose( $handle );
}
} else {
$message = __( 'Problem detected while uploading the file', 'events-made-easy' );
}
} else {
$message = sprintf( __( 'No CSV file detected: %s', 'events-made-easy' ), $_FILES['eme_csv']['type'] );
}
} elseif ( $_POST['eme_admin_action'] == 'do_importdgroups' && isset( $_FILES['eme_csv'] ) && current_user_can( get_option( 'eme_cap_cleanup' ) ) ) {
$inserted = 0;
$errors = 0;
$error_msg = '';
//validate whether uploaded file is a csv file
if ( ! empty( $_FILES['eme_csv']['name'] ) && in_array( $_FILES['eme_csv']['type'], $csvMimes ) ) {
if ( is_uploaded_file( $_FILES['eme_csv']['tmp_name'] ) ) {
$handle = fopen( $_FILES['eme_csv']['tmp_name'], 'r' );
if ( ! $handle ) {
$message = __( 'Problem accessing the uploaded the file, maybe some security issue?', 'events-made-easy' );
} else {
// BOM as a string for comparison.
$bom = "\xef\xbb\xbf";
// Progress file pointer and get first 3 characters to compare to the BOM string.
if ( fgets( $handle, 4 ) !== $bom ) {
// BOM not found - rewind pointer to start of file.
rewind( $handle );
}
if ( ! eme_is_empty_string( $_POST['enclosure'] ) ) {
$enclosure = eme_sanitize_request( $_POST['enclosure'] );
$enclosure = substr( $enclosure, 0, 1 );
} else {
$enclosure = '"';
}
if ( ! eme_is_empty_string( $_POST['delimiter'] ) ) {
$delimiter = eme_sanitize_request( $_POST['delimiter'] );
} else {
$delimiter = ',';
}
// first line is the column headers
$headers = array_map( 'strtolower', fgetcsv( $handle, 0, $delimiter, $enclosure ) );
// check required columns
if ( ! in_array( 'name', $headers ) ) {
$message = __( 'Not all required fields present.', 'events-made-easy' );
} else {
while ( ( $row = fgetcsv( $handle, 0, $delimiter, $enclosure ) ) !== false ) {
$discountgroup = array_combine( $headers, $row );
$res = eme_db_insert_dgroup( $discountgroup );
if ( $res ) {
++$inserted;
} else {
++$errors;
$error_msg .= '<br>' . eme_esc_html( sprintf( __( 'Not imported: %s', 'events-made-easy' ), implode( ',', $row ) ) );
}
}
$message = sprintf( __( 'Import finished: %d inserts, %d errors', 'events-made-easy' ), $inserted, $errors );
if ( $errors ) {
$message .= '<br>' . $error_msg;
}
}
fclose( $handle );
}
} else {
$message = __( 'Problem detected while uploading the file', 'events-made-easy' );
}
} else {
$message = sprintf( __( 'No CSV file detected: %s', 'events-made-easy' ), $_FILES['eme_csv']['type'] );
}
} elseif ( $_POST['eme_admin_action'] == 'do_editdiscount' ) {
if ( ! empty( $_POST['id'] ) ) {
$discount_id = intval( $_POST['id'] );
$discount = eme_get_discount( $discount_id );
} else {
$discount_id = 0;
$discount = eme_new_discount();
}
foreach ( $discount as $key => $val ) {
if ( isset( $_POST[ $key ] ) ) {
$discount[ $key ] = eme_sanitize_request( $_POST[ $key ] );
}
}
// dgroup is an array, let's convert it
if ( is_array( $discount['dgroup'] ) ) {
$discount['dgroup'] = join( ',', $discount['dgroup'] );
}
// unchecked checkboxes don't get sent in forms
if ( ! isset( $_POST['strcase'] ) ) {
$discount['strcase'] = 0;
}
if ( ! isset( $_POST['use_per_seat'] ) ) {
$discount['use_per_seat'] = 0;
}
if ( ! is_numeric( $discount['type'] ) || $discount['type'] < 0 || $discount['type'] > 4 ) {
$discount['type'] = EME_DISCOUNT_TYPE_FIXED;
}
if ( $discount['type'] == EME_DISCOUNT_TYPE_PCT ) { // for percentage type
if ( $discount['value'] < 0 ) {
$discount['value'] = 0;
}
if ( $discount['value'] > 100 ) {
$discount['value'] = 100;
}
}
if ( ! is_numeric( $discount['strcase'] ) || $discount['strcase'] < 0 || $discount['strcase'] > 1 ) {
$discount['strcase'] = 1;
}
if ( eme_is_empty_datetime( $discount['valid_from'] ) ) {
$discount['valid_from'] = null;
}
if ( eme_is_empty_datetime( $discount['valid_to'] ) ) {
$discount['valid_to'] = null;
}
if ( $discount_id ) {
$validation_result = eme_db_update_discount( $discount_id, $discount );
if ( $validation_result !== false ) {
$message = __( 'Successfully edited the discount', 'events-made-easy' );
if ( get_option( 'eme_stay_on_edit_page' ) ) {
eme_discounts_edit_layout( $discount_id, $message );
return;
}
} else {
$message = __( 'There was a problem editing the discount, please try again.', 'events-made-easy' );
}
} else {
$new_id = eme_db_insert_discount( $discount );
if ( $new_id ) {
$message = __( 'Successfully added the discount', 'events-made-easy' );
if ( get_option( 'eme_stay_on_edit_page' ) ) {
eme_discounts_edit_layout( $new_id, $message );
return;
}
} else {
$message = __( 'There was a problem adding the discount, please try again.', 'events-made-easy' );
}
}
eme_manage_discounts_layout( $message );
return;
} elseif ( $_POST['eme_admin_action'] == 'do_editdgroup' ) {
if ( ! empty( $_POST['id'] ) ) {
$dgroup_id = intval( $_POST['id'] );
$dgroup = eme_get_discountgroup( $dgroup_id );
} else {
$dgroup_id = 0;
$dgroup = eme_new_discountgroup();
}
foreach ( $dgroup as $key => $val ) {
if ( isset( $_POST[ $key ] ) ) {
$dgroup[ $key ] = eme_sanitize_request( $_POST[ $key ] );
}
}
if ( $dgroup_id ) {
$validation_result = eme_db_update_dgroup( $dgroup_id, $dgroup );
if ( $validation_result !== false ) {
$message = __( 'Successfully edited the discount group', 'events-made-easy' );
if ( get_option( 'eme_stay_on_edit_page' ) ) {
eme_dgroups_edit_layout( $dgroup_id, $message );
return;
}
} else {
$message = __( 'There was a problem editing the discount group, please try again.', 'events-made-easy' );
}
} else {
$new_id = eme_db_insert_dgroup( $dgroup );
if ( $new_id ) {
$message = __( 'Successfully added the discount group', 'events-made-easy' );
if ( get_option( 'eme_stay_on_edit_page' ) ) {
eme_dgroups_edit_layout( $new_id, $message );
return;
}
} else {
$message = __( 'There was a problem adding the discount group, please try again.', 'events-made-easy' );
}
}
eme_manage_dgroups_layout( $message );
return;
}
}
// now that we handled possible ations, let's show the wanted screen
if ( isset( $_POST['eme_admin_action'] ) && $_POST['eme_admin_action'] == 'add_discount' ) {
check_admin_referer( 'eme_admin', 'eme_admin_nonce' );
eme_discounts_edit_layout();
return;
}
if ( isset( $_POST['eme_admin_action'] ) && $_POST['eme_admin_action'] == 'add_dgroup' ) {
check_admin_referer( 'eme_admin', 'eme_admin_nonce' );
eme_dgroups_edit_layout();
return;
}
if ( isset( $_GET['eme_admin_action'] ) && $_GET['eme_admin_action'] == 'edit_discount' && ! empty( $_GET['id'] ) ) {
check_admin_referer( 'eme_admin', 'eme_admin_nonce' );
eme_discounts_edit_layout( intval( $_GET['id'] ) );
return;
}
if ( isset( $_GET['eme_admin_action'] ) && $_GET['eme_admin_action'] == 'edit_dgroup' && ! empty( $_GET['id'] ) ) {
check_admin_referer( 'eme_admin', 'eme_admin_nonce' );
eme_dgroups_edit_layout( intval( $_GET['id'] ) );
return;
}
if ( isset( $_GET['eme_admin_action'] ) && $_GET['eme_admin_action'] == 'discounts' ) {
eme_manage_discounts_layout( $message );
return;
}
if ( isset( $_GET['eme_admin_action'] ) && $_GET['eme_admin_action'] == 'dgroups' ) {
eme_manage_dgroups_layout( $message );
return;
}
eme_discounts_main_layout();
}
function eme_discounts_main_layout( $message = '' ) {
$discounts_destination = admin_url( 'admin.php?page=eme-discounts&eme_admin_action=discounts' );
$dgroups_destination = admin_url( 'admin.php?page=eme-discounts&eme_admin_action=dgroups' );
$html = "
<div class='wrap nosubsub'>\n
<div id='icon-edit' class='icon32'>
</div>
<h1>" . __( 'Discount management', 'events-made-easy' ) . '</h1>
';
if ( ! empty( $message ) ) {
$html .= '<div id="discounts-message" class="eme-message-admin"><p>' . $message . '</p></div>';
}
$html .= '<h2>' . __( 'Manage discounts', 'events-made-easy' ) . '</h2>';
$html .= "<a href='$discounts_destination'>" . __( 'Manage discounts', 'events-made-easy' ) . '</a><br>';
$html .= '<h2>' . __( 'Manage discountgroups', 'events-made-easy' ) . '</h2>';
$html .= "<a href='$dgroups_destination'>" . __( 'Manage discountgroups', 'events-made-easy' ) . '</a><br>';
echo $html;
}
function eme_manage_discounts_layout( $message = '' ) {
global $plugin_page;
$dgroups = eme_get_dgroups();
$nonce_field = wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false );
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="discounts-message" class="notice is-dismissible eme-message-admin <?php echo $hidden_class; ?>">
<p><?php echo $message; ?></p>
</div>
<h1><?php esc_html_e( 'Add a new discount definition', 'events-made-easy' ); ?></h1>
<div class="wrap">
<form method="post" action="<?php echo admin_url( "admin.php?page=$plugin_page" ); ?>">
<?php echo $nonce_field; ?>
<input type="hidden" name="eme_admin_action" value="add_discount">
<input type="submit" class="button-primary" name="submit" value="<?php esc_attr_e( 'Add discount', 'events-made-easy' ); ?>">
</form>
</div>
<h1><?php esc_html_e( 'Manage discounts', 'events-made-easy' ); ?></h1>
<?php if ( current_user_can( get_option( 'eme_cap_cleanup' ) ) ) { ?>
<span class="eme_import_form_img">
<?php esc_html_e( 'Click on the icon to show the import form', 'events-made-easy' ); ?>
<img src="<?php echo esc_url(EME_PLUGIN_URL); ?>images/showhide.png" class="showhidebutton" alt="show/hide" data-showhide="div_import" style="cursor: pointer; vertical-align: middle; ">
</span>
<div id='div_import' style='display:none;'>
<form id='discount-import' method='post' enctype='multipart/form-data' action='#'>
<?php echo $nonce_field; ?>
<input type="file" name="eme_csv">
<?php esc_html_e( 'Delimiter:', 'events-made-easy' ); ?>
<input type="text" size=1 maxlength=1 name="delimiter" value=','>
<?php esc_html_e( 'Enclosure:', 'events-made-easy' ); ?>
<input required="required" type="text" size=1 maxlength=1 name="enclosure" value='"'>
<input type="hidden" name="eme_admin_action" value="do_importdiscounts">
<input type="submit" value="<?php esc_html_e( 'Import', 'events-made-easy' ); ?>" name="doaction" id="doaction" class="button-primary action">
<?php esc_html_e( 'If you want, use this to import discounts into the database', 'events-made-easy' ); ?>
</form>
</div>
<br>
<?php } ?>
<br>
<form id='discounts-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="deleteDiscounts"><?php esc_html_e( 'Delete selected discounts', 'events-made-easy' ); ?></option>
<option value="addToGroup"><?php esc_html_e( 'Add to group', 'events-made-easy' ); ?></option>
<option value="removeFromGroup"><?php esc_html_e( 'Remove from group', 'events-made-easy' ); ?></option>
<option value="changeValidFrom"><?php esc_html_e( 'Change "valid from" date', 'events-made-easy' ); ?></option>
<option value="changeValidTo"><?php esc_html_e( 'Change "valid until" date', 'events-made-easy' ); ?></option>
</select>
<span id="span_addtogroup" class="eme-hidden">
<?php echo eme_ui_select_key_value( '', 'addtogroup', $dgroups, 'id', 'name', __( 'Select a group', 'events-made-easy' ), 1 ); ?>
</span>
<span id="span_removefromgroup" class="eme-hidden">
<?php echo eme_ui_select_key_value( '', 'removefromgroup', $dgroups, 'id', 'name', __( 'Select a group', 'events-made-easy' ), 1 ); ?>
</span>
<span id="span_newvalidfrom" class="eme-hidden">
<input id="new_validfrom" type="hidden" name="new_validfrom" value="">
<input id="eme_localized_new_validfrom" type="text" name="eme_localized_new_validfrom" value="" style="background: #FCFFAA;" readonly="readonly" placeholder="<?php esc_html_e( 'Select new "valid from" date/time', 'events-made-easy' ); ?>" size=15 data-date='' data-alt-field='new_validfrom' class='eme_formfield_fdatetime'>
</span>
<span id="span_newvalidto" class="eme-hidden">
<input id="new_validto" type="hidden" name="new_validto" value="">
<input id="eme_localized_new_validto" type="text" name="eme_localized_new_validto" value="" style="background: #FCFFAA;" readonly="readonly" placeholder="<?php esc_html_e( 'Select new "valid until" date/time', 'events-made-easy' ); ?>" size=15 data-date='' data-alt-field='new_validto' class='eme_formfield_fdatetime'>
</span>
<button id="DiscountsActionsButton" class="button-secondary action"><?php esc_html_e( 'Apply', 'events-made-easy' ); ?></button>
<span class="rightclickhint">
<?php esc_html_e( 'Hint: rightclick on the column headers to show/hide columns', 'events-made-easy' ); ?>
</span>
<div id="DiscountsTableContainer"></div>
</form>
</div>
</div>
<?php
}
function eme_manage_dgroups_layout( $message = '' ) {
global $plugin_page;
$nonce_field = wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false );
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="discountgroups-message" class="notice is-dismissible eme-message-admin <?php echo $hidden_class; ?>">
<p><?php echo $message; ?></p>
</div>
<h1><?php esc_html_e( 'Add a new discount group', 'events-made-easy' ); ?></h1>
<div class="wrap">
<form method="post" action="<?php echo admin_url( "admin.php?page=$plugin_page" ); ?>">
<?php echo $nonce_field; ?>
<input type="hidden" name="eme_admin_action" value="add_dgroup">
<input type="submit" class="button-primary" name="submit" value="<?php esc_html_e( 'Add discount group', 'events-made-easy' ); ?>">
</form>
</div>
<h1><?php esc_html_e( 'Manage discount groups', 'events-made-easy' ); ?></h1>
<?php if ( current_user_can( get_option( 'eme_cap_cleanup' ) ) ) { ?>
<span class="eme_import_form_img">
<?php esc_html_e( 'Click on the icon to show the import form', 'events-made-easy' ); ?>
<img src="<?php echo esc_url(EME_PLUGIN_URL); ?>images/showhide.png" class="showhidebutton" alt="show/hide" data-showhide="div_import" style="cursor: pointer; vertical-align: middle; ">
</span>
<div id='div_import' style='display:none;'>
<form id='discountgroups-import' method='post' enctype='multipart/form-data' action='#'>
<?php echo $nonce_field; ?>
<input type="file" name="eme_csv">
<?php esc_html_e( 'Delimiter:', 'events-made-easy' ); ?>
<input type="text" size=1 maxlength=1 name="delimiter" value=','>
<?php esc_html_e( 'Enclosure:', 'events-made-easy' ); ?>
<input required="required" type="text" size=1 maxlength=1 name="enclosure" value='"'>
<input type="hidden" name="eme_admin_action" value="do_importdgroups">
<input type="submit" value="<?php esc_html_e( 'Import', 'events-made-easy' ); ?>" name="doaction" id="doaction" class="button-primary action">
<?php esc_html_e( 'If you want, use this to import discountgroups into the database', 'events-made-easy' ); ?>
</form>
</div>
<br>
<?php } ?>
<br>
<form id='discountgroups-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="deleteDiscountGroups"><?php esc_html_e( 'Delete selected discountgroups', 'events-made-easy' ); ?></option>
</select>
<button id="DiscountGroupsActionsButton" class="button-secondary action"><?php esc_html_e( 'Apply', 'events-made-easy' ); ?></button>
<span class="rightclickhint">
<?php esc_html_e( 'Hint: rightclick on the column headers to show/hide columns', 'events-made-easy' ); ?>
</span>
<div id="DiscountGroupsTableContainer"></div>
</form>
</div>
</div>
<?php
}
function eme_booking_discount( $event, $booking ) {
$discountgroup_id = $booking['dgroupid'];
$total_discount = 0;
// make sure to not store an empty discount name:
// explode on an empty string creates a empty first array element
if ( ! empty( $booking['discountids'] ) ) {
$applied_discountids = explode( ',', $booking['discountids'] );
} else {
$applied_discountids = [];
}
if ( eme_is_admin_request() ) {
if ( isset( $_POST['DISCOUNT'] ) ) {
$total_discount = sprintf( '%01.2f', $_POST['DISCOUNT'] );
// if there's an amount entered and it is different than what was calculated before, we clear the discount id references
if ( $total_discount != $booking['discount'] ) {
$applied_discountids = [];
$discountgroup_id = 0;
$booking['dcodes_used'] = [];
}
}
} elseif ( ! empty( $event['event_properties']['rsvp_discountgroup'] ) ) {
if ( is_numeric( $event['event_properties']['rsvp_discountgroup'] ) ) {
$discount_group = eme_get_discountgroup( $event['event_properties']['rsvp_discountgroup'] );
} else {
$discount_group = eme_get_discountgroup_by_name( $event['event_properties']['rsvp_discountgroup'] );
}
$discountgroup_id = $discount_group['id'];
if ( ! $discountgroup_id ) {
return false;
}
$discount_ids = eme_get_discountids_by_group( $discount_group );
$group_count = 0;
$max_discounts = $discount_group['maxdiscounts'];
$booking['dcodes_used'] = [];
foreach ( $discount_ids as $id ) {
// a discount can only be applied once
if ( in_array( $id, $applied_discountids ) ) {
continue;
}
if ( $max_discounts == 0 || $group_count < $max_discounts ) {
$discount = eme_get_discount( $id );
$calc_result = eme_calc_booking_discount( $discount, $booking );
if ( $calc_result === false || empty( $calc_result[0] ) ) {
$amount = 0;
} else {
$amount = $calc_result[0];
}
if ( $amount ) {
++$group_count;
$total_discount += $amount;
$applied_discountids[] = $id;
// we assign the dcodes_used back to $booking, so the next run of this foreach loop has this knowlede in eme_calc_booking_discount()
if ( ! empty( $calc_result[1] ) ) {
$booking['dcodes_used'] = $calc_result[1];
}
}
}
}
} elseif ( ! empty( $event['event_properties']['rsvp_discount'] ) ) {
if ( is_numeric( $event['event_properties']['rsvp_discount'] ) ) {
$discount = eme_get_discount( $event['event_properties']['rsvp_discount'] );
} else {
$discount = eme_get_discount_by_name( $event['event_properties']['rsvp_discount'] );
}
$calc_result = eme_calc_booking_discount( $discount, $booking );
if ( $calc_result === false || empty( $calc_result[0] ) ) {
$amount = 0;
} else {
$amount = $calc_result[0];
}
if ( $amount ) {
$total_discount = $amount;
$applied_discountids[] = $discount['id'];
if ( ! empty( $calc_result[1] ) ) {
$booking['dcodes_used'] = $calc_result[1];
} else {
$booking['dcodes_used'] = [];
}
}
}
$discountids = join( ',', array_unique( $applied_discountids ) );
return [
'discount' => $total_discount,
'discountids' => $discountids,
'dgroupid' => $discountgroup_id,
'dcodes_used' => $booking['dcodes_used'],
];
}
function eme_member_discount( $membership, $member ) {
$discountgroup_id = $member['dgroupid'];
$total_discount = 0;
// make sure to not store an empty discount name:
// explode on an empty string creates a empty first array element
if ( ! empty( $member['discountids'] ) ) {
$applied_discountids = explode( ',', $member['discountids'] );
} else {
$applied_discountids = [];
}
if ( eme_is_admin_request() ) {
if ( isset( $_POST['DISCOUNT'] ) ) {
$total_discount = sprintf( '%01.2f', $_POST['DISCOUNT'] );
// if there's an amount entered and it is different than what was calculated before, we clear the discount id references
if ( $total_discount != $member['discount'] ) {
$applied_discountids = [];
$discountgroup_id = 0;
$member['dcodes_used'] = [];
}
}
} elseif ( ! empty( $membership['properties']['discountgroup'] ) ) {
if ( is_numeric( $membership['properties']['discountgroup'] ) ) {
$discount_group = eme_get_discountgroup( $membership['properties']['discountgroup'] );
} else {
$discount_group = eme_get_discountgroup_by_name( $membership['properties']['discountgroup'] );
}
$discountgroup_id = $discount_group['id'];
if ( ! $discountgroup_id ) {
return false;
}
$discount_ids = eme_get_discountids_by_group( $discount_group );
$group_count = 0;
$max_discounts = $discount_group['maxdiscounts'];
$member['dcodes_used'] = [];
foreach ( $discount_ids as $id ) {
// a discount can only be applied once
if ( in_array( $id, $applied_discountids ) ) {
continue;
}
if ( $max_discounts == 0 || $group_count < $max_discounts ) {
$discount = eme_get_discount( $id );
$calc_result = eme_calc_member_discount( $discount, $member );
if ( $calc_result === false || empty( $calc_result[0] ) ) {
$amount = 0;
} else {
$amount = $calc_result[0];
}
if ( $amount ) {
++$group_count;
$total_discount += $amount;
$applied_discountids[] = $id;
// we assign the dcodes_used back to $member, so the next run of this foreach loop has this knowlede in eme_calc_member_discount()
if ( ! empty( $calc_result[1] ) ) {
$member['dcodes_used'] = $calc_result[1];
}
}
}
}
} elseif ( ! empty( $membership['properties']['discount'] ) ) {
if ( is_numeric( $membership['properties']['discount'] ) ) {
$discount = eme_get_discount( $membership['properties']['discount'] );
} else {
$discount = eme_get_discount_by_name( $membership['properties']['discount'] );
}
$calc_result = eme_calc_member_discount( $discount, $member );
if ( $calc_result === false || empty( $calc_result[0] ) ) {
$amount = 0;
} else {
$amount = $calc_result[0];
}
if ( $amount ) {
$total_discount = $amount;
$applied_discountids[] = $discount['id'];
if ( ! empty( $calc_result[1] ) ) {
$member['dcodes_used'] = $calc_result[1];
} else {
$member['dcodes_used'] = [];
}
}
}
$discountids = join( ',', array_unique( $applied_discountids ) );
return [
'discount' => $total_discount,
'discountids' => $discountids,
'dgroupid' => $discountgroup_id,
'dcodes_used' => $member['dcodes_used'],
];
}
function eme_update_booking_discount( $booking ) {
global $wpdb;
$event = eme_get_event( $booking['event_id'] );
if ( empty( $event ) ) {
return;
}
$calc_discount = eme_booking_discount( $event, $booking );
$bookings_table = EME_DB_PREFIX . EME_BOOKINGS_TBNAME;
$where = [];
$fields = [];
$where['booking_id'] = $booking['booking_id'];
$fields['discount'] = $calc_discount['discount'];
$fields['discountids'] = $calc_discount['discountids'];
$fields['dcodes_used'] = eme_serialize( $calc_discount['dcodes_used'] );
$fields['dgroupid'] = $calc_discount['dgroupid'];
if ( $calc_discount['discount'] != $booking['discount'] ) {
// if the discount is not equal to the original, the $calc_discount['discountids'] value will be empty
// so we also decrease the usage count of the discount ids
$discount_ids = explode( ',', $booking['discountids'] );
foreach ( $discount_ids as $discount_id ) {
eme_decrease_discount_booking_count( $discount_id, $booking );
}
}
$wpdb->update( $bookings_table, $fields, $where );
}
function eme_update_member_discount( $member ) {
global $wpdb;
$membership = eme_get_membership( $member['membership_id'] );
$calc_discount = eme_member_discount( $membership, $member );
$members_table = EME_DB_PREFIX . EME_MEMBERS_TBNAME;
$where = [];
$fields = [];
$where['member_id'] = $member['member_id'];
$fields['discount'] = $calc_discount['discount'];
$fields['discountids'] = $calc_discount['discountids'];
$fields['dcodes_used'] = eme_serialize( $calc_discount['dcodes_used'] );
$fields['dgroupid'] = $calc_discount['dgroupid'];
if ( $calc_discount != $member['discount'] ) {
// if the discount is not equal to the original, the $calc_discount['discountids'] value will be empty
// so we also decrease the usage count of the discount ids
$discount_ids = explode( ',', $member['discountids'] );
foreach ( $discount_ids as $discount_id ) {
eme_decrease_discount_member_count( $discount_id, $member );
}
}
$wpdb->update( $members_table, $fields, $where );
}
function eme_discounts_edit_layout( $discount_id = 0, $message = '' ) {
global $plugin_page;
$selected_dgroup_arr = [];
if ( $discount_id ) {
$discount = eme_get_discount( $discount_id );
$selected_dgroup = $discount['dgroup'];
if ( ! empty( $selected_dgroup ) ) {
// let's see if the dgroup is an array of integers, if not: we take it as a name and convert it to 1 id
$selected_dgroup_arr = explode( ',', $selected_dgroup );
if ( ! eme_is_numeric_array( $selected_dgroup_arr ) ) {
$dgroup = eme_get_discountgroup_by_name( $selected_dgroup );
// take the case where the group no longer exists into account
if ( ! empty( $dgroup ) ) {
$selected_dgroup_arr = [ $dgroup['id'] ];
} else {
$selected_dgroup_arr = [];
}
}
}
$h1_string = __( 'Edit discount', 'events-made-easy' );
$action_string = __( 'Update discount', 'events-made-easy' );
} else {
$discount = eme_new_discount();
$h1_string = __( 'Create discount', 'events-made-easy' );
$action_string = __( 'Add discount', 'events-made-easy' );
}
$nonce_field = wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false );
$discount_types = eme_get_discounttypes();
$dgroups = eme_get_dgroups();
$groups = eme_get_static_groups();
$memberships = eme_get_memberships();
?>
<div class='wrap'>
<div id='icon-edit' class='icon32'>
</div>
<h1><?php echo $h1_string; ?></h1>
<?php if ( $message != '' ) { ?>
<div id='message' class='updated notice notice-success is-dismissible'>
<p><?php echo $message; ?></p>
</div>
<?php } ?>
<div id='ajax-response'></div>
<form name='edit_discounts' id='edit_discounts' method='post' action='<?php echo admin_url( "admin.php?page=$plugin_page" ); ?>'>
<input type='hidden' name='eme_admin_action' value='do_editdiscount'>
<input type='hidden' name='id' value='<?php echo $discount_id; ?>'>
<?php echo $nonce_field; ?>
<table class='form-table'>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='name'><?php esc_html_e( 'Discount name', 'events-made-easy' ); ?></label></th>
<td><input name='name' id='name' required='required' type='text' value='<?php echo eme_esc_html( $discount['name'] ); ?>' size='40'><br>
<?php esc_html_e( 'The name of the discount', 'events-made-easy' ); ?></td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='description'><?php esc_html_e( 'Description', 'events-made-easy' ); ?></label></th>
<td><textarea name='description' id='description' rows='5' ><?php echo eme_esc_html( $discount['description'] ); ?></textarea></td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='type'><?php esc_html_e( 'Type', 'events-made-easy' ); ?></label></th>
<td><?php echo eme_ui_select( $discount['type'], 'type', $discount_types ); ?>
<br><?php esc_html_e( 'For type "Code" you have to create your own discount filters, please read the documention for this', 'events-made-easy' ); ?>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='value'><?php esc_html_e( 'Discount value', 'events-made-easy' ); ?></label></th>
<td><input name='value' id='value' type='text' value='<?php echo eme_esc_html( $discount['value'] ); ?>' size='40'>
<br><?php esc_html_e( 'The applied discount value if the correct coupon code is entered (this does not apply to discounts of type "Code")', 'events-made-easy' ); ?>
<br><?php esc_html_e( 'For type "Percentage" the value should be >=0 and <=100', 'events-made-easy' ); ?>
</td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='coupon'><?php esc_html_e( 'Coupon code', 'events-made-easy' ); ?></label></th>
<td><input name='coupon' id='coupon' type='text' value='<?php echo eme_esc_html( $discount['coupon'] ); ?>' size='40'>
<br><?php esc_html_e( 'The coupon code to enter for the discount to apply (this does not apply to discounts of type "Code")', 'events-made-easy' ); ?>
<br><?php esc_html_e( 'If you leave the coupon code empty but set a discount expiration date, you can use this as an "early bird" discount', 'events-made-easy' ); ?>
</td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='value'><?php esc_html_e( 'Discount groups', 'events-made-easy' ); ?></label></th>
<td><?php echo eme_ui_multiselect_key_value( $selected_dgroup_arr, 'dgroup', $dgroups, 'id', 'name', 5, '', 0, 'eme_select2_width50_class' ); ?>
<br><?php esc_html_e( 'If wanted, you can make this discount a part of one or more discount groups, and then apply a discount group to your event', 'events-made-easy' ); ?>
</td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='dp_valid_from'><?php esc_html_e( 'Valid from', 'events-made-easy' ); ?></label></th>
<td><input type='hidden' readonly='readonly' name='valid_from' id='valid_from'>
<input type='text' readonly='readonly' name='dp_valid_from' id='dp_valid_from' data-date='<?php if ( $discount['valid_from'] ) { echo eme_js_datetime( $discount['valid_from'] );} ?>' data-alt-field='#valid_from' class='eme_formfield_fdatetime'>
<br><?php esc_html_e( 'An optional coupon start date and time, if entered the coupon is not valid before this date and time.', 'events-made-easy' ); ?>
</td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='dp_valid_to'><?php esc_html_e( 'Valid until', 'events-made-easy' ); ?></label></th>
<td><input type='hidden' readonly='readonly' name='valid_to' id='valid_to'>
<input type='text' readonly='readonly' name='dp_valid_to' id='dp_valid_to' data-date='<?php if ( $discount['valid_to'] ) { echo eme_js_datetime( $discount['valid_to'] );} ?>' data-alt-field='#valid_to' class='eme_formfield_fdatetime'>
<br><?php esc_html_e( 'An optional coupon expiration date and time, if entered the coupon is not valid after this date and time.', 'events-made-easy' ); ?>
</td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='properties[invite_only]'><?php esc_html_e( 'Invited people only', 'events-made-easy' ); ?></label></th>
<td><?php echo eme_ui_select_binary( $discount['properties']['invite_only'], 'properties[invite_only]' ); ?>
<br><p class='eme_smaller'><?php esc_html_e( 'People need to be invited and click on the invitation URL for this discount to apply.', 'events-made-easy' ); ?></p>
</td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='properties[wp_users_only]'><?php esc_html_e( 'Logged-in users only', 'events-made-easy' ); ?></label></th>
<td><?php echo eme_ui_select_binary( $discount['properties']['wp_users_only'], 'properties[wp_users_only]' ); ?>
<br><p class='eme_smaller'><?php esc_html_e( 'Require users to be logged-in for this discount to apply.', 'events-made-easy' ); ?></p>
</td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='properties[group_ids]'><?php esc_html_e( 'Require EME groups', 'events-made-easy' ); ?></label></th>
<td><?php echo eme_ui_multiselect_key_value( $discount['properties']['group_ids'], 'properties[group_ids]', $groups, 'group_id', 'name', 5, '', 0, 'eme_select2_width50_class' ); ?>
<br><p class='eme_smaller'><?php esc_html_e( 'Require logged-in user to be in of one of the selected EME groups for this discount to apply.', 'events-made-easy' ); ?></p>
</td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='properties[membership_ids]'><?php esc_html_e( 'Require EME membership', 'events-made-easy' ); ?></label></th>
<td>
<?php
if ( ! empty( $memberships ) ) {
echo eme_ui_multiselect_key_value( $discount['properties']['membership_ids'], 'properties[membership_ids]', $memberships, 'membership_id', 'name', 5, '', 0, 'eme_select2_memberships_class' );
} else {
esc_html_e( 'No memberships defined yet!', 'events-made-easy' );
}
?>
<br><p class='eme_smaller'><?php esc_html_e( 'Require logged-in user to be a member of one of the selected EME memberships for this discount to apply.', 'events-made-easy' ); ?></p>
</td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='properties[wp_role]'><?php esc_html_e( 'WP role required', 'events-made-easy' ); ?></label></th>
<td><select id='wp_role' name='properties[wp_role]'><option value=''> </option><?php wp_dropdown_roles( $discount['properties']['wp_role'] ); ?> </select>
<br><p class='eme_smaller'><?php esc_html_e( 'Require users to have the selected WP role for the discount to apply.', 'events-made-easy' ); ?></p>
</td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='strcase'><?php esc_html_e( 'Case sensitive?', 'events-made-easy' ); ?></label></th>
<td><?php echo eme_ui_select_binary( $discount['strcase'], 'strcase' ); ?></td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='maxcount'><?php esc_html_e( 'Maximum usage count', 'events-made-easy' ); ?></label></th>
<td><input name='maxcount' id='maxcount' type='text' value='<?php echo eme_esc_html( $discount['maxcount'] ); ?>' size='40'>
<br><?php esc_html_e( 'The maximum number of times this discount can be applied', 'events-made-easy' ); ?>
</td>
</tr>
<?php if ( $discount_id ) { ?>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='count'><?php esc_html_e( 'Current usage count', 'events-made-easy' ); ?></label></th>
<td><input name='count' id='count' type='text' value='<?php echo eme_esc_html( $discount['count'] ); ?>' size='40'>
<br><?php esc_html_e( 'The current number of times this discount has been applied', 'events-made-easy' ); ?>
</td>
</tr>
<?php } ?>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='use_per_seat'><?php esc_html_e( 'Count usage per seat?', 'events-made-easy' ); ?></label></th>
<td><?php echo eme_ui_select_binary( $discount['use_per_seat'], 'use_per_seat' ); ?>
<br><?php esc_html_e( 'By default the coupon usage count is counted per form submit. If you want, you can augment the usage count by the number of seats booked instead.', 'events-made-easy' ); ?>
</td>
</tr>
</table>
<p class='submit'><input type='submit' class='button-primary' name='submit' value='<?php echo $action_string; ?>'></p>
</form>
</div>
<?php
}
function eme_dgroups_edit_layout( $dgroup_id = 0, $message = '' ) {
global $plugin_page;
if ( $dgroup_id ) {
$dgroup = eme_get_discountgroup( $dgroup_id );
$h1_string = __( 'Edit discount group', 'events-made-easy' );
$action_string = __( 'Update discount group', 'events-made-easy' );
} else {
$dgroup = eme_new_discountgroup();
$h1_string = __( 'Create discount group', 'events-made-easy' );
$action_string = __( 'Add discount group', 'events-made-easy' );
}
$nonce_field = wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false );
?>
<div class='wrap'>
<div id='icon-edit' class='icon32'>
</div>
<h1><?php echo $h1_string; ?></h1>
<?php if ( $message != '' ) { ?>
<div id='message' class='updated notice notice-success is-dismissible'>
<p><?php echo $message; ?></p>
</div>
<?php } ?>
<div id='ajax-response'></div>
<form name='edit_dgroups' id='edit_dgroups' method='post' action='<?php echo admin_url( "admin.php?page=$plugin_page" ); ?>'>
<input type='hidden' name='eme_admin_action' value='do_editdgroup'>
<input type='hidden' name='id' value='<?php echo $dgroup_id; ?>'>
<?php echo $nonce_field; ?>
<table class='form-table'>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='name'><?php esc_html_e( 'Discountgroup name', 'events-made-easy' ); ?></label></th>
<td><input name='name' id='name' required='required' type='text' value='<?php echo eme_esc_html( $dgroup['name'] ); ?>' size='40'><br>
<?php esc_html_e( 'The name of the discount group', 'events-made-easy' ); ?></td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='description'><?php esc_html_e( 'Description', 'events-made-easy' ); ?></label></th>
<td><textarea name='description' id='description' rows='5' ><?php echo eme_esc_html( $dgroup['description'] ); ?></textarea></td>
</tr>
<tr class='form-field'>
<th scope='row' style='vertical-align:top'><label for='maxdiscounts'><?php esc_html_e( 'Max amount of discounts applied', 'events-made-easy' ); ?></label></th>
<td><input name='maxdiscounts' id='maxdiscounts' type='text' value='<?php echo eme_esc_html( $dgroup['maxdiscounts'] ); ?>' size='40'>
<br><?php esc_html_e( 'A discount group exists of several discounts, and you can ask for several discount codes by using #_DISCOUNT repeatedly. This parameter then puts a limit of the number of valid discounts that can be applied. So even if you e.g. enter 5 valid coupon codes, you can limit the usage to only 3 or so.', 'events-made-easy' ); ?>
</td>
</tr>
</table>
<p class='submit'><input type='submit' class='button-primary' name='submit' value='<?php echo $action_string; ?>'></p>
</form>