-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewtropical.php
More file actions
121 lines (103 loc) · 3.57 KB
/
Copy pathviewtropical.php
File metadata and controls
121 lines (103 loc) · 3.57 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
<?php
// use an output buffer to store page contents
ob_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width">
<link rel=stylesheet href="style.css" type="text/css">
<link rel="shortcut icon" href="flower.ico">
<?php
function callback($matches) {
$key = $matches[1];
if ($key == "K") {
$row2 = array("No" => "K", "Title" => "Plants for a Future", "Author" => "Ken Fern ", "Description" => "Notes from observations, tasting etc at Plants For A Future and on field trips.");
} else {
if ($key) {
global $db;
$result2 = safe_query($db, "SELECT * FROM `References` WHERE `No` = ".$key);
$row2 = mysqli_fetch_assoc($result2);
} else {
return $key;
}
}
$out = "";
if ($row2) {
$out = '<div class="ref"><a href="javascript:;" >'.$key.'</a><div class=".entry-unrelated">'.OutputBookRefRecord($row2).'</div></div>';
}
return $out;
}
function link_to_book($string, $other = false) {
if ($other){
$regex = '/(?<=^|,\s)(\d*)/';
}else {
$regex = '/(?<=\[|,\s)(\d*|K)(?=,\s|\])/';
}
preg_match_all($regex, $string, $matches);
$rep = array();
$pat = array();
$newstring = preg_replace_callback($regex, "callback", $string);
return $newstring;
}
include 'functions.php';
include 'dbconnect.php';
if (empty($_GET["id"])) {
emailError(51, "A plant name must be supplied.",$_SERVER['REQUEST_URI'],"","");
//redirect to index page
header('Location: ./', TRUE, 303);
die;
}
$key = mysqli_real_escape_string($db, $_GET["id"]);
$redir = null;
if (! empty($_GET["redir"])) {
$redir = mysqli_real_escape_string($db, $_GET["redir"]);
}
$result = safe_query($db, "SELECT * FROM `tropicalspecies` WHERE LCASE(`Latin name`) = LCASE('$key')");
$row = mysqli_fetch_assoc($result);
if ($row) {
echo "<title>".$row['Latin name']." - Useful Tropical Plants</title>";
echo "</head>\n<body>";
include 'header.php';
global $redir;
global $row;
include('template.php' );
echo "<script src=\"boxmove.js\"></script>";
include_once 'comments.php';
output_comments($row['Latin name'], 'viewtropical.php?id='.urlencode($row['Latin name']));
} else {
echo "<title>No Record - Useful Tropical Plants</title>";
echo "</head>\n<body>";
include 'header.php';
$names = array();
#mysqli string comparisons aren't case sensitive, no need to convert case
$synresult = safe_query($db, 'SELECT * FROM `Synonyms`WHERE `LatinName` = "'.$key.'"');
while ($row = mysqli_fetch_assoc($synresult)) {
$names[] = $row["TrueLatinName"];
}
if (count($names) < 1) {
echo "<p>We have no record for <b>\"".htmlspecialchars($key)."\"</b></p>";
echo "<p>Try running a search.</p>";
} else if (count($names) == 1) {
#redirect...
header('Location: viewtropical.php?id='.urlencode($names[0]).'&redir='.urlencode($key), TRUE, 303);
#script shouldn't actualy reach here in theory
echo '<p>You probably want:';
echo '<a href="viewtropical.php?id='.urlencode($names[0]).'&redir='.urlencode($key).'">'.$names[0].'</a>';
echo '</p>';
}else {
echo "<p>No record for <b>\"".$key."\"</b></p>";
echo "<p>\"$key\" is a synonym of the following plants.</p>";
mysqli_data_seek($synresult, 0);
output_table_query($synresult, "Nothing", "Synonyms", null, "TrueLatinName", "viewtropical.php", "id",-1 , array("LatinName"), array("TrueLatinName" => "Latin Name", "Author" => "Author"));
#print_r( $names);
}
}
mysqli_free_result($result);
include 'footer.php';
mysqli_close($db);
ob_end_flush();
?>
</body>
</html>