-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.php
More file actions
2220 lines (2130 loc) · 133 KB
/
index.php
File metadata and controls
2220 lines (2130 loc) · 133 KB
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
/*
This is the main page of FreeField. It contains the map that the whole
project revolves around.
*/
/*
Disable all caching.
*/
header("Expires: ".date("r", 0));
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
/*
Ensure that the configuration file exists. If not, proceed to site setup.
*/
if (!file_exists(__DIR__."/includes/userdata/config.json")) {
header("HTTP/1.1 303 See Other");
header("Location: ./admin/install-wizard.php");
exit;
}
require_once("./includes/lib/global.php");
__require("config");
/*
Check if updates have been pulled directly from Git. Normally when updates
are installed, `PostUpgrade::finalizeUpgrade()` will perform checks on the
configuration file to ensure that it is compatible with the currently
installed version. If the source is pulled from Git, this check won't be
performed. To properly handle this case, the upgrade script in `PostUpgrade`
will write the version that the configuration file is compatible with in the
configuration file itself. If this page is visited and the version number
has not been visited, then the `PostUpgrade::finalizeUpgrade()` function has
not been called, thus we should call it.
*/
if (Config::getRaw("install/version-compatible") !== FF_VERSION) {
include("./includes/setup/post-upgrade.php");
PostUpgrade::finalizeUpgrade(
Config::getRaw("install/version-compatible"), true
);
}
__require("auth");
__require("i18n");
__require("security");
__require("update");
Security::requireCSRFToken();
/*
Check for software updates.
*/
if (Auth::getCurrentUser()->hasPermission("admin/updates/general")) {
Update::autoCheckForUpdates();
}
/*
Check if the user currently has access to view the map. If they don't, and
aren't logged in, prompt them to log in. If they are, tell them that they do
not currently have permission to view the map, and prompt them to ask the
admins for access.
*/
if (!Auth::getCurrentUser()->hasPermission("access")) {
if (!Auth::isAuthenticated()) {
header("HTTP/1.1 307 Temporary Redirect");
header("Location: ".Config::getEndpointUri("/auth/login.php"));
exit;
} else {
/*
Execute X-Frame-Options same-origin policy.
*/
Security::declareFrameOptionsHeader();
?>
<!DOCTYPE html>
<html lang="<?php echo htmlspecialchars(I18N::getLanguage(), ENT_QUOTES); ?>">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="<?php echo Config::get("spiders/robots-policy")->valueHTML(); ?>">
<meta name="theme-color" content="<?php echo Config::get("themes/meta/color")->valueHTML(); ?>">
<title><?php echo I18N::resolveArgsHTML(
"page_title.access_denied",
true,
Config::get("site/name")->value()
); ?></title>
<link rel="shortcut icon"
href="./themes/favicon.php?t=<?php
/*
Force refresh the favicon by appending the last
changed time of the file to the path.
https://stackoverflow.com/a/7116701
*/
echo Config::get("themes/meta/favicon")->value()->getUploadTime();
?>">
<link rel="stylesheet"
href="https://unpkg.com/purecss@1.0.0/build/pure-min.css"
integrity="sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w"
crossorigin="anonymous">
<link rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.0.13/css/all.css"
integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp"
crossorigin="anonymous">
<link rel="stylesheet" href="./css/main.css">
<link rel="stylesheet" href="./css/<?php echo Config::get("themes/color/user-settings/theme")->valueHTML(); ?>.css">
<link rel="stylesheet" href="./css/theming.php?<?php echo Config::get("themes/color/user-settings/theme")->valueHTML(); ?>">
<!--[if lte IE 8]>
<link rel="stylesheet" href="./css/layouts/side-menu-old-ie.css">
<![endif]-->
<!--[if gt IE 8]><!-->
<link rel="stylesheet" href="./css/layouts/side-menu.css">
<!--<![endif]-->
</head>
<body>
<div id="main">
<div class="header" style="border-bottom: none; margin-bottom: 50px;">
<h1 class="red"><?php echo I18N::resolveHTML("access_denied.title"); ?></h1>
<h2><?php echo I18N::resolveHTML("access_denied.desc"); ?></h2>
</div>
<div class="content">
<p>
<?php echo I18N::resolveArgsHTML(
"access_denied.info",
true,
Auth::getCurrentUser()->getProviderIdentity()
); ?>
</p>
</div>
</div>
<script src="./js/ui.js"></script>
</body>
</html>
<?php
exit;
}
}
__require("config");
__require("theme");
__require("research");
__require("vendor/parsedown");
/*
A string identifying the chosen map provider for FreeField.
*/
$provider = Config::get("map/provider/source")->value();
/*
Caching tokens. By appending timestamps to the end of URLs of content that
can change often in development, we ensure that the content is cached, while
at the same ensuring that it is up to date when used by the browser.
*/
$linkMod = array(
"/css/main.css" => filemtime("./css/main.css"),
"/css/dark.css" => filemtime("./css/dark.css"),
"/css/light.css" => filemtime("./css/light.css"),
"/js/ie-polyfill.js" => filemtime("./js/ie-polyfill.js"),
"/js/main.js" => filemtime("./js/main.js"),
"/js/option.js" => filemtime("./js/option.js"),
"/pwa/register-sw.js" => filemtime("./pwa/register-sw.js")
);
/*
Execute X-Frame-Options same-origin policy.
*/
Security::declareFrameOptionsHeader();
?>
<!DOCTYPE html>
<html lang="<?php echo htmlspecialchars(I18N::getLanguage(), ENT_QUOTES); ?>">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="robots" content="<?php echo Config::get("spiders/robots-policy")->valueHTML(); ?>">
<meta name="theme-color" content="<?php echo Config::get("themes/meta/color")->valueHTML(); ?>">
<title><?php echo I18N::resolveArgsHTML(
"page_title.main",
true,
Config::get("site/name")->value()
); ?></title>
<?php if (preg_match('/(MSIE|Trident)/', $_SERVER['HTTP_USER_AGENT'])) { ?>
<!--
Internet Explorer requires loading polyfills for certain
JavaScript functionality such as `String.prototype.startsWith()`
since it does not support ECMAScript 6.
-->
<script src="./js/ie-polyfill.js?t=<?php echo $linkMod["/js/ie-polyfill.js"]; ?>"></script>
<?php } ?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="./js/clientside-i18n.php" async defer></script>
<script>
/*
Display options for `IconSetOptionBase` selectors; required by
the `IconSetOption` event handler in /js/option.js.
*/
var isc_opts = <?php
echo json_encode(array(
"icons" => array(
"themedata" => IconSetOption::getIconSetDefinitions(),
"icons" => Theme::listIcons(),
"baseuri" => Config::getEndpointUri("/"),
"colortheme" => Config::get("themes/color/user-settings/theme")->value()
),
"species" => array(
"themedata" => SpeciesSetOption::getIconSetDefinitions(),
"highest" => ParamSpecies::getHighestSpecies(),
"baseuri" => Config::getEndpointUri("/"),
"colortheme" => Config::get("themes/color/user-settings/theme")->value()
)
));
?>;
/*
Determine if user is signed in or not.
*/
function isAuthenticated() {
return <?php echo Auth::isAuthenticated() ? "true" : "false"; ?>;
}
</script>
<script src="./js/option.js?t=<?php echo $linkMod["/js/option.js"]; ?>" async defer></script>
<link rel="shortcut icon"
href="./themes/favicon.php?t=<?php
/*
Force refresh the favicon by appending the last changed time
of the file to the path. https://stackoverflow.com/a/7116701
*/
echo Config::get("themes/meta/favicon")->value()->getUploadTime();
?>">
<style>
body {
background-color: #111;
}
</style>
<?php
/*
Load the map provider stylesheep for the chosen map provider.
*/
switch (Config::get("map/provider/source")->value()) {
case "mapbox":
?>
<link rel="stylesheet"
href="https://api.mapbox.com/mapbox-gl-js/v0.46.0/mapbox-gl.css"
media="none"
onload="if(media!=='all')media='all'">
<?php
break;
case "thunderforest":
?>
<link rel="stylesheet"
href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css"
integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA=="
crossorigin=""
onload="if(media!=='all')media='all'">
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/leaflet.locatecontrol@0.63.0/dist/L.Control.Locate.min.css"
integrity="sha256-mvCapu8voeqbM31gwIzYjSiq79jiT4LdIEQSmjyRNoE="
crossorigin="anonymous"
onload="if(media!=='all')media='all'">
<?php
break;
}
?>
<link rel="stylesheet"
href="https://unpkg.com/purecss@1.0.0/build/pure-min.css"
integrity="sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w"
crossorigin="anonymous">
<link rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.8.2/css/all.css"
integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay"
crossorigin="anonymous"
media="none" onload="if(media!=='all')media='all'">
<link rel="stylesheet"
href="./css/main.css?t=<?php echo $linkMod["/css/main.css"]; ?>">
<link rel="preload"
href="./css/dark.css?t=<?php echo $linkMod["/css/dark.css"]; ?>"
as="style">
<link rel="preload"
href="./css/light.css?t=<?php echo $linkMod["/css/light.css"]; ?>"
as="style">
<link rel="stylesheet" href="./css/map-markers.php"
media="none"
onload="if(media!=='all')media='all'">
<!--
Preload the default theme colors; this will be overridden once the
page has finished loading depending on the color theme the user has
chosen.
-->
<link rel="stylesheet"
href="./css/theming.php?<?php echo Config::get("themes/color/user-settings/theme")->valueHTML(); ?>">
<?php
if (Config::get("mobile/pwa/enabled")->value()) {
?>
<link rel="manifest" href="./pwa/manifest.php">
<script src="./pwa/register-sw.js?t=<?php echo $linkMod["/pwa/register-sw.js"]; ?>"
async defer></script>
<?php
}
?>
<!--[if lte IE 8]>
<link rel="stylesheet" href="./css/layouts/side-menu-old-ie.css">
<![endif]-->
<!--[if gt IE 8]><!-->
<link rel="stylesheet" href="./css/layouts/side-menu.css">
<!--<![endif]-->
</head>
<body>
<div id="layout">
<!-- Menu toggle -->
<a href="#menu" id="menuLink" class="menu-link">
<!-- Hamburger icon -->
<span></span>
</a>
<div id="corner-filter-link" class="filter-overlay-icon">
<!-- Filter icon when active -->
<i class="fas fa-filter"></i>
</div>
<div id="menu">
<div class="pure-menu">
<a class="pure-menu-heading" href=".."<?php
if (Config::get("site/header-style")->value() == "image-plain")
echo ' style="background: none !important; padding-bottom: 0;"';
?>>
<?php
switch (Config::get("site/header-style")->value()) {
case "text":
echo Config::get("site/menu-header")->valueHTML();
break;
case "image":
case "image-plain":
echo '<img src="./themes/sidebar-image.php">';
break;
}
?>
</a>
<?php if (Auth::isAuthenticated()) { ?>
<div class="menu-user-box">
<span class="user-box-small">
<?php echo I18N::resolveHTML("sidebar.signed_in_as"); ?>
</span><br>
<span class="user-box-nick">
<?php echo Auth::getCurrentUser()->getNicknameHTML(); ?>
</span><br>
<span class="user-box-small">
<?php echo Auth::getCurrentUser()->getProviderIdentityHTML(); ?>
</span><br>
<?php
if (!Auth::getCurrentUser()->isApproved()) {
?>
<span class="user-box-small red">
<?php echo I18N::resolveHTML("sidebar.approval_pending"); ?>
</span>
<?php
}
?>
</div>
<ul class="pure-menu-list">
<li class="pure-menu-item">
<a href="./auth/logout.php?<?php echo Security::getCSRFUrlParameter(); ?>"
class="pure-menu-link">
<i class="menu-fas fas fa-sign-in-alt"></i>
<?php echo I18N::resolveHTML("sidebar.logout"); ?>
</a>
</li>
</ul>
<?php } else { ?>
<ul class="pure-menu-list">
<li class="pure-menu-item">
<a href="./auth/login.php" class="pure-menu-link">
<i class="menu-fas fas fa-sign-in-alt"></i>
<?php echo I18N::resolveHTML("sidebar.login"); ?>
</a>
</li>
</ul>
<?php } ?>
<div class="menu-spacer"></div>
<ul id="map-menu" class="pure-menu-list">
<?php if (Auth::getCurrentUser()->hasPermission("submit-poi")) { ?>
<li class="pure-menu-item">
<a href="#" id="add-poi-start" class="pure-menu-link">
<i class="menu-fas fas fa-plus"></i>
<?php echo I18N::resolveHTML("sidebar.add_poi"); ?>
</a>
</li>
<?php } ?>
<li class="pure-menu-item">
<a href="#" id="menu-open-search" class="pure-menu-link">
<i class="menu-fas fas fa-search"></i>
<?php echo I18N::resolveHTML("sidebar.search"); ?>
</a>
</li>
<li class="pure-menu-item">
<a href="#" id="menu-open-filters" class="pure-menu-link">
<i class="menu-fas fas fa-filter"></i>
<?php echo I18N::resolveHTML("sidebar.filters"); ?>
</a>
</li>
<li class="pure-menu-item">
<a href="#" id="menu-open-settings" class="pure-menu-link">
<i class="menu-fas fas fa-wrench"></i>
<?php echo I18N::resolveHTML("sidebar.settings"); ?>
</a>
</li>
<?php
/* Check if user has permission to access any admin pages. */
if (Auth::getCurrentUser()->canAccessAdminPages()) {
?>
<li class="pure-menu-item">
<a href="./admin/" class="pure-menu-link<?php
/*
Highlight "Manage site" link if
an update is available and the
current user has permission to
update FreeField.
*/
if (
Auth::getCurrentUser()->hasPermission(
"admin/updates/general"
) &&
Update::autoIsUpdateAvailable()
) {
echo " menu-update-available";
}
?>">
<i class="menu-fas fas fa-angle-double-right"></i>
<?php echo I18N::resolveHTML("sidebar.manage_site"); ?>
</a>
</li>
<?php
}
?>
<?php
/* Check if the "Show MotD" button should be displayed. */
if (Config::get("motd/display-mode")->value() !== "never") {
?>
<li class="pure-menu-item">
<a href="#" id="motd-open" class="pure-menu-link">
<i class="menu-fas fas fa-bell"></i>
<?php echo I18N::resolveHTML("sidebar.show_motd"); ?>
</a>
</li>
<?php
}
?>
</ul>
<ul id="settings-menu" class="pure-menu-list hidden-by-default">
<li class="pure-menu-item">
<a href="#" id="menu-reset-settings" class="pure-menu-link">
<i class="menu-fas fas fa-undo"></i>
<?php echo I18N::resolveHTML("sidebar.reset"); ?>
</a>
</li>
<li class="pure-menu-item">
<a href="#" id="menu-close-settings" class="pure-menu-link">
<i class="menu-fas fas fa-angle-double-left"></i>
<?php echo I18N::resolveHTML("sidebar.cancel"); ?>
</a>
</li>
</ul>
<div class="menu-about-box">
<p>
<i class="fas fa-globe-americas"></i>
<?php echo I18N::resolveHTML("sidebar.language.label"); ?>
</p>
<p><select id="menu-language-select">
<optgroup label="<?php echo I18N::resolveHTML("sidebar.language.auto"); ?>">
<option value="">
<?php echo I18N::resolveHTML("sidebar.language.device"); ?>
</option>
</optgroup>
<optgroup label="<?php echo I18N::resolveHTML("sidebar.language.select"); ?>">
<?php
$curlang = !isset($_COOKIE["language"]) ? "" : $_COOKIE["language"];
$langs = I18N::getAvailableLanguagesWithNames();
foreach ($langs as $code => $name) {
?>
<option value="<?php echo $code; ?>"<?php if ($code == $curlang) echo " selected"; ?>>
<?php echo $name; ?>
</option>
<?php
}
?>
</optgroup>
</select></p>
<p>
<a href="https://github.com/bilde2910/FreeField" target="_blank">FreeField</a>
v<?php
/*
The sidebar is narrow, so we'll replace
release tags with shorter versions to fit
everything on one line.
*/
echo
str_replace("-alpha.", "-a",
str_replace("-beta.", "-b",
str_replace("-rc.", "-rc",
FF_VERSION
)));
?>
</p>
</div>
</div>
</div>
<div id="main">
<div id="map-container">
<!--
The banner container. Banners created by `spawnBanner()`
in /js/main.js are added here.
-->
<div id="dynamic-banner-container">
</div>
<!--
A special banner that shows up when the user is asked to
click on the map to select the location for a new POI.
-->
<div id="add-poi-banner" class="banner">
<div class="banner-inner">
<?php echo I18N::resolveArgsHTML(
"poi.add.instructions",
false,
'<a href="#" id="add-poi-cancel-banner">',
'</a>'
); ?>
</div>
</div>
<!--
A special banner that shows up when the user is asked to
click on the map to select a new location for a POI.
-->
<div id="move-poi-banner" class="banner">
<div class="banner-inner">
<?php echo I18N::resolveArgsHTML(
"poi.move.instructions",
false,
'<a href="#" id="move-poi-cancel-banner">',
'</a>'
); ?>
</div>
</div>
<!--
A banner that appears at the top of the map if the
amount of POIs within the map's bounding box exceeds the
amount that should reasonably be displayed at the same
time as requested by the user.
-->
<div id="clustering-active-banner" class="top-banner">
<div class="triangle triangle-left"></div>
<a href="https://freefield.readthedocs.io/en/latest/faq.html#why-are-some-markers-hidden-from-the-map"
target="_blank">
<div class="top-banner-inner">
<?php echo I18N::resolveArgsHTML(
"clustering.banner",
false,
'<span id="clustering-active-count"></span>',
'<span id="clustering-active-total"></span>',
'<i class="fas fa-eye-slash"></i>'
); ?>
</div>
</a>
<div class="triangle triangle-right"></div>
</div>
<!--
POI details overlay. Contains details such as the POI's
name, its current active field research, means of
reporting research to the POI (if permission is granted
to do so), and a button to get directions to the POI on
a turn-based navigation service. The overlay is opened
whenever the user clicks on a marker on the map.
-->
<div id="poi-details" class="cover-box">
<div class="cover-box-inner">
<div class="header">
<h1 id="poi-name" class="head-small"></h1>
</div>
<div class="cover-box-content content">
<div class="pure-g">
<div class="pure-u-1-2 right-align">
<img id="poi-objective-icon" src="about:blank" class="bigmarker">
</div>
<div class="pure-u-1-2">
<img id="poi-reward-icon" src="about:blank" class="bigmarker">
</div>
</div>
<p class="centered">
<?php echo I18N::resolveArgsHTML(
"poi.objective_text",
false,
'<strong id="poi-objective" class="strong-color"></strong>',
'<strong id="poi-reward" class="strong-color"></strong>'
); ?>
</p>
<p class="centered">
<span id="poi-last-time"></span>
<span id="poi-last-user-box">
<br />
<span id="poi-last-user-text"></span>
</span>
</p>
<div class="cover-button-spacer"></div>
<div class="pure-g">
<div class="pure-u-1-1 right-align">
<span id="poi-add-report"
class="button-standard split-button">
<?php echo I18N::resolveHTML("poi.report_research"); ?>
</span>
</div>
</div>
<?php
if (Auth::getCurrentUser()->hasPermission("admin/pois/general")) {
/*
Buttons for moving and deleting POIs.
*/
?>
<div class="pure-g">
<div class="pure-u-1-4 right-align">
<span id="poi-move"
class="button-standard split-button button-spaced left fas fa-arrows-alt"
title="<?php echo I18N::resolveHTML("poi.move"); ?>">
</span>
</div>
<div class="pure-u-1-4">
<span id="poi-rename"
class="button-standard split-button button-spaced fas fa-tag"
title="<?php echo I18N::resolveHTML("poi.rename"); ?>">
</span>
</div>
<div class="pure-u-1-4">
<span id="poi-clear"
class="button-standard split-button button-spaced fas fa-broom"
title="<?php echo I18N::resolveHTML("poi.clear"); ?>">
</span>
</div>
<div class="pure-u-1-4">
<span id="poi-delete"
class="button-standard split-button button-spaced right fas fa-trash-alt"
title="<?php echo I18N::resolveHTML("poi.delete"); ?>">
</span>
</div>
</div>
<?php
}
?>
<div class="pure-g">
<div class="pure-u-1-2 right-align">
<span id="poi-directions"
class="button-standard split-button button-spaced left">
<?php echo I18N::resolveHTML("poi.directions"); ?>
</span>
</div>
<div class="pure-u-1-2">
<span id="poi-close"
class="button-standard split-button button-spaced right">
<?php echo I18N::resolveHTML("ui.button.close"); ?>
</span>
</div>
</div>
</div>
</div>
</div>
<!--
New POI overlay that's shown when the user is adding a
new POI to the map, and they have clicked on the
location on the map where they wish the new POI to be
added. The overlay dialog asks for the name of the POI
to be added, and confirms its coordinates.
-->
<div id="add-poi-details" class="cover-box">
<div class="cover-box-inner">
<div class="header">
<h1><?php echo I18N::resolveHTML("poi.add.title"); ?></h1>
</div>
<div class="cover-box-content content pure-form">
<div class="pure-g">
<div class="pure-u-1-3 full-on-mobile">
<p><?php echo I18N::resolveHTML("poi.add.name"); ?>:</p>
</div>
<div class="pure-u-2-3 full-on-mobile">
<p><input type="text" id="add-poi-name"></p>
</div>
</div>
<div class="pure-g">
<div class="pure-u-1-3 full-on-mobile">
<p><?php echo I18N::resolveHTML("poi.add.latitude"); ?>:</p>
</div>
<div class="pure-u-2-3 full-on-mobile">
<p><input type="text" id="add-poi-lat" readonly></p>
</div>
</div>
<div class="pure-g">
<div class="pure-u-1-3 full-on-mobile">
<p><?php echo I18N::resolveHTML("poi.add.longitude"); ?>:</p>
</div>
<div class="pure-u-2-3 full-on-mobile">
<p><input type="text" id="add-poi-lon" readonly></p>
</div>
</div>
<div class="cover-button-spacer"></div>
<div class="pure-g">
<div class="pure-u-1-2 right-align">
<span id="add-poi-cancel"
class="button-standard split-button button-spaced left">
<?php echo I18N::resolveHTML("ui.button.cancel"); ?>
</span>
</div>
<div class="pure-u-1-2">
<span id="add-poi-submit"
class="button-submit split-button button-spaced right">
<?php echo I18N::resolveHTML("poi.add.submit"); ?>
</span>
</div>
</div>
</div>
</div>
</div>
<!--
Field research reporting dialog. If a user wishes to
report field research on a POI, this dialog shows up. It
prompts the user for the type of objective and reward
that constitutes the research task, and requests
objective and reward metadata (parameters, such as a
quantity of typing) as well, if applicable.
-->
<div id="update-poi-details" class="cover-box">
<div class="cover-box-inner">
<div class="header">
<h1>
<?php echo I18N::resolveHTML("poi.update.title"); ?>
</h1>
</div>
<div class="cover-box-content content pure-form">
<div class="pure-g">
<div class="pure-u-1-3 full-on-mobile">
<p><?php echo I18N::resolveHTML("poi.update.name"); ?>:</p>
</div>
<div class="pure-u-2-3 full-on-mobile">
<p><input type="text" id="update-poi-name" readonly></p>
</div>
</div>
<h2><?php echo I18N::resolveHTML("poi.update.objective"); ?></h2>
<div class="pure-g">
<div class="pure-u-5-5 full-on-mobile"><p><select id="update-poi-objective">
<?php
/*
Select box that contains a list of all possible research objectives.
*/
// Sorts objectives and rewards alphabetically according to their translated strings.
/*function sortByI18N($a, $b) {
return strcmp($a["i18n"], $b["i18n"]);
}*/
/*
First, get a list of all current research objectives.
*/
$commonObjectives = Research::listCommonObjectives();
/*
Resolve their display text.
*/
$commonObjectivesText = array();
for ($i = 0; $i < count($commonObjectives); $i++) {
$commonObjectivesText[$i] = htmlspecialchars(
Research::resolveObjective(
$commonObjectives[$i]["type"],
$commonObjectives[$i]["params"]
)
);
}
/*
Sort them alphabetically.
*/
asort($commonObjectivesText);
/*
Echo them to the page in a "Current objectives" optgroup.
*/
echo '<optgroup label="'.I18N::resolveHTML("category.objective.current").'">';
foreach ($commonObjectivesText as $index => $task) {
echo '<option value="_c_'.$index.'">'.$task.'</option>';
}
echo '</optgroup>';
/*
Now move on to the generic research objectives.
We'll sort the research objectives by their first respective categories.
Put all the research objectives into an array ($cats) of the structure
$cats[CATEGORY][RESEARCH OBJECTIVE][PARAMETERS ETC.]
*/
$cats = array();
foreach (Research::listObjectives() as $objective => $data) {
// Skip unknown since it shouldn't be displayed
if ($objective === "unknown") continue;
$cats[$data["categories"][0]][$objective] = $data;
}
/*
After the objectives have been sorted into proper categories, we'll resolve
the I18N string for each research objective, one category at a time.
*/
foreach ($cats as $category => $categorizedObjectives) {
foreach ($categorizedObjectives as $objective => $data) {
// Use the plural string of the objective by default
$i18n = I18N::resolve("objective.{$objective}.plural");
// If the objective is singular-only, use the singular string
if (!in_array("quantity", $data["params"]))
$i18n = I18N::resolve("objective.{$objective}.singular");
// Replace parameters (e.g. {%1}) with placeholders
for ($i = 0; $i < count($data["params"]); $i++) {
$i18n = str_replace(
"{%".($i+1)."}",
I18N::resolve("parameter.".$data["params"][$i].".placeholder"),
$i18n
);
}
// Now save the final localized string back into the objective
$categorizedObjectives[$objective]["i18n"] = htmlspecialchars($i18n, ENT_QUOTES);
}
//uasort($categorizedObjectives, "sortByI18N");
/*
Create a group for each category of objectives, then output each of the
objectives within that category to the selection box.
*/
echo '<optgroup label="'.I18N::resolveHTML("category.objective.{$category}").'">';
foreach ($categorizedObjectives as $objective => $data) {
echo '<option value="'.$objective.'">'.$data["i18n"].'</option>';
}
echo '</optgroup>';
}
/*
$objectives = Research::listObjectives();
foreach ($objectives as $objective => $data) {
if ($objective === "unknown") continue;
$objectives[$objective]["i18n"] = I18N::resolve("objective.{$objective}.plural");
}
uasort($objectives, "sortByI18N");
foreach ($objectives as $objective => $data) {
if ($objective === "unknown") continue;
$text = I18N::resolve("objective.{$objective}.plural");
echo '<option value="'.$objective.'">'.$text.'</option>';
}
*/
?>
</select></p></div>
</div>
<div class="research-params objective-params">
<?php
/*
Each objective may take one or more parameters. This
part of the script ensures that all possible parameters
have an input box representing them in the dialog.
Parameters which are not in use will be hidden by
default.
*/
foreach (Research::PARAMETERS as $param => $class) {
/*
Each parameter type has a class corresponding to it,
containing functions like value parsing, a function
for returning an HTML node allowing users to set a
value for the parameter, etc. These classes are
listed and defined in
/includes/data/objectives.yaml.
We instantiate an instance of the class for each
parameter so that we can check that the parameter
is valid for objectives, and to get the HTML edit
node for the parameter and output it to the page.
The `html()` function of each parameter class is
used to get this node, so we will call it here.
*/
$inst = new $class();
/*
Each parameter can be used for objectives, rewards,
or both. Ensure that the parameter can be used for
objectives before we output it, to avoid unnecessary
and unused elements on the page.
*/
if (in_array("objectives", $inst->getAvailable())) {
?>
<div id="update-poi-objective-param-<?php echo $param; ?>-box"
class="pure-g research-parameter objective-parameter">
<div class="pure-u-1-3 full-on-mobile">
<p><?php echo I18N::resolveHTML("parameter.{$param}.label"); ?>:</p>
</div>
<div class="pure-u-2-3 full-on-mobile">
<?php echo $inst->html(
"update-poi-objective-param-{$param}-input",
"parameter"
); ?>
</div>
</div>
<?php
}
}
?>
<script>
function getObjectiveParameter(param) {
switch (param) {
<?php
/*
The parameter class also has a JavaScript
function to retrieve the value of the input
box(es) on for the parameter on the page,
and converting them to an object that
represents the parameter and can be stored
in a database or configuration file.
We will output all of these to a JavaScript
function called `getObjectiveParameter()`.
We can then call e.g.
`getObjectiveParameter("type")` and have it
return an object e.g. `["ice", "water"]`,
depending on the data input by the user in
the parameter's input box(es).
The ID of the input box is passed to the
`writeJS()` function so that the function
can extract data from the correct input box.
*/
foreach (Research::PARAMETERS as $param => $class) {
$inst = new $class();
if (in_array("objectives", $inst->getAvailable())) {
echo "case '{$param}':\n";
echo $inst->writeJS("update-poi-objective-param-{$param}-input")."\n";
}
}
?>
}
}
function parseObjectiveParameter(param, data) {
switch (param) {
<?php
/*
The `parseObjectiveParameter()` function
does the exact opposite of
`getObjectiveParameter()` - it takes a data
object, as parsed by the latter function,
and puts its value(s) into the HTML input
box(es) for the parameter on the page,
allowing the user to edit them before being
put back into a modified data object using
`getObjectiveParameter()`.
*/
foreach (Research::PARAMETERS as $param => $class) {
$inst = new $class();
if (in_array("objectives", $inst->getAvailable())) {
echo "case '{$param}':\n";
echo $inst->parseJS("update-poi-objective-param-{$param}-input")."\n";
echo "break;\n";
}
}
?>
}
}
/*
When the objective is changed, the parameters used by
that objective should be displayed, and all others
should be hidden. This handler first ensures that all
parameters are hidden (it loops over the server-side
list of registered parameters and outputs a jQuery
`hide()` statement for each of them), then loops over
the list of parameters accepted by the currently
selected objective and shows them.
*/
$("#update-poi-objective").on("change", function() {
<?php
foreach (Research::PARAMETERS as $param => $class) {
$inst = new $class();
if (in_array("objectives", $inst->getAvailable())) {
echo "$('#update-poi-objective-param-{$param}-box').hide();";
}
}
?>
/*
Determine whether the user selected a predefined
common objective.
*/
var selectedObjective = $("#update-poi-objective").val();
if (selectedObjective.startsWith("_c_")) {
/*
If they did, there is no need to display the
parameter input boxes. We can just put the
values for the parameters in directly, as the
parameters are defined in `commonObjectives`.