-
Notifications
You must be signed in to change notification settings - Fork 4
/
Find_CalibrationsByFossils.php
141 lines (119 loc) · 7.18 KB
/
Find_CalibrationsByFossils.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
<?php
// open and load site variables
require('../config.php');
// open and print header template
require('header.php');
?>
<?php
// connect to mySQL server and select the Fossil Calibration database
$connection=mysql_connect($SITEINFO['servername'],$SITEINFO['UserName'], $SITEINFO['password']) or die ('Unable to connect!');
mysql_select_db('FossilCalibration') or die ('Unable to select database!');
$key=array_keys($_GET);
$value=array_values($_GET);
//retrieve calibrations for fossil ID
if (!isset($key[0])) {
$key[0] = 'SHOW ALL'; // default, if no query-string args were provided
}
switch($key[0]) {
case 'Species':
$query='Select DISTINCT C.* FROM (SELECT CF.CalibrationID, V.* FROM View_Fossils V JOIN Link_CalibrationFossil CF ON CF.FossilID=V.FossilID) AS J JOIN View_Calibrations C ON J.CalibrationID=C.CalibrationID WHERE Species LIKE "%'. mysql_real_escape_string($value[0]) .'%" ORDER BY NodeName';
$calibration_list=mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
break;
case 'FossilMinAge':
// treat missing min-age argument as "unbounded" minimum
$trimmedMin = trim( $_GET['FossilMinAge'] );
$minProvided = !empty($trimmedMin);
$carefulMinAge = $minProvided ? $trimmedMin : " 0 ";
//
// treat missing max-age argument as "unbounded" maximum
$trimmedMax = trim( $_GET['FossilMaxAge'] );
$maxProvided = !empty($trimmedMax);
$carefulMaxAge = $maxProvided ? $trimmedMax : " 1000000 ";
//
$query='Select DISTINCT C.*, J.FossilMinAge, J.FossilMaxAge FROM (SELECT CF.CalibrationID, V.* FROM View_Fossils V JOIN Link_CalibrationFossil CF ON CF.FossilID=V.FossilID) AS J JOIN View_Calibrations C ON J.CalibrationID=C.CalibrationID WHERE FossilMinAge>'. mysql_real_escape_string($carefulMinAge) .' AND FossilMaxAge<'. mysql_real_escape_string($carefulMaxAge) .' ORDER BY NodeName';
$calibration_list=mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
//
// show adaptive prompt, based on which age boundaries were provided
echo '<h1>'. mysql_num_rows($calibration_list) .' calibration'. (mysql_num_rows($calibration_list) == 1 ? '' : 's') .' with';
if ($minProvided) {
echo ' minimum age "'. $carefulMinAge .' Ma"';
}
if ($minProvided and $maxProvided) {
echo ' and ';
}
if ($maxProvided) {
echo ' maximum age "'. $carefulMaxAge .' Ma"';
}
if (!$minProvided and !$maxProvided) {
echo 'in all time periods';
}
echo '</h1>';
break;
case 'HigherTaxon':
$query='Select DISTINCT C.* FROM (SELECT CF.CalibrationID, V.* FROM View_Fossils V JOIN Link_CalibrationFossil CF ON CF.FossilID=V.FossilID) AS J JOIN View_Calibrations C ON J.CalibrationID=C.CalibrationID WHERE '. mysql_real_escape_string($key[0]) .'=\''. mysql_real_escape_string($value[0]) .'\' ORDER BY NodeName';
$calibration_list=mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
//
// show adaptive prompt
echo '<h1>'. mysql_num_rows($calibration_list) .' calibration'. (mysql_num_rows($calibration_list) == 1 ? '' : 's') .' found under clade "'. $value[0] .'"</h1>';
break;
case 'System':
$query='Select DISTINCT C.* FROM (SELECT CF.CalibrationID, V.* FROM View_Fossils V JOIN Link_CalibrationFossil CF ON CF.FossilID=V.FossilID) AS J JOIN View_Calibrations C ON J.CalibrationID=C.CalibrationID WHERE '. mysql_real_escape_string($key[0]) .'=\''. mysql_real_escape_string($value[0]) .'\' ORDER BY NodeName';
$calibration_list=mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
break;
case 'Period':
$query='Select DISTINCT C.* FROM (SELECT CF.CalibrationID, V.* FROM View_Fossils V JOIN Link_CalibrationFossil CF ON CF.FossilID=V.FossilID) AS J JOIN View_Calibrations C ON J.CalibrationID=C.CalibrationID WHERE '. mysql_real_escape_string($key[0]) .'=\''. mysql_real_escape_string($value[0]) .'\' ORDER BY NodeName';
$calibration_list=mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
break;
case 'Epoch':
$query='Select DISTINCT C.* FROM (SELECT CF.CalibrationID, V.* FROM View_Fossils V JOIN Link_CalibrationFossil CF ON CF.FossilID=V.FossilID) AS J JOIN View_Calibrations C ON J.CalibrationID=C.CalibrationID WHERE '. mysql_real_escape_string($key[0]) .'=\''. mysql_real_escape_string($value[0]) .'\' ORDER BY NodeName';
$calibration_list=mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
break;
case 'Age':
$query='Select DISTINCT C.* FROM (SELECT CF.CalibrationID, V.* FROM View_Fossils V JOIN Link_CalibrationFossil CF ON CF.FossilID=V.FossilID) AS J JOIN View_Calibrations C ON J.CalibrationID=C.CalibrationID WHERE '. mysql_real_escape_string($key[0]) .'=\''. mysql_real_escape_string($value[0]) .'\' ORDER BY NodeName';
$calibration_list=mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
//
// show adaptive prompt
echo '<h1>'. mysql_num_rows($calibration_list) .' calibration'. (mysql_num_rows($calibration_list) == 1 ? '' : 's') .' found in "'. $value[0] .'" age</h1>';
break;
case 'SHOW ALL':
default:
// unknown (or no) query-string arguments provided; show all calibrations by default
$query='Select DISTINCT C.* FROM (SELECT CF.CalibrationID, V.* FROM View_Fossils V JOIN Link_CalibrationFossil CF ON CF.FossilID=V.FossilID) AS J JOIN View_Calibrations C ON J.CalibrationID=C.CalibrationID ORDER BY NodeName';
$calibration_list=mysql_query($query) or die ('Error in query: '.$query.'|'. mysql_error());
//
// show adaptive prompt
echo '<h1>'. mysql_num_rows($calibration_list) .' calibration'. (mysql_num_rows($calibration_list) == 1 ? '' : 's') .' found</h1>';
}
echo '<p>Click on "Show calibration" to view full calibration information. Click on node name or publication name to find related calibrations.</p>';
?>
<table width="100%" border="0">
<tr>
<td width="10%" align="center" valign="middle" class="small_orange"><strong>Info</strong></td>
<td width="5%" align="center" valign="middle" class="small_orange"><strong>CalibrationID</strong></td>
<td width="15%" align="center" valign="middle" class="small_orange"><strong>Node Name</strong></td>
<td width="5%" align="center" valign="middle" class="small_orange"><strong>Min Age</strong></td>
<td width="5%" align="center" valign="middle" class="small_orange"><strong>Max Age</strong></td>
<td width="15%" align="center" valign="middle" class="small_orange"><strong>Publication</strong></td>
</tr>
<?php
while ($row = mysql_fetch_array($calibration_list)) {
?>
<tr align="center" valign="top">
<td><a href="Show_Calibration.php?CalibrationID=<?=$row['CalibrationID']?>">Show calibration</a></td>
<td><?=$row['CalibrationID']?></td>
<td><a href="#" onclick="alert('Related calibrations COMING SOON...'); return false;"><?=$row['NodeName']?></a></td>
<td><?=$row['MinAge']?>
<? if (isset($_GET["test"])) { ?><i class="diagnostic"> (<?=$row['FossilMinAge']?>)</i><? } ?>
</td>
<td><?=$row['MaxAge']?>
<? if (isset($_GET["test"])) { ?><i class="diagnostic"> (<?=$row['FossilMaxAge']?>)</i><? } ?>
</td>
<td><?=$row['ShortName']?></td>
</tr>
<?php } ?>
</table>
<? if (isset($_GET["test"])) { echo("<br/><br/><i class='diagnostic'>$query</i>"); } ?>
<?php
//open and print page footer template
require('footer.php');
?>