Switch the 'modify' code of admin/field.php to use templates
[bugdar.git] / viewattachment.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2004-2009 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 ob_start();
23
24
25 $focus['showreport'] = 'focus';
26
27 require_once('./global.php');
28
29 $attachment = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "attachment WHERE attachmentid = " . $input->inputClean('attachmentid', TYPE_UINT));
30 if (!$attachment)
31 {
32 $message->error(L_INVALID_ID);
33 }
34
35 $bug = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $attachment[bugid]");
36 if (!check_bug_permissions($bug))
37 {
38 $message->errorPermission();
39 }
40
41 if (!can_perform('cangetattach', $bug['product']))
42 {
43 $message->errorPermission();
44 }
45
46 ob_clean();
47 ob_end_clean();
48
49 // only allow certain images to be displayed inline because all other types are a potential XSS issue waiting to happen
50 if (in_array(strtolower(BSFunctions::fetch_extension($attachment['filename'])), array('jpg', 'jpeg', 'png', 'gif')))
51 {
52 header("Content-Disposition: inline; filename=$attachment[filename]");
53 header("Content-transfer-encoding: binary");
54 }
55 else
56 {
57 header("Content-Disposition: attachment; filename=$attachment[filename]");
58 }
59 header("Content-Length: " . strlen($attachment['attachment']));
60 header("Content-Type: $attachment[mimetype]");
61
62 print($attachment['attachment']);
63
64 ?>