-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathattachment.php
executable file
·322 lines (291 loc) · 9.2 KB
/
attachment.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php
session_start();
echo '<html>';
echo '<head>';
echo '</head>';
echo '<body>';
/*
echo '<pre>';
print_r($GLOBALS);
echo '</pre>';
*/
include 'common.php';
function read_sample_id()
{
echo '<table bgcolor=lightpink border=1>
<form method=post>';
echo '<tr>';
echo '<td>sample_id</td>';
echo '<td><input type=text name=sample_id></td>';
echo '</tr>';
echo '<tr><td colspan=2 align=center><button type=submit name=action value=list_attachment>List Attachment</button></td></tr>';
echo '<tr><td colspan=2 align=center><button type=submit name=action value=add_attachment>Add Attachment</button></td></tr>';
echo '<tr><td colspan=2 align=center><button type=submit name=action value=print_attachment>Print attachment</button></td></tr>';
echo '</form></table>';
}
//echo '<form method=post enctype=\'multipart/form-data\'>';
function list_attachment($sample_id)
{
$sql='select * from attachment where sample_id=\''.$sample_id.'\'';
//echo $sql;
$link=start_nchsls();
if(!$result=mysql_query($sql,$link)){echo 'No attachment for '.$sample_id.'<br>';return FALSE;}
echo '<h3>List of Attachment</h3>';
while($array=mysql_fetch_assoc($result))
{
echo '<table border=1 bgcolor=lightblue><form method=post>';
echo ' <tr>
<td>sample_id:</td>
<td><font color=red>'.$array['sample_id'].'</font></td>
<input type=hidden name=sample_id value=\''.$array['sample_id'].'\'>
<input type=hidden name=attachment_id value=\''.$array['attachment_id'].'\'>';
echo '<td align=center><button type=submit name=action value=delete_attachment>Delete Attachment</button></td>
<td align=center><button type=submit name=action value=edit_attachment>Edit Attachment</button></td>
</tr>';
echo '<tr><td>attachment_id</td><td>'.$array['attachment_id'].'</td></tr>';
echo '<tr><td>description</td><td>'.$array['description'].'</td></tr>';
echo '<tr><td>filetype</td><td>'.$array['filetype'].'</td></tr>';
$filetype=$array['filetype'];
if($filetype=='jpeg' || $filetype=='jpg' || $filetype=='gif')
{
$filename=create_file($array['file'],$array['sample_id'],$array['attachment_id'],$array['filetype']);
echo '<tr><td>file</td><td><img src="'.$filename.'" height=300 width=300></td></tr>';
}
elseif($filetype=='txt')
{
echo '<tr><td>file</td><td><pre>'.htmlspecialchars($array['file']).'</pre></td></tr>';
}
else
{
echo ' <tr>
<td>file</td>
<td>cannot display</td>
<td align=center>upload:<input type=file name=file></td>
</tr>';
}
echo '</form></table>';
}
}
function edit_attachment($sample_id,$attachment_id)
{
$sql='select * from attachment where sample_id=\''.$sample_id.'\' and attachment_id=\''.$attachment_id.'\'';
//echo $sql;
$link=start_nchsls();
if(!$result=mysql_query($sql,$link)){echo 'No such attachment_id=\''.$attachment_id.'\' , sample_id='.$sample_id.'<br>';return FALSE;}
$array=mysql_fetch_assoc($result);
echo '<table border=1 bgcolor=lightblue><form method=post enctype=\'multipart/form-data\'>';
echo '<tr><th>Edit Attachment</th></tr>';
echo ' <tr>
<td>sample_id:</td>
<td><font color=red>'.$array['sample_id'].'</font></td>
<input type=hidden name=sample_id value=\''.$array['sample_id'].'\'>
<input type=hidden name=attachment_id value=\''.$array['attachment_id'].'\'>';
echo '<td align=top><button type=submit name=action value=save_attachment>Save Attachment</button></td>
</tr>';
echo '<tr><td>attachment_id</td><td>'.$array['attachment_id'].'</td></tr>';
echo '<tr><td>description</td><td><input type=text name=description value=\''.$array['description'].'\'></td></tr>';
echo '<tr><td>filetype</td><td><input type=text name=filetype value=\''.$array['filetype'].'\'></td></tr>';
$filetype=$array['filetype'];
if($filetype=='jpeg' || $filetype=='jpg' || $filetype=='gif')
{
$filename=create_file($array['file'],$array['sample_id'],$array['attachment_id'],$array['filetype']);
echo ' <tr>
<td>file</td>
<td><img src="'.$filename.'" height=300 width=300></td>
<td valign=top>upload:<input type=file name=file></td>
</tr>';
}
elseif($filetype=='txt')
{
echo ' <tr>
<td>file</td>
<td><pre>'.htmlspecialchars($array['file']).'</pre></td>
<td valign=top>upload:<input type=file name=file></td>
</tr>';
}
else
{
echo ' <tr>
<td>file</td>
<td>cannot display</td>
<td align=center>upload:<input type=file name=file></td>
</tr>';
}
echo '</form></table>';
}
function add_attachment($sample_id)
{
echo '<table border=1 bgcolor=lightblue><form method=post enctype=\'multipart/form-data\'>';
echo '<tr><th>Add Attachment</th></tr>';
echo ' <tr>
<td>sample_id:</td> <td><font color=red><input type=text readonly name=sample_id value=\''.$sample_id.'\'></font></td>
<td align=top><button type=submit name=action value=insert_attachment>Insert Attachment</button></td>
</tr><tr>
<td>attachment_id</td> <td><input type=text name=attachment_id></td>
</tr>';
echo '<tr><td>description</td><td><input type=text name=description></td></tr>';
echo '<tr><td>filetype</td><td><input type=text name=filetype></td></tr>';
echo ' <tr><td valign=top>upload</td><td><input type=file name=file></td></tr>';
echo '</form></table>';
}
function file_to_str($file)
{
$link=start_nchsls();
$fd=fopen($file['tmp_name'],'r');
$size=$file['size'];
$str=fread($fd,$size);
return mysql_real_escape_string($str,$link);
}
/*
[_FILES] => Array
(
[file] => Array
(
[name] => view_data.sql
[type] => text/x-sql
[tmp_name] => /tmp/phpoeEMAz
[error] => 0
[size] => 2202
)
*/
function save_attachment($array,$files)
{
if(strlen($files['file']['tmp_name'])>0)
{
$str=file_to_str($files['file']);
$sql='update attachment set
description=\''.$array['description'].'\',
filetype=\''.$array['filetype'].'\',
file="'.$str.'"
where
sample_id=\''.$array['sample_id'].'\' and
attachment_id=\''.$array['attachment_id'].'\'';
//echo $sql;
$link=start_nchsls();
if(!$result=mysql_query($sql,$link)){echo mysql_error();}
else
{
echo 'success';
}
}
else
{
$sql='update attachment set
description=\''.$array['description'].'\',
filetype=\''.$array['filetype'].'\'
where
sample_id=\''.$array['sample_id'].'\' and
attachment_id=\''.$array['attachment_id'].'\'';
//echo $sql;
$link=start_nchsls();
if(!$result=mysql_query($sql,$link)){echo mysql_error();}
else
{
echo 'success';
}
}
}
function insert_attachment($array,$files)
{
if(strlen($files['file']['tmp_name'])>0)
{
$str=file_to_str($files['file']);
$sql='insert into attachment values(
\''.$array['sample_id'].'\',
\''.$array['attachment_id'].'\',
\''.$array['description'].'\',
\''.$array['filetype'].'\',
\''.$str.'\')';
//echo $sql;
$link=start_nchsls();
if(!$result=mysql_query($sql,$link)){echo mysql_error();}
else
{
echo 'success';
}
}
else
{
echo 'no file to attach<br>';
}
}
function delete_attachment($sample_id,$attachment_id)
{
$sql='delete from attachment
where
sample_id=\''.$sample_id.'\' and
attachment_id=\''.$attachment_id.'\'';
$link=start_nchsls();
if(!$result=mysql_query($sql,$link)){echo mysql_error();}
else
{
echo 'success';
}
}
function update_cross_reference($sample_id)
{
$sql='select * from attachment where sample_id=\''.$sample_id.'\'';
//echo $sql;
$link=start_nchsls();
if(!$result=mysql_query($sql,$link)){return FALSE;}
$str='';
while($array=mysql_fetch_assoc($result))
{
$str=$str.','.$array['attachment_id'];
}
insert_single_examination($sample_id,1008);
save_single_examination($sample_id,1008,$str);
}
if(!login_varify())
{
exit();
}
main_menu();
read_sample_id();
if(isset($_POST['action']))
{
if($_POST['action']=='list_attachment')
{
list_attachment($_POST['sample_id']);
}
if($_POST['action']=='edit_attachment')
{
edit_attachment($_POST['sample_id'],$_POST['attachment_id']);
}
if($_POST['action']=='add_attachment')
{
add_attachment($_POST['sample_id']);
}
if($_POST['action']=='save_attachment')
{
if(isset($_FILES))
{
save_attachment($_POST,$_FILES);
}
list_attachment($_POST['sample_id']);
}
if($_POST['action']=='insert_attachment')
{
if(isset($_FILES))
{
insert_attachment($_POST,$_FILES);
}
update_cross_reference($_POST['sample_id']);
list_attachment($_POST['sample_id']);
}
if($_POST['action']=='delete_attachment')
{
if(isset($_FILES))
{
delete_attachment($_POST['sample_id'],$_POST['attachment_id']);
}
update_cross_reference($_POST['sample_id']);
list_attachment($_POST['sample_id']);
}
if($_POST['action']=='print_attachment')
{
echo '<h2 style="page-break-before: always;"></h2>';
print_attachment($_POST['sample_id']);
}
}
?>