-
Notifications
You must be signed in to change notification settings - Fork 3
/
report_detail.php
236 lines (196 loc) · 6.64 KB
/
report_detail.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
include 'checkinstance.php';
// Are we authorized to view this page?
if ( !isset($_SESSION['id']) )
{
do_notauthorized();
exit();
}
include 'config.php';
include 'db.php';
if ( isset( $_GET['ID'] ) )
{
$documentID = $_GET['ID'];
do_getDoc( $link, $documentID );
exit();
}
else
display_error( "Unauthorized request." );
exit();
// Display not authorized text
function do_notauthorized()
{
echo <<<HTML
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
<meta name="verify-v1" content="+TIfXSnY08mlIGLtDJVkQxTV4kDYMoWu2GLfWLI7VBE=" />
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<hr>
<address>Apache/2.2.3 (CentOS) Server at uslims3.uthscsa.edu Port 443</address>
</body></html>
HTML;
}
// Function to display a file
function do_getDoc( $link, $documentID )
{
// Let's start with header information
$header = get_header_info( $link, $documentID );
// Now the content
$content = get_document_content( $link, $documentID );
if ( empty( $content ) ) // Then we must be echoing something directly
return;
echo <<<HTML
<html>
<head>
<title>US Lims Database - Report Detail</title>
<link rel="stylesheet" type="text/css" href="css/main.css" />
</head>
<body>
$header
$content
<p><a href='javascript:window.close();'>Close Window</a></p>
</body></html>
HTML;
}
// Function to get document header content
function get_header_info( $link, $documentID )
{
// Let's start with header information
$query = "SELECT report.runID, triple, runType " .
"FROM documentLink, reportTriple, report, experiment " .
"WHERE reportDocumentID = $documentID " .
"AND documentLink.reportTripleID = reportTriple.reportTripleID " .
"AND reportTriple.reportID = report.reportID " .
"AND report.experimentID = experiment.experimentID ";
$result = mysqli_query( $link, $query )
or die( "Query failed : $query<br />\n" . mysqli_error($link) );
list ( $runID, $tripleDesc, $runType ) = mysqli_fetch_array( $result );
list ( $cell, $channel, $wl ) = explode( "/", $tripleDesc );
$radius = $wl / 1000.0; // If WA data
// Now the information we need from the document table
$query = "SELECT reportDocument.label, reportDocument.filename, editedData.filename, " .
"documentType " .
"FROM reportDocument, editedData " .
"WHERE reportDocumentID = $documentID " .
"AND reportDocument.editedDataID = editedData.editedDataID ";
$result = mysqli_query( $link, $query )
or die( "Query failed : $query<br />\n" . mysqli_error($link) );
list( $label, $rfilename, $efilename, $doctype ) = mysqli_fetch_array( $result );
list( $anal, $subanal, $doctype_text ) = explode( ":", $label );
$parts = explode( ".", $efilename );
$edit_profile = $parts[1];
$triple = ( $runType == "WA" )
? "Cell $cell, Channel $channel, Radius $radius<br />\n"
: "Cell $cell, Channel $channel, Wavelength $wl<br />\n";
// Create header information
$header = "<div>\n" .
"<h1>$anal</h1>\n" .
"<h2>Run ID: $runID<br />\n" .
$triple .
"Edited Dataset: $edit_profile</h2>\n" .
"<p><b>$subanal ($doctype_text)</b><br />\n" .
"<b>Filename:</b>$rfilename<br />\n" .
"</div>\n";
// html already has a header in it
if ( $doctype == 'html' || $doctype == 'svgz' )
$header = "";
return $header;
}
// Function to get the document content. Method varies depending on the type
function get_document_content( $link, $documentID )
{
global $full_path, $data_dir;
// First the document and the document type
$query = "SELECT documentType, filename, contents " .
"FROM reportDocument " .
"WHERE reportDocumentID = $documentID ";
$result = mysqli_query( $link, $query )
or die( "Query failed : $query<br />\n" . mysqli_error($link) );
$row = mysqli_fetch_array( $result );
$doctype = $row['documentType'];
$filename = $row['filename'];
$contents = $row['contents'];
//$csize = mb_strlen( $contents, '8bit' );
// Check to see if there was anything
if ( ! $contents )
$text = "<p>The requested record has no document</p>\n";
else if ( $doctype == 'html' )
{
$text = "<div>\n" .
$contents .
"</div>\n";
}
else if ( $doctype == 'dat' ||
$doctype == 'rpt' ||
$doctype == 'csv' )
{
$file = $data_dir . $filename;
$r = fopen( $file, "w+" );
fwrite( $r, $contents );
fclose( $r );
// Figure out the apache file name, assuming a subdirectory
$apache_file = substr( $data_dir, strlen( $full_path ) ) . $filename;
$text = "<div><a href='$apache_file' target=_blank>Download</a></div>";
$text .= "<div><pre>\n" .
$contents .
"</pre></div>\n";
}
else if ( $doctype == 'png' )
{
// Create a new file in the data directory using the known filename
$file = $data_dir . $filename;
$r = fopen( $file, "wb+" );
fwrite( $r, $contents );
fclose( $r );
// Figure out the apache file name, assuming a subdirectory
$apache_file = substr( $data_dir, strlen( $full_path ) ) . $filename;
// Now create some html that includes the file
$text = <<<HTML
<div>
<a href='$apache_file' target=_blank>Download</a>
</div>
<div>
<img src='$apache_file' alt='UltraScan 3 png file' />
</div>
HTML;
}
else if ( $doctype == 'svgz' || $doctype == 'svg' )
{
// Code to echo the blob out to the user directly.
// Send it to the user without writing it out as a file
header( "Pragma: public" ); // required
header( "Expires: 0" );
header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
header( "Cache-Control: private", false ); // required for certain browsers
header( "Content-Type: image/svg+xml" );
header( "Content-Disposition: attachment; filename=$filename" );
header( "Content-Transfer-Encoding: binary" );
// header( "Content-Length: " . $csize );
echo $contents;
return "";
}
else
$text = "<p>Unsupported document format</p>\n";
return $text;
}
// Function to display an error of one sort or another and exit
function display_error( $error_text )
{
echo <<<HTML
<html>
<head>
<title>US Lims Database - display file error</title>
<meta name="verify-v1" content="+TIfXSnY08mlIGLtDJVkQxTV4kDYMoWu2GLfWLI7VBE=" />
<link rel="stylesheet" type="text/css" href="css/main.css" />
</head>
<body>
<p>$error_text</p>
<p>[<a href='index.php'>Return to the Main Menu</a>]</p>
</body></html>
HTML;
exit();
}
?>