forked from DavRowswell/TestSite
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutilities.php
47 lines (44 loc) · 1.54 KB
/
utilities.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
<?php
use airmoi\FileMaker\FileMakerException;
use airmoi\FileMaker\Object\Record;
/**
* Checks the value to see if its a valid database.
* With wrong databases value a error.php page is shown.
* @param string|null $databaseFieldValue
* @param bool $includeAll should the 'all' value be included as valid
*/
function checkDatabaseField(?string $databaseFieldValue, bool $includeAll = false) {
# Check to make sure the database file is loaded or send to error.php
if (!isset($databaseFieldValue) or $databaseFieldValue == ''){
$_SESSION['error'] = "No database given";
header('Location: error.php');
exit;
}
# also check to make sure we dont have the 'all' database tag, if its not desired
else if (!$includeAll and $databaseFieldValue == 'all') {
$_SESSION['error'] = "Wrong page for database given";
header('Location: error.php');
exit;
}
# search in database list
else if (!in_array($databaseFieldValue, DatabaseSearch::$ValidNames)) {
$_SESSION['error'] = "Invalid database value given!";
header('Location: error.php');
exit;
}
}
/**
* Special entomology function to create the records genus page for their website.
* @param Record $record
* @return string
*/
function getGenusPage(Record $record): string
{
try {
$order = $record->getField('Order');
$family = $record->getField('Family');
return 'https://www.zoology.ubc.ca/entomology/main/'.$order.'/'.$family.'/';
} catch (FileMakerException) {
return '#';
}
}