forked from rudolphi/open_enventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getGif.php
200 lines (183 loc) · 6.14 KB
/
getGif.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
<?php
/*
Copyright 2006-2018 Felix Rudolphi and Lukas Goossen
open enventory is distributed under the terms of the GNU Affero General Public License, see COPYING for details. You can also find the license under http://www.gnu.org/licenses/agpl.txt
open enventory is a registered trademark of Felix Rudolphi and Lukas Goossen. Usage of the name "open enventory" or the logo requires prior written permission of the trademark holders.
This file is part of open enventory.
open enventory is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
open enventory is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with open enventory. If not, see <http://www.gnu.org/licenses/>.
*/
/*
Zeigt ein GIF an, das a) in der Datenbank (molecule_id=xyz) oder in der Session[gifFile12345678] (timestamp=12345678) abgelegt wurde
oder (save=true) läßt es den Browser herunterladen und unter dem Namen filename=xyz speichern
*/
require_once "lib_global_funcs.php";
require_once "lib_db_query.php";
require_once "lib_formatting.php";
set_time_limit(10);
// hack for DYMO, allow session id via get parameter, only for this php
if (empty($_COOKIE[db_type]) && !empty($_REQUEST[db_type])) {
$_COOKIE[db_type]=$_REQUEST[db_type];
}
$barcodeTerminal=true;
pageHeader(true,false,true,false);
$db_id=$_REQUEST["db_id"]??-1;
if (empty($db_id)) {
$db_id=-1;
}
$format=$_REQUEST["format"]??"";
if (!empty($_REQUEST["timestamp"]??"")) {
if ($format=="svg" || (empty($format) && $useSvg) ) {
$output=$_SESSION["svgFile"][$_REQUEST["timestamp"]];
$format="svg";
}
else {
$output=$_SESSION["gifFile"][$_REQUEST["timestamp"]];
$format=$analytics_img_params["format"];
}
}
else {
$resultList=array();
if (!empty($_REQUEST["molecule_id"]??"") && loginToDB(false)) {
if ($format=="svg" || (empty($format) && $useSvg) ) {
$resultList=mysql_select_array(array(
"table" => "molecule_svg",
"filter" => "molecule_id=".fixNull($_REQUEST["molecule_id"]),
"dbs" => $db_id,
"limit" => 1,
));
$format="svg";
}
else {
$resultList=mysql_select_array(array(
"table" => "molecule_gif",
"filter" => "molecule_id=".fixNull($_REQUEST["molecule_id"]),
"dbs" => $db_id,
"limit" => 1,
));
$format=$analytics_img_params["format"];
}
mysqli_close($db);
}
elseif (!empty($_REQUEST["reaction_chemical_id"]??"") && loginToDB(false)) {
if ($format=="svg" || (empty($format) && $useSvg) ) {
$resultList=mysql_select_array(array(
"table" => "reaction_chemical_svg",
"filter" => "reaction_chemical_id=".fixNull($_REQUEST["reaction_chemical_id"]),
"dbs" => $db_id,
"limit" => 1,
));
$format="svg";
}
else {
$resultList=mysql_select_array(array(
"table" => "reaction_chemical_gif",
"filter" => "reaction_chemical_id=".fixNull($_REQUEST["reaction_chemical_id"]),
"dbs" => $db_id,
"limit" => 1,
));
$format=$analytics_img_params["format"];
}
mysqli_close($db);
}
elseif (!empty($_REQUEST["reaction_id"]??"") && loginToDB(false)) {
if ($format??null=="svg" || (!isset($format) && $useSvg) ) {
$resultList=mysql_select_array(array(
"table" => "reaction_svg",
"filter" => "reaction_id=".fixNull($_REQUEST["reaction_id"]),
"dbs" => $db_id,
"limit" => 1,
));
$format="svg";
}
else {
$resultList=mysql_select_array(array(
"table" => "reaction_gif",
"filter" => "reaction_id=".fixNull($_REQUEST["reaction_id"]),
"dbs" => $db_id,
"limit" => 1,
));
$format=$analytics_img_params["format"];
}
mysqli_close($db);
}
elseif (!empty($_REQUEST["analytical_data_id"]??"") && loginToDB(false)) {
if (empty($_REQUEST["image_no"])) {
$resultList=mysql_select_array(array(
"table" => "analytical_data_gif",
"filter" => "analytical_data_id=".fixNull($_REQUEST["analytical_data_id"]),
"dbs" => $db_id,
"limit" => 1,
));
}
else {
$resultList=mysql_select_array(array(
"table" => "analytical_data_image_gif",
"filter" => "analytical_data_id=".fixNull($_REQUEST["analytical_data_id"])." AND image_no=".fixNull($_REQUEST["image_no"]),
"dbs" => $db_id,
"limit" => 1,
));
}
$mime=$resultList[0]["analytical_data_graphics_type"]??null;
mysqli_close($db);
}
elseif (!empty($_REQUEST["literature_id"]) && loginToDB(false)) {
$resultList=mysql_select_array(array(
"table" => "literature_gif",
"filter" => "literature_id=".fixNull($_REQUEST["literature_id"]),
"dbs" => $db_id,
"limit" => 1,
));
$mime=$resultList[0]["literature_graphics_type"]??null;
mysqli_close($db);
}
$output=$resultList[0]["image"]??"";
$lastchanged=$resultList[0]["last_changed"]??null;
}
if (empty($output)) {
$format=$analytics_img_params["format"];
$output=getEmptyImage($format);
}
if (empty($mime)) {
$mime=getMimeFromExt($format);
}
if (empty($_REQUEST["save"])) { // display image in browser
header(getHeaderFromMime($mime));
// use cache if possible
if (isset($lastchanged)) {
header("Last-Modified: ".gmdate("D, d M Y H:i:s",$lastchanged)." GMT");
}
}
else { // download
if (!empty($_REQUEST["filename"])) {
$filename=$_REQUEST["filename"];
}
elseif (!empty($_REQUEST["molecule_id"])) {
$filename=$_REQUEST["molecule_id"];
}
elseif (!empty($_REQUEST["timestamp"])) {
$filename=$_REQUEST["timestamp"];
}
else {
$filename="molecule";
}
$filename=fixFilenameForDownload(strip_tags($filename).ifNotEmpty(".",$format) );
header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=".$filename);
if (!strpos(getenv("HTTP_USER_AGENT"),"MSIE")) { // IE bug, always the same sh*t
header(getHeaderFromMime($mime));
}
}
echo $output;
?>