-
Notifications
You must be signed in to change notification settings - Fork 0
/
pollenDatabase.php
executable file
·1539 lines (1321 loc) · 64.6 KB
/
pollenDatabase.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
# Class to display information in the virtualShackleton database
class pollenDatabase extends frontControllerApplication
{
# Function to assign defaults additional to the general application defaults
public function defaults ()
{
# Specify available arguments as defaults or as NULL (to represent a required argument)
$defaults = array (
'database' => 'pollen',
'table' => 'pollen',
'databaseStrictWhere' => true,
'nativeTypes' => true,
'administrators' => true,
'div' => 'pollendatabase',
'tabUlClass' => 'tabsflat',
'useEditing' => true,
'mediaDirectory' => $_SERVER['DOCUMENT_ROOT'] . $this->baseUrl . '/media/', # Location of the images directory from the site root
'collectionName' => 'the Collection',
'copyrightOwner' => NULL,
'introductionHtml' => false,
'page404' => 'sitetech/404.html', # Location of 404 page
'imageGenerationStub' => '/images/generator', #!# Need to remove dependency
'width' => 750, // Image width
'maxArticlesPerPage' => 100, // Max articles per page
'helpTab' => true,
'orderby' => array ('genus', 'family', 'species'),
//'externalAuth' => true,
);
# Return the defaults
return $defaults;
}
# Function assign additional actions
public function actions ()
{
# Specify additional actions
$actions = array (
'articles' => array (
'description' => 'List of taxa',
'url' => 'articles/',
'tab' => 'Database',
),
'clear' => array (
'description' => 'Clear search parameters',
'url' => 'clear.html',
'usetab' => false,
),
'dump' => array (
'description' => 'Dump of all articles',
'url' => 'articles/dump.html',
'usetab' => 'Articles',
'authentication' => true,
'administrator' => true,
),
'add' => array (
'description' => 'Add new record',
'url' => 'articles/add.html',
'authentication' => true,
'administrator' => true,
'parent' => 'articles',
'subtab' => 'Add new',
),
'article' => array (
'description' => 'Record: %detail',
'url' => 'articles/%id/',
'parent' => 'articles',
'subtab' => 'View',
),
'edit' => array (
'description' => 'Edit record: %detail',
'url' => 'articles/%id/edit.html',
'usetab' => 'articles',
'authentication' => true,
'administrator' => true,
'parent' => 'articles',
'subtab' => 'Edit',
),
'editmaterial' => array (
'description' => 'Edit material for record: %detail',
'url' => 'articles/%id/editmaterial.html',
'usetab' => 'articles',
'authentication' => true,
'administrator' => true,
'parent' => 'articles',
),
'editmedia' => array (
'description' => 'Edit media for record: %detail',
'url' => 'articles/%id/editmedia.html',
'usetab' => 'articles',
'authentication' => true,
'administrator' => true,
'parent' => 'articles',
),
'addmaterial' => array (
'description' => 'Add material for record: %detail',
'url' => 'articles/%id/addmaterial.html',
'usetab' => 'articles',
'authentication' => true,
'administrator' => true,
'parent' => 'articles',
),
'addmaterialmedia' => array (
'description' => 'Add media for record: %detail for material %material',
'url' => 'articles/%id/addmaterialmedia.html',
'usetab' => 'articles',
'authentication' => true,
'administrator' => true,
'parent' => 'articles',
),
'addmedia' => array (
'description' => 'Add media for record: %detail',
'url' => 'articles/%id/addmedia.html',
'usetab' => 'articles',
'authentication' => true,
'administrator' => true,
'parent' => 'articles',
),
/*
'clone' => array (
'description' => 'Clone record: %detail to new record',
'url' => 'articles/%id/clone.html',
'usetab' => 'articles',
'authentication' => true,
'administrator' => true,
'parent' => 'articles',
'subtab' => 'Clone',
'method' => 'clonerecord',
),
'delete' => array (
'description' => 'Delete record: %detail',
'url' => 'articles/%id/delete.html',
'usetab' => 'articles',
'authentication' => true,
'administrator' => true,
'parent' => 'articles',
'subtab' => 'Delete',
),
*/
'image' => array (
'description' => 'Image: %detail',
'usetab' => 'articles',
),
'copyright' => array (
'description' => 'Copyright information',
'usetab' => false,
),
/*
'search' => array (
'description' => 'Search for taxa',
'tab' => 'Search for taxa',
'url' => 'search/',
),
*/
'data' => array (
'description' => 'Edit data/lookups',
'parent' => 'admin',
'subtab' => 'Edit data/lookups',
'url' => 'data/',
'authentication' => true,
'administrator' => true,
),
'links' => array (
'description' => false,
'url' => 'links.html',
'tab' => 'Links',
),
);
# Return the actions
return $actions;
}
# Database structure definition
public function databaseStructure ()
{
return "
-- Administrators
CREATE TABLE `administrators` (
`username__JOIN__people__people__reserved` varchar(191) NOT NULL COMMENT 'Username',
`password` varchar(255) NOT NULL COMMENT 'Password for non-Raven users',
`active` enum('','Yes','No') NOT NULL DEFAULT 'Yes' COMMENT 'Currently active?',
`userType` enum('Raven','External') NOT NULL DEFAULT 'Raven' COMMENT 'User login type',
`privilege` enum('Administrator','Restricted administrator') NOT NULL DEFAULT 'Administrator' COMMENT 'Administrator level',
`email` varchar(255) NOT NULL COMMENT 'E-mail address (not public)',
`title` enum('Dr','Mr','Ms','Miss','Mrs','Prof','Prof Sir') DEFAULT NULL COMMENT 'Title',
`forename` varchar(255) NOT NULL COMMENT 'Forename',
`surname` varchar(255) NOT NULL COMMENT 'Surname',
`biography` mediumtext COMMENT 'Biographical summary',
`url` mediumtext COMMENT 'Homepage URL',
PRIMARY KEY (`username__JOIN__people__people__reserved`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
CREATE TABLE `aperture` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'Unique key',
`variant` varchar(255) NOT NULL COMMENT 'Main variant',
`subvariant` varchar(255) DEFAULT NULL COMMENT 'Sub-variant',
`subsubvariant` varchar(255) DEFAULT NULL COMMENT 'Sub-sub-variant',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Aperture';
CREATE TABLE `diameter` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'Unique key',
`variant` varchar(255) NOT NULL COMMENT 'Main variant',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Equatorial diameter';
CREATE TABLE `family` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'ID',
`family` varchar(255) NOT NULL,
`synonyms` mediumtext COMMENT 'Synonym(s)',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Table of families';
CREATE TABLE `features` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'Unique key',
`variant` varchar(255) NOT NULL COMMENT 'Main variant',
`subvariant` varchar(255) DEFAULT NULL COMMENT 'Sub-variant',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Useful diagnostic features';
CREATE TABLE `form` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'Unique key',
`variant` varchar(255) NOT NULL COMMENT 'Main variant',
`subvariant` varchar(255) DEFAULT NULL COMMENT 'Sub-variant',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Form';
CREATE TABLE `imagesources` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'Unique key',
`websiteName` varchar(255) DEFAULT NULL COMMENT 'Website name',
`institution` varchar(255) DEFAULT NULL COMMENT 'Institution',
`category` enum('Database','Collection','Atlas','Glossary','Other') DEFAULT NULL COMMENT 'Category',
`urlFrontPage` mediumtext COMMENT 'Front page URL',
`urlImages` mediumtext COMMENT 'Images index URL',
`lmImages` enum('','Yes','No') DEFAULT NULL COMMENT 'LM images',
`semImages` enum('','Yes','No') DEFAULT NULL COMMENT 'SEM images',
`descriptions` enum('','Yes','No') DEFAULT NULL COMMENT 'Descriptions',
`glossary` enum('','Yes','No') DEFAULT NULL COMMENT 'Glossary',
`numberOfTaxa` int DEFAULT NULL COMMENT 'Approximate number of taxa',
`publicNotes` mediumtext COMMENT 'Public notes',
`privateNotes` mediumtext COMMENT 'Private notes',
`copyrightStatus` enum('Copyright status unsure','Permission granted to reproduce','Permission granted on limited basis (add details to notes)','Copyright approval needed','No right to reproduce') NOT NULL DEFAULT 'Copyright status unsure' COMMENT 'Copyright',
`copyrightNoteste` mediumtext COMMENT 'Copyright notes',
`appearInList` enum('','Yes','No') NOT NULL DEFAULT 'No' COMMENT 'Show this URL in list of links?',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Table of image sources';
CREATE TABLE `materials` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'Unique key',
`pollen__JOIN__pollen__pollen__reserved` int NOT NULL COMMENT 'Pollen database number',
`productionNumber` varchar(255) DEFAULT NULL COMMENT 'Production number',
`residueStatus` enum('','NR [No residue]','Residue present') NOT NULL COMMENT 'Residue status',
`mountant` enum('','GJ [Glycerine Jelly]','SO [Silicon oil]','xGJ [Extracted from Glycerine Jelly]') DEFAULT NULL COMMENT 'Mountant',
`slideStatus` varchar(255) DEFAULT NULL COMMENT 'Slide status',
`storageLocation` varchar(255) DEFAULT NULL COMMENT 'Storage location',
`publicNotes` mediumtext COMMENT 'Visible notes',
`privateNotes` mediumtext COMMENT 'Private notes',
PRIMARY KEY (`id`),
KEY `pollen__JOIN__pollen__pollen__reserved` (`pollen__JOIN__pollen__pollen__reserved`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Table of materials';
CREATE TABLE `media` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'Unique key',
`pollen__JOIN__pollen__pollen__reserved` int DEFAULT NULL COMMENT 'Pollen database number',
`residue` varchar(255) DEFAULT NULL COMMENT 'Residue',
`type` enum('Reference image (item from {$this->settings['collectionName']})','Image (taken from external source)','Video (taken from external source)','Document') DEFAULT NULL COMMENT 'Type',
`filename` varchar(255) DEFAULT NULL COMMENT 'File attachment',
`url` mediumtext COMMENT 'URL of source file',
`copyrightStatus` enum('Copyright status unsure','Permission granted to reproduce','Permission granted on limited basis (add details to notes)','Copyright approval needed','No right to reproduce') NOT NULL DEFAULT 'Copyright status unsure' COMMENT 'Copyright',
`copyrightNotes` mediumtext COMMENT 'Copyright notes',
`shortDescription` varchar(255) NOT NULL COMMENT 'Short description',
`doi` varchar(255) DEFAULT NULL COMMENT 'DOI reference number',
`publicNotes` mediumtext COMMENT 'Public notes',
`privateNotes` mediumtext COMMENT 'Private notes',
PRIMARY KEY (`id`),
KEY `pollen__JOIN__pollen__pollen__reserved` (`pollen__JOIN__pollen__pollen__reserved`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Table of media (images/videos)';
CREATE TABLE `polaraxis` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'Unique key',
`variant` varchar(255) NOT NULL COMMENT 'Main variant',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Polar axis';
CREATE TABLE `pollen` (
`id` int NOT NULL COMMENT 'Record number',
`family__JOIN__pollen__family__reserved` int DEFAULT NULL COMMENT 'Family',
`subfamily__JOIN__pollen__subfamily__reserved` int DEFAULT NULL COMMENT 'Sub-Family',
`genus` varchar(255) DEFAULT NULL COMMENT 'Genus',
`species` varchar(255) DEFAULT NULL COMMENT 'Species',
`FENumber` varchar(255) DEFAULT NULL COMMENT 'Flora Europaea',
`englishCommonName` varchar(255) DEFAULT NULL COMMENT 'English common name',
`continent` set('Africa','Antarctica','Asia','Australia','Europe','North America','South America') DEFAULT NULL COMMENT 'Continent',
`furtherLocationDetails` varchar(255) DEFAULT NULL COMMENT 'Further geographical location details',
`fossilType` enum('','Pollen','Spore') NOT NULL DEFAULT 'Pollen' COMMENT 'Fossil type',
`form__JOIN__pollen__form__reserved` int DEFAULT NULL COMMENT 'Form',
`alternativeForm__JOIN__pollen__form__reserved` int DEFAULT NULL COMMENT 'Alternative form',
`primaryApertureConfiguration__JOIN__pollen__aperture__reserved` int DEFAULT NULL COMMENT 'Primary aperture configuration',
`alternativeaApertureConfig1__JOIN__pollen__aperture__reserved` int DEFAULT NULL COMMENT 'Alternative aperture configuration 1',
`alternativeaApertureConfig2__JOIN__pollen__aperture__reserved` int DEFAULT NULL COMMENT 'Alternative aperture configuration 2',
`alternativeaApertureConfig3__JOIN__pollen__aperture__reserved` int DEFAULT NULL COMMENT 'Alternative aperture configuration 3',
`primarySculpturingType__JOIN__pollen__sculpturing__reserved` int DEFAULT NULL COMMENT 'Primary sculpturing type',
`alternativeSculpturingType1__JOIN__pollen__sculpturing__reserved` int DEFAULT NULL COMMENT 'Alternative sculpturing type 1',
`alternativeSculpturingType2__JOIN__pollen__sculpturing__reserved` int DEFAULT NULL COMMENT 'Alternative sculpturing type 2',
`alternativeSculpturingType3__JOIN__pollen__sculpturing__reserved` int DEFAULT NULL COMMENT 'Alternative sculpturing type 3',
`tectum__JOIN__pollen__tectum__reserved` int DEFAULT NULL COMMENT 'Tectum [Wall Structure]',
`primaryPolarAxis__JOIN__pollen__polaraxis__reserved` int DEFAULT NULL COMMENT 'Primary polar axis',
`alternativePolarAxis1__JOIN__pollen__polaraxis__reserved` int DEFAULT NULL COMMENT 'Alternative polar axis 1',
`primaryEquatorialDiameter__JOIN__pollen__diameter__reserved` int DEFAULT NULL COMMENT 'Primary equatorial diameter',
`alternativeEquatorialDiameter1__JOIN__pollen__diameter__reserved` int DEFAULT NULL COMMENT 'Alternative equatorial diameter 1',
`features1__JOIN__pollen__features__reserved` int DEFAULT NULL COMMENT 'Useful diagnostic features (1)',
`features2__JOIN__pollen__features__reserved` int DEFAULT NULL COMMENT 'Useful diagnostic features (2)',
`features3__JOIN__pollen__features__reserved` int DEFAULT NULL COMMENT 'Useful diagnostic features (3)',
`references` mediumtext COMMENT 'References',
`urls` mediumtext COMMENT 'URLs (and description)',
`ecologicalPreferences` mediumtext COMMENT 'Ecological preferences',
`notes` mediumtext COMMENT 'Visible notes',
`privateNotes` mediumtext COMMENT 'Private notes',
`recordCreation` datetime DEFAULT NULL COMMENT 'Record creation date/time',
`lastModified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Date/time when record last modified',
`userCreator` varchar(255) NOT NULL COMMENT 'Original creator',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Pollen samples';
CREATE TABLE `sculpturing` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'Unique key',
`sculpturing` varchar(255) NOT NULL COMMENT 'Main variant',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Sculpturing';
CREATE TABLE `subfamily` (
`id` int NOT NULL COMMENT 'ID',
`family` varchar(255) NOT NULL,
`synonyms` mediumtext COMMENT 'Synonym(s)',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Table of sub-families';
CREATE TABLE `tectum` (
`id` int NOT NULL AUTO_INCREMENT COMMENT 'Unique key',
`variant` varchar(255) NOT NULL COMMENT 'Main variant',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Tectum [Wall Structure]';
";
}
# Welcome screen
public function home ()
{
# Start the HTML
# Define edit link
$editLink = '';
if ($this->userIsAdministrator) {
$editLink = "\n<li><a rel=\"nofollow\" href=\"{$this->baseUrl}/articles/add.html\">Add new articles or edit existing articles in the collection</a></li>";
}
# Define the HTML
if ($this->settings['introductionHtml']) {
$placeholders = array (
'%baseUrl' => $this->baseUrl,
'%editLink' => $editLink,
);
$html .= strtr ($this->settings['introductionHtml'], $placeholders);
}
# Add comments note
$html .= "<p>Comments/suggestions via the <a href=\"{$this->baseUrl}/feedback.html\">feedback form</a> are most welcome.</p>";
# Show the HTML
echo $html;
}
# Copyright screen
public function copyright ()
{
# Show the introduction
$html = "\n" . "<p>All images on this site are © {$this->settings['copyrightOwner']}.</p>";
$html .= "\n" . "<p>If you wish to reproduce an item, please kindly <a href=\"{$this->baseUrl}/feedback.html\">contact us</a> in the first instance.</p>";
# Return the HTML
echo $html;
}
# Help page; overrides default help page
public function help ()
{
# Define the HTML
$html = '
<h3>Database access</h3>
<p>This database can be viewed by anyone.</p>
<p>Certain images are copyright reserved, so cannot be viewed on external computers.</p>
<p>This database can only be edited by registered users. Registered users can only be created by current administrators. Administrators login is via the University\'s Raven system.</p>
<h3>Using the database</h3>
<p>In view mode, empty fields are hidden.</p>
<p>Depending on the browser in use, refreshing a page may remove entered but unsubmitted information. In order to refresh drop down menus from look-up tables, please use the refresh button next to the drop down menus.</p>
<h3>Copyright statement</h3>
<p>All original images / videos are copyright reserved.</p>
<p>Only openly-licensed images are reproduced. If you believe we have infringed on your copyright, please let us know and we will make the necessary corrections.</p>
';
# Show the HTML
echo $html;
}
# Links page
public function links ()
{
# Get the static HTML file
$html = file_get_contents ($_SERVER['DOCUMENT_ROOT'] . $this->baseUrl . '/links.html');
# Show the HTML
echo $html;
}
# Function to clear search and other parameters
public function clear ()
{
# Reset the session
session_start ();
$_SESSION = array ();
# Redirect to main page
$location = 'https://' . $_SERVER['SERVER_NAME'] . $this->baseUrl . '/articles/';
header ("Location: {$location}");
}
# Search form
private function searchForm ()
{
# Create the form
$template = "{[[PROBLEMS]]}\n<p>Limit to: {family} {genus} {species}{[[SUBMIT]]} [or <a rel=\"nofollow\" href=\"{$this->baseUrl}/articles/clear.html\">reset all</a>]</p>";
$form = new form (array (
'displayRestrictions' => false,
'formCompleteText' => false,
'escapeOutput' => true,
'databaseConnection' => $this->databaseConnection,
'div' => 'ultimateform article',
'reappear' => true,
'display' => 'template',
'displayTemplate' => $template,
'submitButtonText' => 'Search!',
'submitButtonAccesskey' => false,
'nullText' => false,
'requiredFieldIndicator' => false,
'escapeOutput' => true,
));
# Get the data
#!# Add in trimSql ()
$query = "SELECT
DISTINCT
family.family,
family__JOIN__pollen__family__reserved
FROM {$this->dataSource}
LEFT OUTER JOIN pollen.family ON pollen.family__JOIN__pollen__family__reserved = family.id
WHERE family__JOIN__pollen__family__reserved != '0'
ORDER BY family
;";
$familyData = $this->databaseConnection->getData ($query);
$query = "SELECT DISTINCT genus FROM {$this->dataSource} ORDER BY genus;";
$genus = $this->databaseConnection->getPairs ($query);
$query = "SELECT DISTINCT species FROM {$this->dataSource} ORDER BY species;";
$species = $this->databaseConnection->getPairs ($query);
# Re-arrange the family
$family = array ();
foreach ($familyData as $familyItem) {
$family[$familyItem['family__JOIN__pollen__family__reserved']] = trim ($familyItem['family']);
}
# Form widgets
$form->select (array (
'name' => 'family',
'title' => 'Family',
'values' => $family,
'nullText' => '[Family]',
'default' => (isSet ($_SESSION['family']) ? $_SESSION['family'] : ''),
'forceAssociative' => true, // Ensures index is kept
));
$form->select (array (
'name' => 'genus',
'title' => 'Genus',
'values' => $genus,
'nullText' => '[Genus]',
'default' => (isSet ($_SESSION['genus']) ? $_SESSION['genus'] : ''),
));
$form->select (array (
'name' => 'species',
'title' => 'Species',
'values' => $species,
'nullText' => '[Species]',
'default' => (isSet ($_SESSION['species']) ? $_SESSION['species'] : ''),
));
# Process the form
$result = $form->process ($html);
# Default to the session
if (!$result) {
if (isSet ($_SESSION['family'])) {$result['family'] = $_SESSION['family'];}
if (isSet ($_SESSION['genus'])) {$result['genus'] = $_SESSION['genus'];}
if (isSet ($_SESSION['species'])) {$result['species'] = $_SESSION['species'];}
}
# Return the result
return $result;
}
# Articles listing screen
public function articles ($restrictionSql = '', $preparedStatementValues = array ())
{
# Assign the field ordering
$orderby = $this->settings['orderby'];
$firstOrderby = $orderby[0];
$this->arguments['orderby'] = $orderby[0];
if (isSet ($_GET['orderby']) && in_array ($_GET['orderby'], $orderby)) {
$orderby = application::array_move_to_start ($this->settings['orderby'], $_GET['orderby']);
$firstOrderby = $_GET['orderby'];
$this->arguments['orderby'] = $firstOrderby;
}
# Determine the page to use
$usePage = ((isSet ($_GET['page']) && is_numeric ($_GET['page']) && ($_GET['page'])) ? $_GET['page'] : 1);
# Put the ordering and page into the session and redirect if on the main page
session_start ();
if (!isSet ($_GET['orderby']) && !isSet ($_GET['page'])) {
if (isSet ($_SESSION['orderby']) && isSet ($_SESSION['page'])) {
if (in_array ($_SESSION['orderby'], $orderby) && is_numeric ($_SESSION['page'])) { // Page could be checked further
$location = 'https://' . $_SERVER['SERVER_NAME'] . $this->baseUrl . "/articles/{$_SESSION['orderby']},page{$_SESSION['page']}.html";
header ("Location: {$location}");
return;
}
}
} else {
$_SESSION['orderby'] = $this->arguments['orderby'];
$_SESSION['page'] = $usePage;
}
# Show the search form and create SQL from it
if ($result = $this->searchForm ()) {
#!# Session reset is a workaround for offsets bug
$restrictions = array ();
$preparedStatementValues = array ();
foreach ($result as $key => $value) {
$_SESSION[$key] = $value;
if ($value) {
if ($key == 'family') {$key = "family__JOIN__{$this->settings['database']}__family__reserved";}
$restrictions[] = "{$key} = :{$key}";
$preparedStatementValues[$key] = $value;
}
}
if ($restrictions) {
$restrictionSql = ' WHERE ' . implode (' AND ', $restrictions);
}
# Redirect to main page to prevent POST refresh warnings
if ($_POST) {
$location = 'https://' . $_SERVER['SERVER_NAME'] . $this->baseUrl . '/articles/';
header ("Location: {$location}");
}
}
# Get the data or end
list ($data, $totalArticles, $totalPages, $page) = $this->getArticlesData ($restrictionSql, $preparedStatementValues, $orderby, $usePage);
if (!$data) {
echo $html = '<p>No articles were found.</p>';
return false;
}
# Start the HTML with the number of records
$articlesShown = count ($data);
$html = "\n<p>There " . ($totalArticles == 1 ? 'is one taxon' : "are {$totalArticles} taxa") . (($totalArticles != $articlesShown) ? ', of which ' . ($articlesShown == 1 ? 'one is shown' : "{$articlesShown} are shown") : '') . ':</p>';
# Add in pagination links
$html .= pagination::paginationLinks ($page, $totalPages, $this->baseUrl . '/articles/' . $firstOrderby . ',');
# Rearrange the table
foreach ($data as $key => $article) {
# Add the view/edit links
$data[$key]['materials'] = ($data[$key]['materials'] == '0' ? '' : $data[$key]['materials']);
$data[$key]['media'] = ($data[$key]['media'] == '0' ? '' : $data[$key]['media']);
$data[$key]['view'] = "<a href=\"{$this->baseUrl}/articles/" . strtolower ($article['id']) . '/"><strong>View</strong></a>';
$data[$key]['edit'] = "<a rel=\"nofollow\" href=\"{$this->baseUrl}/articles/" . strtolower ($article['id']) . '/edit.html">Edit</a>';
# Unset the id
unset ($data[$key]['id']);
}
# Create table headings
$replacements = array ();
foreach ($orderby as $heading) {
$replacements[$heading] = '<a' . ($heading == $this->arguments['orderby'] ? ' class="selected"' : '') . ' href="' . (($heading == $firstOrderby) ? './' : "{$heading}.html") . '">' . ucfirst ($heading) . '</a>';
}
# Compile the HTML
$html .= application::htmlTable ($data, $replacements, $class = 'lines articles', $showKey = false, $uppercaseHeadings = true, $allowHtml = true, $showColons = false, $addCellClasses = true, $addRowKeys = false);
$html .= $paginationListHtml;
# Link to a mass dump of records
if ($this->userIsAdministrator) {
$html .= "<br /><p>As an administrator, you can also print off a <a href=\"{$this->baseUrl}/articles/dump.html\">full dump of all articles</a>.</p>";
}
# Show the HTML
echo $html;
}
# Function to get data for several articles
private function getArticlesData ($restrictionSql = '', $preparedStatementValues = array (), $orderby = false, $page = 0, $dumpMode = false)
{
# Apply pagination if a page supplied
if ($page) {
# Count the articles
#!# Switch to database.php method when it has $preparedStatementValues support
//$totalRecords = $this->databaseConnection->getTotal ($this->settings['database'], $this->settings['table'], $restrictionSql);
$query = "SELECT COUNT(*) AS total FROM `{$this->settings['database']}`.`{$this->settings['table']}` {$restrictionSql};";
$totalRecords = $this->databaseConnection->getOneField ($query, 'total', $preparedStatementValues);
# Get pager data
list ($totalPages, $offset, $items, $limit, $page) = pagination::getPagerData ($totalRecords, $this->settings['maxArticlesPerPage'], $page);
}
/*
# IsNull technique at: https://www.shawnolson.net/a/730/mysql_sort_order_with_null.html
foreach ($orderby as $index => $item) {
$orderby[$index] = $item . 'IsNull';
}
IsNull technique at: https://www.shawnolson.net/a/730/mysql_sort_order_with_null.html
, IF(family.family IS NULL or family.family='', 1, family.family) AS familyIsNull
, IF(pollen.genus IS NULL or pollen.genus='', 1, pollen.genus) AS genusIsNull
, IF(pollen.species IS NULL or family.family='', 1, pollen.species) AS speciesIsNull
*/
# Dump mode query
if ($dumpMode) {
$query = "SELECT
pollen.id,
family.family,
pollen.genus,
pollen.FENumber,
COUNT(materials.id) AS materials
FROM {$this->dataSource}
LEFT OUTER JOIN pollen.materials ON pollen.id = materials.pollen__JOIN__pollen__pollen__reserved
LEFT OUTER JOIN pollen.family ON pollen.family__JOIN__pollen__family__reserved = family.id
/* WHERE materials <> 0 */
GROUP BY pollen.id
ORDER BY genus;";
} else {
$query = "SELECT
pollen.id,
family.family,
pollen.genus,
pollen.species,
COUNT(materials.id) AS materials
, COUNT(media.id) AS media
FROM {$this->dataSource}
LEFT OUTER JOIN pollen.materials ON pollen.id = materials.pollen__JOIN__pollen__pollen__reserved
LEFT OUTER JOIN pollen.media ON pollen.id = media.pollen__JOIN__pollen__pollen__reserved
LEFT OUTER JOIN pollen.family ON pollen.family__JOIN__pollen__family__reserved = family.id
"
. $restrictionSql
. ' GROUP BY pollen.id'
. ($orderby ? ' ORDER BY ' . implode (',', $orderby) : '')
. ($page ? " LIMIT {$offset}, {$limit}" : '')
. ';';
}
if (!$data = $this->databaseConnection->getData ($query, $this->dataSource, true, $preparedStatementValues)) {
return ($page ? array (false, 0, 0, 0) : false);
}
# Return the data
return ($page ? array ($data, $totalRecords, $totalPages, $page) : $data);
}
# Function to produce a printable dump of all articles
public function dump ()
{
# Start the HTML
$html = '<p>This is a dump of all articles, one after the other.<br />(Printing will result in page breaks at sensible locations.)</p>';
# Get the data or end
if (!$data = $this->getArticlesData ('', array (), false, 0, $dumpMode = true)) {
echo $html = '<p>No articles were found.</p>';
return false;
}
# Display the data
#!# TODO
$html = application::htmlTable ($data);
/*
# Create the list of records
foreach ($data as $key => $article) {
$list[] = "<a href=\"#article{$key}\">Article " . htmlspecialchars (implode (' - ', $article)) . '</a>';
}
$html .= application::htmlUl ($list);
# Loop through each article and create the HTML for it
foreach ($data as $key => $article) {
$html .= '<hr class="pagebreak" />';
$html .= $this->articleManipulation ($key, $action = __FUNCTION__);
}
*/
# Show the HTML
echo $html;
}
# Article viewing - wrapper to main article
public function article ($article)
{
# Hand off to the article method, in addition mode
echo $this->articleManipulation ($article);
}
# Article addition - wrapper to main article
public function add ()
{
# Hand off to the article method, in addition mode
echo $this->articleManipulation (false, $action = __FUNCTION__);
}
# Article editing - wrapper to main article
public function edit ($article)
{
# Hand off to the article method, in edit mode
echo $this->articleManipulation ($article, $action = __FUNCTION__);
}
# Article editing - materials section
public function editmaterial ($article)
{
echo $this->articleManipulation ($article, $action = __FUNCTION__);
}
# Article editing - media section
public function editmedia ($article)
{
echo $this->articleManipulation ($article, $action = __FUNCTION__);
}
# Article addition - materials section
public function addmaterial ($article)
{
echo $this->articleManipulation ($article, $action = __FUNCTION__);
}
# Media addition - material section
public function addmaterialmedia ($article)
{
echo $this->articleManipulation ($article, $action = __FUNCTION__);
}
# Article addition - media section
public function addmedia ($article)
{
echo $this->articleManipulation ($article, $action = __FUNCTION__);
}
# Article cloning - wrapper to main article
public function clonerecord ($article)
{
# Hand off to the article method, in edit mode
echo $this->articleManipulation ($article, $action = 'clone');
}
# Article deletion - wrapper to main article
public function delete ($article)
{
# Hand off to the article method, in edit mode
echo $this->articleManipulation ($article, $action = __FUNCTION__);
}
# Function to construct an item's name
private function constructName ($data, $fields = false)
{
# Get fields if necessary
if (!$fields) {
$fields = $this->databaseConnection->getFields ($this->settings['database'], $this->settings['table']);
}
# Convert the name
$dataset = array ($data);
$dataset = $this->databaseConnection->substituteJoinedData ($dataset, $this->settings['database'], false, $nameField = 'family');
$data = $dataset[0];
# Compile the name from the specified fields that are non-empty
$nameComponents = array ();
$useFields = array ('family__JOIN__pollen__family__reserved', 'genus', 'species');
foreach ($useFields as $field) {
if (isSet ($data[$field]) && !empty ($data[$field])) {
$nameComponents[] = $data[$field];
}
}
$name = implode (' ', $nameComponents);
# Make entity-safe
$name = htmlspecialchars ($name);
# Return the assembled name
return $name;
}
# Function to create previous/index/next navigation links
private function navigationLinks ($article, $actionSupplement = '')
{
# Start the HTML
$html = '';
# Ensure a record is numeric
if (($article) && ctype_digit ($article)) {
# Determine the article and ordering
session_start ();
$firstOrderby = ((isSet ($_SESSION['orderby']) && in_array ($_SESSION['orderby'], $this->settings['orderby'])) ? $_SESSION['orderby'] : $this->settings['orderby'][0]);
$orderby = application::array_move_to_start ($this->settings['orderby'], $firstOrderby);
# Get the previous/next record; note that the technique at https://jystewart.net/2005/06/27/nextprevious-with-mysql/ cannot be used as title is not necessary unique
$data = $this->getArticlesData ('', array (), $orderby, $page = false);
$positions = application::getPositions (array_keys ($data), $article);
# Create the links
$links['first'] = ($positions['start'] ? "<a href=\"{$this->baseUrl}/articles/{$positions['start']}/{$actionSupplement}\" title=\"First record ({$positions['start']})\">«</a>" : ' ');
$links['previous'] = ($positions['previous'] ? "<a href=\"{$this->baseUrl}/articles/{$positions['previous']}/{$actionSupplement}\" title=\"Previous record ({$positions['previous']})\">< Previous</a>" : ' ');
$links['index'] = "<a href=\"{$this->baseUrl}/articles/\" title=\"Return to index of all " . ucfirst ($firstOrderby) . " records\">" . ucfirst ($firstOrderby) . ' index</a>';
$links['next'] = ($positions['next'] ? "<a href=\"{$this->baseUrl}/articles/{$positions['next']}/{$actionSupplement}\" title=\"Next record ({$positions['next']})\">Next ></a>" : ' ');
$links['last'] = ($positions['end'] ? "<a href=\"{$this->baseUrl}/articles/{$positions['end']}/{$actionSupplement}\" title=\"Last record ({$positions['end']})\">»</a>" : ' ');
# Compile the links
$html .= "\n" . application::htmlUl ($links, $parentTabLevel = 0, $className = 'noprint', $ignoreEmpty = true, $sanitise = false, $nl2br = false, $liClass = true, $selected = true);
}
# Return the HTML
return $html;
}
# Article page, defaulting to viewing
private function articleManipulation ($article = false, $action = 'view')
{
# Special handling of dump mode
$dumpMode = false;
if ($action == 'dump') {
$action = 'view';
$dumpMode = true;
}
# Determine the available actions
$actions = array ('view', 'edit', 'clone', 'delete', 'add');
# Get the article data or end
if ($action != 'add') {
if (!$articleData = $this->getArticleData ($article)) {return false;}
}
# Get the fields and headings conversions
$articleFields = $this->databaseConnection->getFields ($this->settings['database'], $this->settings['table']);
$articleHeadings = $this->databaseConnection->getHeadings ($this->settings['database'], $this->settings['table'], $articleFields);
# Get the materials data
$materialsData = $this->databaseConnection->select ($this->settings['database'], 'materials', array ('pollen__JOIN__pollen__pollen__reserved' => $article));
$materialsHeadings = $this->databaseConnection->getHeadings ($this->settings['database'], 'materials');
# Get the media data and regroup it by residue
$mediaDataRaw = $this->getArticleMediaData ($article);
foreach ($mediaDataRaw as $index => $media) {
if ($media['residue'] == '') {
$mediaDataRaw[$index]['residue'] = 0; // '' is changed to: 0, which is being used as a special case meaning 'not attached to a specific residue/material'
}
}
$mediaData = application::regroup ($mediaDataRaw, 'residue', $removeGroupColumn = false);
$mediaFields = $this->databaseConnection->getFields ($this->settings['database'], 'media');
# Determine whether to limit the fields (which is the default, i.e. $article/ rather than $article/full.html
$fullView = (($this->action == 'dump') || (isSet ($_GET['full']) && $_GET['full'] == 'true'));
$limitFields = ($fullView ? false : array ('id', 'pollen__JOIN__pollen__pollen__reserved', 'filename', 'url', 'shortDescription', 'publicNotes', 'copyrightStatus'));
# Start the HTML
$html = '';
# Add the name
if ($action != 'add') {
$html .= "\n" . "<h2 id=\"article{$article}\">" . $this->constructName ($articleData, $articleFields) . '</h2>';
}
# Create navigation links if showing/manipulating an existing article
$html .= "\n<div class=\"location noprint\">";
$html .= $this->navigationLinks ($article, ($action == 'view' ? '' : "{$action}.html"));
$html .= "\n</div>";
# Viewing mode links
if ($action != 'add') {
$html .= "\n<p class=\"noprint\">" . ($fullView ? '<a href="./#media">Return to default viewing mode</a>' : '<a href="full.html#media">View in full view mode</a>') . '</p>';
}
# Show links to materials and media
$attachments = array ();
$totalMaterials = count ($materialsData);
if ($materialsData) {$attachments[] = "\n<a href=\"#materials\"><img src=\"/images/icons/image.png\" alt=\"Material\" class=\"icon\" /> " . ($totalMaterials == 1 ? 'one material' : "{$totalMaterials} materials") . '</a>';}
$totalMedia = count ($mediaDataRaw);
if ($mediaData) {$attachments[] = "\n<a href=\"#media\"><img src=\"/images/icons/picture.png\" alt=\"Media\" class=\"icon\" /> " . ($totalMedia == 1 ? 'one media item' : "{$totalMedia} media items") . '</a>';}
if ($attachments) {
$html .= "\n<p>This item has: " . implode (' and ', $attachments) . '</p>';
}
# Display the record
$html .= "\n<div class=\"pollen\">";
$html .= "\n\n<h3 id=\"pollen\">Data for this pollen</h3>";
$addRecord = ($action == 'add');
$editRecord = ($action == 'edit');
if (!$addRecord) {
$html .= "\n<ul class=\"actions noprint\">";
if ($editRecord) {
$html .= "<li><a rel=\"nofollow\" href=\"{$this->baseUrl}/articles/{$article}/#pollen\"><img src=\"/images/icons/table_delete.png\" alt=\"Cancel\" /> Cancel editing</a></li>";
} else {
$html .= "<li><a rel=\"nofollow\" href=\"{$this->baseUrl}/articles/{$article}/edit.html#pollen\"><img src=\"/images/icons/page_white_edit.png\" alt=\"Edit\" /> Edit main record</a></li>";
}
$html .= "\n</ul>";
}
if ($addRecord || $editRecord) {
$html .= $this->editableRegion ($article, $action, 'pollen', ($addRecord ? false : $articleData), 'pollen');
} else {
$html .= $this->displayRecord ($article, $articleData, $articleFields, $fullView);
}
$html .= "\n</div>";
# End here if adding a main record
if ($addRecord) {
return $html;
}
# Start materials section
$html .= "\n\n<h3 id=\"materials\">Examples of this taxon in the {$this->settings['collectionName']}</h3>";
# Get material data
if (!$materialsData) {
$html .= "\n<p>There are no examples of this taxon in the {$this->settings['collectionName']}.</p>";
}
# Material addition
if ($action == 'addmaterial') {
$html .= "\n<div class=\"material\">";
$html .= "\n<h4 id=\"addmaterial\"><img src=\"/images/icons/image.png\" alt=\"Media\" class=\"icon\" /> Add new material</h4>";
$html .= "\n<ul class=\"actions noprint\">
<li><a rel=\"nofollow\" href=\"{$this->baseUrl}/articles/{$article}/#addmaterial\"><img src=\"/images/icons/image_delete.png\" alt=\"Cancel\" /> Cancel adding material</a></li>
</ul>";
$html .= $this->editableRegion ($article, $action, 'materials', array (), 'addmaterial');
$html .= "\n</div>";
} else {
# Action link
$html .= "\n<ul class=\"actions inline noprint\" id=\"addmaterial\"><li><a rel=\"nofollow\" href=\"{$this->baseUrl}/articles/{$article}/addmaterial.html#addmaterial\"><img src=\"/images/icons/picture_add.png\" class=\"icon\" alt=\"Add material\" /> Add material</a></li></ul>";
}
# Show any existing material by looping through each
if ($materialsData) {
foreach ($materialsData as $materialId => $material) {
# Open a box
$html .= "\n<div class=\"material\">";
# Determine if a material is being edited
$editMaterial = (($action == 'editmaterial' && isSet ($_GET['record']) && $_GET['record'] == $materialId) ? $materialId : false);
$addMaterialMedia = (($action == 'addmaterialmedia' && isSet ($_GET['record']) && $_GET['record'] == $materialId) ? $materialId : false);
# Show through each connected material