-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.php
102 lines (88 loc) · 3.22 KB
/
image.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
<?php
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;
}
?>
<!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 output_img_page($row) {
echo '<h1 class="latin_name">'.$row['LatinName']." Images</h1>";
echo '<a href="viewtropical.php?id='.urlencode($row['LatinName']).'">Back to plant info.</a>';
echo '<br/>';
$imgdata = null;
$imglist = find_images($row['LatinName']);
if (empty($imglist)) {
echo '<div class="NOIMAGE">No Image.</div>';
}
foreach ($imglist as $imgdata) {
global $images_path;
$filename = $images_path.$imgdata["file"];
if ($imgdata and file_exists($filename)) {
echo '<a href="'.$filename.'"><img class="big_pic" src="'.sized_image_bounded($filename,960, 9999).'" id="'.$filename.'" alt="'.$row['LatinName'].'"/></a>';
output_image_info($imgdata);
} else {
echo '<div class="NOIMAGE">No Image.</div>';
trigger_error("Image ".$filename." for ".$row['LatinName']." is in database but the file can not be found!");
}
echo "<br/>\n";
}
}
$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 `PlantPictures` WHERE LCASE(`LatinName`) = LCASE('$key')");
$row = mysqli_fetch_assoc($result);
if ($row) {
echo "<title>".$row['LatinName']." Images - Useful Tropical Plants</title>";
echo "</head>\n<body>";
include 'header.php';
global $redir;
global $row;
output_img_page($row);
} 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: image.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="image.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", "image.php", "id",-1 , array("LatinName"), array("TrueLatinName" => "LatinName", "Author" => "Author"));
#print_r( $names);
}
}
mysqli_free_result($result);
include 'footer.php';
mysqli_close($db);
?>
</body>
</html>