-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
eme-locations.php
3157 lines (2970 loc) · 131 KB
/
eme-locations.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_location() {
$location = [
'location_name' => '',
'location_address1' => '',
'location_address2' => '',
'location_city' => '',
'location_state' => '',
'location_zip' => '',
'location_country' => '',
'location_latitude' => '',
'location_longitude' => '',
'location_description' => '',
'location_category_ids' => '',
'location_url' => '',
'location_prefix' => '',
'location_slug' => '',
'location_image_url' => '',
'location_external_ref' => '',
'location_image_id' => 0,
'location_author' => 0,
'location_attributes' => [],
];
$location['location_properties'] = eme_init_location_props();
return $location;
}
function eme_init_location_props( $props = [] ) {
if ( ! isset( $props['map_icon'] ) ) {
$props['map_icon'] = '';
}
if ( ! isset( $props['online_only'] ) ) {
$props['online_only'] = 0;
}
if ( ! isset( $props['max_capacity'] ) ) {
$props['max_capacity'] = 0;
}
if ( ! isset( $props['override_loc'] ) ) {
$props['override_loc'] = 0;
}
// for sure integers
$numbers = [ 'online_only', 'max_capacity', 'override_loc' ];
foreach ( $numbers as $opt ) {
$props[$opt]=intval($props[$opt]);
}
return $props;
}
function eme_locations_page() {
$current_userid = get_current_user_id();
if ( isset( $_POST['eme_admin_action'] ) && $_POST['eme_admin_action'] == 'import_locations' && isset( $_FILES['eme_csv'] ) && current_user_can( get_option( 'eme_cap_cleanup' ) ) ) {
// eme_cap_cleanup is used for cleanup, cron and imports (should more be something like 'eme_cap_actions')
check_admin_referer( 'eme_admin', 'eme_admin_nonce' );
$message = eme_import_csv_locations();
eme_locations_table( $message );
} elseif ( isset( $_GET['eme_admin_action'] ) && $_GET['eme_admin_action'] == 'edit_location' ) {
$location_id = eme_sanitize_request( $_GET['location_id'] );
$location = eme_get_location( $location_id );
if ( ! empty( $location ) && ( current_user_can( get_option( 'eme_cap_edit_locations' ) ) ||
( current_user_can( get_option( 'eme_cap_author_locations' ) ) && ( $location['location_author'] == $current_userid ) ) ) ) {
// edit location
eme_locations_edit_layout( $location );
} else {
$message = __( 'You have no right to edit this location!', 'events-made-easy' );
eme_locations_table( $message );
}
} elseif ( isset( $_GET['eme_admin_action'] ) && $_GET['eme_admin_action'] == 'copy_location' ) {
$location_id = eme_sanitize_request( $_GET['location_id'] );
$location = eme_get_location( $location_id );
if ( empty( $location ) ) {
$location = eme_new_location();
}
// we add the custom field answers to the location copy
$location['cf_answers'] = eme_get_location_answers( $location_id );
// make it look like a new location
if ( isset( $location['location_id'] ) ) {
unset( $location['location_id'] );
}
$location['location_name'] .= __( ' (Copy)', 'events-made-easy' );
if ( current_user_can( get_option( 'eme_cap_add_locations' ) ) ) {
eme_locations_edit_layout( $location );
} else {
$message = __( 'You have no right to copy this location!', 'events-made-easy' );
eme_locations_table( $message );
}
} elseif ( isset( $_POST['eme_admin_action'] ) && $_POST['eme_admin_action'] == 'add_location' ) {
check_admin_referer( 'eme_admin', 'eme_admin_nonce' );
if ( current_user_can( get_option( 'eme_cap_add_locations' ) ) ) {
$location = eme_new_location();
eme_locations_edit_layout( $location );
} else {
$message = __( 'You have no right to add a location!', 'events-made-easy' );
eme_locations_table( $message );
}
} elseif ( isset( $_POST['eme_admin_action'] ) && ( $_POST['eme_admin_action'] == 'do_editlocation' || $_POST['eme_admin_action'] == 'do_addlocation' ) ) {
check_admin_referer( 'eme_admin', 'eme_admin_nonce' );
$action = eme_sanitize_request( $_POST['eme_admin_action'] );
if ( $action == 'do_editlocation' ) {
$location_id = intval( $_POST['location_id'] );
$location = eme_get_location( $location_id );
if ( empty( $location ) ) {
$location_id = 0;
$location = eme_new_location();
}
} else {
$location_id = 0;
$location = eme_new_location();
}
if ( $action == 'do_addlocation' && ! current_user_can( get_option( 'eme_cap_add_locations' ) ) ) {
$message = __( 'You have no right to add a location!', 'events-made-easy' );
eme_locations_table( $message );
} elseif ( $action == 'do_editlocation' && ! ( current_user_can( get_option( 'eme_cap_edit_locations' ) ) ||
( current_user_can( get_option( 'eme_cap_author_locations' ) ) && ( $location['location_author'] == $current_userid ) ) ) ) {
$message = __( 'You have no right to edit this location!', 'events-made-easy' );
eme_locations_table( $message );
} else {
$post_vars = [ 'location_name', 'location_address1', 'location_address2', 'location_city', 'location_state', 'location_zip', 'location_country', 'location_url', 'location_image_url', 'location_image_id', 'location_prefix', 'location_slug', 'location_latitude', 'location_longitude', 'location_author' ];
foreach ( $post_vars as $post_var ) {
if ( isset( $_POST[ $post_var ] ) ) {
$location[ $post_var ] = eme_sanitize_request( $_POST[ $post_var ] );
}
}
//switched to WP TinyMCE field
$location['location_description'] = eme_kses_maybe_unfiltered( $_POST['location_description'] );
if ( isset( $_POST['location_category_ids'] ) && eme_is_numeric_array( $_POST['location_category_ids'] ) ) {
$location ['location_category_ids'] = join( ',', $_POST['location_category_ids'] );
} else {
$location ['location_category_ids'] = '';
}
$location_attributes = [];
$i=1;
while (isset( $_POST[ "eme_attr_{$i}_ref" ] ) && !eme_is_empty_string( $_POST[ "eme_attr_{$i}_ref" ] ) ) {
if ( !eme_is_empty_string( $_POST[ "eme_attr_{$i}_name" ] ) ) {
$location_attributes[ $_POST[ "eme_attr_{$i}_ref" ] ] = eme_kses( $_POST[ "eme_attr_{$i}_name" ] );
}
$i++;
}
$location['location_attributes'] = $location_attributes;
$location_properties = [];
foreach ( $_POST as $key => $value ) {
if ( preg_match( '/eme_loc_prop_(.+)/', eme_sanitize_request( $key ), $matches ) ) {
$found_key = $matches[1];
if ( preg_match( '/password/', $found_key ) ) {
$location_properties[ $found_key ] = $value;
} else {
$location_properties[ $found_key ] = eme_kses( $value );
}
}
}
$location['location_properties'] = eme_init_location_props( $location_properties );
$location = eme_sanitize_location( $location );
$validation_result = eme_validate_location( $location );
if ( $validation_result == 'OK' ) {
if ( $action == 'do_addlocation' ) {
$new_location_id = eme_insert_location( $location );
if ( $new_location_id ) {
eme_location_store_answers( $new_location_id );
eme_upload_files( $new_location_id, 'locations' );
$new_location = eme_get_location( $new_location_id );
$message = __( 'The location has been added.', 'events-made-easy' );
if ( get_option( 'eme_stay_on_edit_page' ) ) {
eme_locations_edit_layout( $new_location, $message );
return;
}
} else {
$message = __( 'There has been a problem adding the location.', 'events-made-easy' );
}
} elseif ( $action == 'do_editlocation' ) {
if ( eme_update_location( $location, $location_id ) ) {
eme_location_store_answers( $location_id );
eme_upload_files( $location_id, 'locations' );
$message = __( 'The location has been updated.', 'events-made-easy' );
if ( get_option( 'eme_stay_on_edit_page' ) ) {
// for edit, we need a location id
$location = eme_get_location( $location_id );
eme_locations_edit_layout( $location, $message );
return;
}
} else {
$message = __( 'The location update failed.', 'events-made-easy' );
}
}
eme_locations_table( $message );
} else {
// validation failed, show why and return to the edit
$message = $validation_result;
$location['location_attributes'] = eme_unserialize( $location_attributes );
$location['location_properties'] = eme_unserialize( $location_properties );
eme_locations_edit_layout( $location, $message );
}
}
} else {
// no action, just a locations list
eme_locations_table();
}
}
function eme_import_csv_locations() {
global $wpdb;
$answers_table = EME_DB_PREFIX . EME_ANSWERS_TBNAME;
//validate whether uploaded file is a csv file
$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' ];
if ( empty( $_FILES['eme_csv']['name'] ) || ! in_array( $_FILES['eme_csv']['type'], $csvMimes ) ) {
return sprintf( __( 'No CSV file detected: %s', 'events-made-easy' ), $_FILES['eme_csv']['type'] );
}
if ( ! is_uploaded_file( $_FILES['eme_csv']['tmp_name'] ) ) {
return __( 'Problem detected while uploading the file', 'events-made-easy' );
return $result;
}
$updated = 0;
$inserted = 0;
$errors = 0;
$error_msg = '';
$handle = fopen( $_FILES['eme_csv']['tmp_name'], 'r' );
if ( ! $handle ) {
return __( 'Problem accessing the uploaded the file, maybe some security issue?', 'events-made-easy' );
}
// 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 = ',';
}
// get the first row as keys and lowercase them
$headers = array_map( 'strtolower', fgetcsv( $handle, 0, $delimiter, $enclosure ) );
// check required columns
if ( ! in_array( 'location_name', $headers ) || ! in_array( 'location_address1', $headers ) || ! in_array( 'location_city', $headers ) ) {
$result = __( 'Not all required fields present.', 'events-made-easy' );
} else {
$empty_props = [];
$empty_props = eme_init_location_props( $empty_props );
// now loop over the rest
while ( ( $row = fgetcsv( $handle, 0, $delimiter, $enclosure ) ) !== false ) {
$line = array_combine( $headers, $row );
// remove columns with empty values
$line = eme_array_remove_empty_elements( $line );
$location_id = 0;
if ( isset( $line['location_name'] ) && isset( $line['location_address1'] ) && isset( $line['location_city'] ) ) {
// also import attributes
foreach ( $line as $key => $value ) {
if ( preg_match( '/^att_(.*)$/', $key, $matches ) ) {
$att = $matches[1];
if ( ! isset( $line['location_attributes'] ) ) {
$line['location_attributes'] = [];
}
$line['location_attributes'][ $att ] = $value;
}
}
// also import properties
foreach ( $line as $key => $value ) {
if ( preg_match( '/^prop_(.*)$/', $key, $matches ) ) {
$prop = $matches[1];
if ( ! isset( $line['location_properties'] ) ) {
$line['location_properties'] = [];
}
if ( array_key_exists( $prop, $empty_props ) ) {
$line['location_properties'][ $prop ] = $value;
}
}
}
// if the location already exists: update it
if ( isset( $line['external_ref'] ) ) {
$location_id = eme_check_location_external_ref( $line['external_ref'] );
}
#if (!$location_id && isset($line['location_latitude']) && isset($line['location_longitude']))
# $location_id=eme_check_location_coord($line['location_latitude'],$line['location_longitude']);
#if (!$location_id)
# $location_id=eme_check_location_name_address($line);
if ( $location_id ) {
// location_id is returned if update is ok, and we use the location id later on
$location_id = eme_update_location( $line, $location_id );
if ( $location_id ) {
++$updated;
} else {
++$errors;
$error_msg .= '<br>' . eme_esc_html( sprintf( __( 'Not imported (problem updating the location in the db): %s', 'events-made-easy' ), implode( ',', $row ) ) );
}
} else {
$location_id = eme_insert_location( $line );
if ( $location_id ) {
++$inserted;
} else {
++$errors;
$error_msg .= '<br>' . eme_esc_html( sprintf( __( 'Not imported (problem inserting the location in the db): %s', 'events-made-easy' ), implode( ',', $row ) ) );
}
}
if ( $location_id ) {
// now handle all the extra info, in the CSV they need to be named like 'answer_XX' (with 'XX' being either the fieldid or the fieldname, e.g. answer_myfieldname)
foreach ( $line as $key => $value ) {
if ( preg_match( '/^answer_(.*)$/', $key, $matches ) ) {
$field_name = $matches[1];
$formfield = eme_get_formfield( $field_name );
if ( ! empty( $formfield ) && $formfield['field_purpose'] == 'locations' ) {
$field_id = $formfield['field_id'];
$sql = $wpdb->prepare( "DELETE FROM $answers_table WHERE related_id = %d and field_id=%d AND type='location'", $location_id, $field_id );
$wpdb->query( $sql );
$sql = $wpdb->prepare( "INSERT INTO $answers_table (related_id,field_id,answer,type) VALUES (%d,%d,%s,%s)", $location_id, $field_id, $value, 'location' );
$wpdb->query( $sql );
}
}
}
}
} else {
++$errors;
$error_msg .= '<br>' . eme_esc_html( sprintf( __( 'Not imported (not all required fields are present): %s', 'events-made-easy' ), implode( ',', $row ) ) );
}
}
$result = sprintf( __( 'Import finished: %d inserts, %d updates, %d errors', 'events-made-easy' ), $inserted, $updated, $errors );
if ( $errors ) {
$result .= '<br>' . $error_msg;
}
}
fclose( $handle );
return $result;
}
function eme_locations_edit_layout( $location, $message = '' ) {
global $plugin_page;
if ( ! isset( $location['location_id'] ) ) {
$action = 'add';
} else {
$action = 'edit';
}
$nonce_field = wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false );
?>
<div class="wrap">
<?php if ( $message != '' ) { ?>
<div id="message" class="notice is-dismissible eme-message-admin">
<p><?php echo $message; ?></p>
</div>
<?php } ?>
<div id="eme-location-changed" class='notice is-dismissible eme-message-admin' style="display:none;">
<p><?php esc_html_e( 'The location details have changed. Please verify the coordinates and press Save when done', 'events-made-easy' ); ?></p>
</div>
<form enctype="multipart/form-data" name="locationForm" id="locationForm" autocomplete="off" method="post" action="<?php echo admin_url( "admin.php?page=$plugin_page" ); ?>" class="validate">
<?php echo $nonce_field; ?>
<?php if ( $action == 'add' ) { ?>
<input type="hidden" name="eme_admin_action" value="do_addlocation">
<?php } else { ?>
<input type="hidden" name="eme_admin_action" value="do_editlocation">
<?php } ?>
<div id="icon-locations" class="icon32"></div>
<h1>
<?php
if ( $action == 'add' ) {
esc_html_e( 'Insert New Location', 'events-made-easy' );
} else {
echo sprintf( __( "Edit Location '%s'", 'events-made-easy' ), eme_translate( $location['location_name'] ) );
}
?>
</h1>
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-2">
<!-- MAIN -->
<div id="post-body-content">
<div id="location-tabs" style="display: none;">
<ul>
<li><a href="#tab-locationdetails"><?php esc_html_e( 'Location', 'events-made-easy' ); ?></a></li>
<?php if ( get_option( 'eme_attributes_enabled' ) ) : ?>
<li><a href="#tab-locationattributes"><?php esc_html_e( 'Attributes', 'events-made-easy' ); ?></a></li>
<?php endif; ?>
<li><a href="#tab-locationcustomfields"><?php esc_html_e( 'Custom fields', 'events-made-easy' ); ?></a></li>
</ul>
<div id="tab-locationdetails">
<?php
eme_meta_box_div_location_name( $location );
eme_meta_box_div_location_details( $location );
eme_meta_box_div_location_notes( $location );
eme_meta_box_div_location_image( $location );
eme_meta_box_div_location_url( $location );
?>
</div>
<?php if ( get_option( 'eme_attributes_enabled' ) ) : ?>
<div id="tab-locationattributes">
<?php
eme_meta_box_div_location_attributes( $location );
?>
</div>
<?php endif; ?>
<div id="tab-locationcustomfields">
<?php
eme_meta_box_div_location_customfields( $location );
?>
</div>
</div> <!-- end location-tabs -->
<p class="submit"><input type="submit" class="button-primary" name="submit" value="<?php if ( $action == 'add' ) { esc_html_e( 'Add location', 'events-made-easy' ); } else { esc_html_e( 'Update location', 'events-made-easy' ); } ?>"></p>
</div>
<!-- END OF MAIN -->
<!-- SIDEBAR -->
<div id="postbox-container-1" class="postbox-container">
<div id='side-sortables' class="meta-box-sortables ui-sortable">
<!-- author postbox -->
<?php
if ( $action == 'edit' ) {
$location_author = $location['location_author'];
} else {
$location_author = get_current_user_id();
}
?>
<div class="postbox" id="eme_authordiv">
<h2 class='hndle'><span><?php esc_html_e( 'Author', 'events-made-easy' ); ?></span></h2>
<div class="inside">
<p><?php esc_html_e( 'Author of this location: ', 'events-made-easy' ); ?>
<?php
wp_dropdown_users(
[
'name' => 'location_author',
'selected' => $location_author,
]
);
?>
</p>
</div>
</div>
<!-- categories postbox -->
<div class="postbox" id="eme_categoriesdiv">
<h2 class='hndle'><span><?php esc_html_e( 'Category', 'events-made-easy' ); ?></span></h2>
<div class="inside">
<?php
$categories = eme_get_categories();
if ( empty( $categories ) ) {
?>
<span><?php esc_html_e( 'No categories defined.', 'events-made-easy' ); ?></span>
<?php
} else {
foreach ( $categories as $category ) {
if ( $location['location_category_ids'] && in_array( $category['category_id'], explode( ',', $location['location_category_ids'] ) ) ) {
$selected = "checked='checked'";
} else {
$selected = '';
}
?>
<input type="checkbox" name="location_category_ids[]" value="<?php echo $category['category_id']; ?>" <?php echo $selected; ?>><?php echo eme_trans_esc_html( $category['category_name'] ); ?><br>
<?php
} // end foreach
} // end if
?>
</div>
</div>
</div>
</div>
<!-- END OF SIDEBAR -->
</div>
</div>
</form>
</div>
<?php
}
function eme_meta_box_div_location_name( $location ) {
if ( empty( $location['location_id'] ) ) {
$action = 'add';
$location['location_id'] = 0;
} else {
$action = 'edit';
}
echo "<input type='hidden' id='location_id' name='location_id' value='" . intval( $location['location_id'] ) . "'>";
?>
<div id="titlediv">
<input name="location_name" id="location_name" type="text" required="required" placeholder="<?php esc_attr_e( 'Location name', 'events-made-easy' ); ?>" value="<?php echo esc_html( $location['location_name'] ); ?>" size="40">
<br>
<br>
<?php
if ( $action == 'edit' ) {
echo '<b>' . esc_html__( 'Permalink: ', 'events-made-easy' ) . '</b>';
} else {
echo '<b>' . esc_html__( 'Permalink prefix: ', 'events-made-easy' ) . '</b>';
}
echo trailingslashit( home_url() );
$locations_prefixes = get_option( 'eme_permalink_locations_prefix', 'locations' );
if ( preg_match( '/,/', $locations_prefixes ) ) {
$locations_prefixes = explode( ',', $locations_prefixes );
$locations_prefixes_arr = [];
foreach ( $locations_prefixes as $locations_prefix ) {
$locations_prefixes_arr[ $locations_prefix ] = eme_permalink_convert( $locations_prefix );
}
$prefix = $location['location_prefix'] ? $location['location_prefix'] : '';
echo eme_ui_select( $prefix, 'location_prefix', $locations_prefixes_arr );
} else {
echo eme_permalink_convert( $locations_prefixes );
}
if ( $action == 'edit' ) {
$slug = $location['location_slug'] ? $location['location_slug'] : $location['location_name'];
$slug = eme_permalink_convert_noslash( $slug );
?>
<input type="text" id="slug" name="location_slug" value="<?php echo $slug; ?>"><?php echo user_trailingslashit( '' ); ?>
<?php
}
?>
</div>
<?php
}
function eme_meta_box_div_location_name_for_event( $location ) {
if ( empty( $location['location_id'] ) ) {
$edit_link = "<img id='img_edit_location' name='img_edit_location' src='" . esc_url(EME_PLUGIN_URL) . "images/edit.png' alt='" . esc_attr__( 'Add location', 'events-made-easy' ) . "' title='" . __( 'Add location', 'events-made-easy' ) . "' style='cursor: pointer;'>";
$location['location_id'] = 0;
} else {
$edit_link = "<img id='img_edit_location' name='img_edit_location' src='" . esc_url(EME_PLUGIN_URL) . "images/edit.png' alt='" . esc_attr__( 'Edit location', 'events-made-easy' ) . "' title='" . __( 'Edit location', 'events-made-easy' ) . "' style='cursor: pointer;'>";
}
echo "<input type='hidden' id='location_id' name='location_id' value='" . intval( $location['location_id'] ) . "'>";
?>
<div id="loc_name" class="postbox">
<h3>
<?php esc_html_e( 'Location name', 'events-made-easy' ); ?>
</h3>
<div class="inside">
<input name="location_name" id="location_name" type="text" placeholder="<?php esc_attr_e( 'Location name', 'events-made-easy' ); ?>" value="<?php echo esc_html( $location['location_name'] ); ?>" size="40"> <?php echo $edit_link; ?>
<br><span class="eme_smaller"><?php esc_html_e( 'This is an autocomplete field. If a name of an existing location matches, it will be suggested.', 'events-made-easy' ); ?></span>
</div>
</div>
<?php
}
function eme_meta_box_div_location_details( $location ) {
$map_is_active = get_option( 'eme_map_is_active' );
$eme_loc_prop_override_loc_checked = ( $location['location_properties']['override_loc'] ) ? "checked='checked'" : '';
?>
<div id="loc_address" class="postbox" style="overflow: hidden;">
<h3>
<?php esc_html_e( 'Location address', 'events-made-easy' ); ?>
</h3>
<div class="inside" style="float:left; width:50%">
<table><tr>
<td><label for="location_address1"><?php echo eme_translate( get_option( 'eme_address1_string' ) ); ?></label></td>
<td><input id="location_address1" name="location_address1" type="text" value="<?php echo eme_esc_html( $location['location_address1'] ); ?>" size="40"></td>
</tr>
<tr>
<td><label for="location_address2"><?php echo eme_translate( get_option( 'eme_address2_string' ) ); ?></label></td>
<td><input id="location_address2" name="location_address2" type="text" value="<?php echo eme_esc_html( $location['location_address2'] ); ?>" size="40"></td>
</tr>
<tr>
<td><label for="location_city"><?php esc_html_e( 'City', 'events-made-easy' ); ?></label></td>
<td><input name="location_city" id="location_city" type="text" value="<?php echo eme_esc_html( $location['location_city'] ); ?>" size="40"></td>
</tr>
<tr>
<td><label for="location_state"><?php esc_html_e( 'State', 'events-made-easy' ); ?></label></td>
<td><input name="location_state" id="location_state" type="text" value="<?php echo eme_esc_html( $location['location_state'] ); ?>" size="40"></td>
</tr>
<tr>
<td><label for="location_zip"><?php esc_html_e( 'Postal code', 'events-made-easy' ); ?></label></td>
<td><input name="location_zip" id="location_zip" type="text" value="<?php echo eme_esc_html( $location['location_zip'] ); ?>" size="40"></td>
</tr>
<tr>
<td><label for="location_country"><?php esc_html_e( 'Country', 'events-made-easy' ); ?></label></td>
<td><input name="location_country" id="location_country" type="text" value="<?php echo eme_esc_html( $location['location_country'] ); ?>" size="40"></td>
</tr>
<tr>
<td colspan='2'>
<?php esc_html_e( "If you're are really serious about the correct location, specify the latitude and longitude coordinates.", 'events-made-easy' ); ?>
</td>
</tr>
<tr>
<td><label for="eme_loc_prop_override_loc"><?php esc_html_e( 'Override location coordinates', 'events-made-easy' ); ?></label></td>
<td><input id="eme_loc_prop_override_loc" name='eme_loc_prop_override_loc' value='1' type='checkbox' <?php echo $eme_loc_prop_override_loc_checked; ?>>
</tr>
<tr>
<td><label for="location_latitude"><?php esc_html_e( 'Latitude', 'events-made-easy' ); ?></label></td>
<td><input id="location_latitude" name="location_latitude" type="text" value="<?php echo eme_esc_html( $location['location_latitude'] ); ?>" size="40"></td>
</tr>
<tr>
<td><label for="location_longitude"><?php esc_html_e( 'Longitude', 'events-made-easy' ); ?></label></td>
<td><input id="location_longitude" name="location_longitude" type="text" value="<?php echo eme_esc_html( $location['location_longitude'] ); ?>" size="40"></td>
</tr></table>
</div>
<div class="inside" style="float:left;">
<?php
if ( $map_is_active ) {
?>
<div id='eme-edit-location-map' class='eme-adminedit-location-map'></div></td>
<?php
}
?>
</div>
</div>
<?php
if ( $map_is_active ) :
?>
<div id="loc_map_icon" class="postbox">
<h3>
<?php esc_html_e( 'Location map icon url', 'events-made-easy' ); ?>
</h3>
<div class="inside">
<table><tr>
<td><label for="eme_loc_prop_map_icon"><?php esc_html_e( 'Map icon url', 'events-made-easy' ); ?></label></td>
<td><input id="eme_loc_prop_map_icon" name="eme_loc_prop_map_icon" type="text" value="<?php echo eme_esc_html( $location['location_properties']['map_icon'] ); ?>" size="40">
<br><?php esc_html_e( "By default a regular pin is shown on the map where the location is. If you don't like the default, you can set another map icon here.", 'events-made-easy' ); ?>
<br><?php esc_html_e( 'Size should be 32x32, bottom center will be pointing to the location on the map.', 'events-made-easy' ); ?>
</td>
</tr></table>
</div>
</div>
<?php
if ( function_exists( 'qtrans_getLanguage' ) || function_exists( 'ppqtrans_getLanguage' ) || defined( 'ICL_LANGUAGE_CODE' ) ) :
?>
<div id="loc_qtrans_warning" class="postbox"><?php esc_html_e( "Because qtranslate or a derivate is active, the title of the location might not update automatically in the balloon, so don't panic there.", 'events-made-easy' ); ?> </div>
<?php endif; ?>
<?php endif; ?>
<div id="loc_max_capacity" class="postbox">
<h3>
<?php esc_html_e( 'Location maximum capacity', 'events-made-easy' ); ?>
</h3>
<div class="inside">
<table><tr>
<td><label for="eme_loc_prop_max_capacity"><?php esc_html_e( 'Max capacity', 'events-made-easy' ); ?></label></td>
<td><input id="eme_loc_prop_max_capacity" name="eme_loc_prop_max_capacity" type="text" value="<?php echo $location['location_properties']['max_capacity']; ?>" size="40">
<br><?php esc_html_e( "If setting the max capacity to something else than 0, then - for all events that are happening at the same time at this location - a check will be done to see if the location still allows extra people inside.", 'events-made-easy' ); ?>
</td>
</tr></table>
</div>
</div>
<?php
}
function eme_meta_box_div_location_notes( $location ) {
?>
<div class="postbox" id="loc_description">
<h3>
<?php esc_html_e( 'Location description', 'events-made-easy' ); ?>
</h3>
<div class="inside">
<div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>" class="postarea">
<?php
eme_wysiwyg_textarea( 'location_description', $location['location_description'], 1, 1 );
if ( current_user_can( 'unfiltered_html' ) ) {
echo "<div class='eme_notice_unfiltered_html'>";
esc_html_e( 'Your account has the ability to post unrestricted HTML content here, except javascript.', 'events-made-easy' );
echo '</div>';
}
?>
</div>
<?php esc_html_e( 'A description of the location. You may include any kind of info here.', 'events-made-easy' ); ?>
<br>
</div>
</div>
<?php
}
function eme_meta_box_div_location_image( $location ) {
if ( ! empty( $location['location_image_id'] ) ) {
$location['location_image_url'] = esc_url( wp_get_attachment_image_url( $location['location_image_id'], 'full' ) );
}
?>
<div id="div_location_image" class="postbox">
<h3>
<?php esc_html_e( 'Location image', 'events-made-easy' ); ?>
</h3>
<div id="location_current_image_inside" class="inside">
<?php
if ( ! empty( $location['location_image_url'] ) ) {
echo "<img id='eme_location_image_example' alt='" . esc_attr__( 'Location image', 'events-made-easy' ) . "' src='" . $location['location_image_url'] . "' width='200'>";
echo "<input type='hidden' name='location_image_url' id='location_image_url' value='" . $location['location_image_url'] . "'>";
} else {
# to prevent html validation errors, use a transparent small pixel
echo "<img id='eme_location_image_example' alt='" . esc_attr__( 'Location image', 'events-made-easy' ) . "' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNgYAAAAAMAASsJTYQAAAAASUVORK5CYII=' width='200'>";
echo "<input type='hidden' name='location_image_url' id='location_image_url'>";
}
if ( ! empty( $location['location_image_id'] ) ) {
echo "<input type='hidden' name='location_image_id' id='location_image_id' value='" . $location['location_image_id'] . "'>";
} else {
echo "<input type='hidden' name='location_image_id' id='location_image_id'>";
}
?>
<div class="uploader">
<input type="button" name="location_image_button" id="location_image_button" value="<?php esc_attr_e( 'Set a featured image', 'events-made-easy' ); ?>" class="button-secondary action">
<input type="button" id="location_remove_image_button" name="location_remove_image_button" value=" <?php esc_attr_e( 'Unset featured image', 'events-made-easy' ); ?>" class="button-secondary action">
</div>
</div>
</div>
<?php
}
function eme_meta_box_div_location_url( $location ) {
$eme_loc_prop_online_only_checked = ( $location['location_properties']['online_only'] ) ? "checked='checked'" : '';
?>
<div id="div_location_url" class="postbox">
<h3>
<?php esc_html_e( 'External info', 'events-made-easy' ); ?>
</h3>
<div id="div_location_url_inside" class="inside">
<table>
<tr>
<td><label for="location_url"><?php esc_html_e( 'External URL', 'events-made-easy' ); ?></label></td>
<td><input id="location_url" name="location_url" type="text" value="<?php echo eme_esc_html( $location['location_url'] ); ?>" size="40">
</td>
</tr>
<tr>
<td><label for="eme_loc_prop_online_only"><?php esc_html_e( 'Only online location', 'events-made-easy' ); ?></label></td>
<td><input id="eme_loc_prop_online_only" name='eme_loc_prop_online_only' value='1' type='checkbox' <?php echo $eme_loc_prop_online_only_checked; ?>>
<br><span class="eme_smaller"><?php esc_html_e( 'Check this is the location is purely virtual (like a meeting url or so).', 'events-made-easy' ); ?></span>
</td>
</tr>
</table>
</div>
</div>
<?php
}
function eme_meta_box_div_location_attributes( $location ) {
?>
<div id="div_location_attributes">
<br>
<?php
echo '<b>' . esc_html__( 'Attributes', 'events-made-easy' ) . '</b>';
?>
<?php
eme_attributes_form( $location );
?>
</div>
<?php
}
function eme_meta_box_div_location_customfields( $location ) {
$formfields = eme_get_formfields( '', 'locations' );
$formfields = apply_filters( 'eme_location_formfields', $formfields );
?>
<div id="div_location_customfields">
<br><b> <?php esc_html_e( 'Custom fields', 'events-made-easy' ); ?> </b>
<p><?php esc_html_e( "Here custom fields of type 'locations' are shown.", 'events-made-easy' ); ?>
<br><?php esc_html_e( 'The difference with location attributes is that attributes need to be defined in your format first and can only be text, here you can first create custom fields of any kind which allows more freedom.', 'events-made-easy' ); ?>
</p>
<?php
if ( current_user_can( 'unfiltered_html' ) && !empty($formfields) ) {
echo "<div class='eme_notice_unfiltered_html'>";
esc_html_e( 'Your account has the ability to post unrestricted HTML content here, except javascript.', 'events-made-easy' );
echo '</div>';
}
?>
<table style="width: 100%;">
<?php
// only in case of location duplicate, the cf_answers is set
if ( isset( $location['cf_answers'] ) ) {
$answers = $location['cf_answers'];
$files = [];
} elseif ( ! empty( $location['location_id'] ) ) {
$answers = eme_get_location_answers( $location['location_id'] );
$files = eme_get_uploaded_files( $location['location_id'], 'locations' );
} else {
$answers = [];
$files = [];
}
foreach ( $formfields as $formfield ) {
$field_name = eme_trans_esc_html( $formfield['field_name'] );
$field_id = $formfield['field_id'];
$postfield_name = 'FIELD' . $field_id;
$entered_val = '';
foreach ( $answers as $answer ) {
if ( $answer['field_id'] == $field_id ) {
$entered_val = $answer['answer'];
}
}
if ( $formfield['field_type'] == 'file' || $formfield['field_type'] == 'multifile' ) {
$entered_files = [];
foreach ( $files as $file ) {
if ( $file['field_id'] == $field_id ) {
$entered_files[] = $file;
}
}
$entered_val = $entered_files;
}
if ( $formfield['field_required'] ) {
$required = 1;
} else {
$required = 0;
}
if ( $formfield['field_type'] == 'hidden' ) {
$field_html = __( "Custom fields of type 'hidden' are useless here and of course won't be shown.", 'events-made-easy' );
} else {
$field_html = eme_get_formfield_html( $formfield, $postfield_name, $entered_val, $required );
}
echo "<tr><td>$field_name</td><td style='width: 100%;'>$field_html</td></tr>";
}
?>
</table>
</div>
<?php
}
function eme_locations_table( $message = '' ) {
$nonce_field = wp_nonce_field( 'eme_admin', 'eme_admin_nonce', false, false );
?>
<div class="wrap nosubsub">
<div id="poststuff">
<div id="icon-edit" class="icon32">
</div>
<?php if ( current_user_can( get_option( 'eme_cap_add_locations' ) ) ) : ?>
<h1><?php esc_html_e( 'Add a new location', 'events-made-easy' ); ?></h1>
<div class="wrap">
<form id="locations-filter" method="post" action="<?php echo admin_url( 'admin.php?page=eme-locations' ); ?>">
<?php echo $nonce_field; ?>
<input type="hidden" name="eme_admin_action" value="add_location">
<input type="submit" class="button-primary" name="submit" value="<?php esc_html_e( 'Add location', 'events-made-easy' ); ?>">
</form>
</div>
<?php endif; ?>
<h1><?php esc_html_e( 'Manage locations', 'events-made-easy' ); ?></h1>
<?php if ( $message != '' ) { ?>
<div id="message" class="updated notice notice-success is-dismissible">
<p><?php echo $message; ?></p>
</div>
<?php } ?>
<?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='location-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=',' required='required'>
<?php esc_html_e( 'Enclosure:', 'events-made-easy' ); ?>
<input required="required" type="text" size=1 maxlength=1 name="enclosure" value='"' required='required'>
<input type="hidden" name="eme_admin_action" value="import_locations">
<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 locations into the database', 'events-made-easy' ); ?>
</form>
</div>
<?php } ?>
<br>
<form action="#" method="post">
<input type="text" class="clearable" name="search_name" id="search_name" placeholder="<?php esc_attr_e( 'Location name', 'events-made-easy' ); ?>" size=10>
<?php
$formfields_searchable = eme_get_searchable_formfields( 'locations' );
if ( ! empty( $formfields_searchable ) ) {
echo '<input type="text" class="clearable" name="search_customfields" id="search_customfields" placeholder="' . esc_attr__( 'Custom field value to search', 'events-made-easy' ) . '" size=20>';
$label = __( 'Custom fields to filter on', 'events-made-easy' );
$extra_attributes = 'aria-label="' . eme_esc_html( $label ) . '" data-placeholder="' . eme_esc_html( $label ) . '"';
echo eme_ui_multiselect_key_value( '', 'search_customfieldids', $formfields_searchable, 'field_id', 'field_name', 5, $label, 0, 'eme_select2', $extra_attributes, 1 );
}
?>
<button id="LocationsLoadRecordsButton" class="button-secondary action"><?php esc_html_e( 'Filter location', 'events-made-easy' ); ?></button>
<?php
if ( ! empty( $formfields_searchable ) ) {
?>
<div id="hint">
<?php esc_html_e( 'Hint: when searching for custom field values, you can optionally limit which custom fields you want to search in the "Custom fields to filter on" select-box shown.', 'events-made-easy' ); ?><br>
<?php esc_html_e( 'If you can\'t see your custom field in the "Custom fields to filter on" select-box, make sure you marked it as "searchable" in the field definition.', 'events-made-easy' ); ?>
</div>
<?php
}
?>
</form>
<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="deleteLocations"><?php esc_html_e( 'Delete selected locations', 'events-made-easy' ); ?></option>
</select>
<span id="span_transferto" class="eme-hidden">
<?php esc_html_e( 'Transfer associated events to (leave empty to delete the location info for those events):', 'events-made-easy' ); ?>
<input type='hidden' id='transferto_id' name='transferto_id'>
<input type='text' id='chooselocation' name='chooselocation' placeholder="<?php esc_attr_e( 'Start typing a name', 'events-made-easy' ); ?>">
</span>
<button id="LocationsActionsButton" 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>
<?php
$formfields = eme_get_formfields( '', 'locations' );
$extrafields_arr = [];
$extrafieldnames_arr = [];
$extrafieldsearchable_arr = [];
foreach ( $formfields as $formfield ) {
$extrafields_arr[] = $formfield['field_id'];
$extrafieldnames_arr[] = eme_trans_esc_html( $formfield['field_name'] );
$extrafieldsearchable_arr[] = $formfield['searchable'];
}
// these 2 values are used as data-fields to the container-div, and are used by the js to create extra columns
$extrafields = join( ',', $extrafields_arr );
$extrafieldnames = join( ',', $extrafieldnames_arr );
$extrafieldsearchable = join( ',', $extrafieldsearchable_arr );
?>
<div id="LocationsTableContainer" data-extrafields='<?php echo $extrafields; ?>' data-extrafieldnames='<?php echo $extrafieldnames; ?>' data-extrafieldsearchable='<?php echo $extrafieldsearchable; ?>' ></div>
</form>
</div>
</div>
<?php
}
function eme_search_locations( $name ) {
global $wpdb;
$table = EME_DB_PREFIX . EME_LOCATIONS_TBNAME;
$query = "SELECT * FROM $table WHERE (location_name LIKE %s) OR
(location_description LIKE %s) ORDER BY location_name";
$sql = $wpdb->prepare( $query, '%'.$wpdb->esc_like($name).'%', '%'.$wpdb->esc_like($name).'%' );
return $wpdb->get_results( $sql, ARRAY_A );
}
// this returns all locations, can be useful in dropdown for location selects
function eme_get_all_locations() {
global $wpdb;
$locations_table = EME_DB_PREFIX . EME_LOCATIONS_TBNAME;
$sql = "SELECT * FROM $locations_table WHERE location_name != '' ORDER BY location_name";
$locations = $wpdb->get_results( $sql, ARRAY_A );
foreach ( $locations as $key => $location ) {
$locations[ $key ] = eme_get_extra_location_data( $location );
}
if ( has_filter( 'eme_location_list_filter' ) ) {
$locations = apply_filters( 'eme_location_list_filter', $locations );
}
return $locations;
}
function eme_get_locations_by_distance( $longitude, $latitude, $distance, $location_ids_only ) {
global $wpdb;
$locations_table = EME_DB_PREFIX . EME_LOCATIONS_TBNAME;
if ( $location_ids_only ) {
$sql = $wpdb->prepare( "SELECT location_id FROM $locations_table WHERE ST_Distance_Sphere(point(%f,%f),point(location_longitude,location_latitude)) < %d", $longitude, $latitude, $distance );
$locations = $wpdb->get_col( $sql );
} else {
$sql = $wpdb->prepare( "SELECT *, ST_Distance_Sphere(point(%f,%f),point(location_longitude,location_latitude)) AS distance_meters FROM $locations_table HAVING distance_meters < %d ORDER BY distance_meters,location_name", $longitude, $latitude, $distance );
$locations = $wpdb->get_results( $sql, ARRAY_A );
foreach ( $locations as $key => $location ) {
$locations[ $key ] = eme_get_extra_location_data( $location );
}
if ( has_filter( 'eme_location_list_filter' ) ) {
$locations = apply_filters( 'eme_location_list_filter', $locations );
}
}
return $locations;
}
function eme_get_locations( $eventful = false, $scope = 'all', $category = '', $notcategory = '', $limit = 0, $ignore_filter = false, $random_order = false, $author = '', $contact_person = '' ) {
global $wpdb;
$locations_table = EME_DB_PREFIX . EME_LOCATIONS_TBNAME;
$locations = [];
$location_id_arr = [];
$location_id = '';
// 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_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'] );