-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
eme-tasks.php
2066 lines (1931 loc) · 85.5 KB
/
eme-tasks.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_task() {
$task = [
'event_id' => 0,
'task_start' => '',
'task_end' => '',
'name' => '',
'description' => '',
'task_seq' => 1,
'task_nbr' => 0,
'spaces' => 1,
];
return $task;
}
function eme_handle_tasks_post_adminform( $event_id, $day_difference = 0 ) {
$eme_tasks_arr = [];
if ( empty( $_POST['eme_tasks'] ) ) {
return $eme_tasks_arr;
}
$seq_nbr = 1;
$task_nbr_seen = 0;
foreach ( $_POST['eme_tasks'] as $eme_task ) {
if ( ! empty( $eme_task['task_nbr'] ) && intval( $eme_task['task_nbr'] ) > $task_nbr_seen ) {
$task_nbr_seen = intval( $eme_task['task_nbr'] );
}
}
$next_task_nbr = $task_nbr_seen + 1;
foreach ( $_POST['eme_tasks'] as $eme_task ) {
$eme_task['name'] = eme_sanitize_request( $eme_task['name'] );
$eme_task['task_seq'] = $seq_nbr;
$eme_task['event_id'] = $event_id;
$eme_task['task_start'] = eme_sanitize_request( $eme_task['task_start'] );
$eme_task['task_end'] = eme_sanitize_request( $eme_task['task_end'] );
if ( eme_is_empty_string( $eme_task['name'] ) || eme_is_empty_datetime( $eme_task['task_start'] ) || eme_is_empty_datetime( $eme_task['task_end'] ) ) {
continue;
}
if ( $day_difference != 0 ) {
$eme_date_obj_start = new ExpressiveDate( $eme_task['task_start'], EME_TIMEZONE );
$eme_date_obj_end = new ExpressiveDate( $eme_task['task_end'], EME_TIMEZONE );
$eme_task['task_start'] = $eme_date_obj_start->addDays( $day_difference )->getDateTime();
$eme_task['task_end'] = $eme_date_obj_end->addDays( $day_difference )->getDateTime();
}
$eme_task['description'] = eme_sanitize_textarea( $eme_task['description'] );
// we check for task nbr to know if we need an update or insert
if ( empty( $eme_task['task_nbr'] ) ) {
$eme_task['task_nbr'] = $next_task_nbr;
++$next_task_nbr;
$task_id = eme_db_insert_task( $eme_task );
} else {
// we update by the combo event_id and task_nbr and not by task_id
// that way we can do task updates for recurrences too
$task_id = eme_db_update_task_by_task_nbr( $eme_task );
}
$eme_tasks_arr[] = $task_id;
++$seq_nbr;
}
return $eme_tasks_arr;
}
function eme_db_insert_task( $line ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASKS_TBNAME;
// first check for task_nbr
if (!isset($line['task_nbr'])) {
$sql = $wpdb->prepare( "SELECT IFNULL(max(task_nbr),0) FROM $table WHERE event_id = %d", $line['event_id'] );
$task_nbr = intval($wpdb->get_var( $sql ));
$line['task_nbr'] = $task_nbr + 1;
}
$tmp_task = eme_new_task();
// we only want the columns that interest us
$keys = array_intersect_key( $line, $tmp_task );
$task = array_merge( $tmp_task, $keys );
if ( $wpdb->insert( $table, $task ) === false ) {
return false;
} else {
$task_id = $wpdb->insert_id;
return $task_id;
}
}
function eme_db_update_task_by_task_nbr( $line ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASKS_TBNAME;
// get the task id
$sql = $wpdb->prepare( "SELECT task_id FROM $table WHERE event_id = %d AND task_nbr = %d", $line['event_id'], $line['task_nbr'] );
$task_id = $wpdb->get_var( $sql );
if ( empty( $task_id ) ) {
// this happens for recurrences where e.g. a new day is added to the recurrence
return eme_db_insert_task( $line );
} else {
$line['task_id'] = $task_id;
eme_db_update_task( $line );
return $task_id;
}
}
function eme_db_update_task( $line ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASKS_TBNAME;
$where = [];
$where['task_id'] = $line['task_id'];
$tmp_task = eme_new_task();
// we only want the columns that interest us
$keys = array_intersect_key( $line, $tmp_task );
$task = array_merge( $tmp_task, $keys );
if ( $wpdb->update( $table, $task, $where ) === false ) {
return false;
} else {
return true;
}
}
function eme_db_delete_task( $task_id ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASKS_TBNAME;
$wpdb->delete( $table, [ 'task_id' => $task_id ] );
}
function eme_delete_event_tasks( $event_id ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASKS_TBNAME;
$sql = $wpdb->prepare( "DELETE FROM $table WHERE event_id=%d", $event_id );
$wpdb->query( $sql );
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
$sql = $wpdb->prepare( "DELETE FROM $table WHERE event_id=%d", $event_id );
$wpdb->query( $sql );
}
function eme_delete_event_old_tasks( $event_id, $ids_arr ) {
global $wpdb;
if ( empty( $ids_arr ) || ! eme_is_numeric_array( $ids_arr ) ) {
return;
}
$ids_list = implode(',', $ids_arr);
$table = EME_DB_PREFIX . EME_TASKS_TBNAME;
$sql = $wpdb->prepare( "DELETE FROM $table WHERE event_id=%d AND task_id NOT IN ( $ids_list )", $event_id);
$wpdb->query( $sql);
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
$sql = $wpdb->prepare( "DELETE FROM $table WHERE event_id=%d AND task_id NOT IN ( $ids_list )", $event_id);
$wpdb->query( $sql);
}
function eme_cancel_task_signup( $signup_randomid ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
if (empty($signup_randomid)) {
return;
}
$sql = $wpdb->prepare( "DELETE FROM $table WHERE random_id=%s", $signup_randomid );
return $wpdb->query( $sql );
}
function eme_db_insert_task_signup( $line ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
$line['random_id'] = eme_random_id();
$line['signup_date'] = current_time( 'mysql', false );
if ( $wpdb->insert( $table, $line ) === false ) {
return false;
} else {
$signup_id = $wpdb->insert_id;
return $signup_id;
}
}
function eme_db_update_task_signup( $line ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
$where = [];
$where['id'] = $line['id'];
if ( $wpdb->update( $table, $line, $where ) === false ) {
$res = false;
} else {
$res = true;
}
return $res;
}
function eme_approve_task_signup( $signup_id ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
$fields = [];
$fields['signup_status'] = 1;
$where = [];
$where['id'] = $signup_id;
if ( $wpdb->update( $table, $fields, $where ) === false ) {
$res = false;
} else {
$res = true;
}
return $res;
}
function eme_transfer_person_task_signups( $person_ids, $to_person_id ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
if ( eme_is_list_of_int( $person_ids ) ) {
$sql = $wpdb->prepare( "UPDATE $table SET person_id = %d WHERE person_id IN ( $person_ids )", $to_person_id);
return $wpdb->query( $sql );
}
}
function eme_db_delete_task_signup( $signup_id ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
if ( $wpdb->delete( $table, [ 'id' => $signup_id ] ) === false ) {
$res = false;
} else {
$res = true;
}
return $res;
}
function eme_get_task( $task_id ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASKS_TBNAME;
$sql = $wpdb->prepare( "SELECT * FROM $table WHERE task_id=%d", $task_id );
return $wpdb->get_row( $sql, ARRAY_A );
}
function eme_get_event_tasks( $event_id ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASKS_TBNAME;
$sql = $wpdb->prepare( "SELECT * FROM $table WHERE event_id=%d ORDER BY task_seq ASC", $event_id );
return $wpdb->get_results( $sql, ARRAY_A );
}
function eme_get_task_signup( $id ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
$sql = $wpdb->prepare( "SELECT * FROM $table WHERE id=%d", $id );
return $wpdb->get_row( $sql, ARRAY_A );
}
function eme_count_task_signups( $task_id ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
$sql = $wpdb->prepare( "SELECT COUNT(*) FROM $table WHERE task_id=%d", $task_id );
return $wpdb->get_var( $sql );
}
function eme_count_task_approved_signups( $task_id ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
$sql = $wpdb->prepare( "SELECT COUNT(*) FROM $table WHERE task_id=%d AND signup_status=1", $task_id );
return $wpdb->get_var( $sql );
}
function eme_count_task_pending_signups( $task_id ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
$sql = $wpdb->prepare( "SELECT COUNT(*) FROM $table WHERE task_id=%d AND signup_status=0", $task_id );
return $wpdb->get_var( $sql );
}
function eme_get_task_signups( $task_id ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
$sql = $wpdb->prepare( "SELECT * FROM $table WHERE task_id=%d ", $task_id );
return $wpdb->get_results( $sql, ARRAY_A );
}
function eme_get_task_signups_by( $wp_id, $task_id = 0, $event_id = 0, $scope = 'future' ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
$people_table = EME_DB_PREFIX . EME_PEOPLE_TBNAME;
$events_table = EME_DB_PREFIX . EME_EVENTS_TBNAME;
$events_join = "LEFT JOIN $events_table ON $table.event_id=$events_table.event_id";
$order_arr = [];
if ( empty( $event_id ) ) {
$order_arr[] = "$events_table.event_start ASC, $events_table.event_name ASC";
}
if ( empty( $task_id ) ) {
$order_arr[] = "$table.task_start ASC, $table.task_end ASC, $table.task_seq ASC";
}
if ( ! empty( $order_arr ) ) {
$order_by = 'ORDER BY ' . join( ', ', $order_arr );
} else {
$order_by = '';
}
$wp_id = intval( $wp_id );
$where_arr = [ "$people_table.wp_id=$wp_id" ];
if ( empty( $event_id ) ) {
if ( $scope == 'future' ) {
$eme_date_obj_now = new ExpressiveDate( 'now', EME_TIMEZONE );
$search_end_date = $eme_date_obj_now->getDateTime();
$where_arr[] = "$events_table.event_end >= '$search_end_date'";
} elseif ( $scope == 'past' ) {
$eme_date_obj_now = new ExpressiveDate( 'now', EME_TIMEZONE );
$search_end_date = $eme_date_obj_now->getDateTime();
$where_arr[] = "$events_table.event_end <= '$search_end_date'";
}
} else {
$where_arr[] = "$table.event_id = " . intval( $event_id );
}
if ( ! empty( $task_id ) ) {
$where_arr[] = "$table.task_id = " . intval( $task_id );
}
$where = 'WHERE ' . implode( ' AND ', $where_arr );
$sql = "SELECT $table.* FROM $table LEFT JOIN $people_table ON $table.person_id=$people_table.person_id $events_join $where $order_by";
return $wpdb->get_results( $sql, ARRAY_A );
}
function eme_get_tasksignup_personids( $signup_ids ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
if ( eme_is_list_of_int( $signup_ids ) ) {
return $wpdb->get_col ( "SELECT DISTINCT person_id FROM $table WHERE id IN ( $signup_ids )" );
}
}
function eme_count_event_task_signups( $event_id ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
$sql = $wpdb->prepare( "SELECT task_id, COUNT(*) as signup_count FROM $table WHERE event_id=%d GROUP BY task_id", $event_id );
$res = $wpdb->get_results( $sql, ARRAY_A );
$return_arr = [];
foreach ( $res as $row ) {
$return_arr[ $row['task_id'] ] = $row['signup_count'];
}
return $return_arr;
}
function eme_count_event_task_person_signups( $event_id, $person_id ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
$sql = $wpdb->prepare( "SELECT COUNT(*) FROM $table WHERE event_id=%d AND person_id=%d", $event_id, $person_id );
return $wpdb->get_var( $sql );
}
function eme_count_person_task_signups( $task_id, $person_id ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
$sql = $wpdb->prepare( "SELECT COUNT(*) FROM $table WHERE task_id=%d AND person_id=%d", $task_id, $person_id );
return $wpdb->get_var( $sql );
}
function eme_check_task_signup_overlap( $task, $person_id ) {
global $wpdb;
$tasks_table = EME_DB_PREFIX . EME_TASKS_TBNAME;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
$sql = $wpdb->prepare( "SELECT COUNT(*) FROM $table LEFT JOIN $tasks_table ON $table.task_id=$tasks_table.task_id WHERE $table.task_id<>%d AND person_id=%d AND task_start<%s AND task_end>%s", $task['task_id'], $person_id, $task['task_end'], $task['task_start'] );
return $wpdb->get_var( $sql );
}
// for CRON
function eme_tasks_send_signup_reminders() {
$eme_date_obj_now = new ExpressiveDate( 'now', EME_TIMEZONE );
// this gets us future and ongoing events with tasks enabled
$events = eme_get_events( extra_conditions: 'event_tasks=1' );
foreach ( $events as $event ) {
if ( eme_is_empty_string( $event['event_properties']['task_reminder_days'] ) ) {
continue;
}
$task_reminder_days = explode( ',', $event['event_properties']['task_reminder_days'] );
if ( ! eme_is_numeric_array( $task_reminder_days ) ) {
continue;
}
$tasks = eme_get_event_tasks( $event['event_id'] );
foreach ( $tasks as $task ) {
$eme_date_obj = new ExpressiveDate( $task['task_start'], EME_TIMEZONE );
$days_diff = intval( $eme_date_obj_now->startOfDay()->getDifferenceInDays( $eme_date_obj->startOfDay() ) );
foreach ( $task_reminder_days as $reminder_day ) {
$reminder_day = intval( $reminder_day );
if ( $days_diff == $reminder_day ) {
$signups = eme_get_task_signups( $task['task_id'] );
foreach ( $signups as $signup ) {
eme_email_tasksignup_action( $signup, 'reminder' );
}
}
}
}
}
}
// for GDPR CRON
function eme_tasks_remove_old_signups() {
global $wpdb;
$table = EME_DB_PREFIX . EME_TASK_SIGNUPS_TBNAME;
$events_table = EME_DB_PREFIX . EME_EVENTS_TBNAME;
$remove_old_signups_days = get_option( 'eme_gdpr_remove_old_signups_days' );
if ( empty( $remove_old_signups_days ) ) {
return;
} else {
$remove_old_signups_days = abs( intval($remove_old_signups_days) );
}
$eme_date_obj = new ExpressiveDate( 'now', EME_TIMEZONE );
$old_date = $eme_date_obj->minusDays( $remove_old_signups_days )->getDateTime();
// we don't remove old bookings, just anonymize them
$sql = $wpdb->prepare("DELETE FROM $table WHERE event_id IN (SELECT event_id FROM $events_table WHERE $events_table.event_end < %s)", $old_date);
$wpdb->query( $sql );
}
function eme_task_signups_page() {
eme_task_signups_table_layout();
}
function eme_task_signups_table_layout( $message = '' ) {
$nonce_field = wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false );
if ( empty( $message ) ) {
$hidden_class = 'eme-hidden';
} else {
$hidden_class = '';
}
echo "
<div class='wrap nosubsub'>
<div id='poststuff'>
<div id='icon-edit' class='icon32'>
</div>
<h1>" . __( 'Manage task signups', 'events-made-easy' ) . "</h1>\n ";
?>
<div id="tasksignups-message" class="notice is-dismissible eme-message-admin <?php echo $hidden_class; ?>">
<p><?php echo $message; ?></p>
</div>
<form action="#" method="post">
<?php if (isset($_GET['event_id'])) { ?>
<input type="hidden" name="search_eventid" id="search_eventid" value="<?php echo intval($_GET['event_id']);?>">
<?php } else { ?>
<input type="text" class="clearable" name="search_name" id="search_name" placeholder="<?php esc_attr_e( 'Task name', 'events-made-easy' ); ?>" size=20>
<input type="text" class="clearable" name="search_event" id="search_event" placeholder="<?php esc_attr_e( 'Event name', 'events-made-easy' ); ?>" size=20>
<input type="text" class="clearable" name="search_person" id="search_person" placeholder="<?php esc_attr_e( 'Person name', 'events-made-easy' ); ?>" size=20>
<select id="search_scope" name="search_scope">
<?php
$scope_names = [];
$scope_names['past'] = __( 'Past events', 'events-made-easy' );
$scope_names['all'] = __( 'All events', 'events-made-easy' );
$scope_names['future'] = __( 'Future events', 'events-made-easy' );
foreach ( $scope_names as $key => $value ) {
$selected = '';
if ( $key == 'future' ) {
$selected = "selected='selected'";
}
echo "<option value='".esc_attr($key)."' $selected>".esc_html($value)."</option>";
}
?>
</select>
<?php
$eme_signup_status_array = [
-1 => __('All', 'events-made-easy'),
0 => __('Pending', 'events-made-easy'),
1 => __('Approved', 'events-made-easy')
];
if (isset($_GET['status']))
echo eme_ui_select( intval($_GET['status']), 'search_signup_status', $eme_signup_status_array );
else
echo eme_ui_select( -1, 'search_signup_status', $eme_signup_status_array );
?>
<input id="search_start_date" type="hidden" name="search_start_date" value="">
<input id="eme_localized_search_start_date" type="text" name="eme_localized_search_start_date" value="" style="background: #FCFFAA;" readonly="readonly" placeholder="<?php esc_attr_e( 'Filter on start date', 'events-made-easy' ); ?>" size=15 data-date='' data-alt-field='search_start_date' class='eme_formfield_fdate'>
<input id="search_end_date" type="hidden" name="search_end_date" value="">
<input id="eme_localized_search_end_date" type="text" name="eme_localized_search_end_date" value="" style="background: #FCFFAA;" readonly="readonly" placeholder="<?php esc_attr_e( 'Filter on end date', 'events-made-easy' ); ?>" size=15 data-date='' data-alt-field='search_end_date' class='eme_formfield_fdate'>
<button id="TaskSignupsLoadRecordsButton" class="button-secondary action"><?php esc_html_e( 'Filter task signups', 'events-made-easy' ); ?></button>
<?php } ?>
</form>
<form id='task-signups-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="sendMails"><?php esc_html_e( 'Send generic email to selected persons', 'events-made-easy' ); ?></option>
<option value="sendReminders"><?php esc_html_e( 'Send reminders for task signups', 'events-made-easy' ); ?></option>
<option value="approveTaskSignups"><?php esc_html_e( 'Approve selected task signups', 'events-made-easy' ); ?></option>
<option value="deleteTaskSignups"><?php esc_html_e( 'Delete selected task signups', 'events-made-easy' ); ?></option>
</select>
<span id="span_sendmails" class="eme-hidden">
<?php
esc_html_e( 'Send mails to people upon changes being made?', 'events-made-easy' );
echo eme_ui_select_binary( 1, 'send_mail' );
?>
</span>
<button id="TaskSignupsActionsButton" 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>
</form>
<div id="TaskSignupsTableContainer"></div>
</div>
</div>
<?php
}
function eme_meta_box_div_event_task_signup_made_email( $event, $templates_array ) {
?>
<div>
<b><?php esc_html_e( 'Task Signup Made Email Subject', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The subject of the email sent to the respondent when that person signs up for a task.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['task_signup_email_subject_tpl'], 'eme_prop_task_signup_email_subject_tpl', $templates_array );
?>
<br>
<br>
<b><?php esc_html_e( 'Task Signup Made Email Body', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The body of the email sent to the respondent when that person signs up for a task.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['task_signup_email_body_tpl'], 'eme_prop_task_signup_email_body_tpl', $templates_array );
?>
</div>
<br>
<div>
<b><?php esc_html_e( 'Contact Person Task Signup Made Email Subject', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The subject of the email which will be sent to the contact person when someone signs up for a task.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['cp_task_signup_email_subject_tpl'], 'eme_prop_cp_task_signup_email_subject_tpl', $templates_array );
?>
<br>
<br>
<b><?php esc_html_e( 'Contact Person Task Signup Made Email Body', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The body of the email which will be sent to the contact person when someone signs up for a task.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['cp_task_signup_email_body_tpl'], 'eme_prop_cp_task_signup_email_body_tpl', $templates_array );
?>
</div>
<?php
}
function eme_meta_box_div_event_task_signup_pending_email( $event, $templates_array ) {
?>
<div>
<b><?php esc_html_e( 'Task Signup Pending Email Subject', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The subject of the email sent to the respondent when that person signs up for a task that requires approval.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['task_signup_pending_email_subject_tpl'], 'eme_prop_task_signup_pending_email_subject_tpl', $templates_array );
?>
<br>
<br>
<b><?php esc_html_e( 'Task Signup Pending Email Body', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The body of the email sent to the respondent when that person signs up for a task that requires approval.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['task_signup_pending_email_body_tpl'], 'eme_prop_task_signup_pending_email_body_tpl', $templates_array );
?>
</div>
<br>
<div>
<b><?php esc_html_e( 'Contact Person Task Signup Pending Email Subject', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The subject of the email which will be sent to the contact person when someone signs up for a task that requires approval.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['cp_task_signup_pending_email_subject_tpl'], 'eme_prop_cp_task_signup_pending_email_subject_tpl', $templates_array );
?>
<br>
<br>
<b><?php esc_html_e( 'Contact Person Task Signup Pending Email Body', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The body of the email which will be sent to the contact person when someone signs up for a task that requires approval.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['cp_task_signup_pending_email_body_tpl'], 'eme_prop_cp_task_signup_pending_email_body_tpl', $templates_array );
?>
</div>
<?php
}
function eme_meta_box_div_event_task_signup_updated_email( $event, $templates_array ) {
?>
<div>
<b><?php esc_html_e( 'Task Signup Updated Email Subject', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The subject of the email which will be sent to the respondent if the task signup has been updated by an admin.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['task_signup_updated_email_subject_tpl'], 'eme_prop_task_signup_updated_email_subject_tpl', $templates_array );
?>
<br>
<br>
<b><?php esc_html_e( 'Task Signup Updated Email Body', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The body of the email which will be sent to the respondent if the task signup has been updated by an admin.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['task_signup_updated_email_body_tpl'], 'eme_prop_task_signup_updated_email_body_tpl', $templates_array );
?>
</div>
<?php
}
function eme_meta_box_div_event_task_signup_cancelled_email( $event, $templates_array ) {
?>
<div>
<b><?php esc_html_e( 'Task Signup Cancelled Email Subject', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The subject of the email which will be sent to the respondent when he himself cancels a task signup.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['task_signup_cancelled_email_subject_tpl'], 'eme_prop_task_signup_cancelled_email_subject_tpl', $templates_array );
?>
<br>
<br>
<b><?php esc_html_e( 'Task Signup Cancelled Email Body', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The body of the email which will be sent to the respondent when he himself cancels a task signup.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['task_signup_cancelled_email_body_tpl'], 'eme_prop_task_signup_cancelled_email_body_tpl', $templates_array );
?>
</div>
<br>
<div>
<b><?php esc_html_e( 'Contact Person Task Signup Cancelled Email Subject', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The subject of the email which will be sent to the contact person when a respondent cancels a task signup.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['cp_task_signup_cancelled_email_subject_tpl'], 'eme_prop_cp_task_signup_cancelled_email_subject_tpl', $templates_array );
?>
<br>
<br>
<b><?php esc_html_e( 'Contact Person Task Signup Cancelled Email Body', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The body of the email which will be sent to the contact person when a respondent cancels a task signup.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['cp_task_signup_cancelled_email_body_tpl'], 'eme_prop_cp_task_signup_cancelled_email_body_tpl', $templates_array );
?>
</div>
<?php
}
function eme_meta_box_div_event_task_signup_trashed_email( $event, $templates_array ) {
?>
<div id="div_event_task_signup_trashed_email">
<b><?php esc_html_e( 'Task Signup Deleted Email Subject', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The subject of the email which will be sent to the respondent if the task signup is deleted by an admin.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['task_signup_trashed_email_subject_tpl'], 'eme_prop_task_signup_trashed_email_subject_tpl', $templates_array );
?>
<br>
<br>
<b><?php esc_html_e( 'Task Signup Deleted Email Body', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The body of the email which will be sent to the respondent if the task signup is deleted by an admin.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['task_signup_trashed_email_body_tpl'], 'eme_prop_task_signup_trashed_email_body_tpl', $templates_array );
?>
</div>
<?php
}
function eme_meta_box_div_event_task_signup_reminder_email( $event, $templates_array ) {
?>
<div id="div_event_task_signup_reminder_email">
<b><?php esc_html_e( 'Task Signup Reminder Email Subject', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The subject of the reminder email which will be sent to the respondent.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['task_signup_reminder_email_subject_tpl'], 'eme_prop_task_signup_reminder_email_subject_tpl', $templates_array );
?>
<br>
<br>
<b><?php esc_html_e( 'Task Signup Reminder Email Body', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The body of the reminder email which will be sent to the respondent.', 'events-made-easy' ); ?></p>
<br>
<?php
esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' );
echo eme_ui_select( $event['event_properties']['task_signup_reminder_email_body_tpl'], 'eme_prop_task_signup_reminder_email_body_tpl', $templates_array );
?>
</div>
<?php
}
function eme_meta_box_div_event_task_signup_form_format( $event, $templates_array ) {
?>
<div id="div_event_task_signup_form_format">
<b><?php esc_html_e( 'Task Signup Form', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The layout of the task signup form.', 'events-made-easy' ); ?></p>
<br>
<?php esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' ); ?>
<?php esc_html_e( 'Warning: this override will only be used when inside a single event, otherwise the generic setting will always be used!', 'events-made-easy' ); ?>
<?php echo eme_ui_select( $event['event_properties']['task_signup_form_format_tpl'], 'eme_prop_task_signup_form_format_tpl', $templates_array ); ?>
</div>
<?php
}
function eme_meta_box_div_event_task_signup_recorded_ok_html( $event, $templates_array ) {
?>
<div id="div_event_task_signup_recorded_ok_html">
<b><?php esc_html_e( 'Signup recorded message', 'events-made-easy' ); ?></b>
<p class="eme_smaller"><?php esc_html_e( 'The text (html allowed) shown to the user when the task signup has been made successfully.', 'events-made-easy' ); ?></p>
<br>
<?php esc_html_e( 'Only choose a template if you want to override the default settings:', 'events-made-easy' ); ?>
<?php echo eme_ui_select( $event['event_properties']['task_signup_recorded_ok_html_tpl'], 'eme_prop_task_signup_recorded_ok_html_tpl', $templates_array ); ?>
</div>
<?php
}
function eme_meta_box_div_event_tasks( $event, $edit_recurrence = 0 ) {
if ( isset( $event['is_duplicate'] ) ) {
$tasks = eme_get_event_tasks( $event['orig_id'] );
} elseif ( ! empty( $event['event_id'] ) ) {
$tasks = eme_get_event_tasks( $event['event_id'] );
} else {
$tasks = [];
}
?>
<div id="div_tasks">
<?php
if ( ! empty( $tasks ) ) {
esc_html_e( 'Change the date of the listed tasks by this many days', 'events-made-easy' );
print "<input type='number' id=task_offset name=task_offset><button type='button' name='change_task_days' id='change_task_days'>" . __( 'Change', 'events-made-easy' ) . '</button>';
}
?>
<table class="eme_tasks">
<thead>
<tr>
<th></th>
<th></th>
<th><strong><?php esc_html_e( 'Name', 'events-made-easy' ); ?></strong></th>
<th><strong><?php esc_html_e( 'Begin', 'events-made-easy' ); ?></strong></th>
<th><strong><?php esc_html_e( 'End', 'events-made-easy' ); ?></strong></th>
<th><strong><?php esc_html_e( 'Spaces', 'events-made-easy' ); ?></strong></th>
<th><strong><?php esc_html_e( 'Description', 'events-made-easy' ); ?></strong></th>
<th></th>
</tr>
</thead>
<tbody id="eme_tasks_tbody" class="eme_tasks_tbody">
<?php
// if there are no entries in the array, make 1 empty entry in it, so it renders at least 1 row
if ( ! is_array( $tasks ) || count( $tasks ) == 0 ) {
$info = eme_new_task();
$tasks = [ $info ];
$required = '';
} else {
$required = "required='required'";
}
foreach ( $tasks as $count => $task ) {
?>
<tr id="eme_row_task_<?php echo $count; ?>" >
<td>
<?php echo "<img class='eme-sortable-handle' src='" . esc_url(EME_PLUGIN_URL) . "images/reorder.png' alt='" . esc_attr__( 'Reorder', 'events-made-easy' ) . "'>"; ?>
</td>
<td>
<?php if ( ! isset( $event['is_duplicate'] ) ) : // we set the task ids only if it is not a duplicate event ?>
<input type='hidden' id="eme_tasks[<?php echo $count; ?>][task_id]" name="eme_tasks[<?php echo $count; ?>][task_id]" aria-label="hidden index" size="5" value="<?php if ( isset( $task['task_id'] ) ) { echo $task['task_id'];} ?>">
<input type='hidden' id="eme_tasks[<?php echo $count; ?>][task_nbr]" name="eme_tasks[<?php echo $count; ?>][task_nbr]" aria-label="hidden index" size="5" value="<?php if ( isset( $task['task_nbr'] ) ) { echo $task['task_nbr'];} ?>">
<?php endif; ?>
</td>
<td>
<input <?php echo $required; ?> id="eme_tasks[<?php echo $count; ?>][name]" name="eme_tasks[<?php echo $count; ?>][name]" size="12" aria-label="name" value="<?php echo $task['name']; ?>">
</td>
<td>
<input type='hidden' readonly='readonly' name='eme_tasks[<?php echo $count; ?>][task_start]' id='eme_tasks[<?php echo $count; ?>][task_start]'>
<input <?php echo $required; ?> type='text' readonly='readonly' name='eme_tasks[<?php echo $count; ?>][dp_task_start]' id='eme_tasks[<?php echo $count; ?>][dp_task_start]' data-date='<?php if ( $task['task_start'] ) { echo eme_js_datetime( $task['task_start'] );} ?>' data-alt-field='#eme_tasks[<?php echo $count; ?>][task_start]' class='eme_formfield_fdatetime'>
</td>
<td>
<input type='hidden' readonly='readonly' name='eme_tasks[<?php echo $count; ?>][task_end]' id='eme_tasks[<?php echo $count; ?>][task_end]'>
<input <?php echo $required; ?> type='text' readonly='readonly' name='eme_tasks[<?php echo $count; ?>][dp_task_end]' id='eme_tasks[<?php echo $count; ?>][dp_task_end]' data-date='<?php if ( $task['task_end'] ) { echo eme_js_datetime( $task['task_end'] );} ?>' data-alt-field='#eme_tasks[<?php echo $count; ?>][task_end]' class='eme_formfield_fdatetime'>
</td>
<td>
<input <?php echo $required; ?> id="eme_tasks[<?php echo $count; ?>][spaces]" name="eme_tasks[<?php echo $count; ?>][spaces]" size="12" aria-label="spaces" value="<?php echo $task['spaces']; ?>">
</td>
<td>
<textarea class="eme_fullresizable" id="eme_tasks[<?php echo $count; ?>][description]" name="eme_tasks[<?php echo $count; ?>][description]" ><?php echo eme_esc_html( $task['description'] ); ?></textarea>
</td>
<td>
<a href="#" class='eme_remove_task'><?php echo "<img src='" . esc_url(EME_PLUGIN_URL) . "images/cross.png' alt='" . esc_attr__( 'Remove', 'events-made-easy' ) . "' title='" . esc_attr__( 'Remove', 'events-made-easy' ) . "'>"; ?></a><a href="#" class="eme_add_task"><?php echo "<img src='" . esc_url(EME_PLUGIN_URL) . "images/plus_16.png' alt='" . esc_attr__( 'Add new task', 'events-made-easy' ) . "' title='" . esc_attr__( 'Add new task', 'events-made-easy' ) . "'>"; ?></a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<?php esc_html_e( 'If name, start date or end date of a task is empty, it will be ignored.', 'events-made-easy' );
esc_html_e( 'If the number of spaces for a task is 0, the task description will be treated as a section header for the next set of tasks.', 'events-made-easy' ); ?>
<?php
if ( $edit_recurrence ) {
echo "<div style='background-color: lightgrey;'>";
esc_html_e( 'For recurring events, enter the start and end date of the task as if you would do it for the first event in the series. The tasks for the other events will be adjusted accordingly.', 'events-made-easy' );
if ( ! eme_is_empty_date( $event['event_start'] ) ) {
echo '<br>';
echo esc_html(sprintf( __( 'The start date of the first event in the series was initially %s', 'events-made-easy' ), eme_localized_datetime( $event['event_start'], EME_TIMEZONE ) ));
}
echo '</div>';
}
?>
</div>
<?php
}
function eme_meta_box_div_event_task_settings( $event ) {
$eme_prop_task_registered_users_only = ( $event['event_properties']['task_registered_users_only'] ) ? "checked='checked'" : '';
$eme_prop_task_requires_approval = ( $event['event_properties']['task_requires_approval'] ) ? "checked='checked'" : '';
$eme_prop_task_only_one_signup_pp = ( $event['event_properties']['task_only_one_signup_pp'] ) ? "checked='checked'" : '';
$eme_prop_task_allow_overlap = ( $event['event_properties']['task_allow_overlap'] ) ? "checked='checked'" : '';
$eme_prop_task_reminder_days = eme_esc_html( $event['event_properties']['task_reminder_days'] );
?>
<div id='div_event_task_settings'>
<p id='p_task_registered_users_only'>
<input id="eme_prop_task_registered_users_only" name='eme_prop_task_registered_users_only' value='1' type='checkbox' <?php echo $eme_prop_task_registered_users_only; ?>>
<label for="eme_prop_task_registered_users_only"><?php esc_html_e( 'Require WP membership to be able to sign up for tasks?', 'events-made-easy' ); ?></label>
</p>
<p id='p_task_addpersontogroup'>
<label for='eme_prop_task_addpersontogroup'><?php esc_html_e( 'Group to add people to', 'events-made-easy' ); ?></label></td>
<td><?php echo eme_ui_multiselect_key_value( $event['event_properties']['task_addpersontogroup'], 'eme_prop_task_addpersontogroup', eme_get_static_groups(), 'group_id', 'name', 5, '', 0, 'eme_select2_groups_class' ); ?><p class="eme_smaller"><?php esc_html_e( 'The group you want people to automatically become a member of when they subscribe.', 'events-made-easy' ); ?></p>
<p id='p_task_requires_approval'>
<input id="eme_prop_task_requires_approval" name='eme_prop_task_requires_approval' value='1' type='checkbox' <?php echo $eme_prop_task_requires_approval; ?>>
<label for="eme_prop_task_requires_approval"><?php esc_html_e( 'Require approval for task signups?', 'events-made-easy' ); ?></label>
</p>
<p id='p_task_only_one_signup_pp'>
<input id="eme_prop_task_only_one_signup_pp" name='eme_prop_task_only_one_signup_pp' value='1' type='checkbox' <?php echo $eme_prop_task_only_one_signup_pp; ?>>
<label for="eme_prop_task_only_one_signup_pp"><?php esc_html_e( 'Allow only one sign up for tasks per event for a person?', 'events-made-easy' ); ?></label>
</p>
<p id='p_task_allow_overlap'>
<input id="eme_prop_task_allow_overlap" name='eme_prop_task_allow_overlap' value='1' type='checkbox' <?php echo $eme_prop_task_allow_overlap; ?>>
<label for="eme_prop_task_allow_overlap"><?php esc_html_e( 'Allow overlap for task signups?', 'events-made-easy' ); ?></label>
</p>
<p id='p_task_reminder_days'>
<input id="eme_prop_task_reminder_days" name='eme_prop_task_reminder_days' type='text' value="<?php echo $eme_prop_task_reminder_days; ?>">
<label for="eme_prop_task_reminder_days"><?php esc_html_e( 'Set the number of days before task signup reminder emails will be sent (counting from the start date of the task). If you want to send out multiple reminders, seperate the days here by commas. Leave empty for no reminder emails.', 'events-made-easy' ); ?></label>
</p>
</div>
<?php
}
function eme_mytasks_signups_shortcode( $atts ) {
eme_enqueue_frontend();
if ( is_user_logged_in() ) {
$wp_id = get_current_user_id();
} else {
return;
}
$person = eme_get_person_by_wp_id( $wp_id );
if ( empty( $person ) ) {
return;
}
extract(
shortcode_atts(
[
'scope' => 'future',
'task_id' => 0,
'event_id' => 0,
'template_id' => 0,
'template_id_header' => 0,
'template_id_footer' => 0,
],
$atts
)
);
$format = '';
$header = '';
$footer = '';
if ( ! empty( $template_id ) ) {
$format = eme_get_template_format( $template_id );
}
if ( empty( $format ) ) {
$format = eme_translate_string_nowptrans( get_option( 'eme_task_signup_format' ) );
}
if ( ! empty( $template_id_header ) ) {
$header = eme_get_template_format( $template_id_header );
}
if ( ! empty( $template_id_footer ) ) {
$footer = eme_get_template_format( $template_id_footer );
}
$signups = eme_get_task_signups_by( $wp_id, $task_id, $event_id, $scope );
$result = $header;
foreach ( $signups as $signup ) {
$event = eme_get_event( $signup['event_id'] );
$task = eme_get_task( $signup['task_id'] );
$result .= eme_replace_tasksignup_placeholders( $format, $signup, $person, $event, $task );
}
$result .= $footer;
return $result;
}
function eme_tasks_signups_shortcode( $atts ) {
eme_enqueue_frontend();
extract(
shortcode_atts(
[
'scope' => 'future',
'order' => 'ASC',
'category' => '',
'showperiod' => '',
'author' => '',
'contact_person' => '',
'event_id' => 0,
'location_id' => 0,
'task_id' => 0,
'show_ongoing' => 1,
'notcategory' => '',
'show_recurrent_events_once' => 0,
'template_id' => 0,
'template_id_header' => 0,
'template_id_footer' => 0,
'ignore_filter' => 0,
],
$atts
)
);
$event_id_arr = [];
$location_id_arr = [];
$result = '';
// per event, the header and footer are repeated, the template_id itself is repeated per task
$format = '';
$header = '';
$footer = '';
if ( ! empty( $template_id ) ) {
$format = eme_get_template_format( $template_id );
}
if ( empty( $format ) ) {
$format = get_option( 'eme_task_signup_format' );
}
if ( ! empty( $template_id_header ) ) {
$header = eme_get_template_format( $template_id_header );
}
if ( ! empty( $template_id_footer ) ) {
$footer = eme_get_template_format( $template_id_footer );
}
// if a task id is set, show only the signups for that task
$task_id = intval( $task_id );
if ( $task_id > 0 ) {
$signups = eme_get_task_signups( $task_id );
foreach ( $signups as $signup ) {
$person = eme_get_person( $signup['person_id'] );
$result .= eme_replace_tasksignup_placeholders( $format, $signup, $person, $event, $task );
}
return $result;
}
// the filter list overrides the settings
if ( ! $ignore_filter && isset( $_REQUEST['eme_eventAction'] ) && eme_sanitize_request( $_REQUEST['eme_eventAction']) == 'filter' ) {
if ( ! empty( $_REQUEST['eme_scope_filter'] ) ) {
$scope = eme_sanitize_request( $_REQUEST['eme_scope_filter'] );
}
if ( ! empty( $_REQUEST['eme_author_filter'] ) && intval( $_REQUEST['eme_author_filter'] ) > 0 ) {
$author = intval( $_REQUEST['eme_author_filter'] );
}
if ( ! empty( $_REQUEST['eme_contact_filter'] ) && intval( $_REQUEST['eme_contact_filter'] ) > 0 ) {
$contact_person = intval( $_REQUEST['eme_contact_filter'] );
}
if ( ! empty( $_REQUEST['eme_loc_filter'] ) ) {
if ( is_array( $_REQUEST['eme_loc_filter'] ) ) {
$arr = eme_array_remove_empty_elements( eme_sanitize_request( $_REQUEST['eme_loc_filter'] ) );
if ( ! empty( $arr ) ) {
$location_id_arr = $arr;
}
} else {
$location_id_arr[] = eme_sanitize_request( $_REQUEST['eme_loc_filter'] );
}
if ( empty( $location_id_arr ) ) {
$location_id = -1;
}
}
if ( ! empty( $_REQUEST['eme_city_filter'] ) ) {
$cities = eme_sanitize_request( $_REQUEST['eme_city_filter'] );
$tmp_ids = eme_get_city_location_ids( $cities );
if ( empty( $location_id_arr ) ) {
$location_id_arr = $tmp_ids;
} else {
$location_id_arr = array_intersect( $location_id_arr, $tmp_ids );
}
if ( empty( $location_id_arr ) ) {
$location_id = -1;
}
}